2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-11-17 09:08:08 +00:00
|
|
|
/*
|
|
|
|
* MISC driver for TI MUSB Glue.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2016
|
|
|
|
* Texas Instruments Incorporated, <www.ti.com>
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-11-17 09:08:08 +00:00
|
|
|
#include <linux/usb/otg.h>
|
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/lists.h>
|
|
|
|
|
2016-11-17 09:08:11 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/omap_musb.h>
|
|
|
|
#include "musb_uboot.h"
|
|
|
|
|
2016-11-17 09:08:08 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_USB)
|
2016-11-17 09:08:11 +00:00
|
|
|
/* USB 2.0 PHY Control */
|
|
|
|
#define CM_PHY_PWRDN (1 << 0)
|
|
|
|
#define CM_PHY_OTG_PWRDN (1 << 1)
|
|
|
|
#define OTGVDET_EN (1 << 19)
|
|
|
|
#define OTGSESSENDEN (1 << 20)
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
#define AM335X_USB0_CTRL 0x0
|
2016-11-17 09:08:11 +00:00
|
|
|
#define AM335X_USB1_CTRL 0x8
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
static void ti_musb_set_phy_power(struct udevice *dev, u8 on)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ti_musb_plat *plat = dev_get_plat(dev);
|
2018-12-04 10:30:57 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
if (!plat->ctrl_mod_base)
|
2018-12-04 10:30:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (on) {
|
2020-12-03 23:55:18 +00:00
|
|
|
clrsetbits_le32(plat->ctrl_mod_base,
|
2018-12-04 10:30:57 +00:00
|
|
|
CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
|
|
|
|
OTGVDET_EN | OTGSESSENDEN);
|
|
|
|
} else {
|
2020-12-03 23:55:18 +00:00
|
|
|
clrsetbits_le32(plat->ctrl_mod_base, 0,
|
2018-12-04 10:30:57 +00:00
|
|
|
CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
static int ti_musb_get_usb_index(int node)
|
|
|
|
{
|
|
|
|
const void *fdt = gd->fdt_blob;
|
|
|
|
int i = 0;
|
|
|
|
char path[64];
|
|
|
|
const char *alias_path;
|
|
|
|
char alias[16];
|
|
|
|
|
|
|
|
fdt_get_path(fdt, node, path, sizeof(path));
|
|
|
|
|
|
|
|
do {
|
|
|
|
snprintf(alias, sizeof(alias), "usb%d", i);
|
|
|
|
alias_path = fdt_get_alias(fdt, alias);
|
|
|
|
if (alias_path == NULL) {
|
|
|
|
debug("USB index not found\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(path, alias_path))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
} while (alias_path);
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int ti_musb_of_to_plat(struct udevice *dev)
|
2016-11-17 09:08:11 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ti_musb_plat *plat = dev_get_plat(dev);
|
2016-11-17 09:08:11 +00:00
|
|
|
const void *fdt = gd->fdt_blob;
|
2017-01-17 23:52:55 +00:00
|
|
|
int node = dev_of_offset(dev);
|
2016-11-17 09:08:11 +00:00
|
|
|
int phys;
|
|
|
|
int ctrl_mod;
|
|
|
|
int usb_index;
|
2018-12-04 10:30:57 +00:00
|
|
|
struct musb_hdrc_config *musb_config;
|
2016-11-17 09:08:11 +00:00
|
|
|
|
2023-03-13 00:32:31 +00:00
|
|
|
plat->base = devfdt_get_addr_index_ptr(dev, 1);
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
phys = fdtdec_lookup_phandle(fdt, node, "phys");
|
|
|
|
ctrl_mod = fdtdec_lookup_phandle(fdt, phys, "ti,ctrl_mod");
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->ctrl_mod_base = (void *)fdtdec_get_addr(fdt, ctrl_mod, "reg");
|
2016-11-17 09:08:11 +00:00
|
|
|
usb_index = ti_musb_get_usb_index(node);
|
|
|
|
switch (usb_index) {
|
|
|
|
case 1:
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->ctrl_mod_base += AM335X_USB1_CTRL;
|
2018-12-04 10:30:57 +00:00
|
|
|
break;
|
2016-11-17 09:08:11 +00:00
|
|
|
case 0:
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->ctrl_mod_base += AM335X_USB0_CTRL;
|
2018-12-04 10:30:57 +00:00
|
|
|
break;
|
2016-11-17 09:08:11 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
musb_config = malloc(sizeof(struct musb_hdrc_config));
|
|
|
|
memset(musb_config, 0, sizeof(struct musb_hdrc_config));
|
|
|
|
|
|
|
|
musb_config->multipoint = fdtdec_get_int(fdt, node,
|
|
|
|
"mentor,multipoint", -1);
|
|
|
|
if (musb_config->multipoint < 0) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("MUSB multipoint DT entry missing\n");
|
2016-11-17 09:08:11 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
musb_config->dyn_fifo = 1;
|
2016-11-17 09:08:11 +00:00
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
musb_config->num_eps = fdtdec_get_int(fdt, node, "mentor,num-eps",
|
|
|
|
-1);
|
|
|
|
if (musb_config->num_eps < 0) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("MUSB num-eps DT entry missing\n");
|
2016-11-17 09:08:11 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
musb_config->ram_bits = fdtdec_get_int(fdt, node, "mentor,ram-bits",
|
|
|
|
-1);
|
|
|
|
if (musb_config->ram_bits < 0) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("MUSB ram-bits DT entry missing\n");
|
2016-11-17 09:08:11 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.config = musb_config;
|
2016-11-17 09:08:11 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1);
|
|
|
|
if (plat->plat.power < 0) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("MUSB mentor,power DT entry missing\n");
|
2016-11-17 09:08:11 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.platform_ops = &musb_dsps_ops;
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-04 10:30:57 +00:00
|
|
|
#endif
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
static int ti_musb_host_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ti_musb_plat *plat = dev_get_plat(dev);
|
2016-11-17 09:08:11 +00:00
|
|
|
struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
priv->desc_before_addr = true;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
host->host = musb_init_controller(&plat->plat,
|
2018-12-04 10:30:57 +00:00
|
|
|
NULL,
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->base);
|
2016-11-17 09:08:11 +00:00
|
|
|
if (!host->host)
|
|
|
|
return -EIO;
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
ti_musb_set_phy_power(dev, 1);
|
2016-11-17 09:08:11 +00:00
|
|
|
ret = musb_lowlevel_init(host);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ti_musb_host_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
|
|
|
|
musb_stop(host->host);
|
2018-12-04 10:30:57 +00:00
|
|
|
ti_musb_set_phy_power(dev, 0);
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2020-12-03 23:55:21 +00:00
|
|
|
static int ti_musb_host_of_to_plat(struct udevice *dev)
|
2016-11-17 09:08:11 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ti_musb_plat *plat = dev_get_plat(dev);
|
2016-11-17 09:08:11 +00:00
|
|
|
const void *fdt = gd->fdt_blob;
|
2017-01-17 23:52:55 +00:00
|
|
|
int node = dev_of_offset(dev);
|
2016-11-17 09:08:11 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
ret = ti_musb_of_to_plat(dev);
|
2016-11-17 09:08:11 +00:00
|
|
|
if (ret) {
|
2020-12-03 23:55:18 +00:00
|
|
|
pr_err("plat dt parse error\n");
|
2016-11-17 09:08:11 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.mode = MUSB_HOST;
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-04 10:30:57 +00:00
|
|
|
#endif
|
2016-11-17 09:08:11 +00:00
|
|
|
|
|
|
|
U_BOOT_DRIVER(ti_musb_host) = {
|
|
|
|
.name = "ti-musb-host",
|
|
|
|
.id = UCLASS_USB,
|
2018-12-04 10:30:57 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = ti_musb_host_of_to_plat,
|
2018-12-04 10:30:57 +00:00
|
|
|
#endif
|
2016-11-17 09:08:11 +00:00
|
|
|
.probe = ti_musb_host_probe,
|
|
|
|
.remove = ti_musb_host_remove,
|
|
|
|
.ops = &musb_usb_ops,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct ti_musb_plat),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct musb_host_data),
|
2016-11-17 09:08:11 +00:00
|
|
|
};
|
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
|
|
|
|
struct ti_musb_peripheral {
|
|
|
|
struct musb *periph;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2020-12-03 23:55:21 +00:00
|
|
|
static int ti_musb_peripheral_of_to_plat(struct udevice *dev)
|
2018-12-04 10:30:57 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ti_musb_plat *plat = dev_get_plat(dev);
|
2018-12-04 10:30:57 +00:00
|
|
|
const void *fdt = gd->fdt_blob;
|
|
|
|
int node = dev_of_offset(dev);
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
ret = ti_musb_of_to_plat(dev);
|
2018-12-04 10:30:57 +00:00
|
|
|
if (ret) {
|
2020-12-03 23:55:18 +00:00
|
|
|
pr_err("plat dt parse error\n");
|
2018-12-04 10:30:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->plat.mode = MUSB_PERIPHERAL;
|
2018-12-04 10:30:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ti_musb_peripheral *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->periph->isr(0, priv->periph);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ti_musb_peripheral_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ti_musb_peripheral *priv = dev_get_priv(dev);
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ti_musb_plat *plat = dev_get_plat(dev);
|
2018-12-04 10:30:57 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
priv->periph = musb_init_controller(&plat->plat,
|
2018-12-04 10:30:57 +00:00
|
|
|
NULL,
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->base);
|
2018-12-04 10:30:57 +00:00
|
|
|
if (!priv->periph)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
ti_musb_set_phy_power(dev, 1);
|
|
|
|
musb_gadget_setup(priv->periph);
|
|
|
|
return usb_add_gadget_udc((struct device *)dev, &priv->periph->g);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ti_musb_peripheral_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ti_musb_peripheral *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
usb_del_gadget_udc(&priv->periph->g);
|
|
|
|
ti_musb_set_phy_power(dev, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ti_musb_peripheral) = {
|
|
|
|
.name = "ti-musb-peripheral",
|
|
|
|
.id = UCLASS_USB_GADGET_GENERIC,
|
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = ti_musb_peripheral_of_to_plat,
|
2018-12-04 10:30:57 +00:00
|
|
|
#endif
|
|
|
|
.probe = ti_musb_peripheral_probe,
|
|
|
|
.remove = ti_musb_peripheral_remove,
|
|
|
|
.ops = &musb_usb_ops,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct ti_musb_plat),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct ti_musb_peripheral),
|
2018-12-04 10:30:57 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2016-11-17 09:08:08 +00:00
|
|
|
static int ti_musb_wrapper_bind(struct udevice *parent)
|
|
|
|
{
|
2020-03-04 00:59:50 +00:00
|
|
|
ofnode node;
|
2016-11-17 09:08:08 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-12-19 17:40:14 +00:00
|
|
|
ofnode_for_each_subnode(node, dev_ofnode(parent)) {
|
2016-11-17 09:08:08 +00:00
|
|
|
struct udevice *dev;
|
2020-03-04 00:59:50 +00:00
|
|
|
const char *name = ofnode_get_name(node);
|
2016-11-17 09:08:08 +00:00
|
|
|
enum usb_dr_mode dr_mode;
|
|
|
|
struct driver *drv;
|
|
|
|
|
|
|
|
if (strncmp(name, "usb@", 4))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dr_mode = usb_get_dr_mode(node);
|
|
|
|
switch (dr_mode) {
|
|
|
|
case USB_DR_MODE_PERIPHERAL:
|
|
|
|
/* Bind MUSB device */
|
2018-12-04 10:30:57 +00:00
|
|
|
ret = device_bind_driver_to_node(parent,
|
|
|
|
"ti-musb-peripheral",
|
|
|
|
name,
|
2020-03-04 00:59:50 +00:00
|
|
|
node,
|
2018-12-04 10:30:57 +00:00
|
|
|
&dev);
|
|
|
|
if (ret)
|
|
|
|
pr_err("musb - not able to bind usb peripheral node\n");
|
2016-11-17 09:08:08 +00:00
|
|
|
break;
|
|
|
|
case USB_DR_MODE_HOST:
|
|
|
|
/* Bind MUSB host */
|
2018-12-04 10:30:57 +00:00
|
|
|
ret = device_bind_driver_to_node(parent,
|
|
|
|
"ti-musb-host",
|
|
|
|
name,
|
2020-03-04 00:59:50 +00:00
|
|
|
node,
|
2018-12-04 10:30:57 +00:00
|
|
|
&dev);
|
|
|
|
if (ret)
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("musb - not able to bind usb host node\n");
|
2016-11-17 09:08:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id ti_musb_ids[] = {
|
|
|
|
{ .compatible = "ti,am33xx-usb" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ti_musb_wrapper) = {
|
|
|
|
.name = "ti-musb-wrapper",
|
|
|
|
.id = UCLASS_MISC,
|
|
|
|
.of_match = ti_musb_ids,
|
|
|
|
.bind = ti_musb_wrapper_bind,
|
|
|
|
};
|
2018-12-04 10:30:57 +00:00
|
|
|
#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
|
2016-11-17 09:08:08 +00:00
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#endif /* CONFIG_IS_ENABLED(DM_USB) */
|