2 * Copyright 2015,2016 Freescale Semiconductor, Inc.
4 * FSL USB HOST xHCI Controller
6 * Author: Ramneek Mehresh<ramneek.mehresh@freescale.com>
8 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm-generic/errno.h>
14 #include <linux/compat.h>
15 #include <linux/usb/xhci-fsl.h>
16 #include <linux/usb/dwc3.h>
18 #include <fsl_errata.h>
22 /* Declare global data pointer */
23 DECLARE_GLOBAL_DATA_PTR;
26 static struct fsl_xhci fsl_xhci;
27 unsigned long ctr_addr[] = FSL_USB_XHCI_ADDR;
29 struct xhci_fsl_priv {
30 struct xhci_ctrl xhci;
36 __weak int __board_usb_init(int index, enum usb_init_type init)
41 static int erratum_a008751(void)
43 #if defined(CONFIG_TARGET_LS2080AQDS) || defined(CONFIG_TARGET_LS2080ARDB)
44 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
45 writel(SCFG_USB3PRM1CR_INIT, scfg + SCFG_USB3PRM1CR / 4);
51 static void fsl_apply_xhci_errata(void)
54 if (has_erratum_a008751()) {
55 ret = erratum_a008751();
57 puts("Failed to apply erratum a008751\n");
61 static int fsl_xhci_core_init(struct fsl_xhci *fsl_xhci)
65 ret = dwc3_core_init(fsl_xhci->dwc3_reg);
67 debug("%s:failed to initialize core\n", __func__);
71 /* We are hard-coding DWC3 core to Host Mode */
72 dwc3_set_mode(fsl_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
74 /* Set GFLADJ_30MHZ as 20h as per XHCI spec default value */
75 dwc3_set_fladj(fsl_xhci->dwc3_reg, GFLADJ_30MHZ_DEFAULT);
80 static int fsl_xhci_core_exit(struct fsl_xhci *fsl_xhci)
83 * Currently fsl socs do not support PHY shutdown from
84 * sw. But this support may be added in future socs.
90 static int xhci_fsl_probe(struct udevice *dev)
92 struct xhci_fsl_priv *priv = dev_get_priv(dev);
93 struct xhci_hccr *hccr;
94 struct xhci_hcor *hcor;
99 * Get the base address for XHCI controller from the device node
101 priv->hcd_base = dev_get_addr(dev);
102 if (priv->hcd_base == FDT_ADDR_T_NONE) {
103 debug("Can't get the XHCI register base address\n");
106 priv->ctx.hcd = (struct xhci_hccr *)priv->hcd_base;
107 priv->ctx.dwc3_reg = (struct dwc3 *)((char *)(priv->hcd_base) +
110 fsl_apply_xhci_errata();
112 ret = fsl_xhci_core_init(&priv->ctx);
114 puts("Failed to initialize xhci\n");
118 hccr = (struct xhci_hccr *)(priv->ctx.hcd);
119 hcor = (struct xhci_hcor *)((uintptr_t) hccr
120 + HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
122 debug("xhci-fsl: init hccr %lx and hcor %lx hc_length %lx\n",
123 (uintptr_t)hccr, (uintptr_t)hcor,
124 (uintptr_t)HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
126 return xhci_register(dev, hccr, hcor);
129 static int xhci_fsl_remove(struct udevice *dev)
131 struct xhci_fsl_priv *priv = dev_get_priv(dev);
134 fsl_xhci_core_exit(&priv->ctx);
136 ret = xhci_deregister(dev);
143 static const struct udevice_id xhci_usb_ids[] = {
144 { .compatible = "fsl,layerscape-dwc3", },
148 U_BOOT_DRIVER(xhci_fsl) = {
151 .of_match = xhci_usb_ids,
152 .probe = xhci_fsl_probe,
153 .remove = xhci_fsl_remove,
154 .ops = &xhci_usb_ops,
155 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
156 .priv_auto_alloc_size = sizeof(struct xhci_fsl_priv),
157 .flags = DM_FLAG_ALLOC_PRIV_DMA,
160 int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
162 struct fsl_xhci *ctx = &fsl_xhci;
165 ctx->hcd = (struct xhci_hccr *)ctr_addr[index];
166 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
168 ret = board_usb_init(index, USB_INIT_HOST);
170 puts("Failed to initialize board for USB\n");
174 fsl_apply_xhci_errata();
176 ret = fsl_xhci_core_init(ctx);
178 puts("Failed to initialize xhci\n");
182 *hccr = (struct xhci_hccr *)ctx->hcd;
183 *hcor = (struct xhci_hcor *)((uintptr_t) *hccr
184 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
186 debug("fsl-xhci: init hccr %lx and hcor %lx hc_length %lx\n",
187 (uintptr_t)*hccr, (uintptr_t)*hcor,
188 (uintptr_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
193 void xhci_hcd_stop(int index)
195 struct fsl_xhci *ctx = &fsl_xhci;
197 fsl_xhci_core_exit(ctx);