core.c 30 KB

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