Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] usb: dwc3: skip extcon lookup for fixed-role mode
@ 2026-12-01 17:17 Radhey Shyam Pandey
  2026-12-01 17:22 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Radhey Shyam Pandey @ 2026-12-01 17:17 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh; +Cc: linux-usb, git, Radhey Shyam Pandey, stable

As a last resort dwc3_get_extcon() walks the OF graph from the "phys"
phandle and asks extcon for a device bound to the remote node.  A PHY
"port" node no longer implies an extcon provider though: it may link to
a Type-C controller for orientation switching.  There
extcon_find_edev_by_node() returns -EPROBE_DEFER, the same value it uses
for "not registered yet", so the probe defers forever.

An extcon is only consulted for role switching in OTG mode, so skip the
graph walk for a fixed role.  dwc->dr_mode is still the raw device tree
value here, as dwc3_get_dr_mode() runs later, so also account for the
roles GHWPARAMS0 and the Kconfig selection force.  Factor those out of
dwc3_get_dr_mode() into dwc3_get_forced_role() so both callers share
them.

Fixes: d182c2e1bc92 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present")
Cc: stable@vger.kernel.org
Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
---
Changes for v2:
- Add CC stable kernel
- Trim commit and code comment description
- Create common wrapper for dwc3_get_dr_mode and reuse it to determine
  fixed role.
---
 drivers/usb/dwc3/core.c | 76 ++++++++++++++++++++++++++++-------------
 1 file changed, 53 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index f4aa6a01e500..9146d06e7ee1 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -46,6 +46,31 @@
 
 #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
 
+/**
+ * dwc3_get_forced_role - Role forced by the hardware and Kconfig
+ * @dwc: pointer to our context structure
+ *
+ * Return: the forced role, or USB_DR_MODE_OTG if the role is not forced.
+ */
+static enum usb_dr_mode dwc3_get_forced_role(struct dwc3 *dwc)
+{
+	unsigned int hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
+
+	switch (hw_mode) {
+	case DWC3_GHWPARAMS0_MODE_GADGET:
+		return USB_DR_MODE_PERIPHERAL;
+	case DWC3_GHWPARAMS0_MODE_HOST:
+		return USB_DR_MODE_HOST;
+	default:
+		if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
+			return USB_DR_MODE_HOST;
+		else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
+			return USB_DR_MODE_PERIPHERAL;
+
+		return USB_DR_MODE_OTG;
+	}
+}
+
 /**
  * dwc3_get_dr_mode - Validates and sets dr_mode
  * @dwc: pointer to our context structure
@@ -59,31 +84,23 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
 		dwc->dr_mode = USB_DR_MODE_OTG;
 
-	mode = dwc->dr_mode;
 	hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
 
-	switch (hw_mode) {
-	case DWC3_GHWPARAMS0_MODE_GADGET:
-		if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
-			dev_err(dev,
-				"Controller does not support host mode.\n");
-			return -EINVAL;
-		}
-		mode = USB_DR_MODE_PERIPHERAL;
-		break;
-	case DWC3_GHWPARAMS0_MODE_HOST:
-		if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
-			dev_err(dev,
-				"Controller does not support device mode.\n");
-			return -EINVAL;
-		}
-		mode = USB_DR_MODE_HOST;
-		break;
-	default:
-		if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
-			mode = USB_DR_MODE_HOST;
-		else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
-			mode = USB_DR_MODE_PERIPHERAL;
+	if (hw_mode == DWC3_GHWPARAMS0_MODE_GADGET &&
+	    IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
+		dev_err(dev, "Controller does not support host mode.\n");
+		return -EINVAL;
+	}
+
+	if (hw_mode == DWC3_GHWPARAMS0_MODE_HOST &&
+	    IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
+		dev_err(dev, "Controller does not support device mode.\n");
+		return -EINVAL;
+	}
+
+	mode = dwc3_get_forced_role(dwc);
+	if (mode == USB_DR_MODE_OTG) {
+		mode = dwc->dr_mode;
 
 		/*
 		 * DWC_usb31 and DWC_usb3 v3.30a and higher do not support OTG
@@ -2003,6 +2020,15 @@ static void dwc3_check_params(struct dwc3 *dwc)
 	}
 }
 
+static bool dwc3_role_is_fixed(struct dwc3 *dwc)
+{
+	if (dwc->dr_mode == USB_DR_MODE_HOST ||
+	    dwc->dr_mode == USB_DR_MODE_PERIPHERAL)
+		return true;
+
+	return dwc3_get_forced_role(dwc) != USB_DR_MODE_OTG;
+}
+
 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 {
 	struct device *dev = dwc->dev;
@@ -2032,6 +2058,10 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 	    device_property_read_bool(dev, "usb-role-switch"))
 		return NULL;
 
+	/* An extcon is only used for role switching in OTG mode */
+	if (dwc3_role_is_fixed(dwc))
+		return NULL;
+
 	/*
 	 * Try to get an extcon device from the USB PHY controller's "port"
 	 * node. Check if it has the "port" node first, to avoid printing the

base-commit: 3a8ea89f018971d8b595ebf61022871d991a0299
-- 
2.43.0


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

* Re: [PATCH v2] usb: dwc3: skip extcon lookup for fixed-role mode
  2026-12-01 17:17 [PATCH v2] usb: dwc3: skip extcon lookup for fixed-role mode Radhey Shyam Pandey
@ 2026-12-01 17:22 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 17:22 UTC (permalink / raw)
  To: Radhey Shyam Pandey; +Cc: linux-usb

> As a last resort dwc3_get_extcon() walks the OF graph from the "phys"
> phandle and asks extcon for a device bound to the remote node.  A PHY
> "port" node no longer implies an extcon provider though: it may link to
> a Type-C controller for orientation switching.  There
> extcon_find_edev_by_node() returns -EPROBE_DEFER, the same value it uses
> for "not registered yet", so the probe defers forever.
> 
> An extcon is only consulted for role switching in OTG mode, so skip the
> graph walk for a fixed role.  dwc->dr_mode is still the raw device tree
> value here, as dwc3_get_dr_mode() runs later, so also account for the
> roles GHWPARAMS0 and the Kconfig selection force.  Factor those out of
> dwc3_get_dr_mode() into dwc3_get_forced_role() so both callers share
> them.
> 
> Fixes: d182c2e1bc92 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present")
> Cc: stable@vger.kernel.org
> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201171731.730281-1-radhey.shyam.pandey@amd.com?part=1

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

end of thread, other threads:[~2026-12-01 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:17 [PATCH v2] usb: dwc3: skip extcon lookup for fixed-role mode Radhey Shyam Pandey
2026-12-01 17:22 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox