blob: ab459c8cc927cb1a954c2ee21de03b296d84698e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanok7ad75782012-02-06 03:55:33 +00002/*
3 * (C) Copyright 2011 Ilya Yanok, Emcraft Systems
4 * (C) Copyright 2004-2008
5 * Texas Instruments, <www.ti.com>
6 *
7 * Derived from Beagle Board code by
8 * Sunil Kumar <sunilsaini05@gmail.com>
9 * Shashi Ranjan <shashiranjanmca05@gmail.com>
10 *
Ilya Yanok7ad75782012-02-06 03:55:33 +000011 */
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012
Ilya Yanok7ad75782012-02-06 03:55:33 +000013#include <common.h>
14#include <usb.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000015#include <usb/ulpi.h>
16#include <errno.h>
Ilya Yanok7ad75782012-02-06 03:55:33 +000017#include <asm/io.h>
18#include <asm/gpio.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000019#include <asm/arch/ehci.h>
20#include <asm/ehci-omap.h>
Lucas Stach3494a4c2012-09-26 00:14:35 +020021
22#include "ehci.h"
Ilya Yanok7ad75782012-02-06 03:55:33 +000023
Govindraj.Redc16a02012-02-06 03:55:34 +000024static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
25static struct omap_usbtll *const usbtll = (struct omap_usbtll *)OMAP_USBTLL_BASE;
26static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
27
28static int omap_uhh_reset(void)
29{
Roger Quadrosd4f94622013-12-02 15:47:43 +020030 int timeout = 0;
31 u32 rev;
32
33 rev = readl(&uhh->rev);
34
35 /* Soft RESET */
36 writel(OMAP_UHH_SYSCONFIG_SOFTRESET, &uhh->sysc);
37
38 switch (rev) {
39 case OMAP_USBHS_REV1:
40 /* Wait for soft RESET to complete */
41 while (!(readl(&uhh->syss) & 0x1)) {
42 if (timeout > 100) {
43 printf("%s: RESET timeout\n", __func__);
44 return -1;
45 }
46 udelay(10);
47 timeout++;
48 }
49
50 /* Set No-Idle, No-Standby */
51 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
52 break;
53
54 default: /* Rev. 2 onwards */
55
56 udelay(2); /* Need to wait before accessing SYSCONFIG back */
57
58 /* Wait for soft RESET to complete */
59 while ((readl(&uhh->sysc) & 0x1)) {
60 if (timeout > 100) {
61 printf("%s: RESET timeout\n", __func__);
62 return -1;
63 }
64 udelay(10);
65 timeout++;
66 }
67
68 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
69 break;
70 }
71
Govindraj.Redc16a02012-02-06 03:55:34 +000072 return 0;
73}
74
75static int omap_ehci_tll_reset(void)
76{
77 unsigned long init = get_timer(0);
78
79 /* perform TLL soft reset, and wait until reset is complete */
80 writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
81
82 /* Wait for TLL reset to complete */
83 while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
84 if (get_timer(init) > CONFIG_SYS_HZ) {
85 debug("OMAP EHCI error: timeout resetting TLL\n");
86 return -EL3RST;
87 }
88
89 return 0;
90}
91
92static void omap_usbhs_hsic_init(int port)
93{
94 unsigned int reg;
95
96 /* Enable channels now */
97 reg = readl(&usbtll->channel_conf + port);
98
99 setbits_le32(&reg, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
100 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
101 | OMAP_TLL_CHANNEL_CONF_DRVVBUS
102 | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
103 | OMAP_TLL_CHANNEL_CONF_CHANEN));
104
105 writel(reg, &usbtll->channel_conf + port);
106}
107
Dan Murphy4f7f9352013-08-01 14:05:58 -0500108#ifdef CONFIG_USB_ULPI
Govindraj.Redc16a02012-02-06 03:55:34 +0000109static void omap_ehci_soft_phy_reset(int port)
110{
111 struct ulpi_viewport ulpi_vp;
112
113 ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
114 ulpi_vp.port_num = port;
115
116 ulpi_reset(&ulpi_vp);
117}
Dan Murphy4f7f9352013-08-01 14:05:58 -0500118#else
119static void omap_ehci_soft_phy_reset(int port)
120{
121 return;
122}
123#endif
Govindraj.Redc16a02012-02-06 03:55:34 +0000124
Ilya Yanok7ad75782012-02-06 03:55:33 +0000125#if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
Dan Murphybacec782013-08-01 14:05:57 -0500126 defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
127 defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000128/* controls PHY(s) reset signal(s) */
129static inline void omap_ehci_phy_reset(int on, int delay)
130{
131 /*
132 * Refer ISSUE1:
133 * Hold the PHY in RESET for enough time till
134 * PHY is settled and ready
135 */
136 if (delay && !on)
137 udelay(delay);
138#ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
139 gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
140 gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
141#endif
142#ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
143 gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
144 gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
145#endif
Dan Murphybacec782013-08-01 14:05:57 -0500146#ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
147 gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
148 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
149#endif
Ilya Yanok7ad75782012-02-06 03:55:33 +0000150
151 /* Hold the PHY in RESET for enough time till DIR is high */
152 /* Refer: ISSUE1 */
153 if (delay && on)
154 udelay(delay);
155}
156#else
157#define omap_ehci_phy_reset(on, delay) do {} while (0)
158#endif
159
160/* Reset is needed otherwise the kernel-driver will throw an error. */
Govindraj.Redc16a02012-02-06 03:55:34 +0000161int omap_ehci_hcd_stop(void)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000162{
Govindraj.Redc16a02012-02-06 03:55:34 +0000163 debug("Resetting OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000164 omap_ehci_phy_reset(1, 0);
Govindraj.Redc16a02012-02-06 03:55:34 +0000165
166 if (omap_uhh_reset() < 0)
167 return -1;
168
169 if (omap_ehci_tll_reset() < 0)
170 return -1;
171
Ilya Yanok7ad75782012-02-06 03:55:33 +0000172 return 0;
173}
174
175/*
Govindraj.Redc16a02012-02-06 03:55:34 +0000176 * Initialize the OMAP EHCI controller and PHY.
177 * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
Ilya Yanok7ad75782012-02-06 03:55:33 +0000178 * See there for additional Copyrights.
179 */
Mateusz Zalegad862f892013-10-04 19:22:26 +0200180int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
181 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000182{
183 int ret;
Govindraj.Redc16a02012-02-06 03:55:34 +0000184 unsigned int i, reg = 0, rev = 0;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000185
Govindraj.Redc16a02012-02-06 03:55:34 +0000186 debug("Initializing OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000187
Mateusz Zalegad862f892013-10-04 19:22:26 +0200188 ret = board_usb_init(index, USB_INIT_HOST);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000189 if (ret < 0)
190 return ret;
191
192 /* Put the PHY in RESET */
193 omap_ehci_phy_reset(1, 10);
194
Govindraj.Redc16a02012-02-06 03:55:34 +0000195 ret = omap_uhh_reset();
196 if (ret < 0)
197 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000198
Govindraj.Redc16a02012-02-06 03:55:34 +0000199 ret = omap_ehci_tll_reset();
200 if (ret)
201 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000202
203 writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
204 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
Govindraj.Redc16a02012-02-06 03:55:34 +0000205 OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000206
207 /* Put UHH in NoIdle/NoStandby mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000208 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000209
Govindraj.Redc16a02012-02-06 03:55:34 +0000210 /* setup ULPI bypass and burst configurations */
211 clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
212 (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
213 OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
214 OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
215
216 rev = readl(&uhh->rev);
217 if (rev == OMAP_USBHS_REV1) {
218 if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
219 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
220 else
221 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
222
223 if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
224 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
225 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000226 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000227
228 if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
229 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
230 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000231 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000232 } else if (rev == OMAP_USBHS_REV2) {
Dan Murphybacec782013-08-01 14:05:57 -0500233
Govindraj.Redc16a02012-02-06 03:55:34 +0000234 clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
235 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
236
Dan Murphybacec782013-08-01 14:05:57 -0500237 /* Clear port mode fields for PHY mode */
238
239 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
240 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
241
242 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
243 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
244
245 } else if (rev == OMAP_USBHS_REV2_1) {
246
247 clrsetbits_le32(&reg,
248 (OMAP_P1_MODE_CLEAR |
249 OMAP_P2_MODE_CLEAR |
250 OMAP_P3_MODE_CLEAR),
251 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
252
253 /* Clear port mode fields for PHY mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000254
255 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
256 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
257
258 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
259 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
260
261 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[2]))
262 setbits_le32(&reg, OMAP_P3_MODE_HSIC);
263 }
264
265 debug("OMAP UHH_REVISION 0x%x\n", rev);
266 writel(reg, &uhh->hostconfig);
267
268 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
269 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
270 omap_usbhs_hsic_init(i);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000271
272 omap_ehci_phy_reset(0, 10);
273
Govindraj.Redc16a02012-02-06 03:55:34 +0000274 /*
275 * An undocumented "feature" in the OMAP3 EHCI controller,
276 * causes suspended ports to be taken out of suspend when
277 * the USBCMD.Run/Stop bit is cleared (for example when
278 * we do ehci_bus_suspend).
279 * This breaks suspend-resume if the root-hub is allowed
280 * to suspend. Writing 1 to this undocumented register bit
281 * disables this feature and restores normal behavior.
282 */
283 writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
284
285 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
286 if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
287 omap_ehci_soft_phy_reset(i);
288
Lucas Stach3494a4c2012-09-26 00:14:35 +0200289 *hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
290 *hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000291
Govindraj.Redc16a02012-02-06 03:55:34 +0000292 debug("OMAP EHCI init done\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000293 return 0;
294}