2 * (C) Copyright 2011 Ilya Yanok, Emcraft Systems
3 * (C) Copyright 2004-2008
4 * Texas Instruments, <www.ti.com>
6 * Derived from Beagle Board code by
7 * Sunil Kumar <sunilsaini05@gmail.com>
8 * Shashi Ranjan <shashiranjanmca05@gmail.com>
11 * SPDX-License-Identifier: GPL-2.0+
20 #include <asm/arch/ehci.h>
21 #include <asm/ehci-omap.h>
25 static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
26 static struct omap_usbtll *const usbtll = (struct omap_usbtll *)OMAP_USBTLL_BASE;
27 static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
29 static int omap_uhh_reset(void)
32 * Soft resetting the UHH module causes instability issues on
33 * all OMAPs so we just avoid it.
36 * i571: USB host EHCI may stall when entering smart-standby mode
37 * i660: USBHOST Configured In Smart-Idle Can Lead To a Deadlock
39 * On OMAP4/5, soft-resetting the UHH module will put it into
40 * Smart-Idle mode and lead to a deadlock.
42 * On OMAP3, this doesn't seem to be the case but still instabilities
43 * are observed on beagle (3530 ES1.0) if soft-reset is used.
44 * e.g. NFS root failures with Linux kernel.
49 static int omap_ehci_tll_reset(void)
51 unsigned long init = get_timer(0);
53 /* perform TLL soft reset, and wait until reset is complete */
54 writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
56 /* Wait for TLL reset to complete */
57 while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
58 if (get_timer(init) > CONFIG_SYS_HZ) {
59 debug("OMAP EHCI error: timeout resetting TLL\n");
66 static void omap_usbhs_hsic_init(int port)
70 /* Enable channels now */
71 reg = readl(&usbtll->channel_conf + port);
73 setbits_le32(®, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
74 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
75 | OMAP_TLL_CHANNEL_CONF_DRVVBUS
76 | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
77 | OMAP_TLL_CHANNEL_CONF_CHANEN));
79 writel(reg, &usbtll->channel_conf + port);
82 #ifdef CONFIG_USB_ULPI
83 static void omap_ehci_soft_phy_reset(int port)
85 struct ulpi_viewport ulpi_vp;
87 ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
88 ulpi_vp.port_num = port;
93 static void omap_ehci_soft_phy_reset(int port)
99 inline int __board_usb_init(void)
103 int board_usb_init(void) __attribute__((weak, alias("__board_usb_init")));
105 #if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
106 defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
107 defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
108 /* controls PHY(s) reset signal(s) */
109 static inline void omap_ehci_phy_reset(int on, int delay)
113 * Hold the PHY in RESET for enough time till
114 * PHY is settled and ready
118 #ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
119 gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
120 gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
122 #ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
123 gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
124 gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
126 #ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
127 gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
128 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
131 /* Hold the PHY in RESET for enough time till DIR is high */
137 #define omap_ehci_phy_reset(on, delay) do {} while (0)
140 /* Reset is needed otherwise the kernel-driver will throw an error. */
141 int omap_ehci_hcd_stop(void)
143 debug("Resetting OMAP EHCI\n");
144 omap_ehci_phy_reset(1, 0);
146 if (omap_uhh_reset() < 0)
149 if (omap_ehci_tll_reset() < 0)
156 * Initialize the OMAP EHCI controller and PHY.
157 * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
158 * See there for additional Copyrights.
160 int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
161 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
164 unsigned int i, reg = 0, rev = 0;
166 debug("Initializing OMAP EHCI\n");
168 ret = board_usb_init();
172 /* Put the PHY in RESET */
173 omap_ehci_phy_reset(1, 10);
175 ret = omap_uhh_reset();
179 ret = omap_ehci_tll_reset();
183 writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
184 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
185 OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
187 /* Put UHH in NoIdle/NoStandby mode */
188 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
190 /* setup ULPI bypass and burst configurations */
191 clrsetbits_le32(®, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
192 (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
193 OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
194 OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
196 rev = readl(&uhh->rev);
197 if (rev == OMAP_USBHS_REV1) {
198 if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
199 clrbits_le32(®, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
201 setbits_le32(®, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
203 if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
204 clrbits_le32(®, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
206 setbits_le32(®, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
208 if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
209 clrbits_le32(®, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
211 setbits_le32(®, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
212 } else if (rev == OMAP_USBHS_REV2) {
214 clrsetbits_le32(®, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
215 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
217 /* Clear port mode fields for PHY mode */
219 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
220 setbits_le32(®, OMAP_P1_MODE_HSIC);
222 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
223 setbits_le32(®, OMAP_P2_MODE_HSIC);
225 } else if (rev == OMAP_USBHS_REV2_1) {
227 clrsetbits_le32(®,
228 (OMAP_P1_MODE_CLEAR |
231 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
233 /* Clear port mode fields for PHY mode */
235 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
236 setbits_le32(®, OMAP_P1_MODE_HSIC);
238 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
239 setbits_le32(®, OMAP_P2_MODE_HSIC);
241 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[2]))
242 setbits_le32(®, OMAP_P3_MODE_HSIC);
245 debug("OMAP UHH_REVISION 0x%x\n", rev);
246 writel(reg, &uhh->hostconfig);
248 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
249 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
250 omap_usbhs_hsic_init(i);
252 omap_ehci_phy_reset(0, 10);
255 * An undocumented "feature" in the OMAP3 EHCI controller,
256 * causes suspended ports to be taken out of suspend when
257 * the USBCMD.Run/Stop bit is cleared (for example when
258 * we do ehci_bus_suspend).
259 * This breaks suspend-resume if the root-hub is allowed
260 * to suspend. Writing 1 to this undocumented register bit
261 * disables this feature and restores normal behavior.
263 writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
265 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
266 if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
267 omap_ehci_soft_phy_reset(i);
269 *hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
270 *hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
272 debug("OMAP EHCI init done\n");