core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. ret = dwc3_event_buffers_setup(dwc);
  289. if (ret) {
  290. dev_err(dwc->dev, "failed to setup event buffers\n");
  291. goto err0;
  292. }
  293. return 0;
  294. err0:
  295. return ret;
  296. }
  297. static void dwc3_core_exit(struct dwc3 *dwc)
  298. {
  299. dwc3_event_buffers_cleanup(dwc);
  300. usb_phy_shutdown(dwc->usb2_phy);
  301. usb_phy_shutdown(dwc->usb3_phy);
  302. }
  303. #define DWC3_ALIGN_MASK (16 - 1)
  304. static int dwc3_probe(struct platform_device *pdev)
  305. {
  306. struct device_node *node = pdev->dev.of_node;
  307. struct resource *res;
  308. struct dwc3 *dwc;
  309. struct device *dev = &pdev->dev;
  310. int ret = -ENOMEM;
  311. void __iomem *regs;
  312. void *mem;
  313. u8 mode;
  314. mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
  315. if (!mem) {
  316. dev_err(dev, "not enough memory\n");
  317. return -ENOMEM;
  318. }
  319. dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
  320. dwc->mem = mem;
  321. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  322. if (!res) {
  323. dev_err(dev, "missing IRQ\n");
  324. return -ENODEV;
  325. }
  326. dwc->xhci_resources[1].start = res->start;
  327. dwc->xhci_resources[1].end = res->end;
  328. dwc->xhci_resources[1].flags = res->flags;
  329. dwc->xhci_resources[1].name = res->name;
  330. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  331. if (!res) {
  332. dev_err(dev, "missing memory resource\n");
  333. return -ENODEV;
  334. }
  335. dwc->xhci_resources[0].start = res->start;
  336. dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
  337. DWC3_XHCI_REGS_END;
  338. dwc->xhci_resources[0].flags = res->flags;
  339. dwc->xhci_resources[0].name = res->name;
  340. /*
  341. * Request memory region but exclude xHCI regs,
  342. * since it will be requested by the xhci-plat driver.
  343. */
  344. res = devm_request_mem_region(dev, res->start + DWC3_GLOBALS_REGS_START,
  345. resource_size(res) - DWC3_GLOBALS_REGS_START,
  346. dev_name(dev));
  347. if (!res) {
  348. dev_err(dev, "can't request mem region\n");
  349. return -ENOMEM;
  350. }
  351. regs = devm_ioremap_nocache(dev, res->start, resource_size(res));
  352. if (!regs) {
  353. dev_err(dev, "ioremap failed\n");
  354. return -ENOMEM;
  355. }
  356. if (node) {
  357. dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
  358. dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
  359. } else {
  360. dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
  361. dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
  362. }
  363. if (IS_ERR_OR_NULL(dwc->usb2_phy)) {
  364. dev_err(dev, "no usb2 phy configured\n");
  365. return -EPROBE_DEFER;
  366. }
  367. if (IS_ERR_OR_NULL(dwc->usb3_phy)) {
  368. dev_err(dev, "no usb3 phy configured\n");
  369. return -EPROBE_DEFER;
  370. }
  371. usb_phy_set_suspend(dwc->usb2_phy, 0);
  372. usb_phy_set_suspend(dwc->usb3_phy, 0);
  373. spin_lock_init(&dwc->lock);
  374. platform_set_drvdata(pdev, dwc);
  375. dwc->regs = regs;
  376. dwc->regs_size = resource_size(res);
  377. dwc->dev = dev;
  378. if (!strncmp("super", maximum_speed, 5))
  379. dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
  380. else if (!strncmp("high", maximum_speed, 4))
  381. dwc->maximum_speed = DWC3_DCFG_HIGHSPEED;
  382. else if (!strncmp("full", maximum_speed, 4))
  383. dwc->maximum_speed = DWC3_DCFG_FULLSPEED1;
  384. else if (!strncmp("low", maximum_speed, 3))
  385. dwc->maximum_speed = DWC3_DCFG_LOWSPEED;
  386. else
  387. dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
  388. dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
  389. pm_runtime_enable(dev);
  390. pm_runtime_get_sync(dev);
  391. pm_runtime_forbid(dev);
  392. dwc3_cache_hwparams(dwc);
  393. ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
  394. if (ret) {
  395. dev_err(dwc->dev, "failed to allocate event buffers\n");
  396. ret = -ENOMEM;
  397. goto err0;
  398. }
  399. ret = dwc3_core_init(dwc);
  400. if (ret) {
  401. dev_err(dev, "failed to initialize core\n");
  402. goto err0;
  403. }
  404. mode = DWC3_MODE(dwc->hwparams.hwparams0);
  405. switch (mode) {
  406. case DWC3_MODE_DEVICE:
  407. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
  408. ret = dwc3_gadget_init(dwc);
  409. if (ret) {
  410. dev_err(dev, "failed to initialize gadget\n");
  411. goto err1;
  412. }
  413. break;
  414. case DWC3_MODE_HOST:
  415. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
  416. ret = dwc3_host_init(dwc);
  417. if (ret) {
  418. dev_err(dev, "failed to initialize host\n");
  419. goto err1;
  420. }
  421. break;
  422. case DWC3_MODE_DRD:
  423. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
  424. ret = dwc3_host_init(dwc);
  425. if (ret) {
  426. dev_err(dev, "failed to initialize host\n");
  427. goto err1;
  428. }
  429. ret = dwc3_gadget_init(dwc);
  430. if (ret) {
  431. dev_err(dev, "failed to initialize gadget\n");
  432. goto err1;
  433. }
  434. break;
  435. default:
  436. dev_err(dev, "Unsupported mode of operation %d\n", mode);
  437. goto err1;
  438. }
  439. dwc->mode = mode;
  440. ret = dwc3_debugfs_init(dwc);
  441. if (ret) {
  442. dev_err(dev, "failed to initialize debugfs\n");
  443. goto err2;
  444. }
  445. pm_runtime_allow(dev);
  446. return 0;
  447. err2:
  448. switch (mode) {
  449. case DWC3_MODE_DEVICE:
  450. dwc3_gadget_exit(dwc);
  451. break;
  452. case DWC3_MODE_HOST:
  453. dwc3_host_exit(dwc);
  454. break;
  455. case DWC3_MODE_DRD:
  456. dwc3_host_exit(dwc);
  457. dwc3_gadget_exit(dwc);
  458. break;
  459. default:
  460. /* do nothing */
  461. break;
  462. }
  463. err1:
  464. dwc3_core_exit(dwc);
  465. err0:
  466. dwc3_free_event_buffers(dwc);
  467. return ret;
  468. }
  469. static int dwc3_remove(struct platform_device *pdev)
  470. {
  471. struct dwc3 *dwc = platform_get_drvdata(pdev);
  472. usb_phy_set_suspend(dwc->usb2_phy, 1);
  473. usb_phy_set_suspend(dwc->usb3_phy, 1);
  474. pm_runtime_put(&pdev->dev);
  475. pm_runtime_disable(&pdev->dev);
  476. dwc3_debugfs_exit(dwc);
  477. switch (dwc->mode) {
  478. case DWC3_MODE_DEVICE:
  479. dwc3_gadget_exit(dwc);
  480. break;
  481. case DWC3_MODE_HOST:
  482. dwc3_host_exit(dwc);
  483. break;
  484. case DWC3_MODE_DRD:
  485. dwc3_host_exit(dwc);
  486. dwc3_gadget_exit(dwc);
  487. break;
  488. default:
  489. /* do nothing */
  490. break;
  491. }
  492. dwc3_free_event_buffers(dwc);
  493. dwc3_core_exit(dwc);
  494. return 0;
  495. }
  496. #ifdef CONFIG_OF
  497. static const struct of_device_id of_dwc3_match[] = {
  498. {
  499. .compatible = "synopsys,dwc3"
  500. },
  501. { },
  502. };
  503. MODULE_DEVICE_TABLE(of, of_dwc3_match);
  504. #endif
  505. static struct platform_driver dwc3_driver = {
  506. .probe = dwc3_probe,
  507. .remove = dwc3_remove,
  508. .driver = {
  509. .name = "dwc3",
  510. .of_match_table = of_match_ptr(of_dwc3_match),
  511. },
  512. };
  513. module_platform_driver(dwc3_driver);
  514. MODULE_ALIAS("platform:dwc3");
  515. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  516. MODULE_LICENSE("Dual BSD/GPL");
  517. MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");