extcon-usbc-tusb320.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * drivers/extcon/extcon-tusb320.c - TUSB320 extcon driver
  4. *
  5. * Copyright (C) 2020 National Instruments Corporation
  6. * Author: Michael Auchter <michael.auchter@ni.com>
  7. */
  8. #include <linux/bitfield.h>
  9. #include <linux/extcon-provider.h>
  10. #include <linux/i2c.h>
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/regmap.h>
  16. #include <linux/usb/typec.h>
  17. #include <linux/usb/typec_altmode.h>
  18. #include <linux/usb/role.h>
  19. #include <linux/irq.h>
  20. #define TUSB320_REG8 0x8
  21. #define TUSB320_REG8_CURRENT_MODE_ADVERTISE GENMASK(7, 6)
  22. #define TUSB320_REG8_CURRENT_MODE_ADVERTISE_USB 0x0
  23. #define TUSB320_REG8_CURRENT_MODE_ADVERTISE_15A 0x1
  24. #define TUSB320_REG8_CURRENT_MODE_ADVERTISE_30A 0x2
  25. #define TUSB320_REG8_CURRENT_MODE_DETECT GENMASK(5, 4)
  26. #define TUSB320_REG8_CURRENT_MODE_DETECT_DEF 0x0
  27. #define TUSB320_REG8_CURRENT_MODE_DETECT_MED 0x1
  28. #define TUSB320_REG8_CURRENT_MODE_DETECT_ACC 0x2
  29. #define TUSB320_REG8_CURRENT_MODE_DETECT_HI 0x3
  30. #define TUSB320_REG8_ACCESSORY_CONNECTED GENMASK(3, 1)
  31. #define TUSB320_REG8_ACCESSORY_CONNECTED_NONE 0x0
  32. #define TUSB320_REG8_ACCESSORY_CONNECTED_AUDIO 0x4
  33. #define TUSB320_REG8_ACCESSORY_CONNECTED_ACHRG 0x5
  34. #define TUSB320_REG8_ACCESSORY_CONNECTED_DBGDFP 0x6
  35. #define TUSB320_REG8_ACCESSORY_CONNECTED_DBGUFP 0x7
  36. #define TUSB320_REG8_ACTIVE_CABLE_DETECTION BIT(0)
  37. #define TUSB320_REG9 0x9
  38. #define TUSB320_REG9_ATTACHED_STATE GENMASK(7, 6)
  39. #define TUSB320_REG9_CABLE_DIRECTION BIT(5)
  40. #define TUSB320_REG9_INTERRUPT_STATUS BIT(4)
  41. #define TUSB320_REGA 0xa
  42. #define TUSB320L_REGA_DISABLE_TERM BIT(0)
  43. #define TUSB320_REGA_I2C_SOFT_RESET BIT(3)
  44. #define TUSB320_REGA_MODE_SELECT_SHIFT 4
  45. #define TUSB320_REGA_MODE_SELECT_MASK 0x3
  46. #define TUSB320L_REGA0_REVISION 0xa0
  47. enum tusb320_attached_state {
  48. TUSB320_ATTACHED_STATE_NONE,
  49. TUSB320_ATTACHED_STATE_DFP,
  50. TUSB320_ATTACHED_STATE_UFP,
  51. TUSB320_ATTACHED_STATE_ACC,
  52. };
  53. enum tusb320_mode {
  54. TUSB320_MODE_PORT,
  55. TUSB320_MODE_UFP,
  56. TUSB320_MODE_DFP,
  57. TUSB320_MODE_DRP,
  58. };
  59. struct tusb320_priv;
  60. struct tusb320_ops {
  61. int (*set_mode)(struct tusb320_priv *priv, enum tusb320_mode mode);
  62. int (*get_revision)(struct tusb320_priv *priv, unsigned int *revision);
  63. };
  64. struct tusb320_priv {
  65. struct device *dev;
  66. struct regmap *regmap;
  67. struct extcon_dev *edev;
  68. struct tusb320_ops *ops;
  69. enum tusb320_attached_state state;
  70. struct typec_port *port;
  71. struct typec_capability cap;
  72. enum typec_port_type port_type;
  73. enum typec_pwr_opmode pwr_opmode;
  74. struct fwnode_handle *connector_fwnode;
  75. struct usb_role_switch *role_sw;
  76. };
  77. static const char * const tusb_attached_states[] = {
  78. [TUSB320_ATTACHED_STATE_NONE] = "not attached",
  79. [TUSB320_ATTACHED_STATE_DFP] = "downstream facing port",
  80. [TUSB320_ATTACHED_STATE_UFP] = "upstream facing port",
  81. [TUSB320_ATTACHED_STATE_ACC] = "accessory",
  82. };
  83. static const unsigned int tusb320_extcon_cable[] = {
  84. EXTCON_USB,
  85. EXTCON_USB_HOST,
  86. EXTCON_NONE,
  87. };
  88. static int tusb320_check_signature(struct tusb320_priv *priv)
  89. {
  90. static const char sig[] = { '\0', 'T', 'U', 'S', 'B', '3', '2', '0' };
  91. unsigned val;
  92. int i, ret;
  93. for (i = 0; i < sizeof(sig); i++) {
  94. ret = regmap_read(priv->regmap, sizeof(sig) - 1 - i, &val);
  95. if (ret < 0)
  96. return ret;
  97. if (val != sig[i]) {
  98. dev_err(priv->dev, "signature mismatch!\n");
  99. return -ENODEV;
  100. }
  101. }
  102. return 0;
  103. }
  104. static int tusb320_set_mode(struct tusb320_priv *priv, enum tusb320_mode mode)
  105. {
  106. int ret;
  107. /* Mode cannot be changed while cable is attached */
  108. if (priv->state != TUSB320_ATTACHED_STATE_NONE)
  109. return -EBUSY;
  110. /* Write mode */
  111. ret = regmap_write_bits(priv->regmap, TUSB320_REGA,
  112. TUSB320_REGA_MODE_SELECT_MASK << TUSB320_REGA_MODE_SELECT_SHIFT,
  113. mode << TUSB320_REGA_MODE_SELECT_SHIFT);
  114. if (ret) {
  115. dev_err(priv->dev, "failed to write mode: %d\n", ret);
  116. return ret;
  117. }
  118. return 0;
  119. }
  120. static int tusb320l_set_mode(struct tusb320_priv *priv, enum tusb320_mode mode)
  121. {
  122. int ret;
  123. /* Disable CC state machine */
  124. ret = regmap_write_bits(priv->regmap, TUSB320_REGA,
  125. TUSB320L_REGA_DISABLE_TERM, 1);
  126. if (ret) {
  127. dev_err(priv->dev,
  128. "failed to disable CC state machine: %d\n", ret);
  129. return ret;
  130. }
  131. /* Write mode */
  132. ret = regmap_write_bits(priv->regmap, TUSB320_REGA,
  133. TUSB320_REGA_MODE_SELECT_MASK << TUSB320_REGA_MODE_SELECT_SHIFT,
  134. mode << TUSB320_REGA_MODE_SELECT_SHIFT);
  135. if (ret) {
  136. dev_err(priv->dev, "failed to write mode: %d\n", ret);
  137. goto err;
  138. }
  139. msleep(5);
  140. err:
  141. /* Re-enable CC state machine */
  142. ret = regmap_write_bits(priv->regmap, TUSB320_REGA,
  143. TUSB320L_REGA_DISABLE_TERM, 0);
  144. if (ret)
  145. dev_err(priv->dev,
  146. "failed to re-enable CC state machine: %d\n", ret);
  147. return ret;
  148. }
  149. static int tusb320_reset(struct tusb320_priv *priv)
  150. {
  151. int ret;
  152. /* Set mode to default (follow PORT pin) */
  153. ret = priv->ops->set_mode(priv, TUSB320_MODE_PORT);
  154. if (ret && ret != -EBUSY) {
  155. dev_err(priv->dev,
  156. "failed to set mode to PORT: %d\n", ret);
  157. return ret;
  158. }
  159. /* Perform soft reset */
  160. ret = regmap_write_bits(priv->regmap, TUSB320_REGA,
  161. TUSB320_REGA_I2C_SOFT_RESET, 1);
  162. if (ret) {
  163. dev_err(priv->dev,
  164. "failed to write soft reset bit: %d\n", ret);
  165. return ret;
  166. }
  167. /* Wait for chip to go through reset */
  168. msleep(95);
  169. return 0;
  170. }
  171. static int tusb320l_get_revision(struct tusb320_priv *priv, unsigned int *revision)
  172. {
  173. return regmap_read(priv->regmap, TUSB320L_REGA0_REVISION, revision);
  174. }
  175. static struct tusb320_ops tusb320_ops = {
  176. .set_mode = tusb320_set_mode,
  177. };
  178. static struct tusb320_ops tusb320l_ops = {
  179. .set_mode = tusb320l_set_mode,
  180. .get_revision = tusb320l_get_revision,
  181. };
  182. static int tusb320_set_adv_pwr_mode(struct tusb320_priv *priv)
  183. {
  184. u8 mode;
  185. if (priv->pwr_opmode == TYPEC_PWR_MODE_USB)
  186. mode = TUSB320_REG8_CURRENT_MODE_ADVERTISE_USB;
  187. else if (priv->pwr_opmode == TYPEC_PWR_MODE_1_5A)
  188. mode = TUSB320_REG8_CURRENT_MODE_ADVERTISE_15A;
  189. else if (priv->pwr_opmode == TYPEC_PWR_MODE_3_0A)
  190. mode = TUSB320_REG8_CURRENT_MODE_ADVERTISE_30A;
  191. else /* No other mode is supported. */
  192. return -EINVAL;
  193. return regmap_write_bits(priv->regmap, TUSB320_REG8,
  194. TUSB320_REG8_CURRENT_MODE_ADVERTISE,
  195. FIELD_PREP(TUSB320_REG8_CURRENT_MODE_ADVERTISE,
  196. mode));
  197. }
  198. static int tusb320_port_type_set(struct typec_port *port,
  199. enum typec_port_type type)
  200. {
  201. struct tusb320_priv *priv = typec_get_drvdata(port);
  202. if (type == TYPEC_PORT_SRC)
  203. return priv->ops->set_mode(priv, TUSB320_MODE_DFP);
  204. else if (type == TYPEC_PORT_SNK)
  205. return priv->ops->set_mode(priv, TUSB320_MODE_UFP);
  206. else if (type == TYPEC_PORT_DRP)
  207. return priv->ops->set_mode(priv, TUSB320_MODE_DRP);
  208. else
  209. return priv->ops->set_mode(priv, TUSB320_MODE_PORT);
  210. }
  211. static const struct typec_operations tusb320_typec_ops = {
  212. .port_type_set = tusb320_port_type_set,
  213. };
  214. static void tusb320_extcon_irq_handler(struct tusb320_priv *priv, u8 reg)
  215. {
  216. int state, polarity;
  217. state = FIELD_GET(TUSB320_REG9_ATTACHED_STATE, reg);
  218. polarity = !!(reg & TUSB320_REG9_CABLE_DIRECTION);
  219. dev_dbg(priv->dev, "attached state: %s, polarity: %d\n",
  220. tusb_attached_states[state], polarity);
  221. extcon_set_state(priv->edev, EXTCON_USB,
  222. state == TUSB320_ATTACHED_STATE_UFP);
  223. extcon_set_state(priv->edev, EXTCON_USB_HOST,
  224. state == TUSB320_ATTACHED_STATE_DFP);
  225. extcon_set_property(priv->edev, EXTCON_USB,
  226. EXTCON_PROP_USB_TYPEC_POLARITY,
  227. (union extcon_property_value)polarity);
  228. extcon_set_property(priv->edev, EXTCON_USB_HOST,
  229. EXTCON_PROP_USB_TYPEC_POLARITY,
  230. (union extcon_property_value)polarity);
  231. extcon_sync(priv->edev, EXTCON_USB);
  232. extcon_sync(priv->edev, EXTCON_USB_HOST);
  233. priv->state = state;
  234. }
  235. static void tusb320_typec_irq_handler(struct tusb320_priv *priv, u8 reg9)
  236. {
  237. struct typec_port *port = priv->port;
  238. struct device *dev = priv->dev;
  239. int typec_mode;
  240. enum usb_role usb_role;
  241. enum typec_role pwr_role;
  242. enum typec_data_role data_role;
  243. u8 state, mode, accessory;
  244. int ret, reg8;
  245. bool ori;
  246. ret = regmap_read(priv->regmap, TUSB320_REG8, &reg8);
  247. if (ret) {
  248. dev_err(dev, "error during reg8 i2c read, ret=%d!\n", ret);
  249. return;
  250. }
  251. ori = reg9 & TUSB320_REG9_CABLE_DIRECTION;
  252. typec_set_orientation(port, ori ? TYPEC_ORIENTATION_REVERSE :
  253. TYPEC_ORIENTATION_NORMAL);
  254. state = FIELD_GET(TUSB320_REG9_ATTACHED_STATE, reg9);
  255. accessory = FIELD_GET(TUSB320_REG8_ACCESSORY_CONNECTED, reg8);
  256. switch (state) {
  257. case TUSB320_ATTACHED_STATE_DFP:
  258. typec_mode = TYPEC_MODE_USB2;
  259. usb_role = USB_ROLE_HOST;
  260. pwr_role = TYPEC_SOURCE;
  261. data_role = TYPEC_HOST;
  262. break;
  263. case TUSB320_ATTACHED_STATE_UFP:
  264. typec_mode = TYPEC_MODE_USB2;
  265. usb_role = USB_ROLE_DEVICE;
  266. pwr_role = TYPEC_SINK;
  267. data_role = TYPEC_DEVICE;
  268. break;
  269. case TUSB320_ATTACHED_STATE_ACC:
  270. /*
  271. * Accessory detected. For debug accessories, just make some
  272. * qualified guesses as to the role for lack of a better option.
  273. */
  274. if (accessory == TUSB320_REG8_ACCESSORY_CONNECTED_AUDIO ||
  275. accessory == TUSB320_REG8_ACCESSORY_CONNECTED_ACHRG) {
  276. typec_mode = TYPEC_MODE_AUDIO;
  277. usb_role = USB_ROLE_NONE;
  278. pwr_role = TYPEC_SINK;
  279. data_role = TYPEC_DEVICE;
  280. break;
  281. } else if (accessory ==
  282. TUSB320_REG8_ACCESSORY_CONNECTED_DBGDFP) {
  283. typec_mode = TYPEC_MODE_DEBUG;
  284. pwr_role = TYPEC_SOURCE;
  285. usb_role = USB_ROLE_HOST;
  286. data_role = TYPEC_HOST;
  287. break;
  288. } else if (accessory ==
  289. TUSB320_REG8_ACCESSORY_CONNECTED_DBGUFP) {
  290. typec_mode = TYPEC_MODE_DEBUG;
  291. pwr_role = TYPEC_SINK;
  292. usb_role = USB_ROLE_DEVICE;
  293. data_role = TYPEC_DEVICE;
  294. break;
  295. }
  296. dev_warn(priv->dev, "unexpected ACCESSORY_CONNECTED state %d\n",
  297. accessory);
  298. fallthrough;
  299. default:
  300. typec_mode = TYPEC_MODE_USB2;
  301. usb_role = USB_ROLE_NONE;
  302. pwr_role = TYPEC_SINK;
  303. data_role = TYPEC_DEVICE;
  304. break;
  305. }
  306. typec_set_vconn_role(port, pwr_role);
  307. typec_set_pwr_role(port, pwr_role);
  308. typec_set_data_role(port, data_role);
  309. typec_set_mode(port, typec_mode);
  310. usb_role_switch_set_role(priv->role_sw, usb_role);
  311. mode = FIELD_GET(TUSB320_REG8_CURRENT_MODE_DETECT, reg8);
  312. if (mode == TUSB320_REG8_CURRENT_MODE_DETECT_DEF)
  313. typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);
  314. else if (mode == TUSB320_REG8_CURRENT_MODE_DETECT_MED)
  315. typec_set_pwr_opmode(port, TYPEC_PWR_MODE_1_5A);
  316. else if (mode == TUSB320_REG8_CURRENT_MODE_DETECT_HI)
  317. typec_set_pwr_opmode(port, TYPEC_PWR_MODE_3_0A);
  318. else /* Charge through accessory */
  319. typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);
  320. }
  321. static irqreturn_t tusb320_state_update_handler(struct tusb320_priv *priv,
  322. bool force_update)
  323. {
  324. unsigned int reg;
  325. if (regmap_read(priv->regmap, TUSB320_REG9, &reg)) {
  326. dev_err(priv->dev, "error during i2c read!\n");
  327. return IRQ_NONE;
  328. }
  329. if (!force_update && !(reg & TUSB320_REG9_INTERRUPT_STATUS))
  330. return IRQ_NONE;
  331. tusb320_extcon_irq_handler(priv, reg);
  332. /*
  333. * Type-C support is optional. Only call the Type-C handler if a
  334. * port had been registered previously.
  335. */
  336. if (priv->port)
  337. tusb320_typec_irq_handler(priv, reg);
  338. regmap_write(priv->regmap, TUSB320_REG9, reg);
  339. return IRQ_HANDLED;
  340. }
  341. static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)
  342. {
  343. struct tusb320_priv *priv = dev_id;
  344. return tusb320_state_update_handler(priv, false);
  345. }
  346. static const struct regmap_config tusb320_regmap_config = {
  347. .reg_bits = 8,
  348. .val_bits = 8,
  349. };
  350. static int tusb320_extcon_probe(struct tusb320_priv *priv)
  351. {
  352. int ret;
  353. priv->edev = devm_extcon_dev_allocate(priv->dev, tusb320_extcon_cable);
  354. if (IS_ERR(priv->edev)) {
  355. dev_err(priv->dev, "failed to allocate extcon device\n");
  356. return PTR_ERR(priv->edev);
  357. }
  358. ret = devm_extcon_dev_register(priv->dev, priv->edev);
  359. if (ret < 0) {
  360. dev_err(priv->dev, "failed to register extcon device\n");
  361. return ret;
  362. }
  363. extcon_set_property_capability(priv->edev, EXTCON_USB,
  364. EXTCON_PROP_USB_TYPEC_POLARITY);
  365. extcon_set_property_capability(priv->edev, EXTCON_USB_HOST,
  366. EXTCON_PROP_USB_TYPEC_POLARITY);
  367. return 0;
  368. }
  369. static int tusb320_typec_probe(struct i2c_client *client,
  370. struct tusb320_priv *priv)
  371. {
  372. struct fwnode_handle *connector;
  373. const char *cap_str;
  374. int ret;
  375. /* The Type-C connector is optional, for backward compatibility. */
  376. connector = device_get_named_child_node(&client->dev, "connector");
  377. if (!connector)
  378. return 0;
  379. /* Type-C connector found. */
  380. ret = typec_get_fw_cap(&priv->cap, connector);
  381. if (ret)
  382. goto err_put;
  383. priv->port_type = priv->cap.type;
  384. /* This goes into register 0x8 field CURRENT_MODE_ADVERTISE */
  385. ret = fwnode_property_read_string(connector, "typec-power-opmode", &cap_str);
  386. if (ret)
  387. goto err_put;
  388. ret = typec_find_pwr_opmode(cap_str);
  389. if (ret < 0)
  390. goto err_put;
  391. priv->pwr_opmode = ret;
  392. /* Initialize the hardware with the devicetree settings. */
  393. ret = tusb320_set_adv_pwr_mode(priv);
  394. if (ret)
  395. goto err_put;
  396. priv->cap.revision = USB_TYPEC_REV_1_1;
  397. priv->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO;
  398. priv->cap.accessory[1] = TYPEC_ACCESSORY_DEBUG;
  399. priv->cap.orientation_aware = true;
  400. priv->cap.driver_data = priv;
  401. priv->cap.ops = &tusb320_typec_ops;
  402. priv->cap.fwnode = connector;
  403. priv->port = typec_register_port(&client->dev, &priv->cap);
  404. if (IS_ERR(priv->port)) {
  405. ret = PTR_ERR(priv->port);
  406. goto err_put;
  407. }
  408. /* Find any optional USB role switch that needs reporting to */
  409. priv->role_sw = fwnode_usb_role_switch_get(connector);
  410. if (IS_ERR(priv->role_sw)) {
  411. ret = PTR_ERR(priv->role_sw);
  412. goto err_unreg;
  413. }
  414. priv->connector_fwnode = connector;
  415. return 0;
  416. err_unreg:
  417. typec_unregister_port(priv->port);
  418. err_put:
  419. fwnode_handle_put(connector);
  420. return ret;
  421. }
  422. static void tusb320_typec_remove(struct tusb320_priv *priv)
  423. {
  424. usb_role_switch_put(priv->role_sw);
  425. typec_unregister_port(priv->port);
  426. fwnode_handle_put(priv->connector_fwnode);
  427. }
  428. static int tusb320_probe(struct i2c_client *client)
  429. {
  430. struct tusb320_priv *priv;
  431. const void *match_data;
  432. unsigned int revision;
  433. int ret;
  434. u32 irq_trigger_type = IRQF_TRIGGER_FALLING;
  435. struct irq_data *irq_d;
  436. priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
  437. if (!priv)
  438. return -ENOMEM;
  439. priv->dev = &client->dev;
  440. i2c_set_clientdata(client, priv);
  441. priv->regmap = devm_regmap_init_i2c(client, &tusb320_regmap_config);
  442. if (IS_ERR(priv->regmap))
  443. return PTR_ERR(priv->regmap);
  444. ret = tusb320_check_signature(priv);
  445. if (ret)
  446. return ret;
  447. match_data = device_get_match_data(&client->dev);
  448. if (!match_data)
  449. return -EINVAL;
  450. priv->ops = (struct tusb320_ops*)match_data;
  451. if (priv->ops->get_revision) {
  452. ret = priv->ops->get_revision(priv, &revision);
  453. if (ret)
  454. dev_warn(priv->dev,
  455. "failed to read revision register: %d\n", ret);
  456. else
  457. dev_info(priv->dev, "chip revision %d\n", revision);
  458. }
  459. ret = tusb320_extcon_probe(priv);
  460. if (ret)
  461. return ret;
  462. ret = tusb320_typec_probe(client, priv);
  463. if (ret)
  464. return ret;
  465. /* update initial state */
  466. tusb320_state_update_handler(priv, true);
  467. /* Reset chip to its default state */
  468. ret = tusb320_reset(priv);
  469. if (ret)
  470. dev_warn(priv->dev, "failed to reset chip: %d\n", ret);
  471. else
  472. /*
  473. * State and polarity might change after a reset, so update
  474. * them again and make sure the interrupt status bit is cleared.
  475. */
  476. tusb320_state_update_handler(priv, true);
  477. irq_d = irq_get_irq_data(client->irq);
  478. if (irq_d)
  479. irq_trigger_type = irqd_get_trigger_type(irq_d);
  480. ret = devm_request_threaded_irq(priv->dev, client->irq, NULL,
  481. tusb320_irq_handler,
  482. IRQF_ONESHOT | irq_trigger_type,
  483. client->name, priv);
  484. if (ret)
  485. tusb320_typec_remove(priv);
  486. return ret;
  487. }
  488. static void tusb320_remove(struct i2c_client *client)
  489. {
  490. struct tusb320_priv *priv = i2c_get_clientdata(client);
  491. tusb320_typec_remove(priv);
  492. }
  493. static const struct of_device_id tusb320_extcon_dt_match[] = {
  494. { .compatible = "ti,tusb320", .data = &tusb320_ops, },
  495. { .compatible = "ti,tusb320l", .data = &tusb320l_ops, },
  496. { }
  497. };
  498. MODULE_DEVICE_TABLE(of, tusb320_extcon_dt_match);
  499. static struct i2c_driver tusb320_extcon_driver = {
  500. .probe = tusb320_probe,
  501. .remove = tusb320_remove,
  502. .driver = {
  503. .name = "extcon-tusb320",
  504. .of_match_table = tusb320_extcon_dt_match,
  505. },
  506. };
  507. static int __init tusb320_init(void)
  508. {
  509. return i2c_add_driver(&tusb320_extcon_driver);
  510. }
  511. subsys_initcall(tusb320_init);
  512. static void __exit tusb320_exit(void)
  513. {
  514. i2c_del_driver(&tusb320_extcon_driver);
  515. }
  516. module_exit(tusb320_exit);
  517. MODULE_AUTHOR("Michael Auchter <michael.auchter@ni.com>");
  518. MODULE_DESCRIPTION("TI TUSB320 extcon driver");
  519. MODULE_LICENSE("GPL v2");