Lines Matching refs:dwc

52 static int dwc3_get_dr_mode(struct dwc3 *dwc)  in dwc3_get_dr_mode()  argument
55 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
58 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
59 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
61 mode = dwc->dr_mode; in dwc3_get_dr_mode()
62 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
92 if (mode == USB_DR_MODE_OTG && !dwc->edev && in dwc3_get_dr_mode()
94 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
99 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
104 dwc->dr_mode = mode; in dwc3_get_dr_mode()
110 void dwc3_enable_susphy(struct dwc3 *dwc, bool enable) in dwc3_enable_susphy() argument
115 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_enable_susphy()
116 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i)); in dwc3_enable_susphy()
117 if (enable && !dwc->dis_u3_susphy_quirk) in dwc3_enable_susphy()
122 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(i), reg); in dwc3_enable_susphy()
125 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_enable_susphy()
126 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_enable_susphy()
127 if (enable && !dwc->dis_u2_susphy_quirk) in dwc3_enable_susphy()
132 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_enable_susphy()
136 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy) in dwc3_set_prtcap() argument
141 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
148 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_set_prtcap()
151 dwc3_enable_susphy(dwc, false); in dwc3_set_prtcap()
156 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
158 dwc->current_dr_role = mode; in dwc3_set_prtcap()
163 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
170 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
171 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
172 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
173 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
175 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
177 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
178 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
183 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
186 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
189 switch (dwc->current_dr_role) { in __dwc3_set_mode()
191 dwc3_host_exit(dwc); in __dwc3_set_mode()
194 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
195 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
198 dwc3_otg_exit(dwc); in __dwc3_set_mode()
199 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
200 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
201 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
202 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
212 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
215 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
217 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
227 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
229 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
232 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
234 dwc3_set_prtcap(dwc, desired_dr_role, false); in __dwc3_set_mode()
236 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
240 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
242 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
244 if (dwc->usb2_phy) in __dwc3_set_mode()
245 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
247 for (i = 0; i < dwc->num_usb2_ports; i++) in __dwc3_set_mode()
248 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
249 for (i = 0; i < dwc->num_usb3_ports; i++) in __dwc3_set_mode()
250 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
252 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
253 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
255 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
260 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
262 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
264 if (dwc->usb2_phy) in __dwc3_set_mode()
265 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
266 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
267 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
269 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
271 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
274 dwc3_otg_init(dwc); in __dwc3_set_mode()
275 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
282 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
283 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
284 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
287 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
291 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
294 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
295 dwc->desired_dr_role = mode; in dwc3_set_mode()
296 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
298 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
303 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
306 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
310 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
319 int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
329 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
332 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
335 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_core_soft_reset()
347 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
357 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
376 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
384 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
387 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
389 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
391 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
392 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
404 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
412 if (dwc->ref_clk) { in dwc3_ref_clk_period()
413 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
417 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
418 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
424 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
427 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
455 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
463 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
466 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
474 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
477 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
488 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
493 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
497 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
499 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
503 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
515 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
519 evt = dwc->ev_buf; in dwc3_free_event_buffers()
521 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
532 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
537 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_alloc_event_buffers()
539 dwc->ev_buf = NULL; in dwc3_alloc_event_buffers()
543 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
545 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
548 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
559 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
564 if (!dwc->ev_buf) in dwc3_event_buffers_setup()
567 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
569 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
571 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
573 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
577 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_setup()
578 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_setup()
582 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
587 if (!dwc->ev_buf) in dwc3_event_buffers_cleanup()
593 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_event_buffers_cleanup()
597 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
601 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
602 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
603 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
607 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_cleanup()
608 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_cleanup()
611 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
613 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
615 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
618 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
620 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
622 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
623 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
624 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
625 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
626 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
627 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
628 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
629 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
630 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
633 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
636 static void dwc3_config_soc_bus(struct dwc3 *dwc) in dwc3_config_soc_bus() argument
638 if (dwc->gsbuscfg0_reqinfo != DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED) { in dwc3_config_soc_bus()
641 reg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_config_soc_bus()
643 reg |= DWC3_GSBUSCFG0_REQINFO(dwc->gsbuscfg0_reqinfo); in dwc3_config_soc_bus()
644 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, reg); in dwc3_config_soc_bus()
648 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
653 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
657 dwc->hsphy_interface && in dwc3_core_ulpi_init()
658 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
659 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
664 static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index) in dwc3_ss_phy_setup() argument
668 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(index)); in dwc3_ss_phy_setup()
679 if (dwc->u2ss_inp3_quirk) in dwc3_ss_phy_setup()
682 if (dwc->dis_rxdet_inp3_quirk) in dwc3_ss_phy_setup()
685 if (dwc->req_p1p2p3_quirk) in dwc3_ss_phy_setup()
688 if (dwc->del_p1p2p3_quirk) in dwc3_ss_phy_setup()
691 if (dwc->del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
694 if (dwc->lfps_filter_quirk) in dwc3_ss_phy_setup()
697 if (dwc->rx_detect_poll_quirk) in dwc3_ss_phy_setup()
700 if (dwc->tx_de_emphasis_quirk) in dwc3_ss_phy_setup()
701 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_ss_phy_setup()
703 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
706 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(index), reg); in dwc3_ss_phy_setup()
711 static int dwc3_hs_phy_setup(struct dwc3 *dwc, int index) in dwc3_hs_phy_setup() argument
715 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(index)); in dwc3_hs_phy_setup()
718 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_hs_phy_setup()
720 if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
721 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_hs_phy_setup()
724 } else if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
725 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_hs_phy_setup()
727 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
739 switch (dwc->hsphy_mode) { in dwc3_hs_phy_setup()
759 if (dwc->dis_enblslpm_quirk) in dwc3_hs_phy_setup()
764 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_hs_phy_setup()
774 if (dwc->ulpi_ext_vbus_drv) in dwc3_hs_phy_setup()
777 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
790 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
795 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_phy_setup()
796 ret = dwc3_ss_phy_setup(dwc, i); in dwc3_phy_setup()
801 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_setup()
802 ret = dwc3_hs_phy_setup(dwc, i); in dwc3_phy_setup()
810 static int dwc3_phy_init(struct dwc3 *dwc) in dwc3_phy_init() argument
816 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
817 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
819 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_init()
820 ret = phy_init(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
825 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_init()
826 ret = phy_init(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
848 dwc3_enable_susphy(dwc, true); in dwc3_phy_init()
854 phy_exit(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
858 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
860 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
861 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
866 static void dwc3_phy_exit(struct dwc3 *dwc) in dwc3_phy_exit() argument
870 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_exit()
871 phy_exit(dwc->usb3_generic_phy[i]); in dwc3_phy_exit()
873 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_exit()
874 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_exit()
876 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
877 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
880 static int dwc3_phy_power_on(struct dwc3 *dwc) in dwc3_phy_power_on() argument
886 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
887 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
889 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_power_on()
890 ret = phy_power_on(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
895 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_power_on()
896 ret = phy_power_on(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
905 phy_power_off(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
909 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
911 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
912 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
917 static void dwc3_phy_power_off(struct dwc3 *dwc) in dwc3_phy_power_off() argument
921 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_power_off()
922 phy_power_off(dwc->usb3_generic_phy[i]); in dwc3_phy_power_off()
924 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_power_off()
925 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_off()
927 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
928 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
931 static int dwc3_clk_enable(struct dwc3 *dwc) in dwc3_clk_enable() argument
935 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
939 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
943 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
947 ret = clk_prepare_enable(dwc->utmi_clk); in dwc3_clk_enable()
951 ret = clk_prepare_enable(dwc->pipe_clk); in dwc3_clk_enable()
958 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_enable()
960 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_enable()
962 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
964 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
968 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
970 clk_disable_unprepare(dwc->pipe_clk); in dwc3_clk_disable()
971 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_disable()
972 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
973 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
974 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
977 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
979 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
980 dwc3_phy_power_off(dwc); in dwc3_core_exit()
981 dwc3_phy_exit(dwc); in dwc3_core_exit()
982 dwc3_clk_disable(dwc); in dwc3_core_exit()
983 reset_control_assert(dwc->reset); in dwc3_core_exit()
986 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
990 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
991 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
995 dwc->revision = reg; in dwc3_core_is_valid()
997 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
998 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
1006 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
1012 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
1014 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_setup_global_control()
1015 power_opt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_core_setup_global_control()
1031 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
1032 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
1065 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
1066 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
1067 dwc->is_fpga = true; in dwc3_core_setup_global_control()
1070 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
1073 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
1078 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
1090 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
1093 static int dwc3_core_get_phy(struct dwc3 *dwc);
1094 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
1097 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
1099 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
1110 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1185 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1188 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1193 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1209 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1210 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1215 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1219 static void dwc3_config_threshold(struct dwc3 *dwc) in dwc3_config_threshold() argument
1231 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1232 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1233 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1234 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1235 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1238 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1247 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1251 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1260 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1264 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1265 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1266 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1267 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1271 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1280 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1284 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1293 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1297 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1306 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1310 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1319 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1330 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1336 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1342 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1344 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1348 if (!dwc->ulpi_ready) { in dwc3_core_init()
1349 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1352 dwc3_core_soft_reset(dwc); in dwc3_core_init()
1357 dwc->ulpi_ready = true; in dwc3_core_init()
1360 if (!dwc->phys_ready) { in dwc3_core_init()
1361 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1364 dwc->phys_ready = true; in dwc3_core_init()
1367 ret = dwc3_phy_init(dwc); in dwc3_core_init()
1371 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1375 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1376 dwc3_core_num_eps(dwc); in dwc3_core_init()
1379 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1382 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1385 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1387 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1389 dwc3_config_soc_bus(dwc); in dwc3_core_init()
1391 ret = dwc3_phy_power_on(dwc); in dwc3_core_init()
1395 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1397 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1407 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1409 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1422 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1424 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1436 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1437 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1439 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1443 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1461 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1464 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1467 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1471 if (dwc->maximum_speed == USB_SPEED_FULL || in dwc3_core_init()
1472 dwc->maximum_speed == USB_SPEED_HIGH) in dwc3_core_init()
1478 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1481 dwc3_config_threshold(dwc); in dwc3_core_init()
1489 dwc->maximum_speed == USB_SPEED_SUPER) { in dwc3_core_init()
1492 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_init()
1493 reg = dwc3_readl(dwc->regs, DWC3_LLUCTL(i)); in dwc3_core_init()
1495 dwc3_writel(dwc->regs, DWC3_LLUCTL(i), reg); in dwc3_core_init()
1514 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_core_init()
1516 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_core_init()
1522 dwc3_phy_power_off(dwc); in dwc3_core_init()
1524 dwc3_phy_exit(dwc); in dwc3_core_init()
1526 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1531 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1533 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1540 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1541 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1543 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1544 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1547 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1548 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1550 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1555 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1556 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1558 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1563 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_core_get_phy()
1564 if (dwc->num_usb2_ports == 1) in dwc3_core_get_phy()
1569 dwc->usb2_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1570 if (IS_ERR(dwc->usb2_generic_phy[i])) { in dwc3_core_get_phy()
1571 ret = PTR_ERR(dwc->usb2_generic_phy[i]); in dwc3_core_get_phy()
1573 dwc->usb2_generic_phy[i] = NULL; in dwc3_core_get_phy()
1580 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_get_phy()
1581 if (dwc->num_usb3_ports == 1) in dwc3_core_get_phy()
1586 dwc->usb3_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1587 if (IS_ERR(dwc->usb3_generic_phy[i])) { in dwc3_core_get_phy()
1588 ret = PTR_ERR(dwc->usb3_generic_phy[i]); in dwc3_core_get_phy()
1590 dwc->usb3_generic_phy[i] = NULL; in dwc3_core_get_phy()
1600 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1602 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1606 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1608 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, false); in dwc3_core_init_mode()
1610 if (dwc->usb2_phy) in dwc3_core_init_mode()
1611 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1612 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1613 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1615 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1620 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, false); in dwc3_core_init_mode()
1622 if (dwc->usb2_phy) in dwc3_core_init_mode()
1623 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1624 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_core_init_mode()
1625 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1626 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_core_init_mode()
1627 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1629 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1634 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1635 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1640 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1647 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1649 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1651 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1654 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1657 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1665 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, true); in dwc3_core_exit_mode()
1668 static void dwc3_get_software_properties(struct dwc3 *dwc) in dwc3_get_software_properties() argument
1674 dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED; in dwc3_get_software_properties()
1680 for (tmpdev = dwc->dev; tmpdev; tmpdev = tmpdev->parent) { in dwc3_get_software_properties()
1685 dwc->gsbuscfg0_reqinfo = gsbuscfg0_reqinfo; in dwc3_get_software_properties()
1689 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1691 struct device *dev = dwc->dev; in dwc3_get_properties()
1728 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1729 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1730 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1731 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1733 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1735 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1736 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1738 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1740 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); in dwc3_get_properties()
1742 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1746 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1750 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1752 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1754 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1756 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1780 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1782 if (dwc->do_fifo_resize) in dwc3_get_properties()
1786 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1788 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1790 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1792 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1794 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1796 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1798 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1800 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1802 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1804 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1806 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1808 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1810 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1812 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1814 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1816 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1818 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1820 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1822 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1824 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1826 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1828 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1831 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1836 &dwc->hsphy_interface); in dwc3_get_properties()
1838 &dwc->fladj); in dwc3_get_properties()
1840 &dwc->ref_clk_per); in dwc3_get_properties()
1842 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1845 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1848 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1849 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1851 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1853 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1854 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1856 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1857 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1859 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1860 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1862 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1863 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1865 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1867 dwc->num_hc_interrupters = num_hc_interrupters; in dwc3_get_properties()
1871 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1878 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1880 struct device *dev = dwc->dev; in dwc3_check_params()
1882 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1896 if (dwc3_has_imod((dwc))) in dwc3_check_params()
1897 dwc->imod_interval = 1; in dwc3_check_params()
1900 switch (dwc->maximum_speed) { in dwc3_check_params()
1917 dwc->maximum_speed); in dwc3_check_params()
1922 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1926 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1928 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1931 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1934 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1947 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1948 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1963 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1965 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1969 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1977 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1979 struct device *dev = dwc->dev; in dwc3_get_extcon()
2027 static int dwc3_get_clocks(struct dwc3 *dwc) in dwc3_get_clocks() argument
2029 struct device *dev = dwc->dev; in dwc3_get_clocks()
2040 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
2041 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2042 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2046 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
2047 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
2048 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2049 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2054 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
2055 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2056 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2060 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
2061 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
2062 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2063 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2068 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
2069 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2070 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2074 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
2075 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
2076 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2077 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2083 dwc->utmi_clk = devm_clk_get_optional(dev, "utmi"); in dwc3_get_clocks()
2084 if (IS_ERR(dwc->utmi_clk)) { in dwc3_get_clocks()
2085 return dev_err_probe(dev, PTR_ERR(dwc->utmi_clk), in dwc3_get_clocks()
2090 dwc->pipe_clk = devm_clk_get_optional(dev, "pipe"); in dwc3_get_clocks()
2091 if (IS_ERR(dwc->pipe_clk)) { in dwc3_get_clocks()
2092 return dev_err_probe(dev, PTR_ERR(dwc->pipe_clk), in dwc3_get_clocks()
2099 static int dwc3_get_num_ports(struct dwc3 *dwc) in dwc3_get_num_ports() argument
2110 base = ioremap(dwc->xhci_resources[0].start, in dwc3_get_num_ports()
2111 resource_size(&dwc->xhci_resources[0])); in dwc3_get_num_ports()
2127 dwc->num_usb3_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2129 dwc->num_usb2_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2131 dev_warn(dwc->dev, "unrecognized port major revision %d\n", in dwc3_get_num_ports()
2136 dev_dbg(dwc->dev, "hs-ports: %u ss-ports: %u\n", in dwc3_get_num_ports()
2137 dwc->num_usb2_ports, dwc->num_usb3_ports); in dwc3_get_num_ports()
2141 if (dwc->num_usb2_ports > DWC3_USB2_MAX_PORTS || in dwc3_get_num_ports()
2142 dwc->num_usb3_ports > DWC3_USB3_MAX_PORTS) in dwc3_get_num_ports()
2148 static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc) in dwc3_get_usb_power_supply() argument
2154 ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name); in dwc3_get_usb_power_supply()
2167 struct dwc3 *dwc = data->dwc; in dwc3_core_probe() local
2168 struct device *dev = dwc->dev; in dwc3_core_probe()
2175 dwc->xhci_resources[0].start = res->start; in dwc3_core_probe()
2176 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_core_probe()
2178 dwc->xhci_resources[0].flags = res->flags; in dwc3_core_probe()
2179 dwc->xhci_resources[0].name = res->name; in dwc3_core_probe()
2203 dwc->regs = regs; in dwc3_core_probe()
2204 dwc->regs_size = resource_size(&dwc_res); in dwc3_core_probe()
2206 dwc3_get_properties(dwc); in dwc3_core_probe()
2208 dwc3_get_software_properties(dwc); in dwc3_core_probe()
2210 dwc->usb_psy = dwc3_get_usb_power_supply(dwc); in dwc3_core_probe()
2211 if (IS_ERR(dwc->usb_psy)) in dwc3_core_probe()
2212 return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n"); in dwc3_core_probe()
2215 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_core_probe()
2216 if (IS_ERR(dwc->reset)) { in dwc3_core_probe()
2217 ret = PTR_ERR(dwc->reset); in dwc3_core_probe()
2221 ret = dwc3_get_clocks(dwc); in dwc3_core_probe()
2226 ret = reset_control_deassert(dwc->reset); in dwc3_core_probe()
2230 ret = dwc3_clk_enable(dwc); in dwc3_core_probe()
2234 if (!dwc3_core_is_valid(dwc)) { in dwc3_core_probe()
2235 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_core_probe()
2240 dev_set_drvdata(dev, dwc); in dwc3_core_probe()
2241 dwc3_cache_hwparams(dwc); in dwc3_core_probe()
2243 if (!dwc->sysdev_is_parent && in dwc3_core_probe()
2244 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_core_probe()
2245 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_core_probe()
2254 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_probe()
2256 ret = dwc3_get_num_ports(dwc); in dwc3_core_probe()
2260 dwc->num_usb2_ports = 1; in dwc3_core_probe()
2261 dwc->num_usb3_ports = 1; in dwc3_core_probe()
2264 spin_lock_init(&dwc->lock); in dwc3_core_probe()
2265 mutex_init(&dwc->mutex); in dwc3_core_probe()
2275 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_core_probe()
2277 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_core_probe()
2282 dwc->edev = dwc3_get_extcon(dwc); in dwc3_core_probe()
2283 if (IS_ERR(dwc->edev)) { in dwc3_core_probe()
2284 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_core_probe()
2288 ret = dwc3_get_dr_mode(dwc); in dwc3_core_probe()
2292 ret = dwc3_core_init(dwc); in dwc3_core_probe()
2298 dwc3_check_params(dwc); in dwc3_core_probe()
2299 dwc3_debugfs_init(dwc); in dwc3_core_probe()
2301 ret = dwc3_core_init_mode(dwc); in dwc3_core_probe()
2312 dwc3_debugfs_exit(dwc); in dwc3_core_probe()
2313 dwc3_event_buffers_cleanup(dwc); in dwc3_core_probe()
2314 dwc3_phy_power_off(dwc); in dwc3_core_probe()
2315 dwc3_phy_exit(dwc); in dwc3_core_probe()
2316 dwc3_ulpi_exit(dwc); in dwc3_core_probe()
2318 dwc3_free_event_buffers(dwc); in dwc3_core_probe()
2326 dwc3_clk_disable(dwc); in dwc3_core_probe()
2328 reset_control_assert(dwc->reset); in dwc3_core_probe()
2330 if (dwc->usb_psy) in dwc3_core_probe()
2331 power_supply_put(dwc->usb_psy); in dwc3_core_probe()
2341 struct dwc3 *dwc; in dwc3_probe() local
2349 dwc = devm_kzalloc(&pdev->dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
2350 if (!dwc) in dwc3_probe()
2353 dwc->dev = &pdev->dev; in dwc3_probe()
2355 probe_data.dwc = dwc; in dwc3_probe()
2361 void dwc3_core_remove(struct dwc3 *dwc) in dwc3_core_remove() argument
2363 pm_runtime_get_sync(dwc->dev); in dwc3_core_remove()
2365 dwc3_core_exit_mode(dwc); in dwc3_core_remove()
2366 dwc3_debugfs_exit(dwc); in dwc3_core_remove()
2368 dwc3_core_exit(dwc); in dwc3_core_remove()
2369 dwc3_ulpi_exit(dwc); in dwc3_core_remove()
2371 pm_runtime_allow(dwc->dev); in dwc3_core_remove()
2372 pm_runtime_disable(dwc->dev); in dwc3_core_remove()
2373 pm_runtime_dont_use_autosuspend(dwc->dev); in dwc3_core_remove()
2374 pm_runtime_put_noidle(dwc->dev); in dwc3_core_remove()
2379 dev_set_drvdata(dwc->dev, NULL); in dwc3_core_remove()
2380 pm_runtime_set_suspended(dwc->dev); in dwc3_core_remove()
2382 dwc3_free_event_buffers(dwc); in dwc3_core_remove()
2384 if (dwc->usb_psy) in dwc3_core_remove()
2385 power_supply_put(dwc->usb_psy); in dwc3_core_remove()
2395 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
2399 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2403 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
2407 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
2414 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
2416 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2421 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2427 if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) { in dwc3_suspend_common()
2428 dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) & in dwc3_suspend_common()
2430 (dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)) & in dwc3_suspend_common()
2436 if (!dwc->susphy_state) in dwc3_suspend_common()
2437 dwc3_enable_susphy(dwc, true); in dwc3_suspend_common()
2440 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2442 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2444 ret = dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2447 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2448 dwc3_core_exit(dwc); in dwc3_suspend_common()
2451 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2452 dwc3_core_exit(dwc); in dwc3_suspend_common()
2457 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2458 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2459 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_suspend_common()
2460 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_suspend_common()
2463 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_suspend_common()
2470 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_suspend_common()
2471 phy_pm_runtime_put_sync(dwc->usb2_generic_phy[i]); in dwc3_suspend_common()
2472 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_suspend_common()
2473 phy_pm_runtime_put_sync(dwc->usb3_generic_phy[i]); in dwc3_suspend_common()
2480 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2481 ret = dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2484 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2487 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2488 dwc3_core_exit(dwc); in dwc3_suspend_common()
2498 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2504 switch (dwc->current_dr_role) { in dwc3_resume_common()
2506 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2510 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, true); in dwc3_resume_common()
2511 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2514 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2515 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2518 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, true); in dwc3_resume_common()
2522 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_resume_common()
2523 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_resume_common()
2524 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2527 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2530 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_resume_common()
2533 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_resume_common()
2534 phy_pm_runtime_get_sync(dwc->usb2_generic_phy[i]); in dwc3_resume_common()
2535 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_resume_common()
2536 phy_pm_runtime_get_sync(dwc->usb3_generic_phy[i]); in dwc3_resume_common()
2543 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2547 dwc3_set_prtcap(dwc, dwc->current_dr_role, true); in dwc3_resume_common()
2549 dwc3_otg_init(dwc); in dwc3_resume_common()
2550 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2551 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2552 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2553 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2564 dwc3_enable_susphy(dwc, dwc->susphy_state); in dwc3_resume_common()
2570 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2572 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2574 if (dwc->connected) in dwc3_runtime_checks()
2586 int dwc3_runtime_suspend(struct dwc3 *dwc) in dwc3_runtime_suspend() argument
2590 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2593 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2601 int dwc3_runtime_resume(struct dwc3 *dwc) in dwc3_runtime_resume() argument
2603 struct device *dev = dwc->dev; in dwc3_runtime_resume()
2606 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2610 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2612 if (dwc->pending_events) { in dwc3_runtime_resume()
2614 dwc->pending_events = false; in dwc3_runtime_resume()
2615 enable_irq(dwc->irq_gadget); in dwc3_runtime_resume()
2630 int dwc3_runtime_idle(struct dwc3 *dwc) in dwc3_runtime_idle() argument
2632 struct device *dev = dwc->dev; in dwc3_runtime_idle()
2634 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2636 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2669 int dwc3_pm_suspend(struct dwc3 *dwc) in dwc3_pm_suspend() argument
2671 struct device *dev = dwc->dev; in dwc3_pm_suspend()
2674 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_pm_suspend()
2684 int dwc3_pm_resume(struct dwc3 *dwc) in dwc3_pm_resume() argument
2686 struct device *dev = dwc->dev; in dwc3_pm_resume()
2696 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_pm_resume()
2707 void dwc3_pm_complete(struct dwc3 *dwc) in dwc3_pm_complete() argument
2711 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_pm_complete()
2712 dwc->dis_split_quirk) { in dwc3_pm_complete()
2713 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_pm_complete()
2715 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_pm_complete()
2720 int dwc3_pm_prepare(struct dwc3 *dwc) in dwc3_pm_prepare() argument
2722 struct device *dev = dwc->dev; in dwc3_pm_prepare()
2728 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE && in dwc3_pm_prepare()