Lines Matching +full:am62 +full:- +full:usb
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>
32 #include <linux/usb/ch9.h>
33 #include <linux/usb/gadget.h>
34 #include <linux/usb/of.h>
35 #include <linux/usb/otg.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()
133 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
140 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_set_prtcap()
148 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
150 dwc->current_dr_role = mode; in dwc3_set_prtcap()
161 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
162 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
163 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
164 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
166 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
168 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
174 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
177 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
180 switch (dwc->current_dr_role) { in __dwc3_set_mode()
190 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
191 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
192 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
203 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
206 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
208 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
218 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
220 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
223 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
227 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
233 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
235 if (dwc->usb2_phy) in __dwc3_set_mode()
236 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
237 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
238 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
239 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
240 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
242 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
251 if (dwc->usb2_phy) in __dwc3_set_mode()
252 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
253 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
254 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
258 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
269 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
270 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
271 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
278 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
281 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
282 dwc->desired_dr_role = mode; in dwc3_set_mode()
283 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
285 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
290 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space()
293 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
294 DWC3_GDBGFIFOSPACE_NUM(dep->number) | in dwc3_core_fifo_space()
297 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
303 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
314 * host-only mode, then we can return early. in dwc3_core_soft_reset()
316 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
319 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
334 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
342 } while (--retries); in dwc3_core_soft_reset()
344 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
345 return -ETIMEDOUT; in dwc3_core_soft_reset()
360 * dwc3_frame_length_adjustment - Adjusts frame length if required
371 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
374 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
376 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
378 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
379 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
384 * dwc3_ref_clk_period - Reference clock period configuration
399 if (dwc->ref_clk) { in dwc3_ref_clk_period()
400 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
404 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
405 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
411 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
414 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
422 * 125000 * (NSEC_PER_SEC / (rate * period) - 1) in dwc3_ref_clk_period()
424 * but rearranged for fixed-point arithmetic. The division must be in dwc3_ref_clk_period()
425 * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and in dwc3_ref_clk_period()
435 fladj -= 125000; in dwc3_ref_clk_period()
442 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
450 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
453 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
457 * dwc3_free_one_event_buffer - Frees one event buffer
464 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
468 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
480 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
482 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
484 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
485 evt->length = length; in dwc3_alloc_one_event_buffer()
486 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
487 if (!evt->cache) in dwc3_alloc_one_event_buffer()
488 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
490 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
491 &evt->dma, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
492 if (!evt->buf) in dwc3_alloc_one_event_buffer()
493 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
499 * dwc3_free_event_buffers - frees all allocated event buffers
506 evt = dwc->ev_buf; in dwc3_free_event_buffers()
512 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
524 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_alloc_event_buffers()
526 dwc->ev_buf = NULL; in dwc3_alloc_event_buffers()
532 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
535 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
541 * dwc3_event_buffers_setup - setup our allocated event buffers
551 if (!dwc->ev_buf) in dwc3_event_buffers_setup()
554 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
555 evt->lpos = 0; in dwc3_event_buffers_setup()
556 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
557 lower_32_bits(evt->dma)); in dwc3_event_buffers_setup()
558 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
559 upper_32_bits(evt->dma)); in dwc3_event_buffers_setup()
560 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
561 DWC3_GEVNTSIZ_SIZE(evt->length)); in dwc3_event_buffers_setup()
564 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_setup()
565 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_setup()
574 if (!dwc->ev_buf) in dwc3_event_buffers_cleanup()
580 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_event_buffers_cleanup()
584 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
586 evt->lpos = 0; in dwc3_event_buffers_cleanup()
588 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
589 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
590 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
594 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_cleanup()
595 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_cleanup()
600 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
602 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
607 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
609 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
610 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
611 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
612 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
613 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
614 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
615 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
616 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
617 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
620 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
628 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
632 dwc->hsphy_interface && in dwc3_core_ulpi_init()
633 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
640 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
643 * Returns 0 on success. The USB PHY interfaces are configured but not
651 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
662 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
665 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
668 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
671 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
674 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
677 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
680 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
683 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
684 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
686 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
689 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
691 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
694 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
696 if (dwc->hsphy_interface && in dwc3_phy_setup()
697 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
700 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
701 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
703 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
715 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
735 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
740 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
744 * Some ULPI USB PHY does not support internal VBUS supply, to drive in dwc3_phy_setup()
750 if (dwc->ulpi_ext_vbus_drv) in dwc3_phy_setup()
753 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
762 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
763 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
765 ret = phy_init(dwc->usb2_generic_phy); in dwc3_phy_init()
769 ret = phy_init(dwc->usb3_generic_phy); in dwc3_phy_init()
776 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_init()
778 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
779 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
786 phy_exit(dwc->usb3_generic_phy); in dwc3_phy_exit()
787 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_exit()
789 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
790 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
797 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
798 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
800 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_phy_power_on()
804 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_phy_power_on()
830 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_on()
832 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
833 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
840 phy_power_off(dwc->usb3_generic_phy); in dwc3_phy_power_off()
841 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_off()
843 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
844 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
851 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
855 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
859 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
866 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
868 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
874 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
875 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
876 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
885 reset_control_assert(dwc->reset); in dwc3_core_exit()
892 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
893 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
897 dwc->revision = reg; in dwc3_core_is_valid()
899 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
900 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
914 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
916 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_setup_global_control()
917 power_opt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_core_setup_global_control()
930 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based in dwc3_core_setup_global_control()
933 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
934 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
942 * REVISIT Enabling this bit so that host-mode hibernation in dwc3_core_setup_global_control()
943 * will work. Device-mode hibernation is not yet implemented. in dwc3_core_setup_global_control()
967 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
968 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
969 dwc->is_fpga = true; in dwc3_core_setup_global_control()
972 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
973 "disable_scramble cannot be used on non-FPGA builds\n"); in dwc3_core_setup_global_control()
975 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
980 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
986 * and falls back to high-speed mode which causes in dwc3_core_setup_global_control()
992 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
1001 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
1012 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1015 * Handle property "snps,incr-burst-type-adjustment". in dwc3_set_incr_burst_type()
1021 ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment"); in dwc3_set_incr_burst_type()
1031 "snps,incr-burst-type-adjustment", vals, ntype); in dwc3_set_incr_burst_type()
1087 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1095 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1111 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1112 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1117 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1133 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1134 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1135 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1136 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1137 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1140 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1149 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1153 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1162 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1166 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1167 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1168 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1169 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1173 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1182 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1186 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1195 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1199 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1208 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1212 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1221 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1227 * dwc3_core_init - Low-level initialization of DWC3 Core
1238 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1244 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1250 if (!dwc->ulpi_ready) { in dwc3_core_init()
1253 if (ret == -ETIMEDOUT) { in dwc3_core_init()
1255 ret = -EPROBE_DEFER; in dwc3_core_init()
1259 dwc->ulpi_ready = true; in dwc3_core_init()
1262 if (!dwc->phys_ready) { in dwc3_core_init()
1266 dwc->phys_ready = true; in dwc3_core_init()
1297 dev_err(dwc->dev, "failed to setup event buffers\n"); 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()
1322 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1324 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1331 * re-enumeration of usb device attached. All the termsel, xcvrsel, in dwc3_core_init()
1336 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1337 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1339 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1343 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1353 * Decouple USB 2.0 L1 & L2 events which will allow for in dwc3_core_init()
1361 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1364 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1367 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1371 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1372 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1375 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1394 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1395 struct device_node *node = dev->of_node; in dwc3_core_get_phy()
1399 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1400 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1402 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1403 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1406 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1407 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1408 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1409 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1414 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1415 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1416 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1417 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1422 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1423 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1424 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1425 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1426 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1431 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1432 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1433 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1434 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1435 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1445 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1448 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1452 if (dwc->usb2_phy) in dwc3_core_init_mode()
1453 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1454 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1455 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1464 if (dwc->usb2_phy) in dwc3_core_init_mode()
1465 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1466 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1467 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1474 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1477 return dev_err_probe(dev, ret, "failed to initialize dual-role\n"); in dwc3_core_init_mode()
1480 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1481 return -EINVAL; in dwc3_core_init_mode()
1489 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1504 /* de-assert DRVVBUS for HOST and OTG mode */ in dwc3_core_exit_mode()
1510 struct device *dev = dwc->dev; in dwc3_get_properties()
1527 /* default to -3.5dB de-emphasis */ in dwc3_get_properties()
1543 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1544 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1545 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1546 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1548 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1550 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1551 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1553 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1555 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); in dwc3_get_properties()
1557 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1558 "snps,has-lpm-erratum"); in dwc3_get_properties()
1559 device_property_read_u8(dev, "snps,lpm-nyet-threshold", in dwc3_get_properties()
1561 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1562 "snps,is-utmi-l1-suspend"); in dwc3_get_properties()
1563 device_property_read_u8(dev, "snps,hird-threshold", in dwc3_get_properties()
1565 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1566 "snps,dis-start-transfer-quirk"); in dwc3_get_properties()
1567 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1569 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1570 "snps,usb2-lpm-disable"); in dwc3_get_properties()
1571 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1572 "snps,usb2-gadget-lpm-disable"); in dwc3_get_properties()
1573 device_property_read_u8(dev, "snps,rx-thr-num-pkt", in dwc3_get_properties()
1575 device_property_read_u8(dev, "snps,rx-max-burst", in dwc3_get_properties()
1577 device_property_read_u8(dev, "snps,tx-thr-num-pkt", in dwc3_get_properties()
1579 device_property_read_u8(dev, "snps,tx-max-burst", in dwc3_get_properties()
1581 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd", in dwc3_get_properties()
1583 device_property_read_u8(dev, "snps,rx-max-burst-prd", in dwc3_get_properties()
1585 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd", in dwc3_get_properties()
1587 device_property_read_u8(dev, "snps,tx-max-burst-prd", in dwc3_get_properties()
1589 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1590 "tx-fifo-resize"); in dwc3_get_properties()
1591 if (dwc->do_fifo_resize) in dwc3_get_properties()
1592 device_property_read_u8(dev, "tx-fifo-max-num", in dwc3_get_properties()
1595 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1597 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1599 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1601 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1603 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1605 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1607 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1609 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1611 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1613 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1615 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1617 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1618 "snps,dis-u1-entry-quirk"); in dwc3_get_properties()
1619 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1620 "snps,dis-u2-entry-quirk"); in dwc3_get_properties()
1621 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1623 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1624 "snps,dis-u2-freeclk-exists-quirk"); in dwc3_get_properties()
1625 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1626 "snps,dis-del-phy-power-chg-quirk"); in dwc3_get_properties()
1627 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1628 "snps,dis-tx-ipgap-linecheck-quirk"); in dwc3_get_properties()
1629 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1630 "snps,resume-hs-terminations"); in dwc3_get_properties()
1631 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1632 "snps,ulpi-ext-vbus-drv"); in dwc3_get_properties()
1633 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1634 "snps,parkmode-disable-ss-quirk"); in dwc3_get_properties()
1635 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1636 "snps,parkmode-disable-hs-quirk"); in dwc3_get_properties()
1637 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1638 "snps,gfladj-refclk-lpm-sel-quirk"); in dwc3_get_properties()
1640 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1645 &dwc->hsphy_interface); in dwc3_get_properties()
1646 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", in dwc3_get_properties()
1647 &dwc->fladj); in dwc3_get_properties()
1648 device_property_read_u32(dev, "snps,ref-clock-period-ns", in dwc3_get_properties()
1649 &dwc->ref_clk_per); in dwc3_get_properties()
1651 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1654 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1655 "snps,dis-split-quirk"); in dwc3_get_properties()
1657 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1658 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1660 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1662 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1663 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1665 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1666 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1668 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1669 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1671 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1672 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1674 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1687 struct device *dev = dwc->dev; in dwc3_check_params()
1689 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1704 dwc->imod_interval = 1; in dwc3_check_params()
1707 switch (dwc->maximum_speed) { in dwc3_check_params()
1724 dwc->maximum_speed); in dwc3_check_params()
1729 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1733 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1735 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1738 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1741 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1751 * set the default to support dual-lane for DWC_usb32 and single-lane in dwc3_check_params()
1752 * for DWC_usb31 for super-speed-plus. in dwc3_check_params()
1754 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1755 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1770 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1772 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1776 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1786 struct device *dev = dwc->dev; in dwc3_get_extcon()
1800 if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) in dwc3_get_extcon()
1804 * Check explicitly if "usb-role-switch" is used since in dwc3_get_extcon()
1810 device_property_read_bool(dev, "usb-role-switch")) in dwc3_get_extcon()
1814 * Try to get an extcon device from the USB PHY controller's "port" in dwc3_get_extcon()
1817 * device (and "port" node) may be missing in case of "usb-role-switch" in dwc3_get_extcon()
1820 np_phy = of_parse_phandle(dev->of_node, "phys", 0); in dwc3_get_extcon()
1824 np_conn = of_graph_get_remote_node(np_phy, -1, -1); in dwc3_get_extcon()
1836 struct device *dev = dwc->dev; in dwc3_get_clocks()
1838 if (!dev->of_node) in dwc3_get_clocks()
1843 * as required by the DT-binding. in dwc3_get_clocks()
1847 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
1848 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1849 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1853 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
1854 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
1855 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1856 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1861 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
1862 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1863 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1867 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
1868 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
1869 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1870 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1875 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
1876 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1877 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1881 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
1882 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
1883 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1884 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1898 ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name); in dwc3_get_usb_power_supply()
1904 return ERR_PTR(-EPROBE_DEFER); in dwc3_get_usb_power_supply()
1911 struct device *dev = &pdev->dev; in dwc3_probe()
1919 return -ENOMEM; in dwc3_probe()
1921 dwc->dev = dev; in dwc3_probe()
1926 return -ENODEV; in dwc3_probe()
1929 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1930 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1932 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1933 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1937 * since it will be requested by the xhci-plat driver. in dwc3_probe()
1942 if (dev->of_node) { in dwc3_probe()
1943 struct device_node *parent = of_get_parent(dev->of_node); in dwc3_probe()
1945 if (of_device_is_compatible(parent, "realtek,rtd-dwc3")) { in dwc3_probe()
1946 dwc_res.start -= DWC3_GLOBALS_REGS_START; in dwc3_probe()
1957 dwc->regs = regs; in dwc3_probe()
1958 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1962 dwc->usb_psy = dwc3_get_usb_power_supply(dwc); in dwc3_probe()
1963 if (IS_ERR(dwc->usb_psy)) in dwc3_probe()
1964 return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n"); in dwc3_probe()
1966 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1967 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1968 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1976 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1985 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1986 ret = -ENODEV; in dwc3_probe()
1993 if (!dwc->sysdev_is_parent && in dwc3_probe()
1994 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1995 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
2000 spin_lock_init(&dwc->lock); in dwc3_probe()
2001 mutex_init(&dwc->mutex); in dwc3_probe()
2013 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
2014 ret = -ENOMEM; in dwc3_probe()
2018 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
2019 if (IS_ERR(dwc->edev)) { in dwc3_probe()
2020 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
2064 reset_control_assert(dwc->reset); in dwc3_probe()
2066 if (dwc->usb_psy) in dwc3_probe()
2067 power_supply_put(dwc->usb_psy); in dwc3_probe()
2076 pm_runtime_get_sync(&pdev->dev); in dwc3_remove()
2084 pm_runtime_allow(&pdev->dev); in dwc3_remove()
2085 pm_runtime_disable(&pdev->dev); in dwc3_remove()
2086 pm_runtime_dont_use_autosuspend(&pdev->dev); in dwc3_remove()
2087 pm_runtime_put_noidle(&pdev->dev); in dwc3_remove()
2093 pm_runtime_set_suspended(&pdev->dev); in dwc3_remove()
2097 if (dwc->usb_psy) in dwc3_remove()
2098 power_supply_put(dwc->usb_psy); in dwc3_remove()
2106 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2123 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2132 if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) { in dwc3_suspend_common()
2133 dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) & in dwc3_suspend_common()
2135 (dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)) & in dwc3_suspend_common()
2138 * TI AM62 platform requires SUSPHY to be in dwc3_suspend_common()
2141 if (!dwc->susphy_state) in dwc3_suspend_common()
2145 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2147 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2150 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2154 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2160 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2161 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2162 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2165 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2171 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2172 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2179 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2181 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2200 switch (dwc->current_dr_role) { in dwc3_resume_common()
2210 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2218 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2219 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2222 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2225 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2227 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2228 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2239 dwc3_set_prtcap(dwc, dwc->current_dr_role, true); in dwc3_resume_common()
2242 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2244 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2256 dwc3_enable_susphy(dwc, dwc->susphy_state); in dwc3_resume_common()
2264 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2266 if (dwc->connected) in dwc3_runtime_checks()
2267 return -EBUSY; in dwc3_runtime_checks()
2284 return -EBUSY; in dwc3_runtime_suspend()
2302 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2304 if (dwc->pending_events) { in dwc3_runtime_resume()
2305 pm_runtime_put(dwc->dev); in dwc3_runtime_resume()
2306 dwc->pending_events = false; in dwc3_runtime_resume()
2307 enable_irq(dwc->irq_gadget); in dwc3_runtime_resume()
2325 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2328 return -EBUSY; in dwc3_runtime_idle()
2381 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2382 dwc->dis_split_quirk) { in dwc3_complete()
2383 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2385 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()