linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: Prioritize extcon over USB role switching API
@ 2022-01-31 19:21 Andrey Smirnov
  2022-02-03  2:54 ` Thinh Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Smirnov @ 2022-01-31 19:21 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Andrey Smirnov, Thinh Nguyen, linux-usb, linux-kernel

It is necessary that:

   ROLE_SWITCH && device_property_read_bool(dwc->dev, "usb-role-switch")

is true in order for dwc3_get_dr_mode() to _not_ force us from OTG to
PERIPHERAL mode here:

   if (mode == USB_DR_MODE_OTG &&
       (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
        !device_property_read_bool(dwc->dev, "usb-role-switch")) &&
	!DWC3_VER_IS_PRIOR(DWC3, 330A))
	mode = USB_DR_MODE_PERIPHERAL;

and dwc3_drd_init() to be called later in dwc3_core_init_mode(). So,
to avoid always ignoring extcon device returned by dwc3_get_extcon()
change dwc3_drd_init() to check and use it first, before checking if
dwc3_setup_role_switch() should be called.

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Thinh Nguyen <thinhn@synopsys.com>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---

Hopefully I didn't miss something important making this patch
unnecessary. Don't know if this is a good solution or not, part of me
thinks than maybe changing the aforementioned code in
dwc3_get_dr_mode() to account for extcon wopuld be
simpler/better. Happy to rework this.

 drivers/usb/dwc3/drd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index e2b68bb770d1..835bd0be87d5 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -579,12 +579,7 @@ int dwc3_drd_init(struct dwc3 *dwc)
 	if (IS_ERR(dwc->edev))
 		return PTR_ERR(dwc->edev);

-	if (ROLE_SWITCH &&
-	    device_property_read_bool(dwc->dev, "usb-role-switch")) {
-		ret = dwc3_setup_role_switch(dwc);
-		if (ret < 0)
-			return ret;
-	} else if (dwc->edev) {
+	if (dwc->edev) {
 		dwc->edev_nb.notifier_call = dwc3_drd_notifier;
 		ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
 					       &dwc->edev_nb);
@@ -594,6 +589,11 @@ int dwc3_drd_init(struct dwc3 *dwc)
 		}

 		dwc3_drd_update(dwc);
+	} else if (ROLE_SWITCH &&
+		   device_property_read_bool(dwc->dev, "usb-role-switch")) {
+		ret = dwc3_setup_role_switch(dwc);
+		if (ret < 0)
+			return ret;
 	} else {
 		dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG);
 		dwc->current_dr_role = DWC3_GCTL_PRTCAP_OTG;
--
2.25.1

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

end of thread, other threads:[~2022-02-03  4:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 19:21 [PATCH] usb: dwc3: Prioritize extcon over USB role switching API Andrey Smirnov
2022-02-03  2:54 ` Thinh Nguyen
2022-02-03  3:36   ` Andrey Smirnov
2022-02-03  4:13     ` Thinh Nguyen

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).