phy-sun4i-usb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Allwinner sun4i USB phy driver
  3. *
  4. * Copyright (C) 2014-2015 Hans de Goede <hdegoede@redhat.com>
  5. *
  6. * Based on code from
  7. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  8. *
  9. * Modelled after: Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY driver
  10. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  11. * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. */
  23. #include <linux/clk.h>
  24. #include <linux/delay.h>
  25. #include <linux/err.h>
  26. #include <linux/extcon.h>
  27. #include <linux/io.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/mutex.h>
  32. #include <linux/of.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_gpio.h>
  35. #include <linux/phy/phy.h>
  36. #include <linux/phy/phy-sun4i-usb.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/regulator/consumer.h>
  39. #include <linux/reset.h>
  40. #include <linux/workqueue.h>
  41. #define REG_ISCR 0x00
  42. #define REG_PHYCTL 0x04
  43. #define REG_PHYBIST 0x08
  44. #define REG_PHYTUNE 0x0c
  45. #define PHYCTL_DATA BIT(7)
  46. #define SUNXI_AHB_ICHR8_EN BIT(10)
  47. #define SUNXI_AHB_INCR4_BURST_EN BIT(9)
  48. #define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
  49. #define SUNXI_ULPI_BYPASS_EN BIT(0)
  50. /* ISCR, Interface Status and Control bits */
  51. #define ISCR_ID_PULLUP_EN (1 << 17)
  52. #define ISCR_DPDM_PULLUP_EN (1 << 16)
  53. /* sunxi has the phy id/vbus pins not connected, so we use the force bits */
  54. #define ISCR_FORCE_ID_MASK (3 << 14)
  55. #define ISCR_FORCE_ID_LOW (2 << 14)
  56. #define ISCR_FORCE_ID_HIGH (3 << 14)
  57. #define ISCR_FORCE_VBUS_MASK (3 << 12)
  58. #define ISCR_FORCE_VBUS_LOW (2 << 12)
  59. #define ISCR_FORCE_VBUS_HIGH (3 << 12)
  60. /* Common Control Bits for Both PHYs */
  61. #define PHY_PLL_BW 0x03
  62. #define PHY_RES45_CAL_EN 0x0c
  63. /* Private Control Bits for Each PHY */
  64. #define PHY_TX_AMPLITUDE_TUNE 0x20
  65. #define PHY_TX_SLEWRATE_TUNE 0x22
  66. #define PHY_VBUSVALID_TH_SEL 0x25
  67. #define PHY_PULLUP_RES_SEL 0x27
  68. #define PHY_OTG_FUNC_EN 0x28
  69. #define PHY_VBUS_DET_EN 0x29
  70. #define PHY_DISCON_TH_SEL 0x2a
  71. #define PHY_SQUELCH_DETECT 0x3c
  72. #define MAX_PHYS 3
  73. /*
  74. * Note do not raise the debounce time, we must report Vusb high within 100ms
  75. * otherwise we get Vbus errors
  76. */
  77. #define DEBOUNCE_TIME msecs_to_jiffies(50)
  78. #define POLL_TIME msecs_to_jiffies(250)
  79. struct sun4i_usb_phy_data {
  80. void __iomem *base;
  81. struct mutex mutex;
  82. int num_phys;
  83. u32 disc_thresh;
  84. struct sun4i_usb_phy {
  85. struct phy *phy;
  86. void __iomem *pmu;
  87. struct regulator *vbus;
  88. struct reset_control *reset;
  89. struct clk *clk;
  90. bool regulator_on;
  91. int index;
  92. } phys[MAX_PHYS];
  93. /* phy0 / otg related variables */
  94. struct extcon_dev *extcon;
  95. bool phy0_init;
  96. bool phy0_poll;
  97. struct gpio_desc *id_det_gpio;
  98. struct gpio_desc *vbus_det_gpio;
  99. int id_det_irq;
  100. int vbus_det_irq;
  101. int id_det;
  102. int vbus_det;
  103. struct delayed_work detect;
  104. };
  105. #define to_sun4i_usb_phy_data(phy) \
  106. container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index])
  107. static void sun4i_usb_phy0_update_iscr(struct phy *_phy, u32 clr, u32 set)
  108. {
  109. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  110. struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
  111. u32 iscr;
  112. iscr = readl(data->base + REG_ISCR);
  113. iscr &= ~clr;
  114. iscr |= set;
  115. writel(iscr, data->base + REG_ISCR);
  116. }
  117. static void sun4i_usb_phy0_set_id_detect(struct phy *phy, u32 val)
  118. {
  119. if (val)
  120. val = ISCR_FORCE_ID_HIGH;
  121. else
  122. val = ISCR_FORCE_ID_LOW;
  123. sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_ID_MASK, val);
  124. }
  125. static void sun4i_usb_phy0_set_vbus_detect(struct phy *phy, u32 val)
  126. {
  127. if (val)
  128. val = ISCR_FORCE_VBUS_HIGH;
  129. else
  130. val = ISCR_FORCE_VBUS_LOW;
  131. sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_VBUS_MASK, val);
  132. }
  133. static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
  134. int len)
  135. {
  136. struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
  137. u32 temp, usbc_bit = BIT(phy->index * 2);
  138. int i;
  139. mutex_lock(&phy_data->mutex);
  140. for (i = 0; i < len; i++) {
  141. temp = readl(phy_data->base + REG_PHYCTL);
  142. /* clear the address portion */
  143. temp &= ~(0xff << 8);
  144. /* set the address */
  145. temp |= ((addr + i) << 8);
  146. writel(temp, phy_data->base + REG_PHYCTL);
  147. /* set the data bit and clear usbc bit*/
  148. temp = readb(phy_data->base + REG_PHYCTL);
  149. if (data & 0x1)
  150. temp |= PHYCTL_DATA;
  151. else
  152. temp &= ~PHYCTL_DATA;
  153. temp &= ~usbc_bit;
  154. writeb(temp, phy_data->base + REG_PHYCTL);
  155. /* pulse usbc_bit */
  156. temp = readb(phy_data->base + REG_PHYCTL);
  157. temp |= usbc_bit;
  158. writeb(temp, phy_data->base + REG_PHYCTL);
  159. temp = readb(phy_data->base + REG_PHYCTL);
  160. temp &= ~usbc_bit;
  161. writeb(temp, phy_data->base + REG_PHYCTL);
  162. data >>= 1;
  163. }
  164. mutex_unlock(&phy_data->mutex);
  165. }
  166. static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
  167. {
  168. u32 bits, reg_value;
  169. if (!phy->pmu)
  170. return;
  171. bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
  172. SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
  173. reg_value = readl(phy->pmu);
  174. if (enable)
  175. reg_value |= bits;
  176. else
  177. reg_value &= ~bits;
  178. writel(reg_value, phy->pmu);
  179. }
  180. static int sun4i_usb_phy_init(struct phy *_phy)
  181. {
  182. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  183. struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
  184. int ret;
  185. ret = clk_prepare_enable(phy->clk);
  186. if (ret)
  187. return ret;
  188. ret = reset_control_deassert(phy->reset);
  189. if (ret) {
  190. clk_disable_unprepare(phy->clk);
  191. return ret;
  192. }
  193. /* Enable USB 45 Ohm resistor calibration */
  194. if (phy->index == 0)
  195. sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
  196. /* Adjust PHY's magnitude and rate */
  197. sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
  198. /* Disconnect threshold adjustment */
  199. sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2);
  200. sun4i_usb_phy_passby(phy, 1);
  201. if (phy->index == 0) {
  202. data->phy0_init = true;
  203. /* Enable pull-ups */
  204. sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_DPDM_PULLUP_EN);
  205. sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_ID_PULLUP_EN);
  206. if (data->id_det_gpio) {
  207. /* OTG mode, force ISCR and cable state updates */
  208. data->id_det = -1;
  209. data->vbus_det = -1;
  210. queue_delayed_work(system_wq, &data->detect, 0);
  211. } else {
  212. /* Host only mode */
  213. sun4i_usb_phy0_set_id_detect(_phy, 0);
  214. sun4i_usb_phy0_set_vbus_detect(_phy, 1);
  215. }
  216. }
  217. return 0;
  218. }
  219. static int sun4i_usb_phy_exit(struct phy *_phy)
  220. {
  221. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  222. struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
  223. if (phy->index == 0) {
  224. /* Disable pull-ups */
  225. sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
  226. sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
  227. data->phy0_init = false;
  228. }
  229. sun4i_usb_phy_passby(phy, 0);
  230. reset_control_assert(phy->reset);
  231. clk_disable_unprepare(phy->clk);
  232. return 0;
  233. }
  234. static int sun4i_usb_phy_power_on(struct phy *_phy)
  235. {
  236. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  237. struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
  238. int ret;
  239. if (!phy->vbus || phy->regulator_on)
  240. return 0;
  241. /* For phy0 only turn on Vbus if we don't have an ext. Vbus */
  242. if (phy->index == 0 && data->vbus_det)
  243. return 0;
  244. ret = regulator_enable(phy->vbus);
  245. if (ret)
  246. return ret;
  247. phy->regulator_on = true;
  248. /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
  249. if (phy->index == 0 && data->vbus_det_gpio && data->phy0_poll)
  250. mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
  251. return 0;
  252. }
  253. static int sun4i_usb_phy_power_off(struct phy *_phy)
  254. {
  255. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  256. struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
  257. if (!phy->vbus || !phy->regulator_on)
  258. return 0;
  259. regulator_disable(phy->vbus);
  260. phy->regulator_on = false;
  261. /*
  262. * phy0 vbus typically slowly discharges, sometimes this causes the
  263. * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
  264. */
  265. if (phy->index == 0 && data->vbus_det_gpio && !data->phy0_poll)
  266. mod_delayed_work(system_wq, &data->detect, POLL_TIME);
  267. return 0;
  268. }
  269. void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
  270. {
  271. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  272. sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
  273. }
  274. static struct phy_ops sun4i_usb_phy_ops = {
  275. .init = sun4i_usb_phy_init,
  276. .exit = sun4i_usb_phy_exit,
  277. .power_on = sun4i_usb_phy_power_on,
  278. .power_off = sun4i_usb_phy_power_off,
  279. .owner = THIS_MODULE,
  280. };
  281. static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
  282. {
  283. struct sun4i_usb_phy_data *data =
  284. container_of(work, struct sun4i_usb_phy_data, detect.work);
  285. struct phy *phy0 = data->phys[0].phy;
  286. int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
  287. id_det = gpiod_get_value_cansleep(data->id_det_gpio);
  288. if (data->vbus_det_gpio)
  289. vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
  290. else
  291. vbus_det = 1; /* Report vbus as high */
  292. mutex_lock(&phy0->mutex);
  293. if (!data->phy0_init) {
  294. mutex_unlock(&phy0->mutex);
  295. return;
  296. }
  297. if (id_det != data->id_det) {
  298. /*
  299. * When a host cable (id == 0) gets plugged in on systems
  300. * without vbus detection report vbus low for long enough for
  301. * the musb-ip to end the current device session.
  302. */
  303. if (!data->vbus_det_gpio && id_det == 0) {
  304. sun4i_usb_phy0_set_vbus_detect(phy0, 0);
  305. msleep(200);
  306. sun4i_usb_phy0_set_vbus_detect(phy0, 1);
  307. }
  308. sun4i_usb_phy0_set_id_detect(phy0, id_det);
  309. data->id_det = id_det;
  310. id_notify = 1;
  311. }
  312. if (vbus_det != data->vbus_det) {
  313. sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
  314. data->vbus_det = vbus_det;
  315. vbus_notify = 1;
  316. }
  317. mutex_unlock(&phy0->mutex);
  318. if (id_notify) {
  319. extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST,
  320. !id_det);
  321. /*
  322. * When a host cable gets unplugged (id == 1) on systems
  323. * without vbus detection report vbus low for long enough to
  324. * the musb-ip to end the current host session.
  325. */
  326. if (!data->vbus_det_gpio && id_det == 1) {
  327. mutex_lock(&phy0->mutex);
  328. sun4i_usb_phy0_set_vbus_detect(phy0, 0);
  329. msleep(1000);
  330. sun4i_usb_phy0_set_vbus_detect(phy0, 1);
  331. mutex_unlock(&phy0->mutex);
  332. }
  333. }
  334. if (vbus_notify)
  335. extcon_set_cable_state_(data->extcon, EXTCON_USB, vbus_det);
  336. if (data->phy0_poll)
  337. queue_delayed_work(system_wq, &data->detect, POLL_TIME);
  338. }
  339. static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, void *dev_id)
  340. {
  341. struct sun4i_usb_phy_data *data = dev_id;
  342. /* vbus or id changed, let the pins settle and then scan them */
  343. mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
  344. return IRQ_HANDLED;
  345. }
  346. static struct phy *sun4i_usb_phy_xlate(struct device *dev,
  347. struct of_phandle_args *args)
  348. {
  349. struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
  350. if (args->args[0] >= data->num_phys)
  351. return ERR_PTR(-ENODEV);
  352. return data->phys[args->args[0]].phy;
  353. }
  354. static int sun4i_usb_phy_remove(struct platform_device *pdev)
  355. {
  356. struct device *dev = &pdev->dev;
  357. struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
  358. if (data->id_det_irq >= 0)
  359. devm_free_irq(dev, data->id_det_irq, data);
  360. if (data->vbus_det_irq >= 0)
  361. devm_free_irq(dev, data->vbus_det_irq, data);
  362. cancel_delayed_work_sync(&data->detect);
  363. return 0;
  364. }
  365. static const unsigned int sun4i_usb_phy0_cable[] = {
  366. EXTCON_USB,
  367. EXTCON_USB_HOST,
  368. EXTCON_NONE,
  369. };
  370. static int sun4i_usb_phy_probe(struct platform_device *pdev)
  371. {
  372. struct sun4i_usb_phy_data *data;
  373. struct device *dev = &pdev->dev;
  374. struct device_node *np = dev->of_node;
  375. struct phy_provider *phy_provider;
  376. bool dedicated_clocks;
  377. struct resource *res;
  378. int i, ret;
  379. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  380. if (!data)
  381. return -ENOMEM;
  382. mutex_init(&data->mutex);
  383. INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
  384. dev_set_drvdata(dev, data);
  385. if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy"))
  386. data->num_phys = 2;
  387. else
  388. data->num_phys = 3;
  389. if (of_device_is_compatible(np, "allwinner,sun4i-a10-usb-phy") ||
  390. of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy"))
  391. data->disc_thresh = 3;
  392. else
  393. data->disc_thresh = 2;
  394. if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy"))
  395. dedicated_clocks = true;
  396. else
  397. dedicated_clocks = false;
  398. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
  399. data->base = devm_ioremap_resource(dev, res);
  400. if (IS_ERR(data->base))
  401. return PTR_ERR(data->base);
  402. data->id_det_gpio = devm_gpiod_get(dev, "usb0_id_det", GPIOD_IN);
  403. if (IS_ERR(data->id_det_gpio)) {
  404. if (PTR_ERR(data->id_det_gpio) == -EPROBE_DEFER)
  405. return -EPROBE_DEFER;
  406. data->id_det_gpio = NULL;
  407. }
  408. data->vbus_det_gpio = devm_gpiod_get(dev, "usb0_vbus_det", GPIOD_IN);
  409. if (IS_ERR(data->vbus_det_gpio)) {
  410. if (PTR_ERR(data->vbus_det_gpio) == -EPROBE_DEFER)
  411. return -EPROBE_DEFER;
  412. data->vbus_det_gpio = NULL;
  413. }
  414. /* vbus_det without id_det makes no sense, and is not supported */
  415. if (data->vbus_det_gpio && !data->id_det_gpio) {
  416. dev_err(dev, "usb0_id_det missing or invalid\n");
  417. return -ENODEV;
  418. }
  419. if (data->id_det_gpio) {
  420. data->extcon = devm_extcon_dev_allocate(dev,
  421. sun4i_usb_phy0_cable);
  422. if (IS_ERR(data->extcon))
  423. return PTR_ERR(data->extcon);
  424. ret = devm_extcon_dev_register(dev, data->extcon);
  425. if (ret) {
  426. dev_err(dev, "failed to register extcon: %d\n", ret);
  427. return ret;
  428. }
  429. }
  430. for (i = 0; i < data->num_phys; i++) {
  431. struct sun4i_usb_phy *phy = data->phys + i;
  432. char name[16];
  433. snprintf(name, sizeof(name), "usb%d_vbus", i);
  434. phy->vbus = devm_regulator_get_optional(dev, name);
  435. if (IS_ERR(phy->vbus)) {
  436. if (PTR_ERR(phy->vbus) == -EPROBE_DEFER)
  437. return -EPROBE_DEFER;
  438. phy->vbus = NULL;
  439. }
  440. if (dedicated_clocks)
  441. snprintf(name, sizeof(name), "usb%d_phy", i);
  442. else
  443. strlcpy(name, "usb_phy", sizeof(name));
  444. phy->clk = devm_clk_get(dev, name);
  445. if (IS_ERR(phy->clk)) {
  446. dev_err(dev, "failed to get clock %s\n", name);
  447. return PTR_ERR(phy->clk);
  448. }
  449. snprintf(name, sizeof(name), "usb%d_reset", i);
  450. phy->reset = devm_reset_control_get(dev, name);
  451. if (IS_ERR(phy->reset)) {
  452. dev_err(dev, "failed to get reset %s\n", name);
  453. return PTR_ERR(phy->reset);
  454. }
  455. if (i) { /* No pmu for usbc0 */
  456. snprintf(name, sizeof(name), "pmu%d", i);
  457. res = platform_get_resource_byname(pdev,
  458. IORESOURCE_MEM, name);
  459. phy->pmu = devm_ioremap_resource(dev, res);
  460. if (IS_ERR(phy->pmu))
  461. return PTR_ERR(phy->pmu);
  462. }
  463. phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops);
  464. if (IS_ERR(phy->phy)) {
  465. dev_err(dev, "failed to create PHY %d\n", i);
  466. return PTR_ERR(phy->phy);
  467. }
  468. phy->index = i;
  469. phy_set_drvdata(phy->phy, &data->phys[i]);
  470. }
  471. data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
  472. data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
  473. if ((data->id_det_gpio && data->id_det_irq < 0) ||
  474. (data->vbus_det_gpio && data->vbus_det_irq < 0))
  475. data->phy0_poll = true;
  476. if (data->id_det_irq >= 0) {
  477. ret = devm_request_irq(dev, data->id_det_irq,
  478. sun4i_usb_phy0_id_vbus_det_irq,
  479. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  480. "usb0-id-det", data);
  481. if (ret) {
  482. dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
  483. return ret;
  484. }
  485. }
  486. if (data->vbus_det_irq >= 0) {
  487. ret = devm_request_irq(dev, data->vbus_det_irq,
  488. sun4i_usb_phy0_id_vbus_det_irq,
  489. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  490. "usb0-vbus-det", data);
  491. if (ret) {
  492. dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
  493. data->vbus_det_irq = -1;
  494. sun4i_usb_phy_remove(pdev); /* Stop detect work */
  495. return ret;
  496. }
  497. }
  498. phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate);
  499. if (IS_ERR(phy_provider)) {
  500. sun4i_usb_phy_remove(pdev); /* Stop detect work */
  501. return PTR_ERR(phy_provider);
  502. }
  503. return 0;
  504. }
  505. static const struct of_device_id sun4i_usb_phy_of_match[] = {
  506. { .compatible = "allwinner,sun4i-a10-usb-phy" },
  507. { .compatible = "allwinner,sun5i-a13-usb-phy" },
  508. { .compatible = "allwinner,sun6i-a31-usb-phy" },
  509. { .compatible = "allwinner,sun7i-a20-usb-phy" },
  510. { },
  511. };
  512. MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
  513. static struct platform_driver sun4i_usb_phy_driver = {
  514. .probe = sun4i_usb_phy_probe,
  515. .remove = sun4i_usb_phy_remove,
  516. .driver = {
  517. .of_match_table = sun4i_usb_phy_of_match,
  518. .name = "sun4i-usb-phy",
  519. }
  520. };
  521. module_platform_driver(sun4i_usb_phy_driver);
  522. MODULE_DESCRIPTION("Allwinner sun4i USB phy driver");
  523. MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
  524. MODULE_LICENSE("GPL v2");