From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mugunthan V N Date: Thu, 12 May 2016 11:19:52 +0530 Subject: [U-Boot] [PATCH v2 07/11] drivers: usb: musb: add ti musb peripheral driver with driver model support In-Reply-To: <5731D687.40709@denx.de> References: <20160510114816.2899-1-mugunthanvnm@ti.com> <20160510114816.2899-8-mugunthanvnm@ti.com> <5731D687.40709@denx.de> Message-ID: <57341980.6030006@ti.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Tuesday 10 May 2016 06:09 PM, Marek Vasut wrote: > On 05/10/2016 01:48 PM, Mugunthan V N wrote: >> Add a TI MUSB peripheral driver with driver model support and the >> driver will be bound by the MUSB wrapper driver based on the >> dr_mode device tree entry. >> >> Signed-off-by: Mugunthan V N >> --- >> drivers/usb/musb-new/musb_uboot.c | 2 + >> drivers/usb/musb-new/ti-musb.c | 113 ++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 115 insertions(+) >> >> diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c >> index 6ce528c..b03b556 100644 >> --- a/drivers/usb/musb-new/musb_uboot.c >> +++ b/drivers/usb/musb-new/musb_uboot.c >> @@ -373,6 +373,7 @@ struct dm_usb_ops musb_usb_ops = { >> #endif /* CONFIG_DM_USB */ >> #endif /* CONFIG_USB_MUSB_HOST */ >> >> +#ifndef CONFIG_DM_USB >> #ifdef CONFIG_USB_MUSB_GADGET >> static struct musb *gadget; >> >> @@ -453,3 +454,4 @@ int musb_register(struct musb_hdrc_platform_data *plat, void *bdata, >> >> return 0; >> } >> +#endif /* CONFIG_DM_USB */ >> diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c >> index 1c15aa2..11d10aa 100644 >> --- a/drivers/usb/musb-new/ti-musb.c >> +++ b/drivers/usb/musb-new/ti-musb.c >> @@ -14,6 +14,7 @@ >> #include >> #include >> >> +#include >> #include >> #include >> #include "musb_uboot.h" >> @@ -142,6 +143,110 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) >> return 0; >> } >> >> +static struct musb *gadget; >> + >> +int usb_gadget_handle_interrupts(int index) >> +{ >> + WATCHDOG_RESET(); >> + if (!gadget || !gadget->isr) >> + return -EINVAL; >> + >> + return gadget->isr(0, gadget); >> +} >> + >> +int usb_gadget_register_driver(struct usb_gadget_driver *driver) >> +{ >> + int ret; >> + >> + if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind || >> + !driver->setup) { >> + printf("bad parameter.\n"); > > Sentence usually starts with capital letter and ends with fullstop (not > the case below). > >> + return -EINVAL; >> + } >> + >> + if (!gadget) { >> + printf("Controller uninitialized\n"); >> + return -ENXIO; >> + } >> + >> + ret = musb_gadget_start(&gadget->g, driver); >> + if (ret < 0) { >> + printf("gadget_start failed with %d\n", ret); >> + return ret; >> + } >> + >> + ret = driver->bind(&gadget->g); >> + if (ret < 0) { >> + printf("bind failed with %d\n", ret); > > Are all these prints really useful ? This function is just a carry forward from non-DM driver, will have a look to remove irrelevant logs. Regards Mugunthan V N > >> + return ret; >> + } >> + >> + return 0; >> +} >> + >> +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) >> +{ >> + if (driver->disconnect) >> + driver->disconnect(&gadget->g); >> + if (driver->unbind) >> + driver->unbind(&gadget->g); >> + return 0; >> +} >> + >> +static int ti_musb_peripheral_usb_probe(struct udevice *dev) >> +{ >> + struct ti_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; >> + >> + otg_board_data = &platdata->otg_board_data; >> + >> + gadget = musb_init_controller(&platdata->plat, >> + (struct device *)otg_board_data, >> + platdata->base); >> + if (!gadget) { >> + error("gadget init failed\n"); >> + return -EIO; >> + } >> + >> + return 0; >> +} >> + >> +static int ti_musb_peripheral_remove(struct udevice *dev) >> +{ >> + musb_stop(gadget); >> + >> + return 0; >> +} >> + >> +static int ti_musb_peripheral_ofdata_to_platdata(struct udevice *dev) >> +{ >> + struct ti_musb_platdata *platdata = dev_get_platdata(dev); >> + const void *fdt = gd->fdt_blob; >> + int node = dev->of_offset; >> + int ret; >> + >> + ret = ti_musb_ofdata_to_platdata(dev); >> + if (ret) { >> + error("platdata dt parse error\n"); >> + return ret; >> + } >> + >> + platdata->plat.mode = MUSB_PERIPHERAL; >> + >> + return 0; >> +} >> + >> +U_BOOT_DRIVER(ti_musb_peripheral) = { >> + .name = "ti-musb-peripheral", >> + .id = UCLASS_USB_DEV_GENERIC, >> + .ofdata_to_platdata = ti_musb_peripheral_ofdata_to_platdata, >> + .probe = ti_musb_peripheral_usb_probe, >> + .remove = ti_musb_peripheral_remove, >> + .platdata_auto_alloc_size = sizeof(struct ti_musb_platdata), >> + .priv_auto_alloc_size = sizeof(struct musb), >> +}; >> + >> static int ti_musb_host_probe(struct udevice *dev) >> { >> struct musb_host_data *host = dev_get_priv(dev); >> @@ -222,7 +327,15 @@ static int ti_musb_wrapper_bind(struct udevice *parent) >> dr_mode = usb_get_dr_mode(node); >> switch (dr_mode) { >> case USB_DR_MODE_PERIPHERAL: >> + case USB_DR_MODE_OTG: >> /* Bind MUSB device */ >> + ret = device_bind_driver_to_node(parent, >> + "ti-musb-peripheral", >> + name, node, &dev); >> + if (ret) { >> + error("musb - not able to bind usb device node\n"); >> + return ret; >> + } >> break; >> case USB_DR_MODE_HOST: >> /* Bind MUSB host */ >> > >