dwc3-omap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. // SPDX-License-Identifier: GPL-2.0
  2. /**
  3. * dwc3-omap.c - OMAP Specific Glue layer
  4. *
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  6. *
  7. * Authors: Felipe Balbi <balbi@ti.com>,
  8. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/slab.h>
  13. #include <linux/irq.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/platform_data/dwc3-omap.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/ioport.h>
  20. #include <linux/io.h>
  21. #include <linux/of.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/extcon.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/usb/otg.h>
  26. /*
  27. * All these registers belong to OMAP's Wrapper around the
  28. * DesignWare USB3 Core.
  29. */
  30. #define USBOTGSS_REVISION 0x0000
  31. #define USBOTGSS_SYSCONFIG 0x0010
  32. #define USBOTGSS_IRQ_EOI 0x0020
  33. #define USBOTGSS_EOI_OFFSET 0x0008
  34. #define USBOTGSS_IRQSTATUS_RAW_0 0x0024
  35. #define USBOTGSS_IRQSTATUS_0 0x0028
  36. #define USBOTGSS_IRQENABLE_SET_0 0x002c
  37. #define USBOTGSS_IRQENABLE_CLR_0 0x0030
  38. #define USBOTGSS_IRQ0_OFFSET 0x0004
  39. #define USBOTGSS_IRQSTATUS_RAW_1 0x0030
  40. #define USBOTGSS_IRQSTATUS_1 0x0034
  41. #define USBOTGSS_IRQENABLE_SET_1 0x0038
  42. #define USBOTGSS_IRQENABLE_CLR_1 0x003c
  43. #define USBOTGSS_IRQSTATUS_RAW_2 0x0040
  44. #define USBOTGSS_IRQSTATUS_2 0x0044
  45. #define USBOTGSS_IRQENABLE_SET_2 0x0048
  46. #define USBOTGSS_IRQENABLE_CLR_2 0x004c
  47. #define USBOTGSS_IRQSTATUS_RAW_3 0x0050
  48. #define USBOTGSS_IRQSTATUS_3 0x0054
  49. #define USBOTGSS_IRQENABLE_SET_3 0x0058
  50. #define USBOTGSS_IRQENABLE_CLR_3 0x005c
  51. #define USBOTGSS_IRQSTATUS_EOI_MISC 0x0030
  52. #define USBOTGSS_IRQSTATUS_RAW_MISC 0x0034
  53. #define USBOTGSS_IRQSTATUS_MISC 0x0038
  54. #define USBOTGSS_IRQENABLE_SET_MISC 0x003c
  55. #define USBOTGSS_IRQENABLE_CLR_MISC 0x0040
  56. #define USBOTGSS_IRQMISC_OFFSET 0x03fc
  57. #define USBOTGSS_UTMI_OTG_STATUS 0x0080
  58. #define USBOTGSS_UTMI_OTG_CTRL 0x0084
  59. #define USBOTGSS_UTMI_OTG_OFFSET 0x0480
  60. #define USBOTGSS_TXFIFO_DEPTH 0x0508
  61. #define USBOTGSS_RXFIFO_DEPTH 0x050c
  62. #define USBOTGSS_MMRAM_OFFSET 0x0100
  63. #define USBOTGSS_FLADJ 0x0104
  64. #define USBOTGSS_DEBUG_CFG 0x0108
  65. #define USBOTGSS_DEBUG_DATA 0x010c
  66. #define USBOTGSS_DEV_EBC_EN 0x0110
  67. #define USBOTGSS_DEBUG_OFFSET 0x0600
  68. /* SYSCONFIG REGISTER */
  69. #define USBOTGSS_SYSCONFIG_DMADISABLE BIT(16)
  70. /* IRQ_EOI REGISTER */
  71. #define USBOTGSS_IRQ_EOI_LINE_NUMBER BIT(0)
  72. /* IRQS0 BITS */
  73. #define USBOTGSS_IRQO_COREIRQ_ST BIT(0)
  74. /* IRQMISC BITS */
  75. #define USBOTGSS_IRQMISC_DMADISABLECLR BIT(17)
  76. #define USBOTGSS_IRQMISC_OEVT BIT(16)
  77. #define USBOTGSS_IRQMISC_DRVVBUS_RISE BIT(13)
  78. #define USBOTGSS_IRQMISC_CHRGVBUS_RISE BIT(12)
  79. #define USBOTGSS_IRQMISC_DISCHRGVBUS_RISE BIT(11)
  80. #define USBOTGSS_IRQMISC_IDPULLUP_RISE BIT(8)
  81. #define USBOTGSS_IRQMISC_DRVVBUS_FALL BIT(5)
  82. #define USBOTGSS_IRQMISC_CHRGVBUS_FALL BIT(4)
  83. #define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL BIT(3)
  84. #define USBOTGSS_IRQMISC_IDPULLUP_FALL BIT(0)
  85. /* UTMI_OTG_STATUS REGISTER */
  86. #define USBOTGSS_UTMI_OTG_STATUS_DRVVBUS BIT(5)
  87. #define USBOTGSS_UTMI_OTG_STATUS_CHRGVBUS BIT(4)
  88. #define USBOTGSS_UTMI_OTG_STATUS_DISCHRGVBUS BIT(3)
  89. #define USBOTGSS_UTMI_OTG_STATUS_IDPULLUP BIT(0)
  90. /* UTMI_OTG_CTRL REGISTER */
  91. #define USBOTGSS_UTMI_OTG_CTRL_SW_MODE BIT(31)
  92. #define USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT BIT(9)
  93. #define USBOTGSS_UTMI_OTG_CTRL_TXBITSTUFFENABLE BIT(8)
  94. #define USBOTGSS_UTMI_OTG_CTRL_IDDIG BIT(4)
  95. #define USBOTGSS_UTMI_OTG_CTRL_SESSEND BIT(3)
  96. #define USBOTGSS_UTMI_OTG_CTRL_SESSVALID BIT(2)
  97. #define USBOTGSS_UTMI_OTG_CTRL_VBUSVALID BIT(1)
  98. struct dwc3_omap {
  99. struct device *dev;
  100. int irq;
  101. void __iomem *base;
  102. u32 utmi_otg_ctrl;
  103. u32 utmi_otg_offset;
  104. u32 irqmisc_offset;
  105. u32 irq_eoi_offset;
  106. u32 debug_offset;
  107. u32 irq0_offset;
  108. struct extcon_dev *edev;
  109. struct notifier_block vbus_nb;
  110. struct notifier_block id_nb;
  111. struct regulator *vbus_reg;
  112. };
  113. enum omap_dwc3_vbus_id_status {
  114. OMAP_DWC3_ID_FLOAT,
  115. OMAP_DWC3_ID_GROUND,
  116. OMAP_DWC3_VBUS_OFF,
  117. OMAP_DWC3_VBUS_VALID,
  118. };
  119. static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
  120. {
  121. return readl(base + offset);
  122. }
  123. static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
  124. {
  125. writel(value, base + offset);
  126. }
  127. static u32 dwc3_omap_read_utmi_ctrl(struct dwc3_omap *omap)
  128. {
  129. return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_CTRL +
  130. omap->utmi_otg_offset);
  131. }
  132. static void dwc3_omap_write_utmi_ctrl(struct dwc3_omap *omap, u32 value)
  133. {
  134. dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_CTRL +
  135. omap->utmi_otg_offset, value);
  136. }
  137. static u32 dwc3_omap_read_irq0_status(struct dwc3_omap *omap)
  138. {
  139. return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_RAW_0 -
  140. omap->irq0_offset);
  141. }
  142. static void dwc3_omap_write_irq0_status(struct dwc3_omap *omap, u32 value)
  143. {
  144. dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0 -
  145. omap->irq0_offset, value);
  146. }
  147. static u32 dwc3_omap_read_irqmisc_status(struct dwc3_omap *omap)
  148. {
  149. return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_RAW_MISC +
  150. omap->irqmisc_offset);
  151. }
  152. static void dwc3_omap_write_irqmisc_status(struct dwc3_omap *omap, u32 value)
  153. {
  154. dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_MISC +
  155. omap->irqmisc_offset, value);
  156. }
  157. static void dwc3_omap_write_irqmisc_set(struct dwc3_omap *omap, u32 value)
  158. {
  159. dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_MISC +
  160. omap->irqmisc_offset, value);
  161. }
  162. static void dwc3_omap_write_irq0_set(struct dwc3_omap *omap, u32 value)
  163. {
  164. dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0 -
  165. omap->irq0_offset, value);
  166. }
  167. static void dwc3_omap_write_irqmisc_clr(struct dwc3_omap *omap, u32 value)
  168. {
  169. dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_CLR_MISC +
  170. omap->irqmisc_offset, value);
  171. }
  172. static void dwc3_omap_write_irq0_clr(struct dwc3_omap *omap, u32 value)
  173. {
  174. dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_CLR_0 -
  175. omap->irq0_offset, value);
  176. }
  177. static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
  178. enum omap_dwc3_vbus_id_status status)
  179. {
  180. int ret;
  181. u32 val;
  182. switch (status) {
  183. case OMAP_DWC3_ID_GROUND:
  184. if (omap->vbus_reg) {
  185. ret = regulator_enable(omap->vbus_reg);
  186. if (ret) {
  187. dev_err(omap->dev, "regulator enable failed\n");
  188. return;
  189. }
  190. }
  191. val = dwc3_omap_read_utmi_ctrl(omap);
  192. val &= ~USBOTGSS_UTMI_OTG_CTRL_IDDIG;
  193. dwc3_omap_write_utmi_ctrl(omap, val);
  194. break;
  195. case OMAP_DWC3_VBUS_VALID:
  196. val = dwc3_omap_read_utmi_ctrl(omap);
  197. val &= ~USBOTGSS_UTMI_OTG_CTRL_SESSEND;
  198. val |= USBOTGSS_UTMI_OTG_CTRL_VBUSVALID
  199. | USBOTGSS_UTMI_OTG_CTRL_SESSVALID;
  200. dwc3_omap_write_utmi_ctrl(omap, val);
  201. break;
  202. case OMAP_DWC3_ID_FLOAT:
  203. if (omap->vbus_reg)
  204. regulator_disable(omap->vbus_reg);
  205. val = dwc3_omap_read_utmi_ctrl(omap);
  206. val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG;
  207. dwc3_omap_write_utmi_ctrl(omap, val);
  208. break;
  209. case OMAP_DWC3_VBUS_OFF:
  210. val = dwc3_omap_read_utmi_ctrl(omap);
  211. val &= ~(USBOTGSS_UTMI_OTG_CTRL_SESSVALID
  212. | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID);
  213. val |= USBOTGSS_UTMI_OTG_CTRL_SESSEND;
  214. dwc3_omap_write_utmi_ctrl(omap, val);
  215. break;
  216. default:
  217. dev_WARN(omap->dev, "invalid state\n");
  218. }
  219. }
  220. static void dwc3_omap_enable_irqs(struct dwc3_omap *omap);
  221. static void dwc3_omap_disable_irqs(struct dwc3_omap *omap);
  222. static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
  223. {
  224. struct dwc3_omap *omap = _omap;
  225. if (dwc3_omap_read_irqmisc_status(omap) ||
  226. dwc3_omap_read_irq0_status(omap)) {
  227. /* mask irqs */
  228. dwc3_omap_disable_irqs(omap);
  229. return IRQ_WAKE_THREAD;
  230. }
  231. return IRQ_NONE;
  232. }
  233. static irqreturn_t dwc3_omap_interrupt_thread(int irq, void *_omap)
  234. {
  235. struct dwc3_omap *omap = _omap;
  236. u32 reg;
  237. /* clear irq status flags */
  238. reg = dwc3_omap_read_irqmisc_status(omap);
  239. dwc3_omap_write_irqmisc_status(omap, reg);
  240. reg = dwc3_omap_read_irq0_status(omap);
  241. dwc3_omap_write_irq0_status(omap, reg);
  242. /* unmask irqs */
  243. dwc3_omap_enable_irqs(omap);
  244. return IRQ_HANDLED;
  245. }
  246. static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
  247. {
  248. u32 reg;
  249. /* enable all IRQs */
  250. reg = USBOTGSS_IRQO_COREIRQ_ST;
  251. dwc3_omap_write_irq0_set(omap, reg);
  252. reg = (USBOTGSS_IRQMISC_OEVT |
  253. USBOTGSS_IRQMISC_DRVVBUS_RISE |
  254. USBOTGSS_IRQMISC_CHRGVBUS_RISE |
  255. USBOTGSS_IRQMISC_DISCHRGVBUS_RISE |
  256. USBOTGSS_IRQMISC_IDPULLUP_RISE |
  257. USBOTGSS_IRQMISC_DRVVBUS_FALL |
  258. USBOTGSS_IRQMISC_CHRGVBUS_FALL |
  259. USBOTGSS_IRQMISC_DISCHRGVBUS_FALL |
  260. USBOTGSS_IRQMISC_IDPULLUP_FALL);
  261. dwc3_omap_write_irqmisc_set(omap, reg);
  262. }
  263. static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
  264. {
  265. u32 reg;
  266. /* disable all IRQs */
  267. reg = USBOTGSS_IRQO_COREIRQ_ST;
  268. dwc3_omap_write_irq0_clr(omap, reg);
  269. reg = (USBOTGSS_IRQMISC_OEVT |
  270. USBOTGSS_IRQMISC_DRVVBUS_RISE |
  271. USBOTGSS_IRQMISC_CHRGVBUS_RISE |
  272. USBOTGSS_IRQMISC_DISCHRGVBUS_RISE |
  273. USBOTGSS_IRQMISC_IDPULLUP_RISE |
  274. USBOTGSS_IRQMISC_DRVVBUS_FALL |
  275. USBOTGSS_IRQMISC_CHRGVBUS_FALL |
  276. USBOTGSS_IRQMISC_DISCHRGVBUS_FALL |
  277. USBOTGSS_IRQMISC_IDPULLUP_FALL);
  278. dwc3_omap_write_irqmisc_clr(omap, reg);
  279. }
  280. static int dwc3_omap_id_notifier(struct notifier_block *nb,
  281. unsigned long event, void *ptr)
  282. {
  283. struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb);
  284. if (event)
  285. dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
  286. else
  287. dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
  288. return NOTIFY_DONE;
  289. }
  290. static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
  291. unsigned long event, void *ptr)
  292. {
  293. struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb);
  294. if (event)
  295. dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
  296. else
  297. dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
  298. return NOTIFY_DONE;
  299. }
  300. static void dwc3_omap_map_offset(struct dwc3_omap *omap)
  301. {
  302. struct device_node *node = omap->dev->of_node;
  303. /*
  304. * Differentiate between OMAP5 and AM437x.
  305. *
  306. * For OMAP5(ES2.0) and AM437x wrapper revision is same, even
  307. * though there are changes in wrapper register offsets.
  308. *
  309. * Using dt compatible to differentiate AM437x.
  310. */
  311. if (of_device_is_compatible(node, "ti,am437x-dwc3")) {
  312. omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
  313. omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
  314. omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
  315. omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
  316. omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
  317. }
  318. }
  319. static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
  320. {
  321. u32 reg;
  322. struct device_node *node = omap->dev->of_node;
  323. u32 utmi_mode = 0;
  324. reg = dwc3_omap_read_utmi_ctrl(omap);
  325. of_property_read_u32(node, "utmi-mode", &utmi_mode);
  326. switch (utmi_mode) {
  327. case DWC3_OMAP_UTMI_MODE_SW:
  328. reg |= USBOTGSS_UTMI_OTG_CTRL_SW_MODE;
  329. break;
  330. case DWC3_OMAP_UTMI_MODE_HW:
  331. reg &= ~USBOTGSS_UTMI_OTG_CTRL_SW_MODE;
  332. break;
  333. default:
  334. dev_WARN(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode);
  335. }
  336. dwc3_omap_write_utmi_ctrl(omap, reg);
  337. }
  338. static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
  339. {
  340. int ret;
  341. struct device_node *node = omap->dev->of_node;
  342. struct extcon_dev *edev;
  343. if (of_property_read_bool(node, "extcon")) {
  344. edev = extcon_get_edev_by_phandle(omap->dev, 0);
  345. if (IS_ERR(edev)) {
  346. dev_vdbg(omap->dev, "couldn't get extcon device\n");
  347. return -EPROBE_DEFER;
  348. }
  349. omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
  350. ret = devm_extcon_register_notifier(omap->dev, edev,
  351. EXTCON_USB, &omap->vbus_nb);
  352. if (ret < 0)
  353. dev_vdbg(omap->dev, "failed to register notifier for USB\n");
  354. omap->id_nb.notifier_call = dwc3_omap_id_notifier;
  355. ret = devm_extcon_register_notifier(omap->dev, edev,
  356. EXTCON_USB_HOST, &omap->id_nb);
  357. if (ret < 0)
  358. dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
  359. if (extcon_get_state(edev, EXTCON_USB) == true)
  360. dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
  361. if (extcon_get_state(edev, EXTCON_USB_HOST) == true)
  362. dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
  363. omap->edev = edev;
  364. }
  365. return 0;
  366. }
  367. static int dwc3_omap_probe(struct platform_device *pdev)
  368. {
  369. struct device_node *node = pdev->dev.of_node;
  370. struct dwc3_omap *omap;
  371. struct resource *res;
  372. struct device *dev = &pdev->dev;
  373. struct regulator *vbus_reg = NULL;
  374. int ret;
  375. int irq;
  376. u32 reg;
  377. void __iomem *base;
  378. if (!node) {
  379. dev_err(dev, "device node not found\n");
  380. return -EINVAL;
  381. }
  382. omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
  383. if (!omap)
  384. return -ENOMEM;
  385. platform_set_drvdata(pdev, omap);
  386. irq = platform_get_irq(pdev, 0);
  387. if (irq < 0) {
  388. dev_err(dev, "missing IRQ resource: %d\n", irq);
  389. return irq;
  390. }
  391. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  392. base = devm_ioremap_resource(dev, res);
  393. if (IS_ERR(base))
  394. return PTR_ERR(base);
  395. if (of_property_read_bool(node, "vbus-supply")) {
  396. vbus_reg = devm_regulator_get(dev, "vbus");
  397. if (IS_ERR(vbus_reg)) {
  398. dev_err(dev, "vbus init failed\n");
  399. return PTR_ERR(vbus_reg);
  400. }
  401. }
  402. omap->dev = dev;
  403. omap->irq = irq;
  404. omap->base = base;
  405. omap->vbus_reg = vbus_reg;
  406. pm_runtime_enable(dev);
  407. ret = pm_runtime_get_sync(dev);
  408. if (ret < 0) {
  409. dev_err(dev, "get_sync failed with err %d\n", ret);
  410. goto err1;
  411. }
  412. dwc3_omap_map_offset(omap);
  413. dwc3_omap_set_utmi_mode(omap);
  414. /* check the DMA Status */
  415. reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
  416. ret = dwc3_omap_extcon_register(omap);
  417. if (ret < 0)
  418. goto err1;
  419. ret = of_platform_populate(node, NULL, NULL, dev);
  420. if (ret) {
  421. dev_err(&pdev->dev, "failed to create dwc3 core\n");
  422. goto err1;
  423. }
  424. ret = devm_request_threaded_irq(dev, omap->irq, dwc3_omap_interrupt,
  425. dwc3_omap_interrupt_thread, IRQF_SHARED,
  426. "dwc3-omap", omap);
  427. if (ret) {
  428. dev_err(dev, "failed to request IRQ #%d --> %d\n",
  429. omap->irq, ret);
  430. goto err1;
  431. }
  432. dwc3_omap_enable_irqs(omap);
  433. return 0;
  434. err1:
  435. pm_runtime_put_sync(dev);
  436. pm_runtime_disable(dev);
  437. return ret;
  438. }
  439. static int dwc3_omap_remove(struct platform_device *pdev)
  440. {
  441. struct dwc3_omap *omap = platform_get_drvdata(pdev);
  442. dwc3_omap_disable_irqs(omap);
  443. disable_irq(omap->irq);
  444. of_platform_depopulate(omap->dev);
  445. pm_runtime_put_sync(&pdev->dev);
  446. pm_runtime_disable(&pdev->dev);
  447. return 0;
  448. }
  449. static const struct of_device_id of_dwc3_match[] = {
  450. {
  451. .compatible = "ti,dwc3"
  452. },
  453. {
  454. .compatible = "ti,am437x-dwc3"
  455. },
  456. { },
  457. };
  458. MODULE_DEVICE_TABLE(of, of_dwc3_match);
  459. #ifdef CONFIG_PM_SLEEP
  460. static int dwc3_omap_suspend(struct device *dev)
  461. {
  462. struct dwc3_omap *omap = dev_get_drvdata(dev);
  463. omap->utmi_otg_ctrl = dwc3_omap_read_utmi_ctrl(omap);
  464. dwc3_omap_disable_irqs(omap);
  465. return 0;
  466. }
  467. static int dwc3_omap_resume(struct device *dev)
  468. {
  469. struct dwc3_omap *omap = dev_get_drvdata(dev);
  470. dwc3_omap_write_utmi_ctrl(omap, omap->utmi_otg_ctrl);
  471. dwc3_omap_enable_irqs(omap);
  472. pm_runtime_disable(dev);
  473. pm_runtime_set_active(dev);
  474. pm_runtime_enable(dev);
  475. return 0;
  476. }
  477. static void dwc3_omap_complete(struct device *dev)
  478. {
  479. struct dwc3_omap *omap = dev_get_drvdata(dev);
  480. if (extcon_get_state(omap->edev, EXTCON_USB))
  481. dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
  482. else
  483. dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
  484. if (extcon_get_state(omap->edev, EXTCON_USB_HOST))
  485. dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
  486. else
  487. dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
  488. }
  489. static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
  490. SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
  491. .complete = dwc3_omap_complete,
  492. };
  493. #define DEV_PM_OPS (&dwc3_omap_dev_pm_ops)
  494. #else
  495. #define DEV_PM_OPS NULL
  496. #endif /* CONFIG_PM_SLEEP */
  497. static struct platform_driver dwc3_omap_driver = {
  498. .probe = dwc3_omap_probe,
  499. .remove = dwc3_omap_remove,
  500. .driver = {
  501. .name = "omap-dwc3",
  502. .of_match_table = of_dwc3_match,
  503. .pm = DEV_PM_OPS,
  504. },
  505. };
  506. module_platform_driver(dwc3_omap_driver);
  507. MODULE_ALIAS("platform:omap-dwc3");
  508. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  509. MODULE_LICENSE("GPL v2");
  510. MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");