2 * SAMSUNG EXYNOS5 USB HOST XHCI Controller
4 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 * Vivek Gautam <gautam.vivek@samsung.com>
6 * Vikas Sajjan <vikas.sajjan@samsung.com>
8 * SPDX-License-Identifier: GPL-2.0+
12 * This file is a conglomeration for DWC3-init sequence and further
13 * exynos5 specific PHY-init sequence.
22 #include <asm/arch/cpu.h>
23 #include <asm/arch/power.h>
24 #include <asm/arch/xhci-exynos.h>
25 #include <asm-generic/errno.h>
26 #include <linux/compat.h>
27 #include <linux/usb/dwc3.h>
31 /* Declare global data pointer */
32 DECLARE_GLOBAL_DATA_PTR;
35 * Contains pointers to register base addresses
36 * for the usb controller.
39 struct exynos_usb3_phy *usb3_phy;
40 struct xhci_hccr *hcd;
41 struct dwc3 *dwc3_reg;
44 static struct exynos_xhci exynos;
46 #ifdef CONFIG_OF_CONTROL
47 static int exynos_usb3_parse_dt(const void *blob, struct exynos_xhci *exynos)
53 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_XHCI);
55 debug("XHCI: Can't get device node for xhci\n");
60 * Get the base address for XHCI controller from the device node
62 addr = fdtdec_get_addr(blob, node, "reg");
63 if (addr == FDT_ADDR_T_NONE) {
64 debug("Can't get the XHCI register base address\n");
67 exynos->hcd = (struct xhci_hccr *)addr;
70 node = fdtdec_next_compatible_subnode(blob, node,
71 COMPAT_SAMSUNG_EXYNOS5_USB3_PHY, &depth);
73 debug("XHCI: Can't get device node for usb3-phy controller\n");
78 * Get the base address for usbphy from the device node
80 exynos->usb3_phy = (struct exynos_usb3_phy *)fdtdec_get_addr(blob, node,
82 if (exynos->usb3_phy == NULL) {
83 debug("Can't get the usbphy register address\n");
91 static void exynos5_usb3_phy_init(struct exynos_usb3_phy *phy)
95 /* enabling usb_drd phy */
96 set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN);
98 /* Reset USB 3.0 PHY */
99 writel(0x0, &phy->phy_reg0);
101 clrbits_le32(&phy->phy_param0,
102 /* Select PHY CLK source */
103 PHYPARAM0_REF_USE_PAD |
104 /* Set Loss-of-Signal Detector sensitivity */
105 PHYPARAM0_REF_LOSLEVEL_MASK);
106 setbits_le32(&phy->phy_param0, PHYPARAM0_REF_LOSLEVEL);
108 writel(0x0, &phy->phy_resume);
111 * Setting the Frame length Adj value[6:1] to default 0x20
112 * See xHCI 1.0 spec, 5.2.4
114 setbits_le32(&phy->link_system,
115 LINKSYSTEM_XHCI_VERSION_CONTROL |
116 LINKSYSTEM_FLADJ(0x20));
118 /* Set Tx De-Emphasis level */
119 clrbits_le32(&phy->phy_param1, PHYPARAM1_PCS_TXDEEMPH_MASK);
120 setbits_le32(&phy->phy_param1, PHYPARAM1_PCS_TXDEEMPH);
122 setbits_le32(&phy->phy_batchg, PHYBATCHG_UTMI_CLKSEL);
124 /* PHYTEST POWERDOWN Control */
125 clrbits_le32(&phy->phy_test,
126 PHYTEST_POWERDOWN_SSP |
127 PHYTEST_POWERDOWN_HSP);
129 /* UTMI Power Control */
130 writel(PHYUTMI_OTGDISABLE, &phy->phy_utmi);
132 /* Use core clock from main PLL */
133 reg = PHYCLKRST_REFCLKSEL_EXT_REFCLK |
134 /* Default 24Mhz crystal clock */
135 PHYCLKRST_FSEL(FSEL_CLKSEL_24M) |
136 PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF |
137 PHYCLKRST_SSC_REFCLKSEL(0x88) |
138 /* Force PortReset of PHY */
139 PHYCLKRST_PORTRESET |
140 /* Digital power supply in normal operating mode */
141 PHYCLKRST_RETENABLEN |
142 /* Enable ref clock for SS function */
143 PHYCLKRST_REF_SSP_EN |
144 /* Enable spread spectrum */
146 /* Power down HS Bias and PLL blocks in suspend mode */
149 writel(reg, &phy->phy_clk_rst);
151 /* giving time to Phy clock to settle before resetting */
154 reg &= ~PHYCLKRST_PORTRESET;
155 writel(reg, &phy->phy_clk_rst);
158 static void exynos5_usb3_phy_exit(struct exynos_usb3_phy *phy)
160 setbits_le32(&phy->phy_utmi,
162 PHYUTMI_FORCESUSPEND |
165 clrbits_le32(&phy->phy_clk_rst,
166 PHYCLKRST_REF_SSP_EN |
168 PHYCLKRST_COMMONONN);
170 /* PHYTEST POWERDOWN Control to remove leakage current */
171 setbits_le32(&phy->phy_test,
172 PHYTEST_POWERDOWN_SSP |
173 PHYTEST_POWERDOWN_HSP);
175 /* disabling usb_drd phy */
176 set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_DISABLE);
179 void dwc3_set_mode(struct dwc3 *dwc3_reg, u32 mode)
181 clrsetbits_le32(&dwc3_reg->g_ctl,
182 DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG),
183 DWC3_GCTL_PRTCAPDIR(mode));
186 static void dwc3_core_soft_reset(struct dwc3 *dwc3_reg)
188 /* Before Resetting PHY, put Core in Reset */
189 setbits_le32(&dwc3_reg->g_ctl,
190 DWC3_GCTL_CORESOFTRESET);
192 /* Assert USB3 PHY reset */
193 setbits_le32(&dwc3_reg->g_usb3pipectl[0],
194 DWC3_GUSB3PIPECTL_PHYSOFTRST);
196 /* Assert USB2 PHY reset */
197 setbits_le32(&dwc3_reg->g_usb2phycfg,
198 DWC3_GUSB2PHYCFG_PHYSOFTRST);
202 /* Clear USB3 PHY reset */
203 clrbits_le32(&dwc3_reg->g_usb3pipectl[0],
204 DWC3_GUSB3PIPECTL_PHYSOFTRST);
206 /* Clear USB2 PHY reset */
207 clrbits_le32(&dwc3_reg->g_usb2phycfg,
208 DWC3_GUSB2PHYCFG_PHYSOFTRST);
210 /* After PHYs are stable we can take Core out of reset state */
211 clrbits_le32(&dwc3_reg->g_ctl,
212 DWC3_GCTL_CORESOFTRESET);
215 static int dwc3_core_init(struct dwc3 *dwc3_reg)
219 unsigned int dwc3_hwparams1;
221 revision = readl(&dwc3_reg->g_snpsid);
222 /* This should read as U3 followed by revision number */
223 if ((revision & DWC3_GSNPSID_MASK) != 0x55330000) {
224 puts("this is not a DesignWare USB3 DRD Core\n");
228 dwc3_core_soft_reset(dwc3_reg);
230 dwc3_hwparams1 = readl(&dwc3_reg->g_hwparams1);
232 reg = readl(&dwc3_reg->g_ctl);
233 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
234 reg &= ~DWC3_GCTL_DISSCRAMBLE;
235 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc3_hwparams1)) {
236 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
237 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
240 debug("No power optimization available\n");
244 * WORKAROUND: DWC3 revisions <1.90a have a bug
245 * where the device can fail to connect at SuperSpeed
246 * and falls back to high-speed mode which causes
247 * the device to enter a Connect/Disconnect loop
249 if ((revision & DWC3_REVISION_MASK) < 0x190a)
250 reg |= DWC3_GCTL_U2RSTECN;
252 writel(reg, &dwc3_reg->g_ctl);
257 static int exynos_xhci_core_init(struct exynos_xhci *exynos)
261 exynos5_usb3_phy_init(exynos->usb3_phy);
263 ret = dwc3_core_init(exynos->dwc3_reg);
265 debug("failed to initialize core\n");
269 /* We are hard-coding DWC3 core to Host Mode */
270 dwc3_set_mode(exynos->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
275 static void exynos_xhci_core_exit(struct exynos_xhci *exynos)
277 exynos5_usb3_phy_exit(exynos->usb3_phy);
280 int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
282 struct exynos_xhci *ctx = &exynos;
285 #ifdef CONFIG_OF_CONTROL
286 exynos_usb3_parse_dt(gd->fdt_blob, ctx);
288 ctx->usb3_phy = (struct exynos_usb3_phy *)samsung_get_base_usb3_phy();
289 ctx->hcd = (struct xhci_hccr *)samsung_get_base_usb_xhci();
292 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
294 ret = exynos_xhci_core_init(ctx);
296 puts("XHCI: failed to initialize controller\n");
301 *hcor = (struct xhci_hcor *)((uint32_t) *hccr
302 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
304 debug("Exynos5-xhci: init hccr %x and hcor %x hc_length %d\n",
305 (uint32_t)*hccr, (uint32_t)*hcor,
306 (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
311 void xhci_hcd_stop(int index)
313 struct exynos_xhci *ctx = &exynos;
315 exynos_xhci_core_exit(ctx);