From: Mugunthan V N <mugunthan...@ti.com>

Add a misc driver for DWC3 wrapper, so that based on dr_mode the
USB devices can bind to USB host or USB device drivers.

Based on dr_mode property, the device node needs to bind to either
"host" driver or "peripheral" driver. This wrapper will on bind
read dr_mode property and appropriately associate USB DT node with DWC3
peripheral driver or host driver.

This is similar to what exists today for MUSB and is instantiated by
arch_misc_init() function for am33xx and am43xx.

Signed-off-by: Mugunthan V N <mugunthan...@ti.com>
Signed-off-by: Vignesh R <vigne...@ti.com>
---
 drivers/usb/dwc3/dwc3-omap.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/dwc3/gadget.c    |  2 +-
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index b4dde726c6f3..b7daf499515d 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -628,4 +628,53 @@ U_BOOT_DRIVER(dwc3_omap_peripheral) = {
        .priv_auto_alloc_size = sizeof(struct omap_dwc3_priv),
        .flags  = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static int ti_dwc3_wrapper_bind(struct udevice *parent)
+{
+       ofnode node;
+       int ret;
+
+       dev_for_each_subnode(node, parent) {
+               const char *name = ofnode_get_name(node);
+               enum usb_dr_mode dr_mode;
+               struct udevice *dev;
+
+               if (strncmp(name, "usb@", 4))
+                       continue;
+
+               dr_mode = usb_get_dr_mode(ofnode_to_offset(node));
+               switch (dr_mode) {
+               case USB_DR_MODE_PERIPHERAL:
+               case USB_DR_MODE_OTG:
+                       /* Bind MUSB device */
+                       ret = device_bind_driver_to_node(parent,
+                                                        "dwc3-omap-peripheral",
+                                                        name, node, &dev);
+                       if (ret) {
+                               error("dwc3 - not able to bind usb device 
node\n");
+                               return ret;
+                       }
+                       break;
+               case USB_DR_MODE_HOST:
+                       /* Bind MUSB host */
+                       break;
+               default:
+                       break;
+               };
+       }
+       return 0;
+}
+
+static const struct udevice_id ti_dwc3_ids[] = {
+       { .compatible = "ti,am437x-dwc3" },
+       { }
+};
+
+U_BOOT_DRIVER(ti_dwc3_wrapper) = {
+       .name   = "ti-dwc3-wrapper",
+       .id     = UCLASS_MISC,
+       .of_match = ti_dwc3_ids,
+       .bind = ti_dwc3_wrapper_bind,
+};
+
 #endif /* CONFIG_DM_USB */
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index e065c5aeb38d..18bbd5318e48 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2610,7 +2610,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
        if (ret)
                goto err4;
 
-       ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
+       ret = usb_add_gadget_udc((struct device *)dwc->dev, &dwc->gadget);
        if (ret) {
                dev_err(dwc->dev, "failed to register udc\n");
                goto err4;
-- 
2.13.0

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to