extcon.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * External connector (extcon) class driver
  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. */
  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 property 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_cable;
  156. struct extcon_dev;
  157. #if IS_ENABLED(CONFIG_EXTCON)
  158. /*
  159. * Following APIs are for notifiers or configurations.
  160. * Notifiers are the external port and connection devices.
  161. */
  162. extern int extcon_dev_register(struct extcon_dev *edev);
  163. extern void extcon_dev_unregister(struct extcon_dev *edev);
  164. extern int devm_extcon_dev_register(struct device *dev,
  165. struct extcon_dev *edev);
  166. extern void devm_extcon_dev_unregister(struct device *dev,
  167. struct extcon_dev *edev);
  168. extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
  169. /*
  170. * Following APIs control the memory of extcon device.
  171. */
  172. extern struct extcon_dev *extcon_dev_allocate(const unsigned int *cable);
  173. extern void extcon_dev_free(struct extcon_dev *edev);
  174. extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
  175. const unsigned int *cable);
  176. extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
  177. /*
  178. * get/set_state access each bit of the 32b encoded state value.
  179. * They are used to access the status of each cable based on the cable id.
  180. */
  181. extern int extcon_get_state(struct extcon_dev *edev, unsigned int id);
  182. extern int extcon_set_state(struct extcon_dev *edev, unsigned int id,
  183. bool cable_state);
  184. extern int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
  185. bool cable_state);
  186. /*
  187. * Synchronize the state and property data for a specific external connector.
  188. */
  189. extern int extcon_sync(struct extcon_dev *edev, unsigned int id);
  190. /*
  191. * get/set_property access the property value of each external connector.
  192. * They are used to access the property of each cable based on the property id.
  193. */
  194. extern int extcon_get_property(struct extcon_dev *edev, unsigned int id,
  195. unsigned int prop,
  196. union extcon_property_value *prop_val);
  197. extern int extcon_set_property(struct extcon_dev *edev, unsigned int id,
  198. unsigned int prop,
  199. union extcon_property_value prop_val);
  200. extern int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
  201. unsigned int prop,
  202. union extcon_property_value prop_val);
  203. /*
  204. * get/set_property_capability set the capability of the property for each
  205. * external connector. They are used to set the capability of the property
  206. * of each external connector based on the id and property.
  207. */
  208. extern int extcon_get_property_capability(struct extcon_dev *edev,
  209. unsigned int id, unsigned int prop);
  210. extern int extcon_set_property_capability(struct extcon_dev *edev,
  211. unsigned int id, unsigned int prop);
  212. /*
  213. * Following APIs are to monitor every action of a notifier.
  214. * Registrar gets notified for every external port of a connection device.
  215. * Probably this could be used to debug an action of notifier; however,
  216. * we do not recommend to use this for normal 'notifiee' device drivers who
  217. * want to be notified by a specific external port of the notifier.
  218. */
  219. extern int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
  220. struct notifier_block *nb);
  221. extern int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
  222. struct notifier_block *nb);
  223. extern int devm_extcon_register_notifier(struct device *dev,
  224. struct extcon_dev *edev, unsigned int id,
  225. struct notifier_block *nb);
  226. extern void devm_extcon_unregister_notifier(struct device *dev,
  227. struct extcon_dev *edev, unsigned int id,
  228. struct notifier_block *nb);
  229. /*
  230. * Following API get the extcon device from devicetree.
  231. * This function use phandle of devicetree to get extcon device directly.
  232. */
  233. extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
  234. int index);
  235. /* Following API to get information of extcon device */
  236. extern const char *extcon_get_edev_name(struct extcon_dev *edev);
  237. #else /* CONFIG_EXTCON */
  238. static inline int extcon_dev_register(struct extcon_dev *edev)
  239. {
  240. return 0;
  241. }
  242. static inline void extcon_dev_unregister(struct extcon_dev *edev) { }
  243. static inline int devm_extcon_dev_register(struct device *dev,
  244. struct extcon_dev *edev)
  245. {
  246. return -EINVAL;
  247. }
  248. static inline void devm_extcon_dev_unregister(struct device *dev,
  249. struct extcon_dev *edev) { }
  250. static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *cable)
  251. {
  252. return ERR_PTR(-ENOSYS);
  253. }
  254. static inline void extcon_dev_free(struct extcon_dev *edev) { }
  255. static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
  256. const unsigned int *cable)
  257. {
  258. return ERR_PTR(-ENOSYS);
  259. }
  260. static inline void devm_extcon_dev_free(struct extcon_dev *edev) { }
  261. static inline int extcon_get_state(struct extcon_dev *edev, unsigned int id)
  262. {
  263. return 0;
  264. }
  265. static inline int extcon_set_state(struct extcon_dev *edev, unsigned int id,
  266. bool cable_state)
  267. {
  268. return 0;
  269. }
  270. static inline int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
  271. bool cable_state)
  272. {
  273. return 0;
  274. }
  275. static inline int extcon_sync(struct extcon_dev *edev, unsigned int id)
  276. {
  277. return 0;
  278. }
  279. static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id,
  280. unsigned int prop,
  281. union extcon_property_value *prop_val)
  282. {
  283. return 0;
  284. }
  285. static inline int extcon_set_property(struct extcon_dev *edev, unsigned int id,
  286. unsigned int prop,
  287. union extcon_property_value prop_val)
  288. {
  289. return 0;
  290. }
  291. static inline int extcon_set_property_sync(struct extcon_dev *edev,
  292. unsigned int id, unsigned int prop,
  293. union extcon_property_value prop_val)
  294. {
  295. return 0;
  296. }
  297. static inline int extcon_get_property_capability(struct extcon_dev *edev,
  298. unsigned int id, unsigned int prop)
  299. {
  300. return 0;
  301. }
  302. static inline int extcon_set_property_capability(struct extcon_dev *edev,
  303. unsigned int id, unsigned int prop)
  304. {
  305. return 0;
  306. }
  307. static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
  308. {
  309. return NULL;
  310. }
  311. static inline int extcon_register_notifier(struct extcon_dev *edev,
  312. unsigned int id,
  313. struct notifier_block *nb)
  314. {
  315. return 0;
  316. }
  317. static inline int extcon_unregister_notifier(struct extcon_dev *edev,
  318. unsigned int id,
  319. struct notifier_block *nb)
  320. {
  321. return 0;
  322. }
  323. static inline int devm_extcon_register_notifier(struct device *dev,
  324. struct extcon_dev *edev, unsigned int id,
  325. struct notifier_block *nb)
  326. {
  327. return -ENOSYS;
  328. }
  329. static inline void devm_extcon_unregister_notifier(struct device *dev,
  330. struct extcon_dev *edev, unsigned int id,
  331. struct notifier_block *nb) { }
  332. static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
  333. int index)
  334. {
  335. return ERR_PTR(-ENODEV);
  336. }
  337. #endif /* CONFIG_EXTCON */
  338. /*
  339. * Following structure and API are deprecated. EXTCON remains the function
  340. * definition to prevent the build break.
  341. */
  342. struct extcon_specific_cable_nb {
  343. struct notifier_block *user_nb;
  344. int cable_index;
  345. struct extcon_dev *edev;
  346. unsigned long previous_value;
  347. };
  348. static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
  349. const char *extcon_name, const char *cable_name,
  350. struct notifier_block *nb)
  351. {
  352. return -EINVAL;
  353. }
  354. static inline int extcon_unregister_interest(struct extcon_specific_cable_nb
  355. *obj)
  356. {
  357. return -EINVAL;
  358. }
  359. static inline int extcon_get_cable_state_(struct extcon_dev *edev, unsigned int id)
  360. {
  361. return extcon_get_state(edev, id);
  362. }
  363. static inline int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id,
  364. bool cable_state)
  365. {
  366. return extcon_set_state_sync(edev, id, cable_state);
  367. }
  368. #endif /* __LINUX_EXTCON_H__ */