blob: ec24fe05a3f28f6c1bd3a478f1baa128c2bc5115 [file] [log] [blame]
Ilya Yanok7ad75782012-02-06 03:55:33 +00001/*
2 * (C) Copyright 2011 Ilya Yanok, Emcraft Systems
3 * (C) Copyright 2004-2008
4 * Texas Instruments, <www.ti.com>
5 *
6 * Derived from Beagle Board code by
7 * Sunil Kumar <sunilsaini05@gmail.com>
8 * Shashi Ranjan <shashiranjanmca05@gmail.com>
9 *
10 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Ilya Yanok7ad75782012-02-06 03:55:33 +000012 */
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020013
Ilya Yanok7ad75782012-02-06 03:55:33 +000014#include <common.h>
15#include <usb.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000016#include <usb/ulpi.h>
17#include <errno.h>
Ilya Yanok7ad75782012-02-06 03:55:33 +000018#include <asm/io.h>
19#include <asm/gpio.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000020#include <asm/arch/ehci.h>
21#include <asm/ehci-omap.h>
Lucas Stach3494a4c2012-09-26 00:14:35 +020022
23#include "ehci.h"
Ilya Yanok7ad75782012-02-06 03:55:33 +000024
Govindraj.Redc16a02012-02-06 03:55:34 +000025static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
26static struct omap_usbtll *const usbtll = (struct omap_usbtll *)OMAP_USBTLL_BASE;
27static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
28
29static int omap_uhh_reset(void)
30{
Roger Quadros9facca72013-07-22 11:14:37 +030031/*
32 * Soft resetting the UHH module causes instability issues on
33 * all OMAPs so we just avoid it.
34 *
35 * See OMAP36xx Errata
36 * i571: USB host EHCI may stall when entering smart-standby mode
37 * i660: USBHOST Configured In Smart-Idle Can Lead To a Deadlock
38 *
39 * On OMAP4/5, soft-resetting the UHH module will put it into
40 * Smart-Idle mode and lead to a deadlock.
41 *
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.
45 */
Govindraj.Redc16a02012-02-06 03:55:34 +000046 return 0;
47}
48
49static int omap_ehci_tll_reset(void)
50{
51 unsigned long init = get_timer(0);
52
53 /* perform TLL soft reset, and wait until reset is complete */
54 writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
55
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");
60 return -EL3RST;
61 }
62
63 return 0;
64}
65
66static void omap_usbhs_hsic_init(int port)
67{
68 unsigned int reg;
69
70 /* Enable channels now */
71 reg = readl(&usbtll->channel_conf + port);
72
73 setbits_le32(&reg, (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));
78
79 writel(reg, &usbtll->channel_conf + port);
80}
81
82static void omap_ehci_soft_phy_reset(int port)
83{
84 struct ulpi_viewport ulpi_vp;
85
86 ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
87 ulpi_vp.port_num = port;
88
89 ulpi_reset(&ulpi_vp);
90}
91
Ilya Yanok7ad75782012-02-06 03:55:33 +000092inline int __board_usb_init(void)
93{
94 return 0;
95}
96int board_usb_init(void) __attribute__((weak, alias("__board_usb_init")));
97
98#if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
Dan Murphybacec782013-08-01 14:05:57 -050099 defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
100 defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000101/* controls PHY(s) reset signal(s) */
102static inline void omap_ehci_phy_reset(int on, int delay)
103{
104 /*
105 * Refer ISSUE1:
106 * Hold the PHY in RESET for enough time till
107 * PHY is settled and ready
108 */
109 if (delay && !on)
110 udelay(delay);
111#ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
112 gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
113 gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
114#endif
115#ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
116 gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
117 gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
118#endif
Dan Murphybacec782013-08-01 14:05:57 -0500119#ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
120 gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
121 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
122#endif
Ilya Yanok7ad75782012-02-06 03:55:33 +0000123
124 /* Hold the PHY in RESET for enough time till DIR is high */
125 /* Refer: ISSUE1 */
126 if (delay && on)
127 udelay(delay);
128}
129#else
130#define omap_ehci_phy_reset(on, delay) do {} while (0)
131#endif
132
133/* Reset is needed otherwise the kernel-driver will throw an error. */
Govindraj.Redc16a02012-02-06 03:55:34 +0000134int omap_ehci_hcd_stop(void)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000135{
Govindraj.Redc16a02012-02-06 03:55:34 +0000136 debug("Resetting OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000137 omap_ehci_phy_reset(1, 0);
Govindraj.Redc16a02012-02-06 03:55:34 +0000138
139 if (omap_uhh_reset() < 0)
140 return -1;
141
142 if (omap_ehci_tll_reset() < 0)
143 return -1;
144
Ilya Yanok7ad75782012-02-06 03:55:33 +0000145 return 0;
146}
147
148/*
Govindraj.Redc16a02012-02-06 03:55:34 +0000149 * Initialize the OMAP EHCI controller and PHY.
150 * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
Ilya Yanok7ad75782012-02-06 03:55:33 +0000151 * See there for additional Copyrights.
152 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200153int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
154 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000155{
156 int ret;
Govindraj.Redc16a02012-02-06 03:55:34 +0000157 unsigned int i, reg = 0, rev = 0;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000158
Govindraj.Redc16a02012-02-06 03:55:34 +0000159 debug("Initializing OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000160
161 ret = board_usb_init();
162 if (ret < 0)
163 return ret;
164
165 /* Put the PHY in RESET */
166 omap_ehci_phy_reset(1, 10);
167
Govindraj.Redc16a02012-02-06 03:55:34 +0000168 ret = omap_uhh_reset();
169 if (ret < 0)
170 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000171
Govindraj.Redc16a02012-02-06 03:55:34 +0000172 ret = omap_ehci_tll_reset();
173 if (ret)
174 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000175
176 writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
177 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
Govindraj.Redc16a02012-02-06 03:55:34 +0000178 OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000179
180 /* Put UHH in NoIdle/NoStandby mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000181 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000182
Govindraj.Redc16a02012-02-06 03:55:34 +0000183 /* setup ULPI bypass and burst configurations */
184 clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
185 (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
186 OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
187 OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
188
189 rev = readl(&uhh->rev);
190 if (rev == OMAP_USBHS_REV1) {
191 if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
192 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
193 else
194 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
195
196 if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
197 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
198 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000199 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000200
201 if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
202 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
203 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000204 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000205 } else if (rev == OMAP_USBHS_REV2) {
Dan Murphybacec782013-08-01 14:05:57 -0500206
Govindraj.Redc16a02012-02-06 03:55:34 +0000207 clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
208 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
209
Dan Murphybacec782013-08-01 14:05:57 -0500210 /* Clear port mode fields for PHY mode */
211
212 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
213 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
214
215 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
216 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
217
218 } else if (rev == OMAP_USBHS_REV2_1) {
219
220 clrsetbits_le32(&reg,
221 (OMAP_P1_MODE_CLEAR |
222 OMAP_P2_MODE_CLEAR |
223 OMAP_P3_MODE_CLEAR),
224 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
225
226 /* Clear port mode fields for PHY mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000227
228 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
229 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
230
231 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
232 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
233
234 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[2]))
235 setbits_le32(&reg, OMAP_P3_MODE_HSIC);
236 }
237
238 debug("OMAP UHH_REVISION 0x%x\n", rev);
239 writel(reg, &uhh->hostconfig);
240
241 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
242 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
243 omap_usbhs_hsic_init(i);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000244
245 omap_ehci_phy_reset(0, 10);
246
Govindraj.Redc16a02012-02-06 03:55:34 +0000247 /*
248 * An undocumented "feature" in the OMAP3 EHCI controller,
249 * causes suspended ports to be taken out of suspend when
250 * the USBCMD.Run/Stop bit is cleared (for example when
251 * we do ehci_bus_suspend).
252 * This breaks suspend-resume if the root-hub is allowed
253 * to suspend. Writing 1 to this undocumented register bit
254 * disables this feature and restores normal behavior.
255 */
256 writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
257
258 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
259 if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
260 omap_ehci_soft_phy_reset(i);
261
Lucas Stach3494a4c2012-09-26 00:14:35 +0200262 *hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
263 *hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000264
Govindraj.Redc16a02012-02-06 03:55:34 +0000265 debug("OMAP EHCI init done\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000266 return 0;
267}