extcon.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * External Connector (extcon) framework
  3. *
  4. * Copyright (C) 2015 Samsung Electronics
  5. * Author: Chanwoo Choi <cw00.choi@samsung.com>
  6. *
  7. * Copyright (C) 2012 Samsung Electronics
  8. * Author: Donggeun Kim <dg77.kim@samsung.com>
  9. * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
  10. *
  11. * based on switch class driver
  12. * Copyright (C) 2008 Google, Inc.
  13. * Author: Mike Lockwood <lockwood@android.com>
  14. *
  15. * This software is licensed under the terms of the GNU General Public
  16. * License version 2, as published by the Free Software Foundation, and
  17. * may be copied, distributed, and modified under those terms.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. */
  24. #ifndef __LINUX_EXTCON_H__
  25. #define __LINUX_EXTCON_H__
  26. #include <linux/device.h>
  27. /*
  28. * Define the type of supported external connectors
  29. */
  30. #define EXTCON_TYPE_USB BIT(0) /* USB connector */
  31. #define EXTCON_TYPE_CHG BIT(1) /* Charger connector */
  32. #define EXTCON_TYPE_JACK BIT(2) /* Jack connector */
  33. #define EXTCON_TYPE_DISP BIT(3) /* Display connector */
  34. #define EXTCON_TYPE_MISC BIT(4) /* Miscellaneous connector */
  35. /*
  36. * Define the unique id of supported external connectors
  37. */
  38. #define EXTCON_NONE 0
  39. /* USB external connector */
  40. #define EXTCON_USB 1
  41. #define EXTCON_USB_HOST 2
  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. /* 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
  71. /* Display external connector */
  72. #define EXTCON_DISP_HDMI 40 /* High-Definition Multimedia Interface */
  73. #define EXTCON_DISP_MHL 41 /* Mobile High-Definition Link */
  74. #define EXTCON_DISP_DVI 42 /* Digital Visual Interface */
  75. #define EXTCON_DISP_VGA 43 /* Video Graphics Array */
  76. #define EXTCON_DISP_DP 44 /* Display Port */
  77. #define EXTCON_DISP_HMD 45 /* Head-Mounted Display */
  78. /* Miscellaneous external connector */
  79. #define EXTCON_DOCK 60
  80. #define EXTCON_JIG 61
  81. #define EXTCON_MECHANICAL 62
  82. #define EXTCON_NUM 63
  83. /*
  84. * Define the properties of supported external connectors.
  85. *
  86. * When adding the new extcon property, they *must* have
  87. * the type/value/default information. Also, you *have to*
  88. * modify the EXTCON_PROP_[type]_START/END definitions
  89. * which mean the range of the supported properties
  90. * for each extcon type.
  91. *
  92. * The naming style of property
  93. * : EXTCON_PROP_[type]_[property name]
  94. *
  95. * EXTCON_PROP_USB_[property name] : USB property
  96. * EXTCON_PROP_CHG_[property name] : Charger property
  97. * EXTCON_PROP_JACK_[property name] : Jack property
  98. * EXTCON_PROP_DISP_[property name] : Display property
  99. */
  100. /*
  101. * Properties of EXTCON_TYPE_USB.
  102. *
  103. * - EXTCON_PROP_USB_VBUS
  104. * @type: integer (intval)
  105. * @value: 0 (low) or 1 (high)
  106. * @default: 0 (low)
  107. * - EXTCON_PROP_USB_TYPEC_POLARITY
  108. * @type: integer (intval)
  109. * @value: 0 (normal) or 1 (flip)
  110. * @default: 0 (normal)
  111. * - EXTCON_PROP_USB_SS (SuperSpeed)
  112. * @type: integer (intval)
  113. * @value: 0 (USB/USB2) or 1 (USB3)
  114. * @default: 0 (USB/USB2)
  115. *
  116. */
  117. #define EXTCON_PROP_USB_VBUS 0
  118. #define EXTCON_PROP_USB_TYPEC_POLARITY 1
  119. #define EXTCON_PROP_USB_SS 2
  120. #define EXTCON_PROP_USB_MIN 0
  121. #define EXTCON_PROP_USB_MAX 2
  122. #define EXTCON_PROP_USB_CNT (EXTCON_PROP_USB_MAX - EXTCON_PROP_USB_MIN + 1)
  123. /* Properties of EXTCON_TYPE_CHG. */
  124. #define EXTCON_PROP_CHG_MIN 50
  125. #define EXTCON_PROP_CHG_MAX 50
  126. #define EXTCON_PROP_CHG_CNT (EXTCON_PROP_CHG_MAX - EXTCON_PROP_CHG_MIN + 1)
  127. /* Properties of EXTCON_TYPE_JACK. */
  128. #define EXTCON_PROP_JACK_MIN 100
  129. #define EXTCON_PROP_JACK_MAX 100
  130. #define EXTCON_PROP_JACK_CNT (EXTCON_PROP_JACK_MAX - EXTCON_PROP_JACK_MIN + 1)
  131. /*
  132. * Properties of EXTCON_TYPE_DISP.
  133. *
  134. * - EXTCON_PROP_DISP_HPD (Hot Plug Detect)
  135. * @type: integer (intval)
  136. * @value: 0 (no hpd) or 1 (hpd)
  137. * @default: 0 (no hpd)
  138. *
  139. */
  140. #define EXTCON_PROP_DISP_HPD 150
  141. /* Properties of EXTCON_TYPE_DISP. */
  142. #define EXTCON_PROP_DISP_MIN 150
  143. #define EXTCON_PROP_DISP_MAX 151
  144. #define EXTCON_PROP_DISP_CNT (EXTCON_PROP_DISP_MAX - EXTCON_PROP_DISP_MIN + 1)
  145. /*
  146. * Define the type of property's value.
  147. *
  148. * Define the property's value as union type. Because each property
  149. * would need the different data type to store it.
  150. */
  151. union extcon_property_value {
  152. int intval; /* type : integer (intval) */
  153. };
  154. struct extcon_cable;
  155. struct extcon_dev;
  156. #if IS_ENABLED(CONFIG_EXTCON)
  157. /* Following APIs register/unregister the extcon device. */
  158. extern int extcon_dev_register(struct extcon_dev *edev);
  159. extern void extcon_dev_unregister(struct extcon_dev *edev);
  160. extern int devm_extcon_dev_register(struct device *dev,
  161. struct extcon_dev *edev);
  162. extern void devm_extcon_dev_unregister(struct device *dev,
  163. struct extcon_dev *edev);
  164. /* Following APIs allocate/free the memory of the extcon device. */
  165. extern struct extcon_dev *extcon_dev_allocate(const unsigned int *cable);
  166. extern void extcon_dev_free(struct extcon_dev *edev);
  167. extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
  168. const unsigned int *cable);
  169. extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
  170. /* Synchronize the state and property value for each external connector. */
  171. extern int extcon_sync(struct extcon_dev *edev, unsigned int id);
  172. /*
  173. * Following APIs get/set the connected state of each external connector.
  174. * The 'id' argument indicates the defined external connector.
  175. */
  176. extern int extcon_get_state(struct extcon_dev *edev, unsigned int id);
  177. extern int extcon_set_state(struct extcon_dev *edev, unsigned int id,
  178. bool state);
  179. extern int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
  180. bool state);
  181. /*
  182. * Following APIs get/set the property of each external connector.
  183. * The 'id' argument indicates the defined external connector
  184. * and the 'prop' indicates the extcon property.
  185. *
  186. * And extcon_get/set_property_capability() set the capability of the property
  187. * for each external connector. They are used to set the capability of the
  188. * property of each external connector based on the id and property.
  189. */
  190. extern int extcon_get_property(struct extcon_dev *edev, unsigned int id,
  191. unsigned int prop,
  192. union extcon_property_value *prop_val);
  193. extern int extcon_set_property(struct extcon_dev *edev, unsigned int id,
  194. unsigned int prop,
  195. union extcon_property_value prop_val);
  196. extern int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
  197. unsigned int prop,
  198. union extcon_property_value prop_val);
  199. extern int extcon_get_property_capability(struct extcon_dev *edev,
  200. unsigned int id, unsigned int prop);
  201. extern int extcon_set_property_capability(struct extcon_dev *edev,
  202. unsigned int id, unsigned int prop);
  203. /*
  204. * Following APIs register the notifier block in order to detect
  205. * the change of both state and property value for each external connector.
  206. *
  207. * extcon_register_notifier(*edev, id, *nb) : Register a notifier block
  208. * for specific external connector of the extcon.
  209. * extcon_register_notifier_all(*edev, *nb) : Register a notifier block
  210. * for all supported external connectors of the extcon.
  211. */
  212. extern int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
  213. struct notifier_block *nb);
  214. extern int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
  215. struct notifier_block *nb);
  216. extern int devm_extcon_register_notifier(struct device *dev,
  217. struct extcon_dev *edev, unsigned int id,
  218. struct notifier_block *nb);
  219. extern void devm_extcon_unregister_notifier(struct device *dev,
  220. struct extcon_dev *edev, unsigned int id,
  221. struct notifier_block *nb);
  222. extern int extcon_register_notifier_all(struct extcon_dev *edev,
  223. struct notifier_block *nb);
  224. extern int extcon_unregister_notifier_all(struct extcon_dev *edev,
  225. struct notifier_block *nb);
  226. extern int devm_extcon_register_notifier_all(struct device *dev,
  227. struct extcon_dev *edev,
  228. struct notifier_block *nb);
  229. extern void devm_extcon_unregister_notifier_all(struct device *dev,
  230. struct extcon_dev *edev,
  231. struct notifier_block *nb);
  232. /*
  233. * Following APIs get the extcon_dev from devicetree or by through extcon name.
  234. */
  235. extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
  236. extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
  237. int index);
  238. /* Following API get the name of extcon device. */
  239. extern const char *extcon_get_edev_name(struct extcon_dev *edev);
  240. #else /* CONFIG_EXTCON */
  241. static inline int extcon_dev_register(struct extcon_dev *edev)
  242. {
  243. return 0;
  244. }
  245. static inline void extcon_dev_unregister(struct extcon_dev *edev) { }
  246. static inline int devm_extcon_dev_register(struct device *dev,
  247. struct extcon_dev *edev)
  248. {
  249. return -EINVAL;
  250. }
  251. static inline void devm_extcon_dev_unregister(struct device *dev,
  252. struct extcon_dev *edev) { }
  253. static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *cable)
  254. {
  255. return ERR_PTR(-ENOSYS);
  256. }
  257. static inline void extcon_dev_free(struct extcon_dev *edev) { }
  258. static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
  259. const unsigned int *cable)
  260. {
  261. return ERR_PTR(-ENOSYS);
  262. }
  263. static inline void devm_extcon_dev_free(struct extcon_dev *edev) { }
  264. static inline int extcon_get_state(struct extcon_dev *edev, unsigned int id)
  265. {
  266. return 0;
  267. }
  268. static inline int extcon_set_state(struct extcon_dev *edev, unsigned int id,
  269. bool state)
  270. {
  271. return 0;
  272. }
  273. static inline int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
  274. bool state)
  275. {
  276. return 0;
  277. }
  278. static inline int extcon_sync(struct extcon_dev *edev, unsigned int id)
  279. {
  280. return 0;
  281. }
  282. static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id,
  283. unsigned int prop,
  284. union extcon_property_value *prop_val)
  285. {
  286. return 0;
  287. }
  288. static inline int extcon_set_property(struct extcon_dev *edev, unsigned int id,
  289. unsigned int prop,
  290. union extcon_property_value prop_val)
  291. {
  292. return 0;
  293. }
  294. static inline int extcon_set_property_sync(struct extcon_dev *edev,
  295. unsigned int id, unsigned int prop,
  296. union extcon_property_value prop_val)
  297. {
  298. return 0;
  299. }
  300. static inline int extcon_get_property_capability(struct extcon_dev *edev,
  301. unsigned int id, unsigned int prop)
  302. {
  303. return 0;
  304. }
  305. static inline int extcon_set_property_capability(struct extcon_dev *edev,
  306. unsigned int id, unsigned int prop)
  307. {
  308. return 0;
  309. }
  310. static inline int extcon_register_notifier(struct extcon_dev *edev,
  311. unsigned int id, struct notifier_block *nb)
  312. {
  313. return 0;
  314. }
  315. static inline int extcon_unregister_notifier(struct extcon_dev *edev,
  316. unsigned int id, struct notifier_block *nb)
  317. {
  318. return 0;
  319. }
  320. static inline int devm_extcon_register_notifier(struct device *dev,
  321. struct extcon_dev *edev, unsigned int id,
  322. struct notifier_block *nb)
  323. {
  324. return -ENOSYS;
  325. }
  326. static inline void devm_extcon_unregister_notifier(struct device *dev,
  327. struct extcon_dev *edev, unsigned int id,
  328. struct notifier_block *nb) { }
  329. static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
  330. {
  331. return ERR_PTR(-ENODEV);
  332. }
  333. static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
  334. int index)
  335. {
  336. return ERR_PTR(-ENODEV);
  337. }
  338. #endif /* CONFIG_EXTCON */
  339. /*
  340. * Following structure and API are deprecated. EXTCON remains the function
  341. * definition to prevent the build break.
  342. */
  343. struct extcon_specific_cable_nb {
  344. struct notifier_block *user_nb;
  345. int cable_index;
  346. struct extcon_dev *edev;
  347. unsigned long previous_value;
  348. };
  349. static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
  350. const char *extcon_name, const char *cable_name,
  351. struct notifier_block *nb)
  352. {
  353. return -EINVAL;
  354. }
  355. static inline int extcon_unregister_interest(struct extcon_specific_cable_nb *obj)
  356. {
  357. return -EINVAL;
  358. }
  359. #endif /* __LINUX_EXTCON_H__ */