extcon.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * External Connector (extcon) framework
  3. * - linux/include/linux/extcon.h for extcon consumer device driver.
  4. *
  5. * Copyright (C) 2015 Samsung Electronics
  6. * Author: Chanwoo Choi <cw00.choi@samsung.com>
  7. *
  8. * Copyright (C) 2012 Samsung Electronics
  9. * Author: Donggeun Kim <dg77.kim@samsung.com>
  10. * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
  11. *
  12. * based on switch class driver
  13. * Copyright (C) 2008 Google, Inc.
  14. * Author: Mike Lockwood <lockwood@android.com>
  15. *
  16. * This software is licensed under the terms of the GNU General Public
  17. * License version 2, as published by the Free Software Foundation, and
  18. * may be copied, distributed, and modified under those terms.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. */
  25. #ifndef __LINUX_EXTCON_H__
  26. #define __LINUX_EXTCON_H__
  27. #include <linux/device.h>
  28. /*
  29. * Define the type of supported external connectors
  30. */
  31. #define EXTCON_TYPE_USB BIT(0) /* USB connector */
  32. #define EXTCON_TYPE_CHG BIT(1) /* Charger connector */
  33. #define EXTCON_TYPE_JACK BIT(2) /* Jack connector */
  34. #define EXTCON_TYPE_DISP BIT(3) /* Display connector */
  35. #define EXTCON_TYPE_MISC BIT(4) /* Miscellaneous connector */
  36. /*
  37. * Define the unique id of supported external connectors
  38. */
  39. #define EXTCON_NONE 0
  40. /* USB external connector */
  41. #define EXTCON_USB 1
  42. #define EXTCON_USB_HOST 2
  43. /*
  44. * Charging external connector
  45. *
  46. * When one SDP charger connector was reported, we should also report
  47. * the USB connector, which means EXTCON_CHG_USB_SDP should always
  48. * appear together with EXTCON_USB. The same as ACA charger connector,
  49. * EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
  50. *
  51. * The EXTCON_CHG_USB_SLOW connector can provide at least 500mA of
  52. * current at 5V. The EXTCON_CHG_USB_FAST connector can provide at
  53. * least 1A of current at 5V.
  54. */
  55. #define EXTCON_CHG_USB_SDP 5 /* Standard Downstream Port */
  56. #define EXTCON_CHG_USB_DCP 6 /* Dedicated Charging Port */
  57. #define EXTCON_CHG_USB_CDP 7 /* Charging Downstream Port */
  58. #define EXTCON_CHG_USB_ACA 8 /* Accessory Charger Adapter */
  59. #define EXTCON_CHG_USB_FAST 9
  60. #define EXTCON_CHG_USB_SLOW 10
  61. #define EXTCON_CHG_WPT 11 /* Wireless Power Transfer */
  62. #define EXTCON_CHG_USB_PD 12 /* USB Power Delivery */
  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. /* 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 */
  77. #define EXTCON_DISP_DP 44 /* Display Port */
  78. #define EXTCON_DISP_HMD 45 /* Head-Mounted Display */
  79. /* Miscellaneous external connector */
  80. #define EXTCON_DOCK 60
  81. #define EXTCON_JIG 61
  82. #define EXTCON_MECHANICAL 62
  83. #define EXTCON_NUM 63
  84. /*
  85. * Define the properties of supported external connectors.
  86. *
  87. * When adding the new extcon property, they *must* have
  88. * the type/value/default information. Also, you *have to*
  89. * modify the EXTCON_PROP_[type]_START/END definitions
  90. * which mean the range of the supported properties
  91. * for each extcon type.
  92. *
  93. * The naming style of property
  94. * : EXTCON_PROP_[type]_[property name]
  95. *
  96. * EXTCON_PROP_USB_[property name] : USB property
  97. * EXTCON_PROP_CHG_[property name] : Charger property
  98. * EXTCON_PROP_JACK_[property name] : Jack property
  99. * EXTCON_PROP_DISP_[property name] : Display property
  100. */
  101. /*
  102. * Properties of EXTCON_TYPE_USB.
  103. *
  104. * - EXTCON_PROP_USB_VBUS
  105. * @type: integer (intval)
  106. * @value: 0 (low) or 1 (high)
  107. * @default: 0 (low)
  108. * - EXTCON_PROP_USB_TYPEC_POLARITY
  109. * @type: integer (intval)
  110. * @value: 0 (normal) or 1 (flip)
  111. * @default: 0 (normal)
  112. * - EXTCON_PROP_USB_SS (SuperSpeed)
  113. * @type: integer (intval)
  114. * @value: 0 (USB/USB2) or 1 (USB3)
  115. * @default: 0 (USB/USB2)
  116. *
  117. */
  118. #define EXTCON_PROP_USB_VBUS 0
  119. #define EXTCON_PROP_USB_TYPEC_POLARITY 1
  120. #define EXTCON_PROP_USB_SS 2
  121. #define EXTCON_PROP_USB_MIN 0
  122. #define EXTCON_PROP_USB_MAX 2
  123. #define EXTCON_PROP_USB_CNT (EXTCON_PROP_USB_MAX - EXTCON_PROP_USB_MIN + 1)
  124. /* Properties of EXTCON_TYPE_CHG. */
  125. #define EXTCON_PROP_CHG_MIN 50
  126. #define EXTCON_PROP_CHG_MAX 50
  127. #define EXTCON_PROP_CHG_CNT (EXTCON_PROP_CHG_MAX - EXTCON_PROP_CHG_MIN + 1)
  128. /* Properties of EXTCON_TYPE_JACK. */
  129. #define EXTCON_PROP_JACK_MIN 100
  130. #define EXTCON_PROP_JACK_MAX 100
  131. #define EXTCON_PROP_JACK_CNT (EXTCON_PROP_JACK_MAX - EXTCON_PROP_JACK_MIN + 1)
  132. /*
  133. * Properties of EXTCON_TYPE_DISP.
  134. *
  135. * - EXTCON_PROP_DISP_HPD (Hot Plug Detect)
  136. * @type: integer (intval)
  137. * @value: 0 (no hpd) or 1 (hpd)
  138. * @default: 0 (no hpd)
  139. *
  140. */
  141. #define EXTCON_PROP_DISP_HPD 150
  142. /* Properties of EXTCON_TYPE_DISP. */
  143. #define EXTCON_PROP_DISP_MIN 150
  144. #define EXTCON_PROP_DISP_MAX 151
  145. #define EXTCON_PROP_DISP_CNT (EXTCON_PROP_DISP_MAX - EXTCON_PROP_DISP_MIN + 1)
  146. /*
  147. * Define the type of property's value.
  148. *
  149. * Define the property's value as union type. Because each property
  150. * would need the different data type to store it.
  151. */
  152. union extcon_property_value {
  153. int intval; /* type : integer (intval) */
  154. };
  155. struct extcon_dev;
  156. #if IS_ENABLED(CONFIG_EXTCON)
  157. /*
  158. * Following APIs get the connected state of each external connector.
  159. * The 'id' argument indicates the defined external connector.
  160. */
  161. extern int extcon_get_state(struct extcon_dev *edev, unsigned int id);
  162. /*
  163. * Following APIs get the property of each external connector.
  164. * The 'id' argument indicates the defined external connector
  165. * and the 'prop' indicates the extcon property.
  166. *
  167. * And extcon_get_property_capability() get the capability of the property
  168. * for each external connector. They are used to get the capability of the
  169. * property of each external connector based on the id and property.
  170. */
  171. extern int extcon_get_property(struct extcon_dev *edev, unsigned int id,
  172. unsigned int prop,
  173. union extcon_property_value *prop_val);
  174. extern int extcon_get_property_capability(struct extcon_dev *edev,
  175. unsigned int id, unsigned int prop);
  176. /*
  177. * Following APIs register the notifier block in order to detect
  178. * the change of both state and property value for each external connector.
  179. *
  180. * extcon_register_notifier(*edev, id, *nb) : Register a notifier block
  181. * for specific external connector of the extcon.
  182. * extcon_register_notifier_all(*edev, *nb) : Register a notifier block
  183. * for all supported external connectors of the extcon.
  184. */
  185. extern int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
  186. struct notifier_block *nb);
  187. extern int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
  188. struct notifier_block *nb);
  189. extern int devm_extcon_register_notifier(struct device *dev,
  190. struct extcon_dev *edev, unsigned int id,
  191. struct notifier_block *nb);
  192. extern void devm_extcon_unregister_notifier(struct device *dev,
  193. struct extcon_dev *edev, unsigned int id,
  194. struct notifier_block *nb);
  195. extern int extcon_register_notifier_all(struct extcon_dev *edev,
  196. struct notifier_block *nb);
  197. extern int extcon_unregister_notifier_all(struct extcon_dev *edev,
  198. struct notifier_block *nb);
  199. extern int devm_extcon_register_notifier_all(struct device *dev,
  200. struct extcon_dev *edev,
  201. struct notifier_block *nb);
  202. extern void devm_extcon_unregister_notifier_all(struct device *dev,
  203. struct extcon_dev *edev,
  204. struct notifier_block *nb);
  205. /*
  206. * Following APIs get the extcon_dev from devicetree or by through extcon name.
  207. */
  208. extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
  209. extern struct extcon_dev *extcon_find_edev_by_node(struct device_node *node);
  210. extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
  211. int index);
  212. /* Following API get the name of extcon device. */
  213. extern const char *extcon_get_edev_name(struct extcon_dev *edev);
  214. #else /* CONFIG_EXTCON */
  215. static inline int extcon_get_state(struct extcon_dev *edev, unsigned int id)
  216. {
  217. return 0;
  218. }
  219. static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id,
  220. unsigned int prop,
  221. union extcon_property_value *prop_val)
  222. {
  223. return 0;
  224. }
  225. static inline int extcon_get_property_capability(struct extcon_dev *edev,
  226. unsigned int id, unsigned int prop)
  227. {
  228. return 0;
  229. }
  230. static inline int extcon_register_notifier(struct extcon_dev *edev,
  231. unsigned int id, struct notifier_block *nb)
  232. {
  233. return 0;
  234. }
  235. static inline int extcon_unregister_notifier(struct extcon_dev *edev,
  236. unsigned int id, struct notifier_block *nb)
  237. {
  238. return 0;
  239. }
  240. static inline int devm_extcon_register_notifier(struct device *dev,
  241. struct extcon_dev *edev, unsigned int id,
  242. struct notifier_block *nb)
  243. {
  244. return -ENOSYS;
  245. }
  246. static inline void devm_extcon_unregister_notifier(struct device *dev,
  247. struct extcon_dev *edev, unsigned int id,
  248. struct notifier_block *nb) { }
  249. static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
  250. {
  251. return ERR_PTR(-ENODEV);
  252. }
  253. static inline struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
  254. {
  255. return ERR_PTR(-ENODEV);
  256. }
  257. static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
  258. int index)
  259. {
  260. return ERR_PTR(-ENODEV);
  261. }
  262. #endif /* CONFIG_EXTCON */
  263. /*
  264. * Following structure and API are deprecated. EXTCON remains the function
  265. * definition to prevent the build break.
  266. */
  267. struct extcon_specific_cable_nb {
  268. struct notifier_block *user_nb;
  269. int cable_index;
  270. struct extcon_dev *edev;
  271. unsigned long previous_value;
  272. };
  273. static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
  274. const char *extcon_name, const char *cable_name,
  275. struct notifier_block *nb)
  276. {
  277. return -EINVAL;
  278. }
  279. static inline int extcon_unregister_interest(struct extcon_specific_cable_nb *obj)
  280. {
  281. return -EINVAL;
  282. }
  283. #endif /* __LINUX_EXTCON_H__ */