diff options
author | Tom Rini <trini@konsulko.com> | 2018-08-24 16:11:01 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-08-24 16:11:01 -0400 |
commit | 15fd1b7903a3090a03cfe453f661822a613a91ee (patch) | |
tree | 65ab83a17440b38d1c5b61f447e309291eb2ff28 /drivers | |
parent | 8b7f04f14a1b790ff8dec0afc28a9e8477a6eb88 (diff) | |
parent | 49c752c93a785b9bad9d3fbbd52a76bec003eac5 (diff) |
Merge branch 'master' of git://git.denx.de/u-boot-usb
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/core/device-remove.c | 30 | ||||
-rw-r--r-- | drivers/core/device.c | 19 | ||||
-rw-r--r-- | drivers/core/dump.c | 16 | ||||
-rw-r--r-- | drivers/core/uclass.c | 21 | ||||
-rw-r--r-- | drivers/usb/gadget/gadget_chips.h | 2 | ||||
-rw-r--r-- | drivers/usb/musb-new/omap2430.c | 596 |
6 files changed, 173 insertions, 511 deletions
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 1cf2278e9e..586fadee0a 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -17,16 +17,7 @@ #include <dm/uclass-internal.h> #include <dm/util.h> -/** - * device_chld_unbind() - Unbind all device's children from the device - * - * On error, the function continues to unbind all children, and reports the - * first error. - * - * @dev: The device that is to be stripped of its children - * @return 0 on success, -ve on error - */ -static int device_chld_unbind(struct udevice *dev) +int device_chld_unbind(struct udevice *dev, struct driver *drv) { struct udevice *pos, *n; int ret, saved_ret = 0; @@ -34,6 +25,9 @@ static int device_chld_unbind(struct udevice *dev) assert(dev); list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { + if (drv && (pos->driver != drv)) + continue; + ret = device_unbind(pos); if (ret && !saved_ret) saved_ret = ret; @@ -42,13 +36,8 @@ static int device_chld_unbind(struct udevice *dev) return saved_ret; } -/** - * device_chld_remove() - Stop all device's children - * @dev: The device whose children are to be removed - * @pre_os_remove: Flag, if this functions is called in the pre-OS stage - * @return 0 on success, -ve on error - */ -static int device_chld_remove(struct udevice *dev, uint flags) +int device_chld_remove(struct udevice *dev, struct driver *drv, + uint flags) { struct udevice *pos, *n; int ret; @@ -56,6 +45,9 @@ static int device_chld_remove(struct udevice *dev, uint flags) assert(dev); list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { + if (drv && (pos->driver != drv)) + continue; + ret = device_remove(pos, flags); if (ret) return ret; @@ -87,7 +79,7 @@ int device_unbind(struct udevice *dev) return ret; } - ret = device_chld_unbind(dev); + ret = device_chld_unbind(dev, NULL); if (ret) return ret; @@ -178,7 +170,7 @@ int device_remove(struct udevice *dev, uint flags) if (ret) return ret; - ret = device_chld_remove(dev, flags); + ret = device_chld_remove(dev, NULL, flags); if (ret) goto err; diff --git a/drivers/core/device.c b/drivers/core/device.c index 207d566b71..fd59fe1e0f 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -594,16 +594,16 @@ int device_get_child_by_of_offset(struct udevice *parent, int node, return device_get_device_tail(dev, ret, devp); } -static struct udevice *_device_find_global_by_of_offset(struct udevice *parent, - int of_offset) +static struct udevice *_device_find_global_by_ofnode(struct udevice *parent, + ofnode ofnode) { struct udevice *dev, *found; - if (dev_of_offset(parent) == of_offset) + if (ofnode_equal(dev_ofnode(parent), ofnode)) return parent; list_for_each_entry(dev, &parent->child_head, sibling_node) { - found = _device_find_global_by_of_offset(dev, of_offset); + found = _device_find_global_by_ofnode(dev, ofnode); if (found) return found; } @@ -611,11 +611,18 @@ static struct udevice *_device_find_global_by_of_offset(struct udevice *parent, return NULL; } -int device_get_global_by_of_offset(int of_offset, struct udevice **devp) +int device_find_global_by_ofnode(ofnode ofnode, struct udevice **devp) +{ + *devp = _device_find_global_by_ofnode(gd->dm_root, ofnode); + + return *devp ? 0 : -ENOENT; +} + +int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp) { struct udevice *dev; - dev = _device_find_global_by_of_offset(gd->dm_root, of_offset); + dev = _device_find_global_by_ofnode(gd->dm_root, ofnode); return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); } diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 58820cdb2f..d7cdb1475d 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -8,6 +8,7 @@ #include <mapmem.h> #include <dm/root.h> #include <dm/util.h> +#include <dm/uclass-internal.h> static void show_devices(struct udevice *dev, int depth, int last_flag) { @@ -15,7 +16,8 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) struct udevice *child; /* print the first 11 characters to not break the tree-format. */ - printf(" %-10.10s [ %c ] %-10.10s ", dev->uclass->uc_drv->name, + printf(" %-10.10s %d [ %c ] %-10.10s ", dev->uclass->uc_drv->name, + dev_get_uclass_index(dev, NULL), dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name); for (i = depth; i >= 0; i--) { @@ -47,8 +49,8 @@ void dm_dump_all(void) root = dm_root(); if (root) { - printf(" Class Probed Driver Name\n"); - printf("----------------------------------------\n"); + printf(" Class index Probed Driver Name\n"); + printf("-----------------------------------------\n"); show_devices(root, -1, 0); } } @@ -60,9 +62,9 @@ void dm_dump_all(void) * * @dev: Device to display */ -static void dm_display_line(struct udevice *dev) +static void dm_display_line(struct udevice *dev, int index) { - printf("- %c %s @ %08lx", + printf("%i %c %s @ %08lx", index, dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', dev->name, (ulong)map_to_sysmem(dev)); if (dev->seq != -1 || dev->req_seq != -1) @@ -78,6 +80,7 @@ void dm_dump_uclass(void) for (id = 0; id < UCLASS_COUNT; id++) { struct udevice *dev; + int i = 0; ret = uclass_get(id, &uc); if (ret) @@ -87,7 +90,8 @@ void dm_dump_uclass(void) if (list_empty(&uc->dev_head)) continue; list_for_each_entry(dev, &uc->dev_head, uclass_node) { - dm_display_line(dev); + dm_display_line(dev, i); + i++; } puts("\n"); } diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index d609b170e1..3113d6a56b 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -171,6 +171,27 @@ enum uclass_id uclass_get_by_name(const char *name) return UCLASS_INVALID; } +int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp) +{ + struct udevice *iter; + struct uclass *uc = dev->uclass; + int i = 0; + + if (list_empty(&uc->dev_head)) + return -ENODEV; + + list_for_each_entry(iter, &uc->dev_head, uclass_node) { + if (iter == dev) { + if (ucp) + *ucp = uc; + return i; + } + i++; + } + + return -ENODEV; +} + int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) { struct uclass *uc; diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index b9b081999a..2c8f235d51 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h @@ -206,5 +206,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) return 0x21; else if (gadget_is_fotg210(gadget)) return 0x22; + else if (gadget_is_dwc3(gadget)) + return 0x23; return -ENOENT; } diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c index 4753d79ede..342d76bd6f 100644 --- a/drivers/usb/musb-new/omap2430.c +++ b/drivers/usb/musb-new/omap2430.c @@ -8,201 +8,19 @@ * * This file is part of the Inventra Controller Driver for Linux. */ -#ifndef __UBOOT__ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/init.h> -#include <linux/list.h> -#include <linux/io.h> -#include <linux/platform_device.h> -#include <linux/dma-mapping.h> -#include <linux/pm_runtime.h> -#include <linux/err.h> -#include <linux/usb/musb-omap.h> -#else #include <common.h> +#include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <linux/usb/otg.h> #include <asm/omap_common.h> #include <asm/omap_musb.h> #include <twl4030.h> #include <twl6030.h> #include "linux-compat.h" -#endif - #include "musb_core.h" #include "omap2430.h" - -#ifndef __UBOOT__ -struct omap2430_glue { - struct device *dev; - struct platform_device *musb; - enum omap_musb_vbus_id_status status; - struct work_struct omap_musb_mailbox_work; -}; -#define glue_to_musb(g) platform_get_drvdata(g->musb) - -struct omap2430_glue *_glue; - -static struct timer_list musb_idle_timer; - -static void musb_do_idle(unsigned long _musb) -{ - struct musb *musb = (void *)_musb; - unsigned long flags; - u8 power; - u8 devctl; - - spin_lock_irqsave(&musb->lock, flags); - - switch (musb->xceiv->state) { - case OTG_STATE_A_WAIT_BCON: - - devctl = musb_readb(musb->mregs, MUSB_DEVCTL); - if (devctl & MUSB_DEVCTL_BDEVICE) { - musb->xceiv->state = OTG_STATE_B_IDLE; - MUSB_DEV_MODE(musb); - } else { - musb->xceiv->state = OTG_STATE_A_IDLE; - MUSB_HST_MODE(musb); - } - break; - case OTG_STATE_A_SUSPEND: - /* finish RESUME signaling? */ - if (musb->port1_status & MUSB_PORT_STAT_RESUME) { - power = musb_readb(musb->mregs, MUSB_POWER); - power &= ~MUSB_POWER_RESUME; - dev_dbg(musb->controller, "root port resume stopped, power %02x\n", power); - musb_writeb(musb->mregs, MUSB_POWER, power); - musb->is_active = 1; - musb->port1_status &= ~(USB_PORT_STAT_SUSPEND - | MUSB_PORT_STAT_RESUME); - musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; - usb_hcd_poll_rh_status(musb_to_hcd(musb)); - /* NOTE: it might really be A_WAIT_BCON ... */ - musb->xceiv->state = OTG_STATE_A_HOST; - } - break; - case OTG_STATE_A_HOST: - devctl = musb_readb(musb->mregs, MUSB_DEVCTL); - if (devctl & MUSB_DEVCTL_BDEVICE) - musb->xceiv->state = OTG_STATE_B_IDLE; - else - musb->xceiv->state = OTG_STATE_A_WAIT_BCON; - default: - break; - } - spin_unlock_irqrestore(&musb->lock, flags); -} - - -static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) -{ - unsigned long default_timeout = jiffies + msecs_to_jiffies(3); - static unsigned long last_timer; - - if (timeout == 0) - timeout = default_timeout; - - /* Never idle if active, or when VBUS timeout is not set as host */ - if (musb->is_active || ((musb->a_wait_bcon == 0) - && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { - dev_dbg(musb->controller, "%s active, deleting timer\n", - otg_state_string(musb->xceiv->state)); - del_timer(&musb_idle_timer); - last_timer = jiffies; - return; - } - - if (time_after(last_timer, timeout)) { - if (!timer_pending(&musb_idle_timer)) - last_timer = timeout; - else { - dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n"); - return; - } - } - last_timer = timeout; - - dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", - otg_state_string(musb->xceiv->state), - (unsigned long)jiffies_to_msecs(timeout - jiffies)); - mod_timer(&musb_idle_timer, timeout); -} - -static void omap2430_musb_set_vbus(struct musb *musb, int is_on) -{ - struct usb_otg *otg = musb->xceiv->otg; - u8 devctl; - unsigned long timeout = jiffies + msecs_to_jiffies(1000); - int ret = 1; - /* HDRC controls CPEN, but beware current surges during device - * connect. They can trigger transient overcurrent conditions - * that must be ignored. - */ - - devctl = musb_readb(musb->mregs, MUSB_DEVCTL); - - if (is_on) { - if (musb->xceiv->state == OTG_STATE_A_IDLE) { - /* start the session */ - devctl |= MUSB_DEVCTL_SESSION; - musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); - /* - * Wait for the musb to set as A device to enable the - * VBUS - */ - while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { - - cpu_relax(); - - if (time_after(jiffies, timeout)) { - dev_err(musb->controller, - "configured as A device timeout"); - ret = -EINVAL; - break; - } - } - - if (ret && otg->set_vbus) - otg_set_vbus(otg, 1); - } else { - musb->is_active = 1; - otg->default_a = 1; - musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; - devctl |= MUSB_DEVCTL_SESSION; - MUSB_HST_MODE(musb); - } - } else { - musb->is_active = 0; - - /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and - * jumping right to B_IDLE... - */ - - otg->default_a = 0; - musb->xceiv->state = OTG_STATE_B_IDLE; - devctl &= ~MUSB_DEVCTL_SESSION; - - MUSB_DEV_MODE(musb); - } - musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); - - dev_dbg(musb->controller, "VBUS %s, devctl %02x " - /* otg %3x conf %08x prcm %08x */ "\n", - otg_state_string(musb->xceiv->state), - musb_readb(musb->mregs, MUSB_DEVCTL)); -} - -static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode) -{ - u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); - - devctl |= MUSB_DEVCTL_SESSION; - musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); - - return 0; -} -#endif +#include "musb_uboot.h" static inline void omap2430_low_level_exit(struct musb *musb) { @@ -223,100 +41,15 @@ static inline void omap2430_low_level_init(struct musb *musb) musb_writel(musb->mregs, OTG_FORCESTDBY, l); } -#ifndef __UBOOT__ -void omap_musb_mailbox(enum omap_musb_vbus_id_status status) -{ - struct omap2430_glue *glue = _glue; - struct musb *musb = glue_to_musb(glue); - - glue->status = status; - if (!musb) { - dev_err(glue->dev, "musb core is not yet ready\n"); - return; - } - - schedule_work(&glue->omap_musb_mailbox_work); -} -EXPORT_SYMBOL_GPL(omap_musb_mailbox); - -static void omap_musb_set_mailbox(struct omap2430_glue *glue) -{ - struct musb *musb = glue_to_musb(glue); - struct device *dev = musb->controller; - struct musb_hdrc_platform_data *pdata = dev->platform_data; - struct omap_musb_board_data *data = pdata->board_data; - struct usb_otg *otg = musb->xceiv->otg; - - switch (glue->status) { - case OMAP_MUSB_ID_GROUND: - dev_dbg(dev, "ID GND\n"); - - otg->default_a = true; - musb->xceiv->state = OTG_STATE_A_IDLE; - musb->xceiv->last_event = USB_EVENT_ID; - if (!is_otg_enabled(musb) || musb->gadget_driver) { - pm_runtime_get_sync(dev); - usb_phy_init(musb->xceiv); - omap2430_musb_set_vbus(musb, 1); - } - break; - - case OMAP_MUSB_VBUS_VALID: - dev_dbg(dev, "VBUS Connect\n"); - - otg->default_a = false; - musb->xceiv->state = OTG_STATE_B_IDLE; - musb->xceiv->last_event = USB_EVENT_VBUS; - if (musb->gadget_driver) - pm_runtime_get_sync(dev); - usb_phy_init(musb->xceiv); - break; - - case OMAP_MUSB_ID_FLOAT: - case OMAP_MUSB_VBUS_OFF: - dev_dbg(dev, "VBUS Disconnect\n"); - - musb->xceiv->last_event = USB_EVENT_NONE; - if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) - if (musb->gadget_driver) { - pm_runtime_mark_last_busy(dev); - pm_runtime_put_autosuspend(dev); - } - - if (data->interface_type == MUSB_INTERFACE_UTMI) { - if (musb->xceiv->otg->set_vbus) - otg_set_vbus(musb->xceiv->otg, 0); - } - usb_phy_shutdown(musb->xceiv); - break; - default: - dev_dbg(dev, "ID float\n"); - } -} - - -static void omap_musb_mailbox_work(struct work_struct *mailbox_work) -{ - struct omap2430_glue *glue = container_of(mailbox_work, - struct omap2430_glue, omap_musb_mailbox_work); - omap_musb_set_mailbox(glue); -} -#endif static int omap2430_musb_init(struct musb *musb) { u32 l; int status = 0; unsigned long int start; -#ifndef __UBOOT__ - struct device *dev = musb->controller; - struct omap2430_glue *glue = dev_get_drvdata(dev->parent); - struct musb_hdrc_platform_data *plat = dev->platform_data; - struct omap_musb_board_data *data = plat->board_data; -#else + struct omap_musb_board_data *data = (struct omap_musb_board_data *)musb->controller; -#endif /* Reset the controller */ musb_writel(musb->mregs, OTG_SYSCONFIG, SOFTRST); @@ -334,24 +67,6 @@ static int omap2430_musb_init(struct musb *musb) } } -#ifndef __UBOOT__ - /* We require some kind of external transceiver, hooked - * up through ULPI. TWL4030-family PMICs include one, - * which needs a driver, drivers aren't always needed. - */ - musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); - if (IS_ERR_OR_NULL(musb->xceiv)) { - pr_err("HS USB OTG: no transceiver configured\n"); - return -ENODEV; - } - - status = pm_runtime_get_sync(dev); - if (status < 0) { - dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status); - goto err1; - } -#endif - l = musb_readl(musb->mregs, OTG_INTERFSEL); if (data->interface_type == MUSB_INTERFACE_UTMI) { @@ -371,64 +86,14 @@ static int omap2430_musb_init(struct musb *musb) musb_readl(musb->mregs, OTG_SYSSTATUS), musb_readl(musb->mregs, OTG_INTERFSEL), musb_readl(musb->mregs, OTG_SIMENABLE)); - -#ifndef __UBOOT__ - setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); - - if (glue->status != OMAP_MUSB_UNKNOWN) - omap_musb_set_mailbox(glue); - - pm_runtime_put_noidle(musb->controller); -#endif return 0; err1: return status; } -#ifndef __UBOOT__ -static void omap2430_musb_enable(struct musb *musb) -#else static int omap2430_musb_enable(struct musb *musb) -#endif { -#ifndef __UBOOT__ - u8 devctl; - unsigned long timeout = jiffies + msecs_to_jiffies(1000); - struct device *dev = musb->controller; - struct omap2430_glue *glue = dev_get_drvdata(dev->parent); - struct musb_hdrc_platform_data *pdata = dev->platform_data; - struct omap_musb_board_data *data = pdata->board_data; - - switch (glue->status) { - - case OMAP_MUSB_ID_GROUND: - usb_phy_init(musb->xceiv); - if (data->interface_type != MUSB_INTERFACE_UTMI) - break; - devctl = musb_readb(musb->mregs, MUSB_DEVCTL); - /* start the session */ - devctl |= MUSB_DEVCTL_SESSION; - musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); - while (musb_readb(musb->mregs, MUSB_DEVCTL) & - MUSB_DEVCTL_BDEVICE) { - cpu_relax(); - - if (time_after(jiffies, timeout)) { - dev_err(dev, "configured as A device timeout"); - break; - } - } - break; - - case OMAP_MUSB_VBUS_VALID: - usb_phy_init(musb->xceiv); - break; - - default: - break; - } -#else #ifdef CONFIG_TWL4030_USB if (twl4030_usb_ulpi_init()) { serial_printf("ERROR: %s Could not initialize PHY\n", @@ -447,18 +112,11 @@ static int omap2430_musb_enable(struct musb *musb) #endif return 0; -#endif } static void omap2430_musb_disable(struct musb *musb) { -#ifndef __UBOOT__ - struct device *dev = musb->controller; - struct omap2430_glue *glue = dev_get_drvdata(dev->parent); - if (glue->status != OMAP_MUSB_UNKNOWN) - usb_phy_shutdown(musb->xceiv); -#endif } static int omap2430_musb_exit(struct musb *musb) @@ -470,174 +128,152 @@ static int omap2430_musb_exit(struct musb *musb) return 0; } -#ifndef __UBOOT__ -static const struct musb_platform_ops omap2430_ops = { -#else const struct musb_platform_ops omap2430_ops = { -#endif .init = omap2430_musb_init, .exit = omap2430_musb_exit, - -#ifndef __UBOOT__ - .set_mode = omap2430_musb_set_mode, - .try_idle = omap2430_musb_try_idle, - - .set_vbus = omap2430_musb_set_vbus, -#endif - .enable = omap2430_musb_enable, .disable = omap2430_musb_disable, }; -#ifndef __UBOOT__ -static u64 omap2430_dmamask = DMA_BIT_MASK(32); +#if defined(CONFIG_DM_USB) + +struct omap2430_musb_platdata { + 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; +}; -static int __devinit omap2430_probe(struct platform_device *pdev) +static int omap2430_musb_ofdata_to_platdata(struct udevice *dev) { - struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; - struct platform_device *musb; - struct omap2430_glue *glue; - int ret = -ENOMEM; - - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); - if (!glue) { - dev_err(&pdev->dev, "failed to allocate glue context\n"); - goto err0; + struct omap2430_musb_platdata *platdata = dev_get_platdata(dev); + const void *fdt = gd->fdt_blob; + int node = dev_of_offset(dev); + + platdata->base = (void *)dev_read_addr_ptr(dev); + + platdata->musb_config.multipoint = fdtdec_get_int(fdt, node, + "multipoint", + -1); + if (platdata->musb_config.multipoint < 0) { + pr_err("MUSB multipoint DT entry missing\n"); + return -ENOENT; } - musb = platform_device_alloc("musb-hdrc", -1); - if (!musb) { - dev_err(&pdev->dev, "failed to allocate musb device\n"); - goto err0; + platdata->musb_config.dyn_fifo = 1; + platdata->musb_config.num_eps = fdtdec_get_int(fdt, node, + "num-eps", -1); + if (platdata->musb_config.num_eps < 0) { + pr_err("MUSB num-eps DT entry missing\n"); + return -ENOENT; } - musb->dev.parent = &pdev->dev; - musb->dev.dma_mask = &omap2430_dmamask; - musb->dev.coherent_dma_mask = omap2430_dmamask; - - glue->dev = &pdev->dev; - glue->musb = musb; - glue->status = OMAP_MUSB_UNKNOWN; - - pdata->platform_ops = &omap2430_ops; - - platform_set_drvdata(pdev, glue); - - /* - * REVISIT if we ever have two instances of the wrapper, we will be - * in big trouble - */ - _glue = glue; - - INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); - - ret = platform_device_add_resources(musb, pdev->resource, - pdev->num_resources); - if (ret) { - dev_err(&pdev->dev, "failed to add resources\n"); - goto err1; + platdata->musb_config.ram_bits = fdtdec_get_int(fdt, node, + "ram-bits", -1); + if (platdata->musb_config.ram_bits < 0) { + pr_err("MUSB ram-bits DT entry missing\n"); + return -ENOENT; } - ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); - if (ret) { - dev_err(&pdev->dev, "failed to add platform_data\n"); - goto err1; + platdata->plat.power = fdtdec_get_int(fdt, node, + "power", -1); + if (platdata->plat.power < 0) { + pr_err("MUSB power DT entry missing\n"); + return -ENOENT; } - pm_runtime_enable(&pdev->dev); - - ret = platform_device_add(musb); - if (ret) { - dev_err(&pdev->dev, "failed to register musb device\n"); - goto err1; + platdata->otg_board_data.interface_type = fdtdec_get_int(fdt, node, + "interface-type", -1); + if (platdata->otg_board_data.interface_type < 0) { + pr_err("MUSB interface-type DT entry missing\n"); + return -ENOENT; } - return 0; - -err1: - platform_device_put(musb); - -err0: - return ret; -} - -static int __devexit omap2430_remove(struct platform_device *pdev) -{ - struct omap2430_glue *glue = platform_get_drvdata(pdev); - - cancel_work_sync(&glue->omap_musb_mailbox_work); - platform_device_del(glue->musb); - platform_device_put(glue->musb); - +#if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */ + platdata->plat.mode = fdtdec_get_int(fdt, node, + "mode", -1); + if (platdata->plat.mode < 0) { + 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 */ + platdata->plat.mode = MUSB_HOST; +#else /* For that matter, MUSB_PERIPHERAL doesn't either */ + platdata->plat.mode = MUSB_PERIPHERAL; +#endif +#endif + platdata->otg_board_data.dev = dev; + platdata->plat.config = &platdata->musb_config; + platdata->plat.platform_ops = &omap2430_ops; + platdata->plat.board_data = &platdata->otg_board_data; return 0; } -#ifdef CONFIG_PM - -static int omap2430_runtime_suspend(struct device *dev) +static int omap2430_musb_probe(struct udevice *dev) { - struct omap2430_glue *glue = dev_get_drvdata(dev); - struct musb *musb = glue_to_musb(glue); - - if (musb) { - musb->context.otg_interfsel = musb_readl(musb->mregs, - OTG_INTERFSEL); - - omap2430_low_level_exit(musb); - usb_phy_set_suspend(musb->xceiv, 1); +#ifdef CONFIG_USB_MUSB_HOST + struct musb_host_data *host = dev_get_priv(dev); +#endif + struct omap2430_musb_platdata *platdata = dev_get_platdata(dev); + struct usb_bus_priv *priv = dev_get_uclass_priv(dev); + struct omap_musb_board_data *otg_board_data; + int ret; + void *base = dev_read_addr_ptr(dev); + + priv->desc_before_addr = true; + + otg_board_data = &platdata->otg_board_data; + +#ifdef CONFIG_USB_MUSB_HOST + host->host = musb_init_controller(&platdata->plat, + (struct device *)otg_board_data, + platdata->base); + if (!host->host) { + return -EIO; } - return 0; + ret = musb_lowlevel_init(host); +#else + ret = musb_register(&platdata->plat, + (struct device *)otg_board_data, + platdata->base); +#endif + return ret; } -static int omap2430_runtime_resume(struct device *dev) +static int omap2430_musb_remove(struct udevice *dev) { - struct omap2430_glue *glue = dev_get_drvdata(dev); - struct musb *musb = glue_to_musb(glue); + struct musb_host_data *host = dev_get_priv(dev); - if (musb) { - omap2430_low_level_init(musb); - musb_writel(musb->mregs, OTG_INTERFSEL, - musb->context.otg_interfsel); - - usb_phy_set_suspend(musb->xceiv, 0); - } + musb_stop(host->host); return 0; } -static struct dev_pm_ops omap2430_pm_ops = { - .runtime_suspend = omap2430_runtime_suspend, - .runtime_resume = omap2430_runtime_resume, +static const struct udevice_id omap2430_musb_ids[] = { + { .compatible = "ti,omap3-musb" }, + { .compatible = "ti,omap4-musb" }, + { } }; -#define DEV_PM_OPS (&omap2430_pm_ops) +U_BOOT_DRIVER(omap2430_musb) = { + .name = "omap2430-musb", +#ifdef CONFIG_USB_MUSB_HOST + .id = UCLASS_USB, #else -#define DEV_PM_OPS NULL + .id = UCLASS_USB_DEV_GENERIC, #endif - -static struct platform_driver omap2430_driver = { - .probe = omap2430_probe, - .remove = __devexit_p(omap2430_remove), - .driver = { - .name = "musb-omap2430", - .pm = DEV_PM_OPS, - }, + .of_match = omap2430_musb_ids, + .ofdata_to_platdata = omap2430_musb_ofdata_to_platdata, + .probe = omap2430_musb_probe, + .remove = omap2430_musb_remove, +#ifdef CONFIG_USB_MUSB_HOST + .ops = &musb_usb_ops, +#endif + .platdata_auto_alloc_size = sizeof(struct omap2430_musb_platdata), + .priv_auto_alloc_size = sizeof(struct musb_host_data), }; -MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer"); -MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); -MODULE_LICENSE("GPL v2"); - -static int __init omap2430_init(void) -{ - return platform_driver_register(&omap2430_driver); -} -subsys_initcall(omap2430_init); - -static void __exit omap2430_exit(void) -{ - platform_driver_unregister(&omap2430_driver); -} -module_exit(omap2430_exit); -#endif +#endif /* CONFIG_DM_USB */ |