xref: /OK3568_Linux_fs/kernel/include/linux/extcon.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * External Connector (extcon) framework
4  * - linux/include/linux/extcon.h for extcon consumer device driver.
5  *
6  * Copyright (C) 2015 Samsung Electronics
7  * Author: Chanwoo Choi <cw00.choi@samsung.com>
8  *
9  * Copyright (C) 2012 Samsung Electronics
10  * Author: Donggeun Kim <dg77.kim@samsung.com>
11  * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
12  *
13  * based on switch class driver
14  * Copyright (C) 2008 Google, Inc.
15  * Author: Mike Lockwood <lockwood@android.com>
16  */
17 
18 #ifndef __LINUX_EXTCON_H__
19 #define __LINUX_EXTCON_H__
20 
21 #include <linux/device.h>
22 
23 /*
24  * Define the type of supported external connectors
25  */
26 #define EXTCON_TYPE_USB		BIT(0)	/* USB connector */
27 #define EXTCON_TYPE_CHG		BIT(1)	/* Charger connector */
28 #define EXTCON_TYPE_JACK	BIT(2)	/* Jack connector */
29 #define EXTCON_TYPE_DISP	BIT(3)	/* Display connector */
30 #define EXTCON_TYPE_MISC	BIT(4)	/* Miscellaneous connector */
31 
32 /*
33  * Define the unique id of supported external connectors
34  */
35 #define EXTCON_NONE		0
36 
37 /* USB external connector */
38 #define EXTCON_USB		1
39 #define EXTCON_USB_HOST		2
40 #define EXTCON_USB_VBUS_EN	3
41 
42 /*
43  * Charging external connector
44  *
45  * When one SDP charger connector was reported, we should also report
46  * the USB connector, which means EXTCON_CHG_USB_SDP should always
47  * appear together with EXTCON_USB. The same as ACA charger connector,
48  * EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
49  *
50  * The EXTCON_CHG_USB_SLOW connector can provide at least 500mA of
51  * current at 5V. The EXTCON_CHG_USB_FAST connector can provide at
52  * least 1A of current at 5V.
53  */
54 #define EXTCON_CHG_USB_SDP	5	/* Standard Downstream Port */
55 #define EXTCON_CHG_USB_DCP	6	/* Dedicated Charging Port */
56 #define EXTCON_CHG_USB_CDP	7	/* Charging Downstream Port */
57 #define EXTCON_CHG_USB_ACA	8	/* Accessory Charger Adapter */
58 #define EXTCON_CHG_USB_FAST	9
59 #define EXTCON_CHG_USB_SLOW	10
60 #define EXTCON_CHG_WPT		11	/* Wireless Power Transfer */
61 #define EXTCON_CHG_USB_PD	12	/* USB Power Delivery */
62 
63 /* Jack external connector */
64 #define EXTCON_JACK_MICROPHONE	20
65 #define EXTCON_JACK_HEADPHONE	21
66 #define EXTCON_JACK_LINE_IN	22
67 #define EXTCON_JACK_LINE_OUT	23
68 #define EXTCON_JACK_VIDEO_IN	24
69 #define EXTCON_JACK_VIDEO_OUT	25
70 #define EXTCON_JACK_SPDIF_IN	26	/* Sony Philips Digital InterFace */
71 #define EXTCON_JACK_SPDIF_OUT	27
72 
73 /* Display external connector */
74 #define EXTCON_DISP_HDMI	40	/* High-Definition Multimedia Interface */
75 #define EXTCON_DISP_MHL		41	/* Mobile High-Definition Link */
76 #define EXTCON_DISP_DVI		42	/* Digital Visual Interface */
77 #define EXTCON_DISP_VGA		43	/* Video Graphics Array */
78 #define EXTCON_DISP_DP		44	/* Display Port */
79 #define EXTCON_DISP_HMD		45	/* Head-Mounted Display */
80 #define EXTCON_DISP_CVBS	46	/* Composite Video Broadcast Signal */
81 #define EXTCON_DISP_EDP		47	/* Embedded Display Port */
82 
83 /* Miscellaneous external connector */
84 #define EXTCON_DOCK		60
85 #define EXTCON_JIG		61
86 #define EXTCON_MECHANICAL	62
87 
88 #define EXTCON_NUM		63
89 
90 /*
91  * Define the properties of supported external connectors.
92  *
93  * When adding the new extcon property, they *must* have
94  * the type/value/default information. Also, you *have to*
95  * modify the EXTCON_PROP_[type]_START/END definitions
96  * which mean the range of the supported properties
97  * for each extcon type.
98  *
99  * The naming style of property
100  * : EXTCON_PROP_[type]_[property name]
101  *
102  * EXTCON_PROP_USB_[property name]	: USB property
103  * EXTCON_PROP_CHG_[property name]	: Charger property
104  * EXTCON_PROP_JACK_[property name]	: Jack property
105  * EXTCON_PROP_DISP_[property name]	: Display property
106  */
107 
108 /*
109  * Properties of EXTCON_TYPE_USB.
110  *
111  * - EXTCON_PROP_USB_VBUS
112  * @type:	integer (intval)
113  * @value:	0 (low) or 1 (high)
114  * @default:	0 (low)
115  * - EXTCON_PROP_USB_TYPEC_POLARITY
116  * @type:	integer (intval)
117  * @value:	0 (normal) or 1 (flip)
118  * @default:	0 (normal)
119  * - EXTCON_PROP_USB_SS (SuperSpeed)
120  * @type:       integer (intval)
121  * @value:      0 (USB/USB2) or 1 (USB3)
122  * @default:    0 (USB/USB2)
123  *
124  */
125 #define EXTCON_PROP_USB_VBUS		0
126 #define EXTCON_PROP_USB_TYPEC_POLARITY	1
127 #define EXTCON_PROP_USB_SS		2
128 
129 #define EXTCON_PROP_USB_MIN		0
130 #define EXTCON_PROP_USB_MAX		2
131 #define EXTCON_PROP_USB_CNT	(EXTCON_PROP_USB_MAX - EXTCON_PROP_USB_MIN + 1)
132 
133 /* Properties of EXTCON_TYPE_CHG. */
134 #define EXTCON_PROP_CHG_MIN		50
135 #define EXTCON_PROP_CHG_MAX		50
136 #define EXTCON_PROP_CHG_CNT	(EXTCON_PROP_CHG_MAX - EXTCON_PROP_CHG_MIN + 1)
137 
138 /* Properties of EXTCON_TYPE_JACK. */
139 #define EXTCON_PROP_JACK_MIN		100
140 #define EXTCON_PROP_JACK_MAX		100
141 #define EXTCON_PROP_JACK_CNT (EXTCON_PROP_JACK_MAX - EXTCON_PROP_JACK_MIN + 1)
142 
143 /*
144  * Properties of EXTCON_TYPE_DISP.
145  *
146  * - EXTCON_PROP_DISP_HPD (Hot Plug Detect)
147  * @type:       integer (intval)
148  * @value:      0 (no hpd) or 1 (hpd)
149  * @default:    0 (no hpd)
150  *
151  */
152 #define EXTCON_PROP_DISP_HPD		150
153 
154 /* Properties of EXTCON_TYPE_DISP. */
155 #define EXTCON_PROP_DISP_MIN		150
156 #define EXTCON_PROP_DISP_MAX		151
157 #define EXTCON_PROP_DISP_CNT (EXTCON_PROP_DISP_MAX - EXTCON_PROP_DISP_MIN + 1)
158 
159 /*
160  * Define the type of property's value.
161  *
162  * Define the property's value as union type. Because each property
163  * would need the different data type to store it.
164  */
165 union extcon_property_value {
166 	int intval;	/* type : integer (intval) */
167 };
168 
169 struct extcon_dev;
170 
171 #if IS_ENABLED(CONFIG_EXTCON)
172 /*
173  * Following APIs get the connected state of each external connector.
174  * The 'id' argument indicates the defined external connector.
175  */
176 int extcon_get_state(struct extcon_dev *edev, unsigned int id);
177 
178 /*
179  * Following APIs get the property of each external connector.
180  * The 'id' argument indicates the defined external connector
181  * and the 'prop' indicates the extcon property.
182  *
183  * And extcon_get_property_capability() get the capability of the property
184  * for each external connector. They are used to get the capability of the
185  * property of each external connector based on the id and property.
186  */
187 int extcon_get_property(struct extcon_dev *edev, unsigned int id,
188 				unsigned int prop,
189 				union extcon_property_value *prop_val);
190 int extcon_get_property_capability(struct extcon_dev *edev,
191 				unsigned int id, unsigned int prop);
192 
193 /*
194  * Following APIs register the notifier block in order to detect
195  * the change of both state and property value for each external connector.
196  *
197  * extcon_register_notifier(*edev, id, *nb) : Register a notifier block
198  *			for specific external connector of the extcon.
199  * extcon_register_notifier_all(*edev, *nb) : Register a notifier block
200  *			for all supported external connectors of the extcon.
201  */
202 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
203 				struct notifier_block *nb);
204 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
205 				struct notifier_block *nb);
206 int devm_extcon_register_notifier(struct device *dev,
207 				struct extcon_dev *edev, unsigned int id,
208 				struct notifier_block *nb);
209 void devm_extcon_unregister_notifier(struct device *dev,
210 				struct extcon_dev *edev, unsigned int id,
211 				struct notifier_block *nb);
212 
213 int extcon_register_notifier_all(struct extcon_dev *edev,
214 				struct notifier_block *nb);
215 int extcon_unregister_notifier_all(struct extcon_dev *edev,
216 				struct notifier_block *nb);
217 int devm_extcon_register_notifier_all(struct device *dev,
218 				struct extcon_dev *edev,
219 				struct notifier_block *nb);
220 void devm_extcon_unregister_notifier_all(struct device *dev,
221 				struct extcon_dev *edev,
222 				struct notifier_block *nb);
223 
224 /*
225  * Following APIs get the extcon_dev from devicetree or by through extcon name.
226  */
227 struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
228 struct extcon_dev *extcon_find_edev_by_node(struct device_node *node);
229 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
230 						     int index);
231 
232 /* Following API get the name of extcon device. */
233 const char *extcon_get_edev_name(struct extcon_dev *edev);
234 
235 #else /* CONFIG_EXTCON */
extcon_get_state(struct extcon_dev * edev,unsigned int id)236 static inline int extcon_get_state(struct extcon_dev *edev, unsigned int id)
237 {
238 	return 0;
239 }
240 
extcon_get_property(struct extcon_dev * edev,unsigned int id,unsigned int prop,union extcon_property_value * prop_val)241 static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id,
242 				unsigned int prop,
243 				union extcon_property_value *prop_val)
244 {
245 	return 0;
246 }
247 
extcon_get_property_capability(struct extcon_dev * edev,unsigned int id,unsigned int prop)248 static inline int extcon_get_property_capability(struct extcon_dev *edev,
249 				unsigned int id, unsigned int prop)
250 {
251 	return 0;
252 }
253 
extcon_register_notifier(struct extcon_dev * edev,unsigned int id,struct notifier_block * nb)254 static inline int extcon_register_notifier(struct extcon_dev *edev,
255 				unsigned int id, struct notifier_block *nb)
256 {
257 	return 0;
258 }
259 
extcon_unregister_notifier(struct extcon_dev * edev,unsigned int id,struct notifier_block * nb)260 static inline int extcon_unregister_notifier(struct extcon_dev *edev,
261 				unsigned int id, struct notifier_block *nb)
262 {
263 	return 0;
264 }
265 
devm_extcon_register_notifier(struct device * dev,struct extcon_dev * edev,unsigned int id,struct notifier_block * nb)266 static inline int devm_extcon_register_notifier(struct device *dev,
267 				struct extcon_dev *edev, unsigned int id,
268 				struct notifier_block *nb)
269 {
270 	return -ENOSYS;
271 }
272 
devm_extcon_unregister_notifier(struct device * dev,struct extcon_dev * edev,unsigned int id,struct notifier_block * nb)273 static inline  void devm_extcon_unregister_notifier(struct device *dev,
274 				struct extcon_dev *edev, unsigned int id,
275 				struct notifier_block *nb) { }
276 
extcon_register_notifier_all(struct extcon_dev * edev,struct notifier_block * nb)277 static inline int extcon_register_notifier_all(struct extcon_dev *edev,
278 					       struct notifier_block *nb)
279 {
280 	return 0;
281 }
282 
extcon_unregister_notifier_all(struct extcon_dev * edev,struct notifier_block * nb)283 static inline int extcon_unregister_notifier_all(struct extcon_dev *edev,
284 						 struct notifier_block *nb)
285 {
286 	return 0;
287 }
288 
devm_extcon_register_notifier_all(struct device * dev,struct extcon_dev * edev,struct notifier_block * nb)289 static inline int devm_extcon_register_notifier_all(struct device *dev,
290 						    struct extcon_dev *edev,
291 						    struct notifier_block *nb)
292 {
293 	return 0;
294 }
295 
devm_extcon_unregister_notifier_all(struct device * dev,struct extcon_dev * edev,struct notifier_block * nb)296 static inline void devm_extcon_unregister_notifier_all(struct device *dev,
297 						       struct extcon_dev *edev,
298 						       struct notifier_block *nb) { }
299 
extcon_get_extcon_dev(const char * extcon_name)300 static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
301 {
302 	return ERR_PTR(-ENODEV);
303 }
304 
extcon_find_edev_by_node(struct device_node * node)305 static inline struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
306 {
307 	return ERR_PTR(-ENODEV);
308 }
309 
extcon_get_edev_by_phandle(struct device * dev,int index)310 static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
311 				int index)
312 {
313 	return ERR_PTR(-ENODEV);
314 }
315 
extcon_get_edev_name(struct extcon_dev * edev)316 static inline const char *extcon_get_edev_name(struct extcon_dev *edev)
317 {
318 	return NULL;
319 }
320 #endif /* CONFIG_EXTCON */
321 
322 /*
323  * Following structure and API are deprecated. EXTCON remains the function
324  * definition to prevent the build break.
325  */
326 struct extcon_specific_cable_nb {
327        struct notifier_block *user_nb;
328        int cable_index;
329        struct extcon_dev *edev;
330        unsigned long previous_value;
331 };
332 
extcon_register_interest(struct extcon_specific_cable_nb * obj,const char * extcon_name,const char * cable_name,struct notifier_block * nb)333 static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
334 				const char *extcon_name, const char *cable_name,
335 				struct notifier_block *nb)
336 {
337 	return -EINVAL;
338 }
339 
extcon_unregister_interest(struct extcon_specific_cable_nb * obj)340 static inline int extcon_unregister_interest(struct extcon_specific_cable_nb *obj)
341 {
342 	return -EINVAL;
343 }
344 #endif /* __LINUX_EXTCON_H__ */
345