core.c 30 KB

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