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
126 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
128 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
130 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
131 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
133 if (!dwc->desired_dr_role) in __dwc3_set_mode()
136 if (dwc->desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
139 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
142 switch (dwc->current_dr_role) { in __dwc3_set_mode()
144 dwc3_host_exit(dwc); in __dwc3_set_mode()
147 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
148 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
151 dwc3_otg_exit(dwc); in __dwc3_set_mode()
152 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
153 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
154 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
155 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
165 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
167 dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) { in __dwc3_set_mode()
168 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
170 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
180 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
182 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
185 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
187 dwc3_set_prtcap(dwc, dwc->desired_dr_role); in __dwc3_set_mode()
189 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
191 switch (dwc->desired_dr_role) { in __dwc3_set_mode()
193 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
195 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
197 if (dwc->usb2_phy) in __dwc3_set_mode()
198 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
199 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
200 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
201 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
202 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
204 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
209 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
211 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
213 if (dwc->usb2_phy) in __dwc3_set_mode()
214 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
215 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
216 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
218 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
220 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
223 dwc3_otg_init(dwc); in __dwc3_set_mode()
224 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
231 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
232 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
233 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
236 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
240 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
243 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
244 dwc->desired_dr_role = mode; in dwc3_set_mode()
245 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
247 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
252 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
255 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
259 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
266 * @dwc: pointer to our context structure
268 int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
278 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
281 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
284 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_core_soft_reset()
296 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
306 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
325 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
333 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
336 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
338 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
340 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
341 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
351 * @dwc: Pointer to our controller context structure
353 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
361 if (dwc->ref_clk) { in dwc3_ref_clk_period()
362 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
366 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
367 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
373 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
376 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
404 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
412 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
415 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
420 * @dwc: Pointer to our controller context structure
423 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
426 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
431 * @dwc: Pointer to our controller context structure
437 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
442 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
446 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
448 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
452 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
462 * @dwc: Pointer to our controller context structure
464 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
468 evt = dwc->ev_buf; in dwc3_free_event_buffers()
470 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
475 * @dwc: pointer to our controller context structure
478 * Returns 0 on success otherwise negative errno. In the error case, dwc
481 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) in dwc3_alloc_event_buffers() argument
485 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
487 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
490 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
497 * @dwc: pointer to our controller context structure
501 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
505 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
507 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
509 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
511 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
513 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
518 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
522 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
526 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
527 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
528 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
530 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
533 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) in dwc3_alloc_scratch_buffers() argument
535 if (!dwc->has_hibernation) in dwc3_alloc_scratch_buffers()
538 if (!dwc->nr_scratch) in dwc3_alloc_scratch_buffers()
541 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, in dwc3_alloc_scratch_buffers()
543 if (!dwc->scratchbuf) in dwc3_alloc_scratch_buffers()
549 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) in dwc3_setup_scratch_buffers() argument
555 if (!dwc->has_hibernation) in dwc3_setup_scratch_buffers()
558 if (!dwc->nr_scratch) in dwc3_setup_scratch_buffers()
562 if (!WARN_ON(dwc->scratchbuf)) in dwc3_setup_scratch_buffers()
565 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, in dwc3_setup_scratch_buffers()
566 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, in dwc3_setup_scratch_buffers()
568 if (dma_mapping_error(dwc->sysdev, scratch_addr)) { in dwc3_setup_scratch_buffers()
569 dev_err(dwc->sysdev, "failed to map scratch buffer\n"); in dwc3_setup_scratch_buffers()
574 dwc->scratch_addr = scratch_addr; in dwc3_setup_scratch_buffers()
578 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
585 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
593 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_setup_scratch_buffers()
600 static void dwc3_free_scratch_buffers(struct dwc3 *dwc) in dwc3_free_scratch_buffers() argument
602 if (!dwc->has_hibernation) in dwc3_free_scratch_buffers()
605 if (!dwc->nr_scratch) in dwc3_free_scratch_buffers()
609 if (!WARN_ON(dwc->scratchbuf)) in dwc3_free_scratch_buffers()
612 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_free_scratch_buffers()
614 kfree(dwc->scratchbuf); in dwc3_free_scratch_buffers()
617 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
619 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
621 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
624 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
626 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
628 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
629 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
630 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
631 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
632 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
633 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
634 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
635 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
636 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
639 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
642 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
647 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
651 dwc->hsphy_interface && in dwc3_core_ulpi_init()
652 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
653 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
660 * @dwc: Pointer to our controller context structure
666 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
671 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
673 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
698 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
701 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
704 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
707 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
710 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
713 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
716 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
719 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
720 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
722 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
725 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
728 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
730 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
733 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
735 if (dwc->hsphy_interface && in dwc3_phy_setup()
736 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
739 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
740 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
742 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
754 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
788 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
791 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
796 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
799 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
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()
823 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
825 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
829 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
831 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
832 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
833 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
836 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
838 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
840 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_exit()
841 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_exit()
842 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_exit()
843 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_exit()
845 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_exit()
846 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_exit()
847 phy_exit(dwc->usb2_generic_phy); in dwc3_core_exit()
848 phy_exit(dwc->usb3_generic_phy); in dwc3_core_exit()
850 dwc3_clk_disable(dwc); in dwc3_core_exit()
851 reset_control_assert(dwc->reset); in dwc3_core_exit()
854 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
858 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
859 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
863 dwc->revision = reg; in dwc3_core_is_valid()
865 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
866 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
874 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
876 u32 hwparams4 = dwc->hwparams.hwparams4; in dwc3_core_setup_global_control()
879 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
882 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
896 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
897 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
905 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); in dwc3_core_setup_global_control()
919 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
920 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
921 dwc->is_fpga = true; in dwc3_core_setup_global_control()
924 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
927 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
932 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
944 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
947 static int dwc3_core_get_phy(struct dwc3 *dwc);
948 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
951 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
953 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
964 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1039 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1042 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1047 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1063 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1064 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1069 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1075 * @dwc: Pointer to our controller context structure
1079 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1085 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1091 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1093 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1097 if (!dwc->ulpi_ready) { in dwc3_core_init()
1098 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1101 dwc->ulpi_ready = true; in dwc3_core_init()
1104 if (!dwc->phys_ready) { in dwc3_core_init()
1105 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1108 dwc->phys_ready = true; in dwc3_core_init()
1111 usb_phy_init(dwc->usb2_phy); in dwc3_core_init()
1112 usb_phy_init(dwc->usb3_phy); in dwc3_core_init()
1113 ret = phy_init(dwc->usb2_generic_phy); in dwc3_core_init()
1117 ret = phy_init(dwc->usb3_generic_phy); in dwc3_core_init()
1119 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1123 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1129 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
1130 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
1132 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
1135 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
1136 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
1138 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
1142 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1143 dwc3_core_num_eps(dwc); in dwc3_core_init()
1145 ret = dwc3_setup_scratch_buffers(dwc); in dwc3_core_init()
1150 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1153 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1156 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1158 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1160 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_core_init()
1161 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_core_init()
1162 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_core_init()
1166 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_core_init()
1170 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1172 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1182 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1184 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1196 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1197 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1199 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1203 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1221 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1224 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1228 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1229 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1232 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1235 if (dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_init()
1236 dwc->dr_mode == USB_DR_MODE_OTG) { in dwc3_core_init()
1237 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_core_init()
1248 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_core_init()
1255 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_init()
1256 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_core_init()
1257 u8 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_core_init()
1258 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_core_init()
1259 u8 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_core_init()
1262 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_core_init()
1271 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_core_init()
1275 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_core_init()
1284 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_core_init()
1291 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_init()
1294 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_init()
1297 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_init()
1298 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_init()
1301 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_init()
1302 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_init()
1303 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1304 phy_exit(dwc->usb3_generic_phy); in dwc3_core_init()
1307 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1313 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1315 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1320 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1321 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1323 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1324 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1327 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1328 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1330 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1335 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1336 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1338 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1343 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1344 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1345 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1347 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1352 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1353 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1354 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1356 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1364 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1366 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1369 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1371 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1373 if (dwc->usb2_phy) in dwc3_core_init_mode()
1374 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1375 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1376 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1378 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1383 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1385 if (dwc->usb2_phy) in dwc3_core_init_mode()
1386 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1387 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1388 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1390 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1395 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1396 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1401 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1408 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1410 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1412 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1415 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1418 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1426 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1429 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1431 struct device *dev = dwc->dev; in dwc3_get_properties()
1462 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1463 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1464 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1465 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1467 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1469 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1470 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1472 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1476 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1477 if (!dwc->usb_psy) in dwc3_get_properties()
1481 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1485 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1489 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1491 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1493 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1495 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1505 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1507 if (dwc->do_fifo_resize) in dwc3_get_properties()
1511 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1513 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1515 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1517 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1519 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1521 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1523 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1525 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1527 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1529 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1531 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1533 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1535 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1537 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1539 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1541 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1543 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1545 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1547 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1549 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1552 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1557 &dwc->hsphy_interface); in dwc3_get_properties()
1559 &dwc->fladj); in dwc3_get_properties()
1561 &dwc->ref_clk_per); in dwc3_get_properties()
1563 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1566 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1569 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1570 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1572 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1574 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1575 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1577 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1578 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1580 dwc->imod_interval = 0; in dwc3_get_properties()
1582 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1586 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1593 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1595 struct device *dev = dwc->dev; in dwc3_check_params()
1597 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1600 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1601 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1602 dwc->imod_interval = 0; in dwc3_check_params()
1612 if (!dwc->imod_interval && in dwc3_check_params()
1614 dwc->imod_interval = 1; in dwc3_check_params()
1617 switch (dwc->maximum_speed) { in dwc3_check_params()
1634 dwc->maximum_speed); in dwc3_check_params()
1639 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1643 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1645 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1648 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1651 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1664 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1665 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1680 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1682 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1686 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1694 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1696 struct device *dev = dwc->dev; in dwc3_get_extcon()
1748 struct dwc3 *dwc; in dwc3_probe() local
1754 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1755 if (!dwc) in dwc3_probe()
1758 dwc->dev = dev; in dwc3_probe()
1766 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1767 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1769 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1770 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1783 dwc->regs = regs; in dwc3_probe()
1784 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1786 dwc3_get_properties(dwc); in dwc3_probe()
1788 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1789 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1790 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1801 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_probe()
1802 if (IS_ERR(dwc->bus_clk)) { in dwc3_probe()
1803 ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_probe()
1808 if (dwc->bus_clk == NULL) { in dwc3_probe()
1809 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_probe()
1810 if (IS_ERR(dwc->bus_clk)) { in dwc3_probe()
1811 ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_probe()
1817 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_probe()
1818 if (IS_ERR(dwc->ref_clk)) { in dwc3_probe()
1819 ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_probe()
1824 if (dwc->ref_clk == NULL) { in dwc3_probe()
1825 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_probe()
1826 if (IS_ERR(dwc->ref_clk)) { in dwc3_probe()
1827 ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_probe()
1833 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_probe()
1834 if (IS_ERR(dwc->susp_clk)) { in dwc3_probe()
1835 ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_probe()
1840 if (dwc->susp_clk == NULL) { in dwc3_probe()
1841 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_probe()
1842 if (IS_ERR(dwc->susp_clk)) { in dwc3_probe()
1843 ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_probe()
1850 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1854 ret = dwc3_clk_enable(dwc); in dwc3_probe()
1858 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1859 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1864 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1865 dwc3_cache_hwparams(dwc); in dwc3_probe()
1867 if (!dwc->sysdev_is_parent && in dwc3_probe()
1868 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1869 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1874 spin_lock_init(&dwc->lock); in dwc3_probe()
1875 mutex_init(&dwc->mutex); in dwc3_probe()
1887 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1889 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1894 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
1895 if (IS_ERR(dwc->edev)) { in dwc3_probe()
1896 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
1900 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1904 ret = dwc3_alloc_scratch_buffers(dwc); in dwc3_probe()
1908 ret = dwc3_core_init(dwc); in dwc3_probe()
1914 dwc3_check_params(dwc); in dwc3_probe()
1915 dwc3_debugfs_init(dwc); in dwc3_probe()
1917 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
1926 dwc3_debugfs_exit(dwc); in dwc3_probe()
1927 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
1929 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_probe()
1930 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_probe()
1931 phy_power_off(dwc->usb2_generic_phy); in dwc3_probe()
1932 phy_power_off(dwc->usb3_generic_phy); in dwc3_probe()
1934 usb_phy_shutdown(dwc->usb2_phy); in dwc3_probe()
1935 usb_phy_shutdown(dwc->usb3_phy); in dwc3_probe()
1936 phy_exit(dwc->usb2_generic_phy); in dwc3_probe()
1937 phy_exit(dwc->usb3_generic_phy); in dwc3_probe()
1939 dwc3_ulpi_exit(dwc); in dwc3_probe()
1942 dwc3_free_scratch_buffers(dwc); in dwc3_probe()
1945 dwc3_free_event_buffers(dwc); in dwc3_probe()
1955 dwc3_clk_disable(dwc); in dwc3_probe()
1957 reset_control_assert(dwc->reset); in dwc3_probe()
1959 if (dwc->usb_psy) in dwc3_probe()
1960 power_supply_put(dwc->usb_psy); in dwc3_probe()
1967 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
1971 dwc3_core_exit_mode(dwc); in dwc3_remove()
1972 dwc3_debugfs_exit(dwc); in dwc3_remove()
1974 dwc3_core_exit(dwc); in dwc3_remove()
1975 dwc3_ulpi_exit(dwc); in dwc3_remove()
1981 dwc3_free_event_buffers(dwc); in dwc3_remove()
1982 dwc3_free_scratch_buffers(dwc); in dwc3_remove()
1984 if (dwc->usb_psy) in dwc3_remove()
1985 power_supply_put(dwc->usb_psy); in dwc3_remove()
1991 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
1995 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
1999 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
2003 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
2010 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
2012 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2017 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2022 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2024 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2026 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2027 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2028 dwc3_core_exit(dwc); in dwc3_suspend_common()
2031 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2032 dwc3_core_exit(dwc); in dwc3_suspend_common()
2037 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2038 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2039 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2042 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2048 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2049 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2056 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2057 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
2058 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2059 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
2060 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2063 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2064 dwc3_core_exit(dwc); in dwc3_suspend_common()
2074 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2080 switch (dwc->current_dr_role) { in dwc3_resume_common()
2082 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2086 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
2087 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2090 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2091 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2094 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
2098 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2099 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2102 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2105 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2107 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2108 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2115 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2119 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
2121 dwc3_otg_init(dwc); in dwc3_resume_common()
2122 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2123 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2124 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2125 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
2126 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2127 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
2139 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2141 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2143 if (dwc->connected) in dwc3_runtime_checks()
2157 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
2160 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2163 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2172 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
2175 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2179 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2181 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
2196 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
2198 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2200 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2219 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
2222 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
2233 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
2238 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
2251 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
2254 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2255 dwc->dis_split_quirk) { in dwc3_complete()
2256 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2258 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()