Skip to contentSkip to conversation

Avoid delay when initializing USB peripheral by dwc2

PATCH New João Loureiro 2 participants 2 messages Mar 17, 2021 – Mar 19, 2021 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid delay when initializing USB peripheral by dwc2

When usb start is called on the terminal, the dwc2 driver will try to start every USB device as host first, even if it is explicitly configured as peripheral in the device tree (dr_mode = "peripheral").

So to avoid an unwanted 15 seconds delay when initializing the usb (one second per channel = 1s x 15), this patch adds a check to the initialization, and will skip host initialization of the device is explicitly set as peripheral. The checking is already done similarly in the drivers/usb/gadget/dwc2_udc_otg.c driver.

---
 drivers/usb/host/dwc2.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/host/dwc2.c +8 -1
index ec643e9f45..43cc2e0433 100644
@@ -21,6 +21,7 @@
 #include <asm/io.h>
 #include <dm/device_compat.h>
 #include <linux/delay.h>
+#include <linux/usb/otg.h>
 #include <power/regulator.h>
 #include <reset.h>
 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 #endif
 
 	dwc_otg_core_init(dev);
-	dwc_otg_core_host_init(dev, regs);
+
+	if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+		dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping host_init.\n",
+			dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+	} else {
+		dwc_otg_core_host_init(dev, regs);
+	}
 
 	clrsetbits_le32(&regs->hprt0, DWC2_HPRT0_PRTENA |
 			DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 Avoid delay when initializing USB peripheral by dwc2

Quoted 9 lines · Jo?o Loureiro

When usb start is called on the terminal, the dwc2 driver will try to start every USB device as host first, even if it is explicitly configured as peripheral in the device tree (dr_mode = "peripheral").

So to avoid an unwanted 15 seconds delay when initializing the usb (one second per channel = 1s x 15), this patch adds a check to the initialization, and will skip host initialization of the device is explicitly set as peripheral. The checking is already done similarly in the drivers/usb/gadget/dwc2_udc_otg.c driver.

[...]

Quoted 3 lines
---
  drivers/usb/host/dwc2.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)

A few more things, next time you send a subsequent version of the patch, use PATCH vX and document the patch changelog below the diffstat (i.e.
V2: changed foo because bar).

Also, add tags to subject, for this patch it would be "usb: dwc2:". I can fill them in when applying, but in case there is a V3 of this patch, update those in your tree too.

Finally, use ./scripts/get_maintainer to find out who to CC. I'm adding a few more DWC2 users.

Quoted 28 lines
drivers/usb/host/dwc2.c +8 -1
index ec643e9f45..43cc2e0433 100644
@@ -21,6 +21,7 @@
  #include <asm/io.h>
  #include <dm/device_compat.h>
  #include <linux/delay.h>
+#include <linux/usb/otg.h>
  #include <power/regulator.h>
  #include <reset.h>
 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
  #endif
 
  	dwc_otg_core_init(dev);
-	dwc_otg_core_host_init(dev, regs);
+
+	if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+		dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping host_init.\n",
+			dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+	} else {
+		dwc_otg_core_host_init(dev, regs);
+	}
 
  	clrsetbits_le32(&regs->hprt0, DWC2_HPRT0_PRTENA |
  			DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |

[...]