Lines Matching refs:dwc
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()
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()
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()
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()
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()
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()
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()
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 int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) in dwc3_alloc_scratch_buffers() argument
539 if (!dwc->has_hibernation) in dwc3_alloc_scratch_buffers()
542 if (!dwc->nr_scratch) in dwc3_alloc_scratch_buffers()
545 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, in dwc3_alloc_scratch_buffers()
547 if (!dwc->scratchbuf) in dwc3_alloc_scratch_buffers()
553 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) in dwc3_setup_scratch_buffers() argument
559 if (!dwc->has_hibernation) in dwc3_setup_scratch_buffers()
562 if (!dwc->nr_scratch) in dwc3_setup_scratch_buffers()
566 if (!WARN_ON(dwc->scratchbuf)) in dwc3_setup_scratch_buffers()
569 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, in dwc3_setup_scratch_buffers()
570 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, in dwc3_setup_scratch_buffers()
572 if (dma_mapping_error(dwc->sysdev, scratch_addr)) { in dwc3_setup_scratch_buffers()
573 dev_err(dwc->sysdev, "failed to map scratch buffer\n"); in dwc3_setup_scratch_buffers()
578 dwc->scratch_addr = scratch_addr; in dwc3_setup_scratch_buffers()
582 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
589 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
597 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_setup_scratch_buffers()
604 static void dwc3_free_scratch_buffers(struct dwc3 *dwc) in dwc3_free_scratch_buffers() argument
606 if (!dwc->has_hibernation) in dwc3_free_scratch_buffers()
609 if (!dwc->nr_scratch) in dwc3_free_scratch_buffers()
613 if (!WARN_ON(dwc->scratchbuf)) in dwc3_free_scratch_buffers()
616 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_free_scratch_buffers()
618 kfree(dwc->scratchbuf); in dwc3_free_scratch_buffers()
621 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
623 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
625 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
628 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
630 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
632 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
633 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
634 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
635 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
636 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
637 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
638 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
639 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
640 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
643 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
646 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
651 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
655 dwc->hsphy_interface && in dwc3_core_ulpi_init()
656 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
657 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
670 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
675 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
677 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
702 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
705 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
708 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
711 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
714 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
717 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
720 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
723 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
724 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
726 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
729 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
732 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
734 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
737 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
739 if (dwc->hsphy_interface && in dwc3_phy_setup()
740 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
743 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
744 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
746 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
758 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
792 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
795 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
800 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_phy_setup()
803 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
808 static int dwc3_clk_enable(struct dwc3 *dwc) in dwc3_clk_enable() argument
812 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
816 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
820 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
827 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
829 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
833 static void dwc3_clk_disable(struct dwc3 *dwc) in dwc3_clk_disable() argument
835 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
836 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
837 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
840 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
842 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
844 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_exit()
845 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_exit()
846 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_exit()
847 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_exit()
849 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_exit()
850 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_exit()
851 phy_exit(dwc->usb2_generic_phy); in dwc3_core_exit()
852 phy_exit(dwc->usb3_generic_phy); in dwc3_core_exit()
854 dwc3_clk_disable(dwc); in dwc3_core_exit()
855 reset_control_assert(dwc->reset); in dwc3_core_exit()
858 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
862 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
863 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
867 dwc->revision = reg; in dwc3_core_is_valid()
869 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
870 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
878 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
880 u32 hwparams4 = dwc->hwparams.hwparams4; in dwc3_core_setup_global_control()
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()
909 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); in dwc3_core_setup_global_control()
923 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
924 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
925 dwc->is_fpga = true; in dwc3_core_setup_global_control()
928 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
931 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
936 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
948 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
951 static int dwc3_core_get_phy(struct dwc3 *dwc);
952 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
955 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
957 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
968 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1043 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1046 static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) in dwc3_set_power_down_clk_scale() argument
1051 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1067 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1068 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1073 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1083 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
1089 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1095 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1097 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
1101 if (!dwc->ulpi_ready) { in dwc3_core_init()
1102 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
1105 dwc3_core_soft_reset(dwc); in dwc3_core_init()
1110 dwc->ulpi_ready = true; in dwc3_core_init()
1113 if (!dwc->phys_ready) { in dwc3_core_init()
1114 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
1117 dwc->phys_ready = true; in dwc3_core_init()
1120 usb_phy_init(dwc->usb2_phy); in dwc3_core_init()
1121 usb_phy_init(dwc->usb3_phy); in dwc3_core_init()
1122 ret = phy_init(dwc->usb2_generic_phy); in dwc3_core_init()
1126 ret = phy_init(dwc->usb3_generic_phy); in dwc3_core_init()
1128 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1132 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1138 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
1139 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
1141 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
1144 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
1145 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
1147 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
1151 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1152 dwc3_core_num_eps(dwc); in dwc3_core_init()
1154 ret = dwc3_setup_scratch_buffers(dwc); in dwc3_core_init()
1159 dwc3_set_power_down_clk_scale(dwc); in dwc3_core_init()
1162 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1165 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1167 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1169 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_core_init()
1170 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_core_init()
1171 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_core_init()
1175 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_core_init()
1179 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1181 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1191 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1193 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1205 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1206 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1208 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1212 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1230 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1233 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1237 (dwc->maximum_speed == USB_SPEED_HIGH || in dwc3_core_init()
1238 dwc->maximum_speed == USB_SPEED_FULL)) in dwc3_core_init()
1241 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1244 if (dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_init()
1245 dwc->dr_mode == USB_DR_MODE_OTG) { in dwc3_core_init()
1246 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_core_init()
1257 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_core_init()
1264 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_init()
1265 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_core_init()
1266 u8 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_core_init()
1267 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_core_init()
1268 u8 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_core_init()
1271 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_core_init()
1280 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_core_init()
1284 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_core_init()
1293 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_core_init()
1300 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_init()
1303 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_init()
1306 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_init()
1307 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_init()
1310 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_init()
1311 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_init()
1312 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1313 phy_exit(dwc->usb3_generic_phy); in dwc3_core_init()
1316 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1322 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1324 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1329 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1330 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1332 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1333 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1336 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1337 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1339 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1344 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1345 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1347 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1352 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1353 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1354 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1356 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1361 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1362 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1363 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1365 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1373 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1375 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1378 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1380 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1382 if (dwc->usb2_phy) in dwc3_core_init_mode()
1383 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1384 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1385 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1387 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1392 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1394 if (dwc->usb2_phy) in dwc3_core_init_mode()
1395 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1396 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1397 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1399 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1404 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1405 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1410 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1417 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1419 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1421 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1424 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1427 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1435 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1438 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1440 struct device *dev = dwc->dev; in dwc3_get_properties()
1471 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1472 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1473 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1474 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1476 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1478 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1479 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1481 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1485 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1486 if (!dwc->usb_psy) in dwc3_get_properties()
1490 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1494 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1498 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1500 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1502 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1504 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1514 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1516 if (dwc->do_fifo_resize) in dwc3_get_properties()
1520 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1522 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1524 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1526 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1528 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1530 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1532 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1534 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1536 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1538 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1540 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1542 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1544 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1546 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1548 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1550 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1552 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1554 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1556 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1558 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1561 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1566 &dwc->hsphy_interface); in dwc3_get_properties()
1568 &dwc->fladj); in dwc3_get_properties()
1570 &dwc->ref_clk_per); in dwc3_get_properties()
1572 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1575 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1578 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1579 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1581 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1583 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1584 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1586 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1587 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1589 dwc->imod_interval = 0; in dwc3_get_properties()
1591 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1595 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1602 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1604 struct device *dev = dwc->dev; in dwc3_check_params()
1606 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1609 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1610 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1611 dwc->imod_interval = 0; in dwc3_check_params()
1621 if (!dwc->imod_interval && in dwc3_check_params()
1623 dwc->imod_interval = 1; in dwc3_check_params()
1626 switch (dwc->maximum_speed) { in dwc3_check_params()
1643 dwc->maximum_speed); in dwc3_check_params()
1648 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1652 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1654 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1657 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1660 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1673 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1674 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1689 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1691 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1695 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1703 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) in dwc3_get_extcon() argument
1705 struct device *dev = dwc->dev; in dwc3_get_extcon()
1757 struct dwc3 *dwc; in dwc3_probe() local
1763 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1764 if (!dwc) in dwc3_probe()
1767 dwc->dev = dev; in dwc3_probe()
1775 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1776 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1778 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1779 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1792 dwc->regs = regs; in dwc3_probe()
1793 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1795 dwc3_get_properties(dwc); in dwc3_probe()
1797 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1798 if (IS_ERR(dwc->reset)) { in dwc3_probe()
1799 ret = PTR_ERR(dwc->reset); in dwc3_probe()
1810 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_probe()
1811 if (IS_ERR(dwc->bus_clk)) { in dwc3_probe()
1812 ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_probe()
1817 if (dwc->bus_clk == NULL) { in dwc3_probe()
1818 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_probe()
1819 if (IS_ERR(dwc->bus_clk)) { in dwc3_probe()
1820 ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_probe()
1826 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_probe()
1827 if (IS_ERR(dwc->ref_clk)) { in dwc3_probe()
1828 ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_probe()
1833 if (dwc->ref_clk == NULL) { in dwc3_probe()
1834 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_probe()
1835 if (IS_ERR(dwc->ref_clk)) { in dwc3_probe()
1836 ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_probe()
1842 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_probe()
1843 if (IS_ERR(dwc->susp_clk)) { in dwc3_probe()
1844 ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_probe()
1849 if (dwc->susp_clk == NULL) { in dwc3_probe()
1850 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_probe()
1851 if (IS_ERR(dwc->susp_clk)) { in dwc3_probe()
1852 ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_probe()
1859 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1863 ret = dwc3_clk_enable(dwc); in dwc3_probe()
1867 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1868 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1873 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1874 dwc3_cache_hwparams(dwc); in dwc3_probe()
1876 if (!dwc->sysdev_is_parent && in dwc3_probe()
1877 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_probe()
1878 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1883 spin_lock_init(&dwc->lock); in dwc3_probe()
1884 mutex_init(&dwc->mutex); in dwc3_probe()
1896 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1898 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1903 dwc->edev = dwc3_get_extcon(dwc); in dwc3_probe()
1904 if (IS_ERR(dwc->edev)) { in dwc3_probe()
1905 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_probe()
1909 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1913 ret = dwc3_alloc_scratch_buffers(dwc); in dwc3_probe()
1917 ret = dwc3_core_init(dwc); in dwc3_probe()
1923 dwc3_check_params(dwc); in dwc3_probe()
1924 dwc3_debugfs_init(dwc); in dwc3_probe()
1926 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
1935 dwc3_debugfs_exit(dwc); in dwc3_probe()
1936 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
1938 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_probe()
1939 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_probe()
1940 phy_power_off(dwc->usb2_generic_phy); in dwc3_probe()
1941 phy_power_off(dwc->usb3_generic_phy); in dwc3_probe()
1943 usb_phy_shutdown(dwc->usb2_phy); in dwc3_probe()
1944 usb_phy_shutdown(dwc->usb3_phy); in dwc3_probe()
1945 phy_exit(dwc->usb2_generic_phy); in dwc3_probe()
1946 phy_exit(dwc->usb3_generic_phy); in dwc3_probe()
1948 dwc3_ulpi_exit(dwc); in dwc3_probe()
1951 dwc3_free_scratch_buffers(dwc); in dwc3_probe()
1954 dwc3_free_event_buffers(dwc); in dwc3_probe()
1964 dwc3_clk_disable(dwc); in dwc3_probe()
1966 reset_control_assert(dwc->reset); in dwc3_probe()
1968 if (dwc->usb_psy) in dwc3_probe()
1969 power_supply_put(dwc->usb_psy); in dwc3_probe()
1976 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
1980 dwc3_core_exit_mode(dwc); in dwc3_remove()
1981 dwc3_debugfs_exit(dwc); in dwc3_remove()
1983 dwc3_core_exit(dwc); in dwc3_remove()
1984 dwc3_ulpi_exit(dwc); in dwc3_remove()
1990 dwc3_free_event_buffers(dwc); in dwc3_remove()
1991 dwc3_free_scratch_buffers(dwc); in dwc3_remove()
1993 if (dwc->usb_psy) in dwc3_remove()
1994 power_supply_put(dwc->usb_psy); in dwc3_remove()
2000 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
2004 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2008 ret = dwc3_clk_enable(dwc); in dwc3_core_init_for_resume()
2012 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
2019 dwc3_clk_disable(dwc); in dwc3_core_init_for_resume()
2021 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2026 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
2031 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2033 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2035 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2036 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2037 dwc3_core_exit(dwc); in dwc3_suspend_common()
2040 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2041 dwc3_core_exit(dwc); in dwc3_suspend_common()
2046 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2047 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2048 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
2051 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
2057 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
2058 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
2065 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2066 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
2067 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
2068 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
2069 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2072 dwc3_otg_exit(dwc); in dwc3_suspend_common()
2073 dwc3_core_exit(dwc); in dwc3_suspend_common()
2083 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
2089 switch (dwc->current_dr_role) { in dwc3_resume_common()
2091 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2095 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
2096 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2099 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2100 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2103 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
2107 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
2108 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2111 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2114 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
2116 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
2117 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
2124 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
2128 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
2130 dwc3_otg_init(dwc); in dwc3_resume_common()
2131 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2132 dwc3_otg_host_init(dwc); in dwc3_resume_common()
2133 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2134 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
2135 dwc3_gadget_resume(dwc); in dwc3_resume_common()
2136 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
2148 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
2150 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2152 if (dwc->connected) in dwc3_runtime_checks()
2166 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
2169 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
2172 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
2181 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
2184 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
2188 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2190 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
2205 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
2207 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2209 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
2228 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
2231 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
2242 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
2247 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
2260 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
2263 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2264 dwc->dis_split_quirk) { in dwc3_complete()
2265 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2267 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()