• Home
  • Raw
  • Download

Lines Matching refs:dwc

47 static int dwc3_get_dr_mode(struct dwc3 *dwc)  in dwc3_get_dr_mode()  argument
50 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
53 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
54 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
56 mode = dwc->dr_mode; in dwc3_get_dr_mode()
57 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
88 dwc->revision >= DWC3_REVISION_330A) in dwc3_get_dr_mode()
92 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
97 dwc->dr_mode = mode; in dwc3_get_dr_mode()
103 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) in dwc3_set_prtcap() argument
107 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
110 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
112 dwc->current_dr_role = mode; in dwc3_set_prtcap()
117 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
121 if (dwc->dr_mode != USB_DR_MODE_OTG) in __dwc3_set_mode()
124 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
125 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
127 if (!dwc->desired_dr_role) in __dwc3_set_mode()
130 if (dwc->desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
133 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
136 switch (dwc->current_dr_role) { in __dwc3_set_mode()
138 dwc3_host_exit(dwc); in __dwc3_set_mode()
141 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
142 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
145 dwc3_otg_exit(dwc); in __dwc3_set_mode()
146 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
147 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
148 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
149 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
155 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
157 dwc3_set_prtcap(dwc, dwc->desired_dr_role); in __dwc3_set_mode()
159 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
161 switch (dwc->desired_dr_role) { in __dwc3_set_mode()
163 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
165 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
167 if (dwc->usb2_phy) in __dwc3_set_mode()
168 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
169 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
170 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
174 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
176 if (dwc->usb2_phy) in __dwc3_set_mode()
177 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
178 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
179 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
181 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
183 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
186 dwc3_otg_init(dwc); in __dwc3_set_mode()
187 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
195 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
199 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
200 dwc->desired_dr_role = mode; in dwc3_set_mode()
201 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
203 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
208 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
211 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
215 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
224 static int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
230 usb_phy_init(dwc->usb2_phy); in dwc3_core_soft_reset()
231 usb_phy_init(dwc->usb3_phy); in dwc3_core_soft_reset()
232 ret = phy_init(dwc->usb2_generic_phy); in dwc3_core_soft_reset()
236 ret = phy_init(dwc->usb3_generic_phy); in dwc3_core_soft_reset()
238 phy_exit(dwc->usb2_generic_phy); in dwc3_core_soft_reset()
247 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
250 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
252 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_core_soft_reset()
260 if (dwc3_is_usb31(dwc) && dwc->revision >= DWC3_USB31_REVISION_190A) in dwc3_core_soft_reset()
264 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
268 if (dwc3_is_usb31(dwc) && in dwc3_core_soft_reset()
269 dwc->revision >= DWC3_USB31_REVISION_190A) in dwc3_core_soft_reset()
275 phy_exit(dwc->usb3_generic_phy); in dwc3_core_soft_reset()
276 phy_exit(dwc->usb2_generic_phy); in dwc3_core_soft_reset()
286 if (dwc3_is_usb31(dwc) && dwc->revision <= DWC3_USB31_REVISION_180A) in dwc3_core_soft_reset()
302 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
307 if (dwc->revision < DWC3_REVISION_250A) in dwc3_frame_length_adjustment()
310 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
313 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
315 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
317 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
318 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
327 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
330 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
341 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
346 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
350 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
352 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
356 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
368 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
372 evt = dwc->ev_buf; in dwc3_free_event_buffers()
374 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
385 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) in dwc3_alloc_event_buffers() argument
389 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
391 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
394 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
405 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
409 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
411 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
413 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
415 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
417 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
422 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
426 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
430 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
431 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
432 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
434 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
437 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) in dwc3_alloc_scratch_buffers() argument
439 if (!dwc->has_hibernation) in dwc3_alloc_scratch_buffers()
442 if (!dwc->nr_scratch) in dwc3_alloc_scratch_buffers()
445 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, in dwc3_alloc_scratch_buffers()
447 if (!dwc->scratchbuf) in dwc3_alloc_scratch_buffers()
453 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) in dwc3_setup_scratch_buffers() argument
459 if (!dwc->has_hibernation) in dwc3_setup_scratch_buffers()
462 if (!dwc->nr_scratch) in dwc3_setup_scratch_buffers()
466 if (!WARN_ON(dwc->scratchbuf)) in dwc3_setup_scratch_buffers()
469 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, in dwc3_setup_scratch_buffers()
470 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, in dwc3_setup_scratch_buffers()
472 if (dma_mapping_error(dwc->sysdev, scratch_addr)) { in dwc3_setup_scratch_buffers()
473 dev_err(dwc->sysdev, "failed to map scratch buffer\n"); in dwc3_setup_scratch_buffers()
478 dwc->scratch_addr = scratch_addr; in dwc3_setup_scratch_buffers()
482 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
489 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
497 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_setup_scratch_buffers()
504 static void dwc3_free_scratch_buffers(struct dwc3 *dwc) in dwc3_free_scratch_buffers() argument
506 if (!dwc->has_hibernation) in dwc3_free_scratch_buffers()
509 if (!dwc->nr_scratch) in dwc3_free_scratch_buffers()
513 if (!WARN_ON(dwc->scratchbuf)) in dwc3_free_scratch_buffers()
516 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_free_scratch_buffers()
518 kfree(dwc->scratchbuf); in dwc3_free_scratch_buffers()
521 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
523 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
525 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
528 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
530 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
532 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
533 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
534 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
535 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
536 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
537 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
538 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
539 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
540 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
543 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
548 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
552 dwc->hsphy_interface && in dwc3_core_ulpi_init()
553 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
554 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
567 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
571 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
585 if (dwc->revision > DWC3_REVISION_194A) in dwc3_phy_setup()
588 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
591 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
594 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
597 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
600 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
603 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
606 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
609 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
610 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
612 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
615 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
618 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
620 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
623 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
625 if (dwc->hsphy_interface && in dwc3_phy_setup()
626 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
629 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
630 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
632 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
645 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
668 if (dwc->revision > DWC3_REVISION_194A) in dwc3_phy_setup()
671 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
674 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
679 if (dwc->dis_u2_freeclk_exists_quirk) in dwc3_phy_setup()
682 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
687 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
689 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
691 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_exit()
692 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_exit()
693 phy_exit(dwc->usb2_generic_phy); in dwc3_core_exit()
694 phy_exit(dwc->usb3_generic_phy); in dwc3_core_exit()
696 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_exit()
697 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_exit()
698 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_exit()
699 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_exit()
700 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_core_exit()
701 reset_control_assert(dwc->reset); in dwc3_core_exit()
704 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
708 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
713 dwc->revision = reg; in dwc3_core_is_valid()
716 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
717 dwc->revision |= DWC3_REVISION_IS_DWC31; in dwc3_core_is_valid()
718 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
726 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
728 u32 hwparams4 = dwc->hwparams.hwparams4; in dwc3_core_setup_global_control()
731 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
734 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
748 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
749 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
750 (dwc->revision >= DWC3_REVISION_210A && in dwc3_core_setup_global_control()
751 dwc->revision <= DWC3_REVISION_250A)) in dwc3_core_setup_global_control()
758 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); in dwc3_core_setup_global_control()
772 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
773 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
774 dwc->is_fpga = true; in dwc3_core_setup_global_control()
777 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
780 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
785 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
794 if (dwc->revision < DWC3_REVISION_190A) in dwc3_core_setup_global_control()
797 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
800 static int dwc3_core_get_phy(struct dwc3 *dwc);
801 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
804 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
806 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
817 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
894 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
903 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
912 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
915 if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == in dwc3_core_init()
917 if (dwc->maximum_speed == USB_SPEED_SUPER) in dwc3_core_init()
918 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_core_init()
921 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
925 if (!dwc->ulpi_ready) { in dwc3_core_init()
926 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
929 dwc->ulpi_ready = true; in dwc3_core_init()
932 if (!dwc->phys_ready) { in dwc3_core_init()
933 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
936 dwc->phys_ready = true; in dwc3_core_init()
939 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
943 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
944 dwc3_core_num_eps(dwc); in dwc3_core_init()
946 ret = dwc3_setup_scratch_buffers(dwc); in dwc3_core_init()
951 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
953 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
955 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_core_init()
956 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_core_init()
957 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_core_init()
961 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_core_init()
965 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
967 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
976 if (!dwc3_is_usb31(dwc) && dwc->revision >= DWC3_REVISION_310A) { in dwc3_core_init()
977 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
979 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
982 if (dwc->revision >= DWC3_REVISION_250A) { in dwc3_core_init()
983 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
989 if (dwc->revision >= DWC3_REVISION_290A) in dwc3_core_init()
992 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
995 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
998 if (dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_init()
999 dwc->dr_mode == USB_DR_MODE_OTG) { in dwc3_core_init()
1000 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_core_init()
1011 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_core_init()
1018 if (dwc3_is_usb31(dwc) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_init()
1019 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_core_init()
1020 u8 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_core_init()
1021 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_core_init()
1022 u8 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_core_init()
1025 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_core_init()
1034 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_core_init()
1038 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_core_init()
1047 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_core_init()
1054 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_init()
1057 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_init()
1060 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_init()
1061 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_init()
1064 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_init()
1065 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_init()
1066 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1067 phy_exit(dwc->usb3_generic_phy); in dwc3_core_init()
1070 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1076 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1078 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1083 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1084 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1086 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1087 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1090 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1091 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1093 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1102 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1103 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1105 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1114 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1115 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1116 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1118 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1127 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1128 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1129 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1131 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1143 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1145 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1148 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1150 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1152 if (dwc->usb2_phy) in dwc3_core_init_mode()
1153 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1154 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1155 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1157 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1165 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1167 if (dwc->usb2_phy) in dwc3_core_init_mode()
1168 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1169 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1170 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1172 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1180 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1181 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1189 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1196 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1198 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1200 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1203 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1206 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1214 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1217 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1219 struct device *dev = dwc->dev; in dwc3_get_properties()
1240 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1241 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1242 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1244 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1246 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1247 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1249 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1251 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1255 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1259 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1261 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1263 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1274 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1276 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1278 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1280 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1282 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1284 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1286 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1288 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1290 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1292 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1294 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1296 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1298 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1300 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1302 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1304 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1306 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1309 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1314 &dwc->hsphy_interface); in dwc3_get_properties()
1316 &dwc->fladj); in dwc3_get_properties()
1318 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1321 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1322 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1324 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1326 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1327 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1329 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1330 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1332 dwc->imod_interval = 0; in dwc3_get_properties()
1336 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1338 return ((dwc3_is_usb3(dwc) && in dwc3_has_imod()
1339 dwc->revision >= DWC3_REVISION_300A) || in dwc3_has_imod()
1340 (dwc3_is_usb31(dwc) && in dwc3_has_imod()
1341 dwc->revision >= DWC3_USB31_REVISION_120A)); in dwc3_has_imod()
1344 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1346 struct device *dev = dwc->dev; in dwc3_check_params()
1349 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1350 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1351 dwc->imod_interval = 0; in dwc3_check_params()
1361 if (!dwc->imod_interval && in dwc3_check_params()
1362 (dwc->revision == DWC3_REVISION_300A)) in dwc3_check_params()
1363 dwc->imod_interval = 1; in dwc3_check_params()
1366 switch (dwc->maximum_speed) { in dwc3_check_params()
1375 dwc->maximum_speed); in dwc3_check_params()
1379 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1384 if (dwc3_is_usb31(dwc) && in dwc3_check_params()
1385 (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == in dwc3_check_params()
1387 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1397 struct dwc3 *dwc; in dwc3_probe() local
1403 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1404 if (!dwc) in dwc3_probe()
1407 dwc->clks = devm_kmemdup(dev, dwc3_core_clks, sizeof(dwc3_core_clks), in dwc3_probe()
1409 if (!dwc->clks) in dwc3_probe()
1412 dwc->dev = dev; in dwc3_probe()
1420 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1421 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1423 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1424 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1437 dwc->regs = regs; in dwc3_probe()
1438 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1440 dwc3_get_properties(dwc); in dwc3_probe()
1442 dwc->reset = devm_reset_control_get_optional_shared(dev, NULL); in dwc3_probe()
1443 if (IS_ERR(dwc->reset)) in dwc3_probe()
1444 return PTR_ERR(dwc->reset); in dwc3_probe()
1447 dwc->num_clks = ARRAY_SIZE(dwc3_core_clks); in dwc3_probe()
1449 ret = devm_clk_bulk_get(dev, dwc->num_clks, dwc->clks); in dwc3_probe()
1457 dwc->num_clks = 0; in dwc3_probe()
1460 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1464 ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); in dwc3_probe()
1468 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1469 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1474 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1475 dwc3_cache_hwparams(dwc); in dwc3_probe()
1477 spin_lock_init(&dwc->lock); in dwc3_probe()
1489 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1491 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1496 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1500 ret = dwc3_alloc_scratch_buffers(dwc); in dwc3_probe()
1504 ret = dwc3_core_init(dwc); in dwc3_probe()
1511 dwc3_check_params(dwc); in dwc3_probe()
1513 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
1517 dwc3_debugfs_init(dwc); in dwc3_probe()
1523 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
1524 dwc3_ulpi_exit(dwc); in dwc3_probe()
1527 dwc3_free_scratch_buffers(dwc); in dwc3_probe()
1530 dwc3_free_event_buffers(dwc); in dwc3_probe()
1540 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_probe()
1542 reset_control_assert(dwc->reset); in dwc3_probe()
1549 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
1553 dwc3_debugfs_exit(dwc); in dwc3_remove()
1554 dwc3_core_exit_mode(dwc); in dwc3_remove()
1556 dwc3_core_exit(dwc); in dwc3_remove()
1557 dwc3_ulpi_exit(dwc); in dwc3_remove()
1563 dwc3_free_event_buffers(dwc); in dwc3_remove()
1564 dwc3_free_scratch_buffers(dwc); in dwc3_remove()
1570 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
1574 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
1578 ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); in dwc3_core_init_for_resume()
1582 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
1589 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_core_init_for_resume()
1591 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
1596 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
1601 switch (dwc->current_dr_role) { in dwc3_suspend_common()
1603 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
1604 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
1605 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
1606 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
1607 dwc3_core_exit(dwc); in dwc3_suspend_common()
1611 dwc3_core_exit(dwc); in dwc3_suspend_common()
1616 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
1617 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
1618 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
1621 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
1627 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
1628 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
1635 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
1636 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
1637 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
1638 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
1639 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
1642 dwc3_otg_exit(dwc); in dwc3_suspend_common()
1643 dwc3_core_exit(dwc); in dwc3_suspend_common()
1653 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
1659 switch (dwc->current_dr_role) { in dwc3_resume_common()
1661 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1665 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
1666 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
1667 dwc3_gadget_resume(dwc); in dwc3_resume_common()
1668 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
1672 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1675 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
1679 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
1680 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
1683 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
1686 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
1688 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
1689 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
1696 ret = dwc3_core_init(dwc); in dwc3_resume_common()
1700 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
1702 dwc3_otg_init(dwc); in dwc3_resume_common()
1703 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
1704 dwc3_otg_host_init(dwc); in dwc3_resume_common()
1705 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
1706 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
1707 dwc3_gadget_resume(dwc); in dwc3_resume_common()
1708 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
1720 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
1722 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
1724 if (dwc->connected) in dwc3_runtime_checks()
1738 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
1741 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
1744 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
1755 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
1760 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
1764 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
1766 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
1781 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
1783 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
1785 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
1804 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
1807 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
1818 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
1823 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()