Lines Matching +full:burst +full:- +full:length

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
24 #include <linux/dma-mapping.h>
46 * dwc3_get_dr_mode - Validates and sets dr_mode
52 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
55 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
56 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
58 mode = dwc->dr_mode; in dwc3_get_dr_mode()
59 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
66 return -EINVAL; in dwc3_get_dr_mode()
74 return -EINVAL; in dwc3_get_dr_mode()
89 if (mode == USB_DR_MODE_OTG && !dwc->edev && in dwc3_get_dr_mode()
91 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
96 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
101 dwc->dr_mode = mode; in dwc3_get_dr_mode()
111 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
114 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
116 dwc->current_dr_role = mode; in dwc3_set_prtcap()
127 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
128 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
129 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
130 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
132 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
134 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
140 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
143 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
146 switch (dwc->current_dr_role) { in __dwc3_set_mode()
156 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
157 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
158 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
169 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
172 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
174 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
184 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
186 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
189 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
193 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
199 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
201 if (dwc->usb2_phy) in __dwc3_set_mode()
202 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
203 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
204 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
205 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
206 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
208 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
217 if (dwc->usb2_phy) in __dwc3_set_mode()
218 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
219 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
220 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
224 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
235 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
236 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
237 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
244 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
247 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
248 dwc->desired_dr_role = mode; in dwc3_set_mode()
249 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
251 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
256 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space()
259 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
260 DWC3_GDBGFIFOSPACE_NUM(dep->number) | in dwc3_core_fifo_space()
263 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
269 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
280 * host-only mode, then we can return early. in dwc3_core_soft_reset()
282 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
285 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
300 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
308 } while (--retries); in dwc3_core_soft_reset()
310 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
311 return -ETIMEDOUT; in dwc3_core_soft_reset()
326 * dwc3_frame_length_adjustment - Adjusts frame length if required
337 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
340 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
342 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
344 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
345 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
350 * dwc3_ref_clk_period - Reference clock period configuration
365 if (dwc->ref_clk) { in dwc3_ref_clk_period()
366 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
370 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
371 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
377 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
380 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
388 * 125000 * (NSEC_PER_SEC / (rate * period) - 1) in dwc3_ref_clk_period()
390 * but rearranged for fixed-point arithmetic. The division must be in dwc3_ref_clk_period()
391 * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and in dwc3_ref_clk_period()
401 fladj -= 125000; in dwc3_ref_clk_period()
408 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
416 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
419 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
423 * dwc3_free_one_event_buffer - Frees one event buffer
430 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
434 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
436 * @length: size of the event buffer
442 unsigned int length) in dwc3_alloc_one_event_buffer() argument
446 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
448 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
450 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
451 evt->length = length; in dwc3_alloc_one_event_buffer()
452 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
453 if (!evt->cache) in dwc3_alloc_one_event_buffer()
454 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
456 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
457 &evt->dma, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
458 if (!evt->buf) in dwc3_alloc_one_event_buffer()
459 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
465 * dwc3_free_event_buffers - frees all allocated event buffers
472 evt = dwc->ev_buf; in dwc3_free_event_buffers()
478 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
480 * @length: size of event buffer
485 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
489 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
491 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
494 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
500 * dwc3_event_buffers_setup - setup our allocated event buffers
509 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
510 evt->lpos = 0; in dwc3_event_buffers_setup()
511 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
512 lower_32_bits(evt->dma)); in dwc3_event_buffers_setup()
513 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
514 upper_32_bits(evt->dma)); in dwc3_event_buffers_setup()
515 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
516 DWC3_GEVNTSIZ_SIZE(evt->length)); in dwc3_event_buffers_setup()
517 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
526 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
528 evt->lpos = 0; in dwc3_event_buffers_cleanup()
530 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
531 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
532 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
534 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
539 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
541 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
546 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
548 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
549 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
550 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
551 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
552 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
553 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
554 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
555 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
556 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
559 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
567 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
571 dwc->hsphy_interface && in dwc3_core_ulpi_init()
572 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
579 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
591 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
593 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
612 * power-on reset, and it can be set after core initialization, which is in dwc3_phy_setup()
613 * after device soft-reset during initialization. in dwc3_phy_setup()
618 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
621 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
624 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
627 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
630 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
633 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
636 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
639 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
640 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
642 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
645 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
648 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
650 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
653 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
655 if (dwc->hsphy_interface && in dwc3_phy_setup()
656 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
659 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
660 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
662 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
674 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
702 * power-on reset, and it can be set after core initialization, which is in dwc3_phy_setup()
703 * after device soft-reset during initialization. in dwc3_phy_setup()
708 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
711 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
716 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
726 if (dwc->ulpi_ext_vbus_drv) in dwc3_phy_setup()
729 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
738 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
739 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
741 ret = phy_init(dwc->usb2_generic_phy); in dwc3_phy_init()
745 ret = phy_init(dwc->usb3_generic_phy); in dwc3_phy_init()
752 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_init()
754 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
755 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
762 phy_exit(dwc->usb3_generic_phy); in dwc3_phy_exit()
763 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_exit()
765 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
766 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
773 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
774 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
776 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_phy_power_on()
780 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_phy_power_on()
787 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_on()
789 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
790 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
797 phy_power_off(dwc->usb3_generic_phy); in dwc3_phy_power_off()
798 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_off()
800 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
801 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
808 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
812 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
816 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
820 ret = clk_prepare_enable(dwc->utmi_clk); in dwc3_clk_enable()
824 ret = clk_prepare_enable(dwc->pipe_clk); in dwc3_clk_enable()
831 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_enable()
833 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_enable()
835 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
837 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
843 clk_disable_unprepare(dwc->pipe_clk); in dwc3_clk_disable()
844 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_disable()
845 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
846 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
847 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
856 reset_control_assert(dwc->reset); in dwc3_core_exit()
863 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
864 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
868 dwc->revision = reg; in dwc3_core_is_valid()
870 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
871 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
883 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
886 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
897 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based in dwc3_core_setup_global_control()
900 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
901 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
909 * REVISIT Enabling this bit so that host-mode hibernation in dwc3_core_setup_global_control()
910 * will work. Device-mode hibernation is not yet implemented. in dwc3_core_setup_global_control()
920 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
921 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
922 dwc->is_fpga = true; in dwc3_core_setup_global_control()
925 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
926 "disable_scramble cannot be used on non-FPGA builds\n"); in dwc3_core_setup_global_control()
928 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
933 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
939 * and falls back to high-speed mode which causes in dwc3_core_setup_global_control()
945 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
951 /* set global incr burst type configuration registers */
954 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
955 /* incrx_mode : for INCR burst type. */ in dwc3_set_incr_burst_type()
957 /* incrx_size : for size of INCRX burst. */ in dwc3_set_incr_burst_type()
965 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
968 * Handle property "snps,incr-burst-type-adjustment". in dwc3_set_incr_burst_type()
971 * result = 1, means INCRx burst mode supported. in dwc3_set_incr_burst_type()
972 * result > 1, means undefined length burst mode supported. in dwc3_set_incr_burst_type()
974 ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment"); in dwc3_set_incr_burst_type()
982 /* Get INCR burst type, and parse it */ in dwc3_set_incr_burst_type()
984 "snps,incr-burst-type-adjustment", vals, ntype); in dwc3_set_incr_burst_type()
994 /* INCRX (undefined length) burst mode */ in dwc3_set_incr_burst_type()
1001 /* INCRX burst mode */ in dwc3_set_incr_burst_type()
1007 /* Enable Undefined Length INCR Burst and Enable INCRx Burst */ in dwc3_set_incr_burst_type()
1040 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1048 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1064 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1065 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1070 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1083 * Must config both number of packets and max burst settings to enable in dwc3_config_threshold()
1086 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1087 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1088 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1089 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1090 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1093 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1102 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1106 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1115 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1119 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1120 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1121 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1122 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1126 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1135 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1139 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1148 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1152 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1161 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1165 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1174 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1180 * dwc3_core_init - Low-level initialization of DWC3 Core
1191 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1197 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1203 if (!dwc->ulpi_ready) { in dwc3_core_init()
1206 if (ret == -ETIMEDOUT) { in dwc3_core_init()
1208 ret = -EPROBE_DEFER; in dwc3_core_init()
1212 dwc->ulpi_ready = true; in dwc3_core_init()
1215 if (!dwc->phys_ready) { in dwc3_core_init()
1219 dwc->phys_ready = true; in dwc3_core_init()
1232 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
1233 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
1235 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
1238 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
1239 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
1241 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
1251 /* Adjust Frame Length */ in dwc3_core_init()
1265 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1275 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1277 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1284 * re-enumeration of usb device attached. All the termsel, xcvrsel, in dwc3_core_init()
1289 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1290 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1292 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1296 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1314 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1317 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1320 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1324 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1325 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1328 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1339 dwc->maximum_speed == USB_SPEED_SUPER) { in dwc3_core_init()
1340 reg = dwc3_readl(dwc->regs, DWC3_LLUCTL); in dwc3_core_init()
1342 dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); in dwc3_core_init()
1359 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1360 struct device_node *node = dev->of_node; in dwc3_core_get_phy()
1364 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1365 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1367 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1368 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1371 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1372 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1373 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1374 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1379 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1380 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1381 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1382 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1387 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1388 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1389 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1390 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1391 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1396 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1397 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1398 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1399 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1400 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1410 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1413 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1417 if (dwc->usb2_phy) in dwc3_core_init_mode()
1418 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1419 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1420 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1429 if (dwc->usb2_phy) in dwc3_core_init_mode()
1430 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1431 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1432 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1439 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1442 return dev_err_probe(dev, ret, "failed to initialize dual-role\n"); in dwc3_core_init_mode()
1445 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1446 return -EINVAL; in dwc3_core_init_mode()
1454 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1469 /* de-assert DRVVBUS for HOST and OTG mode */ in dwc3_core_exit_mode()
1475 struct device *dev = dwc->dev; in dwc3_get_properties()
1494 /* default to -3.5dB de-emphasis */ in dwc3_get_properties()
1510 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1511 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1512 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1513 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1515 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1517 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1518 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1520 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1522 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name); in dwc3_get_properties()
1524 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1525 if (!dwc->usb_psy) in dwc3_get_properties()
1529 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1530 "snps,has-lpm-erratum"); in dwc3_get_properties()
1531 device_property_read_u8(dev, "snps,lpm-nyet-threshold", in dwc3_get_properties()
1533 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1534 "snps,is-utmi-l1-suspend"); in dwc3_get_properties()
1535 device_property_read_u8(dev, "snps,hird-threshold", in dwc3_get_properties()
1537 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1538 "snps,dis-start-transfer-quirk"); in dwc3_get_properties()
1539 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1541 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1542 "snps,usb2-lpm-disable"); in dwc3_get_properties()
1543 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1544 "snps,usb2-gadget-lpm-disable"); in dwc3_get_properties()
1545 device_property_read_u8(dev, "snps,rx-thr-num-pkt", in dwc3_get_properties()
1547 device_property_read_u8(dev, "snps,rx-max-burst", in dwc3_get_properties()
1549 device_property_read_u8(dev, "snps,tx-thr-num-pkt", in dwc3_get_properties()
1551 device_property_read_u8(dev, "snps,tx-max-burst", in dwc3_get_properties()
1553 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd", in dwc3_get_properties()
1555 device_property_read_u8(dev, "snps,rx-max-burst-prd", in dwc3_get_properties()
1557 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd", in dwc3_get_properties()
1559 device_property_read_u8(dev, "snps,tx-max-burst-prd", in dwc3_get_properties()
1561 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1562 "tx-fifo-resize"); in dwc3_get_properties()
1563 if (dwc->do_fifo_resize) in dwc3_get_properties()
1564 device_property_read_u8(dev, "tx-fifo-max-num", in dwc3_get_properties()
1567 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1569 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1571 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1573 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1575 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1577 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1579 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1581 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1583 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1585 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1587 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1589 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1590 "snps,dis-u1-entry-quirk"); in dwc3_get_properties()
1591 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1592 "snps,dis-u2-entry-quirk"); in dwc3_get_properties()
1593 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1595 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1596 "snps,dis-u2-freeclk-exists-quirk"); in dwc3_get_properties()
1597 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1598 "snps,dis-del-phy-power-chg-quirk"); in dwc3_get_properties()
1599 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1600 "snps,dis-tx-ipgap-linecheck-quirk"); in dwc3_get_properties()
1601 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1602 "snps,resume-hs-terminations"); in dwc3_get_properties()
1603 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1604 "snps,ulpi-ext-vbus-drv"); in dwc3_get_properties()
1605 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1606 "snps,parkmode-disable-ss-quirk"); in dwc3_get_properties()
1607 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1608 "snps,parkmode-disable-hs-quirk"); in dwc3_get_properties()
1609 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1610 "snps,gfladj-refclk-lpm-sel-quirk"); in dwc3_get_properties()
1612 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1617 &dwc->hsphy_interface); in dwc3_get_properties()
1618 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", in dwc3_get_properties()
1619 &dwc->fladj); in dwc3_get_properties()
1620 device_property_read_u32(dev, "snps,ref-clock-period-ns", in dwc3_get_properties()
1621 &dwc->ref_clk_per); in dwc3_get_properties()
1623 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1626 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1627 "snps,dis-split-quirk"); in dwc3_get_properties()
1629 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1630 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1632 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1634 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1635 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1637 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1638 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1640 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1641 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1643 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1644 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1646 dwc->imod_interval = 0; in dwc3_get_properties()
1648 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1661 struct device *dev = dwc->dev; in dwc3_check_params()
1663 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1666 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1667 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1668 dwc->imod_interval = 0; in dwc3_check_params()
1678 if (!dwc->imod_interval && in dwc3_check_params()
1680 dwc->imod_interval = 1; in dwc3_check_params()
1683 switch (dwc->maximum_speed) { in dwc3_check_params()
1700 dwc->maximum_speed); in dwc3_check_params()
1705 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1709 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1711 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1714 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1717 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1727 * set the default to support dual-lane for DWC_usb32 and single-lane in dwc3_check_params()
1728 * for DWC_usb31 for super-speed-plus. in dwc3_check_params()
1730 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1731 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1746 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1748 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1752 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1762 struct device *dev = dwc->dev; in dwc3_get_extcon()
1776 if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) in dwc3_get_extcon()
1780 * Check explicitly if "usb-role-switch" is used since in dwc3_get_extcon()
1786 device_property_read_bool(dev, "usb-role-switch")) in dwc3_get_extcon()
1793 * device (and "port" node) may be missing in case of "usb-role-switch" in dwc3_get_extcon()
1796 np_phy = of_parse_phandle(dev->of_node, "phys", 0); in dwc3_get_extcon()
1800 np_conn = of_graph_get_remote_node(np_phy, -1, -1); in dwc3_get_extcon()
1812 struct device *dev = dwc->dev; in dwc3_get_clocks()
1814 if (!dev->of_node) in dwc3_get_clocks()
1819 * as required by the DT-binding. in dwc3_get_clocks()
1823 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
1824 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1825 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1829 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
1830 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
1831 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1832 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1837 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
1838 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1839 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1843 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
1844 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
1845 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1846 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1851 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
1852 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1853 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1857 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
1858 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
1859 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1860 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1866 dwc->utmi_clk = devm_clk_get_optional(dev, "utmi"); in dwc3_get_clocks()
1867 if (IS_ERR(dwc->utmi_clk)) { in dwc3_get_clocks()
1868 return dev_err_probe(dev, PTR_ERR(dwc->utmi_clk), in dwc3_get_clocks()
1873 dwc->pipe_clk = devm_clk_get_optional(dev, "pipe"); in dwc3_get_clocks()
1874 if (IS_ERR(dwc->pipe_clk)) { in dwc3_get_clocks()
1875 return dev_err_probe(dev, PTR_ERR(dwc->pipe_clk), in dwc3_get_clocks()
1884 struct device *dev = &pdev->dev; in dwc3_probe()
1892 return -ENOMEM; in dwc3_probe()
1894 dwc->dev = dev; in dwc3_probe()
1899 return -ENODEV; in dwc3_probe()
1902 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1903 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1905 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1906 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1910 * since it will be requested by the xhci-plat driver. in dwc3_probe()
1915 if (dev->of_node) { in dwc3_probe()
1916 struct device_node *parent = of_get_parent(dev->of_node); in dwc3_probe()
1918 if (of_device_is_compatible(parent, "realtek,rtd-dwc3")) { in dwc3_probe()
1919 dwc_res.start -= DWC3_GLOBALS_REGS_START; in dwc3_probe()
1930 dwc->regs = regs; in dwc3_probe()
1931 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1935 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1936 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1937 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1945 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1954 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1955 ret = -ENODEV; in dwc3_probe()
1962 if (!dwc->sysdev_is_parent && in dwc3_probe()
1963 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1964 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1969 spin_lock_init(&dwc->lock); in dwc3_probe()
1970 mutex_init(&dwc->mutex); in dwc3_probe()
1982 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1983 ret = -ENOMEM; in dwc3_probe()
1987 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
1988 if (IS_ERR(dwc->edev)) { in dwc3_probe()
1989 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
2033 reset_control_assert(dwc->reset); in dwc3_probe()
2035 if (dwc->usb_psy) in dwc3_probe()
2036 power_supply_put(dwc->usb_psy); in dwc3_probe()
2045 pm_runtime_get_sync(&pdev->dev); in dwc3_remove()
2053 pm_runtime_allow(&pdev->dev); in dwc3_remove()
2054 pm_runtime_disable(&pdev->dev); in dwc3_remove()
2055 pm_runtime_dont_use_autosuspend(&pdev->dev); in dwc3_remove()
2056 pm_runtime_put_noidle(&pdev->dev); in dwc3_remove()
2062 pm_runtime_set_suspended(&pdev->dev); in dwc3_remove()
2066 if (dwc->usb_psy) in dwc3_remove()
2067 power_supply_put(dwc->usb_psy); in dwc3_remove()
2075 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2092 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2102 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2104 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2107 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2111 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2117 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2118 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2119 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2122 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2128 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2129 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2136 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2137 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
2139 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
2140 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2160 switch (dwc->current_dr_role) { in dwc3_resume_common()
2170 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2178 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2179 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2182 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2185 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2187 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2188 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2199 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
2202 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2204 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2205 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
2207 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
2221 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2223 if (dwc->connected) in dwc3_runtime_checks()
2224 return -EBUSY; in dwc3_runtime_checks()
2241 return -EBUSY; in dwc3_runtime_suspend()
2259 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2278 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2281 return -EBUSY; in dwc3_runtime_idle()
2337 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2338 dwc->dis_split_quirk) { in dwc3_complete()
2339 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2341 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()