1 // SPDX-License-Identifier: GPL-2.0
3 * core.c - DesignWare USB3 DRD Controller Core file
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
11 #include <linux/clk.h>
12 #include <linux/version.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/spinlock.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/interrupt.h>
20 #include <linux/ioport.h>
22 #include <linux/list.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
26 #include <linux/of_graph.h>
27 #include <linux/acpi.h>
28 #include <linux/pinctrl/consumer.h>
29 #include <linux/reset.h>
30 #include <linux/bitfield.h>
32 #include <linux/usb/ch9.h>
33 #include <linux/usb/gadget.h>
34 #include <linux/usb/of.h>
35 #include <linux/usb/otg.h>
43 #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */
46 * dwc3_get_dr_mode - Validates and sets dr_mode
47 * @dwc: pointer to our context structure
49 static int dwc3_get_dr_mode(struct dwc3 *dwc)
51 enum usb_dr_mode mode;
52 struct device *dev = dwc->dev;
55 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
56 dwc->dr_mode = USB_DR_MODE_OTG;
59 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
62 case DWC3_GHWPARAMS0_MODE_GADGET:
63 if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
65 "Controller does not support host mode.\n");
68 mode = USB_DR_MODE_PERIPHERAL;
70 case DWC3_GHWPARAMS0_MODE_HOST:
71 if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
73 "Controller does not support device mode.\n");
76 mode = USB_DR_MODE_HOST;
79 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
80 mode = USB_DR_MODE_HOST;
81 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
82 mode = USB_DR_MODE_PERIPHERAL;
85 * DWC_usb31 and DWC_usb3 v3.30a and higher do not support OTG
86 * mode. If the controller supports DRD but the dr_mode is not
87 * specified or set to OTG, then set the mode to peripheral.
89 if (mode == USB_DR_MODE_OTG && !dwc->edev &&
90 (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
91 !device_property_read_bool(dwc->dev, "usb-role-switch")) &&
92 !DWC3_VER_IS_PRIOR(DWC3, 330A))
93 mode = USB_DR_MODE_PERIPHERAL;
96 if (mode != dwc->dr_mode) {
98 "Configuration mismatch. dr_mode forced to %s\n",
99 mode == USB_DR_MODE_HOST ? "host" : "gadget");
107 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
111 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
112 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
113 reg |= DWC3_GCTL_PRTCAPDIR(mode);
114 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
116 dwc->current_dr_role = mode;
119 static void __dwc3_set_mode(struct work_struct *work)
121 struct dwc3 *dwc = work_to_dwc(work);
126 mutex_lock(&dwc->mutex);
128 pm_runtime_get_sync(dwc->dev);
130 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
131 dwc3_otg_update(dwc, 0);
133 if (!dwc->desired_dr_role)
136 if (dwc->desired_dr_role == dwc->current_dr_role)
139 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
142 switch (dwc->current_dr_role) {
143 case DWC3_GCTL_PRTCAP_HOST:
146 case DWC3_GCTL_PRTCAP_DEVICE:
147 dwc3_gadget_exit(dwc);
148 dwc3_event_buffers_cleanup(dwc);
150 case DWC3_GCTL_PRTCAP_OTG:
152 spin_lock_irqsave(&dwc->lock, flags);
153 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE;
154 spin_unlock_irqrestore(&dwc->lock, flags);
155 dwc3_otg_update(dwc, 1);
161 /* For DRD host or device mode only */
162 if (dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG) {
163 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
164 reg |= DWC3_GCTL_CORESOFTRESET;
165 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
168 * Wait for internal clocks to synchronized. DWC_usb31 and
169 * DWC_usb32 may need at least 50ms (less for DWC_usb3). To
170 * keep it consistent across different IPs, let's wait up to
171 * 100ms before clearing GCTL.CORESOFTRESET.
175 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
176 reg &= ~DWC3_GCTL_CORESOFTRESET;
177 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
180 spin_lock_irqsave(&dwc->lock, flags);
182 dwc3_set_prtcap(dwc, dwc->desired_dr_role);
184 spin_unlock_irqrestore(&dwc->lock, flags);
186 switch (dwc->desired_dr_role) {
187 case DWC3_GCTL_PRTCAP_HOST:
188 ret = dwc3_host_init(dwc);
190 dev_err(dwc->dev, "failed to initialize host\n");
193 otg_set_vbus(dwc->usb2_phy->otg, true);
194 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
195 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
196 if (dwc->dis_split_quirk) {
197 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
198 reg |= DWC3_GUCTL3_SPLITDISABLE;
199 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
203 case DWC3_GCTL_PRTCAP_DEVICE:
204 dwc3_core_soft_reset(dwc);
206 dwc3_event_buffers_setup(dwc);
209 otg_set_vbus(dwc->usb2_phy->otg, false);
210 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
211 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
213 ret = dwc3_gadget_init(dwc);
215 dev_err(dwc->dev, "failed to initialize peripheral\n");
217 case DWC3_GCTL_PRTCAP_OTG:
219 dwc3_otg_update(dwc, 0);
226 pm_runtime_mark_last_busy(dwc->dev);
227 pm_runtime_put_autosuspend(dwc->dev);
228 mutex_unlock(&dwc->mutex);
231 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
235 if (dwc->dr_mode != USB_DR_MODE_OTG)
238 spin_lock_irqsave(&dwc->lock, flags);
239 dwc->desired_dr_role = mode;
240 spin_unlock_irqrestore(&dwc->lock, flags);
242 queue_work(system_freezable_wq, &dwc->drd_work);
245 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
247 struct dwc3 *dwc = dep->dwc;
250 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
251 DWC3_GDBGFIFOSPACE_NUM(dep->number) |
252 DWC3_GDBGFIFOSPACE_TYPE(type));
254 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE);
256 return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg);
260 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
261 * @dwc: pointer to our context structure
263 int dwc3_core_soft_reset(struct dwc3 *dwc)
269 * We're resetting only the device side because, if we're in host mode,
270 * XHCI driver will reset the host block. If dwc3 was configured for
271 * host-only mode, then we can return early.
273 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
276 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
277 reg |= DWC3_DCTL_CSFTRST;
278 reg &= ~DWC3_DCTL_RUN_STOP;
279 dwc3_gadget_dctl_write_safe(dwc, reg);
282 * For DWC_usb31 controller 1.90a and later, the DCTL.CSFRST bit
283 * is cleared only after all the clocks are synchronized. This can
284 * take a little more than 50ms. Set the polling rate at 20ms
285 * for 10 times instead.
287 if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
291 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
292 if (!(reg & DWC3_DCTL_CSFTRST))
295 if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
305 * For DWC_usb31 controller 1.80a and prior, once DCTL.CSFRST bit
306 * is cleared, we must wait at least 50ms before accessing the PHY
307 * domain (synchronization delay).
309 if (DWC3_VER_IS_WITHIN(DWC31, ANY, 180A))
316 * dwc3_frame_length_adjustment - Adjusts frame length if required
317 * @dwc3: Pointer to our controller context structure
319 static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
324 if (DWC3_VER_IS_PRIOR(DWC3, 250A))
330 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
331 dft = reg & DWC3_GFLADJ_30MHZ_MASK;
332 if (dft != dwc->fladj) {
333 reg &= ~DWC3_GFLADJ_30MHZ_MASK;
334 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj;
335 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
340 * dwc3_ref_clk_period - Reference clock period configuration
341 * Default reference clock period depends on hardware
342 * configuration. For systems with reference clock that differs
343 * from the default, this will set clock period in DWC3_GUCTL
345 * @dwc: Pointer to our controller context structure
347 static void dwc3_ref_clk_period(struct dwc3 *dwc)
349 unsigned long period;
356 rate = clk_get_rate(dwc->ref_clk);
359 period = NSEC_PER_SEC / rate;
360 } else if (dwc->ref_clk_per) {
361 period = dwc->ref_clk_per;
362 rate = NSEC_PER_SEC / period;
367 reg = dwc3_readl(dwc->regs, DWC3_GUCTL);
368 reg &= ~DWC3_GUCTL_REFCLKPER_MASK;
369 reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period);
370 dwc3_writel(dwc->regs, DWC3_GUCTL, reg);
372 if (DWC3_VER_IS_PRIOR(DWC3, 250A))
376 * The calculation below is
378 * 125000 * (NSEC_PER_SEC / (rate * period) - 1)
380 * but rearranged for fixed-point arithmetic. The division must be
381 * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and
382 * neither does rate * period).
384 * Note that rate * period ~= NSEC_PER_SECOND, minus the number of
385 * nanoseconds of error caused by the truncation which happened during
386 * the division when calculating rate or period (whichever one was
387 * derived from the other). We first calculate the relative error, then
388 * scale it to units of 8 ppm.
390 fladj = div64_u64(125000ULL * NSEC_PER_SEC, (u64)rate * period);
394 * The documented 240MHz constant is scaled by 2 to get PLS1 as well.
396 decr = 480000000 / rate;
398 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
399 reg &= ~DWC3_GFLADJ_REFCLK_FLADJ_MASK
400 & ~DWC3_GFLADJ_240MHZDECR
401 & ~DWC3_GFLADJ_240MHZDECR_PLS1;
402 reg |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, fladj)
403 | FIELD_PREP(DWC3_GFLADJ_240MHZDECR, decr >> 1)
404 | FIELD_PREP(DWC3_GFLADJ_240MHZDECR_PLS1, decr & 1);
405 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
409 * dwc3_free_one_event_buffer - Frees one event buffer
410 * @dwc: Pointer to our controller context structure
411 * @evt: Pointer to event buffer to be freed
413 static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
414 struct dwc3_event_buffer *evt)
416 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma);
420 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
421 * @dwc: Pointer to our controller context structure
422 * @length: size of the event buffer
424 * Returns a pointer to the allocated event buffer structure on success
425 * otherwise ERR_PTR(errno).
427 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
430 struct dwc3_event_buffer *evt;
432 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
434 return ERR_PTR(-ENOMEM);
437 evt->length = length;
438 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL);
440 return ERR_PTR(-ENOMEM);
442 evt->buf = dma_alloc_coherent(dwc->sysdev, length,
443 &evt->dma, GFP_KERNEL);
445 return ERR_PTR(-ENOMEM);
451 * dwc3_free_event_buffers - frees all allocated event buffers
452 * @dwc: Pointer to our controller context structure
454 static void dwc3_free_event_buffers(struct dwc3 *dwc)
456 struct dwc3_event_buffer *evt;
460 dwc3_free_one_event_buffer(dwc, evt);
464 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
465 * @dwc: pointer to our controller context structure
466 * @length: size of event buffer
468 * Returns 0 on success otherwise negative errno. In the error case, dwc
469 * may contain some buffers allocated but not all which were requested.
471 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
473 struct dwc3_event_buffer *evt;
475 evt = dwc3_alloc_one_event_buffer(dwc, length);
477 dev_err(dwc->dev, "can't allocate event buffer\n");
486 * dwc3_event_buffers_setup - setup our allocated event buffers
487 * @dwc: pointer to our controller context structure
489 * Returns 0 on success otherwise negative errno.
491 int dwc3_event_buffers_setup(struct dwc3 *dwc)
493 struct dwc3_event_buffer *evt;
497 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0),
498 lower_32_bits(evt->dma));
499 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0),
500 upper_32_bits(evt->dma));
501 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
502 DWC3_GEVNTSIZ_SIZE(evt->length));
503 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
508 void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
510 struct dwc3_event_buffer *evt;
516 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0);
517 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0);
518 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK
519 | DWC3_GEVNTSIZ_SIZE(0));
520 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
523 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
525 if (!dwc->has_hibernation)
528 if (!dwc->nr_scratch)
531 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
532 DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
533 if (!dwc->scratchbuf)
539 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
541 dma_addr_t scratch_addr;
545 if (!dwc->has_hibernation)
548 if (!dwc->nr_scratch)
551 /* should never fall here */
552 if (!WARN_ON(dwc->scratchbuf))
555 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf,
556 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
558 if (dma_mapping_error(dwc->sysdev, scratch_addr)) {
559 dev_err(dwc->sysdev, "failed to map scratch buffer\n");
564 dwc->scratch_addr = scratch_addr;
566 param = lower_32_bits(scratch_addr);
568 ret = dwc3_send_gadget_generic_command(dwc,
569 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
573 param = upper_32_bits(scratch_addr);
575 ret = dwc3_send_gadget_generic_command(dwc,
576 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
583 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
584 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
590 static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
592 if (!dwc->has_hibernation)
595 if (!dwc->nr_scratch)
598 /* should never fall here */
599 if (!WARN_ON(dwc->scratchbuf))
602 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
603 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
604 kfree(dwc->scratchbuf);
607 static void dwc3_core_num_eps(struct dwc3 *dwc)
609 struct dwc3_hwparams *parms = &dwc->hwparams;
611 dwc->num_eps = DWC3_NUM_EPS(parms);
614 static void dwc3_cache_hwparams(struct dwc3 *dwc)
616 struct dwc3_hwparams *parms = &dwc->hwparams;
618 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
619 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
620 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
621 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
622 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
623 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
624 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
625 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
626 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
628 if (DWC3_IP_IS(DWC32))
629 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9);
632 static int dwc3_core_ulpi_init(struct dwc3 *dwc)
637 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3);
639 if (intf == DWC3_GHWPARAMS3_HSPHY_IFC_ULPI ||
640 (intf == DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI &&
641 dwc->hsphy_interface &&
642 !strncmp(dwc->hsphy_interface, "ulpi", 4)))
643 ret = dwc3_ulpi_init(dwc);
649 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
650 * @dwc: Pointer to our controller context structure
652 * Returns 0 on success. The USB PHY interfaces are configured but not
653 * initialized. The PHY interfaces and the PHYs get initialized together with
654 * the core in dwc3_core_init.
656 static int dwc3_phy_setup(struct dwc3 *dwc)
658 unsigned int hw_mode;
661 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
663 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
666 * Make sure UX_EXIT_PX is cleared as that causes issues with some
667 * PHYs. Also, this bit is not supposed to be used in normal operation.
669 reg &= ~DWC3_GUSB3PIPECTL_UX_EXIT_PX;
672 * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
673 * to '0' during coreConsultant configuration. So default value
674 * will be '0' when the core is reset. Application needs to set it
675 * to '1' after the core initialization is completed.
677 if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A))
678 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
681 * For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be cleared after
682 * power-on reset, and it can be set after core initialization, which is
683 * after device soft-reset during initialization.
685 if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD)
686 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
688 if (dwc->u2ss_inp3_quirk)
689 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
691 if (dwc->dis_rxdet_inp3_quirk)
692 reg |= DWC3_GUSB3PIPECTL_DISRXDETINP3;
694 if (dwc->req_p1p2p3_quirk)
695 reg |= DWC3_GUSB3PIPECTL_REQP1P2P3;
697 if (dwc->del_p1p2p3_quirk)
698 reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN;
700 if (dwc->del_phy_power_chg_quirk)
701 reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE;
703 if (dwc->lfps_filter_quirk)
704 reg |= DWC3_GUSB3PIPECTL_LFPSFILT;
706 if (dwc->rx_detect_poll_quirk)
707 reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL;
709 if (dwc->tx_de_emphasis_quirk)
710 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis);
712 if (dwc->dis_u3_susphy_quirk)
713 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
715 if (dwc->dis_del_phy_power_chg_quirk)
716 reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE;
718 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
720 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
722 /* Select the HS PHY interface */
723 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
724 case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
725 if (dwc->hsphy_interface &&
726 !strncmp(dwc->hsphy_interface, "utmi", 4)) {
727 reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI;
729 } else if (dwc->hsphy_interface &&
730 !strncmp(dwc->hsphy_interface, "ulpi", 4)) {
731 reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
732 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
734 /* Relying on default value. */
735 if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI))
739 case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
744 switch (dwc->hsphy_mode) {
745 case USBPHY_INTERFACE_MODE_UTMI:
746 reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
747 DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
748 reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) |
749 DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT);
751 case USBPHY_INTERFACE_MODE_UTMIW:
752 reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
753 DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
754 reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) |
755 DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT);
762 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
763 * '0' during coreConsultant configuration. So default value will
764 * be '0' when the core is reset. Application needs to set it to
765 * '1' after the core initialization is completed.
767 if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A))
768 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
771 * For DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared after
772 * power-on reset, and it can be set after core initialization, which is
773 * after device soft-reset during initialization.
775 if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD)
776 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
778 if (dwc->dis_u2_susphy_quirk)
779 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
781 if (dwc->dis_enblslpm_quirk)
782 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
784 reg |= DWC3_GUSB2PHYCFG_ENBLSLPM;
786 if (dwc->dis_u2_freeclk_exists_quirk)
787 reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS;
789 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
794 static int dwc3_clk_enable(struct dwc3 *dwc)
798 ret = clk_prepare_enable(dwc->bus_clk);
802 ret = clk_prepare_enable(dwc->ref_clk);
804 goto disable_bus_clk;
806 ret = clk_prepare_enable(dwc->susp_clk);
808 goto disable_ref_clk;
813 clk_disable_unprepare(dwc->ref_clk);
815 clk_disable_unprepare(dwc->bus_clk);
819 static void dwc3_clk_disable(struct dwc3 *dwc)
821 clk_disable_unprepare(dwc->susp_clk);
822 clk_disable_unprepare(dwc->ref_clk);
823 clk_disable_unprepare(dwc->bus_clk);
826 static void dwc3_core_exit(struct dwc3 *dwc)
828 dwc3_event_buffers_cleanup(dwc);
830 usb_phy_shutdown(dwc->usb2_phy);
831 usb_phy_shutdown(dwc->usb3_phy);
832 phy_exit(dwc->usb2_generic_phy);
833 phy_exit(dwc->usb3_generic_phy);
835 usb_phy_set_suspend(dwc->usb2_phy, 1);
836 usb_phy_set_suspend(dwc->usb3_phy, 1);
837 phy_power_off(dwc->usb2_generic_phy);
838 phy_power_off(dwc->usb3_generic_phy);
839 dwc3_clk_disable(dwc);
840 reset_control_assert(dwc->reset);
843 static bool dwc3_core_is_valid(struct dwc3 *dwc)
847 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
848 dwc->ip = DWC3_GSNPS_ID(reg);
850 /* This should read as U3 followed by revision number */
851 if (DWC3_IP_IS(DWC3)) {
853 } else if (DWC3_IP_IS(DWC31) || DWC3_IP_IS(DWC32)) {
854 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
855 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE);
863 static void dwc3_core_setup_global_control(struct dwc3 *dwc)
865 u32 hwparams4 = dwc->hwparams.hwparams4;
868 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
869 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
871 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
872 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
874 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
875 * issue which would cause xHCI compliance tests to fail.
877 * Because of that we cannot enable clock gating on such
882 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
885 if ((dwc->dr_mode == USB_DR_MODE_HOST ||
886 dwc->dr_mode == USB_DR_MODE_OTG) &&
887 DWC3_VER_IS_WITHIN(DWC3, 210A, 250A))
888 reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
890 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
892 case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
893 /* enable hibernation here */
894 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
897 * REVISIT Enabling this bit so that host-mode hibernation
898 * will work. Device-mode hibernation is not yet implemented.
900 reg |= DWC3_GCTL_GBLHIBERNATIONEN;
907 /* check if current dwc3 is on simulation board */
908 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
909 dev_info(dwc->dev, "Running with FPGA optimizations\n");
913 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
914 "disable_scramble cannot be used on non-FPGA builds\n");
916 if (dwc->disable_scramble_quirk && dwc->is_fpga)
917 reg |= DWC3_GCTL_DISSCRAMBLE;
919 reg &= ~DWC3_GCTL_DISSCRAMBLE;
921 if (dwc->u2exit_lfps_quirk)
922 reg |= DWC3_GCTL_U2EXIT_LFPS;
925 * WORKAROUND: DWC3 revisions <1.90a have a bug
926 * where the device can fail to connect at SuperSpeed
927 * and falls back to high-speed mode which causes
928 * the device to enter a Connect/Disconnect loop
930 if (DWC3_VER_IS_PRIOR(DWC3, 190A))
931 reg |= DWC3_GCTL_U2RSTECN;
933 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
936 static int dwc3_core_get_phy(struct dwc3 *dwc);
937 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
939 /* set global incr burst type configuration registers */
940 static void dwc3_set_incr_burst_type(struct dwc3 *dwc)
942 struct device *dev = dwc->dev;
943 /* incrx_mode : for INCR burst type. */
945 /* incrx_size : for size of INCRX burst. */
953 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
956 * Handle property "snps,incr-burst-type-adjustment".
957 * Get the number of value from this property:
958 * result <= 0, means this property is not supported.
959 * result = 1, means INCRx burst mode supported.
960 * result > 1, means undefined length burst mode supported.
962 ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment");
966 vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL);
970 /* Get INCR burst type, and parse it */
971 ret = device_property_read_u32_array(dev,
972 "snps,incr-burst-type-adjustment", vals, ntype);
975 dev_err(dev, "Error to get property\n");
982 /* INCRX (undefined length) burst mode */
983 incrx_mode = INCRX_UNDEF_LENGTH_BURST_MODE;
984 for (i = 1; i < ntype; i++) {
985 if (vals[i] > incrx_size)
986 incrx_size = vals[i];
989 /* INCRX burst mode */
990 incrx_mode = INCRX_BURST_MODE;
995 /* Enable Undefined Length INCR Burst and Enable INCRx Burst */
996 cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
998 cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
999 switch (incrx_size) {
1001 cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
1004 cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
1007 cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
1010 cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
1013 cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
1016 cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
1019 cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
1024 dev_err(dev, "Invalid property\n");
1028 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
1032 * dwc3_core_init - Low-level initialization of DWC3 Core
1033 * @dwc: Pointer to our controller context structure
1035 * Returns 0 on success otherwise negative errno.
1037 static int dwc3_core_init(struct dwc3 *dwc)
1039 unsigned int hw_mode;
1043 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
1046 * Write Linux Version Code to our GUID register so it's easy to figure
1047 * out which kernel version a bug was found.
1049 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
1051 ret = dwc3_phy_setup(dwc);
1055 if (!dwc->ulpi_ready) {
1056 ret = dwc3_core_ulpi_init(dwc);
1059 dwc->ulpi_ready = true;
1062 if (!dwc->phys_ready) {
1063 ret = dwc3_core_get_phy(dwc);
1066 dwc->phys_ready = true;
1069 usb_phy_init(dwc->usb2_phy);
1070 usb_phy_init(dwc->usb3_phy);
1071 ret = phy_init(dwc->usb2_generic_phy);
1075 ret = phy_init(dwc->usb3_generic_phy);
1077 phy_exit(dwc->usb2_generic_phy);
1081 ret = dwc3_core_soft_reset(dwc);
1085 if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD &&
1086 !DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) {
1087 if (!dwc->dis_u3_susphy_quirk) {
1088 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
1089 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
1090 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
1093 if (!dwc->dis_u2_susphy_quirk) {
1094 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1095 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
1096 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1100 dwc3_core_setup_global_control(dwc);
1101 dwc3_core_num_eps(dwc);
1103 ret = dwc3_setup_scratch_buffers(dwc);
1107 /* Adjust Frame Length */
1108 dwc3_frame_length_adjustment(dwc);
1110 /* Adjust Reference Clock Period */
1111 dwc3_ref_clk_period(dwc);
1113 dwc3_set_incr_burst_type(dwc);
1115 usb_phy_set_suspend(dwc->usb2_phy, 0);
1116 usb_phy_set_suspend(dwc->usb3_phy, 0);
1117 ret = phy_power_on(dwc->usb2_generic_phy);
1121 ret = phy_power_on(dwc->usb3_generic_phy);
1125 ret = dwc3_event_buffers_setup(dwc);
1127 dev_err(dwc->dev, "failed to setup event buffers\n");
1132 * ENDXFER polling is available on version 3.10a and later of
1133 * the DWC_usb3 controller. It is NOT available in the
1134 * DWC_usb31 controller.
1136 if (DWC3_VER_IS_WITHIN(DWC3, 310A, ANY)) {
1137 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2);
1138 reg |= DWC3_GUCTL2_RST_ACTBITLATER;
1139 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg);
1142 if (!DWC3_VER_IS_PRIOR(DWC3, 250A)) {
1143 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1);
1146 * Enable hardware control of sending remote wakeup
1147 * in HS when the device is in the L1 state.
1149 if (!DWC3_VER_IS_PRIOR(DWC3, 290A))
1150 reg |= DWC3_GUCTL1_DEV_L1_EXIT_BY_HW;
1153 * Decouple USB 2.0 L1 & L2 events which will allow for
1154 * gadget driver to only receive U3/L2 suspend & wakeup
1155 * events and prevent the more frequent L1 LPM transitions
1156 * from interrupting the driver.
1158 if (!DWC3_VER_IS_PRIOR(DWC3, 300A))
1159 reg |= DWC3_GUCTL1_DEV_DECOUPLE_L1L2_EVT;
1161 if (dwc->dis_tx_ipgap_linecheck_quirk)
1162 reg |= DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS;
1164 if (dwc->parkmode_disable_ss_quirk)
1165 reg |= DWC3_GUCTL1_PARKMODE_DISABLE_SS;
1167 if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY) &&
1168 (dwc->maximum_speed == USB_SPEED_HIGH ||
1169 dwc->maximum_speed == USB_SPEED_FULL))
1170 reg |= DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK;
1172 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg);
1175 if (dwc->dr_mode == USB_DR_MODE_HOST ||
1176 dwc->dr_mode == USB_DR_MODE_OTG) {
1177 reg = dwc3_readl(dwc->regs, DWC3_GUCTL);
1180 * Enable Auto retry Feature to make the controller operating in
1181 * Host mode on seeing transaction errors(CRC errors or internal
1182 * overrun scenerios) on IN transfers to reply to the device
1183 * with a non-terminating retry ACK (i.e, an ACK transcation
1184 * packet with Retry=1 & Nump != 0)
1186 reg |= DWC3_GUCTL_HSTINAUTORETRY;
1188 dwc3_writel(dwc->regs, DWC3_GUCTL, reg);
1192 * Must config both number of packets and max burst settings to enable
1193 * RX and/or TX threshold.
1195 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) {
1196 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd;
1197 u8 rx_maxburst = dwc->rx_max_burst_prd;
1198 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd;
1199 u8 tx_maxburst = dwc->tx_max_burst_prd;
1201 if (rx_thr_num && rx_maxburst) {
1202 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG);
1203 reg |= DWC31_RXTHRNUMPKTSEL_PRD;
1205 reg &= ~DWC31_RXTHRNUMPKT_PRD(~0);
1206 reg |= DWC31_RXTHRNUMPKT_PRD(rx_thr_num);
1208 reg &= ~DWC31_MAXRXBURSTSIZE_PRD(~0);
1209 reg |= DWC31_MAXRXBURSTSIZE_PRD(rx_maxburst);
1211 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg);
1214 if (tx_thr_num && tx_maxburst) {
1215 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG);
1216 reg |= DWC31_TXTHRNUMPKTSEL_PRD;
1218 reg &= ~DWC31_TXTHRNUMPKT_PRD(~0);
1219 reg |= DWC31_TXTHRNUMPKT_PRD(tx_thr_num);
1221 reg &= ~DWC31_MAXTXBURSTSIZE_PRD(~0);
1222 reg |= DWC31_MAXTXBURSTSIZE_PRD(tx_maxburst);
1224 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg);
1231 phy_power_off(dwc->usb3_generic_phy);
1234 phy_power_off(dwc->usb2_generic_phy);
1237 usb_phy_set_suspend(dwc->usb2_phy, 1);
1238 usb_phy_set_suspend(dwc->usb3_phy, 1);
1241 usb_phy_shutdown(dwc->usb2_phy);
1242 usb_phy_shutdown(dwc->usb3_phy);
1243 phy_exit(dwc->usb2_generic_phy);
1244 phy_exit(dwc->usb3_generic_phy);
1247 dwc3_ulpi_exit(dwc);
1253 static int dwc3_core_get_phy(struct dwc3 *dwc)
1255 struct device *dev = dwc->dev;
1256 struct device_node *node = dev->of_node;
1260 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
1261 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
1263 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
1264 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
1267 if (IS_ERR(dwc->usb2_phy)) {
1268 ret = PTR_ERR(dwc->usb2_phy);
1269 if (ret == -ENXIO || ret == -ENODEV) {
1270 dwc->usb2_phy = NULL;
1272 return dev_err_probe(dev, ret, "no usb2 phy configured\n");
1276 if (IS_ERR(dwc->usb3_phy)) {
1277 ret = PTR_ERR(dwc->usb3_phy);
1278 if (ret == -ENXIO || ret == -ENODEV) {
1279 dwc->usb3_phy = NULL;
1281 return dev_err_probe(dev, ret, "no usb3 phy configured\n");
1285 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
1286 if (IS_ERR(dwc->usb2_generic_phy)) {
1287 ret = PTR_ERR(dwc->usb2_generic_phy);
1288 if (ret == -ENOSYS || ret == -ENODEV) {
1289 dwc->usb2_generic_phy = NULL;
1291 return dev_err_probe(dev, ret, "no usb2 phy configured\n");
1295 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
1296 if (IS_ERR(dwc->usb3_generic_phy)) {
1297 ret = PTR_ERR(dwc->usb3_generic_phy);
1298 if (ret == -ENOSYS || ret == -ENODEV) {
1299 dwc->usb3_generic_phy = NULL;
1301 return dev_err_probe(dev, ret, "no usb3 phy configured\n");
1308 static int dwc3_core_init_mode(struct dwc3 *dwc)
1310 struct device *dev = dwc->dev;
1313 switch (dwc->dr_mode) {
1314 case USB_DR_MODE_PERIPHERAL:
1315 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1318 otg_set_vbus(dwc->usb2_phy->otg, false);
1319 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
1320 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
1322 ret = dwc3_gadget_init(dwc);
1324 return dev_err_probe(dev, ret, "failed to initialize gadget\n");
1326 case USB_DR_MODE_HOST:
1327 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
1330 otg_set_vbus(dwc->usb2_phy->otg, true);
1331 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
1332 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
1334 ret = dwc3_host_init(dwc);
1336 return dev_err_probe(dev, ret, "failed to initialize host\n");
1338 case USB_DR_MODE_OTG:
1339 INIT_WORK(&dwc->drd_work, __dwc3_set_mode);
1340 ret = dwc3_drd_init(dwc);
1342 return dev_err_probe(dev, ret, "failed to initialize dual-role\n");
1345 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
1352 static void dwc3_core_exit_mode(struct dwc3 *dwc)
1354 switch (dwc->dr_mode) {
1355 case USB_DR_MODE_PERIPHERAL:
1356 dwc3_gadget_exit(dwc);
1358 case USB_DR_MODE_HOST:
1359 dwc3_host_exit(dwc);
1361 case USB_DR_MODE_OTG:
1369 /* de-assert DRVVBUS for HOST and OTG mode */
1370 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1373 static void dwc3_get_properties(struct dwc3 *dwc)
1375 struct device *dev = dwc->dev;
1376 u8 lpm_nyet_threshold;
1379 u8 rx_thr_num_pkt_prd = 0;
1380 u8 rx_max_burst_prd = 0;
1381 u8 tx_thr_num_pkt_prd = 0;
1382 u8 tx_max_burst_prd = 0;
1383 u8 tx_fifo_resize_max_num;
1384 const char *usb_psy_name;
1387 /* default to highest possible threshold */
1388 lpm_nyet_threshold = 0xf;
1390 /* default to -3.5dB de-emphasis */
1394 * default to assert utmi_sleep_n and use maximum allowed HIRD
1395 * threshold value of 0b1100
1397 hird_threshold = 12;
1400 * default to a TXFIFO size large enough to fit 6 max packets. This
1401 * allows for systems with larger bus latencies to have some headroom
1402 * for endpoints that have a large bMaxBurst value.
1404 tx_fifo_resize_max_num = 6;
1406 dwc->maximum_speed = usb_get_maximum_speed(dev);
1407 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev);
1408 dwc->dr_mode = usb_get_dr_mode(dev);
1409 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
1411 dwc->sysdev_is_parent = device_property_read_bool(dev,
1412 "linux,sysdev_is_parent");
1413 if (dwc->sysdev_is_parent)
1414 dwc->sysdev = dwc->dev->parent;
1416 dwc->sysdev = dwc->dev;
1418 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
1420 dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
1422 dev_err(dev, "couldn't get usb power supply\n");
1425 dwc->has_lpm_erratum = device_property_read_bool(dev,
1426 "snps,has-lpm-erratum");
1427 device_property_read_u8(dev, "snps,lpm-nyet-threshold",
1428 &lpm_nyet_threshold);
1429 dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
1430 "snps,is-utmi-l1-suspend");
1431 device_property_read_u8(dev, "snps,hird-threshold",
1433 dwc->dis_start_transfer_quirk = device_property_read_bool(dev,
1434 "snps,dis-start-transfer-quirk");
1435 dwc->usb3_lpm_capable = device_property_read_bool(dev,
1436 "snps,usb3_lpm_capable");
1437 dwc->usb2_lpm_disable = device_property_read_bool(dev,
1438 "snps,usb2-lpm-disable");
1439 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev,
1440 "snps,usb2-gadget-lpm-disable");
1441 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd",
1442 &rx_thr_num_pkt_prd);
1443 device_property_read_u8(dev, "snps,rx-max-burst-prd",
1445 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd",
1446 &tx_thr_num_pkt_prd);
1447 device_property_read_u8(dev, "snps,tx-max-burst-prd",
1449 dwc->do_fifo_resize = device_property_read_bool(dev,
1451 if (dwc->do_fifo_resize)
1452 device_property_read_u8(dev, "tx-fifo-max-num",
1453 &tx_fifo_resize_max_num);
1455 dwc->disable_scramble_quirk = device_property_read_bool(dev,
1456 "snps,disable_scramble_quirk");
1457 dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
1458 "snps,u2exit_lfps_quirk");
1459 dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
1460 "snps,u2ss_inp3_quirk");
1461 dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
1462 "snps,req_p1p2p3_quirk");
1463 dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
1464 "snps,del_p1p2p3_quirk");
1465 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
1466 "snps,del_phy_power_chg_quirk");
1467 dwc->lfps_filter_quirk = device_property_read_bool(dev,
1468 "snps,lfps_filter_quirk");
1469 dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
1470 "snps,rx_detect_poll_quirk");
1471 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
1472 "snps,dis_u3_susphy_quirk");
1473 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
1474 "snps,dis_u2_susphy_quirk");
1475 dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
1476 "snps,dis_enblslpm_quirk");
1477 dwc->dis_u1_entry_quirk = device_property_read_bool(dev,
1478 "snps,dis-u1-entry-quirk");
1479 dwc->dis_u2_entry_quirk = device_property_read_bool(dev,
1480 "snps,dis-u2-entry-quirk");
1481 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
1482 "snps,dis_rxdet_inp3_quirk");
1483 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
1484 "snps,dis-u2-freeclk-exists-quirk");
1485 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
1486 "snps,dis-del-phy-power-chg-quirk");
1487 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev,
1488 "snps,dis-tx-ipgap-linecheck-quirk");
1489 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev,
1490 "snps,parkmode-disable-ss-quirk");
1492 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
1493 "snps,tx_de_emphasis_quirk");
1494 device_property_read_u8(dev, "snps,tx_de_emphasis",
1496 device_property_read_string(dev, "snps,hsphy_interface",
1497 &dwc->hsphy_interface);
1498 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
1500 device_property_read_u32(dev, "snps,ref-clock-period-ns",
1503 dwc->dis_metastability_quirk = device_property_read_bool(dev,
1504 "snps,dis_metastability_quirk");
1506 dwc->dis_split_quirk = device_property_read_bool(dev,
1507 "snps,dis-split-quirk");
1509 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
1510 dwc->tx_de_emphasis = tx_de_emphasis;
1512 dwc->hird_threshold = hird_threshold;
1514 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd;
1515 dwc->rx_max_burst_prd = rx_max_burst_prd;
1517 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd;
1518 dwc->tx_max_burst_prd = tx_max_burst_prd;
1520 dwc->imod_interval = 0;
1522 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
1525 /* check whether the core supports IMOD */
1526 bool dwc3_has_imod(struct dwc3 *dwc)
1528 return DWC3_VER_IS_WITHIN(DWC3, 300A, ANY) ||
1529 DWC3_VER_IS_WITHIN(DWC31, 120A, ANY) ||
1533 static void dwc3_check_params(struct dwc3 *dwc)
1535 struct device *dev = dwc->dev;
1536 unsigned int hwparam_gen =
1537 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3);
1539 /* Check for proper value of imod_interval */
1540 if (dwc->imod_interval && !dwc3_has_imod(dwc)) {
1541 dev_warn(dwc->dev, "Interrupt moderation not supported\n");
1542 dwc->imod_interval = 0;
1546 * Workaround for STAR 9000961433 which affects only version
1547 * 3.00a of the DWC_usb3 core. This prevents the controller
1548 * interrupt from being masked while handling events. IMOD
1549 * allows us to work around this issue. Enable it for the
1552 if (!dwc->imod_interval &&
1553 DWC3_VER_IS(DWC3, 300A))
1554 dwc->imod_interval = 1;
1556 /* Check the maximum_speed parameter */
1557 switch (dwc->maximum_speed) {
1558 case USB_SPEED_FULL:
1559 case USB_SPEED_HIGH:
1561 case USB_SPEED_SUPER:
1562 if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS)
1563 dev_warn(dev, "UDC doesn't support Gen 1\n");
1565 case USB_SPEED_SUPER_PLUS:
1566 if ((DWC3_IP_IS(DWC32) &&
1567 hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS) ||
1568 (!DWC3_IP_IS(DWC32) &&
1569 hwparam_gen != DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
1570 dev_warn(dev, "UDC doesn't support SSP\n");
1573 dev_err(dev, "invalid maximum_speed parameter %d\n",
1574 dwc->maximum_speed);
1576 case USB_SPEED_UNKNOWN:
1577 switch (hwparam_gen) {
1578 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1579 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1581 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1582 if (DWC3_IP_IS(DWC32))
1583 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1585 dwc->maximum_speed = USB_SPEED_SUPER;
1587 case DWC3_GHWPARAMS3_SSPHY_IFC_DIS:
1588 dwc->maximum_speed = USB_SPEED_HIGH;
1591 dwc->maximum_speed = USB_SPEED_SUPER;
1598 * Currently the controller does not have visibility into the HW
1599 * parameter to determine the maximum number of lanes the HW supports.
1600 * If the number of lanes is not specified in the device property, then
1601 * set the default to support dual-lane for DWC_usb32 and single-lane
1602 * for DWC_usb31 for super-speed-plus.
1604 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) {
1605 switch (dwc->max_ssp_rate) {
1606 case USB_SSP_GEN_2x1:
1607 if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_GEN1)
1608 dev_warn(dev, "UDC only supports Gen 1\n");
1610 case USB_SSP_GEN_1x2:
1611 case USB_SSP_GEN_2x2:
1612 if (DWC3_IP_IS(DWC31))
1613 dev_warn(dev, "UDC only supports single lane\n");
1615 case USB_SSP_GEN_UNKNOWN:
1617 switch (hwparam_gen) {
1618 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1619 if (DWC3_IP_IS(DWC32))
1620 dwc->max_ssp_rate = USB_SSP_GEN_2x2;
1622 dwc->max_ssp_rate = USB_SSP_GEN_2x1;
1624 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1625 if (DWC3_IP_IS(DWC32))
1626 dwc->max_ssp_rate = USB_SSP_GEN_1x2;
1634 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
1636 struct device *dev = dwc->dev;
1637 struct device_node *np_phy;
1638 struct extcon_dev *edev = NULL;
1641 if (device_property_read_bool(dev, "extcon"))
1642 return extcon_get_edev_by_phandle(dev, 0);
1645 * Device tree platforms should get extcon via phandle.
1646 * On ACPI platforms, we get the name from a device property.
1647 * This device property is for kernel internal use only and
1648 * is expected to be set by the glue code.
1650 if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
1651 edev = extcon_get_extcon_dev(name);
1653 return ERR_PTR(-EPROBE_DEFER);
1659 * Try to get an extcon device from the USB PHY controller's "port"
1660 * node. Check if it has the "port" node first, to avoid printing the
1661 * error message from underlying code, as it's a valid case: extcon
1662 * device (and "port" node) may be missing in case of "usb-role-switch"
1665 np_phy = of_parse_phandle(dev->of_node, "phys", 0);
1666 if (of_graph_is_present(np_phy)) {
1667 struct device_node *np_conn;
1669 np_conn = of_graph_get_remote_node(np_phy, -1, -1);
1671 edev = extcon_find_edev_by_node(np_conn);
1672 of_node_put(np_conn);
1674 of_node_put(np_phy);
1679 static int dwc3_probe(struct platform_device *pdev)
1681 struct device *dev = &pdev->dev;
1682 struct resource *res, dwc_res;
1689 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
1695 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1697 dev_err(dev, "missing memory resource\n");
1701 dwc->xhci_resources[0].start = res->start;
1702 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
1704 dwc->xhci_resources[0].flags = res->flags;
1705 dwc->xhci_resources[0].name = res->name;
1708 * Request memory region but exclude xHCI regs,
1709 * since it will be requested by the xhci-plat driver.
1712 dwc_res.start += DWC3_GLOBALS_REGS_START;
1714 regs = devm_ioremap_resource(dev, &dwc_res);
1716 return PTR_ERR(regs);
1719 dwc->regs_size = resource_size(&dwc_res);
1721 dwc3_get_properties(dwc);
1723 if (!dwc->sysdev_is_parent) {
1724 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
1729 dwc->reset = devm_reset_control_array_get_optional_shared(dev);
1730 if (IS_ERR(dwc->reset))
1731 return PTR_ERR(dwc->reset);
1735 * Clocks are optional, but new DT platforms should support all
1736 * clocks as required by the DT-binding.
1737 * Some devices have different clock names in legacy device trees,
1738 * check for them to retain backwards compatibility.
1740 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early");
1741 if (IS_ERR(dwc->bus_clk))
1742 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
1743 "could not get bus clock\n");
1745 if (dwc->bus_clk == NULL) {
1746 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk");
1747 if (IS_ERR(dwc->bus_clk))
1748 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
1749 "could not get bus clock\n");
1752 dwc->ref_clk = devm_clk_get_optional(dev, "ref");
1753 if (IS_ERR(dwc->ref_clk))
1754 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
1755 "could not get ref clock\n");
1757 if (dwc->ref_clk == NULL) {
1758 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk");
1759 if (IS_ERR(dwc->ref_clk))
1760 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
1761 "could not get ref clock\n");
1764 dwc->susp_clk = devm_clk_get_optional(dev, "suspend");
1765 if (IS_ERR(dwc->susp_clk))
1766 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
1767 "could not get suspend clock\n");
1769 if (dwc->susp_clk == NULL) {
1770 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk");
1771 if (IS_ERR(dwc->susp_clk))
1772 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
1773 "could not get suspend clock\n");
1777 ret = reset_control_deassert(dwc->reset);
1781 ret = dwc3_clk_enable(dwc);
1785 if (!dwc3_core_is_valid(dwc)) {
1786 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
1791 platform_set_drvdata(pdev, dwc);
1792 dwc3_cache_hwparams(dwc);
1794 spin_lock_init(&dwc->lock);
1795 mutex_init(&dwc->mutex);
1797 pm_runtime_set_active(dev);
1798 pm_runtime_use_autosuspend(dev);
1799 pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
1800 pm_runtime_enable(dev);
1801 ret = pm_runtime_get_sync(dev);
1805 pm_runtime_forbid(dev);
1807 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
1809 dev_err(dwc->dev, "failed to allocate event buffers\n");
1814 dwc->edev = dwc3_get_extcon(dwc);
1815 if (IS_ERR(dwc->edev)) {
1816 ret = PTR_ERR(dwc->edev);
1817 dev_err_probe(dwc->dev, ret, "failed to get extcon\n");
1821 ret = dwc3_get_dr_mode(dwc);
1825 ret = dwc3_alloc_scratch_buffers(dwc);
1829 ret = dwc3_core_init(dwc);
1831 dev_err_probe(dev, ret, "failed to initialize core\n");
1835 dwc3_check_params(dwc);
1836 dwc3_debugfs_init(dwc);
1838 ret = dwc3_core_init_mode(dwc);
1842 pm_runtime_put(dev);
1847 dwc3_debugfs_exit(dwc);
1848 dwc3_event_buffers_cleanup(dwc);
1850 usb_phy_shutdown(dwc->usb2_phy);
1851 usb_phy_shutdown(dwc->usb3_phy);
1852 phy_exit(dwc->usb2_generic_phy);
1853 phy_exit(dwc->usb3_generic_phy);
1855 usb_phy_set_suspend(dwc->usb2_phy, 1);
1856 usb_phy_set_suspend(dwc->usb3_phy, 1);
1857 phy_power_off(dwc->usb2_generic_phy);
1858 phy_power_off(dwc->usb3_generic_phy);
1860 dwc3_ulpi_exit(dwc);
1863 dwc3_free_scratch_buffers(dwc);
1866 dwc3_free_event_buffers(dwc);
1869 pm_runtime_allow(&pdev->dev);
1872 pm_runtime_put_sync(&pdev->dev);
1873 pm_runtime_disable(&pdev->dev);
1876 dwc3_clk_disable(dwc);
1878 reset_control_assert(dwc->reset);
1881 power_supply_put(dwc->usb_psy);
1886 static int dwc3_remove(struct platform_device *pdev)
1888 struct dwc3 *dwc = platform_get_drvdata(pdev);
1890 pm_runtime_get_sync(&pdev->dev);
1892 dwc3_core_exit_mode(dwc);
1893 dwc3_debugfs_exit(dwc);
1895 dwc3_core_exit(dwc);
1896 dwc3_ulpi_exit(dwc);
1898 pm_runtime_disable(&pdev->dev);
1899 pm_runtime_put_noidle(&pdev->dev);
1900 pm_runtime_set_suspended(&pdev->dev);
1902 dwc3_free_event_buffers(dwc);
1903 dwc3_free_scratch_buffers(dwc);
1906 power_supply_put(dwc->usb_psy);
1912 static int dwc3_core_init_for_resume(struct dwc3 *dwc)
1916 ret = reset_control_deassert(dwc->reset);
1920 ret = dwc3_clk_enable(dwc);
1924 ret = dwc3_core_init(dwc);
1931 dwc3_clk_disable(dwc);
1933 reset_control_assert(dwc->reset);
1938 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
1940 unsigned long flags;
1943 switch (dwc->current_dr_role) {
1944 case DWC3_GCTL_PRTCAP_DEVICE:
1945 if (pm_runtime_suspended(dwc->dev))
1947 spin_lock_irqsave(&dwc->lock, flags);
1948 dwc3_gadget_suspend(dwc);
1949 spin_unlock_irqrestore(&dwc->lock, flags);
1950 synchronize_irq(dwc->irq_gadget);
1951 dwc3_core_exit(dwc);
1953 case DWC3_GCTL_PRTCAP_HOST:
1954 if (!PMSG_IS_AUTO(msg)) {
1955 dwc3_core_exit(dwc);
1959 /* Let controller to suspend HSPHY before PHY driver suspends */
1960 if (dwc->dis_u2_susphy_quirk ||
1961 dwc->dis_enblslpm_quirk) {
1962 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1963 reg |= DWC3_GUSB2PHYCFG_ENBLSLPM |
1964 DWC3_GUSB2PHYCFG_SUSPHY;
1965 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1967 /* Give some time for USB2 PHY to suspend */
1968 usleep_range(5000, 6000);
1971 phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
1972 phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
1974 case DWC3_GCTL_PRTCAP_OTG:
1975 /* do nothing during runtime_suspend */
1976 if (PMSG_IS_AUTO(msg))
1979 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
1980 spin_lock_irqsave(&dwc->lock, flags);
1981 dwc3_gadget_suspend(dwc);
1982 spin_unlock_irqrestore(&dwc->lock, flags);
1983 synchronize_irq(dwc->irq_gadget);
1987 dwc3_core_exit(dwc);
1997 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
1999 unsigned long flags;
2003 switch (dwc->current_dr_role) {
2004 case DWC3_GCTL_PRTCAP_DEVICE:
2005 ret = dwc3_core_init_for_resume(dwc);
2009 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
2010 spin_lock_irqsave(&dwc->lock, flags);
2011 dwc3_gadget_resume(dwc);
2012 spin_unlock_irqrestore(&dwc->lock, flags);
2014 case DWC3_GCTL_PRTCAP_HOST:
2015 if (!PMSG_IS_AUTO(msg)) {
2016 ret = dwc3_core_init_for_resume(dwc);
2019 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
2022 /* Restore GUSB2PHYCFG bits that were modified in suspend */
2023 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
2024 if (dwc->dis_u2_susphy_quirk)
2025 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
2027 if (dwc->dis_enblslpm_quirk)
2028 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
2030 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
2032 phy_pm_runtime_get_sync(dwc->usb2_generic_phy);
2033 phy_pm_runtime_get_sync(dwc->usb3_generic_phy);
2035 case DWC3_GCTL_PRTCAP_OTG:
2036 /* nothing to do on runtime_resume */
2037 if (PMSG_IS_AUTO(msg))
2040 ret = dwc3_core_init_for_resume(dwc);
2044 dwc3_set_prtcap(dwc, dwc->current_dr_role);
2047 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
2048 dwc3_otg_host_init(dwc);
2049 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
2050 spin_lock_irqsave(&dwc->lock, flags);
2051 dwc3_gadget_resume(dwc);
2052 spin_unlock_irqrestore(&dwc->lock, flags);
2064 static int dwc3_runtime_checks(struct dwc3 *dwc)
2066 switch (dwc->current_dr_role) {
2067 case DWC3_GCTL_PRTCAP_DEVICE:
2071 case DWC3_GCTL_PRTCAP_HOST:
2080 static int dwc3_runtime_suspend(struct device *dev)
2082 struct dwc3 *dwc = dev_get_drvdata(dev);
2085 if (dwc3_runtime_checks(dwc))
2088 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND);
2092 device_init_wakeup(dev, true);
2097 static int dwc3_runtime_resume(struct device *dev)
2099 struct dwc3 *dwc = dev_get_drvdata(dev);
2102 device_init_wakeup(dev, false);
2104 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME);
2108 switch (dwc->current_dr_role) {
2109 case DWC3_GCTL_PRTCAP_DEVICE:
2110 dwc3_gadget_process_pending_events(dwc);
2112 case DWC3_GCTL_PRTCAP_HOST:
2118 pm_runtime_mark_last_busy(dev);
2123 static int dwc3_runtime_idle(struct device *dev)
2125 struct dwc3 *dwc = dev_get_drvdata(dev);
2127 switch (dwc->current_dr_role) {
2128 case DWC3_GCTL_PRTCAP_DEVICE:
2129 if (dwc3_runtime_checks(dwc))
2132 case DWC3_GCTL_PRTCAP_HOST:
2138 pm_runtime_mark_last_busy(dev);
2139 pm_runtime_autosuspend(dev);
2143 #endif /* CONFIG_PM */
2145 #ifdef CONFIG_PM_SLEEP
2146 static int dwc3_suspend(struct device *dev)
2148 struct dwc3 *dwc = dev_get_drvdata(dev);
2151 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
2155 pinctrl_pm_select_sleep_state(dev);
2160 static int dwc3_resume(struct device *dev)
2162 struct dwc3 *dwc = dev_get_drvdata(dev);
2165 pinctrl_pm_select_default_state(dev);
2167 ret = dwc3_resume_common(dwc, PMSG_RESUME);
2171 pm_runtime_disable(dev);
2172 pm_runtime_set_active(dev);
2173 pm_runtime_enable(dev);
2178 static void dwc3_complete(struct device *dev)
2180 struct dwc3 *dwc = dev_get_drvdata(dev);
2183 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
2184 dwc->dis_split_quirk) {
2185 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
2186 reg |= DWC3_GUCTL3_SPLITDISABLE;
2187 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
2191 #define dwc3_complete NULL
2192 #endif /* CONFIG_PM_SLEEP */
2194 static const struct dev_pm_ops dwc3_dev_pm_ops = {
2195 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
2196 .complete = dwc3_complete,
2197 SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,
2202 static const struct of_device_id of_dwc3_match[] = {
2204 .compatible = "snps,dwc3"
2207 .compatible = "synopsys,dwc3"
2211 MODULE_DEVICE_TABLE(of, of_dwc3_match);
2216 #define ACPI_ID_INTEL_BSW "808622B7"
2218 static const struct acpi_device_id dwc3_acpi_match[] = {
2219 { ACPI_ID_INTEL_BSW, 0 },
2222 MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
2225 static struct platform_driver dwc3_driver = {
2226 .probe = dwc3_probe,
2227 .remove = dwc3_remove,
2230 .of_match_table = of_match_ptr(of_dwc3_match),
2231 .acpi_match_table = ACPI_PTR(dwc3_acpi_match),
2232 .pm = &dwc3_dev_pm_ops,
2236 module_platform_driver(dwc3_driver);
2238 MODULE_ALIAS("platform:dwc3");
2239 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
2240 MODULE_LICENSE("GPL v2");
2241 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");