[PATCH v2 4/5] usb: dwc2: update the dr_mode on set_mode callback

Michael Grzeschik m.grzeschik at pengutronix.de
Thu Dec 17 06:07:30 EST 2020


The dwc2 dr_mode can be configured with otg.mode in otg mode. Currently
the mode will not be set with the users decision. This patch fixes this
by overwriting the mode with the one set by set_mode callback.

Signed-off-by: Michael Grzeschik <m.grzeschik at pengutronix.de>
---
 drivers/usb/dwc2/dwc2.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 6f5127fc3b..65b92b542e 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -20,6 +20,9 @@ static int dwc2_set_mode(void *ctx, enum usb_dr_mode mode)
 {
 	struct dwc2 *dwc2 = ctx;
 	int ret = -ENODEV;
+	int oldmode = dwc2->dr_mode;
+
+	dwc2->dr_mode = mode;
 
 	if (mode == USB_DR_MODE_HOST || mode == USB_DR_MODE_OTG) {
 		if (IS_ENABLED(CONFIG_USB_DWC2_HOST))
@@ -34,6 +37,9 @@ static int dwc2_set_mode(void *ctx, enum usb_dr_mode mode)
 			dwc2_err(dwc2, "Peripheral support not available\n");
 	}
 
+	if (ret)
+		dwc2->dr_mode = oldmode;
+
 	return ret;
 }
 
-- 
2.29.2




More information about the barebox mailing list