2 * Copyright 2015 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 <asm/arch-ls102xa/immap_ls102xa.h>
15 #include <linux/compat.h>
16 #include <linux/usb/xhci-fsl.h>
17 #include <linux/usb/dwc3.h>
20 /* Declare global data pointer */
21 DECLARE_GLOBAL_DATA_PTR;
23 static struct fsl_xhci fsl_xhci;
24 unsigned long ctr_addr[] = FSL_USB_XHCI_ADDR;
26 __weak int __board_usb_init(int index, enum usb_init_type init)
31 void usb_phy_reset(struct dwc3 *dwc3_reg)
33 /* Assert USB3 PHY reset */
34 setbits_le32(&dwc3_reg->g_usb3pipectl[0], DWC3_GUSB3PIPECTL_PHYSOFTRST);
36 /* Assert USB2 PHY reset */
37 setbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
41 /* Clear USB3 PHY reset */
42 clrbits_le32(&dwc3_reg->g_usb3pipectl[0], DWC3_GUSB3PIPECTL_PHYSOFTRST);
44 /* Clear USB2 PHY reset */
45 clrbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
48 static int fsl_xhci_core_init(struct fsl_xhci *fsl_xhci)
52 ret = dwc3_core_init(fsl_xhci->dwc3_reg);
54 debug("%s:failed to initialize core\n", __func__);
58 /* We are hard-coding DWC3 core to Host Mode */
59 dwc3_set_mode(fsl_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
64 static int fsl_xhci_core_exit(struct fsl_xhci *fsl_xhci)
67 * Currently fsl socs do not support PHY shutdown from
68 * sw. But this support may be added in future socs.
73 int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
75 struct fsl_xhci *ctx = &fsl_xhci;
78 ctx->hcd = (struct xhci_hccr *)ctr_addr[index];
79 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
81 ret = board_usb_init(index, USB_INIT_HOST);
83 puts("Failed to initialize board for USB\n");
87 ret = fsl_xhci_core_init(ctx);
89 puts("Failed to initialize xhci\n");
93 *hccr = (struct xhci_hccr *)ctx->hcd;
94 *hcor = (struct xhci_hcor *)((uintptr_t) *hccr
95 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
97 debug("fsl-xhci: init hccr %lx and hcor %lx hc_length %lx\n",
98 (uintptr_t)*hccr, (uintptr_t)*hcor,
99 (uintptr_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
104 void xhci_hcd_stop(int index)
106 struct fsl_xhci *ctx = &fsl_xhci;
108 fsl_xhci_core_exit(ctx);