Lines Matching full:dwc
51 * @dwc: pointer to our context structure
53 static int dwc3_get_dr_mode(struct dwc3 *dwc) in dwc3_get_dr_mode() argument
56 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
59 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
60 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
62 mode = dwc->dr_mode; in dwc3_get_dr_mode()
63 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
93 if (mode == USB_DR_MODE_OTG && !dwc->edev && in dwc3_get_dr_mode()
95 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
100 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
105 dwc->dr_mode = mode; in dwc3_get_dr_mode()
111 void dwc3_enable_susphy(struct dwc3 *dwc, bool enable) in dwc3_enable_susphy() argument
116 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_enable_susphy()
117 reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(i)); in dwc3_enable_susphy()
118 if (enable && !dwc->dis_u3_susphy_quirk) in dwc3_enable_susphy()
123 dwc3_writel(dwc, DWC3_GUSB3PIPECTL(i), reg); in dwc3_enable_susphy()
126 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_enable_susphy()
127 reg = dwc3_readl(dwc, DWC3_GUSB2PHYCFG(i)); in dwc3_enable_susphy()
128 if (enable && !dwc->dis_u2_susphy_quirk) in dwc3_enable_susphy()
133 dwc3_writel(dwc, DWC3_GUSB2PHYCFG(i), reg); in dwc3_enable_susphy()
138 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy) in dwc3_set_prtcap() argument
143 reg = dwc3_readl(dwc, DWC3_GCTL); in dwc3_set_prtcap()
150 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_set_prtcap()
153 dwc3_enable_susphy(dwc, false); in dwc3_set_prtcap()
158 dwc3_writel(dwc, DWC3_GCTL, reg); in dwc3_set_prtcap()
160 dwc->current_dr_role = mode; in dwc3_set_prtcap()
161 trace_dwc3_set_prtcap(dwc, mode); in dwc3_set_prtcap()
167 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
174 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
175 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
176 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
177 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
179 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
181 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
182 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
187 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
190 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
193 switch (dwc->current_dr_role) { in __dwc3_set_mode()
195 dwc3_host_exit(dwc); in __dwc3_set_mode()
198 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
199 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
202 dwc3_otg_exit(dwc); in __dwc3_set_mode()
203 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
204 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
205 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
206 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
216 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
219 reg = dwc3_readl(dwc, DWC3_GCTL); in __dwc3_set_mode()
221 dwc3_writel(dwc, DWC3_GCTL, reg); in __dwc3_set_mode()
231 reg = dwc3_readl(dwc, DWC3_GCTL); in __dwc3_set_mode()
233 dwc3_writel(dwc, DWC3_GCTL, reg); in __dwc3_set_mode()
236 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
238 dwc3_set_prtcap(dwc, desired_dr_role, false); in __dwc3_set_mode()
240 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
244 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
246 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
248 if (dwc->usb2_phy) in __dwc3_set_mode()
249 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
251 for (i = 0; i < dwc->num_usb2_ports; i++) in __dwc3_set_mode()
252 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
253 for (i = 0; i < dwc->num_usb3_ports; i++) in __dwc3_set_mode()
254 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
256 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
257 reg = dwc3_readl(dwc, DWC3_GUCTL3); in __dwc3_set_mode()
259 dwc3_writel(dwc, DWC3_GUCTL3, reg); in __dwc3_set_mode()
264 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
266 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
268 if (dwc->usb2_phy) in __dwc3_set_mode()
269 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
270 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
271 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
273 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
275 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
278 dwc3_otg_init(dwc); in __dwc3_set_mode()
279 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
286 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
287 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
290 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
294 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
297 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
298 dwc->desired_dr_role = mode; in dwc3_set_mode()
299 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
301 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
306 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
309 dwc3_writel(dwc, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
313 reg = dwc3_readl(dwc, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
320 * @dwc: pointer to our context structure
322 int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
332 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
335 reg = dwc3_readl(dwc, DWC3_DCTL); in dwc3_core_soft_reset()
338 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_core_soft_reset()
350 reg = dwc3_readl(dwc, DWC3_DCTL); in dwc3_core_soft_reset()
360 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
379 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
387 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
390 reg = dwc3_readl(dwc, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
392 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
394 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
395 dwc3_writel(dwc, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
405 * @dwc: Pointer to our controller context structure
407 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
415 if (dwc->ref_clk) { in dwc3_ref_clk_period()
416 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
420 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
421 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
427 reg = dwc3_readl(dwc, DWC3_GUCTL); in dwc3_ref_clk_period()
430 dwc3_writel(dwc, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
458 reg = dwc3_readl(dwc, DWC3_GFLADJ); in dwc3_ref_clk_period()
466 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
469 dwc3_writel(dwc, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
474 * @dwc: Pointer to our controller context structure
477 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
480 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
485 * @dwc: Pointer to our controller context structure
491 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
496 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
500 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
502 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
506 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
516 * @dwc: Pointer to our controller context structure
518 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
522 evt = dwc->ev_buf; in dwc3_free_event_buffers()
524 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
529 * @dwc: pointer to our controller context structure
532 * Returns 0 on success otherwise negative errno. In the error case, dwc
535 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
540 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_alloc_event_buffers()
542 dwc->ev_buf = NULL; in dwc3_alloc_event_buffers()
546 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
548 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
551 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
558 * @dwc: pointer to our controller context structure
562 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
567 if (!dwc->ev_buf) in dwc3_event_buffers_setup()
570 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
572 dwc3_writel(dwc, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
574 dwc3_writel(dwc, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
576 dwc3_writel(dwc, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
580 reg = dwc3_readl(dwc, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_setup()
581 dwc3_writel(dwc, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_setup()
585 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
590 if (!dwc->ev_buf) in dwc3_event_buffers_cleanup()
596 reg = dwc3_readl(dwc, DWC3_DSTS); in dwc3_event_buffers_cleanup()
600 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
604 dwc3_writel(dwc, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
605 dwc3_writel(dwc, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
606 dwc3_writel(dwc, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
610 reg = dwc3_readl(dwc, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_cleanup()
611 dwc3_writel(dwc, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_cleanup()
614 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
616 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
618 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
621 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
623 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
625 parms->hwparams0 = dwc3_readl(dwc, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
626 parms->hwparams1 = dwc3_readl(dwc, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
627 parms->hwparams2 = dwc3_readl(dwc, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
628 parms->hwparams3 = dwc3_readl(dwc, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
629 parms->hwparams4 = dwc3_readl(dwc, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
630 parms->hwparams5 = dwc3_readl(dwc, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
631 parms->hwparams6 = dwc3_readl(dwc, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
632 parms->hwparams7 = dwc3_readl(dwc, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
633 parms->hwparams8 = dwc3_readl(dwc, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
636 parms->hwparams9 = dwc3_readl(dwc, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
639 static void dwc3_config_soc_bus(struct dwc3 *dwc) in dwc3_config_soc_bus() argument
641 if (dwc->gsbuscfg0_reqinfo != DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED) { in dwc3_config_soc_bus()
644 reg = dwc3_readl(dwc, DWC3_GSBUSCFG0); in dwc3_config_soc_bus()
646 reg |= DWC3_GSBUSCFG0_REQINFO(dwc->gsbuscfg0_reqinfo); in dwc3_config_soc_bus()
647 dwc3_writel(dwc, DWC3_GSBUSCFG0, reg); in dwc3_config_soc_bus()
651 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
656 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
660 dwc->hsphy_interface && in dwc3_core_ulpi_init()
661 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
662 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
667 static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index) in dwc3_ss_phy_setup() argument
671 reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(index)); in dwc3_ss_phy_setup()
682 if (dwc->u2ss_inp3_quirk) in dwc3_ss_phy_setup()
685 if (dwc->dis_rxdet_inp3_quirk) in dwc3_ss_phy_setup()
688 if (dwc->req_p1p2p3_quirk) in dwc3_ss_phy_setup()
691 if (dwc->del_p1p2p3_quirk) in dwc3_ss_phy_setup()
694 if (dwc->del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
697 if (dwc->lfps_filter_quirk) in dwc3_ss_phy_setup()
700 if (dwc->rx_detect_poll_quirk) in dwc3_ss_phy_setup()
703 if (dwc->tx_de_emphasis_quirk) in dwc3_ss_phy_setup()
704 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_ss_phy_setup()
706 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
709 dwc3_writel(dwc, DWC3_GUSB3PIPECTL(index), reg); in dwc3_ss_phy_setup()
714 static int dwc3_hs_phy_setup(struct dwc3 *dwc, int index) in dwc3_hs_phy_setup() argument
718 reg = dwc3_readl(dwc, DWC3_GUSB2PHYCFG(index)); in dwc3_hs_phy_setup()
721 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_hs_phy_setup()
723 if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
724 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_hs_phy_setup()
727 } else if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
728 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_hs_phy_setup()
730 dwc3_writel(dwc, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
742 switch (dwc->hsphy_mode) { in dwc3_hs_phy_setup()
762 if (dwc->dis_enblslpm_quirk) in dwc3_hs_phy_setup()
767 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_hs_phy_setup()
777 if (dwc->ulpi_ext_vbus_drv) in dwc3_hs_phy_setup()
780 dwc3_writel(dwc, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
787 * @dwc: Pointer to our controller context structure
793 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
798 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_phy_setup()
799 ret = dwc3_ss_phy_setup(dwc, i); in dwc3_phy_setup()
804 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_setup()
805 ret = dwc3_hs_phy_setup(dwc, i); in dwc3_phy_setup()
813 static int dwc3_phy_init(struct dwc3 *dwc) in dwc3_phy_init() argument
819 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
820 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
822 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_init()
823 ret = phy_init(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
828 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_init()
829 ret = phy_init(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
851 dwc3_enable_susphy(dwc, true); in dwc3_phy_init()
857 phy_exit(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
861 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
863 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
864 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
869 static void dwc3_phy_exit(struct dwc3 *dwc) in dwc3_phy_exit() argument
873 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_exit()
874 phy_exit(dwc->usb3_generic_phy[i]); in dwc3_phy_exit()
876 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_exit()
877 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_exit()
879 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
880 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
883 static int dwc3_phy_power_on(struct dwc3 *dwc) in dwc3_phy_power_on() argument
889 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
890 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
892 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_power_on()
893 ret = phy_power_on(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
898 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_power_on()
899 ret = phy_power_on(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
908 phy_power_off(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
912 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
914 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
915 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
920 static void dwc3_phy_power_off(struct dwc3 *dwc) in dwc3_phy_power_off() argument
924 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_power_off()
925 phy_power_off(dwc->usb3_generic_phy[i]); in dwc3_phy_power_off()
927 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_power_off()
928 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_off()
930 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
931 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
934 static int dwc3_clk_enable(struct dwc3 *dwc) in dwc3_clk_enable() argument
938 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
942 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
946 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
950 ret = clk_prepare_enable(dwc->utmi_clk); in dwc3_clk_enable()
954 ret = clk_prepare_enable(dwc->pipe_clk); in dwc3_clk_enable()
961 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_enable()
963 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_enable()
965 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
967 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
971 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
973 clk_disable_unprepare(dwc->pipe_clk); in dwc3_clk_disable()
974 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_disable()
975 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
976 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
977 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
980 void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
982 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
983 dwc3_phy_power_off(dwc); in dwc3_core_exit()
984 dwc3_phy_exit(dwc); in dwc3_core_exit()
985 dwc3_clk_disable(dwc); in dwc3_core_exit()
986 reset_control_assert(dwc->reset); in dwc3_core_exit()
990 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
994 reg = dwc3_readl(dwc, DWC3_GSNPSID); in dwc3_core_is_valid()
995 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
996 if (dwc->ip == DWC4_IP) in dwc3_core_is_valid()
997 dwc->ip = DWC32_IP; in dwc3_core_is_valid()
1001 dwc->revision = reg; in dwc3_core_is_valid()
1003 dwc->revision = dwc3_readl(dwc, DWC3_VER_NUMBER); in dwc3_core_is_valid()
1004 dwc->version_type = dwc3_readl(dwc, DWC3_VER_TYPE); in dwc3_core_is_valid()
1012 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
1018 reg = dwc3_readl(dwc, DWC3_GCTL); in dwc3_core_setup_global_control()
1020 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_setup_global_control()
1021 power_opt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_core_setup_global_control()
1037 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
1038 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
1071 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
1072 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
1073 dwc->is_fpga = true; in dwc3_core_setup_global_control()
1076 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
1079 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
1084 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
1096 dwc3_writel(dwc, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
1099 static int dwc3_core_get_phy(struct dwc3 *dwc);
1100 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
1103 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
1105 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
1116 cfg = dwc3_readl(dwc, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1191 dwc3_writel(dwc, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1194 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1199 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1215 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1216 reg = dwc3_readl(dwc, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1221 dwc3_writel(dwc, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1225 static void dwc3_config_threshold(struct dwc3 *dwc) in dwc3_config_threshold() argument
1237 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1238 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1239 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1240 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1241 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1244 reg = dwc3_readl(dwc, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1253 dwc3_writel(dwc, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1257 reg = dwc3_readl(dwc, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1266 dwc3_writel(dwc, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1270 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1271 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1272 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1273 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1277 reg = dwc3_readl(dwc, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1286 dwc3_writel(dwc, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1290 reg = dwc3_readl(dwc, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1299 dwc3_writel(dwc, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1303 reg = dwc3_readl(dwc, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1312 dwc3_writel(dwc, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1316 reg = dwc3_readl(dwc, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1325 dwc3_writel(dwc, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1332 * @dwc: Pointer to our controller context structure
1336 int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1342 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1348 dwc3_writel(dwc, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1350 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1354 if (!dwc->ulpi_ready) { in dwc3_core_init()
1355 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1358 dwc3_core_soft_reset(dwc); in dwc3_core_init()
1363 dwc->ulpi_ready = true; in dwc3_core_init()
1366 if (!dwc->phys_ready) { in dwc3_core_init()
1367 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1370 dwc->phys_ready = true; in dwc3_core_init()
1373 ret = dwc3_phy_init(dwc); in dwc3_core_init()
1377 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1381 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1382 dwc3_core_num_eps(dwc); in dwc3_core_init()
1385 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1388 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1391 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1393 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1395 dwc3_config_soc_bus(dwc); in dwc3_core_init()
1397 ret = dwc3_phy_power_on(dwc); in dwc3_core_init()
1401 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1403 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1413 reg = dwc3_readl(dwc, DWC3_GUCTL2); in dwc3_core_init()
1415 dwc3_writel(dwc, DWC3_GUCTL2, reg); in dwc3_core_init()
1428 reg = dwc3_readl(dwc, DWC3_GUCTL2); in dwc3_core_init()
1430 dwc3_writel(dwc, DWC3_GUCTL2, reg); in dwc3_core_init()
1442 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1443 reg = dwc3_readl(dwc, DWC3_GUCTL1); in dwc3_core_init()
1445 dwc3_writel(dwc, DWC3_GUCTL1, reg); in dwc3_core_init()
1449 reg = dwc3_readl(dwc, DWC3_GUCTL1); in dwc3_core_init()
1467 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1470 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1473 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1477 if (dwc->maximum_speed == USB_SPEED_FULL || in dwc3_core_init()
1478 dwc->maximum_speed == USB_SPEED_HIGH) in dwc3_core_init()
1484 dwc3_writel(dwc, DWC3_GUCTL1, reg); in dwc3_core_init()
1487 dwc3_config_threshold(dwc); in dwc3_core_init()
1491 dwc->maximum_speed == USB_SPEED_SUPER) { in dwc3_core_init()
1494 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_init()
1495 reg = dwc3_readl(dwc, DWC3_LLUCTL(i)); in dwc3_core_init()
1497 dwc3_writel(dwc, DWC3_LLUCTL(i), reg); in dwc3_core_init()
1516 reg = dwc3_readl(dwc, DWC3_GUCTL3); in dwc3_core_init()
1518 dwc3_writel(dwc, DWC3_GUCTL3, reg); in dwc3_core_init()
1524 dwc3_phy_power_off(dwc); in dwc3_core_init()
1526 dwc3_phy_exit(dwc); in dwc3_core_init()
1528 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1534 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1536 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1543 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1544 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1546 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1547 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1550 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1551 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1553 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1558 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1559 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1561 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1566 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_core_get_phy()
1567 if (dwc->num_usb2_ports == 1) in dwc3_core_get_phy()
1572 dwc->usb2_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1573 if (IS_ERR(dwc->usb2_generic_phy[i])) { in dwc3_core_get_phy()
1574 ret = PTR_ERR(dwc->usb2_generic_phy[i]); in dwc3_core_get_phy()
1576 dwc->usb2_generic_phy[i] = NULL; in dwc3_core_get_phy()
1583 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_get_phy()
1584 if (dwc->num_usb3_ports == 1) in dwc3_core_get_phy()
1589 dwc->usb3_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1590 if (IS_ERR(dwc->usb3_generic_phy[i])) { in dwc3_core_get_phy()
1591 ret = PTR_ERR(dwc->usb3_generic_phy[i]); in dwc3_core_get_phy()
1593 dwc->usb3_generic_phy[i] = NULL; in dwc3_core_get_phy()
1603 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1605 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1609 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1611 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, false); in dwc3_core_init_mode()
1613 if (dwc->usb2_phy) in dwc3_core_init_mode()
1614 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1615 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1616 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1618 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1623 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, false); in dwc3_core_init_mode()
1625 if (dwc->usb2_phy) in dwc3_core_init_mode()
1626 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1627 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_core_init_mode()
1628 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1629 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_core_init_mode()
1630 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1632 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1637 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1638 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1643 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1650 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1652 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1654 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1657 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1660 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1668 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, true); in dwc3_core_exit_mode()
1671 static void dwc3_get_software_properties(struct dwc3 *dwc, in dwc3_get_software_properties() argument
1678 dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED; in dwc3_get_software_properties()
1682 dwc->gsbuscfg0_reqinfo = properties->gsbuscfg0_reqinfo; in dwc3_get_software_properties()
1690 for (tmpdev = dwc->dev; tmpdev; tmpdev = tmpdev->parent) { in dwc3_get_software_properties()
1695 dwc->gsbuscfg0_reqinfo = gsbuscfg0_reqinfo; in dwc3_get_software_properties()
1699 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1701 struct device *dev = dwc->dev; in dwc3_get_properties()
1738 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1739 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1740 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1741 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1743 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1745 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1746 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1748 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1750 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); in dwc3_get_properties()
1752 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1756 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1760 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1762 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1764 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1766 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1790 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1792 if (dwc->do_fifo_resize) in dwc3_get_properties()
1796 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1798 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1800 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1802 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1804 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1806 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1808 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1810 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1812 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1814 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1816 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1818 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1820 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1822 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1824 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1826 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1828 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1830 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1832 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1834 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1836 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1838 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1841 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1846 &dwc->hsphy_interface); in dwc3_get_properties()
1848 &dwc->fladj); in dwc3_get_properties()
1850 &dwc->ref_clk_per); in dwc3_get_properties()
1852 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1855 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1858 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1859 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1861 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1863 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1864 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1866 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1867 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1869 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1870 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1872 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1873 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1875 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1877 dwc->num_hc_interrupters = num_hc_interrupters; in dwc3_get_properties()
1881 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1888 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1890 struct device *dev = dwc->dev; in dwc3_check_params()
1892 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1906 if (dwc3_has_imod((dwc))) in dwc3_check_params()
1907 dwc->imod_interval = 1; in dwc3_check_params()
1910 switch (dwc->maximum_speed) { in dwc3_check_params()
1927 dwc->maximum_speed); in dwc3_check_params()
1932 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1936 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1938 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1941 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1944 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1957 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1958 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1973 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1975 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1979 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1987 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1989 struct device *dev = dwc->dev; in dwc3_get_extcon()
2037 static int dwc3_get_clocks(struct dwc3 *dwc) in dwc3_get_clocks() argument
2039 struct device *dev = dwc->dev; in dwc3_get_clocks()
2050 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
2051 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2052 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2056 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
2057 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
2058 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2059 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2064 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
2065 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2066 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2070 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
2071 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
2072 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2073 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2078 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
2079 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2080 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2084 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
2085 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
2086 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2087 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2093 dwc->utmi_clk = devm_clk_get_optional(dev, "utmi"); in dwc3_get_clocks()
2094 if (IS_ERR(dwc->utmi_clk)) { in dwc3_get_clocks()
2095 return dev_err_probe(dev, PTR_ERR(dwc->utmi_clk), in dwc3_get_clocks()
2100 dwc->pipe_clk = devm_clk_get_optional(dev, "pipe"); in dwc3_get_clocks()
2101 if (IS_ERR(dwc->pipe_clk)) { in dwc3_get_clocks()
2102 return dev_err_probe(dev, PTR_ERR(dwc->pipe_clk), in dwc3_get_clocks()
2109 static int dwc3_get_num_ports(struct dwc3 *dwc) in dwc3_get_num_ports() argument
2120 base = ioremap(dwc->xhci_resources[0].start, in dwc3_get_num_ports()
2121 resource_size(&dwc->xhci_resources[0])); in dwc3_get_num_ports()
2137 dwc->num_usb3_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2139 dwc->num_usb2_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2141 dev_warn(dwc->dev, "unrecognized port major revision %d\n", in dwc3_get_num_ports()
2146 dev_dbg(dwc->dev, "hs-ports: %u ss-ports: %u\n", in dwc3_get_num_ports()
2147 dwc->num_usb2_ports, dwc->num_usb3_ports); in dwc3_get_num_ports()
2151 if (dwc->num_usb2_ports > DWC3_USB2_MAX_PORTS || in dwc3_get_num_ports()
2152 dwc->num_usb3_ports > DWC3_USB3_MAX_PORTS) in dwc3_get_num_ports()
2160 struct dwc3 *dwc = container_of(work, struct dwc3, vbus_draw_work); in dwc3_vbus_draw_work() local
2164 val.intval = 1000 * (dwc->current_limit); in dwc3_vbus_draw_work()
2165 ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); in dwc3_vbus_draw_work()
2168 dev_dbg(dwc->dev, "Error (%d) setting vbus draw (%d mA)\n", in dwc3_vbus_draw_work()
2169 ret, dwc->current_limit); in dwc3_vbus_draw_work()
2172 static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc) in dwc3_get_usb_power_supply() argument
2178 ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name); in dwc3_get_usb_power_supply()
2186 INIT_WORK(&dwc->vbus_draw_work, dwc3_vbus_draw_work); in dwc3_get_usb_power_supply()
2192 struct dwc3 *dwc = data->dwc; in dwc3_core_probe() local
2193 struct device *dev = dwc->dev; in dwc3_core_probe()
2200 dwc->xhci_resources[0].start = res->start; in dwc3_core_probe()
2201 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_core_probe()
2203 dwc->xhci_resources[0].flags = res->flags; in dwc3_core_probe()
2204 dwc->xhci_resources[0].name = res->name; in dwc3_core_probe()
2228 dwc->regs = regs; in dwc3_core_probe()
2229 dwc->regs_size = resource_size(&dwc_res); in dwc3_core_probe()
2231 dwc3_get_properties(dwc); in dwc3_core_probe()
2233 dwc3_get_software_properties(dwc, &data->properties); in dwc3_core_probe()
2235 dwc->usb_psy = dwc3_get_usb_power_supply(dwc); in dwc3_core_probe()
2236 if (IS_ERR(dwc->usb_psy)) in dwc3_core_probe()
2237 return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n"); in dwc3_core_probe()
2240 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_core_probe()
2241 if (IS_ERR(dwc->reset)) { in dwc3_core_probe()
2242 ret = PTR_ERR(dwc->reset); in dwc3_core_probe()
2246 ret = dwc3_get_clocks(dwc); in dwc3_core_probe()
2251 ret = reset_control_deassert(dwc->reset); in dwc3_core_probe()
2255 ret = dwc3_clk_enable(dwc); in dwc3_core_probe()
2259 if (!dwc3_core_is_valid(dwc)) { in dwc3_core_probe()
2260 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_core_probe()
2265 dev_set_drvdata(dev, dwc); in dwc3_core_probe()
2266 dwc3_cache_hwparams(dwc); in dwc3_core_probe()
2268 if (!dev_is_pci(dwc->sysdev) && in dwc3_core_probe()
2269 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_core_probe()
2270 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_core_probe()
2279 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_probe()
2281 ret = dwc3_get_num_ports(dwc); in dwc3_core_probe()
2285 dwc->num_usb2_ports = 1; in dwc3_core_probe()
2286 dwc->num_usb3_ports = 1; in dwc3_core_probe()
2289 spin_lock_init(&dwc->lock); in dwc3_core_probe()
2290 mutex_init(&dwc->mutex); in dwc3_core_probe()
2300 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_core_probe()
2302 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_core_probe()
2307 dwc->edev = dwc3_get_extcon(dwc); in dwc3_core_probe()
2308 if (IS_ERR(dwc->edev)) { in dwc3_core_probe()
2309 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_core_probe()
2313 ret = dwc3_get_dr_mode(dwc); in dwc3_core_probe()
2317 ret = dwc3_core_init(dwc); in dwc3_core_probe()
2323 dwc3_check_params(dwc); in dwc3_core_probe()
2324 dwc3_debugfs_init(dwc); in dwc3_core_probe()
2327 ret = dwc3_core_init_mode(dwc); in dwc3_core_probe()
2339 dwc3_debugfs_exit(dwc); in dwc3_core_probe()
2340 dwc3_event_buffers_cleanup(dwc); in dwc3_core_probe()
2341 dwc3_phy_power_off(dwc); in dwc3_core_probe()
2342 dwc3_phy_exit(dwc); in dwc3_core_probe()
2343 dwc3_ulpi_exit(dwc); in dwc3_core_probe()
2345 dwc3_free_event_buffers(dwc); in dwc3_core_probe()
2353 dwc3_clk_disable(dwc); in dwc3_core_probe()
2355 reset_control_assert(dwc->reset); in dwc3_core_probe()
2357 if (dwc->usb_psy) in dwc3_core_probe()
2358 power_supply_put(dwc->usb_psy); in dwc3_core_probe()
2368 struct dwc3 *dwc; in dwc3_probe() local
2376 dwc = devm_kzalloc(&pdev->dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
2377 if (!dwc) in dwc3_probe()
2380 dwc->dev = &pdev->dev; in dwc3_probe()
2381 dwc->glue_ops = NULL; in dwc3_probe()
2383 probe_data.dwc = dwc; in dwc3_probe()
2390 void dwc3_core_remove(struct dwc3 *dwc) in dwc3_core_remove() argument
2392 pm_runtime_get_sync(dwc->dev); in dwc3_core_remove()
2394 dwc3_core_exit_mode(dwc); in dwc3_core_remove()
2395 dwc3_debugfs_exit(dwc); in dwc3_core_remove()
2397 dwc3_core_exit(dwc); in dwc3_core_remove()
2398 dwc3_ulpi_exit(dwc); in dwc3_core_remove()
2400 pm_runtime_allow(dwc->dev); in dwc3_core_remove()
2401 pm_runtime_disable(dwc->dev); in dwc3_core_remove()
2402 pm_runtime_dont_use_autosuspend(dwc->dev); in dwc3_core_remove()
2403 pm_runtime_put_noidle(dwc->dev); in dwc3_core_remove()
2408 dev_set_drvdata(dwc->dev, NULL); in dwc3_core_remove()
2409 pm_runtime_set_suspended(dwc->dev); in dwc3_core_remove()
2411 dwc3_free_event_buffers(dwc); in dwc3_core_remove()
2413 if (dwc->usb_psy) { in dwc3_core_remove()
2414 cancel_work_sync(&dwc->vbus_draw_work); in dwc3_core_remove()
2415 power_supply_put(dwc->usb_psy); in dwc3_core_remove()
2426 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
2430 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2434 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
2438 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
2445 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
2447 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2452 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2458 if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) { in dwc3_suspend_common()
2459 dwc->susphy_state = (dwc3_readl(dwc, DWC3_GUSB2PHYCFG(0)) & in dwc3_suspend_common()
2461 (dwc3_readl(dwc, DWC3_GUSB3PIPECTL(0)) & in dwc3_suspend_common()
2467 if (!dwc->susphy_state) in dwc3_suspend_common()
2468 dwc3_enable_susphy(dwc, true); in dwc3_suspend_common()
2471 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2473 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2475 ret = dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2478 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2479 dwc3_core_exit(dwc); in dwc3_suspend_common()
2482 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2483 dwc3_core_exit(dwc); in dwc3_suspend_common()
2488 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2489 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2490 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_suspend_common()
2491 reg = dwc3_readl(dwc, DWC3_GUSB2PHYCFG(i)); in dwc3_suspend_common()
2494 dwc3_writel(dwc, DWC3_GUSB2PHYCFG(i), reg); in dwc3_suspend_common()
2501 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_suspend_common()
2502 phy_pm_runtime_put_sync(dwc->usb2_generic_phy[i]); in dwc3_suspend_common()
2503 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_suspend_common()
2504 phy_pm_runtime_put_sync(dwc->usb3_generic_phy[i]); in dwc3_suspend_common()
2511 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2512 ret = dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2515 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2518 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2519 dwc3_core_exit(dwc); in dwc3_suspend_common()
2529 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2535 switch (dwc->current_dr_role) { in dwc3_resume_common()
2537 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2541 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, true); in dwc3_resume_common()
2542 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2545 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2546 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2549 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, true); in dwc3_resume_common()
2553 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_resume_common()
2554 reg = dwc3_readl(dwc, DWC3_GUSB2PHYCFG(i)); in dwc3_resume_common()
2555 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2558 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2561 dwc3_writel(dwc, DWC3_GUSB2PHYCFG(i), reg); in dwc3_resume_common()
2564 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_resume_common()
2565 phy_pm_runtime_get_sync(dwc->usb2_generic_phy[i]); in dwc3_resume_common()
2566 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_resume_common()
2567 phy_pm_runtime_get_sync(dwc->usb3_generic_phy[i]); in dwc3_resume_common()
2574 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2578 dwc3_set_prtcap(dwc, dwc->current_dr_role, true); in dwc3_resume_common()
2580 dwc3_otg_init(dwc); in dwc3_resume_common()
2581 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2582 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2583 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2584 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2595 dwc3_enable_susphy(dwc, dwc->susphy_state); in dwc3_resume_common()
2601 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2603 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2605 if (dwc->connected) in dwc3_runtime_checks()
2617 int dwc3_runtime_suspend(struct dwc3 *dwc) in dwc3_runtime_suspend() argument
2621 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2624 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2632 int dwc3_runtime_resume(struct dwc3 *dwc) in dwc3_runtime_resume() argument
2634 struct device *dev = dwc->dev; in dwc3_runtime_resume()
2637 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2641 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2643 if (dwc->pending_events) { in dwc3_runtime_resume()
2645 dwc->pending_events = false; in dwc3_runtime_resume()
2646 enable_irq(dwc->irq_gadget); in dwc3_runtime_resume()
2661 int dwc3_runtime_idle(struct dwc3 *dwc) in dwc3_runtime_idle() argument
2663 struct device *dev = dwc->dev; in dwc3_runtime_idle()
2665 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2667 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2699 int dwc3_pm_suspend(struct dwc3 *dwc) in dwc3_pm_suspend() argument
2701 struct device *dev = dwc->dev; in dwc3_pm_suspend()
2704 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_pm_suspend()
2714 int dwc3_pm_resume(struct dwc3 *dwc) in dwc3_pm_resume() argument
2716 struct device *dev = dwc->dev; in dwc3_pm_resume()
2726 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_pm_resume()
2737 void dwc3_pm_complete(struct dwc3 *dwc) in dwc3_pm_complete() argument
2741 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_pm_complete()
2742 dwc->dis_split_quirk) { in dwc3_pm_complete()
2743 reg = dwc3_readl(dwc, DWC3_GUCTL3); in dwc3_pm_complete()
2745 dwc3_writel(dwc, DWC3_GUCTL3, reg); in dwc3_pm_complete()
2750 int dwc3_pm_prepare(struct dwc3 *dwc) in dwc3_pm_prepare() argument
2752 struct device *dev = dwc->dev; in dwc3_pm_prepare()
2758 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE && in dwc3_pm_prepare()