Lines Matching refs:dwc
49 static int dwc3_get_dr_mode(struct dwc3 *dwc) in dwc3_get_dr_mode() argument
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()
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()
107 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) in dwc3_set_prtcap() argument
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()
121 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
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()
135 dwc3_otg_update(dwc, 0); 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()
148 dwc3_host_exit(dwc); in __dwc3_set_mode()
151 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
152 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
155 dwc3_otg_exit(dwc); 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()
159 dwc3_otg_update(dwc, 1); 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()
191 dwc3_set_prtcap(dwc, desired_dr_role); in __dwc3_set_mode()
193 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
197 ret = dwc3_host_init(dwc); 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()
213 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
215 dwc3_event_buffers_setup(dwc); 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()
222 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
224 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
227 dwc3_otg_init(dwc); in __dwc3_set_mode()
228 dwc3_otg_update(dwc, 0); 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()
240 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
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() local
259 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
263 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
272 int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
282 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
296 if (dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_soft_reset()
300 usb3_port = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_soft_reset()
302 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), usb3_port); in dwc3_core_soft_reset()
304 usb2_port = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_soft_reset()
306 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), usb2_port); in dwc3_core_soft_reset()
312 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), usb3_port); in dwc3_core_soft_reset()
315 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), usb2_port); in dwc3_core_soft_reset()
322 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
325 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_core_soft_reset()
337 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
347 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
366 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
374 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
377 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
379 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
381 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
382 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
394 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
402 if (dwc->ref_clk) { in dwc3_ref_clk_period()
403 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
407 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
408 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
414 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
417 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
445 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
453 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
456 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
464 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
467 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
478 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
483 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
487 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
489 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
493 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
505 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
509 evt = dwc->ev_buf; in dwc3_free_event_buffers()
511 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
522 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
526 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
528 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
531 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
542 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
546 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
548 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
550 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
552 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
554 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
559 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
563 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
567 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
568 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
569 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
571 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
574 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
576 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
578 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
581 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
583 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
585 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
586 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
587 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
588 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
589 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
590 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
591 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
592 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
593 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
596 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
599 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
604 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
608 dwc->hsphy_interface && in dwc3_core_ulpi_init()
609 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
610 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
623 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
628 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
630 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
655 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
658 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
661 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
664 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
667 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
670 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
673 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
676 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
677 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
679 if (dwc->dis_u3_susphy_quirk) 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()
745 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
748 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
753 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
763 if (dwc->ulpi_ext_vbus_drv) in dwc3_phy_setup()
766 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
771 static int dwc3_phy_init(struct dwc3 *dwc) in dwc3_phy_init() argument
775 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
776 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
778 ret = phy_init(dwc->usb2_generic_phy); in dwc3_phy_init()
782 ret = phy_init(dwc->usb3_generic_phy); in dwc3_phy_init()
789 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_init()
791 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
792 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
797 static void dwc3_phy_exit(struct dwc3 *dwc) in dwc3_phy_exit() argument
799 phy_exit(dwc->usb3_generic_phy); in dwc3_phy_exit()
800 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_exit()
802 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
803 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
806 static int dwc3_phy_power_on(struct dwc3 *dwc) in dwc3_phy_power_on() argument
810 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
811 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
813 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_phy_power_on()
817 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_phy_power_on()
824 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_on()
826 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
827 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
832 static void dwc3_phy_power_off(struct dwc3 *dwc) in dwc3_phy_power_off() argument
834 phy_power_off(dwc->usb3_generic_phy); in dwc3_phy_power_off()
835 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_off()
837 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
838 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
841 static int dwc3_clk_enable(struct dwc3 *dwc) in dwc3_clk_enable() argument
845 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
849 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
853 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
860 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
862 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
866 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
868 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
869 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
870 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
873 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
875 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
876 dwc3_phy_power_off(dwc); in dwc3_core_exit()
877 dwc3_phy_exit(dwc); in dwc3_core_exit()
878 dwc3_clk_disable(dwc); in dwc3_core_exit()
879 reset_control_assert(dwc->reset); in dwc3_core_exit()
882 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
886 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
887 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
891 dwc->revision = reg; in dwc3_core_is_valid()
893 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
894 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
902 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
906 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
909 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
923 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
924 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
943 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
944 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
945 dwc->is_fpga = true; in dwc3_core_setup_global_control()
948 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
951 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
956 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
968 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
971 static int dwc3_core_get_phy(struct dwc3 *dwc);
972 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
975 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
977 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
988 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1063 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1066 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1071 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1087 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1088 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1093 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1103 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1109 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1115 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1117 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1121 if (!dwc->ulpi_ready) { in dwc3_core_init()
1122 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1125 dwc3_core_soft_reset(dwc); in dwc3_core_init()
1130 dwc->ulpi_ready = true; in dwc3_core_init()
1133 if (!dwc->phys_ready) { in dwc3_core_init()
1134 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1137 dwc->phys_ready = true; in dwc3_core_init()
1140 ret = dwc3_phy_init(dwc); in dwc3_core_init()
1144 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1150 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
1151 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
1153 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
1156 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
1157 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
1159 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
1163 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1164 dwc3_core_num_eps(dwc); in dwc3_core_init()
1167 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1170 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1173 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1175 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1177 ret = dwc3_phy_power_on(dwc); in dwc3_core_init()
1181 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1183 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1193 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1195 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1207 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1208 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1210 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1214 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1232 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1235 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1238 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1242 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1243 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1246 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1253 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_init()
1254 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_core_init()
1255 u8 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_core_init()
1256 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_core_init()
1257 u8 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_core_init()
1260 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_core_init()
1269 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_core_init()
1273 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_core_init()
1282 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_core_init()
1289 dwc3_phy_power_off(dwc); in dwc3_core_init()
1291 dwc3_phy_exit(dwc); in dwc3_core_init()
1293 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1298 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1300 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1305 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1306 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1308 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1309 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1312 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1313 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1315 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1320 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1321 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1323 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1328 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1329 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1330 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1332 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1337 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1338 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1339 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1341 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1349 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1351 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1354 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1356 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1358 if (dwc->usb2_phy) in dwc3_core_init_mode()
1359 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1360 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1361 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1363 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1368 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1370 if (dwc->usb2_phy) in dwc3_core_init_mode()
1371 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1372 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1373 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1375 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1380 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1381 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1386 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1393 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1395 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1397 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1400 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1403 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1411 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1414 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1416 struct device *dev = dwc->dev; in dwc3_get_properties()
1447 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1448 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1449 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1450 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1452 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1454 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1455 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1457 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1461 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1462 if (!dwc->usb_psy) in dwc3_get_properties()
1466 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1470 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1474 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1476 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1478 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1480 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1490 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1492 if (dwc->do_fifo_resize) in dwc3_get_properties()
1496 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1498 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1500 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1502 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1504 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1506 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1508 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1510 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1512 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1514 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1516 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1518 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1520 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1522 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1524 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1526 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1528 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1530 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1532 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1534 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1536 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1538 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1541 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1546 &dwc->hsphy_interface); in dwc3_get_properties()
1548 &dwc->fladj); in dwc3_get_properties()
1550 &dwc->ref_clk_per); in dwc3_get_properties()
1552 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1555 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1558 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1559 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1561 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1563 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1564 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1566 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1567 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1569 dwc->imod_interval = 0; in dwc3_get_properties()
1571 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1575 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1582 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1584 struct device *dev = dwc->dev; in dwc3_check_params()
1586 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1589 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1590 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1591 dwc->imod_interval = 0; in dwc3_check_params()
1601 if (!dwc->imod_interval && in dwc3_check_params()
1603 dwc->imod_interval = 1; in dwc3_check_params()
1606 switch (dwc->maximum_speed) { in dwc3_check_params()
1623 dwc->maximum_speed); in dwc3_check_params()
1628 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1632 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1634 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1637 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1640 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1653 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1654 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1669 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1671 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1675 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1683 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1685 struct device *dev = dwc->dev; in dwc3_get_extcon()
1733 static int dwc3_get_clocks(struct dwc3 *dwc) in dwc3_get_clocks() argument
1735 struct device *dev = dwc->dev; in dwc3_get_clocks()
1746 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
1747 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1748 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1752 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
1753 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
1754 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1755 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1760 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
1761 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1762 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1766 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
1767 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
1768 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1769 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1774 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
1775 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1776 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1780 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
1781 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
1782 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1783 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1796 struct dwc3 *dwc; in dwc3_probe() local
1799 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1800 if (!dwc) in dwc3_probe()
1803 dwc->dev = dev; in dwc3_probe()
1811 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1812 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1814 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1815 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1839 dwc->regs = regs; in dwc3_probe()
1840 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1842 dwc3_get_properties(dwc); in dwc3_probe()
1844 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1845 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1846 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1850 ret = dwc3_get_clocks(dwc); in dwc3_probe()
1854 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1858 ret = dwc3_clk_enable(dwc); in dwc3_probe()
1862 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1863 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1868 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1869 dwc3_cache_hwparams(dwc); in dwc3_probe()
1871 if (!dwc->sysdev_is_parent && in dwc3_probe()
1872 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1873 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1878 spin_lock_init(&dwc->lock); in dwc3_probe()
1879 mutex_init(&dwc->mutex); in dwc3_probe()
1889 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1891 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1896 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
1897 if (IS_ERR(dwc->edev)) { in dwc3_probe()
1898 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
1902 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1906 ret = dwc3_core_init(dwc); in dwc3_probe()
1912 dwc3_check_params(dwc); in dwc3_probe()
1913 dwc3_debugfs_init(dwc); in dwc3_probe()
1915 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
1924 dwc3_debugfs_exit(dwc); in dwc3_probe()
1925 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
1926 dwc3_phy_power_off(dwc); in dwc3_probe()
1927 dwc3_phy_exit(dwc); in dwc3_probe()
1928 dwc3_ulpi_exit(dwc); in dwc3_probe()
1930 dwc3_free_event_buffers(dwc); in dwc3_probe()
1938 dwc3_clk_disable(dwc); in dwc3_probe()
1940 reset_control_assert(dwc->reset); in dwc3_probe()
1942 if (dwc->usb_psy) in dwc3_probe()
1943 power_supply_put(dwc->usb_psy); in dwc3_probe()
1950 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
1954 dwc3_core_exit_mode(dwc); in dwc3_remove()
1955 dwc3_debugfs_exit(dwc); in dwc3_remove()
1957 dwc3_core_exit(dwc); in dwc3_remove()
1958 dwc3_ulpi_exit(dwc); in dwc3_remove()
1971 dwc3_free_event_buffers(dwc); in dwc3_remove()
1973 if (dwc->usb_psy) in dwc3_remove()
1974 power_supply_put(dwc->usb_psy); in dwc3_remove()
1978 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
1982 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
1986 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
1990 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
1997 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
1999 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2004 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2009 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2011 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2013 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2014 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2015 dwc3_core_exit(dwc); in dwc3_suspend_common()
2018 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2019 dwc3_core_exit(dwc); in dwc3_suspend_common()
2024 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2025 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2026 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2029 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2035 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2036 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2043 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2044 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
2045 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2046 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
2047 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2050 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2051 dwc3_core_exit(dwc); in dwc3_suspend_common()
2061 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2067 switch (dwc->current_dr_role) { in dwc3_resume_common()
2069 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2073 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
2074 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2077 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2078 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2081 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
2085 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2086 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2089 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2092 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2094 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2095 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2102 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2106 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
2108 dwc3_otg_init(dwc); in dwc3_resume_common()
2109 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2110 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2111 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2112 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
2113 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2114 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
2126 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2128 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2130 if (dwc->connected) in dwc3_runtime_checks()
2144 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
2147 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2150 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2159 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
2162 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2166 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2168 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
2183 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
2185 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2187 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2206 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
2209 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
2220 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
2225 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
2238 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
2241 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2242 dwc->dis_split_quirk) { in dwc3_complete()
2243 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2245 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()