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

* Re: [PATCH] usb: dwc3: allow dual role switch by defautl for new IP w/o OTG
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Felipe Balbi @ 2020-05-14 10:50 UTC (permalink / raw)
  To: Li Jun; +Cc: gregkh, linux-usb, peter.chen, linux-imx

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]


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.

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* RE: [PATCH] usb: dwc3: allow dual role switch by defautl for new IP w/o OTG
  2020-05-14 10:50 ` Felipe Balbi
@ 2020-05-14 11:57   ` Jun Li
  0 siblings, 0 replies; 3+ messages in thread
From: Jun Li @ 2020-05-14 11:57 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: gregkh, linux-usb, Peter Chen, dl-linux-imx

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

^ permalink raw reply	[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).