The upstream devicetree am33xx.dtsi does not have a "ti,am33xx-usb"
compatible, it uses "ti,sysc-omap4" for the same node. The
implementation of ti-musb uses a wrapper driver that binds to
ti,am33xx-usb and creates new devices ti-musb-host and
ti-musb-peripheral depending on the dr_mode property.

To avoid this wrapper driver with the upstream devicetree, add
compatibles for "ti,musb-am33xx" to both ti-musb-host and
ti-musb-peripheral. Add a bind function that checks for the correct
dr_mode value and rejects binding if it is not the correct driver.

Signed-off-by: Markus Schneider-Pargmann (TI.com) <[email protected]>
---
 drivers/usb/musb-new/ti-musb.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c
index 
d3c3d3057c1df2a5cc62df3c57d8b071bb0f12b8..3ed6428d09883cf5af28b212c0d614b3d8ef9227
 100644
--- a/drivers/usb/musb-new/ti-musb.c
+++ b/drivers/usb/musb-new/ti-musb.c
@@ -183,6 +183,16 @@ static int ti_musb_host_remove(struct udevice *dev)
 }
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+static int ti_musb_host_bind(struct udevice *dev)
+{
+       enum usb_dr_mode dr_mode = usb_get_dr_mode(dev_ofnode(dev));
+
+       if (dr_mode != USB_DR_MODE_HOST && dr_mode != USB_DR_MODE_OTG)
+               return -ENODEV;
+
+       return 0;
+}
+
 static int ti_musb_host_of_to_plat(struct udevice *dev)
 {
        struct ti_musb_plat *plat = dev_get_plat(dev);
@@ -200,12 +210,19 @@ static int ti_musb_host_of_to_plat(struct udevice *dev)
 
        return 0;
 }
+
+static const struct udevice_id ti_musb_host_ids[] = {
+       { .compatible = "ti,musb-am33xx" },
+       { }
+};
 #endif
 
 U_BOOT_DRIVER(ti_musb_host) = {
        .name   = "ti-musb-host",
        .id     = UCLASS_USB,
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+       .of_match = ti_musb_host_ids,
+       .bind = ti_musb_host_bind,
        .of_to_plat = ti_musb_host_of_to_plat,
 #endif
        .probe = ti_musb_host_probe,
@@ -221,6 +238,16 @@ struct ti_musb_peripheral {
 };
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+static int ti_musb_peripheral_bind(struct udevice *dev)
+{
+       enum usb_dr_mode dr_mode = usb_get_dr_mode(dev_ofnode(dev));
+
+       if (dr_mode != USB_DR_MODE_PERIPHERAL)
+               return -ENODEV;
+
+       return 0;
+}
+
 static int ti_musb_peripheral_of_to_plat(struct udevice *dev)
 {
        struct ti_musb_plat *plat = dev_get_plat(dev);
@@ -237,6 +264,11 @@ static int ti_musb_peripheral_of_to_plat(struct udevice 
*dev)
 
        return 0;
 }
+
+static const struct udevice_id ti_musb_peripheral_ids[] = {
+       { .compatible = "ti,musb-am33xx" },
+       { }
+};
 #endif
 
 static int ti_musb_peripheral_probe(struct udevice *dev)
@@ -283,6 +315,8 @@ U_BOOT_DRIVER(ti_musb_peripheral) = {
        .name   = "ti-musb-peripheral",
        .id     = UCLASS_USB_GADGET_GENERIC,
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+       .of_match = ti_musb_peripheral_ids,
+       .bind = ti_musb_peripheral_bind,
        .of_to_plat = ti_musb_peripheral_of_to_plat,
 #endif
        .ops    = &ti_musb_gadget_ops,

-- 
2.51.0

Reply via email to