Lines Matching refs:dwc
48 static int dwc3_get_dr_mode(struct dwc3 *dwc) in dwc3_get_dr_mode() argument
51 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
54 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
55 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
57 mode = dwc->dr_mode; in dwc3_get_dr_mode()
58 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
90 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
95 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
100 dwc->dr_mode = mode; in dwc3_get_dr_mode()
106 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) in dwc3_set_prtcap() argument
110 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
113 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
115 dwc->current_dr_role = mode; in dwc3_set_prtcap()
118 static int dwc3_core_soft_reset(struct dwc3 *dwc);
122 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
127 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
129 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
131 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
132 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
134 if (!dwc->desired_dr_role) in __dwc3_set_mode()
137 if (dwc->desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
140 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
143 switch (dwc->current_dr_role) { in __dwc3_set_mode()
145 dwc3_host_exit(dwc); in __dwc3_set_mode()
148 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
149 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
152 dwc3_otg_exit(dwc); in __dwc3_set_mode()
153 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
154 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
155 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
156 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
163 if (dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG) { in __dwc3_set_mode()
164 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
166 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
176 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
178 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
181 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
183 dwc3_set_prtcap(dwc, dwc->desired_dr_role); in __dwc3_set_mode()
185 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
187 switch (dwc->desired_dr_role) { in __dwc3_set_mode()
189 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
191 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
193 if (dwc->usb2_phy) in __dwc3_set_mode()
194 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
195 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
196 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
197 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
198 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
200 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
205 dwc3_core_soft_reset(dwc); in __dwc3_set_mode()
207 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
209 if (dwc->usb2_phy) in __dwc3_set_mode()
210 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
211 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
212 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
214 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
216 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
219 dwc3_otg_init(dwc); in __dwc3_set_mode()
220 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
227 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
228 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
229 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
232 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
236 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
239 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
240 dwc->desired_dr_role = mode; in dwc3_set_mode()
241 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
243 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
248 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
251 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
255 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
264 static int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
274 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
277 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
279 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_core_soft_reset()
291 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
319 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
327 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
330 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
332 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
334 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
335 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
348 static void dwc3_ref_clk_period(struct dwc3 *dwc) in dwc3_ref_clk_period() argument
352 if (dwc->ref_clk_per == 0) in dwc3_ref_clk_period()
355 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
357 reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, dwc->ref_clk_per); in dwc3_ref_clk_period()
358 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
367 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
370 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
381 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
386 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
390 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
392 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
396 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
408 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
412 evt = dwc->ev_buf; in dwc3_free_event_buffers()
414 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
425 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) in dwc3_alloc_event_buffers() argument
429 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
431 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
434 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
445 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
449 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
451 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
453 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
455 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
457 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
462 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
466 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
470 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
471 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
472 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
474 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
477 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) in dwc3_alloc_scratch_buffers() argument
479 if (!dwc->has_hibernation) in dwc3_alloc_scratch_buffers()
482 if (!dwc->nr_scratch) in dwc3_alloc_scratch_buffers()
485 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, in dwc3_alloc_scratch_buffers()
487 if (!dwc->scratchbuf) in dwc3_alloc_scratch_buffers()
493 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) in dwc3_setup_scratch_buffers() argument
499 if (!dwc->has_hibernation) in dwc3_setup_scratch_buffers()
502 if (!dwc->nr_scratch) in dwc3_setup_scratch_buffers()
506 if (!WARN_ON(dwc->scratchbuf)) in dwc3_setup_scratch_buffers()
509 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, in dwc3_setup_scratch_buffers()
510 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, in dwc3_setup_scratch_buffers()
512 if (dma_mapping_error(dwc->sysdev, scratch_addr)) { in dwc3_setup_scratch_buffers()
513 dev_err(dwc->sysdev, "failed to map scratch buffer\n"); in dwc3_setup_scratch_buffers()
518 dwc->scratch_addr = scratch_addr; in dwc3_setup_scratch_buffers()
522 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
529 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
537 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_setup_scratch_buffers()
544 static void dwc3_free_scratch_buffers(struct dwc3 *dwc) in dwc3_free_scratch_buffers() argument
546 if (!dwc->has_hibernation) in dwc3_free_scratch_buffers()
549 if (!dwc->nr_scratch) in dwc3_free_scratch_buffers()
553 if (!WARN_ON(dwc->scratchbuf)) in dwc3_free_scratch_buffers()
556 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_free_scratch_buffers()
558 kfree(dwc->scratchbuf); in dwc3_free_scratch_buffers()
561 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
563 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
565 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
568 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
570 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
572 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
573 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
574 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
575 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
576 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
577 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
578 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
579 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
580 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
583 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
586 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
591 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
595 dwc->hsphy_interface && in dwc3_core_ulpi_init()
596 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
597 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
610 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
615 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
617 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
642 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
645 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
648 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
651 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
654 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
657 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
660 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
663 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
664 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
666 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
669 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
672 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
674 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
677 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
679 if (dwc->hsphy_interface && in dwc3_phy_setup()
680 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
683 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
684 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
686 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
698 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
732 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
735 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
740 if (dwc->dis_u2_freeclk_exists_quirk) in dwc3_phy_setup()
743 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
748 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
750 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
752 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_exit()
753 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_exit()
754 phy_exit(dwc->usb2_generic_phy); in dwc3_core_exit()
755 phy_exit(dwc->usb3_generic_phy); in dwc3_core_exit()
757 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_exit()
758 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_exit()
759 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_exit()
760 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_exit()
761 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_core_exit()
762 reset_control_assert(dwc->reset); in dwc3_core_exit()
765 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
769 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
770 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
774 dwc->revision = reg; in dwc3_core_is_valid()
776 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
777 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
785 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
787 u32 hwparams4 = dwc->hwparams.hwparams4; in dwc3_core_setup_global_control()
790 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
793 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
807 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
808 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
816 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); in dwc3_core_setup_global_control()
830 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
831 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
832 dwc->is_fpga = true; in dwc3_core_setup_global_control()
835 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
838 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
843 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
855 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
858 static int dwc3_core_get_phy(struct dwc3 *dwc);
859 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
862 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
864 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
875 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
952 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
961 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
967 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
973 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
975 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
979 if (!dwc->ulpi_ready) { in dwc3_core_init()
980 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
983 dwc->ulpi_ready = true; in dwc3_core_init()
986 if (!dwc->phys_ready) { in dwc3_core_init()
987 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
990 dwc->phys_ready = true; in dwc3_core_init()
993 usb_phy_init(dwc->usb2_phy); in dwc3_core_init()
994 usb_phy_init(dwc->usb3_phy); in dwc3_core_init()
995 ret = phy_init(dwc->usb2_generic_phy); in dwc3_core_init()
999 ret = phy_init(dwc->usb3_generic_phy); in dwc3_core_init()
1001 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1005 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
1011 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
1012 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
1014 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
1017 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
1018 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
1020 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
1024 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
1025 dwc3_core_num_eps(dwc); in dwc3_core_init()
1027 ret = dwc3_setup_scratch_buffers(dwc); in dwc3_core_init()
1032 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
1035 dwc3_ref_clk_period(dwc); in dwc3_core_init()
1037 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
1039 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_core_init()
1040 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_core_init()
1041 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_core_init()
1045 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_core_init()
1049 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
1051 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1061 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1063 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1067 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1085 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1088 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1091 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1094 if (dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_init()
1095 dwc->dr_mode == USB_DR_MODE_OTG) { in dwc3_core_init()
1096 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_core_init()
1107 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_core_init()
1114 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_init()
1115 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_core_init()
1116 u8 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_core_init()
1117 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_core_init()
1118 u8 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_core_init()
1121 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_core_init()
1130 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_core_init()
1134 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_core_init()
1143 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_core_init()
1150 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_init()
1153 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_init()
1156 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_init()
1157 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_init()
1160 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_init()
1161 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_init()
1162 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1163 phy_exit(dwc->usb3_generic_phy); in dwc3_core_init()
1166 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1172 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1174 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1179 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1180 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1182 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1183 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1186 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1187 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1189 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1195 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1196 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1198 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1204 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1205 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1206 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1208 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1214 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1215 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1216 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1218 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1227 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1229 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1232 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1234 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1236 if (dwc->usb2_phy) in dwc3_core_init_mode()
1237 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1238 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1239 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1241 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1246 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1248 if (dwc->usb2_phy) in dwc3_core_init_mode()
1249 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1250 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1251 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1253 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1258 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1259 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1264 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1271 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1273 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1275 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1278 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1281 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1289 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1292 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1294 struct device *dev = dwc->dev; in dwc3_get_properties()
1325 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1326 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1327 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1328 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1330 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1332 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1333 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1335 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1339 dwc->usb_psy = power_supply_get_by_name(usb_psy_name); in dwc3_get_properties()
1340 if (!dwc->usb_psy) in dwc3_get_properties()
1344 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1348 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1352 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1354 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1356 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1358 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1368 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1370 if (dwc->do_fifo_resize) in dwc3_get_properties()
1374 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1376 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1378 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1380 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1382 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1384 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1386 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1388 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1390 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1392 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1394 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1396 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1398 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1400 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1402 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1404 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1406 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1408 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1411 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1416 &dwc->hsphy_interface); in dwc3_get_properties()
1418 &dwc->fladj); in dwc3_get_properties()
1420 &dwc->ref_clk_per); in dwc3_get_properties()
1422 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1425 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1428 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1429 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1431 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1433 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1434 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1436 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1437 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1439 dwc->imod_interval = 0; in dwc3_get_properties()
1441 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1445 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1452 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1454 struct device *dev = dwc->dev; in dwc3_check_params()
1456 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1459 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1460 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1461 dwc->imod_interval = 0; in dwc3_check_params()
1471 if (!dwc->imod_interval && in dwc3_check_params()
1473 dwc->imod_interval = 1; in dwc3_check_params()
1476 switch (dwc->maximum_speed) { in dwc3_check_params()
1493 dwc->maximum_speed); in dwc3_check_params()
1498 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1502 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1504 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1507 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1510 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1523 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1524 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1539 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1541 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1545 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1557 struct dwc3 *dwc; in dwc3_probe() local
1563 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1564 if (!dwc) in dwc3_probe()
1567 dwc->dev = dev; in dwc3_probe()
1575 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1576 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1578 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1579 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1592 dwc->regs = regs; in dwc3_probe()
1593 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1595 dwc3_get_properties(dwc); in dwc3_probe()
1597 if (!dwc->sysdev_is_parent) { in dwc3_probe()
1598 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_probe()
1603 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_probe()
1604 if (IS_ERR(dwc->reset)) in dwc3_probe()
1605 return PTR_ERR(dwc->reset); in dwc3_probe()
1608 ret = devm_clk_bulk_get_all(dev, &dwc->clks); in dwc3_probe()
1616 dwc->num_clks = 0; in dwc3_probe()
1618 dwc->num_clks = ret; in dwc3_probe()
1622 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1626 ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); in dwc3_probe()
1630 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1631 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1636 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1637 dwc3_cache_hwparams(dwc); in dwc3_probe()
1639 spin_lock_init(&dwc->lock); in dwc3_probe()
1640 mutex_init(&dwc->mutex); in dwc3_probe()
1652 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1654 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1659 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1663 ret = dwc3_alloc_scratch_buffers(dwc); in dwc3_probe()
1667 ret = dwc3_core_init(dwc); in dwc3_probe()
1673 dwc3_check_params(dwc); in dwc3_probe()
1674 dwc3_debugfs_init(dwc); in dwc3_probe()
1676 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
1685 dwc3_debugfs_exit(dwc); in dwc3_probe()
1686 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
1688 usb_phy_shutdown(dwc->usb2_phy); in dwc3_probe()
1689 usb_phy_shutdown(dwc->usb3_phy); in dwc3_probe()
1690 phy_exit(dwc->usb2_generic_phy); in dwc3_probe()
1691 phy_exit(dwc->usb3_generic_phy); in dwc3_probe()
1693 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_probe()
1694 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_probe()
1695 phy_power_off(dwc->usb2_generic_phy); in dwc3_probe()
1696 phy_power_off(dwc->usb3_generic_phy); in dwc3_probe()
1698 dwc3_ulpi_exit(dwc); in dwc3_probe()
1701 dwc3_free_scratch_buffers(dwc); in dwc3_probe()
1704 dwc3_free_event_buffers(dwc); in dwc3_probe()
1714 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_probe()
1716 reset_control_assert(dwc->reset); in dwc3_probe()
1718 if (dwc->usb_psy) in dwc3_probe()
1719 power_supply_put(dwc->usb_psy); in dwc3_probe()
1726 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
1730 dwc3_core_exit_mode(dwc); in dwc3_remove()
1731 dwc3_debugfs_exit(dwc); in dwc3_remove()
1733 dwc3_core_exit(dwc); in dwc3_remove()
1734 dwc3_ulpi_exit(dwc); in dwc3_remove()
1740 dwc3_free_event_buffers(dwc); in dwc3_remove()
1741 dwc3_free_scratch_buffers(dwc); in dwc3_remove()
1743 if (dwc->usb_psy) in dwc3_remove()
1744 power_supply_put(dwc->usb_psy); in dwc3_remove()
1750 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
1754 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
1758 ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); in dwc3_core_init_for_resume()
1762 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
1769 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_core_init_for_resume()
1771 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
1776 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
1781 switch (dwc->current_dr_role) { in dwc3_suspend_common()
1783 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
1785 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
1786 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
1787 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
1788 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
1789 dwc3_core_exit(dwc); in dwc3_suspend_common()
1793 dwc3_core_exit(dwc); in dwc3_suspend_common()
1798 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
1799 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
1800 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
1803 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
1809 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
1810 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
1817 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
1818 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
1819 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
1820 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
1821 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
1824 dwc3_otg_exit(dwc); in dwc3_suspend_common()
1825 dwc3_core_exit(dwc); in dwc3_suspend_common()
1835 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
1841 switch (dwc->current_dr_role) { in dwc3_resume_common()
1843 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1847 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
1848 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
1849 dwc3_gadget_resume(dwc); in dwc3_resume_common()
1850 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
1854 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1857 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
1861 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
1862 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
1865 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
1868 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
1870 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
1871 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
1878 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1882 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
1884 dwc3_otg_init(dwc); in dwc3_resume_common()
1885 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
1886 dwc3_otg_host_init(dwc); in dwc3_resume_common()
1887 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
1888 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
1889 dwc3_gadget_resume(dwc); in dwc3_resume_common()
1890 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
1902 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
1904 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
1906 if (dwc->connected) in dwc3_runtime_checks()
1920 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
1923 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
1926 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
1937 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
1942 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
1946 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
1948 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
1963 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
1965 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
1967 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
1986 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
1989 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
2000 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
2005 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
2018 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
2021 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
2022 dwc->dis_split_quirk) { in dwc3_complete()
2023 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
2025 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()