phy-tusb1210.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * tusb1210.c - TUSB1210 USB ULPI PHY driver
  4. *
  5. * Copyright (C) 2015 Intel Corporation
  6. *
  7. * Author: Heikki Krogerus <[email protected]>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/bitfield.h>
  11. #include <linux/delay.h>
  12. #include <linux/ulpi/driver.h>
  13. #include <linux/ulpi/regs.h>
  14. #include <linux/gpio/consumer.h>
  15. #include <linux/phy/ulpi_phy.h>
  16. #include <linux/power_supply.h>
  17. #include <linux/workqueue.h>
  18. #define TUSB1211_POWER_CONTROL 0x3d
  19. #define TUSB1211_POWER_CONTROL_SET 0x3e
  20. #define TUSB1211_POWER_CONTROL_CLEAR 0x3f
  21. #define TUSB1211_POWER_CONTROL_SW_CONTROL BIT(0)
  22. #define TUSB1211_POWER_CONTROL_DET_COMP BIT(1)
  23. #define TUSB1211_POWER_CONTROL_DP_VSRC_EN BIT(6)
  24. #define TUSB1210_VENDOR_SPECIFIC2 0x80
  25. #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK GENMASK(3, 0)
  26. #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK GENMASK(5, 4)
  27. #define TUSB1210_VENDOR_SPECIFIC2_DP_MASK BIT(6)
  28. #define TUSB1211_VENDOR_SPECIFIC3 0x85
  29. #define TUSB1211_VENDOR_SPECIFIC3_SET 0x86
  30. #define TUSB1211_VENDOR_SPECIFIC3_CLEAR 0x87
  31. #define TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET BIT(4)
  32. #define TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN BIT(6)
  33. #define TUSB1210_RESET_TIME_MS 50
  34. #define TUSB1210_CHG_DET_MAX_RETRIES 5
  35. /* TUSB1210 charger detection work states */
  36. enum tusb1210_chg_det_state {
  37. TUSB1210_CHG_DET_CONNECTING,
  38. TUSB1210_CHG_DET_START_DET,
  39. TUSB1210_CHG_DET_READ_DET,
  40. TUSB1210_CHG_DET_FINISH_DET,
  41. TUSB1210_CHG_DET_CONNECTED,
  42. TUSB1210_CHG_DET_DISCONNECTING,
  43. TUSB1210_CHG_DET_DISCONNECTING_DONE,
  44. TUSB1210_CHG_DET_DISCONNECTED,
  45. };
  46. struct tusb1210 {
  47. struct ulpi *ulpi;
  48. struct phy *phy;
  49. struct gpio_desc *gpio_reset;
  50. struct gpio_desc *gpio_cs;
  51. u8 otg_ctrl;
  52. u8 vendor_specific2;
  53. #ifdef CONFIG_POWER_SUPPLY
  54. enum power_supply_usb_type chg_type;
  55. enum tusb1210_chg_det_state chg_det_state;
  56. int chg_det_retries;
  57. struct delayed_work chg_det_work;
  58. struct notifier_block psy_nb;
  59. struct power_supply *psy;
  60. struct power_supply *charger;
  61. #endif
  62. };
  63. static int tusb1210_ulpi_write(struct tusb1210 *tusb, u8 reg, u8 val)
  64. {
  65. int ret;
  66. ret = ulpi_write(tusb->ulpi, reg, val);
  67. if (ret)
  68. dev_err(&tusb->ulpi->dev, "error %d writing val 0x%02x to reg 0x%02x\n",
  69. ret, val, reg);
  70. return ret;
  71. }
  72. static int tusb1210_ulpi_read(struct tusb1210 *tusb, u8 reg, u8 *val)
  73. {
  74. int ret;
  75. ret = ulpi_read(tusb->ulpi, reg);
  76. if (ret >= 0) {
  77. *val = ret;
  78. ret = 0;
  79. } else {
  80. dev_err(&tusb->ulpi->dev, "error %d reading reg 0x%02x\n", ret, reg);
  81. }
  82. return ret;
  83. }
  84. static int tusb1210_power_on(struct phy *phy)
  85. {
  86. struct tusb1210 *tusb = phy_get_drvdata(phy);
  87. gpiod_set_value_cansleep(tusb->gpio_reset, 1);
  88. gpiod_set_value_cansleep(tusb->gpio_cs, 1);
  89. msleep(TUSB1210_RESET_TIME_MS);
  90. /* Restore the optional eye diagram optimization value */
  91. tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, tusb->vendor_specific2);
  92. return 0;
  93. }
  94. static int tusb1210_power_off(struct phy *phy)
  95. {
  96. struct tusb1210 *tusb = phy_get_drvdata(phy);
  97. gpiod_set_value_cansleep(tusb->gpio_reset, 0);
  98. gpiod_set_value_cansleep(tusb->gpio_cs, 0);
  99. return 0;
  100. }
  101. static int tusb1210_set_mode(struct phy *phy, enum phy_mode mode, int submode)
  102. {
  103. struct tusb1210 *tusb = phy_get_drvdata(phy);
  104. int ret;
  105. u8 reg;
  106. ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &reg);
  107. if (ret < 0)
  108. return ret;
  109. switch (mode) {
  110. case PHY_MODE_USB_HOST:
  111. reg |= (ULPI_OTG_CTRL_DRVVBUS_EXT
  112. | ULPI_OTG_CTRL_ID_PULLUP
  113. | ULPI_OTG_CTRL_DP_PULLDOWN
  114. | ULPI_OTG_CTRL_DM_PULLDOWN);
  115. tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
  116. reg |= ULPI_OTG_CTRL_DRVVBUS;
  117. break;
  118. case PHY_MODE_USB_DEVICE:
  119. reg &= ~(ULPI_OTG_CTRL_DRVVBUS
  120. | ULPI_OTG_CTRL_DP_PULLDOWN
  121. | ULPI_OTG_CTRL_DM_PULLDOWN);
  122. tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
  123. reg &= ~ULPI_OTG_CTRL_DRVVBUS_EXT;
  124. break;
  125. default:
  126. /* nothing */
  127. return 0;
  128. }
  129. tusb->otg_ctrl = reg;
  130. return tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
  131. }
  132. #ifdef CONFIG_POWER_SUPPLY
  133. static const char * const tusb1210_chg_det_states[] = {
  134. "CHG_DET_CONNECTING",
  135. "CHG_DET_START_DET",
  136. "CHG_DET_READ_DET",
  137. "CHG_DET_FINISH_DET",
  138. "CHG_DET_CONNECTED",
  139. "CHG_DET_DISCONNECTING",
  140. "CHG_DET_DISCONNECTING_DONE",
  141. "CHG_DET_DISCONNECTED",
  142. };
  143. static void tusb1210_reset(struct tusb1210 *tusb)
  144. {
  145. gpiod_set_value_cansleep(tusb->gpio_reset, 0);
  146. usleep_range(200, 500);
  147. gpiod_set_value_cansleep(tusb->gpio_reset, 1);
  148. }
  149. static void tusb1210_chg_det_set_type(struct tusb1210 *tusb,
  150. enum power_supply_usb_type type)
  151. {
  152. dev_dbg(&tusb->ulpi->dev, "charger type: %d\n", type);
  153. tusb->chg_type = type;
  154. tusb->chg_det_retries = 0;
  155. power_supply_changed(tusb->psy);
  156. }
  157. static void tusb1210_chg_det_set_state(struct tusb1210 *tusb,
  158. enum tusb1210_chg_det_state new_state,
  159. int delay_ms)
  160. {
  161. if (delay_ms)
  162. dev_dbg(&tusb->ulpi->dev, "chg_det new state %s in %d ms\n",
  163. tusb1210_chg_det_states[new_state], delay_ms);
  164. tusb->chg_det_state = new_state;
  165. mod_delayed_work(system_long_wq, &tusb->chg_det_work,
  166. msecs_to_jiffies(delay_ms));
  167. }
  168. static void tusb1210_chg_det_handle_ulpi_error(struct tusb1210 *tusb)
  169. {
  170. tusb1210_reset(tusb);
  171. if (tusb->chg_det_retries < TUSB1210_CHG_DET_MAX_RETRIES) {
  172. tusb->chg_det_retries++;
  173. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET,
  174. TUSB1210_RESET_TIME_MS);
  175. } else {
  176. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET,
  177. TUSB1210_RESET_TIME_MS);
  178. }
  179. }
  180. /*
  181. * Boards using a TUSB121x for charger-detection have 3 power_supply class devs:
  182. *
  183. * tusb1211-charger-detect(1) -> charger -> fuel-gauge
  184. *
  185. * To determine if an USB charger is connected to the board, the online prop of
  186. * the charger psy needs to be read. Since the tusb1211-charger-detect psy is
  187. * the start of the supplier -> supplied-to chain, power_supply_am_i_supplied()
  188. * cannot be used here.
  189. *
  190. * Instead, below is a list of the power_supply names of known chargers for
  191. * these boards and the charger psy is looked up by name from this list.
  192. *
  193. * (1) modelling the external USB charger
  194. */
  195. static const char * const tusb1210_chargers[] = {
  196. "bq24190-charger",
  197. };
  198. static bool tusb1210_get_online(struct tusb1210 *tusb)
  199. {
  200. union power_supply_propval val;
  201. int i;
  202. for (i = 0; i < ARRAY_SIZE(tusb1210_chargers) && !tusb->charger; i++)
  203. tusb->charger = power_supply_get_by_name(tusb1210_chargers[i]);
  204. if (!tusb->charger)
  205. return false;
  206. if (power_supply_get_property(tusb->charger, POWER_SUPPLY_PROP_ONLINE, &val))
  207. return false;
  208. return val.intval;
  209. }
  210. static void tusb1210_chg_det_work(struct work_struct *work)
  211. {
  212. struct tusb1210 *tusb = container_of(work, struct tusb1210, chg_det_work.work);
  213. bool vbus_present = tusb1210_get_online(tusb);
  214. int ret;
  215. u8 val;
  216. dev_dbg(&tusb->ulpi->dev, "chg_det state %s vbus_present %d\n",
  217. tusb1210_chg_det_states[tusb->chg_det_state], vbus_present);
  218. switch (tusb->chg_det_state) {
  219. case TUSB1210_CHG_DET_CONNECTING:
  220. tusb->chg_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
  221. tusb->chg_det_retries = 0;
  222. /* Power on USB controller for ulpi_read()/_write() */
  223. ret = pm_runtime_resume_and_get(tusb->ulpi->dev.parent);
  224. if (ret < 0) {
  225. dev_err(&tusb->ulpi->dev, "error %d runtime-resuming\n", ret);
  226. /* Should never happen, skip charger detection */
  227. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
  228. return;
  229. }
  230. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET, 0);
  231. break;
  232. case TUSB1210_CHG_DET_START_DET:
  233. /*
  234. * Use the builtin charger detection FSM to keep things simple.
  235. * This only detects DCP / SDP. This is good enough for the few
  236. * boards which actually rely on the phy for charger detection.
  237. */
  238. mutex_lock(&tusb->phy->mutex);
  239. ret = tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_SET,
  240. TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET);
  241. mutex_unlock(&tusb->phy->mutex);
  242. if (ret) {
  243. tusb1210_chg_det_handle_ulpi_error(tusb);
  244. break;
  245. }
  246. /* Wait 400 ms for the charger detection FSM to finish */
  247. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_READ_DET, 400);
  248. break;
  249. case TUSB1210_CHG_DET_READ_DET:
  250. mutex_lock(&tusb->phy->mutex);
  251. ret = tusb1210_ulpi_read(tusb, TUSB1211_POWER_CONTROL, &val);
  252. mutex_unlock(&tusb->phy->mutex);
  253. if (ret) {
  254. tusb1210_chg_det_handle_ulpi_error(tusb);
  255. break;
  256. }
  257. if (val & TUSB1211_POWER_CONTROL_DET_COMP)
  258. tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_DCP);
  259. else
  260. tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_SDP);
  261. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET, 0);
  262. break;
  263. case TUSB1210_CHG_DET_FINISH_DET:
  264. mutex_lock(&tusb->phy->mutex);
  265. /* Set SW_CONTROL to stop the charger-det FSM */
  266. ret = tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_SET,
  267. TUSB1211_POWER_CONTROL_SW_CONTROL);
  268. /* Clear DP_VSRC_EN which may have been enabled by the charger-det FSM */
  269. ret |= tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_CLEAR,
  270. TUSB1211_POWER_CONTROL_DP_VSRC_EN);
  271. /* Clear CHGD_IDP_SRC_EN (may have been enabled by the charger-det FSM) */
  272. ret |= tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_CLEAR,
  273. TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN);
  274. /* If any of the above fails reset the phy */
  275. if (ret) {
  276. tusb1210_reset(tusb);
  277. msleep(TUSB1210_RESET_TIME_MS);
  278. }
  279. /* Restore phy-parameters and OTG_CTRL register */
  280. tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, tusb->otg_ctrl);
  281. tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2,
  282. tusb->vendor_specific2);
  283. mutex_unlock(&tusb->phy->mutex);
  284. pm_runtime_put(tusb->ulpi->dev.parent);
  285. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
  286. break;
  287. case TUSB1210_CHG_DET_CONNECTED:
  288. if (!vbus_present)
  289. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING, 0);
  290. break;
  291. case TUSB1210_CHG_DET_DISCONNECTING:
  292. /*
  293. * The phy seems to take approx. 600ms longer then the charger
  294. * chip (which is used to get vbus_present) to determine Vbus
  295. * session end. Wait 800ms to ensure the phy has detected and
  296. * signalled Vbus session end.
  297. */
  298. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING_DONE, 800);
  299. break;
  300. case TUSB1210_CHG_DET_DISCONNECTING_DONE:
  301. /*
  302. * The phy often stops reacting to ulpi_read()/_write requests
  303. * after a Vbus-session end. Reset it to work around this.
  304. */
  305. tusb1210_reset(tusb);
  306. tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_UNKNOWN);
  307. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTED, 0);
  308. break;
  309. case TUSB1210_CHG_DET_DISCONNECTED:
  310. if (vbus_present)
  311. tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTING, 0);
  312. break;
  313. }
  314. }
  315. static int tusb1210_psy_notifier(struct notifier_block *nb,
  316. unsigned long event, void *ptr)
  317. {
  318. struct tusb1210 *tusb = container_of(nb, struct tusb1210, psy_nb);
  319. struct power_supply *psy = ptr;
  320. if (psy != tusb->psy && psy->desc->type == POWER_SUPPLY_TYPE_USB)
  321. queue_delayed_work(system_long_wq, &tusb->chg_det_work, 0);
  322. return NOTIFY_OK;
  323. }
  324. static int tusb1210_psy_get_prop(struct power_supply *psy,
  325. enum power_supply_property psp,
  326. union power_supply_propval *val)
  327. {
  328. struct tusb1210 *tusb = power_supply_get_drvdata(psy);
  329. switch (psp) {
  330. case POWER_SUPPLY_PROP_ONLINE:
  331. val->intval = tusb1210_get_online(tusb);
  332. break;
  333. case POWER_SUPPLY_PROP_USB_TYPE:
  334. val->intval = tusb->chg_type;
  335. break;
  336. case POWER_SUPPLY_PROP_CURRENT_MAX:
  337. if (tusb->chg_type == POWER_SUPPLY_USB_TYPE_DCP)
  338. val->intval = 2000000;
  339. else
  340. val->intval = 500000;
  341. break;
  342. default:
  343. return -EINVAL;
  344. }
  345. return 0;
  346. }
  347. static const enum power_supply_usb_type tusb1210_psy_usb_types[] = {
  348. POWER_SUPPLY_USB_TYPE_SDP,
  349. POWER_SUPPLY_USB_TYPE_DCP,
  350. POWER_SUPPLY_USB_TYPE_UNKNOWN,
  351. };
  352. static const enum power_supply_property tusb1210_psy_props[] = {
  353. POWER_SUPPLY_PROP_ONLINE,
  354. POWER_SUPPLY_PROP_USB_TYPE,
  355. POWER_SUPPLY_PROP_CURRENT_MAX,
  356. };
  357. static const struct power_supply_desc tusb1210_psy_desc = {
  358. .name = "tusb1211-charger-detect",
  359. .type = POWER_SUPPLY_TYPE_USB,
  360. .usb_types = tusb1210_psy_usb_types,
  361. .num_usb_types = ARRAY_SIZE(tusb1210_psy_usb_types),
  362. .properties = tusb1210_psy_props,
  363. .num_properties = ARRAY_SIZE(tusb1210_psy_props),
  364. .get_property = tusb1210_psy_get_prop,
  365. };
  366. /* Setup charger detection if requested, on errors continue without chg-det */
  367. static void tusb1210_probe_charger_detect(struct tusb1210 *tusb)
  368. {
  369. struct power_supply_config psy_cfg = { .drv_data = tusb };
  370. struct device *dev = &tusb->ulpi->dev;
  371. int ret;
  372. if (!device_property_read_bool(dev->parent, "linux,phy_charger_detect"))
  373. return;
  374. if (tusb->ulpi->id.product != 0x1508) {
  375. dev_err(dev, "error charger detection is only supported on the TUSB1211\n");
  376. return;
  377. }
  378. ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &tusb->otg_ctrl);
  379. if (ret)
  380. return;
  381. tusb->psy = power_supply_register(dev, &tusb1210_psy_desc, &psy_cfg);
  382. if (IS_ERR(tusb->psy))
  383. return;
  384. /*
  385. * Delay initial run by 2 seconds to allow the charger driver,
  386. * which is used to determine vbus_present, to load.
  387. */
  388. tusb->chg_det_state = TUSB1210_CHG_DET_DISCONNECTED;
  389. INIT_DELAYED_WORK(&tusb->chg_det_work, tusb1210_chg_det_work);
  390. queue_delayed_work(system_long_wq, &tusb->chg_det_work, 2 * HZ);
  391. tusb->psy_nb.notifier_call = tusb1210_psy_notifier;
  392. power_supply_reg_notifier(&tusb->psy_nb);
  393. }
  394. static void tusb1210_remove_charger_detect(struct tusb1210 *tusb)
  395. {
  396. if (!IS_ERR_OR_NULL(tusb->psy)) {
  397. power_supply_unreg_notifier(&tusb->psy_nb);
  398. cancel_delayed_work_sync(&tusb->chg_det_work);
  399. power_supply_unregister(tusb->psy);
  400. }
  401. if (tusb->charger)
  402. power_supply_put(tusb->charger);
  403. }
  404. #else
  405. static void tusb1210_probe_charger_detect(struct tusb1210 *tusb) { }
  406. static void tusb1210_remove_charger_detect(struct tusb1210 *tusb) { }
  407. #endif
  408. static const struct phy_ops phy_ops = {
  409. .power_on = tusb1210_power_on,
  410. .power_off = tusb1210_power_off,
  411. .set_mode = tusb1210_set_mode,
  412. .owner = THIS_MODULE,
  413. };
  414. static int tusb1210_probe(struct ulpi *ulpi)
  415. {
  416. struct tusb1210 *tusb;
  417. u8 val, reg;
  418. int ret;
  419. tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
  420. if (!tusb)
  421. return -ENOMEM;
  422. tusb->ulpi = ulpi;
  423. tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset",
  424. GPIOD_OUT_LOW);
  425. if (IS_ERR(tusb->gpio_reset))
  426. return PTR_ERR(tusb->gpio_reset);
  427. gpiod_set_value_cansleep(tusb->gpio_reset, 1);
  428. tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs",
  429. GPIOD_OUT_LOW);
  430. if (IS_ERR(tusb->gpio_cs))
  431. return PTR_ERR(tusb->gpio_cs);
  432. gpiod_set_value_cansleep(tusb->gpio_cs, 1);
  433. /*
  434. * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
  435. * diagram optimization and DP/DM swap.
  436. */
  437. ret = tusb1210_ulpi_read(tusb, TUSB1210_VENDOR_SPECIFIC2, &reg);
  438. if (ret)
  439. return ret;
  440. /* High speed output drive strength configuration */
  441. if (!device_property_read_u8(&ulpi->dev, "ihstx", &val))
  442. u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK);
  443. /* High speed output impedance configuration */
  444. if (!device_property_read_u8(&ulpi->dev, "zhsdrv", &val))
  445. u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK);
  446. /* DP/DM swap control */
  447. if (!device_property_read_u8(&ulpi->dev, "datapolarity", &val))
  448. u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_DP_MASK);
  449. ret = tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, reg);
  450. if (ret)
  451. return ret;
  452. tusb->vendor_specific2 = reg;
  453. tusb1210_probe_charger_detect(tusb);
  454. tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
  455. if (IS_ERR(tusb->phy)) {
  456. ret = PTR_ERR(tusb->phy);
  457. goto err_remove_charger;
  458. }
  459. phy_set_drvdata(tusb->phy, tusb);
  460. ulpi_set_drvdata(ulpi, tusb);
  461. return 0;
  462. err_remove_charger:
  463. tusb1210_remove_charger_detect(tusb);
  464. return ret;
  465. }
  466. static void tusb1210_remove(struct ulpi *ulpi)
  467. {
  468. struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
  469. ulpi_phy_destroy(ulpi, tusb->phy);
  470. tusb1210_remove_charger_detect(tusb);
  471. }
  472. #define TI_VENDOR_ID 0x0451
  473. static const struct ulpi_device_id tusb1210_ulpi_id[] = {
  474. { TI_VENDOR_ID, 0x1507, }, /* TUSB1210 */
  475. { TI_VENDOR_ID, 0x1508, }, /* TUSB1211 */
  476. { },
  477. };
  478. MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
  479. static struct ulpi_driver tusb1210_driver = {
  480. .id_table = tusb1210_ulpi_id,
  481. .probe = tusb1210_probe,
  482. .remove = tusb1210_remove,
  483. .driver = {
  484. .name = "tusb1210",
  485. .owner = THIS_MODULE,
  486. },
  487. };
  488. module_ulpi_driver(tusb1210_driver);
  489. MODULE_AUTHOR("Intel Corporation");
  490. MODULE_LICENSE("GPL v2");
  491. MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");