Lines Matching full:dwc

48  * @dwc: pointer to our context structure
50 static int dwc3_get_dr_mode(struct dwc3 *dwc) in dwc3_get_dr_mode() argument
53 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
56 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
57 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
59 mode = dwc->dr_mode; in dwc3_get_dr_mode()
60 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
90 if (mode == USB_DR_MODE_OTG && !dwc->edev && in dwc3_get_dr_mode()
92 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
97 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
102 dwc->dr_mode = mode; in dwc3_get_dr_mode()
108 void dwc3_enable_susphy(struct dwc3 *dwc, bool enable) in dwc3_enable_susphy() argument
113 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_enable_susphy()
114 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i)); in dwc3_enable_susphy()
115 if (enable && !dwc->dis_u3_susphy_quirk) in dwc3_enable_susphy()
120 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(i), reg); in dwc3_enable_susphy()
123 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_enable_susphy()
124 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_enable_susphy()
125 if (enable && !dwc->dis_u2_susphy_quirk) in dwc3_enable_susphy()
130 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_enable_susphy()
134 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy) in dwc3_set_prtcap() argument
139 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
146 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_set_prtcap()
149 dwc3_enable_susphy(dwc, false); in dwc3_set_prtcap()
154 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
156 dwc->current_dr_role = mode; in dwc3_set_prtcap()
161 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
168 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
169 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
170 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
171 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
173 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
175 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
176 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
181 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
184 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
187 switch (dwc->current_dr_role) { in __dwc3_set_mode()
189 dwc3_host_exit(dwc); in __dwc3_set_mode()
192 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
193 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
196 dwc3_otg_exit(dwc); in __dwc3_set_mode()
197 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
198 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
199 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
200 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
210 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
213 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
215 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
225 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
227 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
230 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
232 dwc3_set_prtcap(dwc, desired_dr_role, false); in __dwc3_set_mode()
234 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
238 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
240 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
242 if (dwc->usb2_phy) in __dwc3_set_mode()
243 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
245 for (i = 0; i < dwc->num_usb2_ports; i++) in __dwc3_set_mode()
246 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
247 for (i = 0; i < dwc->num_usb3_ports; i++) in __dwc3_set_mode()
248 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
250 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
251 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
253 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
258 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
260 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
262 if (dwc->usb2_phy) in __dwc3_set_mode()
263 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
264 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
265 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
267 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
269 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
272 dwc3_otg_init(dwc); in __dwc3_set_mode()
273 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
280 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
281 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
282 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
285 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
289 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
292 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
293 dwc->desired_dr_role = mode; in dwc3_set_mode()
294 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
296 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
301 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
304 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
308 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
315 * @dwc: pointer to our context structure
317 int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
327 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
330 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
333 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_core_soft_reset()
345 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
355 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
374 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
382 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
385 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
387 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
389 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
390 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
400 * @dwc: Pointer to our controller context structure
402 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
410 if (dwc->ref_clk) { in dwc3_ref_clk_period()
411 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
415 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
416 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
422 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
425 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
453 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
461 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
464 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
469 * @dwc: Pointer to our controller context structure
472 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
475 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
480 * @dwc: Pointer to our controller context structure
486 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
491 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
495 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
497 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
501 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
511 * @dwc: Pointer to our controller context structure
513 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
517 evt = dwc->ev_buf; in dwc3_free_event_buffers()
519 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
524 * @dwc: pointer to our controller context structure
527 * Returns 0 on success otherwise negative errno. In the error case, dwc
530 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
535 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_alloc_event_buffers()
537 dwc->ev_buf = NULL; in dwc3_alloc_event_buffers()
541 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
543 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
546 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
553 * @dwc: pointer to our controller context structure
557 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
562 if (!dwc->ev_buf) in dwc3_event_buffers_setup()
565 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
567 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
569 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
571 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
575 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_setup()
576 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_setup()
580 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
585 if (!dwc->ev_buf) in dwc3_event_buffers_cleanup()
591 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_event_buffers_cleanup()
595 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
599 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
600 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
601 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
605 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_cleanup()
606 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_cleanup()
609 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
611 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
613 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
616 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
618 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
620 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
621 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
622 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
623 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
624 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
625 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
626 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
627 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
628 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
631 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
634 static void dwc3_config_soc_bus(struct dwc3 *dwc) in dwc3_config_soc_bus() argument
636 if (dwc->gsbuscfg0_reqinfo != DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED) { in dwc3_config_soc_bus()
639 reg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_config_soc_bus()
641 reg |= DWC3_GSBUSCFG0_REQINFO(dwc->gsbuscfg0_reqinfo); in dwc3_config_soc_bus()
642 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, reg); in dwc3_config_soc_bus()
646 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
651 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
655 dwc->hsphy_interface && in dwc3_core_ulpi_init()
656 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
657 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
662 static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index) in dwc3_ss_phy_setup() argument
666 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(index)); in dwc3_ss_phy_setup()
677 if (dwc->u2ss_inp3_quirk) in dwc3_ss_phy_setup()
680 if (dwc->dis_rxdet_inp3_quirk) in dwc3_ss_phy_setup()
683 if (dwc->req_p1p2p3_quirk) in dwc3_ss_phy_setup()
686 if (dwc->del_p1p2p3_quirk) in dwc3_ss_phy_setup()
689 if (dwc->del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
692 if (dwc->lfps_filter_quirk) in dwc3_ss_phy_setup()
695 if (dwc->rx_detect_poll_quirk) in dwc3_ss_phy_setup()
698 if (dwc->tx_de_emphasis_quirk) in dwc3_ss_phy_setup()
699 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_ss_phy_setup()
701 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
704 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(index), reg); in dwc3_ss_phy_setup()
709 static int dwc3_hs_phy_setup(struct dwc3 *dwc, int index) in dwc3_hs_phy_setup() argument
713 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(index)); in dwc3_hs_phy_setup()
716 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_hs_phy_setup()
718 if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
719 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_hs_phy_setup()
722 } else if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
723 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_hs_phy_setup()
725 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
737 switch (dwc->hsphy_mode) { in dwc3_hs_phy_setup()
757 if (dwc->dis_enblslpm_quirk) in dwc3_hs_phy_setup()
762 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_hs_phy_setup()
772 if (dwc->ulpi_ext_vbus_drv) in dwc3_hs_phy_setup()
775 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
782 * @dwc: Pointer to our controller context structure
788 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
793 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_phy_setup()
794 ret = dwc3_ss_phy_setup(dwc, i); in dwc3_phy_setup()
799 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_setup()
800 ret = dwc3_hs_phy_setup(dwc, i); in dwc3_phy_setup()
808 static int dwc3_phy_init(struct dwc3 *dwc) in dwc3_phy_init() argument
814 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
815 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
817 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_init()
818 ret = phy_init(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
823 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_init()
824 ret = phy_init(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
846 dwc3_enable_susphy(dwc, true); in dwc3_phy_init()
852 phy_exit(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
856 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
858 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
859 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
864 static void dwc3_phy_exit(struct dwc3 *dwc) in dwc3_phy_exit() argument
868 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_exit()
869 phy_exit(dwc->usb3_generic_phy[i]); in dwc3_phy_exit()
871 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_exit()
872 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_exit()
874 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
875 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
878 static int dwc3_phy_power_on(struct dwc3 *dwc) in dwc3_phy_power_on() argument
884 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
885 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
887 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_power_on()
888 ret = phy_power_on(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
893 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_power_on()
894 ret = phy_power_on(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
903 phy_power_off(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
907 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
909 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
910 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
915 static void dwc3_phy_power_off(struct dwc3 *dwc) in dwc3_phy_power_off() argument
919 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_power_off()
920 phy_power_off(dwc->usb3_generic_phy[i]); in dwc3_phy_power_off()
922 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_power_off()
923 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_off()
925 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
926 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
929 static int dwc3_clk_enable(struct dwc3 *dwc) in dwc3_clk_enable() argument
933 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
937 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
941 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
945 ret = clk_prepare_enable(dwc->utmi_clk); in dwc3_clk_enable()
949 ret = clk_prepare_enable(dwc->pipe_clk); in dwc3_clk_enable()
956 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_enable()
958 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_enable()
960 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
962 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
966 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
968 clk_disable_unprepare(dwc->pipe_clk); in dwc3_clk_disable()
969 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_disable()
970 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
971 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
972 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
975 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
977 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
978 dwc3_phy_power_off(dwc); in dwc3_core_exit()
979 dwc3_phy_exit(dwc); in dwc3_core_exit()
980 dwc3_clk_disable(dwc); in dwc3_core_exit()
981 reset_control_assert(dwc->reset); in dwc3_core_exit()
984 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
988 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
989 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
993 dwc->revision = reg; in dwc3_core_is_valid()
995 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
996 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
1004 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
1010 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
1012 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_setup_global_control()
1013 power_opt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_core_setup_global_control()
1029 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
1030 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
1063 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
1064 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
1065 dwc->is_fpga = true; in dwc3_core_setup_global_control()
1068 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
1071 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
1076 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
1088 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
1091 static int dwc3_core_get_phy(struct dwc3 *dwc);
1092 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
1095 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
1097 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
1108 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1183 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1186 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1191 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1207 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1208 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1213 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1217 static void dwc3_config_threshold(struct dwc3 *dwc) in dwc3_config_threshold() argument
1229 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1230 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1231 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1232 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1233 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1236 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1245 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1249 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1258 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1262 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1263 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1264 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1265 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1269 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1278 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1282 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1291 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1295 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1304 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1308 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1317 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1324 * @dwc: Pointer to our controller context structure
1328 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1334 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1340 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1342 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1346 if (!dwc->ulpi_ready) { in dwc3_core_init()
1347 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1350 dwc3_core_soft_reset(dwc); in dwc3_core_init()
1355 dwc->ulpi_ready = true; in dwc3_core_init()
1358 if (!dwc->phys_ready) { in dwc3_core_init()
1359 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1362 dwc->phys_ready = true; in dwc3_core_init()
1365 ret = dwc3_phy_init(dwc); in dwc3_core_init()
1369 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1373 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1374 dwc3_core_num_eps(dwc); in dwc3_core_init()
1377 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1380 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1383 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1385 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1387 dwc3_config_soc_bus(dwc); in dwc3_core_init()
1389 ret = dwc3_phy_power_on(dwc); in dwc3_core_init()
1393 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1395 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1405 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1407 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1420 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1422 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1434 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1435 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1437 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1441 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1459 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1462 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1465 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1469 if (dwc->maximum_speed == USB_SPEED_FULL || in dwc3_core_init()
1470 dwc->maximum_speed == USB_SPEED_HIGH) in dwc3_core_init()
1476 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1479 dwc3_config_threshold(dwc); in dwc3_core_init()
1487 dwc->maximum_speed == USB_SPEED_SUPER) { in dwc3_core_init()
1490 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_init()
1491 reg = dwc3_readl(dwc->regs, DWC3_LLUCTL(i)); in dwc3_core_init()
1493 dwc3_writel(dwc->regs, DWC3_LLUCTL(i), reg); in dwc3_core_init()
1512 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_core_init()
1514 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_core_init()
1520 dwc3_phy_power_off(dwc); in dwc3_core_init()
1522 dwc3_phy_exit(dwc); in dwc3_core_init()
1524 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1529 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1531 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1538 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1539 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1541 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1542 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1545 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1546 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1548 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1553 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1554 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1556 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1561 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_core_get_phy()
1562 if (dwc->num_usb2_ports == 1) in dwc3_core_get_phy()
1567 dwc->usb2_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1568 if (IS_ERR(dwc->usb2_generic_phy[i])) { in dwc3_core_get_phy()
1569 ret = PTR_ERR(dwc->usb2_generic_phy[i]); in dwc3_core_get_phy()
1571 dwc->usb2_generic_phy[i] = NULL; in dwc3_core_get_phy()
1578 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_get_phy()
1579 if (dwc->num_usb3_ports == 1) in dwc3_core_get_phy()
1584 dwc->usb3_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1585 if (IS_ERR(dwc->usb3_generic_phy[i])) { in dwc3_core_get_phy()
1586 ret = PTR_ERR(dwc->usb3_generic_phy[i]); in dwc3_core_get_phy()
1588 dwc->usb3_generic_phy[i] = NULL; in dwc3_core_get_phy()
1598 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1600 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1604 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1606 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, false); in dwc3_core_init_mode()
1608 if (dwc->usb2_phy) in dwc3_core_init_mode()
1609 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1610 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1611 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1613 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1618 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, false); in dwc3_core_init_mode()
1620 if (dwc->usb2_phy) in dwc3_core_init_mode()
1621 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1622 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_core_init_mode()
1623 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1624 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_core_init_mode()
1625 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1627 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1632 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1633 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1638 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1645 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1647 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1649 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1652 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1655 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1663 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, true); in dwc3_core_exit_mode()
1666 static void dwc3_get_software_properties(struct dwc3 *dwc) in dwc3_get_software_properties() argument
1672 dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED; in dwc3_get_software_properties()
1678 for (tmpdev = dwc->dev; tmpdev; tmpdev = tmpdev->parent) { in dwc3_get_software_properties()
1683 dwc->gsbuscfg0_reqinfo = gsbuscfg0_reqinfo; in dwc3_get_software_properties()
1687 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1689 struct device *dev = dwc->dev; in dwc3_get_properties()
1722 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1723 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1724 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1725 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1727 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1729 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1730 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1732 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1734 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); in dwc3_get_properties()
1736 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1740 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1744 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1746 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1748 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1750 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1768 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1770 if (dwc->do_fifo_resize) in dwc3_get_properties()
1774 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1776 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1778 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1780 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1782 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1784 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1786 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1788 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1790 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1792 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1794 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1796 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1798 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1800 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1802 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1804 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1806 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1808 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1810 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1812 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1814 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1816 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1819 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1824 &dwc->hsphy_interface); in dwc3_get_properties()
1826 &dwc->fladj); in dwc3_get_properties()
1828 &dwc->ref_clk_per); in dwc3_get_properties()
1830 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1833 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1836 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1837 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1839 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1841 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1842 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1844 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1845 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1847 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1848 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1850 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1851 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1853 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1857 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1864 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1866 struct device *dev = dwc->dev; in dwc3_check_params()
1868 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1882 if (dwc3_has_imod((dwc))) in dwc3_check_params()
1883 dwc->imod_interval = 1; in dwc3_check_params()
1886 switch (dwc->maximum_speed) { in dwc3_check_params()
1903 dwc->maximum_speed); in dwc3_check_params()
1908 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1912 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1914 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1917 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1920 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1933 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1934 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1949 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1951 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1955 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1963 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1965 struct device *dev = dwc->dev; in dwc3_get_extcon()
2013 static int dwc3_get_clocks(struct dwc3 *dwc) in dwc3_get_clocks() argument
2015 struct device *dev = dwc->dev; in dwc3_get_clocks()
2026 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
2027 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2028 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2032 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
2033 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
2034 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2035 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2040 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
2041 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2042 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2046 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
2047 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
2048 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2049 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2054 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
2055 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2056 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2060 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
2061 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
2062 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2063 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2069 dwc->utmi_clk = devm_clk_get_optional(dev, "utmi"); in dwc3_get_clocks()
2070 if (IS_ERR(dwc->utmi_clk)) { in dwc3_get_clocks()
2071 return dev_err_probe(dev, PTR_ERR(dwc->utmi_clk), in dwc3_get_clocks()
2076 dwc->pipe_clk = devm_clk_get_optional(dev, "pipe"); in dwc3_get_clocks()
2077 if (IS_ERR(dwc->pipe_clk)) { in dwc3_get_clocks()
2078 return dev_err_probe(dev, PTR_ERR(dwc->pipe_clk), in dwc3_get_clocks()
2085 static int dwc3_get_num_ports(struct dwc3 *dwc) in dwc3_get_num_ports() argument
2096 base = ioremap(dwc->xhci_resources[0].start, in dwc3_get_num_ports()
2097 resource_size(&dwc->xhci_resources[0])); in dwc3_get_num_ports()
2113 dwc->num_usb3_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2115 dwc->num_usb2_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2117 dev_warn(dwc->dev, "unrecognized port major revision %d\n", in dwc3_get_num_ports()
2122 dev_dbg(dwc->dev, "hs-ports: %u ss-ports: %u\n", in dwc3_get_num_ports()
2123 dwc->num_usb2_ports, dwc->num_usb3_ports); in dwc3_get_num_ports()
2127 if (dwc->num_usb2_ports > DWC3_USB2_MAX_PORTS || in dwc3_get_num_ports()
2128 dwc->num_usb3_ports > DWC3_USB3_MAX_PORTS) in dwc3_get_num_ports()
2134 static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc) in dwc3_get_usb_power_supply() argument
2140 ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name); in dwc3_get_usb_power_supply()
2157 struct dwc3 *dwc; in dwc3_probe() local
2160 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
2161 if (!dwc) in dwc3_probe()
2164 dwc->dev = dev; in dwc3_probe()
2172 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
2173 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
2175 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
2176 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
2200 dwc->regs = regs; in dwc3_probe()
2201 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
2203 dwc3_get_properties(dwc); in dwc3_probe()
2205 dwc3_get_software_properties(dwc); in dwc3_probe()
2207 dwc->usb_psy = dwc3_get_usb_power_supply(dwc); in dwc3_probe()
2208 if (IS_ERR(dwc->usb_psy)) in dwc3_probe()
2209 return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n"); in dwc3_probe()
2211 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
2212 if (IS_ERR(dwc->reset)) { in dwc3_probe()
2213 ret = PTR_ERR(dwc->reset); in dwc3_probe()
2217 ret = dwc3_get_clocks(dwc); in dwc3_probe()
2221 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
2225 ret = dwc3_clk_enable(dwc); in dwc3_probe()
2229 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
2230 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
2235 platform_set_drvdata(pdev, dwc); in dwc3_probe()
2236 dwc3_cache_hwparams(dwc); in dwc3_probe()
2238 if (!dwc->sysdev_is_parent && in dwc3_probe()
2239 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
2240 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
2249 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_probe()
2251 ret = dwc3_get_num_ports(dwc); in dwc3_probe()
2255 dwc->num_usb2_ports = 1; in dwc3_probe()
2256 dwc->num_usb3_ports = 1; in dwc3_probe()
2259 spin_lock_init(&dwc->lock); in dwc3_probe()
2260 mutex_init(&dwc->mutex); in dwc3_probe()
2270 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
2272 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
2277 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
2278 if (IS_ERR(dwc->edev)) { in dwc3_probe()
2279 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
2283 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
2287 ret = dwc3_core_init(dwc); in dwc3_probe()
2293 dwc3_check_params(dwc); in dwc3_probe()
2294 dwc3_debugfs_init(dwc); in dwc3_probe()
2296 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
2307 dwc3_debugfs_exit(dwc); in dwc3_probe()
2308 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
2309 dwc3_phy_power_off(dwc); in dwc3_probe()
2310 dwc3_phy_exit(dwc); in dwc3_probe()
2311 dwc3_ulpi_exit(dwc); in dwc3_probe()
2313 dwc3_free_event_buffers(dwc); in dwc3_probe()
2321 dwc3_clk_disable(dwc); in dwc3_probe()
2323 reset_control_assert(dwc->reset); in dwc3_probe()
2325 if (dwc->usb_psy) in dwc3_probe()
2326 power_supply_put(dwc->usb_psy); in dwc3_probe()
2333 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
2337 dwc3_core_exit_mode(dwc); in dwc3_remove()
2338 dwc3_debugfs_exit(dwc); in dwc3_remove()
2340 dwc3_core_exit(dwc); in dwc3_remove()
2341 dwc3_ulpi_exit(dwc); in dwc3_remove()
2354 dwc3_free_event_buffers(dwc); in dwc3_remove()
2356 if (dwc->usb_psy) in dwc3_remove()
2357 power_supply_put(dwc->usb_psy); in dwc3_remove()
2361 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
2365 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2369 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
2373 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
2380 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
2382 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2387 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2392 if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) { in dwc3_suspend_common()
2393 dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) & in dwc3_suspend_common()
2395 (dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)) & in dwc3_suspend_common()
2401 if (!dwc->susphy_state) in dwc3_suspend_common()
2402 dwc3_enable_susphy(dwc, true); in dwc3_suspend_common()
2405 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2407 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2409 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2410 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2411 dwc3_core_exit(dwc); in dwc3_suspend_common()
2414 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2415 dwc3_core_exit(dwc); in dwc3_suspend_common()
2420 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2421 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2422 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_suspend_common()
2423 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_suspend_common()
2426 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_suspend_common()
2433 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_suspend_common()
2434 phy_pm_runtime_put_sync(dwc->usb2_generic_phy[i]); in dwc3_suspend_common()
2435 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_suspend_common()
2436 phy_pm_runtime_put_sync(dwc->usb3_generic_phy[i]); in dwc3_suspend_common()
2443 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2444 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2445 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2448 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2449 dwc3_core_exit(dwc); in dwc3_suspend_common()
2459 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2465 switch (dwc->current_dr_role) { in dwc3_resume_common()
2467 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2471 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, true); in dwc3_resume_common()
2472 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2475 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2476 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2479 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, true); in dwc3_resume_common()
2483 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_resume_common()
2484 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_resume_common()
2485 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2488 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2491 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_resume_common()
2494 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_resume_common()
2495 phy_pm_runtime_get_sync(dwc->usb2_generic_phy[i]); in dwc3_resume_common()
2496 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_resume_common()
2497 phy_pm_runtime_get_sync(dwc->usb3_generic_phy[i]); in dwc3_resume_common()
2504 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2508 dwc3_set_prtcap(dwc, dwc->current_dr_role, true); in dwc3_resume_common()
2510 dwc3_otg_init(dwc); in dwc3_resume_common()
2511 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2512 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2513 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2514 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2525 dwc3_enable_susphy(dwc, dwc->susphy_state); in dwc3_resume_common()
2531 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2533 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2535 if (dwc->connected) in dwc3_runtime_checks()
2549 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
2552 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2555 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2564 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
2567 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2571 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2573 if (dwc->pending_events) { in dwc3_runtime_resume()
2574 pm_runtime_put(dwc->dev); in dwc3_runtime_resume()
2575 dwc->pending_events = false; in dwc3_runtime_resume()
2576 enable_irq(dwc->irq_gadget); in dwc3_runtime_resume()
2592 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
2594 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2596 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2615 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
2618 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
2629 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
2639 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
2651 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
2654 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2655 dwc->dis_split_quirk) { in dwc3_complete()
2656 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2658 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()