dwc3-omap.c 16 KB

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