From 631619a42f9578c0b4232a59f3f3f1b7adfc3090 Mon Sep 17 00:00:00 2001 From: William Wu Date: Thu, 28 Jan 2021 10:11:51 +0800 Subject: [PATCH] usb: dwc3-generic: support host mode if dr_mode is otg The Rockchip DWC3 controller only support DRD mode (Dual Role Device), but not support OTG mode. So if the dr_mode in DTS is configured to OTG, then we force it to Host mode. This patch does not affect the device function of OTG, such as rockusb. Signed-off-by: William Wu Change-Id: I806623aa9b0bb8b595417755db7d9c6b6c4f38f1 --- drivers/usb/dwc3/dwc3-generic.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index c5106d98fc..ea5aeaa9b3 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -120,6 +120,10 @@ static int dwc3_generic_ofdata_to_platdata(struct udevice *dev) if (plat->dr_mode == USB_DR_MODE_UNKNOWN) { pr_err("Invalid usb mode setup\n"); return -ENODEV; + } else if (plat->dr_mode != USB_DR_MODE_HOST && + !strcmp(dev->driver->name, "dwc3-generic-host")) { + pr_info("Set dr_mode to HOST\n"); + plat->dr_mode = USB_DR_MODE_HOST; } return 0; @@ -310,8 +314,13 @@ static int dwc3_glue_bind(struct udevice *parent) dr_mode = usb_get_dr_mode(node); switch (dr_mode) { - case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: +#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_USB_XHCI_HCD) + debug("%s: dr_mode: force to HOST\n", __func__); + driver = "dwc3-generic-host"; + break; +#endif + case USB_DR_MODE_PERIPHERAL: #if CONFIG_IS_ENABLED(DM_USB_GADGET) debug("%s: dr_mode: OTG or Peripheral\n", __func__); driver = "dwc3-generic-peripheral";