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

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 after the lookup, so also
derive the fixed cases it would force from GHWPARAMS0 and from the
Kconfig role selection.  Its remaining OTG to peripheral downgrade
cannot be covered because it consumes dwc->edev, but it is only
reached once the lookup has already returned NULL.

The check stays below the explicit "extcon" and "linux,extcon-name"
lookups so those keep working for a fixed role.

Fixes: d182c2e1bc92 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present")
Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
---

Trace sequence before this change:
dwc3-xilinx edec0000.usb: extcon-dbg: enter, raw dr_mode=1 node=/axi/usb@edec0000
dwc3-xilinx edec0000.usb: extcon-dbg: phys[0]=/axi/phy@edeb8000 graph_present=1
dwc3-xilinx edec0000.usb: extcon-dbg: graph remote node=/axi/i2c@f1000000/usb-pd@22/connector
dwc3-xilinx edec0000.usb: extcon-dbg: HIT - no extcon bound to /axi/i2c@f1000000/usb-pd@22/connector,
returning -EPROBE_DEFER
---
 drivers/usb/dwc3/core.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 372737f4750b..a70cfa9e1df1 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -2003,6 +2003,26 @@ static void dwc3_check_params(struct dwc3 *dwc)
 	}
 }
 
+/*
+ * dwc3_get_dr_mode() can force a fixed role from GHWPARAMS0 or from the
+ * Kconfig role selection, but it runs after the extcon lookup and consumes
+ * dwc->edev, so replicate the parts of that decision which do not.
+ */
+static bool dwc3_role_is_fixed(struct dwc3 *dwc)
+{
+	unsigned int hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
+
+	if (dwc->dr_mode == USB_DR_MODE_HOST ||
+	    dwc->dr_mode == USB_DR_MODE_PERIPHERAL)
+		return true;
+
+	if (hw_mode == DWC3_GHWPARAMS0_MODE_HOST ||
+	    hw_mode == DWC3_GHWPARAMS0_MODE_GADGET)
+		return true;
+
+	return !IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE);
+}
+
 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 {
 	struct device *dev = dwc->dev;
@@ -2032,6 +2052,14 @@ 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, and the
+	 * graph walk below cannot tell "no extcon" from "not registered
+	 * yet", so for a fixed role it would defer the probe forever.
+	 */
+	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: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.44.4


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

end of thread, other threads:[~2026-11-16 13:06 UTC | newest]

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

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