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