Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2005-2007 by Texas Instruments |
| 4 | * Some code has been taken from tusb6010.c |
| 5 | * Copyrights for that are attributable to: |
| 6 | * Copyright (C) 2006 Nokia Corporation |
| 7 | * Tony Lindgren <tony@atomide.com> |
| 8 | * |
| 9 | * This file is part of the Inventra Controller Driver for Linux. |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 10 | */ |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 11 | #include <common.h> |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 12 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | bd7a59a | 2019-11-14 12:57:23 -0700 | [diff] [blame] | 14 | #include <serial.h> |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 15 | #include <dm/device-internal.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 16 | #include <dm/device_compat.h> |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 17 | #include <dm/lists.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 19 | #include <linux/usb/otg.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Paul Kocialkowski | d5a43ba | 2016-02-27 19:19:05 +0100 | [diff] [blame] | 21 | #include <asm/omap_common.h> |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 22 | #include <asm/omap_musb.h> |
| 23 | #include <twl4030.h> |
Paul Kocialkowski | d5a43ba | 2016-02-27 19:19:05 +0100 | [diff] [blame] | 24 | #include <twl6030.h> |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 25 | #include "linux-compat.h" |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 26 | #include "musb_core.h" |
| 27 | #include "omap2430.h" |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 28 | #include "musb_uboot.h" |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 29 | |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 30 | static inline void omap2430_low_level_exit(struct musb *musb) |
| 31 | { |
| 32 | u32 l; |
| 33 | |
| 34 | /* in any role */ |
| 35 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
| 36 | l |= ENABLEFORCE; /* enable MSTANDBY */ |
| 37 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); |
| 38 | } |
| 39 | |
| 40 | static inline void omap2430_low_level_init(struct musb *musb) |
| 41 | { |
| 42 | u32 l; |
| 43 | |
| 44 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
| 45 | l &= ~ENABLEFORCE; /* disable MSTANDBY */ |
| 46 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); |
| 47 | } |
| 48 | |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 49 | |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 50 | static int omap2430_musb_init(struct musb *musb) |
| 51 | { |
| 52 | u32 l; |
| 53 | int status = 0; |
Paul Kocialkowski | 68dbdef | 2015-01-19 18:33:43 +0100 | [diff] [blame] | 54 | unsigned long int start; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 55 | |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 56 | struct omap_musb_board_data *data = |
| 57 | (struct omap_musb_board_data *)musb->controller; |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 58 | |
Paul Kocialkowski | 68dbdef | 2015-01-19 18:33:43 +0100 | [diff] [blame] | 59 | /* Reset the controller */ |
| 60 | musb_writel(musb->mregs, OTG_SYSCONFIG, SOFTRST); |
| 61 | |
| 62 | start = get_timer(0); |
| 63 | |
| 64 | while (1) { |
| 65 | l = musb_readl(musb->mregs, OTG_SYSCONFIG); |
| 66 | if ((l & SOFTRST) == 0) |
| 67 | break; |
| 68 | |
| 69 | if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) { |
| 70 | dev_err(musb->controller, "MUSB reset is taking too long\n"); |
| 71 | return -ENODEV; |
| 72 | } |
| 73 | } |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 74 | |
| 75 | l = musb_readl(musb->mregs, OTG_INTERFSEL); |
| 76 | |
| 77 | if (data->interface_type == MUSB_INTERFACE_UTMI) { |
| 78 | /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */ |
| 79 | l &= ~ULPI_12PIN; /* Disable ULPI */ |
| 80 | l |= UTMI_8BIT; /* Enable UTMI */ |
| 81 | } else { |
| 82 | l |= ULPI_12PIN; |
| 83 | } |
| 84 | |
| 85 | musb_writel(musb->mregs, OTG_INTERFSEL, l); |
| 86 | |
| 87 | pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, " |
| 88 | "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n", |
| 89 | musb_readl(musb->mregs, OTG_REVISION), |
| 90 | musb_readl(musb->mregs, OTG_SYSCONFIG), |
| 91 | musb_readl(musb->mregs, OTG_SYSSTATUS), |
| 92 | musb_readl(musb->mregs, OTG_INTERFSEL), |
| 93 | musb_readl(musb->mregs, OTG_SIMENABLE)); |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 94 | return 0; |
| 95 | |
| 96 | err1: |
| 97 | return status; |
| 98 | } |
| 99 | |
Hans de Goede | 81c4998 | 2015-06-17 21:33:54 +0200 | [diff] [blame] | 100 | static int omap2430_musb_enable(struct musb *musb) |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 101 | { |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 102 | #ifdef CONFIG_TWL4030_USB |
| 103 | if (twl4030_usb_ulpi_init()) { |
| 104 | serial_printf("ERROR: %s Could not initialize PHY\n", |
| 105 | __PRETTY_FUNCTION__); |
| 106 | } |
| 107 | #endif |
Paul Kocialkowski | d5a43ba | 2016-02-27 19:19:05 +0100 | [diff] [blame] | 108 | |
| 109 | #ifdef CONFIG_TWL6030_POWER |
| 110 | twl6030_usb_device_settings(); |
| 111 | #endif |
| 112 | |
Tom Rini | 8d4bfb8 | 2017-05-12 22:33:19 -0400 | [diff] [blame] | 113 | #ifdef CONFIG_OMAP44XX |
Paul Kocialkowski | d5a43ba | 2016-02-27 19:19:05 +0100 | [diff] [blame] | 114 | u32 *usbotghs_control = (u32 *)((*ctrl)->control_usbotghs_ctrl); |
| 115 | *usbotghs_control = USBOTGHS_CONTROL_AVALID | |
| 116 | USBOTGHS_CONTROL_VBUSVALID | USBOTGHS_CONTROL_IDDIG; |
| 117 | #endif |
| 118 | |
Hans de Goede | 81c4998 | 2015-06-17 21:33:54 +0200 | [diff] [blame] | 119 | return 0; |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static void omap2430_musb_disable(struct musb *musb) |
| 123 | { |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 124 | |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static int omap2430_musb_exit(struct musb *musb) |
| 128 | { |
| 129 | del_timer_sync(&musb_idle_timer); |
| 130 | |
| 131 | omap2430_low_level_exit(musb); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 136 | const struct musb_platform_ops omap2430_ops = { |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 137 | .init = omap2430_musb_init, |
| 138 | .exit = omap2430_musb_exit, |
Ilya Yanok | a3292f2 | 2012-11-06 13:48:29 +0000 | [diff] [blame] | 139 | .enable = omap2430_musb_enable, |
| 140 | .disable = omap2430_musb_disable, |
| 141 | }; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 142 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 143 | #if CONFIG_IS_ENABLED(DM_USB) |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 144 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 145 | struct omap2430_musb_plat { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 146 | void *base; |
| 147 | void *ctrl_mod_base; |
| 148 | struct musb_hdrc_platform_data plat; |
| 149 | struct musb_hdrc_config musb_config; |
| 150 | struct omap_musb_board_data otg_board_data; |
| 151 | }; |
| 152 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 153 | static int omap2430_musb_of_to_plat(struct udevice *dev) |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 154 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 155 | struct omap2430_musb_plat *plat = dev_get_plat(dev); |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 156 | const void *fdt = gd->fdt_blob; |
| 157 | int node = dev_of_offset(dev); |
| 158 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 159 | plat->base = (void *)dev_read_addr_ptr(dev); |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 160 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 161 | plat->musb_config.multipoint = fdtdec_get_int(fdt, node, "multipoint", |
| 162 | -1); |
| 163 | if (plat->musb_config.multipoint < 0) { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 164 | pr_err("MUSB multipoint DT entry missing\n"); |
| 165 | return -ENOENT; |
| 166 | } |
| 167 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 168 | plat->musb_config.dyn_fifo = 1; |
| 169 | plat->musb_config.num_eps = fdtdec_get_int(fdt, node, "num-eps", -1); |
| 170 | if (plat->musb_config.num_eps < 0) { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 171 | pr_err("MUSB num-eps DT entry missing\n"); |
| 172 | return -ENOENT; |
| 173 | } |
| 174 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 175 | plat->musb_config.ram_bits = fdtdec_get_int(fdt, node, "ram-bits", -1); |
| 176 | if (plat->musb_config.ram_bits < 0) { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 177 | pr_err("MUSB ram-bits DT entry missing\n"); |
| 178 | return -ENOENT; |
| 179 | } |
| 180 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 181 | plat->plat.power = fdtdec_get_int(fdt, node, "power", -1); |
| 182 | if (plat->plat.power < 0) { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 183 | pr_err("MUSB power DT entry missing\n"); |
| 184 | return -ENOENT; |
| 185 | } |
| 186 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 187 | plat->otg_board_data.interface_type = fdtdec_get_int(fdt, node, |
| 188 | "interface-type", |
| 189 | -1); |
| 190 | if (plat->otg_board_data.interface_type < 0) { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 191 | pr_err("MUSB interface-type DT entry missing\n"); |
| 192 | return -ENOENT; |
| 193 | } |
| 194 | |
| 195 | #if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 196 | plat->plat.mode = fdtdec_get_int(fdt, node, "mode", -1); |
| 197 | if (plat->plat.mode < 0) { |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 198 | pr_err("MUSB mode DT entry missing\n"); |
| 199 | return -ENOENT; |
| 200 | } |
| 201 | #else /* MUSB_OTG, it doesn't work */ |
| 202 | #ifdef CONFIG_USB_MUSB_HOST /* Host seems to be the only option that works */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 203 | plat->plat.mode = MUSB_HOST; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 204 | #else /* For that matter, MUSB_PERIPHERAL doesn't either */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 205 | plat->plat.mode = MUSB_PERIPHERAL; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 206 | #endif |
| 207 | #endif |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 208 | plat->otg_board_data.dev = dev; |
| 209 | plat->plat.config = &plat->musb_config; |
| 210 | plat->plat.platform_ops = &omap2430_ops; |
| 211 | plat->plat.board_data = &plat->otg_board_data; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int omap2430_musb_probe(struct udevice *dev) |
| 216 | { |
| 217 | #ifdef CONFIG_USB_MUSB_HOST |
| 218 | struct musb_host_data *host = dev_get_priv(dev); |
Derald D. Woods | 3f12cf1 | 2019-05-27 21:22:00 -0500 | [diff] [blame] | 219 | #else |
| 220 | struct musb *musbp; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 221 | #endif |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 222 | struct omap2430_musb_plat *plat = dev_get_plat(dev); |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 223 | struct usb_bus_priv *priv = dev_get_uclass_priv(dev); |
| 224 | struct omap_musb_board_data *otg_board_data; |
Derald D. Woods | 3f12cf1 | 2019-05-27 21:22:00 -0500 | [diff] [blame] | 225 | int ret = 0; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 226 | void *base = dev_read_addr_ptr(dev); |
| 227 | |
| 228 | priv->desc_before_addr = true; |
| 229 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 230 | otg_board_data = &plat->otg_board_data; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 231 | |
| 232 | #ifdef CONFIG_USB_MUSB_HOST |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 233 | host->host = musb_init_controller(&plat->plat, |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 234 | (struct device *)otg_board_data, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 235 | plat->base); |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 236 | if (!host->host) { |
| 237 | return -EIO; |
| 238 | } |
| 239 | |
| 240 | ret = musb_lowlevel_init(host); |
| 241 | #else |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 242 | musbp = musb_register(&plat->plat, (struct device *)otg_board_data, |
| 243 | plat->base); |
Derald D. Woods | 3f12cf1 | 2019-05-27 21:22:00 -0500 | [diff] [blame] | 244 | if (IS_ERR_OR_NULL(musbp)) |
| 245 | return -EINVAL; |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 246 | #endif |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | static int omap2430_musb_remove(struct udevice *dev) |
| 251 | { |
| 252 | struct musb_host_data *host = dev_get_priv(dev); |
| 253 | |
| 254 | musb_stop(host->host); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | static const struct udevice_id omap2430_musb_ids[] = { |
| 260 | { .compatible = "ti,omap3-musb" }, |
| 261 | { .compatible = "ti,omap4-musb" }, |
| 262 | { } |
| 263 | }; |
| 264 | |
| 265 | U_BOOT_DRIVER(omap2430_musb) = { |
| 266 | .name = "omap2430-musb", |
| 267 | #ifdef CONFIG_USB_MUSB_HOST |
| 268 | .id = UCLASS_USB, |
| 269 | #else |
Jean-Jacques Hiblot | 9dc0d5c | 2018-11-29 10:52:46 +0100 | [diff] [blame] | 270 | .id = UCLASS_USB_GADGET_GENERIC, |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 271 | #endif |
| 272 | .of_match = omap2430_musb_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 273 | .of_to_plat = omap2430_musb_of_to_plat, |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 274 | .probe = omap2430_musb_probe, |
| 275 | .remove = omap2430_musb_remove, |
| 276 | #ifdef CONFIG_USB_MUSB_HOST |
| 277 | .ops = &musb_usb_ops, |
| 278 | #endif |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 279 | .plat_auto = sizeof(struct omap2430_musb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 280 | .priv_auto = sizeof(struct musb_host_data), |
Adam Ford | 0b957cd | 2018-07-31 05:58:01 -0500 | [diff] [blame] | 281 | }; |
| 282 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 283 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |