[PATCH] Avoid delay when initializing USB peripherals by dwc2

Marek Vasut marex at denx.de
Wed Mar 17 14:30:44 CET 2021


On 3/17/21 2:24 PM, João Loureiro wrote:
> When `usb start` is called, 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, as the documentation explains (`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 a host initialization of the device,
> when it is explicitly set as peripheral. The checking is already done
> similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.
> 
> An example device tree entry:
> &usb0 {
>    compatible = "snps,dwc2";
>    status = "okay";
>    dr_mode = "peripheral";
> };
> 
> Signed-off-by: João Loureiro <joaofl at gmail.com>
> ---
> drivers/usb/host/dwc2.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
> 
> 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);
> + }

The patch is corrupted, please use git send-email if possible.


More information about the U-Boot mailing list