]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
usb: dwc3-generic: allow fallback of dr_mode property to "otg"
authorKaustabh Chakraborty <kauschluss@disroot.org>
Thu, 8 Jan 2026 12:33:44 +0000 (18:03 +0530)
committerMarek Vasut <marek.vasut+usb@mailbox.org>
Thu, 8 Jan 2026 14:13:19 +0000 (15:13 +0100)
Documentation [1] states that the default value of the dr_mode property
is "otg". It also isn't marked a mandatory node, so it may or may not be
set. So, accordingly if dr_mode is not mentioned in the devicetree node,
OTG mode must be assumed.

In this driver however, this case is not handled. If dr_mode is not
mentioned, USB_DR_MODE_UNKNOWN is set. The logic implemented raises an
error, instead of falling back to USB_DR_MODE_OTG. Correct this to
conform to the specification.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git/tree/Bindings/usb/usb-drd.yaml?h=v6.18-dts
Reviewed-by: Marek Vasut <marek.vasut@mailbox.org>
Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
drivers/usb/dwc3/dwc3-generic.c

index c09014aec60d1ea48afa3bd065d3f1f9672b8633..c15eda19e8fbcf615fac2702bde02587e785db1e 100644 (file)
@@ -10,6 +10,7 @@
 #include <dm.h>
 #include <reset.h>
 #include <asm/gpio.h>
+#include <dm/device_compat.h>
 #include <dm/lists.h>
 #include <linux/delay.h>
 #include <linux/usb/gadget.h>
@@ -173,8 +174,8 @@ static int dwc3_generic_of_to_plat(struct udevice *dev)
                node = dev_ofnode(dev->parent);
                plat->dr_mode = usb_get_dr_mode(node);
                if (plat->dr_mode == USB_DR_MODE_UNKNOWN) {
-                       pr_err("Invalid usb mode setup\n");
-                       return -ENODEV;
+                       dev_info(dev, "No USB mode specified. Using 'otg'\n");
+                       plat->dr_mode = USB_DR_MODE_OTG;
                }
        }
 
@@ -516,6 +517,10 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
        if (!dr_mode)
                dr_mode = usb_get_dr_mode(node);
 
+       /* usb mode must fallback to peripheral if not known */
+       if (dr_mode == USB_DR_MODE_UNKNOWN)
+               dr_mode = USB_DR_MODE_OTG;
+
        if (CONFIG_IS_ENABLED(DM_USB_GADGET) &&
            (dr_mode == USB_DR_MODE_PERIPHERAL || dr_mode == USB_DR_MODE_OTG)) {
                debug("%s: dr_mode: OTG or Peripheral\n", __func__);