Lines Matching +full:hird +full:- +full:threshold
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_GUSB3PIPECTL(0)); in dwc3_enable_susphy()
112 if (enable && !dwc->dis_u3_susphy_quirk) in dwc3_enable_susphy()
117 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_enable_susphy()
119 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_enable_susphy()
120 if (enable && !dwc->dis_u2_susphy_quirk) in dwc3_enable_susphy()
125 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_enable_susphy()
132 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
135 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
137 dwc->current_dr_role = mode; in dwc3_set_prtcap()
148 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
149 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
150 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
151 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
153 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
155 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
161 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
164 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
167 switch (dwc->current_dr_role) { in __dwc3_set_mode()
177 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
178 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
179 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
190 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
193 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
195 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
205 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
207 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
210 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
214 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
220 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
222 if (dwc->usb2_phy) in __dwc3_set_mode()
223 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
224 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
225 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
226 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
227 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
229 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
238 if (dwc->usb2_phy) in __dwc3_set_mode()
239 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
240 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
241 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
245 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
256 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
257 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
258 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
265 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
268 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
269 dwc->desired_dr_role = mode; in dwc3_set_mode()
270 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
272 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
277 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space()
280 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
281 DWC3_GDBGFIFOSPACE_NUM(dep->number) | in dwc3_core_fifo_space()
284 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
290 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
301 * host-only mode, then we can return early. in dwc3_core_soft_reset()
303 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
306 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
321 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
329 } while (--retries); in dwc3_core_soft_reset()
331 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
332 return -ETIMEDOUT; in dwc3_core_soft_reset()
347 * dwc3_frame_length_adjustment - Adjusts frame length if required
358 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
361 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
363 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
365 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
366 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
371 * dwc3_ref_clk_period - Reference clock period configuration
386 if (dwc->ref_clk) { in dwc3_ref_clk_period()
387 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
391 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
392 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
398 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
401 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
409 * 125000 * (NSEC_PER_SEC / (rate * period) - 1) in dwc3_ref_clk_period()
411 * but rearranged for fixed-point arithmetic. The division must be in dwc3_ref_clk_period()
412 * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and in dwc3_ref_clk_period()
422 fladj -= 125000; in dwc3_ref_clk_period()
429 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
437 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
440 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
444 * dwc3_free_one_event_buffer - Frees one event buffer
451 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
455 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
467 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
469 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
471 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
472 evt->length = length; in dwc3_alloc_one_event_buffer()
473 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
474 if (!evt->cache) in dwc3_alloc_one_event_buffer()
475 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
477 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
478 &evt->dma, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
479 if (!evt->buf) in dwc3_alloc_one_event_buffer()
480 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
486 * dwc3_free_event_buffers - frees all allocated event buffers
493 evt = dwc->ev_buf; in dwc3_free_event_buffers()
499 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
511 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_alloc_event_buffers()
513 dwc->ev_buf = NULL; in dwc3_alloc_event_buffers()
519 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
522 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
528 * dwc3_event_buffers_setup - setup our allocated event buffers
538 if (!dwc->ev_buf) in dwc3_event_buffers_setup()
541 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
542 evt->lpos = 0; in dwc3_event_buffers_setup()
543 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
544 lower_32_bits(evt->dma)); in dwc3_event_buffers_setup()
545 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
546 upper_32_bits(evt->dma)); in dwc3_event_buffers_setup()
547 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
548 DWC3_GEVNTSIZ_SIZE(evt->length)); in dwc3_event_buffers_setup()
551 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_setup()
552 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_setup()
561 if (!dwc->ev_buf) in dwc3_event_buffers_cleanup()
567 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_event_buffers_cleanup()
571 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
573 evt->lpos = 0; in dwc3_event_buffers_cleanup()
575 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
576 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
577 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
581 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_cleanup()
582 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_cleanup()
587 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
589 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
594 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
596 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
597 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
598 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
599 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
600 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
601 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
602 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
603 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
604 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
607 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
615 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
619 dwc->hsphy_interface && in dwc3_core_ulpi_init()
620 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
627 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
638 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
653 * cleared after power-on reset, and it can be set after core in dwc3_phy_setup()
658 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
661 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
664 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
667 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
670 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
673 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
676 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
679 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
680 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
682 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
685 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
687 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
690 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
692 if (dwc->hsphy_interface && in dwc3_phy_setup()
693 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
696 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
697 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
699 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
711 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
735 * after power-on reset, and it can be set after core initialization. in dwc3_phy_setup()
739 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
744 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
754 if (dwc->ulpi_ext_vbus_drv) in dwc3_phy_setup()
757 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
766 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
767 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
769 ret = phy_init(dwc->usb2_generic_phy); in dwc3_phy_init()
773 ret = phy_init(dwc->usb3_generic_phy); in dwc3_phy_init()
780 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_init()
782 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
783 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
790 phy_exit(dwc->usb3_generic_phy); in dwc3_phy_exit()
791 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_exit()
793 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
794 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
801 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
802 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
804 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_phy_power_on()
808 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_phy_power_on()
815 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_on()
817 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
818 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
825 phy_power_off(dwc->usb3_generic_phy); in dwc3_phy_power_off()
826 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_off()
828 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
829 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
836 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
840 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
844 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
851 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
853 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
859 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
860 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
861 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
870 reset_control_assert(dwc->reset); in dwc3_core_exit()
877 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
878 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
882 dwc->revision = reg; in dwc3_core_is_valid()
884 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
885 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
899 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
901 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_setup_global_control()
902 power_opt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_core_setup_global_control()
915 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based in dwc3_core_setup_global_control()
918 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
919 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
927 * REVISIT Enabling this bit so that host-mode hibernation in dwc3_core_setup_global_control()
928 * will work. Device-mode hibernation is not yet implemented. in dwc3_core_setup_global_control()
952 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
953 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
954 dwc->is_fpga = true; in dwc3_core_setup_global_control()
957 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
958 "disable_scramble cannot be used on non-FPGA builds\n"); in dwc3_core_setup_global_control()
960 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
965 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
971 * and falls back to high-speed mode which causes in dwc3_core_setup_global_control()
977 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
986 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
997 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1000 * Handle property "snps,incr-burst-type-adjustment". in dwc3_set_incr_burst_type()
1006 ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment"); in dwc3_set_incr_burst_type()
1016 "snps,incr-burst-type-adjustment", vals, ntype); in dwc3_set_incr_burst_type()
1072 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1080 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1096 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1097 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1102 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1116 * RX and/or TX threshold. in dwc3_config_threshold()
1118 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1119 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1120 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1121 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1122 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1125 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1134 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1138 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1147 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1151 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1152 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1153 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1154 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1158 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1167 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1171 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1180 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1184 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1193 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1197 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1206 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1212 * dwc3_core_init - Low-level initialization of DWC3 Core
1223 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1229 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1235 if (!dwc->ulpi_ready) { in dwc3_core_init()
1238 if (ret == -ETIMEDOUT) { in dwc3_core_init()
1240 ret = -EPROBE_DEFER; in dwc3_core_init()
1244 dwc->ulpi_ready = true; in dwc3_core_init()
1247 if (!dwc->phys_ready) { in dwc3_core_init()
1251 dwc->phys_ready = true; in dwc3_core_init()
1282 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1292 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1294 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1307 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1309 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1316 * re-enumeration of usb device attached. All the termsel, xcvrsel, in dwc3_core_init()
1321 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1322 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1324 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1328 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1346 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1349 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1352 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1356 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1357 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1360 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1379 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1380 struct device_node *node = dev->of_node; in dwc3_core_get_phy()
1384 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1385 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1387 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1388 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1391 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1392 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1393 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1394 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1399 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1400 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1401 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1402 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1407 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1408 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1409 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1410 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1411 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1416 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1417 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1418 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1419 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1420 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1430 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1433 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1437 if (dwc->usb2_phy) in dwc3_core_init_mode()
1438 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1439 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1440 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1449 if (dwc->usb2_phy) in dwc3_core_init_mode()
1450 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1451 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1452 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1459 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1462 return dev_err_probe(dev, ret, "failed to initialize dual-role\n"); in dwc3_core_init_mode()
1465 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1466 return -EINVAL; in dwc3_core_init_mode()
1474 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1489 /* de-assert DRVVBUS for HOST and OTG mode */ in dwc3_core_exit_mode()
1495 struct device *dev = dwc->dev; in dwc3_get_properties()
1511 /* default to highest possible threshold */ in dwc3_get_properties()
1514 /* default to -3.5dB de-emphasis */ in dwc3_get_properties()
1518 * default to assert utmi_sleep_n and use maximum allowed HIRD in dwc3_get_properties()
1519 * threshold value of 0b1100 in dwc3_get_properties()
1530 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1531 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1532 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1533 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1535 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1537 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1538 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1540 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1542 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); in dwc3_get_properties()
1544 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name); in dwc3_get_properties()
1546 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1547 if (!dwc->usb_psy) in dwc3_get_properties()
1551 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1552 "snps,has-lpm-erratum"); in dwc3_get_properties()
1553 device_property_read_u8(dev, "snps,lpm-nyet-threshold", in dwc3_get_properties()
1555 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1556 "snps,is-utmi-l1-suspend"); in dwc3_get_properties()
1557 device_property_read_u8(dev, "snps,hird-threshold", in dwc3_get_properties()
1559 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1560 "snps,dis-start-transfer-quirk"); in dwc3_get_properties()
1561 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1563 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1564 "snps,usb2-lpm-disable"); in dwc3_get_properties()
1565 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1566 "snps,usb2-gadget-lpm-disable"); in dwc3_get_properties()
1567 device_property_read_u8(dev, "snps,rx-thr-num-pkt", in dwc3_get_properties()
1569 device_property_read_u8(dev, "snps,rx-max-burst", in dwc3_get_properties()
1571 device_property_read_u8(dev, "snps,tx-thr-num-pkt", in dwc3_get_properties()
1573 device_property_read_u8(dev, "snps,tx-max-burst", in dwc3_get_properties()
1575 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd", in dwc3_get_properties()
1577 device_property_read_u8(dev, "snps,rx-max-burst-prd", in dwc3_get_properties()
1579 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd", in dwc3_get_properties()
1581 device_property_read_u8(dev, "snps,tx-max-burst-prd", in dwc3_get_properties()
1583 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1584 "tx-fifo-resize"); in dwc3_get_properties()
1585 if (dwc->do_fifo_resize) in dwc3_get_properties()
1586 device_property_read_u8(dev, "tx-fifo-max-num", in dwc3_get_properties()
1589 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1591 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1593 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1595 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1597 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1599 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1601 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1603 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1605 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1607 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1609 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1611 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1612 "snps,dis-u1-entry-quirk"); in dwc3_get_properties()
1613 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1614 "snps,dis-u2-entry-quirk"); in dwc3_get_properties()
1615 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1617 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1618 "snps,dis-u2-freeclk-exists-quirk"); in dwc3_get_properties()
1619 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1620 "snps,dis-del-phy-power-chg-quirk"); in dwc3_get_properties()
1621 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1622 "snps,dis-tx-ipgap-linecheck-quirk"); in dwc3_get_properties()
1623 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1624 "snps,resume-hs-terminations"); in dwc3_get_properties()
1625 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1626 "snps,ulpi-ext-vbus-drv"); in dwc3_get_properties()
1627 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1628 "snps,parkmode-disable-ss-quirk"); in dwc3_get_properties()
1629 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1630 "snps,parkmode-disable-hs-quirk"); in dwc3_get_properties()
1631 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1632 "snps,gfladj-refclk-lpm-sel-quirk"); in dwc3_get_properties()
1634 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1639 &dwc->hsphy_interface); in dwc3_get_properties()
1640 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", in dwc3_get_properties()
1641 &dwc->fladj); in dwc3_get_properties()
1642 device_property_read_u32(dev, "snps,ref-clock-period-ns", in dwc3_get_properties()
1643 &dwc->ref_clk_per); in dwc3_get_properties()
1645 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1648 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1649 "snps,dis-split-quirk"); in dwc3_get_properties()
1651 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1652 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1654 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1656 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1657 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1659 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1660 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1662 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1663 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1665 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1666 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1668 dwc->imod_interval = 0; in dwc3_get_properties()
1670 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1683 struct device *dev = dwc->dev; in dwc3_check_params()
1685 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1688 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1689 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1690 dwc->imod_interval = 0; in dwc3_check_params()
1700 if (!dwc->imod_interval && in dwc3_check_params()
1702 dwc->imod_interval = 1; in dwc3_check_params()
1705 switch (dwc->maximum_speed) { in dwc3_check_params()
1722 dwc->maximum_speed); in dwc3_check_params()
1727 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1731 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1733 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1736 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1739 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1749 * set the default to support dual-lane for DWC_usb32 and single-lane in dwc3_check_params()
1750 * for DWC_usb31 for super-speed-plus. in dwc3_check_params()
1752 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1753 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1768 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1770 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1774 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1784 struct device *dev = dwc->dev; in dwc3_get_extcon()
1798 if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) in dwc3_get_extcon()
1802 * Check explicitly if "usb-role-switch" is used since in dwc3_get_extcon()
1808 device_property_read_bool(dev, "usb-role-switch")) in dwc3_get_extcon()
1815 * device (and "port" node) may be missing in case of "usb-role-switch" in dwc3_get_extcon()
1818 np_phy = of_parse_phandle(dev->of_node, "phys", 0); in dwc3_get_extcon()
1822 np_conn = of_graph_get_remote_node(np_phy, -1, -1); in dwc3_get_extcon()
1834 struct device *dev = dwc->dev; in dwc3_get_clocks()
1836 if (!dev->of_node) in dwc3_get_clocks()
1841 * as required by the DT-binding. in dwc3_get_clocks()
1845 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
1846 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1847 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1851 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
1852 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
1853 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1854 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1859 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
1860 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1861 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1865 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
1866 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
1867 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1868 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1873 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
1874 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1875 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1879 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
1880 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
1881 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1882 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1892 struct device *dev = &pdev->dev; in dwc3_probe()
1900 return -ENOMEM; in dwc3_probe()
1902 dwc->dev = dev; in dwc3_probe()
1907 return -ENODEV; in dwc3_probe()
1910 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1911 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1913 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1914 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1918 * since it will be requested by the xhci-plat driver. in dwc3_probe()
1923 if (dev->of_node) { in dwc3_probe()
1924 struct device_node *parent = of_get_parent(dev->of_node); in dwc3_probe()
1926 if (of_device_is_compatible(parent, "realtek,rtd-dwc3")) { in dwc3_probe()
1927 dwc_res.start -= DWC3_GLOBALS_REGS_START; in dwc3_probe()
1938 dwc->regs = regs; in dwc3_probe()
1939 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1943 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1944 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1945 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1953 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1962 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1963 ret = -ENODEV; in dwc3_probe()
1970 if (!dwc->sysdev_is_parent && in dwc3_probe()
1971 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1972 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1977 spin_lock_init(&dwc->lock); in dwc3_probe()
1978 mutex_init(&dwc->mutex); in dwc3_probe()
1990 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1991 ret = -ENOMEM; in dwc3_probe()
1995 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
1996 if (IS_ERR(dwc->edev)) { in dwc3_probe()
1997 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
2041 reset_control_assert(dwc->reset); in dwc3_probe()
2043 if (dwc->usb_psy) in dwc3_probe()
2044 power_supply_put(dwc->usb_psy); in dwc3_probe()
2053 pm_runtime_get_sync(&pdev->dev); in dwc3_remove()
2061 pm_runtime_allow(&pdev->dev); in dwc3_remove()
2062 pm_runtime_disable(&pdev->dev); in dwc3_remove()
2063 pm_runtime_dont_use_autosuspend(&pdev->dev); in dwc3_remove()
2064 pm_runtime_put_noidle(&pdev->dev); in dwc3_remove()
2070 pm_runtime_set_suspended(&pdev->dev); in dwc3_remove()
2074 if (dwc->usb_psy) in dwc3_remove()
2075 power_supply_put(dwc->usb_psy); in dwc3_remove()
2083 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2100 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2109 if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) { in dwc3_suspend_common()
2110 dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) & in dwc3_suspend_common()
2112 (dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)) & in dwc3_suspend_common()
2118 if (!dwc->susphy_state) in dwc3_suspend_common()
2122 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2124 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2127 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2131 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2137 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2138 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2139 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2142 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2148 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2149 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2156 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2158 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2177 switch (dwc->current_dr_role) { in dwc3_resume_common()
2187 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2195 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2196 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2199 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2202 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2204 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2205 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2216 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
2219 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2221 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2233 dwc3_enable_susphy(dwc, dwc->susphy_state); in dwc3_resume_common()
2241 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2243 if (dwc->connected) in dwc3_runtime_checks()
2244 return -EBUSY; in dwc3_runtime_checks()
2261 return -EBUSY; in dwc3_runtime_suspend()
2279 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2281 if (dwc->pending_events) { in dwc3_runtime_resume()
2282 pm_runtime_put(dwc->dev); in dwc3_runtime_resume()
2283 dwc->pending_events = false; in dwc3_runtime_resume()
2284 enable_irq(dwc->irq_gadget); in dwc3_runtime_resume()
2302 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2305 return -EBUSY; in dwc3_runtime_idle()
2358 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2359 dwc->dis_split_quirk) { in dwc3_complete()
2360 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2362 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()