diff mbox series

Avoid delay when inializing USB peripheral by dwc2

Message ID 20210317151937.703119-1-joaofl@gmail.com
State Superseded
Delegated to: Marek Vasut
Headers show
Series Avoid delay when inializing USB peripheral by dwc2 | expand

Commit Message

João Loureiro March 17, 2021, 3:19 p.m. UTC
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 am 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 and correctly done similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

Signed-off-by: João Loureiro <joaofl@gmail.com>
---
 drivers/usb/host/dwc2.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Marek Vasut March 17, 2021, 3:33 p.m. UTC | #1
On 3/17/21 4:19 PM, João Loureiro wrote:
> 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 am 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 and correctly done similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

Can you limit the commit message to 72 chars per line ?
fmt -w 72 can help you here.

> @@ -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",\

This backslash at the end is not needed.

> +			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 |
> 

Thanks
diff mbox series

Patch

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..7990060f3c 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -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 |