1 // SPDX-License-Identifier: GPL-2.0
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>
9 * This file is part of the Inventra Controller Driver for Linux.
15 #include <dm/device-internal.h>
16 #include <dm/device_compat.h>
18 #include <linux/err.h>
19 #include <linux/usb/otg.h>
20 #include <asm/global_data.h>
21 #include <asm/omap_common.h>
22 #include <asm/omap_musb.h>
25 #include "linux-compat.h"
26 #include "musb_core.h"
28 #include "musb_uboot.h"
30 static inline void omap2430_low_level_exit(struct musb *musb)
35 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
36 l |= ENABLEFORCE; /* enable MSTANDBY */
37 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
40 static inline void omap2430_low_level_init(struct musb *musb)
44 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
45 l &= ~ENABLEFORCE; /* disable MSTANDBY */
46 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
49 #ifdef CONFIG_DM_USB_GADGET
50 int dm_usb_gadget_handle_interrupts(struct udevice *dev)
52 struct musb_host_data *host = dev_get_priv(dev);
54 host->host->isr(0, host->host);
59 static int omap2430_musb_init(struct musb *musb)
63 unsigned long int start;
65 struct omap_musb_board_data *data =
66 (struct omap_musb_board_data *)musb->controller;
68 /* Reset the controller */
69 musb_writel(musb->mregs, OTG_SYSCONFIG, SOFTRST);
74 l = musb_readl(musb->mregs, OTG_SYSCONFIG);
75 if ((l & SOFTRST) == 0)
78 if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
79 dev_err(musb->controller, "MUSB reset is taking too long\n");
84 l = musb_readl(musb->mregs, OTG_INTERFSEL);
86 if (data->interface_type == MUSB_INTERFACE_UTMI) {
87 /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
88 l &= ~ULPI_12PIN; /* Disable ULPI */
89 l |= UTMI_8BIT; /* Enable UTMI */
94 musb_writel(musb->mregs, OTG_INTERFSEL, l);
96 pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
97 "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
98 musb_readl(musb->mregs, OTG_REVISION),
99 musb_readl(musb->mregs, OTG_SYSCONFIG),
100 musb_readl(musb->mregs, OTG_SYSSTATUS),
101 musb_readl(musb->mregs, OTG_INTERFSEL),
102 musb_readl(musb->mregs, OTG_SIMENABLE));
109 static int omap2430_musb_enable(struct musb *musb)
111 #ifdef CONFIG_TWL4030_USB
112 if (twl4030_usb_ulpi_init()) {
113 serial_printf("ERROR: %s Could not initialize PHY\n",
114 __PRETTY_FUNCTION__);
118 #ifdef CONFIG_TWL6030_POWER
119 twl6030_usb_device_settings();
122 #ifdef CONFIG_OMAP44XX
123 u32 *usbotghs_control = (u32 *)((*ctrl)->control_usbotghs_ctrl);
124 *usbotghs_control = USBOTGHS_CONTROL_AVALID |
125 USBOTGHS_CONTROL_VBUSVALID | USBOTGHS_CONTROL_IDDIG;
131 static void omap2430_musb_disable(struct musb *musb)
136 static int omap2430_musb_exit(struct musb *musb)
138 del_timer_sync(&musb_idle_timer);
140 omap2430_low_level_exit(musb);
145 const struct musb_platform_ops omap2430_ops = {
146 .init = omap2430_musb_init,
147 .exit = omap2430_musb_exit,
148 .enable = omap2430_musb_enable,
149 .disable = omap2430_musb_disable,
152 #if CONFIG_IS_ENABLED(DM_USB)
154 struct omap2430_musb_plat {
157 struct musb_hdrc_platform_data plat;
158 struct musb_hdrc_config musb_config;
159 struct omap_musb_board_data otg_board_data;
162 static int omap2430_musb_of_to_plat(struct udevice *dev)
164 struct omap2430_musb_plat *plat = dev_get_plat(dev);
165 const void *fdt = gd->fdt_blob;
166 int node = dev_of_offset(dev);
168 plat->base = (void *)dev_read_addr_ptr(dev);
170 plat->musb_config.multipoint = fdtdec_get_int(fdt, node, "multipoint",
172 if (plat->musb_config.multipoint < 0) {
173 pr_err("MUSB multipoint DT entry missing\n");
177 plat->musb_config.dyn_fifo = 1;
178 plat->musb_config.num_eps = fdtdec_get_int(fdt, node, "num-eps", -1);
179 if (plat->musb_config.num_eps < 0) {
180 pr_err("MUSB num-eps DT entry missing\n");
184 plat->musb_config.ram_bits = fdtdec_get_int(fdt, node, "ram-bits", -1);
185 if (plat->musb_config.ram_bits < 0) {
186 pr_err("MUSB ram-bits DT entry missing\n");
190 plat->plat.power = fdtdec_get_int(fdt, node, "power", -1);
191 if (plat->plat.power < 0) {
192 pr_err("MUSB power DT entry missing\n");
196 plat->otg_board_data.interface_type = fdtdec_get_int(fdt, node,
199 if (plat->otg_board_data.interface_type < 0) {
200 pr_err("MUSB interface-type DT entry missing\n");
204 #if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */
205 plat->plat.mode = fdtdec_get_int(fdt, node, "mode", -1);
206 if (plat->plat.mode < 0) {
207 pr_err("MUSB mode DT entry missing\n");
210 #else /* MUSB_OTG, it doesn't work */
211 #ifdef CONFIG_USB_MUSB_HOST /* Host seems to be the only option that works */
212 plat->plat.mode = MUSB_HOST;
213 #else /* For that matter, MUSB_PERIPHERAL doesn't either */
214 plat->plat.mode = MUSB_PERIPHERAL;
217 plat->otg_board_data.dev = dev;
218 plat->plat.config = &plat->musb_config;
219 plat->plat.platform_ops = &omap2430_ops;
220 plat->plat.board_data = &plat->otg_board_data;
224 static int omap2430_musb_probe(struct udevice *dev)
226 struct omap2430_musb_plat *plat = dev_get_plat(dev);
227 struct omap_musb_board_data *otg_board_data;
229 void *base = dev_read_addr_ptr(dev);
232 otg_board_data = &plat->otg_board_data;
234 if (IS_ENABLED(CONFIG_USB_MUSB_HOST)) {
235 struct musb_host_data *host = dev_get_priv(dev);
236 struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
238 priv->desc_before_addr = true;
240 host->host = musb_init_controller(&plat->plat,
241 (struct device *)otg_board_data,
246 return musb_lowlevel_init(host);
247 } else if (CONFIG_IS_ENABLED(DM_USB_GADGET)) {
248 struct musb_host_data *host = dev_get_priv(dev);
250 host->host = musb_init_controller(&plat->plat,
251 (struct device *)otg_board_data,
256 return usb_add_gadget_udc((struct device *)otg_board_data, &host->host->g);
259 musbp = musb_register(&plat->plat, (struct device *)otg_board_data,
261 if (IS_ERR_OR_NULL(musbp))
267 static int omap2430_musb_remove(struct udevice *dev)
269 struct musb_host_data *host = dev_get_priv(dev);
271 musb_stop(host->host);
276 static const struct udevice_id omap2430_musb_ids[] = {
277 { .compatible = "ti,omap3-musb" },
278 { .compatible = "ti,omap4-musb" },
282 U_BOOT_DRIVER(omap2430_musb) = {
283 .name = "omap2430-musb",
284 #ifdef CONFIG_USB_MUSB_HOST
287 .id = UCLASS_USB_GADGET_GENERIC,
289 .of_match = omap2430_musb_ids,
290 .of_to_plat = omap2430_musb_of_to_plat,
291 .probe = omap2430_musb_probe,
292 .remove = omap2430_musb_remove,
293 #ifdef CONFIG_USB_MUSB_HOST
294 .ops = &musb_usb_ops,
296 .plat_auto = sizeof(struct omap2430_musb_plat),
297 .priv_auto = sizeof(struct musb_host_data),
300 #endif /* CONFIG_IS_ENABLED(DM_USB) */