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");
1275 if (IS_ERR(dwc->usb3_phy)) {
1276 ret = PTR_ERR(dwc->usb3_phy);
1277 if (ret == -ENXIO || ret == -ENODEV)
1278 dwc->usb3_phy = NULL;
1280 return dev_err_probe(dev, ret, "no usb3 phy configured\n");
1283 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
1284 if (IS_ERR(dwc->usb2_generic_phy)) {
1285 ret = PTR_ERR(dwc->usb2_generic_phy);
1286 if (ret == -ENOSYS || ret == -ENODEV)
1287 dwc->usb2_generic_phy = NULL;
1289 return dev_err_probe(dev, ret, "no usb2 phy configured\n");
1292 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
1293 if (IS_ERR(dwc->usb3_generic_phy)) {
1294 ret = PTR_ERR(dwc->usb3_generic_phy);
1295 if (ret == -ENOSYS || ret == -ENODEV)
1296 dwc->usb3_generic_phy = NULL;
1298 return dev_err_probe(dev, ret, "no usb3 phy configured\n");
1304 static int dwc3_core_init_mode(struct dwc3 *dwc)
1306 struct device *dev = dwc->dev;
1309 switch (dwc->dr_mode) {
1310 case USB_DR_MODE_PERIPHERAL:
1311 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1314 otg_set_vbus(dwc->usb2_phy->otg, false);
1315 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
1316 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
1318 ret = dwc3_gadget_init(dwc);
1320 return dev_err_probe(dev, ret, "failed to initialize gadget\n");
1322 case USB_DR_MODE_HOST:
1323 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
1326 otg_set_vbus(dwc->usb2_phy->otg, true);
1327 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
1328 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
1330 ret = dwc3_host_init(dwc);
1332 return dev_err_probe(dev, ret, "failed to initialize host\n");
1334 case USB_DR_MODE_OTG:
1335 INIT_WORK(&dwc->drd_work, __dwc3_set_mode);
1336 ret = dwc3_drd_init(dwc);
1338 return dev_err_probe(dev, ret, "failed to initialize dual-role\n");
1341 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
1348 static void dwc3_core_exit_mode(struct dwc3 *dwc)
1350 switch (dwc->dr_mode) {
1351 case USB_DR_MODE_PERIPHERAL:
1352 dwc3_gadget_exit(dwc);
1354 case USB_DR_MODE_HOST:
1355 dwc3_host_exit(dwc);
1357 case USB_DR_MODE_OTG:
1365 /* de-assert DRVVBUS for HOST and OTG mode */
1366 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1369 static void dwc3_get_properties(struct dwc3 *dwc)
1371 struct device *dev = dwc->dev;
1372 u8 lpm_nyet_threshold;
1375 u8 rx_thr_num_pkt_prd = 0;
1376 u8 rx_max_burst_prd = 0;
1377 u8 tx_thr_num_pkt_prd = 0;
1378 u8 tx_max_burst_prd = 0;
1379 u8 tx_fifo_resize_max_num;
1380 const char *usb_psy_name;
1383 /* default to highest possible threshold */
1384 lpm_nyet_threshold = 0xf;
1386 /* default to -3.5dB de-emphasis */
1390 * default to assert utmi_sleep_n and use maximum allowed HIRD
1391 * threshold value of 0b1100
1393 hird_threshold = 12;
1396 * default to a TXFIFO size large enough to fit 6 max packets. This
1397 * allows for systems with larger bus latencies to have some headroom
1398 * for endpoints that have a large bMaxBurst value.
1400 tx_fifo_resize_max_num = 6;
1402 dwc->maximum_speed = usb_get_maximum_speed(dev);
1403 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev);
1404 dwc->dr_mode = usb_get_dr_mode(dev);
1405 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
1407 dwc->sysdev_is_parent = device_property_read_bool(dev,
1408 "linux,sysdev_is_parent");
1409 if (dwc->sysdev_is_parent)
1410 dwc->sysdev = dwc->dev->parent;
1412 dwc->sysdev = dwc->dev;
1414 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
1416 dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
1418 dev_err(dev, "couldn't get usb power supply\n");
1421 dwc->has_lpm_erratum = device_property_read_bool(dev,
1422 "snps,has-lpm-erratum");
1423 device_property_read_u8(dev, "snps,lpm-nyet-threshold",
1424 &lpm_nyet_threshold);
1425 dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
1426 "snps,is-utmi-l1-suspend");
1427 device_property_read_u8(dev, "snps,hird-threshold",
1429 dwc->dis_start_transfer_quirk = device_property_read_bool(dev,
1430 "snps,dis-start-transfer-quirk");
1431 dwc->usb3_lpm_capable = device_property_read_bool(dev,
1432 "snps,usb3_lpm_capable");
1433 dwc->usb2_lpm_disable = device_property_read_bool(dev,
1434 "snps,usb2-lpm-disable");
1435 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev,
1436 "snps,usb2-gadget-lpm-disable");
1437 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd",
1438 &rx_thr_num_pkt_prd);
1439 device_property_read_u8(dev, "snps,rx-max-burst-prd",
1441 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd",
1442 &tx_thr_num_pkt_prd);
1443 device_property_read_u8(dev, "snps,tx-max-burst-prd",
1445 dwc->do_fifo_resize = device_property_read_bool(dev,
1447 if (dwc->do_fifo_resize)
1448 device_property_read_u8(dev, "tx-fifo-max-num",
1449 &tx_fifo_resize_max_num);
1451 dwc->disable_scramble_quirk = device_property_read_bool(dev,
1452 "snps,disable_scramble_quirk");
1453 dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
1454 "snps,u2exit_lfps_quirk");
1455 dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
1456 "snps,u2ss_inp3_quirk");
1457 dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
1458 "snps,req_p1p2p3_quirk");
1459 dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
1460 "snps,del_p1p2p3_quirk");
1461 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
1462 "snps,del_phy_power_chg_quirk");
1463 dwc->lfps_filter_quirk = device_property_read_bool(dev,
1464 "snps,lfps_filter_quirk");
1465 dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
1466 "snps,rx_detect_poll_quirk");
1467 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
1468 "snps,dis_u3_susphy_quirk");
1469 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
1470 "snps,dis_u2_susphy_quirk");
1471 dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
1472 "snps,dis_enblslpm_quirk");
1473 dwc->dis_u1_entry_quirk = device_property_read_bool(dev,
1474 "snps,dis-u1-entry-quirk");
1475 dwc->dis_u2_entry_quirk = device_property_read_bool(dev,
1476 "snps,dis-u2-entry-quirk");
1477 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
1478 "snps,dis_rxdet_inp3_quirk");
1479 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
1480 "snps,dis-u2-freeclk-exists-quirk");
1481 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
1482 "snps,dis-del-phy-power-chg-quirk");
1483 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev,
1484 "snps,dis-tx-ipgap-linecheck-quirk");
1485 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev,
1486 "snps,parkmode-disable-ss-quirk");
1488 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
1489 "snps,tx_de_emphasis_quirk");
1490 device_property_read_u8(dev, "snps,tx_de_emphasis",
1492 device_property_read_string(dev, "snps,hsphy_interface",
1493 &dwc->hsphy_interface);
1494 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
1496 device_property_read_u32(dev, "snps,ref-clock-period-ns",
1499 dwc->dis_metastability_quirk = device_property_read_bool(dev,
1500 "snps,dis_metastability_quirk");
1502 dwc->dis_split_quirk = device_property_read_bool(dev,
1503 "snps,dis-split-quirk");
1505 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
1506 dwc->tx_de_emphasis = tx_de_emphasis;
1508 dwc->hird_threshold = hird_threshold;
1510 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd;
1511 dwc->rx_max_burst_prd = rx_max_burst_prd;
1513 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd;
1514 dwc->tx_max_burst_prd = tx_max_burst_prd;
1516 dwc->imod_interval = 0;
1518 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
1521 /* check whether the core supports IMOD */
1522 bool dwc3_has_imod(struct dwc3 *dwc)
1524 return DWC3_VER_IS_WITHIN(DWC3, 300A, ANY) ||
1525 DWC3_VER_IS_WITHIN(DWC31, 120A, ANY) ||
1529 static void dwc3_check_params(struct dwc3 *dwc)
1531 struct device *dev = dwc->dev;
1532 unsigned int hwparam_gen =
1533 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3);
1535 /* Check for proper value of imod_interval */
1536 if (dwc->imod_interval && !dwc3_has_imod(dwc)) {
1537 dev_warn(dwc->dev, "Interrupt moderation not supported\n");
1538 dwc->imod_interval = 0;
1542 * Workaround for STAR 9000961433 which affects only version
1543 * 3.00a of the DWC_usb3 core. This prevents the controller
1544 * interrupt from being masked while handling events. IMOD
1545 * allows us to work around this issue. Enable it for the
1548 if (!dwc->imod_interval &&
1549 DWC3_VER_IS(DWC3, 300A))
1550 dwc->imod_interval = 1;
1552 /* Check the maximum_speed parameter */
1553 switch (dwc->maximum_speed) {
1554 case USB_SPEED_FULL:
1555 case USB_SPEED_HIGH:
1557 case USB_SPEED_SUPER:
1558 if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS)
1559 dev_warn(dev, "UDC doesn't support Gen 1\n");
1561 case USB_SPEED_SUPER_PLUS:
1562 if ((DWC3_IP_IS(DWC32) &&
1563 hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS) ||
1564 (!DWC3_IP_IS(DWC32) &&
1565 hwparam_gen != DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
1566 dev_warn(dev, "UDC doesn't support SSP\n");
1569 dev_err(dev, "invalid maximum_speed parameter %d\n",
1570 dwc->maximum_speed);
1572 case USB_SPEED_UNKNOWN:
1573 switch (hwparam_gen) {
1574 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1575 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1577 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1578 if (DWC3_IP_IS(DWC32))
1579 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1581 dwc->maximum_speed = USB_SPEED_SUPER;
1583 case DWC3_GHWPARAMS3_SSPHY_IFC_DIS:
1584 dwc->maximum_speed = USB_SPEED_HIGH;
1587 dwc->maximum_speed = USB_SPEED_SUPER;
1594 * Currently the controller does not have visibility into the HW
1595 * parameter to determine the maximum number of lanes the HW supports.
1596 * If the number of lanes is not specified in the device property, then
1597 * set the default to support dual-lane for DWC_usb32 and single-lane
1598 * for DWC_usb31 for super-speed-plus.
1600 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) {
1601 switch (dwc->max_ssp_rate) {
1602 case USB_SSP_GEN_2x1:
1603 if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_GEN1)
1604 dev_warn(dev, "UDC only supports Gen 1\n");
1606 case USB_SSP_GEN_1x2:
1607 case USB_SSP_GEN_2x2:
1608 if (DWC3_IP_IS(DWC31))
1609 dev_warn(dev, "UDC only supports single lane\n");
1611 case USB_SSP_GEN_UNKNOWN:
1613 switch (hwparam_gen) {
1614 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1615 if (DWC3_IP_IS(DWC32))
1616 dwc->max_ssp_rate = USB_SSP_GEN_2x2;
1618 dwc->max_ssp_rate = USB_SSP_GEN_2x1;
1620 case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1621 if (DWC3_IP_IS(DWC32))
1622 dwc->max_ssp_rate = USB_SSP_GEN_1x2;
1630 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
1632 struct device *dev = dwc->dev;
1633 struct device_node *np_phy;
1634 struct extcon_dev *edev = NULL;
1637 if (device_property_read_bool(dev, "extcon"))
1638 return extcon_get_edev_by_phandle(dev, 0);
1641 * Device tree platforms should get extcon via phandle.
1642 * On ACPI platforms, we get the name from a device property.
1643 * This device property is for kernel internal use only and
1644 * is expected to be set by the glue code.
1646 if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
1647 edev = extcon_get_extcon_dev(name);
1649 return ERR_PTR(-EPROBE_DEFER);
1655 * Try to get an extcon device from the USB PHY controller's "port"
1656 * node. Check if it has the "port" node first, to avoid printing the
1657 * error message from underlying code, as it's a valid case: extcon
1658 * device (and "port" node) may be missing in case of "usb-role-switch"
1661 np_phy = of_parse_phandle(dev->of_node, "phys", 0);
1662 if (of_graph_is_present(np_phy)) {
1663 struct device_node *np_conn;
1665 np_conn = of_graph_get_remote_node(np_phy, -1, -1);
1667 edev = extcon_find_edev_by_node(np_conn);
1668 of_node_put(np_conn);
1670 of_node_put(np_phy);
1675 static int dwc3_probe(struct platform_device *pdev)
1677 struct device *dev = &pdev->dev;
1678 struct resource *res, dwc_res;
1685 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
1691 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1693 dev_err(dev, "missing memory resource\n");
1697 dwc->xhci_resources[0].start = res->start;
1698 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
1700 dwc->xhci_resources[0].flags = res->flags;
1701 dwc->xhci_resources[0].name = res->name;
1704 * Request memory region but exclude xHCI regs,
1705 * since it will be requested by the xhci-plat driver.
1708 dwc_res.start += DWC3_GLOBALS_REGS_START;
1710 regs = devm_ioremap_resource(dev, &dwc_res);
1712 return PTR_ERR(regs);
1715 dwc->regs_size = resource_size(&dwc_res);
1717 dwc3_get_properties(dwc);
1719 if (!dwc->sysdev_is_parent) {
1720 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
1725 dwc->reset = devm_reset_control_array_get_optional_shared(dev);
1726 if (IS_ERR(dwc->reset))
1727 return PTR_ERR(dwc->reset);
1731 * Clocks are optional, but new DT platforms should support all
1732 * clocks as required by the DT-binding.
1733 * Some devices have different clock names in legacy device trees,
1734 * check for them to retain backwards compatibility.
1736 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early");
1737 if (IS_ERR(dwc->bus_clk))
1738 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
1739 "could not get bus clock\n");
1741 if (dwc->bus_clk == NULL) {
1742 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk");
1743 if (IS_ERR(dwc->bus_clk))
1744 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
1745 "could not get bus clock\n");
1748 dwc->ref_clk = devm_clk_get_optional(dev, "ref");
1749 if (IS_ERR(dwc->ref_clk))
1750 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
1751 "could not get ref clock\n");
1753 if (dwc->ref_clk == NULL) {
1754 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk");
1755 if (IS_ERR(dwc->ref_clk))
1756 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
1757 "could not get ref clock\n");
1760 dwc->susp_clk = devm_clk_get_optional(dev, "suspend");
1761 if (IS_ERR(dwc->susp_clk))
1762 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
1763 "could not get suspend clock\n");
1765 if (dwc->susp_clk == NULL) {
1766 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk");
1767 if (IS_ERR(dwc->susp_clk))
1768 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
1769 "could not get suspend clock\n");
1773 ret = reset_control_deassert(dwc->reset);
1777 ret = dwc3_clk_enable(dwc);
1781 if (!dwc3_core_is_valid(dwc)) {
1782 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
1787 platform_set_drvdata(pdev, dwc);
1788 dwc3_cache_hwparams(dwc);
1790 spin_lock_init(&dwc->lock);
1791 mutex_init(&dwc->mutex);
1793 pm_runtime_set_active(dev);
1794 pm_runtime_use_autosuspend(dev);
1795 pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
1796 pm_runtime_enable(dev);
1797 ret = pm_runtime_get_sync(dev);
1801 pm_runtime_forbid(dev);
1803 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
1805 dev_err(dwc->dev, "failed to allocate event buffers\n");
1810 dwc->edev = dwc3_get_extcon(dwc);
1811 if (IS_ERR(dwc->edev)) {
1812 ret = PTR_ERR(dwc->edev);
1813 dev_err_probe(dwc->dev, ret, "failed to get extcon\n");
1817 ret = dwc3_get_dr_mode(dwc);
1821 ret = dwc3_alloc_scratch_buffers(dwc);
1825 ret = dwc3_core_init(dwc);
1827 dev_err_probe(dev, ret, "failed to initialize core\n");
1831 dwc3_check_params(dwc);
1832 dwc3_debugfs_init(dwc);
1834 ret = dwc3_core_init_mode(dwc);
1838 pm_runtime_put(dev);
1843 dwc3_debugfs_exit(dwc);
1844 dwc3_event_buffers_cleanup(dwc);
1846 usb_phy_shutdown(dwc->usb2_phy);
1847 usb_phy_shutdown(dwc->usb3_phy);
1848 phy_exit(dwc->usb2_generic_phy);
1849 phy_exit(dwc->usb3_generic_phy);
1851 usb_phy_set_suspend(dwc->usb2_phy, 1);
1852 usb_phy_set_suspend(dwc->usb3_phy, 1);
1853 phy_power_off(dwc->usb2_generic_phy);
1854 phy_power_off(dwc->usb3_generic_phy);
1856 dwc3_ulpi_exit(dwc);
1859 dwc3_free_scratch_buffers(dwc);
1862 dwc3_free_event_buffers(dwc);
1865 pm_runtime_allow(&pdev->dev);
1868 pm_runtime_put_sync(&pdev->dev);
1869 pm_runtime_disable(&pdev->dev);
1872 dwc3_clk_disable(dwc);
1874 reset_control_assert(dwc->reset);
1877 power_supply_put(dwc->usb_psy);
1882 static int dwc3_remove(struct platform_device *pdev)
1884 struct dwc3 *dwc = platform_get_drvdata(pdev);
1886 pm_runtime_get_sync(&pdev->dev);
1888 dwc3_core_exit_mode(dwc);
1889 dwc3_debugfs_exit(dwc);
1891 dwc3_core_exit(dwc);
1892 dwc3_ulpi_exit(dwc);
1894 pm_runtime_disable(&pdev->dev);
1895 pm_runtime_put_noidle(&pdev->dev);
1896 pm_runtime_set_suspended(&pdev->dev);
1898 dwc3_free_event_buffers(dwc);
1899 dwc3_free_scratch_buffers(dwc);
1902 power_supply_put(dwc->usb_psy);
1908 static int dwc3_core_init_for_resume(struct dwc3 *dwc)
1912 ret = reset_control_deassert(dwc->reset);
1916 ret = dwc3_clk_enable(dwc);
1920 ret = dwc3_core_init(dwc);
1927 dwc3_clk_disable(dwc);
1929 reset_control_assert(dwc->reset);
1934 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
1936 unsigned long flags;
1939 switch (dwc->current_dr_role) {
1940 case DWC3_GCTL_PRTCAP_DEVICE:
1941 if (pm_runtime_suspended(dwc->dev))
1943 spin_lock_irqsave(&dwc->lock, flags);
1944 dwc3_gadget_suspend(dwc);
1945 spin_unlock_irqrestore(&dwc->lock, flags);
1946 synchronize_irq(dwc->irq_gadget);
1947 dwc3_core_exit(dwc);
1949 case DWC3_GCTL_PRTCAP_HOST:
1950 if (!PMSG_IS_AUTO(msg)) {
1951 dwc3_core_exit(dwc);
1955 /* Let controller to suspend HSPHY before PHY driver suspends */
1956 if (dwc->dis_u2_susphy_quirk ||
1957 dwc->dis_enblslpm_quirk) {
1958 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1959 reg |= DWC3_GUSB2PHYCFG_ENBLSLPM |
1960 DWC3_GUSB2PHYCFG_SUSPHY;
1961 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1963 /* Give some time for USB2 PHY to suspend */
1964 usleep_range(5000, 6000);
1967 phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
1968 phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
1970 case DWC3_GCTL_PRTCAP_OTG:
1971 /* do nothing during runtime_suspend */
1972 if (PMSG_IS_AUTO(msg))
1975 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
1976 spin_lock_irqsave(&dwc->lock, flags);
1977 dwc3_gadget_suspend(dwc);
1978 spin_unlock_irqrestore(&dwc->lock, flags);
1979 synchronize_irq(dwc->irq_gadget);
1983 dwc3_core_exit(dwc);
1993 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
1995 unsigned long flags;
1999 switch (dwc->current_dr_role) {
2000 case DWC3_GCTL_PRTCAP_DEVICE:
2001 ret = dwc3_core_init_for_resume(dwc);
2005 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
2006 spin_lock_irqsave(&dwc->lock, flags);
2007 dwc3_gadget_resume(dwc);
2008 spin_unlock_irqrestore(&dwc->lock, flags);
2010 case DWC3_GCTL_PRTCAP_HOST:
2011 if (!PMSG_IS_AUTO(msg)) {
2012 ret = dwc3_core_init_for_resume(dwc);
2015 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
2018 /* Restore GUSB2PHYCFG bits that were modified in suspend */
2019 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
2020 if (dwc->dis_u2_susphy_quirk)
2021 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
2023 if (dwc->dis_enblslpm_quirk)
2024 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
2026 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
2028 phy_pm_runtime_get_sync(dwc->usb2_generic_phy);
2029 phy_pm_runtime_get_sync(dwc->usb3_generic_phy);
2031 case DWC3_GCTL_PRTCAP_OTG:
2032 /* nothing to do on runtime_resume */
2033 if (PMSG_IS_AUTO(msg))
2036 ret = dwc3_core_init_for_resume(dwc);
2040 dwc3_set_prtcap(dwc, dwc->current_dr_role);
2043 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
2044 dwc3_otg_host_init(dwc);
2045 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
2046 spin_lock_irqsave(&dwc->lock, flags);
2047 dwc3_gadget_resume(dwc);
2048 spin_unlock_irqrestore(&dwc->lock, flags);
2060 static int dwc3_runtime_checks(struct dwc3 *dwc)
2062 switch (dwc->current_dr_role) {
2063 case DWC3_GCTL_PRTCAP_DEVICE:
2067 case DWC3_GCTL_PRTCAP_HOST:
2076 static int dwc3_runtime_suspend(struct device *dev)
2078 struct dwc3 *dwc = dev_get_drvdata(dev);
2081 if (dwc3_runtime_checks(dwc))
2084 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND);
2088 device_init_wakeup(dev, true);
2093 static int dwc3_runtime_resume(struct device *dev)
2095 struct dwc3 *dwc = dev_get_drvdata(dev);
2098 device_init_wakeup(dev, false);
2100 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME);
2104 switch (dwc->current_dr_role) {
2105 case DWC3_GCTL_PRTCAP_DEVICE:
2106 dwc3_gadget_process_pending_events(dwc);
2108 case DWC3_GCTL_PRTCAP_HOST:
2114 pm_runtime_mark_last_busy(dev);
2119 static int dwc3_runtime_idle(struct device *dev)
2121 struct dwc3 *dwc = dev_get_drvdata(dev);
2123 switch (dwc->current_dr_role) {
2124 case DWC3_GCTL_PRTCAP_DEVICE:
2125 if (dwc3_runtime_checks(dwc))
2128 case DWC3_GCTL_PRTCAP_HOST:
2134 pm_runtime_mark_last_busy(dev);
2135 pm_runtime_autosuspend(dev);
2139 #endif /* CONFIG_PM */
2141 #ifdef CONFIG_PM_SLEEP
2142 static int dwc3_suspend(struct device *dev)
2144 struct dwc3 *dwc = dev_get_drvdata(dev);
2147 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
2151 pinctrl_pm_select_sleep_state(dev);
2156 static int dwc3_resume(struct device *dev)
2158 struct dwc3 *dwc = dev_get_drvdata(dev);
2161 pinctrl_pm_select_default_state(dev);
2163 ret = dwc3_resume_common(dwc, PMSG_RESUME);
2167 pm_runtime_disable(dev);
2168 pm_runtime_set_active(dev);
2169 pm_runtime_enable(dev);
2174 static void dwc3_complete(struct device *dev)
2176 struct dwc3 *dwc = dev_get_drvdata(dev);
2179 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
2180 dwc->dis_split_quirk) {
2181 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
2182 reg |= DWC3_GUCTL3_SPLITDISABLE;
2183 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
2187 #define dwc3_complete NULL
2188 #endif /* CONFIG_PM_SLEEP */
2190 static const struct dev_pm_ops dwc3_dev_pm_ops = {
2191 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
2192 .complete = dwc3_complete,
2193 SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,
2198 static const struct of_device_id of_dwc3_match[] = {
2200 .compatible = "snps,dwc3"
2203 .compatible = "synopsys,dwc3"
2207 MODULE_DEVICE_TABLE(of, of_dwc3_match);
2212 #define ACPI_ID_INTEL_BSW "808622B7"
2214 static const struct acpi_device_id dwc3_acpi_match[] = {
2215 { ACPI_ID_INTEL_BSW, 0 },
2218 MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
2221 static struct platform_driver dwc3_driver = {
2222 .probe = dwc3_probe,
2223 .remove = dwc3_remove,
2226 .of_match_table = of_match_ptr(of_dwc3_match),
2227 .acpi_match_table = ACPI_PTR(dwc3_acpi_match),
2228 .pm = &dwc3_dev_pm_ops,
2232 module_platform_driver(dwc3_driver);
2234 MODULE_ALIAS("platform:dwc3");
2235 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
2236 MODULE_LICENSE("GPL v2");
2237 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");