core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. #define DWC3_DEVS_POSSIBLE 32
  63. static DECLARE_BITMAP(dwc3_devs, DWC3_DEVS_POSSIBLE);
  64. int dwc3_get_device_id(void)
  65. {
  66. int id;
  67. again:
  68. id = find_first_zero_bit(dwc3_devs, DWC3_DEVS_POSSIBLE);
  69. if (id < DWC3_DEVS_POSSIBLE) {
  70. int old;
  71. old = test_and_set_bit(id, dwc3_devs);
  72. if (old)
  73. goto again;
  74. } else {
  75. pr_err("dwc3: no space for new device\n");
  76. id = -ENOMEM;
  77. }
  78. return id;
  79. }
  80. EXPORT_SYMBOL_GPL(dwc3_get_device_id);
  81. void dwc3_put_device_id(int id)
  82. {
  83. int ret;
  84. if (id < 0)
  85. return;
  86. ret = test_bit(id, dwc3_devs);
  87. WARN(!ret, "dwc3: ID %d not in use\n", id);
  88. clear_bit(id, dwc3_devs);
  89. }
  90. EXPORT_SYMBOL_GPL(dwc3_put_device_id);
  91. void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
  92. {
  93. u32 reg;
  94. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  95. reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
  96. reg |= DWC3_GCTL_PRTCAPDIR(mode);
  97. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  98. }
  99. /**
  100. * dwc3_core_soft_reset - Issues core soft reset and PHY reset
  101. * @dwc: pointer to our context structure
  102. */
  103. static void dwc3_core_soft_reset(struct dwc3 *dwc)
  104. {
  105. u32 reg;
  106. /* Before Resetting PHY, put Core in Reset */
  107. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  108. reg |= DWC3_GCTL_CORESOFTRESET;
  109. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  110. /* Assert USB3 PHY reset */
  111. reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
  112. reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
  113. dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
  114. /* Assert USB2 PHY reset */
  115. reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
  116. reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
  117. dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
  118. usb_phy_init(dwc->usb2_phy);
  119. usb_phy_init(dwc->usb3_phy);
  120. mdelay(100);
  121. /* Clear USB3 PHY reset */
  122. reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
  123. reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
  124. dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
  125. /* Clear USB2 PHY reset */
  126. reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
  127. reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
  128. dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
  129. mdelay(100);
  130. /* After PHYs are stable we can take Core out of reset state */
  131. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  132. reg &= ~DWC3_GCTL_CORESOFTRESET;
  133. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  134. }
  135. /**
  136. * dwc3_free_one_event_buffer - Frees one event buffer
  137. * @dwc: Pointer to our controller context structure
  138. * @evt: Pointer to event buffer to be freed
  139. */
  140. static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
  141. struct dwc3_event_buffer *evt)
  142. {
  143. dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
  144. kfree(evt);
  145. }
  146. /**
  147. * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
  148. * @dwc: Pointer to our controller context structure
  149. * @length: size of the event buffer
  150. *
  151. * Returns a pointer to the allocated event buffer structure on success
  152. * otherwise ERR_PTR(errno).
  153. */
  154. static struct dwc3_event_buffer *__devinit
  155. dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length)
  156. {
  157. struct dwc3_event_buffer *evt;
  158. evt = kzalloc(sizeof(*evt), GFP_KERNEL);
  159. if (!evt)
  160. return ERR_PTR(-ENOMEM);
  161. evt->dwc = dwc;
  162. evt->length = length;
  163. evt->buf = dma_alloc_coherent(dwc->dev, length,
  164. &evt->dma, GFP_KERNEL);
  165. if (!evt->buf) {
  166. kfree(evt);
  167. return ERR_PTR(-ENOMEM);
  168. }
  169. return evt;
  170. }
  171. /**
  172. * dwc3_free_event_buffers - frees all allocated event buffers
  173. * @dwc: Pointer to our controller context structure
  174. */
  175. static void dwc3_free_event_buffers(struct dwc3 *dwc)
  176. {
  177. struct dwc3_event_buffer *evt;
  178. int i;
  179. for (i = 0; i < dwc->num_event_buffers; i++) {
  180. evt = dwc->ev_buffs[i];
  181. if (evt)
  182. dwc3_free_one_event_buffer(dwc, evt);
  183. }
  184. kfree(dwc->ev_buffs);
  185. }
  186. /**
  187. * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
  188. * @dwc: pointer to our controller context structure
  189. * @length: size of event buffer
  190. *
  191. * Returns 0 on success otherwise negative errno. In the error case, dwc
  192. * may contain some buffers allocated but not all which were requested.
  193. */
  194. static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
  195. {
  196. int num;
  197. int i;
  198. num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
  199. dwc->num_event_buffers = num;
  200. dwc->ev_buffs = kzalloc(sizeof(*dwc->ev_buffs) * num, GFP_KERNEL);
  201. if (!dwc->ev_buffs) {
  202. dev_err(dwc->dev, "can't allocate event buffers array\n");
  203. return -ENOMEM;
  204. }
  205. for (i = 0; i < num; i++) {
  206. struct dwc3_event_buffer *evt;
  207. evt = dwc3_alloc_one_event_buffer(dwc, length);
  208. if (IS_ERR(evt)) {
  209. dev_err(dwc->dev, "can't allocate event buffer\n");
  210. return PTR_ERR(evt);
  211. }
  212. dwc->ev_buffs[i] = evt;
  213. }
  214. return 0;
  215. }
  216. /**
  217. * dwc3_event_buffers_setup - setup our allocated event buffers
  218. * @dwc: pointer to our controller context structure
  219. *
  220. * Returns 0 on success otherwise negative errno.
  221. */
  222. static int dwc3_event_buffers_setup(struct dwc3 *dwc)
  223. {
  224. struct dwc3_event_buffer *evt;
  225. int n;
  226. for (n = 0; n < dwc->num_event_buffers; n++) {
  227. evt = dwc->ev_buffs[n];
  228. dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
  229. evt->buf, (unsigned long long) evt->dma,
  230. evt->length);
  231. evt->lpos = 0;
  232. dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
  233. lower_32_bits(evt->dma));
  234. dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
  235. upper_32_bits(evt->dma));
  236. dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
  237. evt->length & 0xffff);
  238. dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  239. }
  240. return 0;
  241. }
  242. static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
  243. {
  244. struct dwc3_event_buffer *evt;
  245. int n;
  246. for (n = 0; n < dwc->num_event_buffers; n++) {
  247. evt = dwc->ev_buffs[n];
  248. evt->lpos = 0;
  249. dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
  250. dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
  251. dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0);
  252. dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  253. }
  254. }
  255. static void __devinit dwc3_cache_hwparams(struct dwc3 *dwc)
  256. {
  257. struct dwc3_hwparams *parms = &dwc->hwparams;
  258. parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
  259. parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
  260. parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
  261. parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
  262. parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
  263. parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
  264. parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
  265. parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
  266. parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
  267. }
  268. /**
  269. * dwc3_core_init - Low-level initialization of DWC3 Core
  270. * @dwc: Pointer to our controller context structure
  271. *
  272. * Returns 0 on success otherwise negative errno.
  273. */
  274. static int __devinit dwc3_core_init(struct dwc3 *dwc)
  275. {
  276. unsigned long timeout;
  277. u32 reg;
  278. int ret;
  279. reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
  280. /* This should read as U3 followed by revision number */
  281. if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) {
  282. dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
  283. ret = -ENODEV;
  284. goto err0;
  285. }
  286. dwc->revision = reg;
  287. /* issue device SoftReset too */
  288. timeout = jiffies + msecs_to_jiffies(500);
  289. dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
  290. do {
  291. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  292. if (!(reg & DWC3_DCTL_CSFTRST))
  293. break;
  294. if (time_after(jiffies, timeout)) {
  295. dev_err(dwc->dev, "Reset Timed Out\n");
  296. ret = -ETIMEDOUT;
  297. goto err0;
  298. }
  299. cpu_relax();
  300. } while (true);
  301. dwc3_core_soft_reset(dwc);
  302. dwc3_cache_hwparams(dwc);
  303. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  304. reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
  305. reg &= ~DWC3_GCTL_DISSCRAMBLE;
  306. switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
  307. case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
  308. reg &= ~DWC3_GCTL_DSBLCLKGTNG;
  309. break;
  310. default:
  311. dev_dbg(dwc->dev, "No power optimization available\n");
  312. }
  313. /*
  314. * WORKAROUND: DWC3 revisions <1.90a have a bug
  315. * where the device can fail to connect at SuperSpeed
  316. * and falls back to high-speed mode which causes
  317. * the device to enter a Connect/Disconnect loop
  318. */
  319. if (dwc->revision < DWC3_REVISION_190A)
  320. reg |= DWC3_GCTL_U2RSTECN;
  321. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  322. ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
  323. if (ret) {
  324. dev_err(dwc->dev, "failed to allocate event buffers\n");
  325. ret = -ENOMEM;
  326. goto err1;
  327. }
  328. ret = dwc3_event_buffers_setup(dwc);
  329. if (ret) {
  330. dev_err(dwc->dev, "failed to setup event buffers\n");
  331. goto err1;
  332. }
  333. return 0;
  334. err1:
  335. dwc3_free_event_buffers(dwc);
  336. err0:
  337. return ret;
  338. }
  339. static void dwc3_core_exit(struct dwc3 *dwc)
  340. {
  341. dwc3_event_buffers_cleanup(dwc);
  342. dwc3_free_event_buffers(dwc);
  343. }
  344. #define DWC3_ALIGN_MASK (16 - 1)
  345. static int __devinit dwc3_probe(struct platform_device *pdev)
  346. {
  347. struct device_node *node = pdev->dev.of_node;
  348. struct resource *res;
  349. struct dwc3 *dwc;
  350. struct device *dev = &pdev->dev;
  351. int ret = -ENOMEM;
  352. void __iomem *regs;
  353. void *mem;
  354. u8 mode;
  355. mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
  356. if (!mem) {
  357. dev_err(dev, "not enough memory\n");
  358. return -ENOMEM;
  359. }
  360. dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
  361. dwc->mem = mem;
  362. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  363. if (!res) {
  364. dev_err(dev, "missing IRQ\n");
  365. return -ENODEV;
  366. }
  367. dwc->xhci_resources[1] = *res;
  368. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  369. if (!res) {
  370. dev_err(dev, "missing memory resource\n");
  371. return -ENODEV;
  372. }
  373. dwc->xhci_resources[0] = *res;
  374. dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
  375. DWC3_XHCI_REGS_END;
  376. /*
  377. * Request memory region but exclude xHCI regs,
  378. * since it will be requested by the xhci-plat driver.
  379. */
  380. res = devm_request_mem_region(dev, res->start + DWC3_GLOBALS_REGS_START,
  381. resource_size(res) - DWC3_GLOBALS_REGS_START,
  382. dev_name(dev));
  383. if (!res) {
  384. dev_err(dev, "can't request mem region\n");
  385. return -ENOMEM;
  386. }
  387. regs = devm_ioremap(dev, res->start, resource_size(res));
  388. if (!regs) {
  389. dev_err(dev, "ioremap failed\n");
  390. return -ENOMEM;
  391. }
  392. dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
  393. if (IS_ERR_OR_NULL(dwc->usb2_phy)) {
  394. dev_err(dev, "no usb2 phy configured\n");
  395. return -EPROBE_DEFER;
  396. }
  397. dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
  398. if (IS_ERR_OR_NULL(dwc->usb3_phy)) {
  399. dev_err(dev, "no usb3 phy configured\n");
  400. return -EPROBE_DEFER;
  401. }
  402. spin_lock_init(&dwc->lock);
  403. platform_set_drvdata(pdev, dwc);
  404. dwc->regs = regs;
  405. dwc->regs_size = resource_size(res);
  406. dwc->dev = dev;
  407. if (!strncmp("super", maximum_speed, 5))
  408. dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
  409. else if (!strncmp("high", maximum_speed, 4))
  410. dwc->maximum_speed = DWC3_DCFG_HIGHSPEED;
  411. else if (!strncmp("full", maximum_speed, 4))
  412. dwc->maximum_speed = DWC3_DCFG_FULLSPEED1;
  413. else if (!strncmp("low", maximum_speed, 3))
  414. dwc->maximum_speed = DWC3_DCFG_LOWSPEED;
  415. else
  416. dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
  417. if (of_get_property(node, "tx-fifo-resize", NULL))
  418. dwc->needs_fifo_resize = true;
  419. pm_runtime_enable(dev);
  420. pm_runtime_get_sync(dev);
  421. pm_runtime_forbid(dev);
  422. ret = dwc3_core_init(dwc);
  423. if (ret) {
  424. dev_err(dev, "failed to initialize core\n");
  425. return ret;
  426. }
  427. mode = DWC3_MODE(dwc->hwparams.hwparams0);
  428. switch (mode) {
  429. case DWC3_MODE_DEVICE:
  430. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
  431. ret = dwc3_gadget_init(dwc);
  432. if (ret) {
  433. dev_err(dev, "failed to initialize gadget\n");
  434. goto err1;
  435. }
  436. break;
  437. case DWC3_MODE_HOST:
  438. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
  439. ret = dwc3_host_init(dwc);
  440. if (ret) {
  441. dev_err(dev, "failed to initialize host\n");
  442. goto err1;
  443. }
  444. break;
  445. case DWC3_MODE_DRD:
  446. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
  447. ret = dwc3_host_init(dwc);
  448. if (ret) {
  449. dev_err(dev, "failed to initialize host\n");
  450. goto err1;
  451. }
  452. ret = dwc3_gadget_init(dwc);
  453. if (ret) {
  454. dev_err(dev, "failed to initialize gadget\n");
  455. goto err1;
  456. }
  457. break;
  458. default:
  459. dev_err(dev, "Unsupported mode of operation %d\n", mode);
  460. goto err1;
  461. }
  462. dwc->mode = mode;
  463. ret = dwc3_debugfs_init(dwc);
  464. if (ret) {
  465. dev_err(dev, "failed to initialize debugfs\n");
  466. goto err2;
  467. }
  468. pm_runtime_allow(dev);
  469. return 0;
  470. err2:
  471. switch (mode) {
  472. case DWC3_MODE_DEVICE:
  473. dwc3_gadget_exit(dwc);
  474. break;
  475. case DWC3_MODE_HOST:
  476. dwc3_host_exit(dwc);
  477. break;
  478. case DWC3_MODE_DRD:
  479. dwc3_host_exit(dwc);
  480. dwc3_gadget_exit(dwc);
  481. break;
  482. default:
  483. /* do nothing */
  484. break;
  485. }
  486. err1:
  487. dwc3_core_exit(dwc);
  488. return ret;
  489. }
  490. static int __devexit dwc3_remove(struct platform_device *pdev)
  491. {
  492. struct dwc3 *dwc = platform_get_drvdata(pdev);
  493. struct resource *res;
  494. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  495. pm_runtime_put(&pdev->dev);
  496. pm_runtime_disable(&pdev->dev);
  497. dwc3_debugfs_exit(dwc);
  498. switch (dwc->mode) {
  499. case DWC3_MODE_DEVICE:
  500. dwc3_gadget_exit(dwc);
  501. break;
  502. case DWC3_MODE_HOST:
  503. dwc3_host_exit(dwc);
  504. break;
  505. case DWC3_MODE_DRD:
  506. dwc3_host_exit(dwc);
  507. dwc3_gadget_exit(dwc);
  508. break;
  509. default:
  510. /* do nothing */
  511. break;
  512. }
  513. dwc3_core_exit(dwc);
  514. return 0;
  515. }
  516. static struct platform_driver dwc3_driver = {
  517. .probe = dwc3_probe,
  518. .remove = __devexit_p(dwc3_remove),
  519. .driver = {
  520. .name = "dwc3",
  521. },
  522. };
  523. module_platform_driver(dwc3_driver);
  524. MODULE_ALIAS("platform:dwc3");
  525. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  526. MODULE_LICENSE("Dual BSD/GPL");
  527. MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");