linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: allow dual role switch by defautl for new IP w/o OTG
@ 2020-05-12  8:32 Li Jun
  2020-05-14 10:50 ` Felipe Balbi
  0 siblings, 1 reply; 3+ messages in thread
From: Li Jun @ 2020-05-12  8:32 UTC (permalink / raw)
  To: balbi; +Cc: gregkh, linux-usb, peter.chen, linux-imx

For new IP version DWC3_REVISION_330A or above, current code only allows
dual role if role-switch is used, those IP w/o OTG only removes OTG
block but dual role should be capable so don't limit dual role, user
may use debugfs or any other way to switch role.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/usb/dwc3/core.c | 11 -----------
 drivers/usb/dwc3/drd.c  | 10 +++++++++-
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 75ee602..e4e473f 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -78,17 +78,6 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 			mode = USB_DR_MODE_HOST;
 		else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
 			mode = USB_DR_MODE_PERIPHERAL;
-
-		/*
-		 * DWC_usb31 and DWC_usb3 v3.30a and higher do not support OTG
-		 * mode. If the controller supports DRD but the dr_mode is not
-		 * specified or set to OTG, then set the mode to peripheral.
-		 */
-		if (mode == USB_DR_MODE_OTG &&
-		    (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
-		     !device_property_read_bool(dwc->dev, "usb-role-switch")) &&
-		    dwc->revision >= DWC3_REVISION_330A)
-			mode = USB_DR_MODE_PERIPHERAL;
 	}
 
 	if (mode != dwc->dr_mode) {
diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index a24c6c0..4281e96 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -587,7 +587,7 @@ int dwc3_drd_init(struct dwc3 *dwc)
 		}
 
 		dwc3_drd_update(dwc);
-	} else {
+	} else if (!dwc3_is_usb31(dwc) && dwc->revision < DWC3_REVISION_330A) {
 		dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG);
 		dwc->current_dr_role = DWC3_GCTL_PRTCAP_OTG;
 
@@ -615,6 +615,14 @@ int dwc3_drd_init(struct dwc3 *dwc)
 
 		dwc3_otg_init(dwc);
 		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
+	} else {
+		/*
+		 * DWC_usb3 dwc_usb31, v3.30a and higher do not support
+		 * OTG mode. If the controller supports DRD but the
+		 * dr_mode is not specified or set to OTG, then set the
+		 * default role to be peripheral.
+		 */
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
 	}
 
 	return 0;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-14 11:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-12  8:32 [PATCH] usb: dwc3: allow dual role switch by defautl for new IP w/o OTG Li Jun
2020-05-14 10:50 ` Felipe Balbi
2020-05-14 11:57   ` Jun Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).