phy-cpcap-usb.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * Motorola CPCAP PMIC USB PHY driver
  3. * Copyright (C) 2017 Tony Lindgren <tony@atomide.com>
  4. *
  5. * Some parts based on earlier Motorola Linux kernel tree code in
  6. * board-mapphone-usb.c and cpcap-usb-det.c:
  7. * Copyright (C) 2007 - 2011 Motorola, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/atomic.h>
  19. #include <linux/clk.h>
  20. #include <linux/delay.h>
  21. #include <linux/err.h>
  22. #include <linux/io.h>
  23. #include <linux/module.h>
  24. #include <linux/of.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/iio/consumer.h>
  27. #include <linux/pinctrl/consumer.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/regmap.h>
  30. #include <linux/slab.h>
  31. #include <linux/gpio/consumer.h>
  32. #include <linux/mfd/motorola-cpcap.h>
  33. #include <linux/phy/omap_usb.h>
  34. #include <linux/phy/phy.h>
  35. #include <linux/regulator/consumer.h>
  36. #include <linux/usb/musb.h>
  37. /* CPCAP_REG_USBC1 register bits */
  38. #define CPCAP_BIT_IDPULSE BIT(15)
  39. #define CPCAP_BIT_ID100KPU BIT(14)
  40. #define CPCAP_BIT_IDPUCNTRL BIT(13)
  41. #define CPCAP_BIT_IDPU BIT(12)
  42. #define CPCAP_BIT_IDPD BIT(11)
  43. #define CPCAP_BIT_VBUSCHRGTMR3 BIT(10)
  44. #define CPCAP_BIT_VBUSCHRGTMR2 BIT(9)
  45. #define CPCAP_BIT_VBUSCHRGTMR1 BIT(8)
  46. #define CPCAP_BIT_VBUSCHRGTMR0 BIT(7)
  47. #define CPCAP_BIT_VBUSPU BIT(6)
  48. #define CPCAP_BIT_VBUSPD BIT(5)
  49. #define CPCAP_BIT_DMPD BIT(4)
  50. #define CPCAP_BIT_DPPD BIT(3)
  51. #define CPCAP_BIT_DM1K5PU BIT(2)
  52. #define CPCAP_BIT_DP1K5PU BIT(1)
  53. #define CPCAP_BIT_DP150KPU BIT(0)
  54. /* CPCAP_REG_USBC2 register bits */
  55. #define CPCAP_BIT_ZHSDRV1 BIT(15)
  56. #define CPCAP_BIT_ZHSDRV0 BIT(14)
  57. #define CPCAP_BIT_DPLLCLKREQ BIT(13)
  58. #define CPCAP_BIT_SE0CONN BIT(12)
  59. #define CPCAP_BIT_UARTTXTRI BIT(11)
  60. #define CPCAP_BIT_UARTSWAP BIT(10)
  61. #define CPCAP_BIT_UARTMUX1 BIT(9)
  62. #define CPCAP_BIT_UARTMUX0 BIT(8)
  63. #define CPCAP_BIT_ULPISTPLOW BIT(7)
  64. #define CPCAP_BIT_TXENPOL BIT(6)
  65. #define CPCAP_BIT_USBXCVREN BIT(5)
  66. #define CPCAP_BIT_USBCNTRL BIT(4)
  67. #define CPCAP_BIT_USBSUSPEND BIT(3)
  68. #define CPCAP_BIT_EMUMODE2 BIT(2)
  69. #define CPCAP_BIT_EMUMODE1 BIT(1)
  70. #define CPCAP_BIT_EMUMODE0 BIT(0)
  71. /* CPCAP_REG_USBC3 register bits */
  72. #define CPCAP_BIT_SPARE_898_15 BIT(15)
  73. #define CPCAP_BIT_IHSTX03 BIT(14)
  74. #define CPCAP_BIT_IHSTX02 BIT(13)
  75. #define CPCAP_BIT_IHSTX01 BIT(12)
  76. #define CPCAP_BIT_IHSTX0 BIT(11)
  77. #define CPCAP_BIT_IDPU_SPI BIT(10)
  78. #define CPCAP_BIT_UNUSED_898_9 BIT(9)
  79. #define CPCAP_BIT_VBUSSTBY_EN BIT(8)
  80. #define CPCAP_BIT_VBUSEN_SPI BIT(7)
  81. #define CPCAP_BIT_VBUSPU_SPI BIT(6)
  82. #define CPCAP_BIT_VBUSPD_SPI BIT(5)
  83. #define CPCAP_BIT_DMPD_SPI BIT(4)
  84. #define CPCAP_BIT_DPPD_SPI BIT(3)
  85. #define CPCAP_BIT_SUSPEND_SPI BIT(2)
  86. #define CPCAP_BIT_PU_SPI BIT(1)
  87. #define CPCAP_BIT_ULPI_SPI_SEL BIT(0)
  88. struct cpcap_usb_ints_state {
  89. bool id_ground;
  90. bool id_float;
  91. bool chrg_det;
  92. bool rvrs_chrg;
  93. bool vbusov;
  94. bool chrg_se1b;
  95. bool se0conn;
  96. bool rvrs_mode;
  97. bool chrgcurr1;
  98. bool vbusvld;
  99. bool sessvld;
  100. bool sessend;
  101. bool se1;
  102. bool battdetb;
  103. bool dm;
  104. bool dp;
  105. };
  106. enum cpcap_gpio_mode {
  107. CPCAP_DM_DP,
  108. CPCAP_MDM_RX_TX,
  109. CPCAP_UNKNOWN,
  110. CPCAP_OTG_DM_DP,
  111. };
  112. struct cpcap_phy_ddata {
  113. struct regmap *reg;
  114. struct device *dev;
  115. struct clk *refclk;
  116. struct usb_phy phy;
  117. struct delayed_work detect_work;
  118. struct pinctrl *pins;
  119. struct pinctrl_state *pins_ulpi;
  120. struct pinctrl_state *pins_utmi;
  121. struct pinctrl_state *pins_uart;
  122. struct gpio_desc *gpio[2];
  123. struct iio_channel *vbus;
  124. struct iio_channel *id;
  125. struct regulator *vusb;
  126. atomic_t active;
  127. };
  128. static bool cpcap_usb_vbus_valid(struct cpcap_phy_ddata *ddata)
  129. {
  130. int error, value = 0;
  131. error = iio_read_channel_processed(ddata->vbus, &value);
  132. if (error >= 0)
  133. return value > 3900 ? true : false;
  134. dev_err(ddata->dev, "error reading VBUS: %i\n", error);
  135. return false;
  136. }
  137. static int cpcap_usb_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
  138. {
  139. otg->host = host;
  140. if (!host)
  141. otg->state = OTG_STATE_UNDEFINED;
  142. return 0;
  143. }
  144. static int cpcap_usb_phy_set_peripheral(struct usb_otg *otg,
  145. struct usb_gadget *gadget)
  146. {
  147. otg->gadget = gadget;
  148. if (!gadget)
  149. otg->state = OTG_STATE_UNDEFINED;
  150. return 0;
  151. }
  152. static const struct phy_ops ops = {
  153. .owner = THIS_MODULE,
  154. };
  155. static int cpcap_phy_get_ints_state(struct cpcap_phy_ddata *ddata,
  156. struct cpcap_usb_ints_state *s)
  157. {
  158. int val, error;
  159. error = regmap_read(ddata->reg, CPCAP_REG_INTS1, &val);
  160. if (error)
  161. return error;
  162. s->id_ground = val & BIT(15);
  163. s->id_float = val & BIT(14);
  164. s->vbusov = val & BIT(11);
  165. error = regmap_read(ddata->reg, CPCAP_REG_INTS2, &val);
  166. if (error)
  167. return error;
  168. s->vbusvld = val & BIT(3);
  169. s->sessvld = val & BIT(2);
  170. s->sessend = val & BIT(1);
  171. s->se1 = val & BIT(0);
  172. error = regmap_read(ddata->reg, CPCAP_REG_INTS4, &val);
  173. if (error)
  174. return error;
  175. s->dm = val & BIT(1);
  176. s->dp = val & BIT(0);
  177. return 0;
  178. }
  179. static int cpcap_usb_set_uart_mode(struct cpcap_phy_ddata *ddata);
  180. static int cpcap_usb_set_usb_mode(struct cpcap_phy_ddata *ddata);
  181. static void cpcap_usb_detect(struct work_struct *work)
  182. {
  183. struct cpcap_phy_ddata *ddata;
  184. struct cpcap_usb_ints_state s;
  185. bool vbus = false;
  186. int error;
  187. ddata = container_of(work, struct cpcap_phy_ddata, detect_work.work);
  188. error = cpcap_phy_get_ints_state(ddata, &s);
  189. if (error)
  190. return;
  191. if (s.id_ground) {
  192. dev_dbg(ddata->dev, "id ground, USB host mode\n");
  193. error = cpcap_usb_set_usb_mode(ddata);
  194. if (error)
  195. goto out_err;
  196. error = musb_mailbox(MUSB_ID_GROUND);
  197. if (error)
  198. goto out_err;
  199. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3,
  200. CPCAP_BIT_VBUSSTBY_EN,
  201. CPCAP_BIT_VBUSSTBY_EN);
  202. if (error)
  203. goto out_err;
  204. return;
  205. }
  206. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3,
  207. CPCAP_BIT_VBUSSTBY_EN, 0);
  208. if (error)
  209. goto out_err;
  210. vbus = cpcap_usb_vbus_valid(ddata);
  211. if (vbus) {
  212. /* Are we connected to a docking station with vbus? */
  213. if (s.id_ground) {
  214. dev_dbg(ddata->dev, "connected to a dock\n");
  215. /* No VBUS needed with docks */
  216. error = cpcap_usb_set_usb_mode(ddata);
  217. if (error)
  218. goto out_err;
  219. error = musb_mailbox(MUSB_ID_GROUND);
  220. if (error)
  221. goto out_err;
  222. return;
  223. }
  224. /* Otherwise assume we're connected to a USB host */
  225. dev_dbg(ddata->dev, "connected to USB host\n");
  226. error = cpcap_usb_set_usb_mode(ddata);
  227. if (error)
  228. goto out_err;
  229. error = musb_mailbox(MUSB_VBUS_VALID);
  230. if (error)
  231. goto out_err;
  232. return;
  233. }
  234. /* Default to debug UART mode */
  235. error = cpcap_usb_set_uart_mode(ddata);
  236. if (error)
  237. goto out_err;
  238. error = musb_mailbox(MUSB_VBUS_OFF);
  239. if (error)
  240. goto out_err;
  241. dev_dbg(ddata->dev, "set UART mode\n");
  242. return;
  243. out_err:
  244. dev_err(ddata->dev, "error setting cable state: %i\n", error);
  245. }
  246. static irqreturn_t cpcap_phy_irq_thread(int irq, void *data)
  247. {
  248. struct cpcap_phy_ddata *ddata = data;
  249. if (!atomic_read(&ddata->active))
  250. return IRQ_NONE;
  251. schedule_delayed_work(&ddata->detect_work, msecs_to_jiffies(1));
  252. return IRQ_HANDLED;
  253. }
  254. static int cpcap_usb_init_irq(struct platform_device *pdev,
  255. struct cpcap_phy_ddata *ddata,
  256. const char *name)
  257. {
  258. int irq, error;
  259. irq = platform_get_irq_byname(pdev, name);
  260. if (irq < 0)
  261. return -ENODEV;
  262. error = devm_request_threaded_irq(ddata->dev, irq, NULL,
  263. cpcap_phy_irq_thread,
  264. IRQF_SHARED,
  265. name, ddata);
  266. if (error) {
  267. dev_err(ddata->dev, "could not get irq %s: %i\n",
  268. name, error);
  269. return error;
  270. }
  271. return 0;
  272. }
  273. static const char * const cpcap_phy_irqs[] = {
  274. /* REG_INT_0 */
  275. "id_ground", "id_float",
  276. /* REG_INT1 */
  277. "se0conn", "vbusvld", "sessvld", "sessend", "se1",
  278. /* REG_INT_3 */
  279. "dm", "dp",
  280. };
  281. static int cpcap_usb_init_interrupts(struct platform_device *pdev,
  282. struct cpcap_phy_ddata *ddata)
  283. {
  284. int i, error;
  285. for (i = 0; i < ARRAY_SIZE(cpcap_phy_irqs); i++) {
  286. error = cpcap_usb_init_irq(pdev, ddata, cpcap_phy_irqs[i]);
  287. if (error)
  288. return error;
  289. }
  290. return 0;
  291. }
  292. /*
  293. * Optional pins and modes. At least Motorola mapphone devices
  294. * are using two GPIOs and dynamic pinctrl to multiplex PHY pins
  295. * to UART, ULPI or UTMI mode.
  296. */
  297. static int cpcap_usb_gpio_set_mode(struct cpcap_phy_ddata *ddata,
  298. enum cpcap_gpio_mode mode)
  299. {
  300. if (!ddata->gpio[0] || !ddata->gpio[1])
  301. return 0;
  302. gpiod_set_value(ddata->gpio[0], mode & 1);
  303. gpiod_set_value(ddata->gpio[1], mode >> 1);
  304. return 0;
  305. }
  306. static int cpcap_usb_set_uart_mode(struct cpcap_phy_ddata *ddata)
  307. {
  308. int error;
  309. error = cpcap_usb_gpio_set_mode(ddata, CPCAP_DM_DP);
  310. if (error)
  311. goto out_err;
  312. if (ddata->pins_uart) {
  313. error = pinctrl_select_state(ddata->pins, ddata->pins_uart);
  314. if (error)
  315. goto out_err;
  316. }
  317. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC1,
  318. CPCAP_BIT_VBUSPD,
  319. CPCAP_BIT_VBUSPD);
  320. if (error)
  321. goto out_err;
  322. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC2,
  323. 0xffff, CPCAP_BIT_UARTMUX0 |
  324. CPCAP_BIT_EMUMODE0);
  325. if (error)
  326. goto out_err;
  327. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3, 0x7fff,
  328. CPCAP_BIT_IDPU_SPI);
  329. if (error)
  330. goto out_err;
  331. return 0;
  332. out_err:
  333. dev_err(ddata->dev, "%s failed with %i\n", __func__, error);
  334. return error;
  335. }
  336. static int cpcap_usb_set_usb_mode(struct cpcap_phy_ddata *ddata)
  337. {
  338. int error;
  339. error = cpcap_usb_gpio_set_mode(ddata, CPCAP_OTG_DM_DP);
  340. if (error)
  341. return error;
  342. if (ddata->pins_utmi) {
  343. error = pinctrl_select_state(ddata->pins, ddata->pins_utmi);
  344. if (error) {
  345. dev_err(ddata->dev, "could not set usb mode: %i\n",
  346. error);
  347. return error;
  348. }
  349. }
  350. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC1,
  351. CPCAP_BIT_VBUSPD, 0);
  352. if (error)
  353. goto out_err;
  354. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC2,
  355. CPCAP_BIT_USBXCVREN,
  356. CPCAP_BIT_USBXCVREN);
  357. if (error)
  358. goto out_err;
  359. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3,
  360. CPCAP_BIT_PU_SPI |
  361. CPCAP_BIT_DMPD_SPI |
  362. CPCAP_BIT_DPPD_SPI |
  363. CPCAP_BIT_SUSPEND_SPI |
  364. CPCAP_BIT_ULPI_SPI_SEL, 0);
  365. if (error)
  366. goto out_err;
  367. error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC2,
  368. CPCAP_BIT_USBXCVREN,
  369. CPCAP_BIT_USBXCVREN);
  370. if (error)
  371. goto out_err;
  372. return 0;
  373. out_err:
  374. dev_err(ddata->dev, "%s failed with %i\n", __func__, error);
  375. return error;
  376. }
  377. static int cpcap_usb_init_optional_pins(struct cpcap_phy_ddata *ddata)
  378. {
  379. ddata->pins = devm_pinctrl_get(ddata->dev);
  380. if (IS_ERR(ddata->pins)) {
  381. dev_info(ddata->dev, "default pins not configured: %ld\n",
  382. PTR_ERR(ddata->pins));
  383. ddata->pins = NULL;
  384. return 0;
  385. }
  386. ddata->pins_ulpi = pinctrl_lookup_state(ddata->pins, "ulpi");
  387. if (IS_ERR(ddata->pins_ulpi)) {
  388. dev_info(ddata->dev, "ulpi pins not configured\n");
  389. ddata->pins_ulpi = NULL;
  390. }
  391. ddata->pins_utmi = pinctrl_lookup_state(ddata->pins, "utmi");
  392. if (IS_ERR(ddata->pins_utmi)) {
  393. dev_info(ddata->dev, "utmi pins not configured\n");
  394. ddata->pins_utmi = NULL;
  395. }
  396. ddata->pins_uart = pinctrl_lookup_state(ddata->pins, "uart");
  397. if (IS_ERR(ddata->pins_uart)) {
  398. dev_info(ddata->dev, "uart pins not configured\n");
  399. ddata->pins_uart = NULL;
  400. }
  401. if (ddata->pins_uart)
  402. return pinctrl_select_state(ddata->pins, ddata->pins_uart);
  403. return 0;
  404. }
  405. static void cpcap_usb_init_optional_gpios(struct cpcap_phy_ddata *ddata)
  406. {
  407. int i;
  408. for (i = 0; i < 2; i++) {
  409. ddata->gpio[i] = devm_gpiod_get_index(ddata->dev, "mode",
  410. i, GPIOD_OUT_HIGH);
  411. if (IS_ERR(ddata->gpio[i])) {
  412. dev_info(ddata->dev, "no mode change GPIO%i: %li\n",
  413. i, PTR_ERR(ddata->gpio[i]));
  414. ddata->gpio[i] = NULL;
  415. }
  416. }
  417. }
  418. static int cpcap_usb_init_iio(struct cpcap_phy_ddata *ddata)
  419. {
  420. enum iio_chan_type type;
  421. int error;
  422. ddata->vbus = devm_iio_channel_get(ddata->dev, "vbus");
  423. if (IS_ERR(ddata->vbus)) {
  424. error = PTR_ERR(ddata->vbus);
  425. goto out_err;
  426. }
  427. if (!ddata->vbus->indio_dev) {
  428. error = -ENXIO;
  429. goto out_err;
  430. }
  431. error = iio_get_channel_type(ddata->vbus, &type);
  432. if (error < 0)
  433. goto out_err;
  434. if (type != IIO_VOLTAGE) {
  435. error = -EINVAL;
  436. goto out_err;
  437. }
  438. return 0;
  439. out_err:
  440. dev_err(ddata->dev, "could not initialize VBUS or ID IIO: %i\n",
  441. error);
  442. return error;
  443. }
  444. #ifdef CONFIG_OF
  445. static const struct of_device_id cpcap_usb_phy_id_table[] = {
  446. {
  447. .compatible = "motorola,cpcap-usb-phy",
  448. },
  449. {
  450. .compatible = "motorola,mapphone-cpcap-usb-phy",
  451. },
  452. {},
  453. };
  454. MODULE_DEVICE_TABLE(of, cpcap_usb_phy_id_table);
  455. #endif
  456. static int cpcap_usb_phy_probe(struct platform_device *pdev)
  457. {
  458. struct cpcap_phy_ddata *ddata;
  459. struct phy *generic_phy;
  460. struct phy_provider *phy_provider;
  461. struct usb_otg *otg;
  462. const struct of_device_id *of_id;
  463. int error;
  464. of_id = of_match_device(of_match_ptr(cpcap_usb_phy_id_table),
  465. &pdev->dev);
  466. if (!of_id)
  467. return -EINVAL;
  468. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  469. if (!ddata)
  470. return -ENOMEM;
  471. ddata->reg = dev_get_regmap(pdev->dev.parent, NULL);
  472. if (!ddata->reg)
  473. return -ENODEV;
  474. otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
  475. if (!otg)
  476. return -ENOMEM;
  477. ddata->dev = &pdev->dev;
  478. ddata->phy.dev = ddata->dev;
  479. ddata->phy.label = "cpcap_usb_phy";
  480. ddata->phy.otg = otg;
  481. ddata->phy.type = USB_PHY_TYPE_USB2;
  482. otg->set_host = cpcap_usb_phy_set_host;
  483. otg->set_peripheral = cpcap_usb_phy_set_peripheral;
  484. otg->usb_phy = &ddata->phy;
  485. INIT_DELAYED_WORK(&ddata->detect_work, cpcap_usb_detect);
  486. platform_set_drvdata(pdev, ddata);
  487. ddata->vusb = devm_regulator_get(&pdev->dev, "vusb");
  488. if (IS_ERR(ddata->vusb))
  489. return PTR_ERR(ddata->vusb);
  490. error = regulator_enable(ddata->vusb);
  491. if (error)
  492. return error;
  493. generic_phy = devm_phy_create(ddata->dev, NULL, &ops);
  494. if (IS_ERR(generic_phy)) {
  495. error = PTR_ERR(generic_phy);
  496. return PTR_ERR(generic_phy);
  497. }
  498. phy_set_drvdata(generic_phy, ddata);
  499. phy_provider = devm_of_phy_provider_register(ddata->dev,
  500. of_phy_simple_xlate);
  501. if (IS_ERR(phy_provider))
  502. return PTR_ERR(phy_provider);
  503. error = cpcap_usb_init_optional_pins(ddata);
  504. if (error)
  505. return error;
  506. cpcap_usb_init_optional_gpios(ddata);
  507. error = cpcap_usb_init_iio(ddata);
  508. if (error)
  509. return error;
  510. error = cpcap_usb_init_interrupts(pdev, ddata);
  511. if (error)
  512. return error;
  513. usb_add_phy_dev(&ddata->phy);
  514. atomic_set(&ddata->active, 1);
  515. schedule_delayed_work(&ddata->detect_work, msecs_to_jiffies(1));
  516. return 0;
  517. }
  518. static int cpcap_usb_phy_remove(struct platform_device *pdev)
  519. {
  520. struct cpcap_phy_ddata *ddata = platform_get_drvdata(pdev);
  521. int error;
  522. atomic_set(&ddata->active, 0);
  523. error = cpcap_usb_set_uart_mode(ddata);
  524. if (error)
  525. dev_err(ddata->dev, "could not set UART mode\n");
  526. error = musb_mailbox(MUSB_VBUS_OFF);
  527. if (error)
  528. dev_err(ddata->dev, "could not set mailbox\n");
  529. usb_remove_phy(&ddata->phy);
  530. cancel_delayed_work_sync(&ddata->detect_work);
  531. clk_unprepare(ddata->refclk);
  532. regulator_disable(ddata->vusb);
  533. return 0;
  534. }
  535. static struct platform_driver cpcap_usb_phy_driver = {
  536. .probe = cpcap_usb_phy_probe,
  537. .remove = cpcap_usb_phy_remove,
  538. .driver = {
  539. .name = "cpcap-usb-phy",
  540. .of_match_table = of_match_ptr(cpcap_usb_phy_id_table),
  541. },
  542. };
  543. module_platform_driver(cpcap_usb_phy_driver);
  544. MODULE_ALIAS("platform:cpcap_usb");
  545. MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
  546. MODULE_DESCRIPTION("CPCAP usb phy driver");
  547. MODULE_LICENSE("GPL v2");