arm: vf610: fix double iomux configuration for vf610twr board
[u-boot/qq2440-u-boot.git] / drivers / usb / host / xhci-omap.c
blobe667810bb3dc54c1159e81b75928fe5a7a1330b3
1 /*
2 * OMAP USB HOST xHCI Controller
4 * (C) Copyright 2013
5 * Texas Instruments, <www.ti.com>
7 * Author: Dan Murphy <dmurphy@ti.com>
9 * SPDX-License-Identifier: GPL-2.0+
12 #include <common.h>
13 #include <usb.h>
14 #include <asm-generic/errno.h>
15 #include <asm/omap_common.h>
16 #include <asm/arch/cpu.h>
17 #include <asm/arch/sys_proto.h>
19 #include <linux/compat.h>
20 #include <linux/usb/dwc3.h>
21 #include <linux/usb/xhci-omap.h>
23 #include "xhci.h"
25 /* Declare global data pointer */
26 DECLARE_GLOBAL_DATA_PTR;
28 static struct omap_xhci omap;
30 inline int __board_usb_init(int index, enum usb_init_type init)
32 return 0;
34 int board_usb_init(int index, enum usb_init_type init)
35 __attribute__((weak, alias("__board_usb_init")));
37 static void dwc3_set_mode(struct dwc3 *dwc3_reg, u32 mode)
39 clrsetbits_le32(&dwc3_reg->g_ctl,
40 DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG),
41 DWC3_GCTL_PRTCAPDIR(mode));
44 static void dwc3_core_soft_reset(struct dwc3 *dwc3_reg)
46 /* Before Resetting PHY, put Core in Reset */
47 setbits_le32(&dwc3_reg->g_ctl, DWC3_GCTL_CORESOFTRESET);
49 omap_reset_usb_phy(dwc3_reg);
51 /* After PHYs are stable we can take Core out of reset state */
52 clrbits_le32(&dwc3_reg->g_ctl, DWC3_GCTL_CORESOFTRESET);
55 static int dwc3_core_init(struct dwc3 *dwc3_reg)
57 u32 reg;
58 u32 revision;
59 unsigned int dwc3_hwparams1;
61 revision = readl(&dwc3_reg->g_snpsid);
62 /* This should read as U3 followed by revision number */
63 if ((revision & DWC3_GSNPSID_MASK) != 0x55330000) {
64 puts("this is not a DesignWare USB3 DRD Core\n");
65 return -1;
68 dwc3_core_soft_reset(dwc3_reg);
70 dwc3_hwparams1 = readl(&dwc3_reg->g_hwparams1);
72 reg = readl(&dwc3_reg->g_ctl);
73 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
74 reg &= ~DWC3_GCTL_DISSCRAMBLE;
75 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc3_hwparams1)) {
76 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
77 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
78 break;
79 default:
80 debug("No power optimization available\n");
84 * WORKAROUND: DWC3 revisions <1.90a have a bug
85 * where the device can fail to connect at SuperSpeed
86 * and falls back to high-speed mode which causes
87 * the device to enter a Connect/Disconnect loop
89 if ((revision & DWC3_REVISION_MASK) < 0x190a)
90 reg |= DWC3_GCTL_U2RSTECN;
92 writel(reg, &dwc3_reg->g_ctl);
94 return 0;
97 static int omap_xhci_core_init(struct omap_xhci *omap)
99 int ret = 0;
101 omap_enable_phy(omap);
103 ret = dwc3_core_init(omap->dwc3_reg);
104 if (ret) {
105 debug("%s:failed to initialize core\n", __func__);
106 return ret;
109 /* We are hard-coding DWC3 core to Host Mode */
110 dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
112 return ret;
115 static void omap_xhci_core_exit(struct omap_xhci *omap)
117 usb_phy_power(0);
120 int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
122 struct omap_xhci *ctx = &omap;
123 int ret = 0;
125 ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
126 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
127 ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
128 ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
130 ret = board_usb_init(index, USB_INIT_HOST);
131 if (ret != 0) {
132 puts("Failed to initialize board for USB\n");
133 return ret;
136 ret = omap_xhci_core_init(ctx);
137 if (ret < 0) {
138 puts("Failed to initialize xhci\n");
139 return ret;
142 *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
143 *hcor = (struct xhci_hcor *)((uint32_t) *hccr
144 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
146 debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
147 (uint32_t)*hccr, (uint32_t)*hcor,
148 (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
150 return ret;
153 void xhci_hcd_stop(int index)
155 struct omap_xhci *ctx = &omap;
157 omap_xhci_core_exit(ctx);