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 <linux/compat.h>
15 #include <linux/usb/xhci-fsl.h>
16 #include <linux/usb/dwc3.h>
19 /* Declare global data pointer */
20 DECLARE_GLOBAL_DATA_PTR;
22 static struct fsl_xhci fsl_xhci;
23 unsigned long ctr_addr[] = FSL_USB_XHCI_ADDR;
25 __weak int __board_usb_init(int index, enum usb_init_type init)
30 void usb_phy_reset(struct dwc3 *dwc3_reg)
32 /* Assert USB3 PHY reset */
33 setbits_le32(&dwc3_reg->g_usb3pipectl[0], DWC3_GUSB3PIPECTL_PHYSOFTRST);
35 /* Assert USB2 PHY reset */
36 setbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
40 /* Clear USB3 PHY reset */
41 clrbits_le32(&dwc3_reg->g_usb3pipectl[0], DWC3_GUSB3PIPECTL_PHYSOFTRST);
43 /* Clear USB2 PHY reset */
44 clrbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
47 static int fsl_xhci_core_init(struct fsl_xhci *fsl_xhci)
51 ret = dwc3_core_init(fsl_xhci->dwc3_reg);
53 debug("%s:failed to initialize core\n", __func__);
57 /* We are hard-coding DWC3 core to Host Mode */
58 dwc3_set_mode(fsl_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
60 /* Set GFLADJ_30MHZ as 20h as per XHCI spec default value */
61 dwc3_set_fladj(fsl_xhci->dwc3_reg, GFLADJ_30MHZ_DEFAULT);
66 static int fsl_xhci_core_exit(struct fsl_xhci *fsl_xhci)
69 * Currently fsl socs do not support PHY shutdown from
70 * sw. But this support may be added in future socs.
75 int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
77 struct fsl_xhci *ctx = &fsl_xhci;
80 ctx->hcd = (struct xhci_hccr *)ctr_addr[index];
81 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
83 ret = board_usb_init(index, USB_INIT_HOST);
85 puts("Failed to initialize board for USB\n");
89 ret = fsl_xhci_core_init(ctx);
91 puts("Failed to initialize xhci\n");
95 *hccr = (struct xhci_hccr *)ctx->hcd;
96 *hcor = (struct xhci_hcor *)((uintptr_t) *hccr
97 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
99 debug("fsl-xhci: init hccr %lx and hcor %lx hc_length %lx\n",
100 (uintptr_t)*hccr, (uintptr_t)*hcor,
101 (uintptr_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
106 void xhci_hcd_stop(int index)
108 struct fsl_xhci *ctx = &fsl_xhci;
110 fsl_xhci_core_exit(ctx);