core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /**
  2. * core.c - DesignWare USB3 DRD Controller Core file
  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. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions, and the following disclaimer,
  14. * without modification.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. The names of the above-listed copyright holders may not be used
  19. * to endorse or promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * ALTERNATIVELY, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2, as published by the Free
  24. * Software Foundation.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  36. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #include <linux/module.h>
  39. #include <linux/kernel.h>
  40. #include <linux/slab.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/pm_runtime.h>
  44. #include <linux/interrupt.h>
  45. #include <linux/ioport.h>
  46. #include <linux/io.h>
  47. #include <linux/list.h>
  48. #include <linux/delay.h>
  49. #include <linux/dma-mapping.h>
  50. #include <linux/of.h>
  51. #include <linux/usb/otg.h>
  52. #include <linux/usb/ch9.h>
  53. #include <linux/usb/gadget.h>
  54. #include "core.h"
  55. #include "gadget.h"
  56. #include "io.h"
  57. #include "debug.h"
  58. static char *maximum_speed = "super";
  59. module_param(maximum_speed, charp, 0);
  60. MODULE_PARM_DESC(maximum_speed, "Maximum supported speed.");
  61. /* -------------------------------------------------------------------------- */
  62. void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
  63. {
  64. u32 reg;
  65. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  66. reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
  67. reg |= DWC3_GCTL_PRTCAPDIR(mode);
  68. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  69. }
  70. /**
  71. * dwc3_core_soft_reset - Issues core soft reset and PHY reset
  72. * @dwc: pointer to our context structure
  73. */
  74. static void dwc3_core_soft_reset(struct dwc3 *dwc)
  75. {
  76. u32 reg;
  77. /* Before Resetting PHY, put Core in Reset */
  78. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  79. reg |= DWC3_GCTL_CORESOFTRESET;
  80. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  81. /* Assert USB3 PHY reset */
  82. reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
  83. reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
  84. dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
  85. /* Assert USB2 PHY reset */
  86. reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
  87. reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
  88. dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
  89. usb_phy_init(dwc->usb2_phy);
  90. usb_phy_init(dwc->usb3_phy);
  91. mdelay(100);
  92. /* Clear USB3 PHY reset */
  93. reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
  94. reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
  95. dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
  96. /* Clear USB2 PHY reset */
  97. reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
  98. reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
  99. dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
  100. mdelay(100);
  101. /* After PHYs are stable we can take Core out of reset state */
  102. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  103. reg &= ~DWC3_GCTL_CORESOFTRESET;
  104. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  105. }
  106. /**
  107. * dwc3_free_one_event_buffer - Frees one event buffer
  108. * @dwc: Pointer to our controller context structure
  109. * @evt: Pointer to event buffer to be freed
  110. */
  111. static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
  112. struct dwc3_event_buffer *evt)
  113. {
  114. dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
  115. }
  116. /**
  117. * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
  118. * @dwc: Pointer to our controller context structure
  119. * @length: size of the event buffer
  120. *
  121. * Returns a pointer to the allocated event buffer structure on success
  122. * otherwise ERR_PTR(errno).
  123. */
  124. static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length)
  125. {
  126. struct dwc3_event_buffer *evt;
  127. evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
  128. if (!evt)
  129. return ERR_PTR(-ENOMEM);
  130. evt->dwc = dwc;
  131. evt->length = length;
  132. evt->buf = dma_alloc_coherent(dwc->dev, length,
  133. &evt->dma, GFP_KERNEL);
  134. if (!evt->buf)
  135. return ERR_PTR(-ENOMEM);
  136. return evt;
  137. }
  138. /**
  139. * dwc3_free_event_buffers - frees all allocated event buffers
  140. * @dwc: Pointer to our controller context structure
  141. */
  142. static void dwc3_free_event_buffers(struct dwc3 *dwc)
  143. {
  144. struct dwc3_event_buffer *evt;
  145. int i;
  146. for (i = 0; i < dwc->num_event_buffers; i++) {
  147. evt = dwc->ev_buffs[i];
  148. if (evt)
  149. dwc3_free_one_event_buffer(dwc, evt);
  150. }
  151. }
  152. /**
  153. * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
  154. * @dwc: pointer to our controller context structure
  155. * @length: size of event buffer
  156. *
  157. * Returns 0 on success otherwise negative errno. In the error case, dwc
  158. * may contain some buffers allocated but not all which were requested.
  159. */
  160. static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
  161. {
  162. int num;
  163. int i;
  164. num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
  165. dwc->num_event_buffers = num;
  166. dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
  167. GFP_KERNEL);
  168. if (!dwc->ev_buffs) {
  169. dev_err(dwc->dev, "can't allocate event buffers array\n");
  170. return -ENOMEM;
  171. }
  172. for (i = 0; i < num; i++) {
  173. struct dwc3_event_buffer *evt;
  174. evt = dwc3_alloc_one_event_buffer(dwc, length);
  175. if (IS_ERR(evt)) {
  176. dev_err(dwc->dev, "can't allocate event buffer\n");
  177. return PTR_ERR(evt);
  178. }
  179. dwc->ev_buffs[i] = evt;
  180. }
  181. return 0;
  182. }
  183. /**
  184. * dwc3_event_buffers_setup - setup our allocated event buffers
  185. * @dwc: pointer to our controller context structure
  186. *
  187. * Returns 0 on success otherwise negative errno.
  188. */
  189. static int dwc3_event_buffers_setup(struct dwc3 *dwc)
  190. {
  191. struct dwc3_event_buffer *evt;
  192. int n;
  193. for (n = 0; n < dwc->num_event_buffers; n++) {
  194. evt = dwc->ev_buffs[n];
  195. dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
  196. evt->buf, (unsigned long long) evt->dma,
  197. evt->length);
  198. evt->lpos = 0;
  199. dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
  200. lower_32_bits(evt->dma));
  201. dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
  202. upper_32_bits(evt->dma));
  203. dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
  204. evt->length & 0xffff);
  205. dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  206. }
  207. return 0;
  208. }
  209. static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
  210. {
  211. struct dwc3_event_buffer *evt;
  212. int n;
  213. for (n = 0; n < dwc->num_event_buffers; n++) {
  214. evt = dwc->ev_buffs[n];
  215. evt->lpos = 0;
  216. dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
  217. dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
  218. dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0);
  219. dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  220. }
  221. }
  222. static void dwc3_cache_hwparams(struct dwc3 *dwc)
  223. {
  224. struct dwc3_hwparams *parms = &dwc->hwparams;
  225. parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
  226. parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
  227. parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
  228. parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
  229. parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
  230. parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
  231. parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
  232. parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
  233. parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
  234. }
  235. /**
  236. * dwc3_core_init - Low-level initialization of DWC3 Core
  237. * @dwc: Pointer to our controller context structure
  238. *
  239. * Returns 0 on success otherwise negative errno.
  240. */
  241. static int dwc3_core_init(struct dwc3 *dwc)
  242. {
  243. unsigned long timeout;
  244. u32 reg;
  245. int ret;
  246. reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
  247. /* This should read as U3 followed by revision number */
  248. if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) {
  249. dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
  250. ret = -ENODEV;
  251. goto err0;
  252. }
  253. dwc->revision = reg;
  254. /* issue device SoftReset too */
  255. timeout = jiffies + msecs_to_jiffies(500);
  256. dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
  257. do {
  258. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  259. if (!(reg & DWC3_DCTL_CSFTRST))
  260. break;
  261. if (time_after(jiffies, timeout)) {
  262. dev_err(dwc->dev, "Reset Timed Out\n");
  263. ret = -ETIMEDOUT;
  264. goto err0;
  265. }
  266. cpu_relax();
  267. } while (true);
  268. dwc3_core_soft_reset(dwc);
  269. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  270. reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
  271. reg &= ~DWC3_GCTL_DISSCRAMBLE;
  272. switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
  273. case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
  274. reg &= ~DWC3_GCTL_DSBLCLKGTNG;
  275. break;
  276. default:
  277. dev_dbg(dwc->dev, "No power optimization available\n");
  278. }
  279. /*
  280. * WORKAROUND: DWC3 revisions <1.90a have a bug
  281. * where the device can fail to connect at SuperSpeed
  282. * and falls back to high-speed mode which causes
  283. * the device to enter a Connect/Disconnect loop
  284. */
  285. if (dwc->revision < DWC3_REVISION_190A)
  286. reg |= DWC3_GCTL_U2RSTECN;
  287. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  288. return 0;
  289. err0:
  290. return ret;
  291. }
  292. static void dwc3_core_exit(struct dwc3 *dwc)
  293. {
  294. usb_phy_shutdown(dwc->usb2_phy);
  295. usb_phy_shutdown(dwc->usb3_phy);
  296. }
  297. #define DWC3_ALIGN_MASK (16 - 1)
  298. static int dwc3_probe(struct platform_device *pdev)
  299. {
  300. struct device_node *node = pdev->dev.of_node;
  301. struct resource *res;
  302. struct dwc3 *dwc;
  303. struct device *dev = &pdev->dev;
  304. int ret = -ENOMEM;
  305. void __iomem *regs;
  306. void *mem;
  307. u8 mode;
  308. mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
  309. if (!mem) {
  310. dev_err(dev, "not enough memory\n");
  311. return -ENOMEM;
  312. }
  313. dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
  314. dwc->mem = mem;
  315. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  316. if (!res) {
  317. dev_err(dev, "missing IRQ\n");
  318. return -ENODEV;
  319. }
  320. dwc->xhci_resources[1].start = res->start;
  321. dwc->xhci_resources[1].end = res->end;
  322. dwc->xhci_resources[1].flags = res->flags;
  323. dwc->xhci_resources[1].name = res->name;
  324. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  325. if (!res) {
  326. dev_err(dev, "missing memory resource\n");
  327. return -ENODEV;
  328. }
  329. dwc->xhci_resources[0].start = res->start;
  330. dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
  331. DWC3_XHCI_REGS_END;
  332. dwc->xhci_resources[0].flags = res->flags;
  333. dwc->xhci_resources[0].name = res->name;
  334. /*
  335. * Request memory region but exclude xHCI regs,
  336. * since it will be requested by the xhci-plat driver.
  337. */
  338. res = devm_request_mem_region(dev, res->start + DWC3_GLOBALS_REGS_START,
  339. resource_size(res) - DWC3_GLOBALS_REGS_START,
  340. dev_name(dev));
  341. if (!res) {
  342. dev_err(dev, "can't request mem region\n");
  343. return -ENOMEM;
  344. }
  345. regs = devm_ioremap_nocache(dev, res->start, resource_size(res));
  346. if (!regs) {
  347. dev_err(dev, "ioremap failed\n");
  348. return -ENOMEM;
  349. }
  350. if (node) {
  351. dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
  352. dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
  353. } else {
  354. dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
  355. dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
  356. }
  357. if (IS_ERR_OR_NULL(dwc->usb2_phy)) {
  358. dev_err(dev, "no usb2 phy configured\n");
  359. return -EPROBE_DEFER;
  360. }
  361. if (IS_ERR_OR_NULL(dwc->usb3_phy)) {
  362. dev_err(dev, "no usb3 phy configured\n");
  363. return -EPROBE_DEFER;
  364. }
  365. usb_phy_set_suspend(dwc->usb2_phy, 0);
  366. usb_phy_set_suspend(dwc->usb3_phy, 0);
  367. spin_lock_init(&dwc->lock);
  368. platform_set_drvdata(pdev, dwc);
  369. dwc->regs = regs;
  370. dwc->regs_size = resource_size(res);
  371. dwc->dev = dev;
  372. if (!strncmp("super", maximum_speed, 5))
  373. dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
  374. else if (!strncmp("high", maximum_speed, 4))
  375. dwc->maximum_speed = DWC3_DCFG_HIGHSPEED;
  376. else if (!strncmp("full", maximum_speed, 4))
  377. dwc->maximum_speed = DWC3_DCFG_FULLSPEED1;
  378. else if (!strncmp("low", maximum_speed, 3))
  379. dwc->maximum_speed = DWC3_DCFG_LOWSPEED;
  380. else
  381. dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
  382. dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
  383. pm_runtime_enable(dev);
  384. pm_runtime_get_sync(dev);
  385. pm_runtime_forbid(dev);
  386. dwc3_cache_hwparams(dwc);
  387. ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
  388. if (ret) {
  389. dev_err(dwc->dev, "failed to allocate event buffers\n");
  390. ret = -ENOMEM;
  391. goto err0;
  392. }
  393. ret = dwc3_core_init(dwc);
  394. if (ret) {
  395. dev_err(dev, "failed to initialize core\n");
  396. goto err0;
  397. }
  398. ret = dwc3_event_buffers_setup(dwc);
  399. if (ret) {
  400. dev_err(dwc->dev, "failed to setup event buffers\n");
  401. goto err1;
  402. }
  403. mode = DWC3_MODE(dwc->hwparams.hwparams0);
  404. switch (mode) {
  405. case DWC3_MODE_DEVICE:
  406. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
  407. ret = dwc3_gadget_init(dwc);
  408. if (ret) {
  409. dev_err(dev, "failed to initialize gadget\n");
  410. goto err2;
  411. }
  412. break;
  413. case DWC3_MODE_HOST:
  414. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
  415. ret = dwc3_host_init(dwc);
  416. if (ret) {
  417. dev_err(dev, "failed to initialize host\n");
  418. goto err2;
  419. }
  420. break;
  421. case DWC3_MODE_DRD:
  422. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
  423. ret = dwc3_host_init(dwc);
  424. if (ret) {
  425. dev_err(dev, "failed to initialize host\n");
  426. goto err2;
  427. }
  428. ret = dwc3_gadget_init(dwc);
  429. if (ret) {
  430. dev_err(dev, "failed to initialize gadget\n");
  431. goto err2;
  432. }
  433. break;
  434. default:
  435. dev_err(dev, "Unsupported mode of operation %d\n", mode);
  436. goto err2;
  437. }
  438. dwc->mode = mode;
  439. ret = dwc3_debugfs_init(dwc);
  440. if (ret) {
  441. dev_err(dev, "failed to initialize debugfs\n");
  442. goto err3;
  443. }
  444. pm_runtime_allow(dev);
  445. return 0;
  446. err3:
  447. switch (mode) {
  448. case DWC3_MODE_DEVICE:
  449. dwc3_gadget_exit(dwc);
  450. break;
  451. case DWC3_MODE_HOST:
  452. dwc3_host_exit(dwc);
  453. break;
  454. case DWC3_MODE_DRD:
  455. dwc3_host_exit(dwc);
  456. dwc3_gadget_exit(dwc);
  457. break;
  458. default:
  459. /* do nothing */
  460. break;
  461. }
  462. err2:
  463. dwc3_event_buffers_cleanup(dwc);
  464. err1:
  465. dwc3_core_exit(dwc);
  466. err0:
  467. dwc3_free_event_buffers(dwc);
  468. return ret;
  469. }
  470. static int dwc3_remove(struct platform_device *pdev)
  471. {
  472. struct dwc3 *dwc = platform_get_drvdata(pdev);
  473. usb_phy_set_suspend(dwc->usb2_phy, 1);
  474. usb_phy_set_suspend(dwc->usb3_phy, 1);
  475. pm_runtime_put(&pdev->dev);
  476. pm_runtime_disable(&pdev->dev);
  477. dwc3_debugfs_exit(dwc);
  478. switch (dwc->mode) {
  479. case DWC3_MODE_DEVICE:
  480. dwc3_gadget_exit(dwc);
  481. break;
  482. case DWC3_MODE_HOST:
  483. dwc3_host_exit(dwc);
  484. break;
  485. case DWC3_MODE_DRD:
  486. dwc3_host_exit(dwc);
  487. dwc3_gadget_exit(dwc);
  488. break;
  489. default:
  490. /* do nothing */
  491. break;
  492. }
  493. dwc3_event_buffers_cleanup(dwc);
  494. dwc3_free_event_buffers(dwc);
  495. dwc3_core_exit(dwc);
  496. return 0;
  497. }
  498. #ifdef CONFIG_OF
  499. static const struct of_device_id of_dwc3_match[] = {
  500. {
  501. .compatible = "synopsys,dwc3"
  502. },
  503. { },
  504. };
  505. MODULE_DEVICE_TABLE(of, of_dwc3_match);
  506. #endif
  507. static struct platform_driver dwc3_driver = {
  508. .probe = dwc3_probe,
  509. .remove = dwc3_remove,
  510. .driver = {
  511. .name = "dwc3",
  512. .of_match_table = of_match_ptr(of_dwc3_match),
  513. },
  514. };
  515. module_platform_driver(dwc3_driver);
  516. MODULE_ALIAS("platform:dwc3");
  517. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  518. MODULE_LICENSE("Dual BSD/GPL");
  519. MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");