2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-11-06 13:48:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005-2007 by Texas Instruments
|
|
|
|
* Some code has been taken from tusb6010.c
|
|
|
|
* Copyrights for that are attributable to:
|
|
|
|
* Copyright (C) 2006 Nokia Corporation
|
|
|
|
* Tony Lindgren <tony@atomide.com>
|
|
|
|
*
|
|
|
|
* This file is part of the Inventra Controller Driver for Linux.
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2018-07-31 10:58:01 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-11-14 19:57:23 +00:00
|
|
|
#include <serial.h>
|
2018-07-31 10:58:01 +00:00
|
|
|
#include <dm/device-internal.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2018-07-31 10:58:01 +00:00
|
|
|
#include <dm/lists.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2018-07-31 10:58:01 +00:00
|
|
|
#include <linux/usb/otg.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-02-27 18:19:05 +00:00
|
|
|
#include <asm/omap_common.h>
|
2012-11-06 13:48:29 +00:00
|
|
|
#include <asm/omap_musb.h>
|
|
|
|
#include <twl4030.h>
|
2016-02-27 18:19:05 +00:00
|
|
|
#include <twl6030.h>
|
2012-11-06 13:48:29 +00:00
|
|
|
#include "linux-compat.h"
|
|
|
|
#include "musb_core.h"
|
|
|
|
#include "omap2430.h"
|
2018-07-31 10:58:01 +00:00
|
|
|
#include "musb_uboot.h"
|
2012-11-06 13:48:29 +00:00
|
|
|
|
|
|
|
static inline void omap2430_low_level_exit(struct musb *musb)
|
|
|
|
{
|
|
|
|
u32 l;
|
|
|
|
|
|
|
|
/* in any role */
|
|
|
|
l = musb_readl(musb->mregs, OTG_FORCESTDBY);
|
|
|
|
l |= ENABLEFORCE; /* enable MSTANDBY */
|
|
|
|
musb_writel(musb->mregs, OTG_FORCESTDBY, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void omap2430_low_level_init(struct musb *musb)
|
|
|
|
{
|
|
|
|
u32 l;
|
|
|
|
|
|
|
|
l = musb_readl(musb->mregs, OTG_FORCESTDBY);
|
|
|
|
l &= ~ENABLEFORCE; /* disable MSTANDBY */
|
|
|
|
musb_writel(musb->mregs, OTG_FORCESTDBY, l);
|
|
|
|
}
|
|
|
|
|
2023-01-09 07:13:31 +00:00
|
|
|
#ifdef CONFIG_DM_USB_GADGET
|
|
|
|
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
|
|
|
|
host->host->isr(0, host->host);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-06 13:48:29 +00:00
|
|
|
|
|
|
|
static int omap2430_musb_init(struct musb *musb)
|
|
|
|
{
|
|
|
|
u32 l;
|
|
|
|
int status = 0;
|
2015-01-19 17:33:43 +00:00
|
|
|
unsigned long int start;
|
2018-07-31 10:58:01 +00:00
|
|
|
|
2012-11-06 13:48:29 +00:00
|
|
|
struct omap_musb_board_data *data =
|
|
|
|
(struct omap_musb_board_data *)musb->controller;
|
|
|
|
|
2015-01-19 17:33:43 +00:00
|
|
|
/* Reset the controller */
|
|
|
|
musb_writel(musb->mregs, OTG_SYSCONFIG, SOFTRST);
|
|
|
|
|
|
|
|
start = get_timer(0);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
l = musb_readl(musb->mregs, OTG_SYSCONFIG);
|
|
|
|
if ((l & SOFTRST) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
|
|
|
|
dev_err(musb->controller, "MUSB reset is taking too long\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
2012-11-06 13:48:29 +00:00
|
|
|
|
|
|
|
l = musb_readl(musb->mregs, OTG_INTERFSEL);
|
|
|
|
|
|
|
|
if (data->interface_type == MUSB_INTERFACE_UTMI) {
|
|
|
|
/* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
|
|
|
|
l &= ~ULPI_12PIN; /* Disable ULPI */
|
|
|
|
l |= UTMI_8BIT; /* Enable UTMI */
|
|
|
|
} else {
|
|
|
|
l |= ULPI_12PIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
musb_writel(musb->mregs, OTG_INTERFSEL, l);
|
|
|
|
|
|
|
|
pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
|
|
|
|
"sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
|
|
|
|
musb_readl(musb->mregs, OTG_REVISION),
|
|
|
|
musb_readl(musb->mregs, OTG_SYSCONFIG),
|
|
|
|
musb_readl(musb->mregs, OTG_SYSSTATUS),
|
|
|
|
musb_readl(musb->mregs, OTG_INTERFSEL),
|
|
|
|
musb_readl(musb->mregs, OTG_SIMENABLE));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err1:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:54 +00:00
|
|
|
static int omap2430_musb_enable(struct musb *musb)
|
2012-11-06 13:48:29 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_TWL4030_USB
|
|
|
|
if (twl4030_usb_ulpi_init()) {
|
|
|
|
serial_printf("ERROR: %s Could not initialize PHY\n",
|
|
|
|
__PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-27 18:19:05 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_TWL6030_POWER
|
|
|
|
twl6030_usb_device_settings();
|
|
|
|
#endif
|
|
|
|
|
2017-05-13 02:33:19 +00:00
|
|
|
#ifdef CONFIG_OMAP44XX
|
2016-02-27 18:19:05 +00:00
|
|
|
u32 *usbotghs_control = (u32 *)((*ctrl)->control_usbotghs_ctrl);
|
|
|
|
*usbotghs_control = USBOTGHS_CONTROL_AVALID |
|
|
|
|
USBOTGHS_CONTROL_VBUSVALID | USBOTGHS_CONTROL_IDDIG;
|
|
|
|
#endif
|
|
|
|
|
2015-06-17 19:33:54 +00:00
|
|
|
return 0;
|
2012-11-06 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omap2430_musb_disable(struct musb *musb)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap2430_musb_exit(struct musb *musb)
|
|
|
|
{
|
|
|
|
del_timer_sync(&musb_idle_timer);
|
|
|
|
|
|
|
|
omap2430_low_level_exit(musb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct musb_platform_ops omap2430_ops = {
|
|
|
|
.init = omap2430_musb_init,
|
|
|
|
.exit = omap2430_musb_exit,
|
|
|
|
.enable = omap2430_musb_enable,
|
|
|
|
.disable = omap2430_musb_disable,
|
|
|
|
};
|
2018-07-31 10:58:01 +00:00
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_USB)
|
2018-07-31 10:58:01 +00:00
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct omap2430_musb_plat {
|
2018-07-31 10:58:01 +00:00
|
|
|
void *base;
|
|
|
|
void *ctrl_mod_base;
|
|
|
|
struct musb_hdrc_platform_data plat;
|
|
|
|
struct musb_hdrc_config musb_config;
|
|
|
|
struct omap_musb_board_data otg_board_data;
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int omap2430_musb_of_to_plat(struct udevice *dev)
|
2018-07-31 10:58:01 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct omap2430_musb_plat *plat = dev_get_plat(dev);
|
2018-07-31 10:58:01 +00:00
|
|
|
const void *fdt = gd->fdt_blob;
|
|
|
|
int node = dev_of_offset(dev);
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->base = (void *)dev_read_addr_ptr(dev);
|
2018-07-31 10:58:01 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->musb_config.multipoint = fdtdec_get_int(fdt, node, "multipoint",
|
|
|
|
-1);
|
|
|
|
if (plat->musb_config.multipoint < 0) {
|
2018-07-31 10:58:01 +00:00
|
|
|
pr_err("MUSB multipoint DT entry missing\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->musb_config.dyn_fifo = 1;
|
|
|
|
plat->musb_config.num_eps = fdtdec_get_int(fdt, node, "num-eps", -1);
|
|
|
|
if (plat->musb_config.num_eps < 0) {
|
2018-07-31 10:58:01 +00:00
|
|
|
pr_err("MUSB num-eps DT entry missing\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->musb_config.ram_bits = fdtdec_get_int(fdt, node, "ram-bits", -1);
|
|
|
|
if (plat->musb_config.ram_bits < 0) {
|
2018-07-31 10:58:01 +00:00
|
|
|
pr_err("MUSB ram-bits DT entry missing\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.power = fdtdec_get_int(fdt, node, "power", -1);
|
|
|
|
if (plat->plat.power < 0) {
|
2018-07-31 10:58:01 +00:00
|
|
|
pr_err("MUSB power DT entry missing\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->otg_board_data.interface_type = fdtdec_get_int(fdt, node,
|
|
|
|
"interface-type",
|
|
|
|
-1);
|
|
|
|
if (plat->otg_board_data.interface_type < 0) {
|
2018-07-31 10:58:01 +00:00
|
|
|
pr_err("MUSB interface-type DT entry missing\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.mode = fdtdec_get_int(fdt, node, "mode", -1);
|
|
|
|
if (plat->plat.mode < 0) {
|
2018-07-31 10:58:01 +00:00
|
|
|
pr_err("MUSB mode DT entry missing\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
#else /* MUSB_OTG, it doesn't work */
|
|
|
|
#ifdef CONFIG_USB_MUSB_HOST /* Host seems to be the only option that works */
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.mode = MUSB_HOST;
|
2018-07-31 10:58:01 +00:00
|
|
|
#else /* For that matter, MUSB_PERIPHERAL doesn't either */
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.mode = MUSB_PERIPHERAL;
|
2018-07-31 10:58:01 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->otg_board_data.dev = dev;
|
|
|
|
plat->plat.config = &plat->musb_config;
|
|
|
|
plat->plat.platform_ops = &omap2430_ops;
|
|
|
|
plat->plat.board_data = &plat->otg_board_data;
|
2018-07-31 10:58:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap2430_musb_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct omap2430_musb_plat *plat = dev_get_plat(dev);
|
2018-07-31 10:58:01 +00:00
|
|
|
struct omap_musb_board_data *otg_board_data;
|
2019-05-28 02:22:00 +00:00
|
|
|
int ret = 0;
|
2018-07-31 10:58:01 +00:00
|
|
|
void *base = dev_read_addr_ptr(dev);
|
2023-01-09 07:13:30 +00:00
|
|
|
struct musb *musbp;
|
2018-07-31 10:58:01 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
otg_board_data = &plat->otg_board_data;
|
2018-07-31 10:58:01 +00:00
|
|
|
|
2023-02-05 22:44:26 +00:00
|
|
|
if (IS_ENABLED(CONFIG_USB_MUSB_HOST)) {
|
2023-01-09 07:13:30 +00:00
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
priv->desc_before_addr = true;
|
|
|
|
|
|
|
|
host->host = musb_init_controller(&plat->plat,
|
|
|
|
(struct device *)otg_board_data,
|
|
|
|
plat->base);
|
|
|
|
if (!host->host)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return musb_lowlevel_init(host);
|
2023-01-09 07:13:31 +00:00
|
|
|
} else if (CONFIG_IS_ENABLED(DM_USB_GADGET)) {
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
|
|
|
|
host->host = musb_init_controller(&plat->plat,
|
|
|
|
(struct device *)otg_board_data,
|
|
|
|
plat->base);
|
|
|
|
if (!host->host)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return usb_add_gadget_udc((struct device *)otg_board_data, &host->host->g);
|
2018-07-31 10:58:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
musbp = musb_register(&plat->plat, (struct device *)otg_board_data,
|
|
|
|
plat->base);
|
2019-05-28 02:22:00 +00:00
|
|
|
if (IS_ERR_OR_NULL(musbp))
|
|
|
|
return -EINVAL;
|
2023-01-09 07:13:30 +00:00
|
|
|
|
|
|
|
return 0;
|
2018-07-31 10:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int omap2430_musb_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
|
|
|
|
musb_stop(host->host);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id omap2430_musb_ids[] = {
|
|
|
|
{ .compatible = "ti,omap3-musb" },
|
|
|
|
{ .compatible = "ti,omap4-musb" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(omap2430_musb) = {
|
|
|
|
.name = "omap2430-musb",
|
|
|
|
#ifdef CONFIG_USB_MUSB_HOST
|
|
|
|
.id = UCLASS_USB,
|
|
|
|
#else
|
2018-11-29 09:52:46 +00:00
|
|
|
.id = UCLASS_USB_GADGET_GENERIC,
|
2018-07-31 10:58:01 +00:00
|
|
|
#endif
|
|
|
|
.of_match = omap2430_musb_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = omap2430_musb_of_to_plat,
|
2018-07-31 10:58:01 +00:00
|
|
|
.probe = omap2430_musb_probe,
|
|
|
|
.remove = omap2430_musb_remove,
|
|
|
|
#ifdef CONFIG_USB_MUSB_HOST
|
|
|
|
.ops = &musb_usb_ops,
|
|
|
|
#endif
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct omap2430_musb_plat),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct musb_host_data),
|
2018-07-31 10:58:01 +00:00
|
|
|
};
|
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#endif /* CONFIG_IS_ENABLED(DM_USB) */
|