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
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/acpi.h>
27 #include <linux/pinctrl/consumer.h>
28 #include <linux/reset.h>
29 #include <linux/bitfield.h>
31 #include <linux/usb/ch9.h>
32 #include <linux/usb/gadget.h>
33 #include <linux/usb/of.h>
34 #include <linux/usb/otg.h>
42 #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */
45 * dwc3_get_dr_mode - Validates and sets dr_mode
46 * @dwc: pointer to our context structure
48 static int dwc3_get_dr_mode(struct dwc3 *dwc)
50 enum usb_dr_mode mode;
51 struct device *dev = dwc->dev;
54 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
55 dwc->dr_mode = USB_DR_MODE_OTG;
58 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
61 case DWC3_GHWPARAMS0_MODE_GADGET:
62 if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
64 "Controller does not support host mode.\n");
67 mode = USB_DR_MODE_PERIPHERAL;
69 case DWC3_GHWPARAMS0_MODE_HOST:
70 if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
72 "Controller does not support device mode.\n");
75 mode = USB_DR_MODE_HOST;
78 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
79 mode = USB_DR_MODE_HOST;
80 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
81 mode = USB_DR_MODE_PERIPHERAL;
84 * DWC_usb31 and DWC_usb3 v3.30a and higher do not support OTG
85 * mode. If the controller supports DRD but the dr_mode is not
86 * specified or set to OTG, then set the mode to peripheral.
88 if (mode == USB_DR_MODE_OTG &&
89 (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
90 !device_property_read_bool(dwc->dev, "usb-role-switch")) &&
91 !DWC3_VER_IS_PRIOR(DWC3, 330A))
92 mode = USB_DR_MODE_PERIPHERAL;
95 if (mode != dwc->dr_mode) {
97 "Configuration mismatch. dr_mode forced to %s\n",
98 mode == USB_DR_MODE_HOST ? "host" : "gadget");
106 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
110 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
111 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
112 reg |= DWC3_GCTL_PRTCAPDIR(mode);
113 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
115 dwc->current_dr_role = mode;
118 static void __dwc3_set_mode(struct work_struct *work)
120 struct dwc3 *dwc = work_to_dwc(work);
125 mutex_lock(&dwc->mutex);
127 pm_runtime_get_sync(dwc->dev);
129 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
130 dwc3_otg_update(dwc, 0);
132 if (!dwc->desired_dr_role)
135 if (dwc->desired_dr_role == dwc->current_dr_role)
138 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
141 switch (dwc->current_dr_role) {
142 case DWC3_GCTL_PRTCAP_HOST:
145 case DWC3_GCTL_PRTCAP_DEVICE:
146 dwc3_gadget_exit(dwc);
147 dwc3_event_buffers_cleanup(dwc);
149 case DWC3_GCTL_PRTCAP_OTG:
151 spin_lock_irqsave(&dwc->lock, flags);
152 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE;
153 spin_unlock_irqrestore(&dwc->lock, flags);
154 dwc3_otg_update(dwc, 1);
161 * When current_dr_role is not set, there's no role switching.
162 * Only perform GCTL.CoreSoftReset when there's DRD role switching.
164 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
165 DWC3_VER_IS_PRIOR(DWC31, 190A)) &&
166 dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
167 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
168 reg |= DWC3_GCTL_CORESOFTRESET;
169 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
172 * Wait for internal clocks to synchronized. DWC_usb31 and
173 * DWC_usb32 may need at least 50ms (less for DWC_usb3). To
174 * keep it consistent across different IPs, let's wait up to
175 * 100ms before clearing GCTL.CORESOFTRESET.
179 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
180 reg &= ~DWC3_GCTL_CORESOFTRESET;
181 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
184 spin_lock_irqsave(&dwc->lock, flags);
186 dwc3_set_prtcap(dwc, dwc->desired_dr_role);
188 spin_unlock_irqrestore(&dwc->lock, flags);
190 switch (dwc->desired_dr_role) {
191 case DWC3_GCTL_PRTCAP_HOST:
192 ret = dwc3_host_init(dwc);
194 dev_err(dwc->dev, "failed to initialize host\n");
197 otg_set_vbus(dwc->usb2_phy->otg, true);
198 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
199 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
200 if (dwc->dis_split_quirk) {
201 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
202 reg |= DWC3_GUCTL3_SPLITDISABLE;
203 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
207 case DWC3_GCTL_PRTCAP_DEVICE:
208 dwc3_core_soft_reset(dwc);
210 dwc3_event_buffers_setup(dwc);
213 otg_set_vbus(dwc->usb2_phy->otg, false);
214 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
215 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
217 ret = dwc3_gadget_init(dwc);
219 dev_err(dwc->dev, "failed to initialize peripheral\n");
221 case DWC3_GCTL_PRTCAP_OTG:
223 dwc3_otg_update(dwc, 0);
230 pm_runtime_mark_last_busy(dwc->dev);
231 pm_runtime_put_autosuspend(dwc->dev);
232 mutex_unlock(&dwc->mutex);
235 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
239 if (dwc->dr_mode != USB_DR_MODE_OTG)
242 spin_lock_irqsave(&dwc->lock, flags);
243 dwc->desired_dr_role = mode;
244 spin_unlock_irqrestore(&dwc->lock, flags);
246 queue_work(system_freezable_wq, &dwc->drd_work);
249 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
251 struct dwc3 *dwc = dep->dwc;
254 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
255 DWC3_GDBGFIFOSPACE_NUM(dep->number) |
256 DWC3_GDBGFIFOSPACE_TYPE(type));
258 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE);
260 return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg);
264 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
265 * @dwc: pointer to our context structure
267 int dwc3_core_soft_reset(struct dwc3 *dwc)
273 * We're resetting only the device side because, if we're in host mode,
274 * XHCI driver will reset the host block. If dwc3 was configured for
275 * host-only mode, then we can return early.
277 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
280 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
281 reg |= DWC3_DCTL_CSFTRST;
282 reg &= ~DWC3_DCTL_RUN_STOP;
283 dwc3_gadget_dctl_write_safe(dwc, reg);
286 * For DWC_usb31 controller 1.90a and later, the DCTL.CSFRST bit
287 * is cleared only after all the clocks are synchronized. This can
288 * take a little more than 50ms. Set the polling rate at 20ms
289 * for 10 times instead.
291 if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
295 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
296 if (!(reg & DWC3_DCTL_CSFTRST))
299 if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
305 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n");
310 * For DWC_usb31 controller 1.80a and prior, once DCTL.CSFRST bit
311 * is cleared, we must wait at least 50ms before accessing the PHY
312 * domain (synchronization delay).
314 if (DWC3_VER_IS_WITHIN(DWC31, ANY, 180A))
321 * dwc3_frame_length_adjustment - Adjusts frame length if required
322 * @dwc3: Pointer to our controller context structure
324 static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
329 if (DWC3_VER_IS_PRIOR(DWC3, 250A))
335 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
336 dft = reg & DWC3_GFLADJ_30MHZ_MASK;
337 if (dft != dwc->fladj) {
338 reg &= ~DWC3_GFLADJ_30MHZ_MASK;
339 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj;
340 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
345 * dwc3_ref_clk_period - Reference clock period configuration
346 * Default reference clock period depends on hardware
347 * configuration. For systems with reference clock that differs
348 * from the default, this will set clock period in DWC3_GUCTL
350 * @dwc: Pointer to our controller context structure
352 static void dwc3_ref_clk_period(struct dwc3 *dwc)
354 unsigned long period;
361 rate = clk_get_rate(dwc->ref_clk);
364 period = NSEC_PER_SEC / rate;
365 } else if (dwc->ref_clk_per) {
366 period = dwc->ref_clk_per;
367 rate = NSEC_PER_SEC / period;
372 reg = dwc3_readl(dwc->regs, DWC3_GUCTL);
373 reg &= ~DWC3_GUCTL_REFCLKPER_MASK;
374 reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period);
375 dwc3_writel(dwc->regs, DWC3_GUCTL, reg);
377 if (DWC3_VER_IS_PRIOR(DWC3, 250A))
381 * The calculation below is
383 * 125000 * (NSEC_PER_SEC / (rate * period) - 1)
385 * but rearranged for fixed-point arithmetic. The division must be
386 * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and
387 * neither does rate * period).
389 * Note that rate * period ~= NSEC_PER_SECOND, minus the number of
390 * nanoseconds of error caused by the truncation which happened during
391 * the division when calculating rate or period (whichever one was
392 * derived from the other). We first calculate the relative error, then
393 * scale it to units of 8 ppm.
395 fladj = div64_u64(125000ULL * NSEC_PER_SEC, (u64)rate * period);
399 * The documented 240MHz constant is scaled by 2 to get PLS1 as well.
401 decr = 480000000 / rate;
403 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
404 reg &= ~DWC3_GFLADJ_REFCLK_FLADJ_MASK
405 & ~DWC3_GFLADJ_240MHZDECR
406 & ~DWC3_GFLADJ_240MHZDECR_PLS1;
407 reg |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, fladj)
408 | FIELD_PREP(DWC3_GFLADJ_240MHZDECR, decr >> 1)
409 | FIELD_PREP(DWC3_GFLADJ_240MHZDECR_PLS1, decr & 1);
411 if (dwc->gfladj_refclk_lpm_sel)
412 reg |= DWC3_GFLADJ_REFCLK_LPM_SEL;
414 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
418 * dwc3_free_one_event_buffer - Frees one event buffer
419 * @dwc: Pointer to our controller context structure
420 * @evt: Pointer to event buffer to be freed
422 static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
423 struct dwc3_event_buffer *evt)
425 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma);
429 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
430 * @dwc: Pointer to our controller context structure
431 * @length: size of the event buffer
433 * Returns a pointer to the allocated event buffer structure on success
434 * otherwise ERR_PTR(errno).
436 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
439 struct dwc3_event_buffer *evt;
441 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
443 return ERR_PTR(-ENOMEM);
446 evt->length = length;
447 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL);
449 return ERR_PTR(-ENOMEM);
451 evt->buf = dma_alloc_coherent(dwc->sysdev, length,
452 &evt->dma, GFP_KERNEL);
454 return ERR_PTR(-ENOMEM);
460 * dwc3_free_event_buffers - frees all allocated event buffers
461 * @dwc: Pointer to our controller context structure
463 static void dwc3_free_event_buffers(struct dwc3 *dwc)
465 struct dwc3_event_buffer *evt;
469 dwc3_free_one_event_buffer(dwc, evt);
473 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
474 * @dwc: pointer to our controller context structure
475 * @length: size of event buffer
477 * Returns 0 on success otherwise negative errno. In the error case, dwc
478 * may contain some buffers allocated but not all which were requested.
480 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length)
482 struct dwc3_event_buffer *evt;
484 evt = dwc3_alloc_one_event_buffer(dwc, length);
486 dev_err(dwc->dev, "can't allocate event buffer\n");
495 * dwc3_event_buffers_setup - setup our allocated event buffers
496 * @dwc: pointer to our controller context structure
498 * Returns 0 on success otherwise negative errno.
500 int dwc3_event_buffers_setup(struct dwc3 *dwc)
502 struct dwc3_event_buffer *evt;
506 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0),
507 lower_32_bits(evt->dma));
508 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0),
509 upper_32_bits(evt->dma));
510 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
511 DWC3_GEVNTSIZ_SIZE(evt->length));
512 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
517 void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
519 struct dwc3_event_buffer *evt;
525 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0);
526 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0);
527 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK
528 | DWC3_GEVNTSIZ_SIZE(0));
529 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
532 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
534 if (!dwc->has_hibernation)
537 if (!dwc->nr_scratch)
540 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
541 DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
542 if (!dwc->scratchbuf)
548 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
550 dma_addr_t scratch_addr;
554 if (!dwc->has_hibernation)
557 if (!dwc->nr_scratch)
560 /* should never fall here */
561 if (!WARN_ON(dwc->scratchbuf))
564 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf,
565 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
567 if (dma_mapping_error(dwc->sysdev, scratch_addr)) {
568 dev_err(dwc->sysdev, "failed to map scratch buffer\n");
573 dwc->scratch_addr = scratch_addr;
575 param = lower_32_bits(scratch_addr);
577 ret = dwc3_send_gadget_generic_command(dwc,
578 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
582 param = upper_32_bits(scratch_addr);
584 ret = dwc3_send_gadget_generic_command(dwc,
585 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
592 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
593 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
599 static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
601 if (!dwc->has_hibernation)
604 if (!dwc->nr_scratch)
607 /* should never fall here */
608 if (!WARN_ON(dwc->scratchbuf))
611 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
612 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
613 kfree(dwc->scratchbuf);
616 static void dwc3_core_num_eps(struct dwc3 *dwc)
618 struct dwc3_hwparams *parms = &dwc->hwparams;
620 dwc->num_eps = DWC3_NUM_EPS(parms);
623 static void dwc3_cache_hwparams(struct dwc3 *dwc)
625 struct dwc3_hwparams *parms = &dwc->hwparams;
627 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
628 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
629 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
630 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
631 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
632 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
633 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
634 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
635 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
637 if (DWC3_IP_IS(DWC32))
638 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9);
641 static int dwc3_core_ulpi_init(struct dwc3 *dwc)
646 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3);
648 if (intf == DWC3_GHWPARAMS3_HSPHY_IFC_ULPI ||
649 (intf == DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI &&
650 dwc->hsphy_interface &&
651 !strncmp(dwc->hsphy_interface, "ulpi", 4)))
652 ret = dwc3_ulpi_init(dwc);
658 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
659 * @dwc: Pointer to our controller context structure
661 * Returns 0 on success. The USB PHY interfaces are configured but not
662 * initialized. The PHY interfaces and the PHYs get initialized together with
663 * the core in dwc3_core_init.
665 static int dwc3_phy_setup(struct dwc3 *dwc)
667 unsigned int hw_mode;
670 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
672 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
675 * Make sure UX_EXIT_PX is cleared as that causes issues with some
676 * PHYs. Also, this bit is not supposed to be used in normal operation.
678 reg &= ~DWC3_GUSB3PIPECTL_UX_EXIT_PX;
681 * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
682 * to '0' during coreConsultant configuration. So default value
683 * will be '0' when the core is reset. Application needs to set it
684 * to '1' after the core initialization is completed.
686 if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A))
687 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
690 * For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be cleared after
691 * power-on reset, and it can be set after core initialization, which is
692 * after device soft-reset during initialization.
694 if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD)
695 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
697 if (dwc->u2ss_inp3_quirk)
698 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
700 if (dwc->dis_rxdet_inp3_quirk)
701 reg |= DWC3_GUSB3PIPECTL_DISRXDETINP3;
703 if (dwc->req_p1p2p3_quirk)
704 reg |= DWC3_GUSB3PIPECTL_REQP1P2P3;
706 if (dwc->del_p1p2p3_quirk)
707 reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN;
709 if (dwc->del_phy_power_chg_quirk)
710 reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE;
712 if (dwc->lfps_filter_quirk)
713 reg |= DWC3_GUSB3PIPECTL_LFPSFILT;
715 if (dwc->rx_detect_poll_quirk)
716 reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL;
718 if (dwc->tx_de_emphasis_quirk)
719 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis);
721 if (dwc->dis_u3_susphy_quirk)
722 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
724 if (dwc->dis_del_phy_power_chg_quirk)
725 reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE;
727 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
729 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
731 /* Select the HS PHY interface */
732 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
733 case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
734 if (dwc->hsphy_interface &&
735 !strncmp(dwc->hsphy_interface, "utmi", 4)) {
736 reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI;
738 } else if (dwc->hsphy_interface &&
739 !strncmp(dwc->hsphy_interface, "ulpi", 4)) {
740 reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
741 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
743 /* Relying on default value. */
744 if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI))
748 case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
753 switch (dwc->hsphy_mode) {
754 case USBPHY_INTERFACE_MODE_UTMI:
755 reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
756 DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
757 reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) |
758 DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT);
760 case USBPHY_INTERFACE_MODE_UTMIW:
761 reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
762 DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
763 reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) |
764 DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT);
771 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
772 * '0' during coreConsultant configuration. So default value will
773 * be '0' when the core is reset. Application needs to set it to
774 * '1' after the core initialization is completed.
776 if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A))
777 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
780 * For DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared after
781 * power-on reset, and it can be set after core initialization, which is
782 * after device soft-reset during initialization.
784 if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD)
785 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
787 if (dwc->dis_u2_susphy_quirk)
788 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
790 if (dwc->dis_enblslpm_quirk)
791 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
793 reg |= DWC3_GUSB2PHYCFG_ENBLSLPM;
795 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel)
796 reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS;
798 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
803 static int dwc3_clk_enable(struct dwc3 *dwc)
807 ret = clk_prepare_enable(dwc->bus_clk);
811 ret = clk_prepare_enable(dwc->ref_clk);
813 goto disable_bus_clk;
815 ret = clk_prepare_enable(dwc->susp_clk);
817 goto disable_ref_clk;
822 clk_disable_unprepare(dwc->ref_clk);
824 clk_disable_unprepare(dwc->bus_clk);
828 static void dwc3_clk_disable(struct dwc3 *dwc)
830 clk_disable_unprepare(dwc->susp_clk);
831 clk_disable_unprepare(dwc->ref_clk);
832 clk_disable_unprepare(dwc->bus_clk);
835 static void dwc3_core_exit(struct dwc3 *dwc)
837 dwc3_event_buffers_cleanup(dwc);
839 usb_phy_set_suspend(dwc->usb2_phy, 1);
840 usb_phy_set_suspend(dwc->usb3_phy, 1);
841 phy_power_off(dwc->usb2_generic_phy);
842 phy_power_off(dwc->usb3_generic_phy);
844 usb_phy_shutdown(dwc->usb2_phy);
845 usb_phy_shutdown(dwc->usb3_phy);
846 phy_exit(dwc->usb2_generic_phy);
847 phy_exit(dwc->usb3_generic_phy);
849 dwc3_clk_disable(dwc);
850 reset_control_assert(dwc->reset);
853 static bool dwc3_core_is_valid(struct dwc3 *dwc)
857 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
858 dwc->ip = DWC3_GSNPS_ID(reg);
860 /* This should read as U3 followed by revision number */
861 if (DWC3_IP_IS(DWC3)) {
863 } else if (DWC3_IP_IS(DWC31) || DWC3_IP_IS(DWC32)) {
864 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
865 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE);
873 static void dwc3_core_setup_global_control(struct dwc3 *dwc)
875 u32 hwparams4 = dwc->hwparams.hwparams4;
878 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
879 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
881 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
882 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
884 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
885 * issue which would cause xHCI compliance tests to fail.
887 * Because of that we cannot enable clock gating on such
892 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
895 if ((dwc->dr_mode == USB_DR_MODE_HOST ||
896 dwc->dr_mode == USB_DR_MODE_OTG) &&
897 DWC3_VER_IS_WITHIN(DWC3, 210A, 250A))
898 reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
900 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
902 case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
903 /* enable hibernation here */
904 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
907 * REVISIT Enabling this bit so that host-mode hibernation
908 * will work. Device-mode hibernation is not yet implemented.
910 reg |= DWC3_GCTL_GBLHIBERNATIONEN;
917 /* check if current dwc3 is on simulation board */
918 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
919 dev_info(dwc->dev, "Running with FPGA optimizations\n");
923 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
924 "disable_scramble cannot be used on non-FPGA builds\n");
926 if (dwc->disable_scramble_quirk && dwc->is_fpga)
927 reg |= DWC3_GCTL_DISSCRAMBLE;
929 reg &= ~DWC3_GCTL_DISSCRAMBLE;
931 if (dwc->u2exit_lfps_quirk)
932 reg |= DWC3_GCTL_U2EXIT_LFPS;
935 * WORKAROUND: DWC3 revisions <1.90a have a bug
936 * where the device can fail to connect at SuperSpeed
937 * and falls back to high-speed mode which causes
938 * the device to enter a Connect/Disconnect loop
940 if (DWC3_VER_IS_PRIOR(DWC3, 190A))
941 reg |= DWC3_GCTL_U2RSTECN;
943 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
946 static int dwc3_core_get_phy(struct dwc3 *dwc);
947 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
949 /* set global incr burst type configuration registers */
950 static void dwc3_set_incr_burst_type(struct dwc3 *dwc)
952 struct device *dev = dwc->dev;
953 /* incrx_mode : for INCR burst type. */
955 /* incrx_size : for size of INCRX burst. */
963 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
966 * Handle property "snps,incr-burst-type-adjustment".
967 * Get the number of value from this property:
968 * result <= 0, means this property is not supported.
969 * result = 1, means INCRx burst mode supported.
970 * result > 1, means undefined length burst mode supported.
972 ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment");
976 vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL);
980 /* Get INCR burst type, and parse it */
981 ret = device_property_read_u32_array(dev,
982 "snps,incr-burst-type-adjustment", vals, ntype);
985 dev_err(dev, "Error to get property\n");
992 /* INCRX (undefined length) burst mode */
993 incrx_mode = INCRX_UNDEF_LENGTH_BURST_MODE;
994 for (i = 1; i < ntype; i++) {
995 if (vals[i] > incrx_size)
996 incrx_size = vals[i];
999 /* INCRX burst mode */
1000 incrx_mode = INCRX_BURST_MODE;
1005 /* Enable Undefined Length INCR Burst and Enable INCRx Burst */
1006 cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
1008 cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
1009 switch (incrx_size) {
1011 cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
1014 cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
1017 cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
1020 cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
1023 cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
1026 cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
1029 cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
1034 dev_err(dev, "Invalid property\n");
1038 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
1041 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc)
1050 * The power down scale field specifies how many suspend_clk
1051 * periods fit into a 16KHz clock period. When performing
1052 * the division, round up the remainder.
1054 * The power down scale value is calculated using the fastest
1055 * frequency of the suspend_clk. If it isn't fixed (but within
1056 * the accuracy requirement), the driver may not know the max
1057 * rate of the suspend_clk, so only update the power down scale
1058 * if the default is less than the calculated value from
1059 * clk_get_rate() or if the default is questionably high
1060 * (3x or more) to be within the requirement.
1062 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000);
1063 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
1064 if ((reg & DWC3_GCTL_PWRDNSCALE_MASK) < DWC3_GCTL_PWRDNSCALE(scale) ||
1065 (reg & DWC3_GCTL_PWRDNSCALE_MASK) > DWC3_GCTL_PWRDNSCALE(scale*3)) {
1066 reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK);
1067 reg |= DWC3_GCTL_PWRDNSCALE(scale);
1068 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
1073 * dwc3_core_init - Low-level initialization of DWC3 Core
1074 * @dwc: Pointer to our controller context structure
1076 * Returns 0 on success otherwise negative errno.
1078 static int dwc3_core_init(struct dwc3 *dwc)
1080 unsigned int hw_mode;
1084 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
1087 * Write Linux Version Code to our GUID register so it's easy to figure
1088 * out which kernel version a bug was found.
1090 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
1092 ret = dwc3_phy_setup(dwc);
1096 if (!dwc->ulpi_ready) {
1097 ret = dwc3_core_ulpi_init(dwc);
1100 dwc->ulpi_ready = true;
1103 if (!dwc->phys_ready) {
1104 ret = dwc3_core_get_phy(dwc);
1107 dwc->phys_ready = true;
1110 usb_phy_init(dwc->usb2_phy);
1111 usb_phy_init(dwc->usb3_phy);
1112 ret = phy_init(dwc->usb2_generic_phy);
1116 ret = phy_init(dwc->usb3_generic_phy);
1118 phy_exit(dwc->usb2_generic_phy);
1122 ret = dwc3_core_soft_reset(dwc);
1126 if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD &&
1127 !DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) {
1128 if (!dwc->dis_u3_susphy_quirk) {
1129 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
1130 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
1131 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
1134 if (!dwc->dis_u2_susphy_quirk) {
1135 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1136 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
1137 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1141 dwc3_core_setup_global_control(dwc);
1142 dwc3_core_num_eps(dwc);
1144 ret = dwc3_setup_scratch_buffers(dwc);
1148 /* Set power down scale of suspend_clk */
1149 dwc3_set_power_down_clk_scale(dwc);
1151 /* Adjust Frame Length */
1152 dwc3_frame_length_adjustment(dwc);
1154 /* Adjust Reference Clock Period */
1155 dwc3_ref_clk_period(dwc);
1157 dwc3_set_incr_burst_type(dwc);
1159 usb_phy_set_suspend(dwc->usb2_phy, 0);
1160 usb_phy_set_suspend(dwc->usb3_phy, 0);
1161 ret = phy_power_on(dwc->usb2_generic_phy);
1165 ret = phy_power_on(dwc->usb3_generic_phy);
1169 ret = dwc3_event_buffers_setup(dwc);
1171 dev_err(dwc->dev, "failed to setup event buffers\n");
1176 * ENDXFER polling is available on version 3.10a and later of
1177 * the DWC_usb3 controller. It is NOT available in the
1178 * DWC_usb31 controller.
1180 if (DWC3_VER_IS_WITHIN(DWC3, 310A, ANY)) {
1181 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2);
1182 reg |= DWC3_GUCTL2_RST_ACTBITLATER;
1183 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg);
1187 * When configured in HOST mode, after issuing U3/L2 exit controller
1188 * fails to send proper CRC checksum in CRC5 feild. Because of this
1189 * behaviour Transaction Error is generated, resulting in reset and
1190 * re-enumeration of usb device attached. All the termsel, xcvrsel,
1191 * opmode becomes 0 during end of resume. Enabling bit 10 of GUCTL1
1192 * will correct this problem. This option is to support certain
1195 if (dwc->resume_hs_terminations) {
1196 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1);
1197 reg |= DWC3_GUCTL1_RESUME_OPMODE_HS_HOST;
1198 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg);
1201 if (!DWC3_VER_IS_PRIOR(DWC3, 250A)) {
1202 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1);
1205 * Enable hardware control of sending remote wakeup
1206 * in HS when the device is in the L1 state.
1208 if (!DWC3_VER_IS_PRIOR(DWC3, 290A))
1209 reg |= DWC3_GUCTL1_DEV_L1_EXIT_BY_HW;
1212 * Decouple USB 2.0 L1 & L2 events which will allow for
1213 * gadget driver to only receive U3/L2 suspend & wakeup
1214 * events and prevent the more frequent L1 LPM transitions
1215 * from interrupting the driver.
1217 if (!DWC3_VER_IS_PRIOR(DWC3, 300A))
1218 reg |= DWC3_GUCTL1_DEV_DECOUPLE_L1L2_EVT;
1220 if (dwc->dis_tx_ipgap_linecheck_quirk)
1221 reg |= DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS;
1223 if (dwc->parkmode_disable_ss_quirk)
1224 reg |= DWC3_GUCTL1_PARKMODE_DISABLE_SS;
1226 if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY) &&
1227 (dwc->maximum_speed == USB_SPEED_HIGH ||
1228 dwc->maximum_speed == USB_SPEED_FULL))
1229 reg |= DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK;
1231 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg);
1234 if (dwc->dr_mode == USB_DR_MODE_HOST ||
1235 dwc->dr_mode == USB_DR_MODE_OTG) {
1236 reg = dwc3_readl(dwc->regs, DWC3_GUCTL);
1239 * Enable Auto retry Feature to make the controller operating in
1240 * Host mode on seeing transaction errors(CRC errors or internal
1241 * overrun scenerios) on IN transfers to reply to the device
1242 * with a non-terminating retry ACK (i.e, an ACK transcation
1243 * packet with Retry=1 & Nump != 0)
1245 reg |= DWC3_GUCTL_HSTINAUTORETRY;
1247 dwc3_writel(dwc->regs, DWC3_GUCTL, reg);
1251 * Must config both number of packets and max burst settings to enable
1252 * RX and/or TX threshold.
1254 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) {
1255 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd;
1256 u8 rx_maxburst = dwc->rx_max_burst_prd;
1257 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd;
1258 u8 tx_maxburst = dwc->tx_max_burst_prd;
1260 if (rx_thr_num && rx_maxburst) {
1261 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG);
1262 reg |= DWC31_RXTHRNUMPKTSEL_PRD;
1264 reg &= ~DWC31_RXTHRNUMPKT_PRD(~0);
1265 reg |= DWC31_RXTHRNUMPKT_PRD(rx_thr_num);
1267 reg &= ~DWC31_MAXRXBURSTSIZE_PRD(~0);
1268 reg |= DWC31_MAXRXBURSTSIZE_PRD(rx_maxburst);
1270 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg);
1273 if (tx_thr_num && tx_maxburst) {
1274 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG);
1275 reg |= DWC31_TXTHRNUMPKTSEL_PRD;
1277 reg &= ~DWC31_TXTHRNUMPKT_PRD(~0);
1278 reg |= DWC31_TXTHRNUMPKT_PRD(tx_thr_num);
1280 reg &= ~DWC31_MAXTXBURSTSIZE_PRD(~0);
1281 reg |= DWC31_MAXTXBURSTSIZE_PRD(tx_maxburst);
1283 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg);
1290 phy_power_off(dwc->usb3_generic_phy);
1293 phy_power_off(dwc->usb2_generic_phy);
1296 usb_phy_set_suspend(dwc->usb2_phy, 1);
1297 usb_phy_set_suspend(dwc->usb3_phy, 1);
1300 usb_phy_shutdown(dwc->usb2_phy);
1301 usb_phy_shutdown(dwc->usb3_phy);
1302 phy_exit(dwc->usb2_generic_phy);
1303 phy_exit(dwc->usb3_generic_phy);
1306 dwc3_ulpi_exit(dwc);
1312 static int dwc3_core_get_phy(struct dwc3 *dwc)
1314 struct device *dev = dwc->dev;
1315 struct device_node *node = dev->of_node;
1319 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
1320 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
1322 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
1323 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
1326 if (IS_ERR(dwc->usb2_phy)) {
1327 ret = PTR_ERR(dwc->usb2_phy);
1328 if (ret == -ENXIO || ret == -ENODEV)
1329 dwc->usb2_phy = NULL;
1331 return dev_err_probe(dev, ret, "no usb2 phy configured\n");
1334 if (IS_ERR(dwc->usb3_phy)) {
1335 ret = PTR_ERR(dwc->usb3_phy);
1336 if (ret == -ENXIO || ret == -ENODEV)
1337 dwc->usb3_phy = NULL;
1339 return dev_err_probe(dev, ret, "no usb3 phy configured\n");
1342 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
1343 if (IS_ERR(dwc->usb2_generic_phy)) {
1344 ret = PTR_ERR(dwc->usb2_generic_phy);
1345 if (ret == -ENOSYS || ret == -ENODEV)
1346 dwc->usb2_generic_phy = NULL;
1348 return dev_err_probe(dev, ret, "no usb2 phy configured\n");
1351 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
1352 if (IS_ERR(dwc->usb3_generic_phy)) {
1353 ret = PTR_ERR(dwc->usb3_generic_phy);
1354 if (ret == -ENOSYS || ret == -ENODEV)
1355 dwc->usb3_generic_phy = NULL;
1357 return dev_err_probe(dev, ret, "no usb3 phy configured\n");
1363 static int dwc3_core_init_mode(struct dwc3 *dwc)
1365 struct device *dev = dwc->dev;
1368 switch (dwc->dr_mode) {
1369 case USB_DR_MODE_PERIPHERAL:
1370 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1373 otg_set_vbus(dwc->usb2_phy->otg, false);
1374 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
1375 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
1377 ret = dwc3_gadget_init(dwc);
1379 return dev_err_probe(dev, ret, "failed to initialize gadget\n");
1381 case USB_DR_MODE_HOST:
1382 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
1385 otg_set_vbus(dwc->usb2_phy->otg, true);
1386 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
1387 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
1389 ret = dwc3_host_init(dwc);
1391 return dev_err_probe(dev, ret, "failed to initialize host\n");
1393 case USB_DR_MODE_OTG:
1394 INIT_WORK(&dwc->drd_work, __dwc3_set_mode);
1395 ret = dwc3_drd_init(dwc);
1397 return dev_err_probe(dev, ret, "failed to initialize dual-role\n");
1400 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
1407 static void dwc3_core_exit_mode(struct dwc3 *dwc)
1409 switch (dwc->dr_mode) {
1410 case USB_DR_MODE_PERIPHERAL:
1411 dwc3_gadget_exit(dwc);
1413 case USB_DR_MODE_HOST:
1414 dwc3_host_exit(dwc);
1416 case USB_DR_MODE_OTG:
1424 /* de-assert DRVVBUS for HOST and OTG mode */
1425 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1428 static void dwc3_get_properties(struct dwc3 *dwc)
1430 struct device *dev = dwc->dev;
1431 u8 lpm_nyet_threshold;
1434 u8 rx_thr_num_pkt_prd = 0;
1435 u8 rx_max_burst_prd = 0;
1436 u8 tx_thr_num_pkt_prd = 0;
1437 u8 tx_max_burst_prd = 0;
1438 u8 tx_fifo_resize_max_num;
1439 const char *usb_psy_name;
1442 /* default to highest possible threshold */
1443 lpm_nyet_threshold = 0xf;
1445 /* default to -3.5dB de-emphasis */
1449 * default to assert utmi_sleep_n and use maximum allowed HIRD
1450 * threshold value of 0b1100
1452 hird_threshold = 12;
1455 * default to a TXFIFO size large enough to fit 6 max packets. This
1456 * allows for systems with larger bus latencies to have some headroom
1457 * for endpoints that have a large bMaxBurst value.
1459 tx_fifo_resize_max_num = 6;
1461 dwc->maximum_speed = usb_get_maximum_speed(dev);
1462 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev);
1463 dwc->dr_mode = usb_get_dr_mode(dev);
1464 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
1466 dwc->sysdev_is_parent = device_property_read_bool(dev,
1467 "linux,sysdev_is_parent");
1468 if (dwc->sysdev_is_parent)
1469 dwc->sysdev = dwc->dev->parent;
1471 dwc->sysdev = dwc->dev;
1473 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
1475 dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
1477 dev_err(dev, "couldn't get usb power supply\n");
1480 dwc->has_lpm_erratum = device_property_read_bool(dev,
1481 "snps,has-lpm-erratum");
1482 device_property_read_u8(dev, "snps,lpm-nyet-threshold",
1483 &lpm_nyet_threshold);
1484 dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
1485 "snps,is-utmi-l1-suspend");
1486 device_property_read_u8(dev, "snps,hird-threshold",
1488 dwc->dis_start_transfer_quirk = device_property_read_bool(dev,
1489 "snps,dis-start-transfer-quirk");
1490 dwc->usb3_lpm_capable = device_property_read_bool(dev,
1491 "snps,usb3_lpm_capable");
1492 dwc->usb2_lpm_disable = device_property_read_bool(dev,
1493 "snps,usb2-lpm-disable");
1494 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev,
1495 "snps,usb2-gadget-lpm-disable");
1496 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd",
1497 &rx_thr_num_pkt_prd);
1498 device_property_read_u8(dev, "snps,rx-max-burst-prd",
1500 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd",
1501 &tx_thr_num_pkt_prd);
1502 device_property_read_u8(dev, "snps,tx-max-burst-prd",
1504 dwc->do_fifo_resize = device_property_read_bool(dev,
1506 if (dwc->do_fifo_resize)
1507 device_property_read_u8(dev, "tx-fifo-max-num",
1508 &tx_fifo_resize_max_num);
1510 dwc->disable_scramble_quirk = device_property_read_bool(dev,
1511 "snps,disable_scramble_quirk");
1512 dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
1513 "snps,u2exit_lfps_quirk");
1514 dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
1515 "snps,u2ss_inp3_quirk");
1516 dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
1517 "snps,req_p1p2p3_quirk");
1518 dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
1519 "snps,del_p1p2p3_quirk");
1520 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
1521 "snps,del_phy_power_chg_quirk");
1522 dwc->lfps_filter_quirk = device_property_read_bool(dev,
1523 "snps,lfps_filter_quirk");
1524 dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
1525 "snps,rx_detect_poll_quirk");
1526 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
1527 "snps,dis_u3_susphy_quirk");
1528 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
1529 "snps,dis_u2_susphy_quirk");
1530 dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
1531 "snps,dis_enblslpm_quirk");
1532 dwc->dis_u1_entry_quirk = device_property_read_bool(dev,
1533 "snps,dis-u1-entry-quirk");
1534 dwc->dis_u2_entry_quirk = device_property_read_bool(dev,
1535 "snps,dis-u2-entry-quirk");
1536 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
1537 "snps,dis_rxdet_inp3_quirk");
1538 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
1539 "snps,dis-u2-freeclk-exists-quirk");
1540 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
1541 "snps,dis-del-phy-power-chg-quirk");
1542 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev,
1543 "snps,dis-tx-ipgap-linecheck-quirk");
1544 dwc->resume_hs_terminations = device_property_read_bool(dev,
1545 "snps,resume-hs-terminations");
1546 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev,
1547 "snps,parkmode-disable-ss-quirk");
1548 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev,
1549 "snps,gfladj-refclk-lpm-sel-quirk");
1551 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
1552 "snps,tx_de_emphasis_quirk");
1553 device_property_read_u8(dev, "snps,tx_de_emphasis",
1555 device_property_read_string(dev, "snps,hsphy_interface",
1556 &dwc->hsphy_interface);
1557 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
1559 device_property_read_u32(dev, "snps,ref-clock-period-ns",
1562 dwc->dis_metastability_quirk = device_property_read_bool(dev,
1563 "snps,dis_metastability_quirk");
1565 dwc->dis_split_quirk = device_property_read_bool(dev,
1566 "snps,dis-split-quirk");
1568 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
1569 dwc->tx_de_emphasis = tx_de_emphasis;
1571 dwc->hird_threshold = hird_threshold;
1573 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd;
1574 dwc->rx_max_burst_prd = rx_max_burst_prd;
1576 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd;
1577 dwc->tx_max_burst_prd = tx_max_burst_prd;
1579 dwc->imod_interval = 0;
1581 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
1584 /* check whether the core supports IMOD */
1585 bool dwc3_has_imod(struct dwc3 *dwc)
1587 return DWC3_VER_IS_WITHIN(DWC3, 300A, ANY) ||
1588 DWC3_VER_IS_WITHIN(DWC31, 120A, ANY) ||
1592 static void dwc3_check_params(struct dwc3 *dwc)
1594 struct device *dev = dwc->dev;
1595 unsigned int hwparam_gen =
1596 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3);
1598 /* Check for proper value of imod_interval */
1599 if (dwc->imod_interval && !dwc3_has_imod(dwc)) {
1600 dev_warn(dwc->dev, "Interrupt moderation not supported\n");
1601 dwc->imod_interval = 0;
1605 * Workaround for STAR 9000961433 which affects only version
1606 * 3.00a of the DWC_usb3 core. This prevents the controller
1607 * interrupt from being masked while handling events. IMOD
1608 * allows us to work around this issue. Enable it for the
1611 if (!dwc->imod_interval &&
1612 DWC3_VER_IS(DWC3, 300A))
1613 dwc->imod_interval = 1;
1615 /* Check the maximum_speed parameter */
1616 switch (dwc->maximum_speed) {
1617 case USB_SPEED_FULL:
1618 case USB_SPEED_HIGH:
1620 case USB_SPEED_SUPER:
1621 if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS)
1622 dev_warn(dev, "UDC doesn't support Gen 1\n");
1624 case USB_SPEED_SUPER_PLUS:
1625 if ((DWC3_IP_IS(DWC32) &&
1626 hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS) ||
1627 (!DWC3_IP_IS(DWC32) &&
1628 hwparam_gen != DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
1629 dev_warn(dev, "UDC doesn't support SSP\n");
1632 dev_err(dev, "invalid maximum_speed parameter %d\n",
1633 dwc->maximum_speed);
1635 case USB_SPEED_UNKNOWN:
1636 switch (hwparam_gen) {
1637 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1638 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1640 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1641 if (DWC3_IP_IS(DWC32))
1642 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1644 dwc->maximum_speed = USB_SPEED_SUPER;
1646 case DWC3_GHWPARAMS3_SSPHY_IFC_DIS:
1647 dwc->maximum_speed = USB_SPEED_HIGH;
1650 dwc->maximum_speed = USB_SPEED_SUPER;
1657 * Currently the controller does not have visibility into the HW
1658 * parameter to determine the maximum number of lanes the HW supports.
1659 * If the number of lanes is not specified in the device property, then
1660 * set the default to support dual-lane for DWC_usb32 and single-lane
1661 * for DWC_usb31 for super-speed-plus.
1663 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) {
1664 switch (dwc->max_ssp_rate) {
1665 case USB_SSP_GEN_2x1:
1666 if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_GEN1)
1667 dev_warn(dev, "UDC only supports Gen 1\n");
1669 case USB_SSP_GEN_1x2:
1670 case USB_SSP_GEN_2x2:
1671 if (DWC3_IP_IS(DWC31))
1672 dev_warn(dev, "UDC only supports single lane\n");
1674 case USB_SSP_GEN_UNKNOWN:
1676 switch (hwparam_gen) {
1677 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1678 if (DWC3_IP_IS(DWC32))
1679 dwc->max_ssp_rate = USB_SSP_GEN_2x2;
1681 dwc->max_ssp_rate = USB_SSP_GEN_2x1;
1683 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1684 if (DWC3_IP_IS(DWC32))
1685 dwc->max_ssp_rate = USB_SSP_GEN_1x2;
1693 static int dwc3_probe(struct platform_device *pdev)
1695 struct device *dev = &pdev->dev;
1696 struct resource *res, dwc_res;
1703 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
1709 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1711 dev_err(dev, "missing memory resource\n");
1715 dwc->xhci_resources[0].start = res->start;
1716 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
1718 dwc->xhci_resources[0].flags = res->flags;
1719 dwc->xhci_resources[0].name = res->name;
1722 * Request memory region but exclude xHCI regs,
1723 * since it will be requested by the xhci-plat driver.
1726 dwc_res.start += DWC3_GLOBALS_REGS_START;
1728 regs = devm_ioremap_resource(dev, &dwc_res);
1730 return PTR_ERR(regs);
1733 dwc->regs_size = resource_size(&dwc_res);
1735 dwc3_get_properties(dwc);
1737 dwc->reset = devm_reset_control_array_get_optional_shared(dev);
1738 if (IS_ERR(dwc->reset)) {
1739 ret = PTR_ERR(dwc->reset);
1745 * Clocks are optional, but new DT platforms should support all
1746 * clocks as required by the DT-binding.
1747 * Some devices have different clock names in legacy device trees,
1748 * check for them to retain backwards compatibility.
1750 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early");
1751 if (IS_ERR(dwc->bus_clk)) {
1752 ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
1753 "could not get bus clock\n");
1757 if (dwc->bus_clk == NULL) {
1758 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk");
1759 if (IS_ERR(dwc->bus_clk)) {
1760 ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
1761 "could not get bus clock\n");
1766 dwc->ref_clk = devm_clk_get_optional(dev, "ref");
1767 if (IS_ERR(dwc->ref_clk)) {
1768 ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
1769 "could not get ref clock\n");
1773 if (dwc->ref_clk == NULL) {
1774 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk");
1775 if (IS_ERR(dwc->ref_clk)) {
1776 ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
1777 "could not get ref clock\n");
1782 dwc->susp_clk = devm_clk_get_optional(dev, "suspend");
1783 if (IS_ERR(dwc->susp_clk)) {
1784 ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
1785 "could not get suspend clock\n");
1789 if (dwc->susp_clk == NULL) {
1790 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk");
1791 if (IS_ERR(dwc->susp_clk)) {
1792 ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
1793 "could not get suspend clock\n");
1799 ret = reset_control_deassert(dwc->reset);
1803 ret = dwc3_clk_enable(dwc);
1807 if (!dwc3_core_is_valid(dwc)) {
1808 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
1813 platform_set_drvdata(pdev, dwc);
1814 dwc3_cache_hwparams(dwc);
1816 if (!dwc->sysdev_is_parent &&
1817 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) {
1818 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
1823 spin_lock_init(&dwc->lock);
1824 mutex_init(&dwc->mutex);
1826 pm_runtime_set_active(dev);
1827 pm_runtime_use_autosuspend(dev);
1828 pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
1829 pm_runtime_enable(dev);
1830 ret = pm_runtime_get_sync(dev);
1834 pm_runtime_forbid(dev);
1836 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
1838 dev_err(dwc->dev, "failed to allocate event buffers\n");
1843 ret = dwc3_get_dr_mode(dwc);
1847 ret = dwc3_alloc_scratch_buffers(dwc);
1851 ret = dwc3_core_init(dwc);
1853 dev_err_probe(dev, ret, "failed to initialize core\n");
1857 dwc3_check_params(dwc);
1858 dwc3_debugfs_init(dwc);
1860 ret = dwc3_core_init_mode(dwc);
1864 pm_runtime_put(dev);
1869 dwc3_debugfs_exit(dwc);
1870 dwc3_event_buffers_cleanup(dwc);
1872 usb_phy_set_suspend(dwc->usb2_phy, 1);
1873 usb_phy_set_suspend(dwc->usb3_phy, 1);
1874 phy_power_off(dwc->usb2_generic_phy);
1875 phy_power_off(dwc->usb3_generic_phy);
1877 usb_phy_shutdown(dwc->usb2_phy);
1878 usb_phy_shutdown(dwc->usb3_phy);
1879 phy_exit(dwc->usb2_generic_phy);
1880 phy_exit(dwc->usb3_generic_phy);
1882 dwc3_ulpi_exit(dwc);
1885 dwc3_free_scratch_buffers(dwc);
1888 dwc3_free_event_buffers(dwc);
1891 pm_runtime_allow(&pdev->dev);
1894 pm_runtime_put_sync(&pdev->dev);
1895 pm_runtime_disable(&pdev->dev);
1898 dwc3_clk_disable(dwc);
1900 reset_control_assert(dwc->reset);
1903 power_supply_put(dwc->usb_psy);
1908 static int dwc3_remove(struct platform_device *pdev)
1910 struct dwc3 *dwc = platform_get_drvdata(pdev);
1912 pm_runtime_get_sync(&pdev->dev);
1914 dwc3_core_exit_mode(dwc);
1915 dwc3_debugfs_exit(dwc);
1917 dwc3_core_exit(dwc);
1918 dwc3_ulpi_exit(dwc);
1920 pm_runtime_disable(&pdev->dev);
1921 pm_runtime_put_noidle(&pdev->dev);
1922 pm_runtime_set_suspended(&pdev->dev);
1924 dwc3_free_event_buffers(dwc);
1925 dwc3_free_scratch_buffers(dwc);
1928 power_supply_put(dwc->usb_psy);
1934 static int dwc3_core_init_for_resume(struct dwc3 *dwc)
1938 ret = reset_control_deassert(dwc->reset);
1942 ret = dwc3_clk_enable(dwc);
1946 ret = dwc3_core_init(dwc);
1953 dwc3_clk_disable(dwc);
1955 reset_control_assert(dwc->reset);
1960 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
1962 unsigned long flags;
1965 switch (dwc->current_dr_role) {
1966 case DWC3_GCTL_PRTCAP_DEVICE:
1967 if (pm_runtime_suspended(dwc->dev))
1969 dwc3_gadget_suspend(dwc);
1970 synchronize_irq(dwc->irq_gadget);
1971 dwc3_core_exit(dwc);
1973 case DWC3_GCTL_PRTCAP_HOST:
1974 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
1975 dwc3_core_exit(dwc);
1979 /* Let controller to suspend HSPHY before PHY driver suspends */
1980 if (dwc->dis_u2_susphy_quirk ||
1981 dwc->dis_enblslpm_quirk) {
1982 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1983 reg |= DWC3_GUSB2PHYCFG_ENBLSLPM |
1984 DWC3_GUSB2PHYCFG_SUSPHY;
1985 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1987 /* Give some time for USB2 PHY to suspend */
1988 usleep_range(5000, 6000);
1991 phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
1992 phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
1994 case DWC3_GCTL_PRTCAP_OTG:
1995 /* do nothing during runtime_suspend */
1996 if (PMSG_IS_AUTO(msg))
1999 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
2000 spin_lock_irqsave(&dwc->lock, flags);
2001 dwc3_gadget_suspend(dwc);
2002 spin_unlock_irqrestore(&dwc->lock, flags);
2003 synchronize_irq(dwc->irq_gadget);
2007 dwc3_core_exit(dwc);
2017 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
2019 unsigned long flags;
2023 switch (dwc->current_dr_role) {
2024 case DWC3_GCTL_PRTCAP_DEVICE:
2025 ret = dwc3_core_init_for_resume(dwc);
2029 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
2030 dwc3_gadget_resume(dwc);
2032 case DWC3_GCTL_PRTCAP_HOST:
2033 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
2034 ret = dwc3_core_init_for_resume(dwc);
2037 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
2040 /* Restore GUSB2PHYCFG bits that were modified in suspend */
2041 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
2042 if (dwc->dis_u2_susphy_quirk)
2043 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
2045 if (dwc->dis_enblslpm_quirk)
2046 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
2048 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
2050 phy_pm_runtime_get_sync(dwc->usb2_generic_phy);
2051 phy_pm_runtime_get_sync(dwc->usb3_generic_phy);
2053 case DWC3_GCTL_PRTCAP_OTG:
2054 /* nothing to do on runtime_resume */
2055 if (PMSG_IS_AUTO(msg))
2058 ret = dwc3_core_init_for_resume(dwc);
2062 dwc3_set_prtcap(dwc, dwc->current_dr_role);
2065 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
2066 dwc3_otg_host_init(dwc);
2067 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
2068 spin_lock_irqsave(&dwc->lock, flags);
2069 dwc3_gadget_resume(dwc);
2070 spin_unlock_irqrestore(&dwc->lock, flags);
2082 static int dwc3_runtime_checks(struct dwc3 *dwc)
2084 switch (dwc->current_dr_role) {
2085 case DWC3_GCTL_PRTCAP_DEVICE:
2089 case DWC3_GCTL_PRTCAP_HOST:
2098 static int dwc3_runtime_suspend(struct device *dev)
2100 struct dwc3 *dwc = dev_get_drvdata(dev);
2103 if (dwc3_runtime_checks(dwc))
2106 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND);
2113 static int dwc3_runtime_resume(struct device *dev)
2115 struct dwc3 *dwc = dev_get_drvdata(dev);
2118 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME);
2122 switch (dwc->current_dr_role) {
2123 case DWC3_GCTL_PRTCAP_DEVICE:
2124 dwc3_gadget_process_pending_events(dwc);
2126 case DWC3_GCTL_PRTCAP_HOST:
2132 pm_runtime_mark_last_busy(dev);
2137 static int dwc3_runtime_idle(struct device *dev)
2139 struct dwc3 *dwc = dev_get_drvdata(dev);
2141 switch (dwc->current_dr_role) {
2142 case DWC3_GCTL_PRTCAP_DEVICE:
2143 if (dwc3_runtime_checks(dwc))
2146 case DWC3_GCTL_PRTCAP_HOST:
2152 pm_runtime_mark_last_busy(dev);
2153 pm_runtime_autosuspend(dev);
2157 #endif /* CONFIG_PM */
2159 #ifdef CONFIG_PM_SLEEP
2160 static int dwc3_suspend(struct device *dev)
2162 struct dwc3 *dwc = dev_get_drvdata(dev);
2165 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
2169 pinctrl_pm_select_sleep_state(dev);
2174 static int dwc3_resume(struct device *dev)
2176 struct dwc3 *dwc = dev_get_drvdata(dev);
2179 pinctrl_pm_select_default_state(dev);
2181 ret = dwc3_resume_common(dwc, PMSG_RESUME);
2185 pm_runtime_disable(dev);
2186 pm_runtime_set_active(dev);
2187 pm_runtime_enable(dev);
2192 static void dwc3_complete(struct device *dev)
2194 struct dwc3 *dwc = dev_get_drvdata(dev);
2197 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
2198 dwc->dis_split_quirk) {
2199 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
2200 reg |= DWC3_GUCTL3_SPLITDISABLE;
2201 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
2205 #define dwc3_complete NULL
2206 #endif /* CONFIG_PM_SLEEP */
2208 static const struct dev_pm_ops dwc3_dev_pm_ops = {
2209 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
2210 .complete = dwc3_complete,
2211 SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,
2216 static const struct of_device_id of_dwc3_match[] = {
2218 .compatible = "snps,dwc3"
2221 .compatible = "synopsys,dwc3"
2225 MODULE_DEVICE_TABLE(of, of_dwc3_match);
2230 #define ACPI_ID_INTEL_BSW "808622B7"
2232 static const struct acpi_device_id dwc3_acpi_match[] = {
2233 { ACPI_ID_INTEL_BSW, 0 },
2236 MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
2239 static struct platform_driver dwc3_driver = {
2240 .probe = dwc3_probe,
2241 .remove = dwc3_remove,
2244 .of_match_table = of_match_ptr(of_dwc3_match),
2245 .acpi_match_table = ACPI_PTR(dwc3_acpi_match),
2246 .pm = &dwc3_dev_pm_ops,
2250 module_platform_driver(dwc3_driver);
2252 MODULE_ALIAS("platform:dwc3");
2254 MODULE_LICENSE("GPL v2");
2255 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");