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()
89 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
94 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
99 dwc->dr_mode = mode; in dwc3_get_dr_mode()
105 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) in dwc3_set_prtcap() argument
109 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
112 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
114 dwc->current_dr_role = mode; in dwc3_set_prtcap()
119 struct dwc3 *dwc = work_to_dwc(work); in __dwc3_set_mode() local
124 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
126 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
127 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
129 if (!dwc->desired_dr_role) in __dwc3_set_mode()
132 if (dwc->desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
135 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
138 switch (dwc->current_dr_role) { in __dwc3_set_mode()
140 dwc3_host_exit(dwc); in __dwc3_set_mode()
143 dwc3_gadget_exit(dwc); in __dwc3_set_mode()
144 dwc3_event_buffers_cleanup(dwc); in __dwc3_set_mode()
147 dwc3_otg_exit(dwc); in __dwc3_set_mode()
148 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
149 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
150 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
151 dwc3_otg_update(dwc, 1); in __dwc3_set_mode()
157 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
159 dwc3_set_prtcap(dwc, dwc->desired_dr_role); in __dwc3_set_mode()
161 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
163 switch (dwc->desired_dr_role) { in __dwc3_set_mode()
165 ret = dwc3_host_init(dwc); in __dwc3_set_mode()
167 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
169 if (dwc->usb2_phy) in __dwc3_set_mode()
170 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
171 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
172 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in __dwc3_set_mode()
173 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
174 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
176 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
181 dwc3_event_buffers_setup(dwc); in __dwc3_set_mode()
183 if (dwc->usb2_phy) in __dwc3_set_mode()
184 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
185 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
186 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
188 ret = dwc3_gadget_init(dwc); in __dwc3_set_mode()
190 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
193 dwc3_otg_init(dwc); in __dwc3_set_mode()
194 dwc3_otg_update(dwc, 0); in __dwc3_set_mode()
201 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
202 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
205 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) in dwc3_set_mode() argument
209 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
212 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
213 dwc->desired_dr_role = mode; in dwc3_set_mode()
214 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
216 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
221 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space() local
224 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
228 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
237 static int dwc3_core_soft_reset(struct dwc3 *dwc) in dwc3_core_soft_reset() argument
243 usb_phy_init(dwc->usb2_phy); in dwc3_core_soft_reset()
244 usb_phy_init(dwc->usb3_phy); in dwc3_core_soft_reset()
245 ret = phy_init(dwc->usb2_generic_phy); in dwc3_core_soft_reset()
249 ret = phy_init(dwc->usb3_generic_phy); in dwc3_core_soft_reset()
251 phy_exit(dwc->usb2_generic_phy); in dwc3_core_soft_reset()
260 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
263 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
265 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_core_soft_reset()
277 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
287 phy_exit(dwc->usb3_generic_phy); in dwc3_core_soft_reset()
288 phy_exit(dwc->usb2_generic_phy); in dwc3_core_soft_reset()
308 static void dwc3_frame_length_adjustment(struct dwc3 *dwc) in dwc3_frame_length_adjustment() argument
316 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
319 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
321 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
323 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
324 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
333 static void dwc3_free_one_event_buffer(struct dwc3 *dwc, in dwc3_free_one_event_buffer() argument
336 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
347 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, in dwc3_alloc_one_event_buffer() argument
352 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
356 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
358 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
362 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
374 static void dwc3_free_event_buffers(struct dwc3 *dwc) in dwc3_free_event_buffers() argument
378 evt = dwc->ev_buf; in dwc3_free_event_buffers()
380 dwc3_free_one_event_buffer(dwc, evt); in dwc3_free_event_buffers()
391 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) in dwc3_alloc_event_buffers() argument
395 evt = dwc3_alloc_one_event_buffer(dwc, length); in dwc3_alloc_event_buffers()
397 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
400 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
411 int dwc3_event_buffers_setup(struct dwc3 *dwc) in dwc3_event_buffers_setup() argument
415 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
417 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
419 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
421 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
423 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_setup()
428 void dwc3_event_buffers_cleanup(struct dwc3 *dwc) in dwc3_event_buffers_cleanup() argument
432 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
436 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
437 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
438 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
440 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); in dwc3_event_buffers_cleanup()
443 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) in dwc3_alloc_scratch_buffers() argument
445 if (!dwc->has_hibernation) in dwc3_alloc_scratch_buffers()
448 if (!dwc->nr_scratch) in dwc3_alloc_scratch_buffers()
451 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, in dwc3_alloc_scratch_buffers()
453 if (!dwc->scratchbuf) in dwc3_alloc_scratch_buffers()
459 static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) in dwc3_setup_scratch_buffers() argument
465 if (!dwc->has_hibernation) in dwc3_setup_scratch_buffers()
468 if (!dwc->nr_scratch) in dwc3_setup_scratch_buffers()
472 if (!WARN_ON(dwc->scratchbuf)) in dwc3_setup_scratch_buffers()
475 scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, in dwc3_setup_scratch_buffers()
476 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, in dwc3_setup_scratch_buffers()
478 if (dma_mapping_error(dwc->sysdev, scratch_addr)) { in dwc3_setup_scratch_buffers()
479 dev_err(dwc->sysdev, "failed to map scratch buffer\n"); in dwc3_setup_scratch_buffers()
484 dwc->scratch_addr = scratch_addr; in dwc3_setup_scratch_buffers()
488 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
495 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_setup_scratch_buffers()
503 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_setup_scratch_buffers()
510 static void dwc3_free_scratch_buffers(struct dwc3 *dwc) in dwc3_free_scratch_buffers() argument
512 if (!dwc->has_hibernation) in dwc3_free_scratch_buffers()
515 if (!dwc->nr_scratch) in dwc3_free_scratch_buffers()
519 if (!WARN_ON(dwc->scratchbuf)) in dwc3_free_scratch_buffers()
522 dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * in dwc3_free_scratch_buffers()
524 kfree(dwc->scratchbuf); in dwc3_free_scratch_buffers()
527 static void dwc3_core_num_eps(struct dwc3 *dwc) in dwc3_core_num_eps() argument
529 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
531 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
534 static void dwc3_cache_hwparams(struct dwc3 *dwc) in dwc3_cache_hwparams() argument
536 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
538 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
539 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
540 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
541 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
542 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
543 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
544 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
545 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
546 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
549 static int dwc3_core_ulpi_init(struct dwc3 *dwc) in dwc3_core_ulpi_init() argument
554 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
558 dwc->hsphy_interface && in dwc3_core_ulpi_init()
559 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
560 ret = dwc3_ulpi_init(dwc); in dwc3_core_ulpi_init()
573 static int dwc3_phy_setup(struct dwc3 *dwc) in dwc3_phy_setup() argument
578 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_phy_setup()
580 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_phy_setup()
605 if (dwc->u2ss_inp3_quirk) in dwc3_phy_setup()
608 if (dwc->dis_rxdet_inp3_quirk) in dwc3_phy_setup()
611 if (dwc->req_p1p2p3_quirk) in dwc3_phy_setup()
614 if (dwc->del_p1p2p3_quirk) in dwc3_phy_setup()
617 if (dwc->del_phy_power_chg_quirk) in dwc3_phy_setup()
620 if (dwc->lfps_filter_quirk) in dwc3_phy_setup()
623 if (dwc->rx_detect_poll_quirk) in dwc3_phy_setup()
626 if (dwc->tx_de_emphasis_quirk) in dwc3_phy_setup()
627 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_phy_setup()
629 if (dwc->dis_u3_susphy_quirk) in dwc3_phy_setup()
632 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_phy_setup()
635 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_phy_setup()
637 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_phy_setup()
640 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_phy_setup()
642 if (dwc->hsphy_interface && in dwc3_phy_setup()
643 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_phy_setup()
646 } else if (dwc->hsphy_interface && in dwc3_phy_setup()
647 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_phy_setup()
649 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
661 switch (dwc->hsphy_mode) { in dwc3_phy_setup()
695 if (dwc->dis_u2_susphy_quirk) in dwc3_phy_setup()
698 if (dwc->dis_enblslpm_quirk) in dwc3_phy_setup()
703 if (dwc->dis_u2_freeclk_exists_quirk) in dwc3_phy_setup()
706 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_phy_setup()
711 static void dwc3_core_exit(struct dwc3 *dwc) in dwc3_core_exit() argument
713 dwc3_event_buffers_cleanup(dwc); in dwc3_core_exit()
715 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_exit()
716 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_exit()
717 phy_exit(dwc->usb2_generic_phy); in dwc3_core_exit()
718 phy_exit(dwc->usb3_generic_phy); in dwc3_core_exit()
720 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_exit()
721 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_exit()
722 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_exit()
723 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_exit()
724 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_core_exit()
725 reset_control_assert(dwc->reset); in dwc3_core_exit()
728 static bool dwc3_core_is_valid(struct dwc3 *dwc) in dwc3_core_is_valid() argument
732 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
733 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
737 dwc->revision = reg; in dwc3_core_is_valid()
739 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
740 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
748 static void dwc3_core_setup_global_control(struct dwc3 *dwc) in dwc3_core_setup_global_control() argument
750 u32 hwparams4 = dwc->hwparams.hwparams4; in dwc3_core_setup_global_control()
753 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
756 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { in dwc3_core_setup_global_control()
770 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
771 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
779 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); in dwc3_core_setup_global_control()
793 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
794 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
795 dwc->is_fpga = true; in dwc3_core_setup_global_control()
798 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
801 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
806 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
818 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
821 static int dwc3_core_get_phy(struct dwc3 *dwc);
822 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
825 static void dwc3_set_incr_burst_type(struct dwc3 *dwc) in dwc3_set_incr_burst_type() argument
827 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
838 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
915 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
924 static int dwc3_core_init(struct dwc3 *dwc) in dwc3_core_init() argument
930 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
936 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
938 ret = dwc3_phy_setup(dwc); in dwc3_core_init()
942 if (!dwc->ulpi_ready) { in dwc3_core_init()
943 ret = dwc3_core_ulpi_init(dwc); in dwc3_core_init()
946 dwc->ulpi_ready = true; in dwc3_core_init()
949 if (!dwc->phys_ready) { in dwc3_core_init()
950 ret = dwc3_core_get_phy(dwc); in dwc3_core_init()
953 dwc->phys_ready = true; in dwc3_core_init()
956 ret = dwc3_core_soft_reset(dwc); in dwc3_core_init()
962 if (!dwc->dis_u3_susphy_quirk) { in dwc3_core_init()
963 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); in dwc3_core_init()
965 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); in dwc3_core_init()
968 if (!dwc->dis_u2_susphy_quirk) { in dwc3_core_init()
969 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_core_init()
971 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_core_init()
975 dwc3_core_setup_global_control(dwc); in dwc3_core_init()
976 dwc3_core_num_eps(dwc); in dwc3_core_init()
978 ret = dwc3_setup_scratch_buffers(dwc); in dwc3_core_init()
983 dwc3_frame_length_adjustment(dwc); in dwc3_core_init()
985 dwc3_set_incr_burst_type(dwc); in dwc3_core_init()
987 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_core_init()
988 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_core_init()
989 ret = phy_power_on(dwc->usb2_generic_phy); in dwc3_core_init()
993 ret = phy_power_on(dwc->usb3_generic_phy); in dwc3_core_init()
997 ret = dwc3_event_buffers_setup(dwc); in dwc3_core_init()
999 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1009 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1011 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1015 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1024 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1027 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1030 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1033 if (dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_init()
1034 dwc->dr_mode == USB_DR_MODE_OTG) { in dwc3_core_init()
1035 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_core_init()
1046 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_core_init()
1053 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_core_init()
1054 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_core_init()
1055 u8 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_core_init()
1056 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_core_init()
1057 u8 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_core_init()
1060 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_core_init()
1069 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_core_init()
1073 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_core_init()
1082 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_core_init()
1089 phy_power_off(dwc->usb3_generic_phy); in dwc3_core_init()
1092 phy_power_off(dwc->usb2_generic_phy); in dwc3_core_init()
1095 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_core_init()
1096 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_core_init()
1099 usb_phy_shutdown(dwc->usb2_phy); in dwc3_core_init()
1100 usb_phy_shutdown(dwc->usb3_phy); in dwc3_core_init()
1101 phy_exit(dwc->usb2_generic_phy); in dwc3_core_init()
1102 phy_exit(dwc->usb3_generic_phy); in dwc3_core_init()
1105 dwc3_ulpi_exit(dwc); in dwc3_core_init()
1111 static int dwc3_core_get_phy(struct dwc3 *dwc) in dwc3_core_get_phy() argument
1113 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1118 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1119 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1121 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1122 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1125 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1126 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1128 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1137 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1138 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1140 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1149 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); in dwc3_core_get_phy()
1150 if (IS_ERR(dwc->usb2_generic_phy)) { in dwc3_core_get_phy()
1151 ret = PTR_ERR(dwc->usb2_generic_phy); in dwc3_core_get_phy()
1153 dwc->usb2_generic_phy = NULL; in dwc3_core_get_phy()
1162 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); in dwc3_core_get_phy()
1163 if (IS_ERR(dwc->usb3_generic_phy)) { in dwc3_core_get_phy()
1164 ret = PTR_ERR(dwc->usb3_generic_phy); in dwc3_core_get_phy()
1166 dwc->usb3_generic_phy = NULL; in dwc3_core_get_phy()
1178 static int dwc3_core_init_mode(struct dwc3 *dwc) in dwc3_core_init_mode() argument
1180 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1183 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1185 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_init_mode()
1187 if (dwc->usb2_phy) in dwc3_core_init_mode()
1188 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1189 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1190 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1192 ret = dwc3_gadget_init(dwc); in dwc3_core_init_mode()
1200 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_core_init_mode()
1202 if (dwc->usb2_phy) in dwc3_core_init_mode()
1203 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1204 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1205 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1207 ret = dwc3_host_init(dwc); in dwc3_core_init_mode()
1215 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1216 ret = dwc3_drd_init(dwc); in dwc3_core_init_mode()
1224 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1231 static void dwc3_core_exit_mode(struct dwc3 *dwc) in dwc3_core_exit_mode() argument
1233 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1235 dwc3_gadget_exit(dwc); in dwc3_core_exit_mode()
1238 dwc3_host_exit(dwc); in dwc3_core_exit_mode()
1241 dwc3_drd_exit(dwc); in dwc3_core_exit_mode()
1249 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_core_exit_mode()
1252 static void dwc3_get_properties(struct dwc3 *dwc) in dwc3_get_properties() argument
1254 struct device *dev = dwc->dev; in dwc3_get_properties()
1275 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1276 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1277 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1279 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1281 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1282 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1284 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1286 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1290 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1294 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1296 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1298 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1309 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1311 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1313 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1315 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1317 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1319 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1321 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1323 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1325 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1327 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1329 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1331 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1333 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1335 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1337 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1339 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1341 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1343 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1346 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1351 &dwc->hsphy_interface); in dwc3_get_properties()
1353 &dwc->fladj); in dwc3_get_properties()
1355 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1358 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1361 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1362 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1364 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1366 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1367 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1369 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1370 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1372 dwc->imod_interval = 0; in dwc3_get_properties()
1376 bool dwc3_has_imod(struct dwc3 *dwc) in dwc3_has_imod() argument
1383 static void dwc3_check_params(struct dwc3 *dwc) in dwc3_check_params() argument
1385 struct device *dev = dwc->dev; in dwc3_check_params()
1387 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1390 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { in dwc3_check_params()
1391 dev_warn(dwc->dev, "Interrupt moderation not supported\n"); in dwc3_check_params()
1392 dwc->imod_interval = 0; in dwc3_check_params()
1402 if (!dwc->imod_interval && in dwc3_check_params()
1404 dwc->imod_interval = 1; in dwc3_check_params()
1407 switch (dwc->maximum_speed) { in dwc3_check_params()
1425 dwc->maximum_speed); in dwc3_check_params()
1430 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1434 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1436 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1439 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1442 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1453 struct dwc3 *dwc; in dwc3_probe() local
1459 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
1460 if (!dwc) in dwc3_probe()
1463 dwc->dev = dev; in dwc3_probe()
1471 dwc->xhci_resources[0].start = res->start; in dwc3_probe()
1472 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_probe()
1474 dwc->xhci_resources[0].flags = res->flags; in dwc3_probe()
1475 dwc->xhci_resources[0].name = res->name; in dwc3_probe()
1488 dwc->regs = regs; in dwc3_probe()
1489 dwc->regs_size = resource_size(&dwc_res); in dwc3_probe()
1491 dwc3_get_properties(dwc); in dwc3_probe()
1493 dwc->reset = devm_reset_control_array_get(dev, true, true); in dwc3_probe()
1494 if (IS_ERR(dwc->reset)) in dwc3_probe()
1495 return PTR_ERR(dwc->reset); in dwc3_probe()
1498 ret = devm_clk_bulk_get_all(dev, &dwc->clks); in dwc3_probe()
1506 dwc->num_clks = 0; in dwc3_probe()
1508 dwc->num_clks = ret; in dwc3_probe()
1512 ret = reset_control_deassert(dwc->reset); in dwc3_probe()
1516 ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); in dwc3_probe()
1520 if (!dwc3_core_is_valid(dwc)) { in dwc3_probe()
1521 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_probe()
1526 platform_set_drvdata(pdev, dwc); in dwc3_probe()
1527 dwc3_cache_hwparams(dwc); in dwc3_probe()
1529 spin_lock_init(&dwc->lock); in dwc3_probe()
1541 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); in dwc3_probe()
1543 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_probe()
1548 ret = dwc3_get_dr_mode(dwc); in dwc3_probe()
1552 ret = dwc3_alloc_scratch_buffers(dwc); in dwc3_probe()
1556 ret = dwc3_core_init(dwc); in dwc3_probe()
1563 dwc3_check_params(dwc); in dwc3_probe()
1565 ret = dwc3_core_init_mode(dwc); in dwc3_probe()
1569 dwc3_debugfs_init(dwc); in dwc3_probe()
1575 dwc3_event_buffers_cleanup(dwc); in dwc3_probe()
1577 usb_phy_shutdown(dwc->usb2_phy); in dwc3_probe()
1578 usb_phy_shutdown(dwc->usb3_phy); in dwc3_probe()
1579 phy_exit(dwc->usb2_generic_phy); in dwc3_probe()
1580 phy_exit(dwc->usb3_generic_phy); in dwc3_probe()
1582 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_probe()
1583 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_probe()
1584 phy_power_off(dwc->usb2_generic_phy); in dwc3_probe()
1585 phy_power_off(dwc->usb3_generic_phy); in dwc3_probe()
1587 dwc3_ulpi_exit(dwc); in dwc3_probe()
1590 dwc3_free_scratch_buffers(dwc); in dwc3_probe()
1593 dwc3_free_event_buffers(dwc); in dwc3_probe()
1603 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_probe()
1605 reset_control_assert(dwc->reset); in dwc3_probe()
1612 struct dwc3 *dwc = platform_get_drvdata(pdev); in dwc3_remove() local
1616 dwc3_debugfs_exit(dwc); in dwc3_remove()
1617 dwc3_core_exit_mode(dwc); in dwc3_remove()
1619 dwc3_core_exit(dwc); in dwc3_remove()
1620 dwc3_ulpi_exit(dwc); in dwc3_remove()
1626 dwc3_free_event_buffers(dwc); in dwc3_remove()
1627 dwc3_free_scratch_buffers(dwc); in dwc3_remove()
1633 static int dwc3_core_init_for_resume(struct dwc3 *dwc) in dwc3_core_init_for_resume() argument
1637 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
1641 ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); in dwc3_core_init_for_resume()
1645 ret = dwc3_core_init(dwc); in dwc3_core_init_for_resume()
1652 clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); in dwc3_core_init_for_resume()
1654 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
1659 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_suspend_common() argument
1664 switch (dwc->current_dr_role) { in dwc3_suspend_common()
1666 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
1668 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
1669 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
1670 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
1671 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
1672 dwc3_core_exit(dwc); in dwc3_suspend_common()
1676 dwc3_core_exit(dwc); in dwc3_suspend_common()
1681 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
1682 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
1683 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_suspend_common()
1686 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_suspend_common()
1692 phy_pm_runtime_put_sync(dwc->usb2_generic_phy); in dwc3_suspend_common()
1693 phy_pm_runtime_put_sync(dwc->usb3_generic_phy); in dwc3_suspend_common()
1700 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
1701 spin_lock_irqsave(&dwc->lock, flags); in dwc3_suspend_common()
1702 dwc3_gadget_suspend(dwc); in dwc3_suspend_common()
1703 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_suspend_common()
1704 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
1707 dwc3_otg_exit(dwc); in dwc3_suspend_common()
1708 dwc3_core_exit(dwc); in dwc3_suspend_common()
1718 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) in dwc3_resume_common() argument
1724 switch (dwc->current_dr_role) { in dwc3_resume_common()
1726 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1730 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); in dwc3_resume_common()
1731 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
1732 dwc3_gadget_resume(dwc); in dwc3_resume_common()
1733 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
1737 ret = dwc3_core_init_for_resume(dwc); in dwc3_resume_common()
1740 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); in dwc3_resume_common()
1744 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_resume_common()
1745 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
1748 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
1751 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_resume_common()
1753 phy_pm_runtime_get_sync(dwc->usb2_generic_phy); in dwc3_resume_common()
1754 phy_pm_runtime_get_sync(dwc->usb3_generic_phy); in dwc3_resume_common()
1761 ret = dwc3_core_init(dwc); in dwc3_resume_common()
1765 dwc3_set_prtcap(dwc, dwc->current_dr_role); in dwc3_resume_common()
1767 dwc3_otg_init(dwc); in dwc3_resume_common()
1768 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
1769 dwc3_otg_host_init(dwc); in dwc3_resume_common()
1770 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
1771 spin_lock_irqsave(&dwc->lock, flags); in dwc3_resume_common()
1772 dwc3_gadget_resume(dwc); in dwc3_resume_common()
1773 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_resume_common()
1785 static int dwc3_runtime_checks(struct dwc3 *dwc) in dwc3_runtime_checks() argument
1787 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
1789 if (dwc->connected) in dwc3_runtime_checks()
1803 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_suspend() local
1806 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_suspend()
1809 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND); in dwc3_runtime_suspend()
1820 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_resume() local
1825 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); in dwc3_runtime_resume()
1829 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
1831 dwc3_gadget_process_pending_events(dwc); in dwc3_runtime_resume()
1846 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_runtime_idle() local
1848 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
1850 if (dwc3_runtime_checks(dwc)) in dwc3_runtime_idle()
1869 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_suspend() local
1872 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); in dwc3_suspend()
1883 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_resume() local
1888 ret = dwc3_resume_common(dwc, PMSG_RESUME); in dwc3_resume()
1901 struct dwc3 *dwc = dev_get_drvdata(dev); in dwc3_complete() local
1904 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_complete()
1905 dwc->dis_split_quirk) { in dwc3_complete()
1906 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_complete()
1908 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_complete()