blob: d5facf10e120a20f85deb7e94239f419a50b93d1 [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>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Ilya Yanok7ad75782012-02-06 03:55:33 +000015#include <usb.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000017#include <usb/ulpi.h>
18#include <errno.h>
Ilya Yanok7ad75782012-02-06 03:55:33 +000019#include <asm/io.h>
20#include <asm/gpio.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000021#include <asm/arch/ehci.h>
22#include <asm/ehci-omap.h>
Adam Fordcb167e82020-05-16 01:19:53 -050023#include <dm.h>
24#include <dm/device-internal.h>
25#include <dm/lists.h>
26#include <power/regulator.h>
Lucas Stach3494a4c2012-09-26 00:14:35 +020027
28#include "ehci.h"
Ilya Yanok7ad75782012-02-06 03:55:33 +000029
Govindraj.Redc16a02012-02-06 03:55:34 +000030static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
31static struct omap_usbtll *const usbtll = (struct omap_usbtll *)OMAP_USBTLL_BASE;
32static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
33
34static int omap_uhh_reset(void)
35{
Roger Quadrosd4f94622013-12-02 15:47:43 +020036 int timeout = 0;
37 u32 rev;
38
39 rev = readl(&uhh->rev);
40
41 /* Soft RESET */
42 writel(OMAP_UHH_SYSCONFIG_SOFTRESET, &uhh->sysc);
43
44 switch (rev) {
45 case OMAP_USBHS_REV1:
46 /* Wait for soft RESET to complete */
47 while (!(readl(&uhh->syss) & 0x1)) {
48 if (timeout > 100) {
49 printf("%s: RESET timeout\n", __func__);
50 return -1;
51 }
52 udelay(10);
53 timeout++;
54 }
55
56 /* Set No-Idle, No-Standby */
57 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
58 break;
59
60 default: /* Rev. 2 onwards */
61
62 udelay(2); /* Need to wait before accessing SYSCONFIG back */
63
64 /* Wait for soft RESET to complete */
65 while ((readl(&uhh->sysc) & 0x1)) {
66 if (timeout > 100) {
67 printf("%s: RESET timeout\n", __func__);
68 return -1;
69 }
70 udelay(10);
71 timeout++;
72 }
73
74 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
75 break;
76 }
77
Govindraj.Redc16a02012-02-06 03:55:34 +000078 return 0;
79}
80
81static int omap_ehci_tll_reset(void)
82{
83 unsigned long init = get_timer(0);
84
85 /* perform TLL soft reset, and wait until reset is complete */
86 writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
87
88 /* Wait for TLL reset to complete */
89 while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
90 if (get_timer(init) > CONFIG_SYS_HZ) {
91 debug("OMAP EHCI error: timeout resetting TLL\n");
92 return -EL3RST;
93 }
94
95 return 0;
96}
97
98static void omap_usbhs_hsic_init(int port)
99{
100 unsigned int reg;
101
102 /* Enable channels now */
103 reg = readl(&usbtll->channel_conf + port);
104
105 setbits_le32(&reg, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
106 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
107 | OMAP_TLL_CHANNEL_CONF_DRVVBUS
108 | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
109 | OMAP_TLL_CHANNEL_CONF_CHANEN));
110
111 writel(reg, &usbtll->channel_conf + port);
112}
113
Dan Murphy4f7f9352013-08-01 14:05:58 -0500114#ifdef CONFIG_USB_ULPI
Govindraj.Redc16a02012-02-06 03:55:34 +0000115static void omap_ehci_soft_phy_reset(int port)
116{
117 struct ulpi_viewport ulpi_vp;
118
119 ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
120 ulpi_vp.port_num = port;
121
122 ulpi_reset(&ulpi_vp);
123}
Dan Murphy4f7f9352013-08-01 14:05:58 -0500124#else
125static void omap_ehci_soft_phy_reset(int port)
126{
127 return;
128}
129#endif
Govindraj.Redc16a02012-02-06 03:55:34 +0000130
Ilya Yanok7ad75782012-02-06 03:55:33 +0000131#if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
Dan Murphybacec782013-08-01 14:05:57 -0500132 defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
133 defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000134/* controls PHY(s) reset signal(s) */
135static inline void omap_ehci_phy_reset(int on, int delay)
136{
137 /*
138 * Refer ISSUE1:
139 * Hold the PHY in RESET for enough time till
140 * PHY is settled and ready
141 */
142 if (delay && !on)
143 udelay(delay);
144#ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
145 gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
146 gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
147#endif
148#ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
149 gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
150 gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
151#endif
Dan Murphybacec782013-08-01 14:05:57 -0500152#ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
153 gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
154 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
155#endif
Ilya Yanok7ad75782012-02-06 03:55:33 +0000156
157 /* Hold the PHY in RESET for enough time till DIR is high */
158 /* Refer: ISSUE1 */
159 if (delay && on)
160 udelay(delay);
161}
162#else
163#define omap_ehci_phy_reset(on, delay) do {} while (0)
164#endif
165
166/* Reset is needed otherwise the kernel-driver will throw an error. */
Govindraj.Redc16a02012-02-06 03:55:34 +0000167int omap_ehci_hcd_stop(void)
Ilya Yanok7ad75782012-02-06 03:55:33 +0000168{
Govindraj.Redc16a02012-02-06 03:55:34 +0000169 debug("Resetting OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000170 omap_ehci_phy_reset(1, 0);
Govindraj.Redc16a02012-02-06 03:55:34 +0000171
172 if (omap_uhh_reset() < 0)
173 return -1;
174
175 if (omap_ehci_tll_reset() < 0)
176 return -1;
177
Ilya Yanok7ad75782012-02-06 03:55:33 +0000178 return 0;
179}
180
181/*
Govindraj.Redc16a02012-02-06 03:55:34 +0000182 * Initialize the OMAP EHCI controller and PHY.
183 * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
Ilya Yanok7ad75782012-02-06 03:55:33 +0000184 * See there for additional Copyrights.
185 */
Adam Fordcb167e82020-05-16 01:19:53 -0500186int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata)
187{
Ilya Yanok7ad75782012-02-06 03:55:33 +0000188 int ret;
Govindraj.Redc16a02012-02-06 03:55:34 +0000189 unsigned int i, reg = 0, rev = 0;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000190
Govindraj.Redc16a02012-02-06 03:55:34 +0000191 debug("Initializing OMAP EHCI\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000192
Mateusz Zalegad862f892013-10-04 19:22:26 +0200193 ret = board_usb_init(index, USB_INIT_HOST);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000194 if (ret < 0)
195 return ret;
196
197 /* Put the PHY in RESET */
198 omap_ehci_phy_reset(1, 10);
199
Govindraj.Redc16a02012-02-06 03:55:34 +0000200 ret = omap_uhh_reset();
201 if (ret < 0)
202 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000203
Govindraj.Redc16a02012-02-06 03:55:34 +0000204 ret = omap_ehci_tll_reset();
205 if (ret)
206 return ret;
Ilya Yanok7ad75782012-02-06 03:55:33 +0000207
208 writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
209 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
Govindraj.Redc16a02012-02-06 03:55:34 +0000210 OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000211
212 /* Put UHH in NoIdle/NoStandby mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000213 writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000214
Govindraj.Redc16a02012-02-06 03:55:34 +0000215 /* setup ULPI bypass and burst configurations */
216 clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
217 (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
218 OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
219 OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
220
221 rev = readl(&uhh->rev);
222 if (rev == OMAP_USBHS_REV1) {
223 if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
224 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
225 else
226 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
227
228 if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
229 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
230 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000231 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000232
233 if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
234 clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
235 else
Jeroen Hofstee2addcfd2012-04-19 11:25:18 +0000236 setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
Govindraj.Redc16a02012-02-06 03:55:34 +0000237 } else if (rev == OMAP_USBHS_REV2) {
Dan Murphybacec782013-08-01 14:05:57 -0500238
Govindraj.Redc16a02012-02-06 03:55:34 +0000239 clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
240 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
241
Dan Murphybacec782013-08-01 14:05:57 -0500242 /* Clear port mode fields for PHY mode */
243
244 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
245 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
246
247 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
248 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
249
250 } else if (rev == OMAP_USBHS_REV2_1) {
251
252 clrsetbits_le32(&reg,
253 (OMAP_P1_MODE_CLEAR |
254 OMAP_P2_MODE_CLEAR |
255 OMAP_P3_MODE_CLEAR),
256 OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
257
258 /* Clear port mode fields for PHY mode */
Govindraj.Redc16a02012-02-06 03:55:34 +0000259
260 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
261 setbits_le32(&reg, OMAP_P1_MODE_HSIC);
262
263 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
264 setbits_le32(&reg, OMAP_P2_MODE_HSIC);
265
266 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[2]))
267 setbits_le32(&reg, OMAP_P3_MODE_HSIC);
268 }
269
270 debug("OMAP UHH_REVISION 0x%x\n", rev);
271 writel(reg, &uhh->hostconfig);
272
273 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
274 if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
275 omap_usbhs_hsic_init(i);
Ilya Yanok7ad75782012-02-06 03:55:33 +0000276
277 omap_ehci_phy_reset(0, 10);
278
Govindraj.Redc16a02012-02-06 03:55:34 +0000279 /*
280 * An undocumented "feature" in the OMAP3 EHCI controller,
281 * causes suspended ports to be taken out of suspend when
282 * the USBCMD.Run/Stop bit is cleared (for example when
283 * we do ehci_bus_suspend).
284 * This breaks suspend-resume if the root-hub is allowed
285 * to suspend. Writing 1 to this undocumented register bit
286 * disables this feature and restores normal behavior.
287 */
288 writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
289
290 for (i = 0; i < OMAP_HS_USB_PORTS; i++)
291 if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
292 omap_ehci_soft_phy_reset(i);
293
Govindraj.Redc16a02012-02-06 03:55:34 +0000294 debug("OMAP EHCI init done\n");
Ilya Yanok7ad75782012-02-06 03:55:33 +0000295 return 0;
296}
Adam Fordcb167e82020-05-16 01:19:53 -0500297
Adam Fordcb167e82020-05-16 01:19:53 -0500298static struct omap_usbhs_board_data usbhs_bdata = {
299 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
300 .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
301 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
302};
303
304static void omap_usbhs_set_mode(u8 index, const char *mode)
305{
306 if (!strcmp(mode, "ehci-phy"))
307 usbhs_bdata.port_mode[index] = OMAP_EHCI_PORT_MODE_PHY;
308 else if (!strcmp(mode, "ehci-tll"))
309 usbhs_bdata.port_mode[index] = OMAP_EHCI_PORT_MODE_TLL;
310 else if (!strcmp(mode, "ehci-hsic"))
311 usbhs_bdata.port_mode[index] = OMAP_EHCI_PORT_MODE_HSIC;
312}
313
314static int omap_usbhs_probe(struct udevice *dev)
315{
316 u8 i;
317 const char *mode;
318 char prop[11];
319
320 /* Go through each port portX-mode to determing phy mode */
321 for (i = 0; i < OMAP_HS_USB_PORTS; i++) {
322 snprintf(prop, sizeof(prop), "port%d-mode", i + 1);
323 mode = dev_read_string(dev, prop);
324
325 /* If the portX-mode exists, set the mode */
326 if (mode)
327 omap_usbhs_set_mode(i, mode);
328 }
329
330 return omap_ehci_hcd_init(0, &usbhs_bdata);
331}
332
333static const struct udevice_id omap_usbhs_dt_ids[] = {
334 { .compatible = "ti,usbhs-host" },
335 { }
336};
337
338U_BOOT_DRIVER(usb_omaphs_host) = {
339 .name = "usbhs-host",
340 .id = UCLASS_SIMPLE_BUS,
341 .of_match = omap_usbhs_dt_ids,
342 .probe = omap_usbhs_probe,
343 .flags = DM_FLAG_ALLOC_PRIV_DMA,
344};
345
346struct ehci_omap_priv_data {
347 struct ehci_ctrl ctrl;
348 struct omap_ehci *ehci;
349#ifdef CONFIG_DM_REGULATOR
350 struct udevice *vbus_supply;
351#endif
352 enum usb_init_type init_type;
353 int portnr;
354 struct phy phy[OMAP_HS_USB_PORTS];
355 int nports;
356};
357
Simon Glassaad29ae2020-12-03 16:55:21 -0700358static int ehci_usb_of_to_plat(struct udevice *dev)
Adam Fordcb167e82020-05-16 01:19:53 -0500359{
Simon Glassb75b15b2020-12-03 16:55:23 -0700360 struct usb_plat *plat = dev_get_plat(dev);
Adam Fordcb167e82020-05-16 01:19:53 -0500361
362 plat->init_type = USB_INIT_HOST;
363
364 return 0;
365}
366
367static int omap_ehci_probe(struct udevice *dev)
368{
Simon Glassb75b15b2020-12-03 16:55:23 -0700369 struct usb_plat *plat = dev_get_plat(dev);
Adam Fordcb167e82020-05-16 01:19:53 -0500370 struct ehci_omap_priv_data *priv = dev_get_priv(dev);
371 struct ehci_hccr *hccr;
372 struct ehci_hcor *hcor;
373
Masahiro Yamada1096ae12020-07-17 14:36:46 +0900374 priv->ehci = dev_read_addr_ptr(dev);
Simon Glass75e534b2020-12-16 21:20:07 -0700375 priv->portnr = dev_seq(dev);
Adam Fordcb167e82020-05-16 01:19:53 -0500376 priv->init_type = plat->init_type;
377
378 hccr = (struct ehci_hccr *)&priv->ehci->hccapbase;
379 hcor = (struct ehci_hcor *)&priv->ehci->usbcmd;
380
381 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
382}
383
384static const struct udevice_id omap_ehci_dt_ids[] = {
385 { .compatible = "ti,ehci-omap" },
386 { }
387};
388
389U_BOOT_DRIVER(usb_omap_ehci) = {
390 .name = "omap-ehci",
391 .id = UCLASS_USB,
392 .of_match = omap_ehci_dt_ids,
393 .probe = omap_ehci_probe,
Simon Glassaad29ae2020-12-03 16:55:21 -0700394 .of_to_plat = ehci_usb_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700395 .plat_auto = sizeof(struct usb_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700396 .priv_auto = sizeof(struct ehci_omap_priv_data),
Adam Fordcb167e82020-05-16 01:19:53 -0500397 .remove = ehci_deregister,
398 .ops = &ehci_usb_ops,
399 .flags = DM_FLAG_ALLOC_PRIV_DMA,
400};