core.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  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. * 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. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/version.h>
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/slab.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/ioport.h>
  30. #include <linux/io.h>
  31. #include <linux/list.h>
  32. #include <linux/delay.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/of.h>
  35. #include <linux/acpi.h>
  36. #include <linux/pinctrl/consumer.h>
  37. #include <linux/usb/ch9.h>
  38. #include <linux/usb/gadget.h>
  39. #include <linux/usb/of.h>
  40. #include <linux/usb/otg.h>
  41. #include "platform_data.h"
  42. #include "core.h"
  43. #include "gadget.h"
  44. #include "io.h"
  45. #include "debug.h"
  46. /* -------------------------------------------------------------------------- */
  47. void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
  48. {
  49. u32 reg;
  50. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  51. reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
  52. reg |= DWC3_GCTL_PRTCAPDIR(mode);
  53. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  54. }
  55. /**
  56. * dwc3_core_soft_reset - Issues core soft reset and PHY reset
  57. * @dwc: pointer to our context structure
  58. */
  59. static int dwc3_core_soft_reset(struct dwc3 *dwc)
  60. {
  61. u32 reg;
  62. int retries = 1000;
  63. int ret;
  64. usb_phy_init(dwc->usb2_phy);
  65. usb_phy_init(dwc->usb3_phy);
  66. ret = phy_init(dwc->usb2_generic_phy);
  67. if (ret < 0)
  68. return ret;
  69. ret = phy_init(dwc->usb3_generic_phy);
  70. if (ret < 0) {
  71. phy_exit(dwc->usb2_generic_phy);
  72. return ret;
  73. }
  74. /*
  75. * We're resetting only the device side because, if we're in host mode,
  76. * XHCI driver will reset the host block. If dwc3 was configured for
  77. * host-only mode, then we can return early.
  78. */
  79. if (dwc->dr_mode == USB_DR_MODE_HOST)
  80. return 0;
  81. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  82. reg |= DWC3_DCTL_CSFTRST;
  83. dwc3_writel(dwc->regs, DWC3_DCTL, reg);
  84. do {
  85. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  86. if (!(reg & DWC3_DCTL_CSFTRST))
  87. return 0;
  88. udelay(1);
  89. } while (--retries);
  90. return -ETIMEDOUT;
  91. }
  92. /**
  93. * dwc3_soft_reset - Issue soft reset
  94. * @dwc: Pointer to our controller context structure
  95. */
  96. static int dwc3_soft_reset(struct dwc3 *dwc)
  97. {
  98. unsigned long timeout;
  99. u32 reg;
  100. timeout = jiffies + msecs_to_jiffies(500);
  101. dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
  102. do {
  103. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  104. if (!(reg & DWC3_DCTL_CSFTRST))
  105. break;
  106. if (time_after(jiffies, timeout)) {
  107. dev_err(dwc->dev, "Reset Timed Out\n");
  108. return -ETIMEDOUT;
  109. }
  110. cpu_relax();
  111. } while (true);
  112. return 0;
  113. }
  114. /*
  115. * dwc3_frame_length_adjustment - Adjusts frame length if required
  116. * @dwc3: Pointer to our controller context structure
  117. * @fladj: Value of GFLADJ_30MHZ to adjust frame length
  118. */
  119. static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj)
  120. {
  121. u32 reg;
  122. u32 dft;
  123. if (dwc->revision < DWC3_REVISION_250A)
  124. return;
  125. if (fladj == 0)
  126. return;
  127. reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
  128. dft = reg & DWC3_GFLADJ_30MHZ_MASK;
  129. if (!dev_WARN_ONCE(dwc->dev, dft == fladj,
  130. "request value same as default, ignoring\n")) {
  131. reg &= ~DWC3_GFLADJ_30MHZ_MASK;
  132. reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | fladj;
  133. dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
  134. }
  135. }
  136. /**
  137. * dwc3_free_one_event_buffer - Frees one event buffer
  138. * @dwc: Pointer to our controller context structure
  139. * @evt: Pointer to event buffer to be freed
  140. */
  141. static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
  142. struct dwc3_event_buffer *evt)
  143. {
  144. dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
  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 *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
  155. unsigned length)
  156. {
  157. struct dwc3_event_buffer *evt;
  158. evt = devm_kzalloc(dwc->dev, 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. return ERR_PTR(-ENOMEM);
  167. return evt;
  168. }
  169. /**
  170. * dwc3_free_event_buffers - frees all allocated event buffers
  171. * @dwc: Pointer to our controller context structure
  172. */
  173. static void dwc3_free_event_buffers(struct dwc3 *dwc)
  174. {
  175. struct dwc3_event_buffer *evt;
  176. int i;
  177. for (i = 0; i < dwc->num_event_buffers; i++) {
  178. evt = dwc->ev_buffs[i];
  179. if (evt)
  180. dwc3_free_one_event_buffer(dwc, evt);
  181. }
  182. }
  183. /**
  184. * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
  185. * @dwc: pointer to our controller context structure
  186. * @length: size of event buffer
  187. *
  188. * Returns 0 on success otherwise negative errno. In the error case, dwc
  189. * may contain some buffers allocated but not all which were requested.
  190. */
  191. static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
  192. {
  193. int num;
  194. int i;
  195. num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
  196. dwc->num_event_buffers = num;
  197. dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
  198. GFP_KERNEL);
  199. if (!dwc->ev_buffs)
  200. return -ENOMEM;
  201. for (i = 0; i < num; i++) {
  202. struct dwc3_event_buffer *evt;
  203. evt = dwc3_alloc_one_event_buffer(dwc, length);
  204. if (IS_ERR(evt)) {
  205. dev_err(dwc->dev, "can't allocate event buffer\n");
  206. return PTR_ERR(evt);
  207. }
  208. dwc->ev_buffs[i] = evt;
  209. }
  210. return 0;
  211. }
  212. /**
  213. * dwc3_event_buffers_setup - setup our allocated event buffers
  214. * @dwc: pointer to our controller context structure
  215. *
  216. * Returns 0 on success otherwise negative errno.
  217. */
  218. static int dwc3_event_buffers_setup(struct dwc3 *dwc)
  219. {
  220. struct dwc3_event_buffer *evt;
  221. int n;
  222. for (n = 0; n < dwc->num_event_buffers; n++) {
  223. evt = dwc->ev_buffs[n];
  224. dwc3_trace(trace_dwc3_core,
  225. "Event buf %p dma %08llx length %d\n",
  226. evt->buf, (unsigned long long) evt->dma,
  227. evt->length);
  228. evt->lpos = 0;
  229. dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
  230. lower_32_bits(evt->dma));
  231. dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
  232. upper_32_bits(evt->dma));
  233. dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
  234. DWC3_GEVNTSIZ_SIZE(evt->length));
  235. dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  236. }
  237. return 0;
  238. }
  239. static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
  240. {
  241. struct dwc3_event_buffer *evt;
  242. int n;
  243. for (n = 0; n < dwc->num_event_buffers; n++) {
  244. evt = dwc->ev_buffs[n];
  245. evt->lpos = 0;
  246. dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
  247. dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
  248. dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
  249. | DWC3_GEVNTSIZ_SIZE(0));
  250. dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  251. }
  252. }
  253. static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
  254. {
  255. if (!dwc->has_hibernation)
  256. return 0;
  257. if (!dwc->nr_scratch)
  258. return 0;
  259. dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
  260. DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
  261. if (!dwc->scratchbuf)
  262. return -ENOMEM;
  263. return 0;
  264. }
  265. static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
  266. {
  267. dma_addr_t scratch_addr;
  268. u32 param;
  269. int ret;
  270. if (!dwc->has_hibernation)
  271. return 0;
  272. if (!dwc->nr_scratch)
  273. return 0;
  274. /* should never fall here */
  275. if (!WARN_ON(dwc->scratchbuf))
  276. return 0;
  277. scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
  278. dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
  279. DMA_BIDIRECTIONAL);
  280. if (dma_mapping_error(dwc->dev, scratch_addr)) {
  281. dev_err(dwc->dev, "failed to map scratch buffer\n");
  282. ret = -EFAULT;
  283. goto err0;
  284. }
  285. dwc->scratch_addr = scratch_addr;
  286. param = lower_32_bits(scratch_addr);
  287. ret = dwc3_send_gadget_generic_command(dwc,
  288. DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
  289. if (ret < 0)
  290. goto err1;
  291. param = upper_32_bits(scratch_addr);
  292. ret = dwc3_send_gadget_generic_command(dwc,
  293. DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
  294. if (ret < 0)
  295. goto err1;
  296. return 0;
  297. err1:
  298. dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
  299. DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
  300. err0:
  301. return ret;
  302. }
  303. static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
  304. {
  305. if (!dwc->has_hibernation)
  306. return;
  307. if (!dwc->nr_scratch)
  308. return;
  309. /* should never fall here */
  310. if (!WARN_ON(dwc->scratchbuf))
  311. return;
  312. dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
  313. DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
  314. kfree(dwc->scratchbuf);
  315. }
  316. static void dwc3_core_num_eps(struct dwc3 *dwc)
  317. {
  318. struct dwc3_hwparams *parms = &dwc->hwparams;
  319. dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
  320. dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
  321. dwc3_trace(trace_dwc3_core, "found %d IN and %d OUT endpoints",
  322. dwc->num_in_eps, dwc->num_out_eps);
  323. }
  324. static void dwc3_cache_hwparams(struct dwc3 *dwc)
  325. {
  326. struct dwc3_hwparams *parms = &dwc->hwparams;
  327. parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
  328. parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
  329. parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
  330. parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
  331. parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
  332. parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
  333. parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
  334. parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
  335. parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
  336. }
  337. /**
  338. * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
  339. * @dwc: Pointer to our controller context structure
  340. *
  341. * Returns 0 on success. The USB PHY interfaces are configured but not
  342. * initialized. The PHY interfaces and the PHYs get initialized together with
  343. * the core in dwc3_core_init.
  344. */
  345. static int dwc3_phy_setup(struct dwc3 *dwc)
  346. {
  347. u32 reg;
  348. int ret;
  349. reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
  350. /*
  351. * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
  352. * to '0' during coreConsultant configuration. So default value
  353. * will be '0' when the core is reset. Application needs to set it
  354. * to '1' after the core initialization is completed.
  355. */
  356. if (dwc->revision > DWC3_REVISION_194A)
  357. reg |= DWC3_GUSB3PIPECTL_SUSPHY;
  358. if (dwc->u2ss_inp3_quirk)
  359. reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
  360. if (dwc->req_p1p2p3_quirk)
  361. reg |= DWC3_GUSB3PIPECTL_REQP1P2P3;
  362. if (dwc->del_p1p2p3_quirk)
  363. reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN;
  364. if (dwc->del_phy_power_chg_quirk)
  365. reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE;
  366. if (dwc->lfps_filter_quirk)
  367. reg |= DWC3_GUSB3PIPECTL_LFPSFILT;
  368. if (dwc->rx_detect_poll_quirk)
  369. reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL;
  370. if (dwc->tx_de_emphasis_quirk)
  371. reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis);
  372. if (dwc->dis_u3_susphy_quirk)
  373. reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
  374. dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
  375. reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
  376. /* Select the HS PHY interface */
  377. switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
  378. case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
  379. if (dwc->hsphy_interface &&
  380. !strncmp(dwc->hsphy_interface, "utmi", 4)) {
  381. reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI;
  382. break;
  383. } else if (dwc->hsphy_interface &&
  384. !strncmp(dwc->hsphy_interface, "ulpi", 4)) {
  385. reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
  386. dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
  387. } else {
  388. /* Relying on default value. */
  389. if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI))
  390. break;
  391. }
  392. /* FALLTHROUGH */
  393. case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
  394. /* Making sure the interface and PHY are operational */
  395. ret = dwc3_soft_reset(dwc);
  396. if (ret)
  397. return ret;
  398. udelay(1);
  399. ret = dwc3_ulpi_init(dwc);
  400. if (ret)
  401. return ret;
  402. /* FALLTHROUGH */
  403. default:
  404. break;
  405. }
  406. /*
  407. * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
  408. * '0' during coreConsultant configuration. So default value will
  409. * be '0' when the core is reset. Application needs to set it to
  410. * '1' after the core initialization is completed.
  411. */
  412. if (dwc->revision > DWC3_REVISION_194A)
  413. reg |= DWC3_GUSB2PHYCFG_SUSPHY;
  414. if (dwc->dis_u2_susphy_quirk)
  415. reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
  416. if (dwc->dis_enblslpm_quirk)
  417. reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
  418. dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
  419. return 0;
  420. }
  421. /**
  422. * dwc3_core_init - Low-level initialization of DWC3 Core
  423. * @dwc: Pointer to our controller context structure
  424. *
  425. * Returns 0 on success otherwise negative errno.
  426. */
  427. static int dwc3_core_init(struct dwc3 *dwc)
  428. {
  429. u32 hwparams4 = dwc->hwparams.hwparams4;
  430. u32 reg;
  431. int ret;
  432. reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
  433. /* This should read as U3 followed by revision number */
  434. if ((reg & DWC3_GSNPSID_MASK) == 0x55330000) {
  435. /* Detected DWC_usb3 IP */
  436. dwc->revision = reg;
  437. } else if ((reg & DWC3_GSNPSID_MASK) == 0x33310000) {
  438. /* Detected DWC_usb31 IP */
  439. dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
  440. dwc->revision |= DWC3_REVISION_IS_DWC31;
  441. } else {
  442. dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
  443. ret = -ENODEV;
  444. goto err0;
  445. }
  446. /*
  447. * Write Linux Version Code to our GUID register so it's easy to figure
  448. * out which kernel version a bug was found.
  449. */
  450. dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
  451. /* Handle USB2.0-only core configuration */
  452. if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
  453. DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
  454. if (dwc->maximum_speed == USB_SPEED_SUPER)
  455. dwc->maximum_speed = USB_SPEED_HIGH;
  456. }
  457. /* issue device SoftReset too */
  458. ret = dwc3_soft_reset(dwc);
  459. if (ret)
  460. goto err0;
  461. ret = dwc3_core_soft_reset(dwc);
  462. if (ret)
  463. goto err0;
  464. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  465. reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
  466. switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
  467. case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
  468. /**
  469. * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
  470. * issue which would cause xHCI compliance tests to fail.
  471. *
  472. * Because of that we cannot enable clock gating on such
  473. * configurations.
  474. *
  475. * Refers to:
  476. *
  477. * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
  478. * SOF/ITP Mode Used
  479. */
  480. if ((dwc->dr_mode == USB_DR_MODE_HOST ||
  481. dwc->dr_mode == USB_DR_MODE_OTG) &&
  482. (dwc->revision >= DWC3_REVISION_210A &&
  483. dwc->revision <= DWC3_REVISION_250A))
  484. reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
  485. else
  486. reg &= ~DWC3_GCTL_DSBLCLKGTNG;
  487. break;
  488. case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
  489. /* enable hibernation here */
  490. dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
  491. /*
  492. * REVISIT Enabling this bit so that host-mode hibernation
  493. * will work. Device-mode hibernation is not yet implemented.
  494. */
  495. reg |= DWC3_GCTL_GBLHIBERNATIONEN;
  496. break;
  497. default:
  498. dwc3_trace(trace_dwc3_core, "No power optimization available\n");
  499. }
  500. /* check if current dwc3 is on simulation board */
  501. if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
  502. dwc3_trace(trace_dwc3_core,
  503. "running on FPGA platform\n");
  504. dwc->is_fpga = true;
  505. }
  506. WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
  507. "disable_scramble cannot be used on non-FPGA builds\n");
  508. if (dwc->disable_scramble_quirk && dwc->is_fpga)
  509. reg |= DWC3_GCTL_DISSCRAMBLE;
  510. else
  511. reg &= ~DWC3_GCTL_DISSCRAMBLE;
  512. if (dwc->u2exit_lfps_quirk)
  513. reg |= DWC3_GCTL_U2EXIT_LFPS;
  514. /*
  515. * WORKAROUND: DWC3 revisions <1.90a have a bug
  516. * where the device can fail to connect at SuperSpeed
  517. * and falls back to high-speed mode which causes
  518. * the device to enter a Connect/Disconnect loop
  519. */
  520. if (dwc->revision < DWC3_REVISION_190A)
  521. reg |= DWC3_GCTL_U2RSTECN;
  522. dwc3_core_num_eps(dwc);
  523. dwc3_writel(dwc->regs, DWC3_GCTL, reg);
  524. ret = dwc3_alloc_scratch_buffers(dwc);
  525. if (ret)
  526. goto err1;
  527. ret = dwc3_setup_scratch_buffers(dwc);
  528. if (ret)
  529. goto err2;
  530. return 0;
  531. err2:
  532. dwc3_free_scratch_buffers(dwc);
  533. err1:
  534. usb_phy_shutdown(dwc->usb2_phy);
  535. usb_phy_shutdown(dwc->usb3_phy);
  536. phy_exit(dwc->usb2_generic_phy);
  537. phy_exit(dwc->usb3_generic_phy);
  538. err0:
  539. return ret;
  540. }
  541. static void dwc3_core_exit(struct dwc3 *dwc)
  542. {
  543. dwc3_free_scratch_buffers(dwc);
  544. usb_phy_shutdown(dwc->usb2_phy);
  545. usb_phy_shutdown(dwc->usb3_phy);
  546. phy_exit(dwc->usb2_generic_phy);
  547. phy_exit(dwc->usb3_generic_phy);
  548. }
  549. static int dwc3_core_get_phy(struct dwc3 *dwc)
  550. {
  551. struct device *dev = dwc->dev;
  552. struct device_node *node = dev->of_node;
  553. int ret;
  554. if (node) {
  555. dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
  556. dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
  557. } else {
  558. dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
  559. dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
  560. }
  561. if (IS_ERR(dwc->usb2_phy)) {
  562. ret = PTR_ERR(dwc->usb2_phy);
  563. if (ret == -ENXIO || ret == -ENODEV) {
  564. dwc->usb2_phy = NULL;
  565. } else if (ret == -EPROBE_DEFER) {
  566. return ret;
  567. } else {
  568. dev_err(dev, "no usb2 phy configured\n");
  569. return ret;
  570. }
  571. }
  572. if (IS_ERR(dwc->usb3_phy)) {
  573. ret = PTR_ERR(dwc->usb3_phy);
  574. if (ret == -ENXIO || ret == -ENODEV) {
  575. dwc->usb3_phy = NULL;
  576. } else if (ret == -EPROBE_DEFER) {
  577. return ret;
  578. } else {
  579. dev_err(dev, "no usb3 phy configured\n");
  580. return ret;
  581. }
  582. }
  583. dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
  584. if (IS_ERR(dwc->usb2_generic_phy)) {
  585. ret = PTR_ERR(dwc->usb2_generic_phy);
  586. if (ret == -ENOSYS || ret == -ENODEV) {
  587. dwc->usb2_generic_phy = NULL;
  588. } else if (ret == -EPROBE_DEFER) {
  589. return ret;
  590. } else {
  591. dev_err(dev, "no usb2 phy configured\n");
  592. return ret;
  593. }
  594. }
  595. dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
  596. if (IS_ERR(dwc->usb3_generic_phy)) {
  597. ret = PTR_ERR(dwc->usb3_generic_phy);
  598. if (ret == -ENOSYS || ret == -ENODEV) {
  599. dwc->usb3_generic_phy = NULL;
  600. } else if (ret == -EPROBE_DEFER) {
  601. return ret;
  602. } else {
  603. dev_err(dev, "no usb3 phy configured\n");
  604. return ret;
  605. }
  606. }
  607. return 0;
  608. }
  609. static int dwc3_core_init_mode(struct dwc3 *dwc)
  610. {
  611. struct device *dev = dwc->dev;
  612. int ret;
  613. switch (dwc->dr_mode) {
  614. case USB_DR_MODE_PERIPHERAL:
  615. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
  616. ret = dwc3_gadget_init(dwc);
  617. if (ret) {
  618. dev_err(dev, "failed to initialize gadget\n");
  619. return ret;
  620. }
  621. break;
  622. case USB_DR_MODE_HOST:
  623. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
  624. ret = dwc3_host_init(dwc);
  625. if (ret) {
  626. dev_err(dev, "failed to initialize host\n");
  627. return ret;
  628. }
  629. break;
  630. case USB_DR_MODE_OTG:
  631. dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
  632. ret = dwc3_host_init(dwc);
  633. if (ret) {
  634. dev_err(dev, "failed to initialize host\n");
  635. return ret;
  636. }
  637. ret = dwc3_gadget_init(dwc);
  638. if (ret) {
  639. dev_err(dev, "failed to initialize gadget\n");
  640. return ret;
  641. }
  642. break;
  643. default:
  644. dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
  645. return -EINVAL;
  646. }
  647. return 0;
  648. }
  649. static void dwc3_core_exit_mode(struct dwc3 *dwc)
  650. {
  651. switch (dwc->dr_mode) {
  652. case USB_DR_MODE_PERIPHERAL:
  653. dwc3_gadget_exit(dwc);
  654. break;
  655. case USB_DR_MODE_HOST:
  656. dwc3_host_exit(dwc);
  657. break;
  658. case USB_DR_MODE_OTG:
  659. dwc3_host_exit(dwc);
  660. dwc3_gadget_exit(dwc);
  661. break;
  662. default:
  663. /* do nothing */
  664. break;
  665. }
  666. }
  667. #define DWC3_ALIGN_MASK (16 - 1)
  668. static int dwc3_probe(struct platform_device *pdev)
  669. {
  670. struct device *dev = &pdev->dev;
  671. struct dwc3_platform_data *pdata = dev_get_platdata(dev);
  672. struct resource *res;
  673. struct dwc3 *dwc;
  674. u8 lpm_nyet_threshold;
  675. u8 tx_de_emphasis;
  676. u8 hird_threshold;
  677. u32 fladj = 0;
  678. int ret;
  679. void __iomem *regs;
  680. void *mem;
  681. mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
  682. if (!mem)
  683. return -ENOMEM;
  684. dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
  685. dwc->mem = mem;
  686. dwc->dev = dev;
  687. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  688. if (!res) {
  689. dev_err(dev, "missing IRQ\n");
  690. return -ENODEV;
  691. }
  692. dwc->xhci_resources[1].start = res->start;
  693. dwc->xhci_resources[1].end = res->end;
  694. dwc->xhci_resources[1].flags = res->flags;
  695. dwc->xhci_resources[1].name = res->name;
  696. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  697. if (!res) {
  698. dev_err(dev, "missing memory resource\n");
  699. return -ENODEV;
  700. }
  701. dwc->xhci_resources[0].start = res->start;
  702. dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
  703. DWC3_XHCI_REGS_END;
  704. dwc->xhci_resources[0].flags = res->flags;
  705. dwc->xhci_resources[0].name = res->name;
  706. res->start += DWC3_GLOBALS_REGS_START;
  707. /*
  708. * Request memory region but exclude xHCI regs,
  709. * since it will be requested by the xhci-plat driver.
  710. */
  711. regs = devm_ioremap_resource(dev, res);
  712. if (IS_ERR(regs)) {
  713. ret = PTR_ERR(regs);
  714. goto err0;
  715. }
  716. dwc->regs = regs;
  717. dwc->regs_size = resource_size(res);
  718. /* default to highest possible threshold */
  719. lpm_nyet_threshold = 0xff;
  720. /* default to -3.5dB de-emphasis */
  721. tx_de_emphasis = 1;
  722. /*
  723. * default to assert utmi_sleep_n and use maximum allowed HIRD
  724. * threshold value of 0b1100
  725. */
  726. hird_threshold = 12;
  727. dwc->maximum_speed = usb_get_maximum_speed(dev);
  728. dwc->dr_mode = usb_get_dr_mode(dev);
  729. dwc->has_lpm_erratum = device_property_read_bool(dev,
  730. "snps,has-lpm-erratum");
  731. device_property_read_u8(dev, "snps,lpm-nyet-threshold",
  732. &lpm_nyet_threshold);
  733. dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
  734. "snps,is-utmi-l1-suspend");
  735. device_property_read_u8(dev, "snps,hird-threshold",
  736. &hird_threshold);
  737. dwc->usb3_lpm_capable = device_property_read_bool(dev,
  738. "snps,usb3_lpm_capable");
  739. dwc->needs_fifo_resize = device_property_read_bool(dev,
  740. "tx-fifo-resize");
  741. dwc->disable_scramble_quirk = device_property_read_bool(dev,
  742. "snps,disable_scramble_quirk");
  743. dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
  744. "snps,u2exit_lfps_quirk");
  745. dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
  746. "snps,u2ss_inp3_quirk");
  747. dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
  748. "snps,req_p1p2p3_quirk");
  749. dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
  750. "snps,del_p1p2p3_quirk");
  751. dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
  752. "snps,del_phy_power_chg_quirk");
  753. dwc->lfps_filter_quirk = device_property_read_bool(dev,
  754. "snps,lfps_filter_quirk");
  755. dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
  756. "snps,rx_detect_poll_quirk");
  757. dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
  758. "snps,dis_u3_susphy_quirk");
  759. dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
  760. "snps,dis_u2_susphy_quirk");
  761. dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
  762. "snps,dis_enblslpm_quirk");
  763. dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
  764. "snps,tx_de_emphasis_quirk");
  765. device_property_read_u8(dev, "snps,tx_de_emphasis",
  766. &tx_de_emphasis);
  767. device_property_read_string(dev, "snps,hsphy_interface",
  768. &dwc->hsphy_interface);
  769. device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
  770. &fladj);
  771. if (pdata) {
  772. dwc->maximum_speed = pdata->maximum_speed;
  773. dwc->has_lpm_erratum = pdata->has_lpm_erratum;
  774. if (pdata->lpm_nyet_threshold)
  775. lpm_nyet_threshold = pdata->lpm_nyet_threshold;
  776. dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend;
  777. if (pdata->hird_threshold)
  778. hird_threshold = pdata->hird_threshold;
  779. dwc->needs_fifo_resize = pdata->tx_fifo_resize;
  780. dwc->usb3_lpm_capable = pdata->usb3_lpm_capable;
  781. dwc->dr_mode = pdata->dr_mode;
  782. dwc->disable_scramble_quirk = pdata->disable_scramble_quirk;
  783. dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
  784. dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
  785. dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk;
  786. dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk;
  787. dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk;
  788. dwc->lfps_filter_quirk = pdata->lfps_filter_quirk;
  789. dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk;
  790. dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk;
  791. dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk;
  792. dwc->dis_enblslpm_quirk = pdata->dis_enblslpm_quirk;
  793. dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk;
  794. if (pdata->tx_de_emphasis)
  795. tx_de_emphasis = pdata->tx_de_emphasis;
  796. dwc->hsphy_interface = pdata->hsphy_interface;
  797. fladj = pdata->fladj_value;
  798. }
  799. dwc->lpm_nyet_threshold = lpm_nyet_threshold;
  800. dwc->tx_de_emphasis = tx_de_emphasis;
  801. dwc->hird_threshold = hird_threshold
  802. | (dwc->is_utmi_l1_suspend << 4);
  803. platform_set_drvdata(pdev, dwc);
  804. dwc3_cache_hwparams(dwc);
  805. ret = dwc3_phy_setup(dwc);
  806. if (ret)
  807. goto err0;
  808. ret = dwc3_core_get_phy(dwc);
  809. if (ret)
  810. goto err0;
  811. spin_lock_init(&dwc->lock);
  812. if (!dev->dma_mask) {
  813. dev->dma_mask = dev->parent->dma_mask;
  814. dev->dma_parms = dev->parent->dma_parms;
  815. dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
  816. }
  817. pm_runtime_enable(dev);
  818. pm_runtime_get_sync(dev);
  819. pm_runtime_forbid(dev);
  820. ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
  821. if (ret) {
  822. dev_err(dwc->dev, "failed to allocate event buffers\n");
  823. ret = -ENOMEM;
  824. goto err1;
  825. }
  826. if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
  827. dwc->dr_mode = USB_DR_MODE_HOST;
  828. else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
  829. dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
  830. if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
  831. dwc->dr_mode = USB_DR_MODE_OTG;
  832. ret = dwc3_core_init(dwc);
  833. if (ret) {
  834. dev_err(dev, "failed to initialize core\n");
  835. goto err1;
  836. }
  837. /* Check the maximum_speed parameter */
  838. switch (dwc->maximum_speed) {
  839. case USB_SPEED_LOW:
  840. case USB_SPEED_FULL:
  841. case USB_SPEED_HIGH:
  842. case USB_SPEED_SUPER:
  843. case USB_SPEED_SUPER_PLUS:
  844. break;
  845. default:
  846. dev_err(dev, "invalid maximum_speed parameter %d\n",
  847. dwc->maximum_speed);
  848. /* fall through */
  849. case USB_SPEED_UNKNOWN:
  850. /* default to superspeed */
  851. dwc->maximum_speed = USB_SPEED_SUPER;
  852. /*
  853. * default to superspeed plus if we are capable.
  854. */
  855. if (dwc3_is_usb31(dwc) &&
  856. (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
  857. DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
  858. dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
  859. break;
  860. }
  861. /* Adjust Frame Length */
  862. dwc3_frame_length_adjustment(dwc, fladj);
  863. usb_phy_set_suspend(dwc->usb2_phy, 0);
  864. usb_phy_set_suspend(dwc->usb3_phy, 0);
  865. ret = phy_power_on(dwc->usb2_generic_phy);
  866. if (ret < 0)
  867. goto err2;
  868. ret = phy_power_on(dwc->usb3_generic_phy);
  869. if (ret < 0)
  870. goto err3;
  871. ret = dwc3_event_buffers_setup(dwc);
  872. if (ret) {
  873. dev_err(dwc->dev, "failed to setup event buffers\n");
  874. goto err4;
  875. }
  876. ret = dwc3_core_init_mode(dwc);
  877. if (ret)
  878. goto err5;
  879. ret = dwc3_debugfs_init(dwc);
  880. if (ret) {
  881. dev_err(dev, "failed to initialize debugfs\n");
  882. goto err6;
  883. }
  884. pm_runtime_allow(dev);
  885. return 0;
  886. err6:
  887. dwc3_core_exit_mode(dwc);
  888. err5:
  889. dwc3_event_buffers_cleanup(dwc);
  890. err4:
  891. phy_power_off(dwc->usb3_generic_phy);
  892. err3:
  893. phy_power_off(dwc->usb2_generic_phy);
  894. err2:
  895. usb_phy_set_suspend(dwc->usb2_phy, 1);
  896. usb_phy_set_suspend(dwc->usb3_phy, 1);
  897. dwc3_core_exit(dwc);
  898. err1:
  899. dwc3_free_event_buffers(dwc);
  900. dwc3_ulpi_exit(dwc);
  901. err0:
  902. /*
  903. * restore res->start back to its original value so that, in case the
  904. * probe is deferred, we don't end up getting error in request the
  905. * memory region the next time probe is called.
  906. */
  907. res->start -= DWC3_GLOBALS_REGS_START;
  908. return ret;
  909. }
  910. static int dwc3_remove(struct platform_device *pdev)
  911. {
  912. struct dwc3 *dwc = platform_get_drvdata(pdev);
  913. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  914. /*
  915. * restore res->start back to its original value so that, in case the
  916. * probe is deferred, we don't end up getting error in request the
  917. * memory region the next time probe is called.
  918. */
  919. res->start -= DWC3_GLOBALS_REGS_START;
  920. dwc3_debugfs_exit(dwc);
  921. dwc3_core_exit_mode(dwc);
  922. dwc3_event_buffers_cleanup(dwc);
  923. dwc3_free_event_buffers(dwc);
  924. usb_phy_set_suspend(dwc->usb2_phy, 1);
  925. usb_phy_set_suspend(dwc->usb3_phy, 1);
  926. phy_power_off(dwc->usb2_generic_phy);
  927. phy_power_off(dwc->usb3_generic_phy);
  928. dwc3_core_exit(dwc);
  929. dwc3_ulpi_exit(dwc);
  930. pm_runtime_put_sync(&pdev->dev);
  931. pm_runtime_disable(&pdev->dev);
  932. return 0;
  933. }
  934. #ifdef CONFIG_PM_SLEEP
  935. static int dwc3_suspend(struct device *dev)
  936. {
  937. struct dwc3 *dwc = dev_get_drvdata(dev);
  938. unsigned long flags;
  939. spin_lock_irqsave(&dwc->lock, flags);
  940. switch (dwc->dr_mode) {
  941. case USB_DR_MODE_PERIPHERAL:
  942. case USB_DR_MODE_OTG:
  943. dwc3_gadget_suspend(dwc);
  944. /* FALLTHROUGH */
  945. case USB_DR_MODE_HOST:
  946. default:
  947. dwc3_event_buffers_cleanup(dwc);
  948. break;
  949. }
  950. dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
  951. spin_unlock_irqrestore(&dwc->lock, flags);
  952. usb_phy_shutdown(dwc->usb3_phy);
  953. usb_phy_shutdown(dwc->usb2_phy);
  954. phy_exit(dwc->usb2_generic_phy);
  955. phy_exit(dwc->usb3_generic_phy);
  956. pinctrl_pm_select_sleep_state(dev);
  957. return 0;
  958. }
  959. static int dwc3_resume(struct device *dev)
  960. {
  961. struct dwc3 *dwc = dev_get_drvdata(dev);
  962. unsigned long flags;
  963. int ret;
  964. pinctrl_pm_select_default_state(dev);
  965. usb_phy_init(dwc->usb3_phy);
  966. usb_phy_init(dwc->usb2_phy);
  967. ret = phy_init(dwc->usb2_generic_phy);
  968. if (ret < 0)
  969. return ret;
  970. ret = phy_init(dwc->usb3_generic_phy);
  971. if (ret < 0)
  972. goto err_usb2phy_init;
  973. spin_lock_irqsave(&dwc->lock, flags);
  974. dwc3_event_buffers_setup(dwc);
  975. dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
  976. switch (dwc->dr_mode) {
  977. case USB_DR_MODE_PERIPHERAL:
  978. case USB_DR_MODE_OTG:
  979. dwc3_gadget_resume(dwc);
  980. /* FALLTHROUGH */
  981. case USB_DR_MODE_HOST:
  982. default:
  983. /* do nothing */
  984. break;
  985. }
  986. spin_unlock_irqrestore(&dwc->lock, flags);
  987. pm_runtime_disable(dev);
  988. pm_runtime_set_active(dev);
  989. pm_runtime_enable(dev);
  990. return 0;
  991. err_usb2phy_init:
  992. phy_exit(dwc->usb2_generic_phy);
  993. return ret;
  994. }
  995. static const struct dev_pm_ops dwc3_dev_pm_ops = {
  996. SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
  997. };
  998. #define DWC3_PM_OPS &(dwc3_dev_pm_ops)
  999. #else
  1000. #define DWC3_PM_OPS NULL
  1001. #endif
  1002. #ifdef CONFIG_OF
  1003. static const struct of_device_id of_dwc3_match[] = {
  1004. {
  1005. .compatible = "snps,dwc3"
  1006. },
  1007. {
  1008. .compatible = "synopsys,dwc3"
  1009. },
  1010. { },
  1011. };
  1012. MODULE_DEVICE_TABLE(of, of_dwc3_match);
  1013. #endif
  1014. #ifdef CONFIG_ACPI
  1015. #define ACPI_ID_INTEL_BSW "808622B7"
  1016. static const struct acpi_device_id dwc3_acpi_match[] = {
  1017. { ACPI_ID_INTEL_BSW, 0 },
  1018. { },
  1019. };
  1020. MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
  1021. #endif
  1022. static struct platform_driver dwc3_driver = {
  1023. .probe = dwc3_probe,
  1024. .remove = dwc3_remove,
  1025. .driver = {
  1026. .name = "dwc3",
  1027. .of_match_table = of_match_ptr(of_dwc3_match),
  1028. .acpi_match_table = ACPI_PTR(dwc3_acpi_match),
  1029. .pm = DWC3_PM_OPS,
  1030. },
  1031. };
  1032. module_platform_driver(dwc3_driver);
  1033. MODULE_ALIAS("platform:dwc3");
  1034. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  1035. MODULE_LICENSE("GPL v2");
  1036. MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");