1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#ifndef __LINUX_EXTCON_H__
24#define __LINUX_EXTCON_H__
25
26#include <linux/device.h>
27#include <linux/notifier.h>
28#include <linux/sysfs.h>
29
30#define SUPPORTED_CABLE_MAX 32
31#define CABLE_NAME_MAX 30
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51enum extcon_cable_name {
52 EXTCON_USB = 0,
53 EXTCON_USB_HOST,
54 EXTCON_TA,
55 EXTCON_FAST_CHARGER,
56 EXTCON_SLOW_CHARGER,
57 EXTCON_CHARGE_DOWNSTREAM,
58 EXTCON_HDMI,
59 EXTCON_MHL,
60 EXTCON_DVI,
61 EXTCON_VGA,
62 EXTCON_DOCK,
63 EXTCON_LINE_IN,
64 EXTCON_LINE_OUT,
65 EXTCON_MIC_IN,
66 EXTCON_HEADPHONE_OUT,
67 EXTCON_SPDIF_IN,
68 EXTCON_SPDIF_OUT,
69 EXTCON_VIDEO_IN,
70 EXTCON_VIDEO_OUT,
71 EXTCON_MECHANICAL,
72};
73extern const char extcon_cable_name[][CABLE_NAME_MAX + 1];
74
75struct extcon_cable;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113struct extcon_dev {
114
115 const char *name;
116 const char **supported_cable;
117 const u32 *mutually_exclusive;
118
119
120 ssize_t (*print_name)(struct extcon_dev *edev, char *buf);
121 ssize_t (*print_state)(struct extcon_dev *edev, char *buf);
122
123
124 struct device dev;
125 struct raw_notifier_head nh;
126 struct list_head entry;
127 int max_supported;
128 spinlock_t lock;
129 u32 state;
130
131
132 struct device_type extcon_dev_type;
133 struct extcon_cable *cables;
134
135
136 struct attribute_group attr_g_muex;
137 struct attribute **attrs_muex;
138 struct device_attribute *d_attrs_muex;
139};
140
141
142
143
144
145
146
147
148
149
150struct extcon_cable {
151 struct extcon_dev *edev;
152 int cable_index;
153
154 struct attribute_group attr_g;
155 struct device_attribute attr_name;
156 struct device_attribute attr_state;
157
158 struct attribute *attrs[3];
159};
160
161
162
163
164
165
166
167
168
169
170
171
172struct extcon_specific_cable_nb {
173 struct notifier_block internal_nb;
174 struct notifier_block *user_nb;
175 int cable_index;
176 struct extcon_dev *edev;
177 unsigned long previous_value;
178};
179
180#if IS_ENABLED(CONFIG_EXTCON)
181
182
183
184
185
186extern int extcon_dev_register(struct extcon_dev *edev);
187extern void extcon_dev_unregister(struct extcon_dev *edev);
188extern int devm_extcon_dev_register(struct device *dev,
189 struct extcon_dev *edev);
190extern void devm_extcon_dev_unregister(struct device *dev,
191 struct extcon_dev *edev);
192extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
193
194
195
196
197extern struct extcon_dev *extcon_dev_allocate(const char **cables);
198extern void extcon_dev_free(struct extcon_dev *edev);
199extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
200 const char **cables);
201extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
202
203
204
205
206
207
208
209static inline u32 extcon_get_state(struct extcon_dev *edev)
210{
211 return edev->state;
212}
213
214extern int extcon_set_state(struct extcon_dev *edev, u32 state);
215extern int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state);
216
217
218
219
220
221
222extern int extcon_find_cable_index(struct extcon_dev *sdev,
223 const char *cable_name);
224extern int extcon_get_cable_state_(struct extcon_dev *edev, int cable_index);
225extern int extcon_set_cable_state_(struct extcon_dev *edev, int cable_index,
226 bool cable_state);
227
228extern int extcon_get_cable_state(struct extcon_dev *edev,
229 const char *cable_name);
230extern int extcon_set_cable_state(struct extcon_dev *edev,
231 const char *cable_name, bool cable_state);
232
233
234
235
236
237
238
239extern int extcon_register_interest(struct extcon_specific_cable_nb *obj,
240 const char *extcon_name,
241 const char *cable_name,
242 struct notifier_block *nb);
243extern int extcon_unregister_interest(struct extcon_specific_cable_nb *nb);
244
245
246
247
248
249
250
251
252extern int extcon_register_notifier(struct extcon_dev *edev,
253 struct notifier_block *nb);
254extern int extcon_unregister_notifier(struct extcon_dev *edev,
255 struct notifier_block *nb);
256
257
258
259
260
261extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index);
262#else
263static inline int extcon_dev_register(struct extcon_dev *edev)
264{
265 return 0;
266}
267
268static inline void extcon_dev_unregister(struct extcon_dev *edev) { }
269
270static inline int devm_extcon_dev_register(struct device *dev,
271 struct extcon_dev *edev)
272{
273 return -EINVAL;
274}
275
276static inline void devm_extcon_dev_unregister(struct device *dev,
277 struct extcon_dev *edev) { }
278
279static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
280{
281 return ERR_PTR(-ENOSYS);
282}
283
284static inline void extcon_dev_free(struct extcon_dev *edev) { }
285
286static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
287 const char **cables)
288{
289 return ERR_PTR(-ENOSYS);
290}
291
292static inline void devm_extcon_dev_free(struct extcon_dev *edev) { }
293
294static inline u32 extcon_get_state(struct extcon_dev *edev)
295{
296 return 0;
297}
298
299static inline int extcon_set_state(struct extcon_dev *edev, u32 state)
300{
301 return 0;
302}
303
304static inline int extcon_update_state(struct extcon_dev *edev, u32 mask,
305 u32 state)
306{
307 return 0;
308}
309
310static inline int extcon_find_cable_index(struct extcon_dev *edev,
311 const char *cable_name)
312{
313 return 0;
314}
315
316static inline int extcon_get_cable_state_(struct extcon_dev *edev,
317 int cable_index)
318{
319 return 0;
320}
321
322static inline int extcon_set_cable_state_(struct extcon_dev *edev,
323 int cable_index, bool cable_state)
324{
325 return 0;
326}
327
328static inline int extcon_get_cable_state(struct extcon_dev *edev,
329 const char *cable_name)
330{
331 return 0;
332}
333
334static inline int extcon_set_cable_state(struct extcon_dev *edev,
335 const char *cable_name, int state)
336{
337 return 0;
338}
339
340static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
341{
342 return NULL;
343}
344
345static inline int extcon_register_notifier(struct extcon_dev *edev,
346 struct notifier_block *nb)
347{
348 return 0;
349}
350
351static inline int extcon_unregister_notifier(struct extcon_dev *edev,
352 struct notifier_block *nb)
353{
354 return 0;
355}
356
357static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
358 const char *extcon_name,
359 const char *cable_name,
360 struct notifier_block *nb)
361{
362 return 0;
363}
364
365static inline int extcon_unregister_interest(struct extcon_specific_cable_nb
366 *obj)
367{
368 return 0;
369}
370
371static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
372 int index)
373{
374 return ERR_PTR(-ENODEV);
375}
376#endif
377#endif
378