blob: 1b215c25f689793adade508823d448ddf7421236 [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 Quadrosd4f94622013-12-02 15:47:43 +020031 int timeout = 0;
32 u32 rev;
33
34 rev = readl(&uhh->rev);
35
36 /* Soft RESET */
37 writel(OMAP_UHH_SYSCONFIG_SOFTRESET, &uhh->sysc);
38
39 switch (rev) {
40 case OMAP_USBHS_REV1:
41 /* Wait for soft RESET to complete */
42 while (!(readl(&uhh->syss) & 0x1)) {
43 if (timeout > 100) {
44 printf("%s: RESET timeout\n", __func__);
45 return -1;
46 }
47 udelay(10);
48 timeout++;
49 }
50
51 /* Set No-Idle, No-Standby */
52 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
53 break;
54
55 default: /* Rev. 2 onwards */
56
57 udelay(2); /* Need to wait before accessing SYSCONFIG back */
58
59 /* Wait for soft RESET to complete */
60 while ((readl(&uhh->sysc) & 0x1)) {
61 if (timeout > 100) {
62 printf("%s: RESET timeout\n", __func__);
63 return -1;
64 }
65 udelay(10);
66 timeout++;
67 }
68
69 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
70 break;
71 }
72
Govindraj.Redc16a02012-02-06 03:55:34 +000073 return 0;
74}
75
76static int omap_ehci_tll_reset(void)
77{
78 unsigned long init = get_timer(0);
79
80 /* perform TLL soft reset, and wait until reset is complete */
81 writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
82
83 /* Wait for TLL reset to complete */
84 while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
85 if (get_timer(init) > CONFIG_SYS_HZ) {
86 debug("OMAP EHCI error: timeout resetting TLL\n");
87 return -EL3RST;
88 }
89
90 return 0;
91}
92
93static void omap_usbhs_hsic_init(int port)
94{
95 unsigned int reg;
96
97 /* Enable channels now */
98 reg = readl(&usbtll->channel_conf + port);
99
100 setbits_le32(&reg, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
101 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
102 | OMAP_TLL_CHANNEL_CONF_DRVVBUS
103 | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
104 | OMAP_TLL_CHANNEL_CONF_CHANEN));
105
106 writel(reg, &usbtll->channel_conf + port);
107}
108
Dan Murphy4f7f9352013-08-01 14:05:58 -0500109#ifdef CONFIG_USB_ULPI
Govindraj.Redc16a02012-02-06 03:55:34 +0000110static void omap_ehci_soft_phy_reset(int port)
111{
112 struct ulpi_viewport ulpi_vp;
113
114 ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
115 ulpi_vp.port_num = port;
116
117 ulpi_reset(&ulpi_vp);
118}
Dan Murphy4f7f9352013-08-01 14:05:58 -0500119#else
120static void omap_ehci_soft_phy_reset(int port)
121{
122 return;
123}
124#endif
Govindraj.Redc16a02012-02-06 03:55:34 +0000125
Ilya Yanok7ad75782012-02-06 03:55:33 +0000126#if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
Dan Murphybacec782013-08-01 14:05:57 -0500127 defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
128 defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000129/* controls PHY(s) reset signal(s) */
130static inline void omap_ehci_phy_reset(int on, int delay)
131{
132 /*
133 * Refer ISSUE1:
134 * Hold the PHY in RESET for enough time till
135 * PHY is settled and ready
136 */
137 if (delay && !on)
138 udelay(delay);
139#ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
140 gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
141 gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
142#endif
143#ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
144 gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
145 gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
146#endif
Dan Murphybacec782013-08-01 14:05:57 -0500147#ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
148 gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
149 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
150#endif
Ilya Yanok7ad75782012-02-06 03:55:33 +0000151
152 /* Hold the PHY in RESET for enough time till DIR is high */
153 /* Refer: ISSUE1 */
154 if (delay && on)
155 udelay(delay);
156}
157#else
158#define omap_ehci_phy_reset(on, delay) do {} while (0)
159#endif
160
161/* Reset is needed otherwise the kernel-driver will throw an error. */
Govindraj.Redc16a02012-02-06 03:55:34 +0000162int omap_ehci_hcd_stop(void)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000163{
Govindraj.Redc16a02012-02-06 03:55:34 +0000164 debug("Resetting OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000165 omap_ehci_phy_reset(1, 0);
Govindraj.Redc16a02012-02-06 03:55:34 +0000166
167 if (omap_uhh_reset() < 0)
168 return -1;
169
170 if (omap_ehci_tll_reset() < 0)
171 return -1;
172
Ilya Yanok7ad75782012-02-06 03:55:33 +0000173 return 0;
174}
175
176/*
Govindraj.Redc16a02012-02-06 03:55:34 +0000177 * Initialize the OMAP EHCI controller and PHY.
178 * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
Ilya Yanok7ad75782012-02-06 03:55:33 +0000179 * See there for additional Copyrights.
180 */
Mateusz Zalegad862f892013-10-04 19:22:26 +0200181int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
182 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000183{
184 int ret;
Govindraj.Redc16a02012-02-06 03:55:34 +0000185 unsigned int i, reg = 0, rev = 0;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000186
Govindraj.Redc16a02012-02-06 03:55:34 +0000187 debug("Initializing OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000188
Mateusz Zalegad862f892013-10-04 19:22:26 +0200189 ret = board_usb_init(index, USB_INIT_HOST);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000190 if (ret < 0)
191 return ret;
192
193 /* Put the PHY in RESET */
194 omap_ehci_phy_reset(1, 10);
195
Govindraj.Redc16a02012-02-06 03:55:34 +0000196 ret = omap_uhh_reset();
197 if (ret < 0)
198 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000199
Govindraj.Redc16a02012-02-06 03:55:34 +0000200 ret = omap_ehci_tll_reset();
201 if (ret)
202 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000203
204 writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
205 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
Govindraj.Redc16a02012-02-06 03:55:34 +0000206 OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000207
208 /* Put UHH in NoIdle/NoStandby mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000209 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000210
Govindraj.Redc16a02012-02-06 03:55:34 +0000211 /* setup ULPI bypass and burst configurations */
212 clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
213 (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
214 OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
215 OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
216
217 rev = readl(&uhh->rev);
218 if (rev == OMAP_USBHS_REV1) {
219 if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
220 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
221 else
222 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
223
224 if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
225 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
226 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000227 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000228
229 if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
230 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
231 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000232 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000233 } else if (rev == OMAP_USBHS_REV2) {
Dan Murphybacec782013-08-01 14:05:57 -0500234
Govindraj.Redc16a02012-02-06 03:55:34 +0000235 clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
236 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
237
Dan Murphybacec782013-08-01 14:05:57 -0500238 /* Clear port mode fields for PHY mode */
239
240 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
241 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
242
243 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
244 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
245
246 } else if (rev == OMAP_USBHS_REV2_1) {
247
248 clrsetbits_le32(&reg,
249 (OMAP_P1_MODE_CLEAR |
250 OMAP_P2_MODE_CLEAR |
251 OMAP_P3_MODE_CLEAR),
252 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
253
254 /* Clear port mode fields for PHY mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000255
256 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
257 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
258
259 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
260 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
261
262 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[2]))
263 setbits_le32(&reg, OMAP_P3_MODE_HSIC);
264 }
265
266 debug("OMAP UHH_REVISION 0x%x\n", rev);
267 writel(reg, &uhh->hostconfig);
268
269 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
270 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
271 omap_usbhs_hsic_init(i);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000272
273 omap_ehci_phy_reset(0, 10);
274
Govindraj.Redc16a02012-02-06 03:55:34 +0000275 /*
276 * An undocumented "feature" in the OMAP3 EHCI controller,
277 * causes suspended ports to be taken out of suspend when
278 * the USBCMD.Run/Stop bit is cleared (for example when
279 * we do ehci_bus_suspend).
280 * This breaks suspend-resume if the root-hub is allowed
281 * to suspend. Writing 1 to this undocumented register bit
282 * disables this feature and restores normal behavior.
283 */
284 writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
285
286 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
287 if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
288 omap_ehci_soft_phy_reset(i);
289
Lucas Stach3494a4c2012-09-26 00:14:35 +0200290 *hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
291 *hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000292
Govindraj.Redc16a02012-02-06 03:55:34 +0000293 debug("OMAP EHCI init done\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000294 return 0;
295}