Lines Matching +full:ips +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
3 * core.c - DesignWare USB3 DRD Controller Core file
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
24 #include <linux/dma-mapping.h>
44 #include "../host/xhci-ext-caps.h"
49 * dwc3_get_dr_mode - Validates and sets dr_mode
55 struct device *dev = dwc->dev; in dwc3_get_dr_mode()
58 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) in dwc3_get_dr_mode()
59 dwc->dr_mode = USB_DR_MODE_OTG; in dwc3_get_dr_mode()
61 mode = dwc->dr_mode; in dwc3_get_dr_mode()
62 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_get_dr_mode()
69 return -EINVAL; in dwc3_get_dr_mode()
77 return -EINVAL; in dwc3_get_dr_mode()
92 if (mode == USB_DR_MODE_OTG && !dwc->edev && in dwc3_get_dr_mode()
94 !device_property_read_bool(dwc->dev, "usb-role-switch")) && in dwc3_get_dr_mode()
99 if (mode != dwc->dr_mode) { in dwc3_get_dr_mode()
104 dwc->dr_mode = mode; in dwc3_get_dr_mode()
115 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_enable_susphy()
116 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i)); in dwc3_enable_susphy()
117 if (enable && !dwc->dis_u3_susphy_quirk) in dwc3_enable_susphy()
122 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(i), reg); in dwc3_enable_susphy()
125 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_enable_susphy()
126 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_enable_susphy()
127 if (enable && !dwc->dis_u2_susphy_quirk) in dwc3_enable_susphy()
132 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_enable_susphy()
141 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_prtcap()
148 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_set_prtcap()
156 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_prtcap()
158 dwc->current_dr_role = mode; in dwc3_set_prtcap()
170 mutex_lock(&dwc->mutex); in __dwc3_set_mode()
171 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
172 desired_dr_role = dwc->desired_dr_role; in __dwc3_set_mode()
173 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
175 pm_runtime_get_sync(dwc->dev); in __dwc3_set_mode()
177 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) in __dwc3_set_mode()
183 if (desired_dr_role == dwc->current_dr_role) in __dwc3_set_mode()
186 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) in __dwc3_set_mode()
189 switch (dwc->current_dr_role) { in __dwc3_set_mode()
199 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
200 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in __dwc3_set_mode()
201 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
212 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || in __dwc3_set_mode()
215 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
217 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
222 * keep it consistent across different IPs, let's wait up to in __dwc3_set_mode()
227 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in __dwc3_set_mode()
229 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in __dwc3_set_mode()
232 spin_lock_irqsave(&dwc->lock, flags); in __dwc3_set_mode()
236 spin_unlock_irqrestore(&dwc->lock, flags); in __dwc3_set_mode()
242 dev_err(dwc->dev, "failed to initialize host\n"); in __dwc3_set_mode()
244 if (dwc->usb2_phy) in __dwc3_set_mode()
245 otg_set_vbus(dwc->usb2_phy->otg, true); in __dwc3_set_mode()
247 for (i = 0; i < dwc->num_usb2_ports; i++) in __dwc3_set_mode()
248 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
249 for (i = 0; i < dwc->num_usb3_ports; i++) in __dwc3_set_mode()
250 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in __dwc3_set_mode()
252 if (dwc->dis_split_quirk) { in __dwc3_set_mode()
253 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in __dwc3_set_mode()
255 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in __dwc3_set_mode()
264 if (dwc->usb2_phy) in __dwc3_set_mode()
265 otg_set_vbus(dwc->usb2_phy->otg, false); in __dwc3_set_mode()
266 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
267 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in __dwc3_set_mode()
271 dev_err(dwc->dev, "failed to initialize peripheral\n"); in __dwc3_set_mode()
282 pm_runtime_mark_last_busy(dwc->dev); in __dwc3_set_mode()
283 pm_runtime_put_autosuspend(dwc->dev); in __dwc3_set_mode()
284 mutex_unlock(&dwc->mutex); in __dwc3_set_mode()
291 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_set_mode()
294 spin_lock_irqsave(&dwc->lock, flags); in dwc3_set_mode()
295 dwc->desired_dr_role = mode; in dwc3_set_mode()
296 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_set_mode()
298 queue_work(system_freezable_wq, &dwc->drd_work); in dwc3_set_mode()
303 struct dwc3 *dwc = dep->dwc; in dwc3_core_fifo_space()
306 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, in dwc3_core_fifo_space()
307 DWC3_GDBGFIFOSPACE_NUM(dep->number) | in dwc3_core_fifo_space()
310 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); in dwc3_core_fifo_space()
316 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
327 * host-only mode, then we can return early. in dwc3_core_soft_reset()
329 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) in dwc3_core_soft_reset()
332 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
347 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_core_soft_reset()
355 } while (--retries); in dwc3_core_soft_reset()
357 dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n"); in dwc3_core_soft_reset()
358 return -ETIMEDOUT; in dwc3_core_soft_reset()
373 * dwc3_frame_length_adjustment - Adjusts frame length if required
384 if (dwc->fladj == 0) in dwc3_frame_length_adjustment()
387 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_frame_length_adjustment()
389 if (dft != dwc->fladj) { in dwc3_frame_length_adjustment()
391 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; in dwc3_frame_length_adjustment()
392 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_frame_length_adjustment()
397 * dwc3_ref_clk_period - Reference clock period configuration
412 if (dwc->ref_clk) { in dwc3_ref_clk_period()
413 rate = clk_get_rate(dwc->ref_clk); in dwc3_ref_clk_period()
417 } else if (dwc->ref_clk_per) { in dwc3_ref_clk_period()
418 period = dwc->ref_clk_per; in dwc3_ref_clk_period()
424 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); in dwc3_ref_clk_period()
427 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); in dwc3_ref_clk_period()
435 * 125000 * (NSEC_PER_SEC / (rate * period) - 1) in dwc3_ref_clk_period()
437 * but rearranged for fixed-point arithmetic. The division must be in dwc3_ref_clk_period()
438 * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and in dwc3_ref_clk_period()
448 fladj -= 125000; in dwc3_ref_clk_period()
455 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); in dwc3_ref_clk_period()
463 if (dwc->gfladj_refclk_lpm_sel) in dwc3_ref_clk_period()
466 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); in dwc3_ref_clk_period()
470 * dwc3_free_one_event_buffer - Frees one event buffer
477 dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); in dwc3_free_one_event_buffer()
481 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
493 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); in dwc3_alloc_one_event_buffer()
495 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
497 evt->dwc = dwc; in dwc3_alloc_one_event_buffer()
498 evt->length = length; in dwc3_alloc_one_event_buffer()
499 evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
500 if (!evt->cache) in dwc3_alloc_one_event_buffer()
501 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
503 evt->buf = dma_alloc_coherent(dwc->sysdev, length, in dwc3_alloc_one_event_buffer()
504 &evt->dma, GFP_KERNEL); in dwc3_alloc_one_event_buffer()
505 if (!evt->buf) in dwc3_alloc_one_event_buffer()
506 return ERR_PTR(-ENOMEM); in dwc3_alloc_one_event_buffer()
512 * dwc3_free_event_buffers - frees all allocated event buffers
519 evt = dwc->ev_buf; in dwc3_free_event_buffers()
525 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
537 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_alloc_event_buffers()
539 dwc->ev_buf = NULL; in dwc3_alloc_event_buffers()
545 dev_err(dwc->dev, "can't allocate event buffer\n"); in dwc3_alloc_event_buffers()
548 dwc->ev_buf = evt; in dwc3_alloc_event_buffers()
554 * dwc3_event_buffers_setup - setup our allocated event buffers
564 if (!dwc->ev_buf) in dwc3_event_buffers_setup()
567 evt = dwc->ev_buf; in dwc3_event_buffers_setup()
568 evt->lpos = 0; in dwc3_event_buffers_setup()
569 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), in dwc3_event_buffers_setup()
570 lower_32_bits(evt->dma)); in dwc3_event_buffers_setup()
571 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), in dwc3_event_buffers_setup()
572 upper_32_bits(evt->dma)); in dwc3_event_buffers_setup()
573 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_event_buffers_setup()
574 DWC3_GEVNTSIZ_SIZE(evt->length)); in dwc3_event_buffers_setup()
577 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_setup()
578 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_setup()
587 if (!dwc->ev_buf) in dwc3_event_buffers_cleanup()
593 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_event_buffers_cleanup()
597 evt = dwc->ev_buf; in dwc3_event_buffers_cleanup()
599 evt->lpos = 0; in dwc3_event_buffers_cleanup()
601 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); in dwc3_event_buffers_cleanup()
602 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); in dwc3_event_buffers_cleanup()
603 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK in dwc3_event_buffers_cleanup()
607 reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_event_buffers_cleanup()
608 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg); in dwc3_event_buffers_cleanup()
613 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_core_num_eps()
615 dwc->num_eps = DWC3_NUM_EPS(parms); in dwc3_core_num_eps()
620 struct dwc3_hwparams *parms = &dwc->hwparams; in dwc3_cache_hwparams()
622 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); in dwc3_cache_hwparams()
623 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); in dwc3_cache_hwparams()
624 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); in dwc3_cache_hwparams()
625 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); in dwc3_cache_hwparams()
626 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); in dwc3_cache_hwparams()
627 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); in dwc3_cache_hwparams()
628 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); in dwc3_cache_hwparams()
629 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); in dwc3_cache_hwparams()
630 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); in dwc3_cache_hwparams()
633 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); in dwc3_cache_hwparams()
638 if (dwc->gsbuscfg0_reqinfo != DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED) { in dwc3_config_soc_bus()
641 reg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_config_soc_bus()
643 reg |= DWC3_GSBUSCFG0_REQINFO(dwc->gsbuscfg0_reqinfo); in dwc3_config_soc_bus()
644 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, reg); in dwc3_config_soc_bus()
653 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_core_ulpi_init()
657 dwc->hsphy_interface && in dwc3_core_ulpi_init()
658 !strncmp(dwc->hsphy_interface, "ulpi", 4))) in dwc3_core_ulpi_init()
668 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(index)); in dwc3_ss_phy_setup()
679 if (dwc->u2ss_inp3_quirk) in dwc3_ss_phy_setup()
682 if (dwc->dis_rxdet_inp3_quirk) in dwc3_ss_phy_setup()
685 if (dwc->req_p1p2p3_quirk) in dwc3_ss_phy_setup()
688 if (dwc->del_p1p2p3_quirk) in dwc3_ss_phy_setup()
691 if (dwc->del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
694 if (dwc->lfps_filter_quirk) in dwc3_ss_phy_setup()
697 if (dwc->rx_detect_poll_quirk) in dwc3_ss_phy_setup()
700 if (dwc->tx_de_emphasis_quirk) in dwc3_ss_phy_setup()
701 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); in dwc3_ss_phy_setup()
703 if (dwc->dis_del_phy_power_chg_quirk) in dwc3_ss_phy_setup()
706 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(index), reg); in dwc3_ss_phy_setup()
715 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(index)); in dwc3_hs_phy_setup()
718 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { in dwc3_hs_phy_setup()
720 if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
721 !strncmp(dwc->hsphy_interface, "utmi", 4)) { in dwc3_hs_phy_setup()
724 } else if (dwc->hsphy_interface && in dwc3_hs_phy_setup()
725 !strncmp(dwc->hsphy_interface, "ulpi", 4)) { in dwc3_hs_phy_setup()
727 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
739 switch (dwc->hsphy_mode) { in dwc3_hs_phy_setup()
759 if (dwc->dis_enblslpm_quirk) in dwc3_hs_phy_setup()
764 if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) in dwc3_hs_phy_setup()
768 * Some ULPI USB PHY does not support internal VBUS supply, to drive in dwc3_hs_phy_setup()
772 * with an external supply. in dwc3_hs_phy_setup()
774 if (dwc->ulpi_ext_vbus_drv) in dwc3_hs_phy_setup()
777 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(index), reg); in dwc3_hs_phy_setup()
783 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
795 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_phy_setup()
801 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_setup()
816 usb_phy_init(dwc->usb2_phy); in dwc3_phy_init()
817 usb_phy_init(dwc->usb3_phy); in dwc3_phy_init()
819 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_init()
820 ret = phy_init(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
825 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_init()
826 ret = phy_init(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
853 while (--j >= 0) in dwc3_phy_init()
854 phy_exit(dwc->usb3_generic_phy[j]); in dwc3_phy_init()
857 while (--i >= 0) in dwc3_phy_init()
858 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_init()
860 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_init()
861 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_init()
870 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_exit()
871 phy_exit(dwc->usb3_generic_phy[i]); in dwc3_phy_exit()
873 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_exit()
874 phy_exit(dwc->usb2_generic_phy[i]); in dwc3_phy_exit()
876 usb_phy_shutdown(dwc->usb3_phy); in dwc3_phy_exit()
877 usb_phy_shutdown(dwc->usb2_phy); in dwc3_phy_exit()
886 usb_phy_set_suspend(dwc->usb2_phy, 0); in dwc3_phy_power_on()
887 usb_phy_set_suspend(dwc->usb3_phy, 0); in dwc3_phy_power_on()
889 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_phy_power_on()
890 ret = phy_power_on(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
895 for (j = 0; j < dwc->num_usb3_ports; j++) { in dwc3_phy_power_on()
896 ret = phy_power_on(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
904 while (--j >= 0) in dwc3_phy_power_on()
905 phy_power_off(dwc->usb3_generic_phy[j]); in dwc3_phy_power_on()
908 while (--i >= 0) in dwc3_phy_power_on()
909 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_on()
911 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_on()
912 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_on()
921 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_phy_power_off()
922 phy_power_off(dwc->usb3_generic_phy[i]); in dwc3_phy_power_off()
924 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_phy_power_off()
925 phy_power_off(dwc->usb2_generic_phy[i]); in dwc3_phy_power_off()
927 usb_phy_set_suspend(dwc->usb3_phy, 1); in dwc3_phy_power_off()
928 usb_phy_set_suspend(dwc->usb2_phy, 1); in dwc3_phy_power_off()
935 ret = clk_prepare_enable(dwc->bus_clk); in dwc3_clk_enable()
939 ret = clk_prepare_enable(dwc->ref_clk); in dwc3_clk_enable()
943 ret = clk_prepare_enable(dwc->susp_clk); in dwc3_clk_enable()
947 ret = clk_prepare_enable(dwc->utmi_clk); in dwc3_clk_enable()
951 ret = clk_prepare_enable(dwc->pipe_clk); in dwc3_clk_enable()
958 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_enable()
960 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_enable()
962 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_enable()
964 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_enable()
970 clk_disable_unprepare(dwc->pipe_clk); in dwc3_clk_disable()
971 clk_disable_unprepare(dwc->utmi_clk); in dwc3_clk_disable()
972 clk_disable_unprepare(dwc->susp_clk); in dwc3_clk_disable()
973 clk_disable_unprepare(dwc->ref_clk); in dwc3_clk_disable()
974 clk_disable_unprepare(dwc->bus_clk); in dwc3_clk_disable()
983 reset_control_assert(dwc->reset); in dwc3_core_exit()
990 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); in dwc3_core_is_valid()
991 dwc->ip = DWC3_GSNPS_ID(reg); in dwc3_core_is_valid()
995 dwc->revision = reg; in dwc3_core_is_valid()
997 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); in dwc3_core_is_valid()
998 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE); in dwc3_core_is_valid()
1012 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_core_setup_global_control()
1014 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_setup_global_control()
1015 power_opt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_core_setup_global_control()
1028 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based in dwc3_core_setup_global_control()
1031 if ((dwc->dr_mode == USB_DR_MODE_HOST || in dwc3_core_setup_global_control()
1032 dwc->dr_mode == USB_DR_MODE_OTG) && in dwc3_core_setup_global_control()
1040 * REVISIT Enabling this bit so that host-mode hibernation in dwc3_core_setup_global_control()
1041 * will work. Device-mode hibernation is not yet implemented. in dwc3_core_setup_global_control()
1065 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { in dwc3_core_setup_global_control()
1066 dev_info(dwc->dev, "Running with FPGA optimizations\n"); in dwc3_core_setup_global_control()
1067 dwc->is_fpga = true; in dwc3_core_setup_global_control()
1070 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, in dwc3_core_setup_global_control()
1071 "disable_scramble cannot be used on non-FPGA builds\n"); in dwc3_core_setup_global_control()
1073 if (dwc->disable_scramble_quirk && dwc->is_fpga) in dwc3_core_setup_global_control()
1078 if (dwc->u2exit_lfps_quirk) in dwc3_core_setup_global_control()
1084 * and falls back to high-speed mode which causes in dwc3_core_setup_global_control()
1090 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_core_setup_global_control()
1099 struct device *dev = dwc->dev; in dwc3_set_incr_burst_type()
1110 cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); in dwc3_set_incr_burst_type()
1113 * Handle property "snps,incr-burst-type-adjustment". in dwc3_set_incr_burst_type()
1119 ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment"); in dwc3_set_incr_burst_type()
1129 "snps,incr-burst-type-adjustment", vals, ntype); in dwc3_set_incr_burst_type()
1185 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); in dwc3_set_incr_burst_type()
1193 if (!dwc->susp_clk) in dwc3_set_power_down_clk_scale()
1209 scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); in dwc3_set_power_down_clk_scale()
1210 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_set_power_down_clk_scale()
1215 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_set_power_down_clk_scale()
1231 if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) { in dwc3_config_threshold()
1232 rx_thr_num = dwc->rx_thr_num_pkt_prd; in dwc3_config_threshold()
1233 rx_maxburst = dwc->rx_max_burst_prd; in dwc3_config_threshold()
1234 tx_thr_num = dwc->tx_thr_num_pkt_prd; in dwc3_config_threshold()
1235 tx_maxburst = dwc->tx_max_burst_prd; in dwc3_config_threshold()
1238 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1247 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1251 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1260 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1264 rx_thr_num = dwc->rx_thr_num_pkt; in dwc3_config_threshold()
1265 rx_maxburst = dwc->rx_max_burst; in dwc3_config_threshold()
1266 tx_thr_num = dwc->tx_thr_num_pkt; in dwc3_config_threshold()
1267 tx_maxburst = dwc->tx_max_burst; in dwc3_config_threshold()
1271 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1280 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1284 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1293 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1297 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in dwc3_config_threshold()
1306 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in dwc3_config_threshold()
1310 reg = dwc3_readl(dwc->regs, DWC3_GTXTHRCFG); in dwc3_config_threshold()
1319 dwc3_writel(dwc->regs, DWC3_GTXTHRCFG, reg); in dwc3_config_threshold()
1325 * dwc3_core_init - Low-level initialization of DWC3 Core
1336 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_init()
1342 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); in dwc3_core_init()
1348 if (!dwc->ulpi_ready) { in dwc3_core_init()
1351 if (ret == -ETIMEDOUT) { in dwc3_core_init()
1353 ret = -EPROBE_DEFER; in dwc3_core_init()
1357 dwc->ulpi_ready = true; in dwc3_core_init()
1360 if (!dwc->phys_ready) { in dwc3_core_init()
1364 dwc->phys_ready = true; in dwc3_core_init()
1397 dev_err(dwc->dev, "failed to setup event buffers\n"); in dwc3_core_init()
1407 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1409 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1422 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); in dwc3_core_init()
1424 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); in dwc3_core_init()
1431 * re-enumeration of usb device attached. All the termsel, xcvrsel, in dwc3_core_init()
1436 if (dwc->resume_hs_terminations) { in dwc3_core_init()
1437 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1439 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1443 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); in dwc3_core_init()
1461 if (dwc->dis_tx_ipgap_linecheck_quirk) in dwc3_core_init()
1464 if (dwc->parkmode_disable_ss_quirk) in dwc3_core_init()
1467 if (dwc->parkmode_disable_hs_quirk) in dwc3_core_init()
1471 if (dwc->maximum_speed == USB_SPEED_FULL || in dwc3_core_init()
1472 dwc->maximum_speed == USB_SPEED_HIGH) in dwc3_core_init()
1478 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); in dwc3_core_init()
1489 dwc->maximum_speed == USB_SPEED_SUPER) { in dwc3_core_init()
1492 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_init()
1493 reg = dwc3_readl(dwc->regs, DWC3_LLUCTL(i)); in dwc3_core_init()
1495 dwc3_writel(dwc->regs, DWC3_LLUCTL(i), reg); in dwc3_core_init()
1514 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_core_init()
1516 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_core_init()
1533 struct device *dev = dwc->dev; in dwc3_core_get_phy()
1534 struct device_node *node = dev->of_node; in dwc3_core_get_phy()
1540 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); in dwc3_core_get_phy()
1541 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); in dwc3_core_get_phy()
1543 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in dwc3_core_get_phy()
1544 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in dwc3_core_get_phy()
1547 if (IS_ERR(dwc->usb2_phy)) { in dwc3_core_get_phy()
1548 ret = PTR_ERR(dwc->usb2_phy); in dwc3_core_get_phy()
1549 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1550 dwc->usb2_phy = NULL; in dwc3_core_get_phy()
1555 if (IS_ERR(dwc->usb3_phy)) { in dwc3_core_get_phy()
1556 ret = PTR_ERR(dwc->usb3_phy); in dwc3_core_get_phy()
1557 if (ret == -ENXIO || ret == -ENODEV) in dwc3_core_get_phy()
1558 dwc->usb3_phy = NULL; in dwc3_core_get_phy()
1563 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_core_get_phy()
1564 if (dwc->num_usb2_ports == 1) in dwc3_core_get_phy()
1565 snprintf(phy_name, sizeof(phy_name), "usb2-phy"); in dwc3_core_get_phy()
1567 snprintf(phy_name, sizeof(phy_name), "usb2-%u", i); in dwc3_core_get_phy()
1569 dwc->usb2_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1570 if (IS_ERR(dwc->usb2_generic_phy[i])) { in dwc3_core_get_phy()
1571 ret = PTR_ERR(dwc->usb2_generic_phy[i]); in dwc3_core_get_phy()
1572 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1573 dwc->usb2_generic_phy[i] = NULL; in dwc3_core_get_phy()
1580 for (i = 0; i < dwc->num_usb3_ports; i++) { in dwc3_core_get_phy()
1581 if (dwc->num_usb3_ports == 1) in dwc3_core_get_phy()
1582 snprintf(phy_name, sizeof(phy_name), "usb3-phy"); in dwc3_core_get_phy()
1584 snprintf(phy_name, sizeof(phy_name), "usb3-%u", i); in dwc3_core_get_phy()
1586 dwc->usb3_generic_phy[i] = devm_phy_get(dev, phy_name); in dwc3_core_get_phy()
1587 if (IS_ERR(dwc->usb3_generic_phy[i])) { in dwc3_core_get_phy()
1588 ret = PTR_ERR(dwc->usb3_generic_phy[i]); in dwc3_core_get_phy()
1589 if (ret == -ENOSYS || ret == -ENODEV) in dwc3_core_get_phy()
1590 dwc->usb3_generic_phy[i] = NULL; in dwc3_core_get_phy()
1602 struct device *dev = dwc->dev; in dwc3_core_init_mode()
1606 switch (dwc->dr_mode) { in dwc3_core_init_mode()
1610 if (dwc->usb2_phy) in dwc3_core_init_mode()
1611 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_core_init_mode()
1612 phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1613 phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); in dwc3_core_init_mode()
1622 if (dwc->usb2_phy) in dwc3_core_init_mode()
1623 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_core_init_mode()
1624 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_core_init_mode()
1625 phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1626 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_core_init_mode()
1627 phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); in dwc3_core_init_mode()
1634 INIT_WORK(&dwc->drd_work, __dwc3_set_mode); in dwc3_core_init_mode()
1637 return dev_err_probe(dev, ret, "failed to initialize dual-role\n"); in dwc3_core_init_mode()
1640 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); in dwc3_core_init_mode()
1641 return -EINVAL; in dwc3_core_init_mode()
1649 switch (dwc->dr_mode) { in dwc3_core_exit_mode()
1664 /* de-assert DRVVBUS for HOST and OTG mode */ in dwc3_core_exit_mode()
1674 dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED; in dwc3_get_software_properties()
1678 * and non-DT (non-ABI) properties. in dwc3_get_software_properties()
1680 for (tmpdev = dwc->dev; tmpdev; tmpdev = tmpdev->parent) { in dwc3_get_software_properties()
1682 "snps,gsbuscfg0-reqinfo", in dwc3_get_software_properties()
1685 dwc->gsbuscfg0_reqinfo = gsbuscfg0_reqinfo; in dwc3_get_software_properties()
1691 struct device *dev = dwc->dev; in dwc3_get_properties()
1709 /* default to -3.5dB de-emphasis */ in dwc3_get_properties()
1728 dwc->maximum_speed = usb_get_maximum_speed(dev); in dwc3_get_properties()
1729 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); in dwc3_get_properties()
1730 dwc->dr_mode = usb_get_dr_mode(dev); in dwc3_get_properties()
1731 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); in dwc3_get_properties()
1733 dwc->sysdev_is_parent = device_property_read_bool(dev, in dwc3_get_properties()
1735 if (dwc->sysdev_is_parent) in dwc3_get_properties()
1736 dwc->sysdev = dwc->dev->parent; in dwc3_get_properties()
1738 dwc->sysdev = dwc->dev; in dwc3_get_properties()
1740 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); in dwc3_get_properties()
1742 dwc->has_lpm_erratum = device_property_read_bool(dev, in dwc3_get_properties()
1743 "snps,has-lpm-erratum"); in dwc3_get_properties()
1744 device_property_read_u8(dev, "snps,lpm-nyet-threshold", in dwc3_get_properties()
1746 dwc->is_utmi_l1_suspend = device_property_read_bool(dev, in dwc3_get_properties()
1747 "snps,is-utmi-l1-suspend"); in dwc3_get_properties()
1748 device_property_read_u8(dev, "snps,hird-threshold", in dwc3_get_properties()
1750 dwc->dis_start_transfer_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1751 "snps,dis-start-transfer-quirk"); in dwc3_get_properties()
1752 dwc->usb3_lpm_capable = device_property_read_bool(dev, in dwc3_get_properties()
1754 dwc->usb2_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1755 "snps,usb2-lpm-disable"); in dwc3_get_properties()
1756 dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev, in dwc3_get_properties()
1757 "snps,usb2-gadget-lpm-disable"); in dwc3_get_properties()
1758 device_property_read_u8(dev, "snps,rx-thr-num-pkt", in dwc3_get_properties()
1760 device_property_read_u8(dev, "snps,rx-max-burst", in dwc3_get_properties()
1762 device_property_read_u8(dev, "snps,tx-thr-num-pkt", in dwc3_get_properties()
1764 device_property_read_u8(dev, "snps,tx-max-burst", in dwc3_get_properties()
1766 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd", in dwc3_get_properties()
1768 device_property_read_u8(dev, "snps,rx-max-burst-prd", in dwc3_get_properties()
1770 device_property_read_u8(dev, "snps,tx-thr-num-pkt-prd", in dwc3_get_properties()
1772 device_property_read_u8(dev, "snps,tx-max-burst-prd", in dwc3_get_properties()
1774 device_property_read_u16(dev, "num-hc-interrupters", in dwc3_get_properties()
1780 dwc->do_fifo_resize = device_property_read_bool(dev, in dwc3_get_properties()
1781 "tx-fifo-resize"); in dwc3_get_properties()
1782 if (dwc->do_fifo_resize) in dwc3_get_properties()
1783 device_property_read_u8(dev, "tx-fifo-max-num", in dwc3_get_properties()
1786 dwc->disable_scramble_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1788 dwc->u2exit_lfps_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1790 dwc->u2ss_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1792 dwc->req_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1794 dwc->del_p1p2p3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1796 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1798 dwc->lfps_filter_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1800 dwc->rx_detect_poll_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1802 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1804 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1806 dwc->dis_enblslpm_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1808 dwc->dis_u1_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1809 "snps,dis-u1-entry-quirk"); in dwc3_get_properties()
1810 dwc->dis_u2_entry_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1811 "snps,dis-u2-entry-quirk"); in dwc3_get_properties()
1812 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1814 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1815 "snps,dis-u2-freeclk-exists-quirk"); in dwc3_get_properties()
1816 dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1817 "snps,dis-del-phy-power-chg-quirk"); in dwc3_get_properties()
1818 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1819 "snps,dis-tx-ipgap-linecheck-quirk"); in dwc3_get_properties()
1820 dwc->resume_hs_terminations = device_property_read_bool(dev, in dwc3_get_properties()
1821 "snps,resume-hs-terminations"); in dwc3_get_properties()
1822 dwc->ulpi_ext_vbus_drv = device_property_read_bool(dev, in dwc3_get_properties()
1823 "snps,ulpi-ext-vbus-drv"); in dwc3_get_properties()
1824 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1825 "snps,parkmode-disable-ss-quirk"); in dwc3_get_properties()
1826 dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1827 "snps,parkmode-disable-hs-quirk"); in dwc3_get_properties()
1828 dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, in dwc3_get_properties()
1829 "snps,gfladj-refclk-lpm-sel-quirk"); in dwc3_get_properties()
1831 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1836 &dwc->hsphy_interface); in dwc3_get_properties()
1837 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", in dwc3_get_properties()
1838 &dwc->fladj); in dwc3_get_properties()
1839 device_property_read_u32(dev, "snps,ref-clock-period-ns", in dwc3_get_properties()
1840 &dwc->ref_clk_per); in dwc3_get_properties()
1842 dwc->dis_metastability_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1845 dwc->dis_split_quirk = device_property_read_bool(dev, in dwc3_get_properties()
1846 "snps,dis-split-quirk"); in dwc3_get_properties()
1848 dwc->lpm_nyet_threshold = lpm_nyet_threshold; in dwc3_get_properties()
1849 dwc->tx_de_emphasis = tx_de_emphasis; in dwc3_get_properties()
1851 dwc->hird_threshold = hird_threshold; in dwc3_get_properties()
1853 dwc->rx_thr_num_pkt = rx_thr_num_pkt; in dwc3_get_properties()
1854 dwc->rx_max_burst = rx_max_burst; in dwc3_get_properties()
1856 dwc->tx_thr_num_pkt = tx_thr_num_pkt; in dwc3_get_properties()
1857 dwc->tx_max_burst = tx_max_burst; in dwc3_get_properties()
1859 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; in dwc3_get_properties()
1860 dwc->rx_max_burst_prd = rx_max_burst_prd; in dwc3_get_properties()
1862 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; in dwc3_get_properties()
1863 dwc->tx_max_burst_prd = tx_max_burst_prd; in dwc3_get_properties()
1865 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; in dwc3_get_properties()
1867 dwc->num_hc_interrupters = num_hc_interrupters; in dwc3_get_properties()
1880 struct device *dev = dwc->dev; in dwc3_check_params()
1882 DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); in dwc3_check_params()
1897 dwc->imod_interval = 1; in dwc3_check_params()
1900 switch (dwc->maximum_speed) { in dwc3_check_params()
1917 dwc->maximum_speed); in dwc3_check_params()
1922 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1926 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; in dwc3_check_params()
1928 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1931 dwc->maximum_speed = USB_SPEED_HIGH; in dwc3_check_params()
1934 dwc->maximum_speed = USB_SPEED_SUPER; in dwc3_check_params()
1944 * set the default to support dual-lane for DWC_usb32 and single-lane in dwc3_check_params()
1945 * for DWC_usb31 for super-speed-plus. in dwc3_check_params()
1947 if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { in dwc3_check_params()
1948 switch (dwc->max_ssp_rate) { in dwc3_check_params()
1963 dwc->max_ssp_rate = USB_SSP_GEN_2x2; in dwc3_check_params()
1965 dwc->max_ssp_rate = USB_SSP_GEN_2x1; in dwc3_check_params()
1969 dwc->max_ssp_rate = USB_SSP_GEN_1x2; in dwc3_check_params()
1979 struct device *dev = dwc->dev; in dwc3_get_extcon()
1993 if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) in dwc3_get_extcon()
1997 * Check explicitly if "usb-role-switch" is used since in dwc3_get_extcon()
2003 device_property_read_bool(dev, "usb-role-switch")) in dwc3_get_extcon()
2010 * device (and "port" node) may be missing in case of "usb-role-switch" in dwc3_get_extcon()
2013 np_phy = of_parse_phandle(dev->of_node, "phys", 0); in dwc3_get_extcon()
2017 np_conn = of_graph_get_remote_node(np_phy, -1, -1); in dwc3_get_extcon()
2029 struct device *dev = dwc->dev; in dwc3_get_clocks()
2031 if (!dev->of_node) in dwc3_get_clocks()
2036 * as required by the DT-binding. in dwc3_get_clocks()
2040 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); in dwc3_get_clocks()
2041 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2042 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2046 if (dwc->bus_clk == NULL) { in dwc3_get_clocks()
2047 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); in dwc3_get_clocks()
2048 if (IS_ERR(dwc->bus_clk)) { in dwc3_get_clocks()
2049 return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), in dwc3_get_clocks()
2054 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); in dwc3_get_clocks()
2055 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2056 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2060 if (dwc->ref_clk == NULL) { in dwc3_get_clocks()
2061 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); in dwc3_get_clocks()
2062 if (IS_ERR(dwc->ref_clk)) { in dwc3_get_clocks()
2063 return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), in dwc3_get_clocks()
2068 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); in dwc3_get_clocks()
2069 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2070 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2074 if (dwc->susp_clk == NULL) { in dwc3_get_clocks()
2075 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); in dwc3_get_clocks()
2076 if (IS_ERR(dwc->susp_clk)) { in dwc3_get_clocks()
2077 return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), in dwc3_get_clocks()
2083 dwc->utmi_clk = devm_clk_get_optional(dev, "utmi"); in dwc3_get_clocks()
2084 if (IS_ERR(dwc->utmi_clk)) { in dwc3_get_clocks()
2085 return dev_err_probe(dev, PTR_ERR(dwc->utmi_clk), in dwc3_get_clocks()
2090 dwc->pipe_clk = devm_clk_get_optional(dev, "pipe"); in dwc3_get_clocks()
2091 if (IS_ERR(dwc->pipe_clk)) { in dwc3_get_clocks()
2092 return dev_err_probe(dev, PTR_ERR(dwc->pipe_clk), in dwc3_get_clocks()
2110 base = ioremap(dwc->xhci_resources[0].start, in dwc3_get_num_ports()
2111 resource_size(&dwc->xhci_resources[0])); in dwc3_get_num_ports()
2113 return -ENOMEM; in dwc3_get_num_ports()
2127 dwc->num_usb3_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2129 dwc->num_usb2_ports += XHCI_EXT_PORT_COUNT(val); in dwc3_get_num_ports()
2131 dev_warn(dwc->dev, "unrecognized port major revision %d\n", in dwc3_get_num_ports()
2136 dev_dbg(dwc->dev, "hs-ports: %u ss-ports: %u\n", in dwc3_get_num_ports()
2137 dwc->num_usb2_ports, dwc->num_usb3_ports); in dwc3_get_num_ports()
2141 if (dwc->num_usb2_ports > DWC3_USB2_MAX_PORTS || in dwc3_get_num_ports()
2142 dwc->num_usb3_ports > DWC3_USB3_MAX_PORTS) in dwc3_get_num_ports()
2143 return -EINVAL; in dwc3_get_num_ports()
2154 ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name); in dwc3_get_usb_power_supply()
2160 return ERR_PTR(-EPROBE_DEFER); in dwc3_get_usb_power_supply()
2167 struct dwc3 *dwc = data->dwc; in dwc3_core_probe()
2168 struct device *dev = dwc->dev; in dwc3_core_probe()
2172 struct resource *res = data->res; in dwc3_core_probe()
2175 dwc->xhci_resources[0].start = res->start; in dwc3_core_probe()
2176 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + in dwc3_core_probe()
2178 dwc->xhci_resources[0].flags = res->flags; in dwc3_core_probe()
2179 dwc->xhci_resources[0].name = res->name; in dwc3_core_probe()
2183 * since it will be requested by the xhci-plat driver. in dwc3_core_probe()
2188 if (dev->of_node) { in dwc3_core_probe()
2189 struct device_node *parent = of_get_parent(dev->of_node); in dwc3_core_probe()
2191 if (of_device_is_compatible(parent, "realtek,rtd-dwc3")) { in dwc3_core_probe()
2192 dwc_res.start -= DWC3_GLOBALS_REGS_START; in dwc3_core_probe()
2203 dwc->regs = regs; in dwc3_core_probe()
2204 dwc->regs_size = resource_size(&dwc_res); in dwc3_core_probe()
2210 dwc->usb_psy = dwc3_get_usb_power_supply(dwc); in dwc3_core_probe()
2211 if (IS_ERR(dwc->usb_psy)) in dwc3_core_probe()
2212 return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n"); in dwc3_core_probe()
2214 if (!data->ignore_clocks_and_resets) { in dwc3_core_probe()
2215 dwc->reset = devm_reset_control_array_get_optional_shared(dev); in dwc3_core_probe()
2216 if (IS_ERR(dwc->reset)) { in dwc3_core_probe()
2217 ret = PTR_ERR(dwc->reset); in dwc3_core_probe()
2226 ret = reset_control_deassert(dwc->reset); in dwc3_core_probe()
2235 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); in dwc3_core_probe()
2236 ret = -ENODEV; in dwc3_core_probe()
2243 if (!dwc->sysdev_is_parent && in dwc3_core_probe()
2244 DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { in dwc3_core_probe()
2245 ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); in dwc3_core_probe()
2251 * Currently only DWC3 controllers that are host-only capable in dwc3_core_probe()
2254 hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); in dwc3_core_probe()
2260 dwc->num_usb2_ports = 1; in dwc3_core_probe()
2261 dwc->num_usb3_ports = 1; in dwc3_core_probe()
2264 spin_lock_init(&dwc->lock); in dwc3_core_probe()
2265 mutex_init(&dwc->mutex); in dwc3_core_probe()
2277 dev_err(dwc->dev, "failed to allocate event buffers\n"); in dwc3_core_probe()
2278 ret = -ENOMEM; in dwc3_core_probe()
2282 dwc->edev = dwc3_get_extcon(dwc); in dwc3_core_probe()
2283 if (IS_ERR(dwc->edev)) { in dwc3_core_probe()
2284 ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); in dwc3_core_probe()
2328 reset_control_assert(dwc->reset); in dwc3_core_probe()
2330 if (dwc->usb_psy) in dwc3_core_probe()
2331 power_supply_put(dwc->usb_psy); in dwc3_core_probe()
2345 dev_err(&pdev->dev, "missing memory resource\n"); in dwc3_probe()
2346 return -ENODEV; in dwc3_probe()
2349 dwc = devm_kzalloc(&pdev->dev, sizeof(*dwc), GFP_KERNEL); in dwc3_probe()
2351 return -ENOMEM; in dwc3_probe()
2353 dwc->dev = &pdev->dev; in dwc3_probe()
2363 pm_runtime_get_sync(dwc->dev); in dwc3_core_remove()
2371 pm_runtime_allow(dwc->dev); in dwc3_core_remove()
2372 pm_runtime_disable(dwc->dev); in dwc3_core_remove()
2373 pm_runtime_dont_use_autosuspend(dwc->dev); in dwc3_core_remove()
2374 pm_runtime_put_noidle(dwc->dev); in dwc3_core_remove()
2379 dev_set_drvdata(dwc->dev, NULL); in dwc3_core_remove()
2380 pm_runtime_set_suspended(dwc->dev); in dwc3_core_remove()
2384 if (dwc->usb_psy) in dwc3_core_remove()
2385 power_supply_put(dwc->usb_psy); in dwc3_core_remove()
2399 ret = reset_control_deassert(dwc->reset); in dwc3_core_init_for_resume()
2416 reset_control_assert(dwc->reset); in dwc3_core_init_for_resume()
2427 if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) { in dwc3_suspend_common()
2428 dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) & in dwc3_suspend_common()
2430 (dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)) & in dwc3_suspend_common()
2436 if (!dwc->susphy_state) in dwc3_suspend_common()
2440 switch (dwc->current_dr_role) { in dwc3_suspend_common()
2442 if (pm_runtime_suspended(dwc->dev)) in dwc3_suspend_common()
2447 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2451 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_suspend_common()
2457 if (dwc->dis_u2_susphy_quirk || in dwc3_suspend_common()
2458 dwc->dis_enblslpm_quirk) { in dwc3_suspend_common()
2459 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_suspend_common()
2460 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_suspend_common()
2463 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_suspend_common()
2470 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_suspend_common()
2471 phy_pm_runtime_put_sync(dwc->usb2_generic_phy[i]); in dwc3_suspend_common()
2472 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_suspend_common()
2473 phy_pm_runtime_put_sync(dwc->usb3_generic_phy[i]); in dwc3_suspend_common()
2480 if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_suspend_common()
2484 synchronize_irq(dwc->irq_gadget); in dwc3_suspend_common()
2504 switch (dwc->current_dr_role) { in dwc3_resume_common()
2514 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { in dwc3_resume_common()
2522 for (i = 0; i < dwc->num_usb2_ports; i++) { in dwc3_resume_common()
2523 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); in dwc3_resume_common()
2524 if (dwc->dis_u2_susphy_quirk) in dwc3_resume_common()
2527 if (dwc->dis_enblslpm_quirk) in dwc3_resume_common()
2530 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); in dwc3_resume_common()
2533 for (i = 0; i < dwc->num_usb2_ports; i++) in dwc3_resume_common()
2534 phy_pm_runtime_get_sync(dwc->usb2_generic_phy[i]); in dwc3_resume_common()
2535 for (i = 0; i < dwc->num_usb3_ports; i++) in dwc3_resume_common()
2536 phy_pm_runtime_get_sync(dwc->usb3_generic_phy[i]); in dwc3_resume_common()
2547 dwc3_set_prtcap(dwc, dwc->current_dr_role, true); in dwc3_resume_common()
2550 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) { in dwc3_resume_common()
2552 } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) { in dwc3_resume_common()
2564 dwc3_enable_susphy(dwc, dwc->susphy_state); in dwc3_resume_common()
2572 switch (dwc->current_dr_role) { in dwc3_runtime_checks()
2574 if (dwc->connected) in dwc3_runtime_checks()
2575 return -EBUSY; in dwc3_runtime_checks()
2591 return -EBUSY; in dwc3_runtime_suspend()
2603 struct device *dev = dwc->dev; in dwc3_runtime_resume()
2610 switch (dwc->current_dr_role) { in dwc3_runtime_resume()
2612 if (dwc->pending_events) { in dwc3_runtime_resume()
2614 dwc->pending_events = false; in dwc3_runtime_resume()
2615 enable_irq(dwc->irq_gadget); in dwc3_runtime_resume()
2632 struct device *dev = dwc->dev; in dwc3_runtime_idle()
2634 switch (dwc->current_dr_role) { in dwc3_runtime_idle()
2637 return -EBUSY; in dwc3_runtime_idle()
2671 struct device *dev = dwc->dev; in dwc3_pm_suspend()
2686 struct device *dev = dwc->dev; in dwc3_pm_resume()
2711 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && in dwc3_pm_complete()
2712 dwc->dis_split_quirk) { in dwc3_pm_complete()
2713 reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); in dwc3_pm_complete()
2715 dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); in dwc3_pm_complete()
2722 struct device *dev = dwc->dev; in dwc3_pm_prepare()
2726 * runtime suspend if runtime-suspended already in device mode. in dwc3_pm_prepare()
2728 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE && in dwc3_pm_prepare()