extcon.h 10 KB

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