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