diff mbox series

usb: dwc3: allow dual role switch by defautl for new IP w/o OTG

Message ID 1589272379-30536-1-git-send-email-jun.li@nxp.com (mailing list archive)
State New, archived
Headers show
Series usb: dwc3: allow dual role switch by defautl for new IP w/o OTG | expand

Commit Message

Jun Li May 12, 2020, 8:32 a.m. UTC
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(-)

Comments

Felipe Balbi May 14, 2020, 10:50 a.m. UTC | #1
Hi,

Li Jun <jun.li@nxp.com> writes:
> 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.

then you need to compile your kernel with support for Dual Role. This
patch is the wrong way to go.
Jun Li May 14, 2020, 11:57 a.m. UTC | #2
Hi,
> -----Original Message-----
> From: Felipe Balbi <balbif@gmail.com> On Behalf Of Felipe Balbi
> Sent: 2020年5月14日 18:51
> To: Jun Li <jun.li@nxp.com>
> Cc: gregkh@linuxfoundation.org; linux-usb@vger.kernel.org; Peter Chen
> <peter.chen@nxp.com>; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH] usb: dwc3: allow dual role switch by defautl for new IP w/o
> OTG
> 
> 
> Hi,
> 
> Li Jun <jun.li@nxp.com> writes:
> > 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.
> 
> then you need to compile your kernel with support for Dual Role. This patch is the
> wrong way to go.

I am not sure I catch your point.
For dwc3, the change intention is to make the port to be still dual role(
don't force dwc->dr_mode to be USB_DR_MODE_PERIPHERAL, but still keep it
to be USB_DR_MODE_OTG) in this case. so need compile the kernel with
CONFIG_USB_DWC3_DUAL_ROLE enabled is reasonable.

Li Jun 
> 
> --
> balbi
diff mbox series

Patch

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;