Lines Matching full:dwc
47 * @dwc: pointer to our context structure
49 static int dwc3_get_dr_mode(struct dwc3 *dwc) in dwc3_get_dr_mode() argument
52 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
55 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
56 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
58 mode = dwc->dr_mode; in dwc3_get_dr_mode()
59 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
89 if (mode == USB_DR_MODE_OTG && !dwc->edev && in dwc3_get_dr_mode()
91 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
96 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
101 dwc->dr_mode = mode; in dwc3_get_dr_mode()
107 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) in dwc3_set_prtcap() argument
111 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
114 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
116 dwc->current_dr_role = mode; in dwc3_set_prtcap()
121 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
127 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
128 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
129 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
130 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
132 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
134 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
135 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
140 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
143 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
146 switch (dwc->current_dr_role) { in __dwc3_set_mode()
148 dwc3_host_exit(dwc); in __dwc3_set_mode()
151 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
152 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
155 dwc3_otg_exit(dwc); in __dwc3_set_mode()
156 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
157 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
158 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
159 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
169 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
172 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
174 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
184 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
186 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
189 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
191 dwc3_set_prtcap(dwc, desired_dr_role); in __dwc3_set_mode()
193 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
197 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
199 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
201 if (dwc->usb2_phy) in __dwc3_set_mode()
202 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
203 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
204 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
205 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
206 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
208 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
213 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
215 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
217 if (dwc->usb2_phy) in __dwc3_set_mode()
218 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
219 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
220 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
222 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
224 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
227 dwc3_otg_init(dwc); in __dwc3_set_mode()
228 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
235 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
236 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
237 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
240 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
244 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
247 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
248 dwc->desired_dr_role = mode; in dwc3_set_mode()
249 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
251 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
256 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
259 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
263 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
270 * @dwc: pointer to our context structure
272 int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
282 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
285 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
288 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_core_soft_reset()
300 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
310 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
329 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
337 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
340 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
342 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
344 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
345 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
355 * @dwc: Pointer to our controller context structure
357 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
365 if (dwc->ref_clk) { in dwc3_ref_clk_period()
366 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
370 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
371 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
377 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
380 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
408 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
416 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
419 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
424 * @dwc: Pointer to our controller context structure
427 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
430 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
435 * @dwc: Pointer to our controller context structure
441 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
446 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
450 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
452 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
456 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
466 * @dwc: Pointer to our controller context structure
468 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
472 evt = dwc->ev_buf; in dwc3_free_event_buffers()
474 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
479 * @dwc: pointer to our controller context structure
482 * Returns 0 on success otherwise negative errno. In the error case, dwc
485 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
489 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
491 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
494 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
501 * @dwc: pointer to our controller context structure
505 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
509 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
511 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
513 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
515 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
517 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
522 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
526 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
530 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
531 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
532 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
534 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
537 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
539 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
541 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
544 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
546 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
548 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
549 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
550 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
551 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
552 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
553 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
554 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
555 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
556 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
559 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
562 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
567 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
571 dwc->hsphy_interface && in dwc3_core_ulpi_init()
572 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
573 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
580 * @dwc: Pointer to our controller context structure
586 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
591 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
593 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
618 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
621 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
624 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
627 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
630 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
633 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
636 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
639 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
640 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
642 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
645 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
648 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
650 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
653 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
655 if (dwc->hsphy_interface && in dwc3_phy_setup()
656 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
659 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
660 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
662 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
674 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
708 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
711 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
716 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
726 if (dwc->ulpi_ext_vbus_drv) in dwc3_phy_setup()
729 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
734 static int dwc3_phy_init(struct dwc3 *dwc) in dwc3_phy_init() argument
738 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
739 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
741 ret = phy_init(dwc->usb2_generic_phy); in dwc3_phy_init()
745 ret = phy_init(dwc->usb3_generic_phy); in dwc3_phy_init()
752 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_init()
754 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
755 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
760 static void dwc3_phy_exit(struct dwc3 *dwc) in dwc3_phy_exit() argument
762 phy_exit(dwc->usb3_generic_phy); in dwc3_phy_exit()
763 phy_exit(dwc->usb2_generic_phy); in dwc3_phy_exit()
765 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
766 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
769 static int dwc3_phy_power_on(struct dwc3 *dwc) in dwc3_phy_power_on() argument
773 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
774 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
776 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_phy_power_on()
780 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_phy_power_on()
787 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_on()
789 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
790 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
795 static void dwc3_phy_power_off(struct dwc3 *dwc) in dwc3_phy_power_off() argument
797 phy_power_off(dwc->usb3_generic_phy); in dwc3_phy_power_off()
798 phy_power_off(dwc->usb2_generic_phy); in dwc3_phy_power_off()
800 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
801 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
804 static int dwc3_clk_enable(struct dwc3 *dwc) in dwc3_clk_enable() argument
808 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
812 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
816 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
820 ret = clk_prepare_enable(dwc->utmi_clk); in dwc3_clk_enable()
824 ret = clk_prepare_enable(dwc->pipe_clk); in dwc3_clk_enable()
831 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_enable()
833 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_enable()
835 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
837 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
841 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
843 clk_disable_unprepare(dwc->pipe_clk); in dwc3_clk_disable()
844 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_disable()
845 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
846 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
847 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
850 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
852 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
853 dwc3_phy_power_off(dwc); in dwc3_core_exit()
854 dwc3_phy_exit(dwc); in dwc3_core_exit()
855 dwc3_clk_disable(dwc); in dwc3_core_exit()
856 reset_control_assert(dwc->reset); in dwc3_core_exit()
859 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
863 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
864 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
868 dwc->revision = reg; in dwc3_core_is_valid()
870 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
871 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
879 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
883 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
886 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
900 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
901 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
920 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
921 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
922 dwc->is_fpga = true; in dwc3_core_setup_global_control()
925 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
928 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
933 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
945 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
948 static int dwc3_core_get_phy(struct dwc3 *dwc);
949 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
952 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
954 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
965 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1040 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1043 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1048 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1064 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1065 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1070 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1074 static void dwc3_config_threshold(struct dwc3 *dwc) in dwc3_config_threshold() argument
1086 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1087 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1088 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1089 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1090 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1093 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1102 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1106 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1115 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1119 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1120 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1121 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1122 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1126 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1135 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1139 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1148 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1152 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1161 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1165 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1174 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1181 * @dwc: Pointer to our controller context structure
1185 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1191 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1197 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1199 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1203 if (!dwc->ulpi_ready) { in dwc3_core_init()
1204 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1207 dwc3_core_soft_reset(dwc); in dwc3_core_init()
1212 dwc->ulpi_ready = true; in dwc3_core_init()
1215 if (!dwc->phys_ready) { in dwc3_core_init()
1216 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1219 dwc->phys_ready = true; in dwc3_core_init()
1222 ret = dwc3_phy_init(dwc); in dwc3_core_init()
1226 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1232 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
1233 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
1235 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
1238 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
1239 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
1241 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
1245 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1246 dwc3_core_num_eps(dwc); in dwc3_core_init()
1249 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1252 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1255 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1257 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1259 ret = dwc3_phy_power_on(dwc); in dwc3_core_init()
1263 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1265 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1275 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1277 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1289 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1290 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1292 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1296 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1314 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1317 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1320 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1324 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1325 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1328 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1331 dwc3_config_threshold(dwc); in dwc3_core_init()
1339 dwc->maximum_speed == USB_SPEED_SUPER) { in dwc3_core_init()
1340 reg = dwc3_readl(dwc->regs, DWC3_LLUCTL); in dwc3_core_init()
1342 dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); in dwc3_core_init()
1348 dwc3_phy_power_off(dwc); in dwc3_core_init()
1350 dwc3_phy_exit(dwc); in dwc3_core_init()
1352 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1357 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1359 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1364 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1365 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1367 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1368 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1371 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1372 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1374 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1379 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1380 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1382 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1387 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1388 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1389 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1391 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1396 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1397 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1398 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1400 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1408 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1410 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1413 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1415 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1417 if (dwc->usb2_phy) in dwc3_core_init_mode()
1418 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1419 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1420 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1422 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1427 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1429 if (dwc->usb2_phy) in dwc3_core_init_mode()
1430 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1431 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1432 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1434 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1439 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1440 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1445 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1452 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1454 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1456 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1459 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1462 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1470 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1473 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1475 struct device *dev = dwc->dev; in dwc3_get_properties()
1510 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1511 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1512 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1513 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1515 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1517 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1518 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1520 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1524 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1525 if (!dwc->usb_psy) in dwc3_get_properties()
1529 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1533 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1537 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1539 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1541 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1543 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1561 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1563 if (dwc->do_fifo_resize) in dwc3_get_properties()
1567 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1569 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1571 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1573 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1575 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1577 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1579 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1581 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1583 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1585 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1587 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1589 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1591 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1593 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1595 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1597 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1599 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1601 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1603 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1605 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1607 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1609 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1612 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1617 &dwc->hsphy_interface); in dwc3_get_properties()
1619 &dwc->fladj); in dwc3_get_properties()
1621 &dwc->ref_clk_per); in dwc3_get_properties()
1623 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1626 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1629 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1630 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1632 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1634 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1635 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1637 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1638 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1640 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1641 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1643 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1644 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1646 dwc->imod_interval = 0; in dwc3_get_properties()
1648 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1652 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1659 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1661 struct device *dev = dwc->dev; in dwc3_check_params()
1663 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1666 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1667 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1668 dwc->imod_interval = 0; in dwc3_check_params()
1678 if (!dwc->imod_interval && in dwc3_check_params()
1680 dwc->imod_interval = 1; in dwc3_check_params()
1683 switch (dwc->maximum_speed) { in dwc3_check_params()
1700 dwc->maximum_speed); in dwc3_check_params()
1705 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1709 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1711 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1714 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1717 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1730 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1731 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1746 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1748 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1752 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1760 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1762 struct device *dev = dwc->dev; in dwc3_get_extcon()
1810 static int dwc3_get_clocks(struct dwc3 *dwc) in dwc3_get_clocks() argument
1812 struct device *dev = dwc->dev; in dwc3_get_clocks()
1823 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
1824 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1825 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1829 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
1830 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
1831 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
1832 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
1837 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
1838 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1839 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1843 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
1844 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
1845 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
1846 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
1851 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
1852 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1853 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1857 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
1858 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
1859 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
1860 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
1866 dwc->utmi_clk = devm_clk_get_optional(dev, "utmi"); in dwc3_get_clocks()
1867 if (IS_ERR(dwc->utmi_clk)) { in dwc3_get_clocks()
1868 return dev_err_probe(dev, PTR_ERR(dwc->utmi_clk), in dwc3_get_clocks()
1873 dwc->pipe_clk = devm_clk_get_optional(dev, "pipe"); in dwc3_get_clocks()
1874 if (IS_ERR(dwc->pipe_clk)) { in dwc3_get_clocks()
1875 return dev_err_probe(dev, PTR_ERR(dwc->pipe_clk), in dwc3_get_clocks()
1887 struct dwc3 *dwc; in dwc3_probe() local
1890 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1891 if (!dwc) in dwc3_probe()
1894 dwc->dev = dev; in dwc3_probe()
1902 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1903 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1905 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1906 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1930 dwc->regs = regs; in dwc3_probe()
1931 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1933 dwc3_get_properties(dwc); in dwc3_probe()
1935 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1936 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1937 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1941 ret = dwc3_get_clocks(dwc); in dwc3_probe()
1945 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1949 ret = dwc3_clk_enable(dwc); in dwc3_probe()
1953 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1954 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1959 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1960 dwc3_cache_hwparams(dwc); in dwc3_probe()
1962 if (!dwc->sysdev_is_parent && in dwc3_probe()
1963 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1964 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1969 spin_lock_init(&dwc->lock); in dwc3_probe()
1970 mutex_init(&dwc->mutex); in dwc3_probe()
1980 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1982 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1987 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
1988 if (IS_ERR(dwc->edev)) { in dwc3_probe()
1989 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
1993 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1997 ret = dwc3_core_init(dwc); in dwc3_probe()
2003 dwc3_check_params(dwc); in dwc3_probe()
2004 dwc3_debugfs_init(dwc); in dwc3_probe()
2006 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
2017 dwc3_debugfs_exit(dwc); in dwc3_probe()
2018 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
2019 dwc3_phy_power_off(dwc); in dwc3_probe()
2020 dwc3_phy_exit(dwc); in dwc3_probe()
2021 dwc3_ulpi_exit(dwc); in dwc3_probe()
2023 dwc3_free_event_buffers(dwc); in dwc3_probe()
2031 dwc3_clk_disable(dwc); in dwc3_probe()
2033 reset_control_assert(dwc->reset); in dwc3_probe()
2035 if (dwc->usb_psy) in dwc3_probe()
2036 power_supply_put(dwc->usb_psy); in dwc3_probe()
2043 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
2047 dwc3_core_exit_mode(dwc); in dwc3_remove()
2048 dwc3_debugfs_exit(dwc); in dwc3_remove()
2050 dwc3_core_exit(dwc); in dwc3_remove()
2051 dwc3_ulpi_exit(dwc); in dwc3_remove()
2064 dwc3_free_event_buffers(dwc); in dwc3_remove()
2066 if (dwc->usb_psy) in dwc3_remove()
2067 power_supply_put(dwc->usb_psy); in dwc3_remove()
2071 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
2075 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2079 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
2083 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
2090 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
2092 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2097 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2102 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2104 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2106 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2107 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2108 dwc3_core_exit(dwc); in dwc3_suspend_common()
2111 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2112 dwc3_core_exit(dwc); in dwc3_suspend_common()
2117 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2118 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2119 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2122 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2128 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2129 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2136 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2137 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
2138 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2139 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
2140 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2143 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2144 dwc3_core_exit(dwc); in dwc3_suspend_common()
2154 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2160 switch (dwc->current_dr_role) { in dwc3_resume_common()
2162 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2166 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
2167 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2170 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2171 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2174 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
2178 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2179 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2182 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2185 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2187 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2188 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2195 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2199 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
2201 dwc3_otg_init(dwc); in dwc3_resume_common()
2202 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2203 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2204 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2205 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
2206 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2207 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
2219 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2221 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2223 if (dwc->connected) in dwc3_runtime_checks()
2237 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
2240 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2243 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2252 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
2255 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2259 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2261 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
2276 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
2278 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2280 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2299 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
2302 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
2313 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
2321 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
2334 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
2337 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2338 dwc->dis_split_quirk) { in dwc3_complete()
2339 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2341 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()