Skip to contentSkip to conversation

usb: dwc3: qcom: Keep USB 2.0 working in DisplayPort-only modes

PATCH Superseded Joonhoe Kim 5 participants 16 messages Nov 3 – Nov 19

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover usb: dwc3: qcom: Keep USB 2.0 working in DisplayPort-only modes

With a USB-C monitor in DisplayPort pin assignment C or E, the QMP USB3-DP combo PHY gives all four lanes to DisplayPort and keeps its USB PCS powered down. The USB 2.0 pair still works. Such monitors often have a USB 2.0 hub. But the dwc3 controller still depends on the USB3 PIPE clock. On Kaanapali the next xHCI reset in this state times out ("Host halt failed, -110"). USB stays lost until the cable is replugged. Commit f546912bcac6 ("phy: qcom: qmp-combo: Move pipe_clk on/off to common") keeps the pipe clock branch enabled. That is not enough here.

This series lets the controller be a Type-C mode switch next to the PHY and moves it to the UTMI clock, the way "qcom,select-utmi-as-pipe-clk" does statically, before the PHY switches to DP-only mode.

On Kaanapali the PHY becomes a mode switch with Balaji Kalkonda's DisplayPort series [1]; patch 3 is the controller side for the same SoC. Other SoCs whose PHY is already a mode switch (e.g. SM8650, SM8750) may need the same property on their controller node (not tested).

Related fixes sent separately: "phy: qcom: qmp-combo: Leave the USB PCS alone in DP-only mode" (suspend in DP-only mode) [2] and "usb: typec:
mux: fsa4480: Keep the USB 2.0 switch on in DP-only modes" (boards with an FSA4480 on the USB 2.0 pair) [3].

Patch 2 conflicts with Vladyslav Tymoshchuk's "usb: dwc3: qcom: Defer VBUS override update during system suspend" [4] in dwc3_qcom_pm_suspend() and dwc3_qcom_pm_resume(). Both add a lock there. Like [4], the mux callback defers the QSCRATCH write while the glue is suspended for system sleep. On top of [4] the two locks can become one.

Patches 1-2 are for the USB tree. Patch 3 must not be applied before patch 2: with "mode-switch" on the controller and no mux registered by dwc3-qcom, pmic_glink_altmode defers its probe indefinitely.

Tested on a Lenovo Y700 Gen 5 (TB323FU, Kaanapali) with the series backported to v7.3, plus [2] and [3]. A USB-C monitor ran over 4-lane HBR3. Its USB 2.0 hub worked after 10 replugs and after a plug-in during s2idle. In the s2idle case the mux state came after resume, so the deferred clock switch was not exercised. With the monitor unplugged, a USB 3 stick enumerated at SuperSpeed. Quick replugs (under a second) worked 9 times out of 10. The other time no PD contract was made, so no alternate mode was entered.

Changes in v2:
- Patch 1: use the common usb-switch schema
- Patch 2: switch back to the PIPE clock in the mux callback, when a USB state follows the safe state. v1 waited for the next role change, which can come before the mux state (Sashiko)
- Patch 2: keep the UTMI clock on a change of pin assignment while DisplayPort is active, as the PHY keeps its mode then
- Patch 2: while the glue is suspended for system sleep, only record the mux state and select the clock on resume
- Patch 2: depend on TYPEC || TYPEC=n. Skip the mux without CONFIG_TYPEC. The arm64 defconfig has USB_DWC3_QCOM=y and TYPEC=m, which failed to link (Sashiko). It now builds the glue as a module
- Patch 2: no change to the role notifier
- Patch 3: note the dependency on [1] for the PHY's "mode-switch"
- Patch 3: add Reviewed-by from Abel
- Link to v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

Joonhoe Kim (3):
dt-bindings: usb: qcom,snps-dwc3: Add mode-switch
usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only
modes
arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode
switch

 .../bindings/usb/qcom,snps-dwc3.yaml          |   3 +
 arch/arm64/boot/dts/qcom/kaanapali.dtsi       |   1 +
 drivers/usb/dwc3/Kconfig                      |   1 +
 drivers/usb/dwc3/dwc3-qcom.c                  | 103 +++++++++++++++---
 4 files changed, 95 insertions(+), 13 deletions(-)

base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c

Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 dt-bindings: usb: qcom,snps-dwc3: Add mode-switch

The QMP USB3-DP combo PHY stops the USB3 PIPE clock when a Type-C DisplayPort pin assignment gives it all four lanes for DisplayPort, while the controller can keep running its USB 2.0 port. The controller has to move to the UTMI clock before that happens, so it needs the Type-C mux state as well. fwnode_typec_mux_get() only matches graph nodes that have the "mode-switch" property, so allow it on the controller node.

---
v2:
- Use the common usb-switch schema instead of a local definition

 Documentation/devicetree/bindings/usb/qcom,snps-dwc3.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/usb/qcom,snps-dwc3.yaml +3 -0
index b77c02c64d45..14fc7e4ebc80 100644
@@ -158,6 +158,8 @@ properties:
       HS/FS/LS modes are supported.
     type: boolean
 
+  mode-switch: true
+
   wakeup-source: true
 
 required:
@@ -170,6 +172,7 @@ required:
 
 allOf:
   - $ref: snps,dwc3-common.yaml#
+  - $ref: /schemas/usb/usb-switch.yaml#
   - if:
       properties:
         compatible:
Signature · 1 line
2.43.0
#5 lore raw

PATCH v2 2/3 usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only modes

In reply to Joonhoe Kim

With DisplayPort pin assignment C or E the QMP USB3-DP combo PHY gives all four lanes to DisplayPort and powers its USB PCS down. The controller can still run USB 2.0, e.g. for the hub of a USB-C monitor. Keeping the pipe clock branch enabled, as commit f546912bcac6 ("phy:
qcom: qmp-combo: Move pipe_clk on/off to common") does, is not enough on Kaanapali. The next xHCI reset in this mode times out ("Host halt failed, -110"), and USB stops working until the cable is replugged.

Register the glue as a Type-C mode switch when the node has the "mode-switch" property. Select the UTMI clock as PIPE clock in DP-only modes, as "qcom,select-utmi-as-pipe-clk" does statically. typec_mux_set() calls the switches in the order of the connector's ports. Port 0 (HS, the controller) comes before port 1 (SS, the PHY). So the controller switches before the PHY powers its USB side down.

Go back to the PIPE clock when a USB state follows the safe state. A change of pin assignment while DisplayPort is active keeps the UTMI clock, as the PHY keeps DP-only mode then. The PHY also delays its switch while DisplayPort is still powered, which the controller does not see. After a very quick replug the controller could thus use the PIPE clock while the PHY is still in DP-only mode. This has not been seen on hardware.

The mux can be called while the glue is suspended for system sleep, e.g. from the UCSI connector change work. Then only record the state and select the clock on resume, before the core resumes.

The mux needs the Type-C class, so depend on TYPEC || TYPEC=n as PHY_QCOM_QMP_COMBO does, and do not register the mux without it. With the arm64 defconfig (TYPEC=m) this builds the glue, including dwc3-qcom-legacy, as a module.

---
v2:
- Switch back to the PIPE clock from the mux callback, not on a role change (Sashiko)
- Keep dp_only while DisplayPort is active, as the PHY keeps its mode
- Defer the clock switch to resume while suspended for system sleep
- Depend on TYPEC || TYPEC=n, skip the mux without CONFIG_TYPEC (Sashiko)

 drivers/usb/dwc3/Kconfig     |   1 +
 drivers/usb/dwc3/dwc3-qcom.c | 103 ++++++++++++++++++++++++++++++-----
 2 files changed, 91 insertions(+), 13 deletions(-)
drivers/usb/dwc3/Kconfig +1 -0
index 18169727a413..282f366de9af 100644
@@ -132,6 +132,7 @@ config USB_DWC3_QCOM
 	depends on ARCH_QCOM || COMPILE_TEST
 	depends on EXTCON || !EXTCON
 	depends on OF
+	depends on TYPEC || TYPEC=n
 	default USB_DWC3
 	help
 	  Some Qualcomm SoCs use DesignWare Core IP for USB2/3
drivers/usb/dwc3/dwc3-qcom.c +90 -13

181 lines not on this page · raw message

Signature · 1 line
2.43.0
#8 lore raw

PATCH v2 3/3 arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode switch

In reply to Joonhoe Kim

When the USB3-DP combo PHY is a mode switch, DisplayPort pin assignments C and E put it in DP-only mode, where it stops the USB3 PIPE clock. Make the USB controller a mode switch as well, so that it moves to the UTMI clock first and keeps its USB 2.0 port working.

---
The "mode-switch" property of usb_dp_qmpphy comes with patch 3 of Balaji Kalkonda's Kaanapali DisplayPort series:
https://lore.kernel.org/all/[email protected]/

 arch/arm64/boot/dts/qcom/kaanapali.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/qcom/kaanapali.dtsi +1 -0
index e48a179d0722..a06d5d867488 100644
@@ -3941,6 +3941,7 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
 			tx-fifo-resize;
 			dma-coherent;
 
+			mode-switch;
 			usb-role-switch;
 			wakeup-source;
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/3] dt-bindings: usb: qcom,snps-dwc3: Add mode-switch

In reply to Joonhoe Kim
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

The QMP USB3-DP combo PHY stops the USB3 PIPE clock when a Type-C DisplayPort pin assignment gives it all four lanes for DisplayPort, while the controller can keep running its USB 2.0 port. The controller has to move to the UTMI clock before that happens, so it needs the Type-C mux state as well. fwnode_typec_mux_get() only matches graph nodes that have the "mode-switch" property, so allow it on the controller node.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#6 lore raw

Re: [PATCH v2 2/3] usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only modes

In reply to Joonhoe Kim
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] usb: dwc3: qcom: broken Type-C state handling in dwc3_qcom_mux_set() - [High] usb: dwc3: qcom: PM…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] usb: dwc3: qcom: broken Type-C state handling in dwc3_qcom_mux_set()
- [High] usb: dwc3: qcom: PM races and lost clock switches with dwc3_qcom_mux_set() --

commit 8f6090d15a3eafa1d84e143a83d04937bda97612
Author: Joonhoe Kim <[email protected]>

usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only modes

This commit registers the Qualcomm DWC3 glue driver as a Type-C mode switch when the mode-switch property is present. It switches the controller to use the UTMI clock in place of the PIPE clock during 4-lane DisplayPort-only modes (pin assignments C and E) so that USB 2.0 continues to work when the QMP combo PHY powers down its USB PCS.

Quoted 4 lines
drivers/usb/dwc3/dwc3-qcom.c +0 -0
index ac68b4218b56b..71b0402f0ae66 100644

[ ... ]

Quoted 37 lines
drivers/usb/dwc3/dwc3-qcom.c +18 -4
@@ -419,21 +429,72 @@ static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static void dwc3_qcom_select_utmi_clk(struct dwc3_qcom *qcom)
+static void dwc3_qcom_select_utmi_clk(struct dwc3_qcom *qcom, bool utmi)
 {
-	/* Configure dwc3 to use UTMI clock as PIPE clock not present */
 	dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
 			  PIPE_UTMI_CLK_DIS);
 
 	usleep_range(100, 1000);
 
-	dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
-			  PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW);
+	if (utmi)
+		dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
+				  PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW);
+	else
+		dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
+				  PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW);
 
 	usleep_range(100, 1000);
 
 	dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
 			  PIPE_UTMI_CLK_DIS);
+
+	qcom->utmi_pipe_clk = utmi;
+}
+
+static int dwc3_qcom_mux_set(struct typec_mux_dev *mux,
+			     struct typec_mux_state *state)
+{
+	struct dwc3_qcom *qcom = typec_mux_get_drvdata(mux);
+
+	guard(mutex)(&qcom->pipe_clk_lock);
+

drivers/usb/dwc3/dwc3-qcom.c static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data) · line 470

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +10 -0
+	if (state->alt && state->alt->svid == USB_TYPEC_DP_SID) {
+		if (!qcom->dp_active)
+			qcom->dp_only = state->mode == TYPEC_DP_STATE_C ||
+					state->mode == TYPEC_DP_STATE_E;
+		qcom->dp_active = true;
+	} else if (state->mode == TYPEC_STATE_SAFE) {
+		qcom->dp_active = false;
+	} else if (!qcom->dp_active) {
+		qcom->dp_only = false;
+	}

[Severity: High]
When the Type-C DisplayPort altmode driver transitions through the safe state or exits altmode, typec_altmode_set_mux() in drivers/usb/typec/bus.c populates state.alt with the DP altmode device (where state.alt->svid is USB_TYPEC_DP_SID):

drivers/usb/typec/bus.c:typec_altmode_set_mux()

	state.alt = &alt->adev;
	state.mode = conf;
	state.data = data;

	return typec_mux_set(alt->mux, &state);

Before configuring pin assignment C or E, typec_altmode_enter() and dp_altmode_configure_vdm() in drivers/usb/typec/altmodes/displayport.c first place the connector into TYPEC_STATE_SAFE via typec_altmode_notify(). Because dwc3_qcom_mux_set() checks state->alt && state->alt->svid == USB_TYPEC_DP_SID before checking state->mode == TYPEC_STATE_SAFE, that initial TYPEC_STATE_SAFE notification enters the first branch, sets qcom->dp_only = false, and sets qcom->dp_active = true. When dp_altmode_configured() then notifies TYPEC_DP_STATE_C or TYPEC_DP_STATE_E, qcom->dp_active is already true, so qcom->dp_only is not updated and dwc3_qcom_select_utmi_clk() is never called.

Similarly, on disconnect or mode exit, typec_altmode_exit(), typec_remove(), and dp_altmode_notify() pass state->alt->svid == USB_TYPEC_DP_SID with TYPEC_STATE_SAFE or TYPEC_STATE_USB, which also hit the first branch and leave qcom->dp_active and qcom->dp_only stuck.

In addition, qmp_combo_typec_mux_set() in drivers/phy/qualcomm/phy-qcom-qmp-combo.c only delays a PHY mode switch when qmp->dp_powered_on is true:

	if (qmp->qmpphy_mode != QMPPHY_MODE_USB3_ONLY && qmp->dp_powered_on) {
		dev_dbg(qmp->dev, "typec_mux_set: DP PHY is still in use, delaying switch\n");
		return 0;
	}

If a port driver such as pmic_glink_altmode enters TYPEC_DP_STATE_D while qmp->dp_powered_on is false and then reconfigures to TYPEC_DP_STATE_C or TYPEC_DP_STATE_E without an intervening TYPEC_STATE_SAFE, the PHY switches to QMPPHY_MODE_DP_ONLY while dwc3_qcom_mux_set() skips updating qcom->dp_only because qcom->dp_active is already true.

Should state->mode == TYPEC_STATE_SAFE and TYPEC_STATE_USB be checked before inspecting state->alt, and can gating qcom->dp_only on !qcom->dp_active miss valid transitions to DP-only mode?

Quoted 11 lines
drivers/usb/dwc3/dwc3-qcom.c +11 -0
+
+	if (qcom->ignore_pipe_clk || qcom->pm_suspended ||
+	    qcom->dp_only == qcom->utmi_pipe_clk ||
+	    pm_runtime_resume_and_get(qcom->dev))
+		return 0;
+
+	dwc3_qcom_select_utmi_clk(qcom, qcom->dp_only);
+	pm_runtime_put_autosuspend(qcom->dev);
+
+	return 0;
+}

[ ... ]

Quoted 21 lines
drivers/usb/dwc3/dwc3-qcom.c +6 -3
@@ -756,6 +825,8 @@ static int dwc3_qcom_pm_suspend(struct device *dev)
 	if (ret)
 		return ret;
 
+	guard(mutex)(&qcom->pipe_clk_lock);
+
 	ret = dwc3_qcom_suspend(qcom, wakeup);
 	if (ret)
 		return ret;
@@ -772,11 +843,17 @@ static int dwc3_qcom_pm_resume(struct device *dev)
 	bool wakeup = device_may_wakeup(dev);
 	int ret;
 
-	ret = dwc3_qcom_resume(qcom, wakeup);
-	if (ret)
-		return ret;
+	scoped_guard(mutex, &qcom->pipe_clk_lock) {
+		ret = dwc3_qcom_resume(qcom, wakeup);
+		if (ret)
+			return ret;
 

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_pm_resume(struct device *dev) · line 859

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +6 -1
-	qcom->pm_suspended = false;
+		if (!qcom->ignore_pipe_clk &&
+		    qcom->dp_only != qcom->utmi_pipe_clk)
+			dwc3_qcom_select_utmi_clk(qcom, qcom->dp_only);
+
+		qcom->pm_suspended = false;
+	}
 
 	ret = dwc3_pm_resume(&qcom->dwc);
 	if (ret)

[Severity: High]
How does the synchronization between dwc3_qcom_mux_set(), system sleep, and runtime PM handle the following cases?

1. In dwc3_qcom_pm_resume(), qcom->pm_suspended is cleared and qcom->pipe_clk_lock is released before dwc3_pm_resume(&qcom->dwc) runs:

drivers/usb/dwc3/core.c:dwc3_pm_resume()

	pm_runtime_disable(dev);
	ret = pm_runtime_set_active(dev);
	if (ret)
		goto out;

	ret = dwc3_resume_common(dwc, PMSG_RESUME);

If dwc3_qcom_mux_set() runs on a workqueue right after pipe_clk_lock is released:
- Before pm_runtime_disable(dev), if the device was runtime-suspended prior to system sleep, pm_runtime_resume_and_get(qcom->dev) can trigger dwc3_qcom_runtime_resume() -> dwc3_runtime_resume(&qcom->dwc) concurrently with dwc3_pm_resume(&qcom->dwc).
- Between pm_runtime_disable(dev) and pm_runtime_enable(dev), if last_status was RPM_SUSPENDED, pm_runtime_resume_and_get(qcom->dev) returns -EACCES and dwc3_qcom_mux_set() returns 0 after dwc3_qcom_pm_resume() has already checked qcom->dp_only != qcom->utmi_pipe_clk, losing the clock switch.
- If the device was runtime-active, pm_runtime_resume_and_get(qcom->dev) succeeds and dwc3_qcom_select_utmi_clk() gates PIPE_UTMI_CLK_DIS while dwc3_resume_common() is resetting and reinitializing the DWC3 core.

2. In dwc3_qcom_pm_suspend(), dwc3_pm_suspend(&qcom->dwc) runs before acquiring qcom->pipe_clk_lock and setting qcom->pm_suspended = true. If the device was runtime-suspended, a concurrent dwc3_qcom_mux_set() call can invoke pm_runtime_resume_and_get(qcom->dev) -> dwc3_qcom_runtime_resume() after dwc3_pm_suspend() has completed, and dwc3_qcom_suspend() will then disable qcom->clks while the DWC3 core and PHYs are active.

3. When the device is runtime-suspended in device role without wakeup, dwc3_qcom_prepare() -> dwc3_pm_prepare() returns 1, enabling the PM core direct_complete path, which disables runtime PM and skips both dwc3_qcom_pm_suspend() and dwc3_qcom_pm_resume(). If dwc3_qcom_mux_set() is called during system sleep under direct_complete, qcom->pm_suspended is false and pm_runtime_resume_and_get(qcom->dev) fails with -EACCES. Because dwc3_qcom_runtime_resume() does not check qcom->dp_only != qcom->utmi_pipe_clk, the pending clock switch is never applied on a subsequent runtime resume.

4. When the controller is runtime-suspended and dwc3_qcom_mux_set() calls pm_runtime_resume_and_get(qcom->dev), dwc3_qcom_runtime_resume() calls dwc3_runtime_resume(&qcom->dwc) before dwc3_qcom_mux_set() switches the clock via dwc3_qcom_select_utmi_clk().

Could the clock selection check be performed inside dwc3_qcom_resume() (so both system resume and runtime resume apply any pending change before the core resumes), with qcom->pipe_clk_lock and qcom->pm_suspended covering the full suspend and resume sequences?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#9 lore raw

Re: [PATCH v2 3/3] arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode switch

In reply to Joonhoe Kim
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] usb: dwc3: qcom: race between dwc3_qcom_mux_set() and system suspend/resume --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] usb: dwc3: qcom: race between dwc3_qcom_mux_set() and system suspend/resume --

commit fe7520845f2780f9c1a4d2eb56c40d6f95200b73
Author: Joonhoe Kim <[email protected]>

arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode switch

This commit marks the Kaanapali USB controller node with the mode-switch property so that it switches to the UTMI clock when the USB3-DP combo PHY enters DisplayPort-only mode and stops the USB3 PIPE clock.

arch/arm64/boot/dts/qcom/kaanapali.dtsi &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, · line 3944

Quoted 9 lines
arch/arm64/boot/dts/qcom/kaanapali.dtsi +1 -0
index e48a179d07220..a06d5d8674885 100644
@@ -3941,6 +3941,7 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
 			tx-fifo-resize;
 			dma-coherent;
 
+			mode-switch;

[Severity: Medium]
Can enabling mode-switch on the Kaanapali USB controller trigger a race between dwc3_qcom_mux_set() and system suspend/resume in drivers/usb/dwc3/dwc3-qcom.c?

On Kaanapali boards (kaanapali-mtp.dts and kaanapali-qrd.dts), qcom,kaanapali-pmic-glink instantiates UCSI on connector@0. In ucsi_register_port(), UCSI creates a non-freezable singlethread workqueue (con->wq) and acquires the USB controller mode switch via typec_mux_get(). If a connector change happens during system sleep transitions, ucsi_handle_connector_change() runs on con->wq and invokes typec_set_mode() -> typec_mux_set() -> dwc3_qcom_mux_set():

drivers/usb/dwc3/dwc3-qcom.c:dwc3_qcom_mux_set() {
	...
	if (qcom->ignore_pipe_clk || qcom->pm_suspended ||
	    qcom->dp_only == qcom->utmi_pipe_clk ||
	    pm_runtime_resume_and_get(qcom->dev))
		return 0;

	dwc3_qcom_select_utmi_clk(qcom, qcom->dp_only);
	...
}

In dwc3_qcom_pm_suspend(), dwc3_pm_suspend(&qcom->dwc) runs before acquiring qcom->pipe_clk_lock and setting qcom->pm_suspended = true, while runtime PM is still enabled until device_suspend_late():

drivers/usb/dwc3/dwc3-qcom.c:dwc3_qcom_pm_suspend() {
	...
	ret = dwc3_pm_suspend(&qcom->dwc);
	if (ret)
		return ret;

	guard(mutex)(&qcom->pipe_clk_lock);

	ret = dwc3_qcom_suspend(qcom, wakeup);
	if (ret)
		return ret;

	qcom->pm_suspended = true;
	...
}

If qcom->dev was runtime-suspended and dwc3_qcom_mux_set() runs after dwc3_pm_suspend() finishes but before pipe_clk_lock is acquired, dwc3_qcom_mux_set() sees qcom->pm_suspended == false and calls pm_runtime_resume_and_get(qcom->dev). Wouldn't that run dwc3_qcom_runtime_resume() -> dwc3_runtime_resume(&qcom->dwc) (reinitializing the core and resuming the PHYs) right before dwc3_qcom_suspend() disables the glue clocks and interconnects?

Similarly, in dwc3_qcom_pm_resume(), qcom->pm_suspended is cleared and pipe_clk_lock is released before calling dwc3_pm_resume(&qcom->dwc):

drivers/usb/dwc3/dwc3-qcom.c:dwc3_qcom_pm_resume() {
	...
	scoped_guard(mutex, &qcom->pipe_clk_lock) {
		ret = dwc3_qcom_resume(qcom, wakeup);
		if (ret)
			return ret;

		if (!qcom->ignore_pipe_clk &&
		    qcom->dp_only != qcom->utmi_pipe_clk)
			dwc3_qcom_select_utmi_clk(qcom, qcom->dp_only);

		qcom->pm_suspended = false;
	}

	ret = dwc3_pm_resume(&qcom->dwc);
	...
}

Inside dwc3_pm_resume(), pm_runtime_disable(dev) is held across pm_runtime_set_active(dev) and dwc3_resume_common(). If qcom->dev was runtime-suspended prior to system sleep, __pm_runtime_disable() records dev->power.last_status = RPM_SUSPENDED, so rpm_resume() returns -EACCES while runtime PM is disabled. If dwc3_qcom_mux_set() runs during that window, it sees qcom->pm_suspended == false, updates qcom->dp_only, and returns 0 when pm_runtime_resume_and_get(qcom->dev) fails with -EACCES. Doesn't this skip dwc3_qcom_select_utmi_clk() and leave qcom->utmi_pipe_clk out of sync with qcom->dp_only?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#11 lore raw

Re: [PATCH v2 3/3] arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode switch

In reply to Joonhoe Kim
Quoted 11 lines · Joonhoe Kim

When the USB3-DP combo PHY is a mode switch, DisplayPort pin assignments C and E put it in DP-only mode, where it stops the USB3 PIPE clock. Make the USB controller a mode switch as well, so that it moves to the UTMI clock first and keeps its USB 2.0 port working.

---
The "mode-switch" property of usb_dp_qmpphy comes with patch 3 of Balaji Kalkonda's Kaanapali DisplayPort series:
https://lore.kernel.org/all/[email protected]/

DTS cannot be combined in this patchset and must be split. Don't mix patches from independent subsystems when you send something explicitly targeting only one subsystem.
See also: Documentation/devicetree/bindings/submitting-patches.rst

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 1/3] dt-bindings: usb: qcom,snps-dwc3: Add mode-switch

In reply to Joonhoe Kim
Quoted 5 lines · Joonhoe Kim

The QMP USB3-DP combo PHY stops the USB3 PIPE clock when a Type-C DisplayPort pin assignment gives it all four lanes for DisplayPort, while the controller can keep running its USB 2.0 port. The controller has to move to the UTMI clock before that happens, so it needs the Type-C mux state as well. fwnode_typec_mux_get() only matches graph

Controller does not perform the switch, does it?

Quoted 2 lines

nodes that have the "mode-switch" property, so allow it on the controller node.

So judging by this, you would need to fix fwnode_typec_mux_get() or opther driver code, not the binding?

Quoted 14 lines

---
v2:
- Use the common usb-switch schema instead of a local definition

 Documentation/devicetree/bindings/usb/qcom,snps-dwc3.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/usb/qcom,snps-dwc3.yaml +0 -0
index b77c02c64d45..14fc7e4ebc80 100644

Documentation/devicetree/bindings/usb/qcom,snps-dwc3.yaml properties: · line 161

Quoted 4 lines
Documentation/devicetree/bindings/usb/qcom,snps-dwc3.yaml +1 -0
@@ -158,6 +158,8 @@ properties:
       HS/FS/LS modes are supported.
     type: boolean
 
+  mode-switch: true

Drop, but you might explicitly disallow orientation and retimer, if entire solution stays after review.

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v2 1/3] dt-bindings: usb: qcom,snps-dwc3: Add mode-switch

Quoted 8 lines · Krzysztof Kozlowski
Quoted 5 lines · Joonhoe Kim

The QMP USB3-DP combo PHY stops the USB3 PIPE clock when a Type-C DisplayPort pin assignment gives it all four lanes for DisplayPort, while the controller can keep running its USB 2.0 port. The controller has to move to the UTMI clock before that happens, so it needs the Type-C mux state as well. fwnode_typec_mux_get() only matches graph

Controller does not perform the switch, does it?

No, it does not route any signals. It only needs to know the mode: in pin assignments C and E it selects the UTMI clock as its PIPE clock before the PHY stops the PIPE clock.

usb-switch.yaml describes mode-switch as "Possible handler of altmode switching". The WCD939x codec uses it in a similar way: its mux callback only reports the audio accessory mode to its headset detection. The codec nodes in sm8650-qrd.dts and sm8750-mtp.dts have mode-switch.

Quoted 5 lines
Quoted 2 lines

nodes that have the "mode-switch" property, so allow it on the controller node.

So judging by this, you would need to fix fwnode_typec_mux_get() or opther driver code, not the binding?

The binding is needed because typec_mux_match() checks this property before the mux driver has probed (see the comment in typec_mux_match(), drivers/usb/typec/mux.c). Without that check, any graph neighbour that is not a mux would make fwnode_typec_mux_get() return -EPROBE_DEFER forever.

Apple and Rockchip handle this in the PHY driver, because there the PHY driver can reach the controller-side USB3 control (the Apple PIPE handler, the Rockchip USB GRF). On Qualcomm the clock
select is in the dwc3 glue (QSCRATCH), so the alternative would be a new interface for the QMP PHY to notify the controller. I found no existing one. It would have one advantage: the PHY knows when it actually switches. I can try that if you prefer it.

Quoted 4 lines
Quoted 1 line

+ mode-switch: true

Drop, but you might explicitly disallow orientation and retimer, if entire solution stays after review.

OK. v3 will keep the usb-switch.yaml reference, drop this line and set orientation-switch and retimer-switch to false.

Thanks,
Joonhoe Kim

maintainer
#12 lore raw
In reply to Joonhoe Kim
Quoted 73 lines · Joonhoe Kim

With a USB-C monitor in DisplayPort pin assignment C or E, the QMP USB3-DP combo PHY gives all four lanes to DisplayPort and keeps its USB PCS powered down. The USB 2.0 pair still works. Such monitors often have a USB 2.0 hub. But the dwc3 controller still depends on the USB3 PIPE clock. On Kaanapali the next xHCI reset in this state times out ("Host halt failed, -110"). USB stays lost until the cable is replugged. Commit f546912bcac6 ("phy: qcom: qmp-combo: Move pipe_clk on/off to common") keeps the pipe clock branch enabled. That is not enough here.

This series lets the controller be a Type-C mode switch next to the PHY and moves it to the UTMI clock, the way "qcom,select-utmi-as-pipe-clk" does statically, before the PHY switches to DP-only mode.

On Kaanapali the PHY becomes a mode switch with Balaji Kalkonda's DisplayPort series [1]; patch 3 is the controller side for the same SoC. Other SoCs whose PHY is already a mode switch (e.g. SM8650, SM8750) may need the same property on their controller node (not tested).

Related fixes sent separately: "phy: qcom: qmp-combo: Leave the USB PCS alone in DP-only mode" (suspend in DP-only mode) [2] and "usb: typec:
mux: fsa4480: Keep the USB 2.0 switch on in DP-only modes" (boards with an FSA4480 on the USB 2.0 pair) [3].

Patch 2 conflicts with Vladyslav Tymoshchuk's "usb: dwc3: qcom: Defer VBUS override update during system suspend" [4] in dwc3_qcom_pm_suspend() and dwc3_qcom_pm_resume(). Both add a lock there. Like [4], the mux callback defers the QSCRATCH write while the glue is suspended for system sleep. On top of [4] the two locks can become one.

Patches 1-2 are for the USB tree. Patch 3 must not be applied before patch 2: with "mode-switch" on the controller and no mux registered by dwc3-qcom, pmic_glink_altmode defers its probe indefinitely.

Tested on a Lenovo Y700 Gen 5 (TB323FU, Kaanapali) with the series backported to v7.3, plus [2] and [3]. A USB-C monitor ran over 4-lane HBR3. Its USB 2.0 hub worked after 10 replugs and after a plug-in during s2idle. In the s2idle case the mux state came after resume, so the deferred clock switch was not exercised. With the monitor unplugged, a USB 3 stick enumerated at SuperSpeed. Quick replugs (under a second) worked 9 times out of 10. The other time no PD contract was made, so no alternate mode was entered.

Changes in v2:
- Patch 1: use the common usb-switch schema
- Patch 2: switch back to the PIPE clock in the mux callback, when a
USB state follows the safe state. v1 waited for the next role change,
which can come before the mux state (Sashiko)
- Patch 2: keep the UTMI clock on a change of pin assignment while
DisplayPort is active, as the PHY keeps its mode then
- Patch 2: while the glue is suspended for system sleep, only record
the mux state and select the clock on resume
- Patch 2: depend on TYPEC || TYPEC=n. Skip the mux without
CONFIG_TYPEC. The arm64 defconfig has USB_DWC3_QCOM=y and TYPEC=m,
which failed to link (Sashiko). It now builds the glue as a module
- Patch 2: no change to the role notifier
- Patch 3: note the dependency on [1] for the PHY's "mode-switch"
- Patch 3: add Reviewed-by from Abel
- Link to v1: https://urldefense.com/v3/__https://lore.kernel.org/all/[email protected]/__;!!A4F2R9G_pg!YksTt8G_fqiWUQQ_PwsYBGRXdl6VqqTDWd2wikgoX8SgvenwmVlKWzlnwkd6rTZnTFYmByY8ANgOkYQjs1Y$

[1] https://urldefense.com/v3/__https://lore.kernel.org/all/[email protected]/__;!!A4F2R9G_pg!YksTt8G_fqiWUQQ_PwsYBGRXdl6VqqTDWd2wikgoX8SgvenwmVlKWzlnwkd6rTZnTFYmByY8ANgO7ae9gpE$
[2] https://urldefense.com/v3/__https://lore.kernel.org/all/[email protected]/__;!!A4F2R9G_pg!YksTt8G_fqiWUQQ_PwsYBGRXdl6VqqTDWd2wikgoX8SgvenwmVlKWzlnwkd6rTZnTFYmByY8ANgOBOrhEyU$
[3] https://urldefense.com/v3/__https://lore.kernel.org/all/[email protected]/__;!!A4F2R9G_pg!YksTt8G_fqiWUQQ_PwsYBGRXdl6VqqTDWd2wikgoX8SgvenwmVlKWzlnwkd6rTZnTFYmByY8ANgOFxAQjF4$
[4] https://urldefense.com/v3/__https://lore.kernel.org/all/[email protected]/__;!!A4F2R9G_pg!YksTt8G_fqiWUQQ_PwsYBGRXdl6VqqTDWd2wikgoX8SgvenwmVlKWzlnwkd6rTZnTFYmByY8ANgOPYhgXAc$

Joonhoe Kim (3):
dt-bindings: usb: qcom,snps-dwc3: Add mode-switch
usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only
modes
arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode
switch

Quoted 11 lines
 .../bindings/usb/qcom,snps-dwc3.yaml          |   3 +
 arch/arm64/boot/dts/qcom/kaanapali.dtsi       |   1 +
 drivers/usb/dwc3/Kconfig                      |   1 +
 drivers/usb/dwc3/dwc3-qcom.c                  | 103 +++++++++++++++---
 4 files changed, 95 insertions(+), 13 deletions(-)

base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c

Signature · 1 line
2.43.0

Can you address Sashiko's review comments?

Thanks,
Thinh

#7 lore raw

Re: [PATCH v2 2/3] usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only modes

In reply to [email protected]
Quoted 1 line · On Tue, 03 Nov 2026 14:35:19 +0000, [email protected] wrote:

[Severity: High]

[...]

Quoted 3 lines

Should state->mode == TYPEC_STATE_SAFE and TYPEC_STATE_USB be checked before inspecting state->alt, and can gating qcom->dp_only on !qcom->dp_active miss valid transitions to DP-only mode?

Yes to both.

typec_altmode_set_mux() passes the DP altmode with the safe and USB states as well. pmic_glink_altmode passes no altmode with the safe state, so this did not show up in my tests. v3 checks the safe state first and treats only the modal states with the DP SVID as DisplayPort.

The USB states from the DisplayPort altmode driver (exit, removal, configuration back to USB) all follow a safe state, so they now switch back to the PIPE clock. Always selecting the UTMI clock for C or E also covers a change from D to C/E without a safe state in between.

v3 also always selects the UTMI clock for pin assignment C or E. It keeps the UTMI clock on a change from C/E to D/F while DisplayPort is active. If the PHY switches then, USB 2.0 keeps working and USB 3 waits until a USB state follows the next safe state. The PIPE clock while the PHY is in DP-only mode would stop USB, so v3 errs towards the UTMI clock.

Quoted 3 lines

[Severity: High]
How does the synchronization between dwc3_qcom_mux_set(), system sleep, and runtime PM handle the following cases?

[...]

Quoted 4 lines

Could the clock selection check be performed inside dwc3_qcom_resume() (so both system resume and runtime resume apply any pending change before the core resumes), with qcom->pipe_clk_lock and qcom->pm_suspended covering the full suspend and resume sequences?

Yes, the cases are real. v3 follows the suggestion:

- The mux callback no longer resumes the glue.
- A flag set under the lock at the start of a runtime or system suspend and cleared after the core has resumed makes the callback only record the state in between (cases 1 and 2). If the suspend fails, the flag is cleared and the state applied right away.
- dwc3_qcom_resume() compares the recorded state with the clock selected in QSCRATCH and switches before the core resumes (cases 1, 3 and 4). v3 has no cached clock state any more. A change recorded while the core resumes is applied when the flag is cleared.

I kept pm_suspended as it is, because the resume interrupt handler uses it.

Tested on the Lenovo Y700 Gen 5 (TB323FU, Kaanapali); details are in the v3 cover. In those tests the mux state came after resume or needed no clock change, so a recorded change was not applied on resume.

v3: https://lore.kernel.org/all/[email protected]/

Thanks,
Joonhoe Kim

#10 lore raw

Re: [PATCH v2 3/3] arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode switch

In reply to [email protected]
Quoted 4 lines · On Tue, 03 Nov 2026 15:05:12 +0000, [email protected] wrote:

[Severity: Medium]
Can enabling mode-switch on the Kaanapali USB controller trigger a race between dwc3_qcom_mux_set() and system suspend/resume in drivers/usb/dwc3/dwc3-qcom.c?

[...]

Yes. This is the same race as in your review of patch 2, and the fix is in the driver. In v3 the mux callback no longer resumes the glue. From the start of a runtime or system suspend until the core has resumed, it only records the state. dwc3_qcom_resume() applies it before the core resumes. v3 also compares with the clock selected in QSCRATCH instead of a cached value, so a selection lost with QSCRATCH in system suspend is restored on resume.

As Krzysztof asked, the DTS patch is now sent on its own:
https://lore.kernel.org/all/[email protected]/

Thanks,
Joonhoe Kim

#14 lore raw
In reply to Joonhoe Kim
Quoted 9 lines · Joonhoe Kim

With a USB-C monitor in DisplayPort pin assignment C or E, the QMP USB3-DP combo PHY gives all four lanes to DisplayPort and keeps its USB PCS powered down. The USB 2.0 pair still works. Such monitors often have a USB 2.0 hub. But the dwc3 controller still depends on the USB3 PIPE clock. On Kaanapali the next xHCI reset in this state times out ("Host halt failed, -110"). USB stays lost until the cable is replugged. Commit f546912bcac6 ("phy: qcom: qmp-combo: Move pipe_clk on/off to common") keeps the pipe clock branch enabled. That is not enough here.

Quoted 3 lines

This series lets the controller be a Type-C mode switch next to the PHY and moves it to the UTMI clock, the way "qcom,select-utmi-as-pipe-clk" does statically, before the PHY switches to DP-only mode.

Joonhoe, thanks for adding this generic features for Qcom platforms, it is not only for Kaanapali, but also for platforms which have USB/DP combo PHY.

We did an internal discussion for this use case, we may prefer the solution that let the PHY notify the controller this PHY lane is going to change from USB to DP (4lane) event, it could keep driver independent with dts for this feature.

We more prefer an general solution like [1], but it seems PHY maintainer Vinod prefers private interface between controller and PHY [2].

[1]: https://lore.kernel.org/all/20260924-b4-rockchip-dwc3-rockchip-glue-v16-1-126a2e9133c3@collabora.com/
[2]: https://lore.kernel.org/all/[email protected]/

Peter

Quoted 73 lines

On Kaanapali the PHY becomes a mode switch with Balaji Kalkonda's DisplayPort series [1]; patch 3 is the controller side for the same SoC. Other SoCs whose PHY is already a mode switch (e.g. SM8650, SM8750) may need the same property on their controller node (not tested).

Related fixes sent separately: "phy: qcom: qmp-combo: Leave the USB PCS alone in DP-only mode" (suspend in DP-only mode) [2] and "usb: typec:
mux: fsa4480: Keep the USB 2.0 switch on in DP-only modes" (boards with an FSA4480 on the USB 2.0 pair) [3].

Patch 2 conflicts with Vladyslav Tymoshchuk's "usb: dwc3: qcom: Defer VBUS override update during system suspend" [4] in dwc3_qcom_pm_suspend() and dwc3_qcom_pm_resume(). Both add a lock there. Like [4], the mux callback defers the QSCRATCH write while the glue is suspended for system sleep. On top of [4] the two locks can become one.

Patches 1-2 are for the USB tree. Patch 3 must not be applied before patch 2: with "mode-switch" on the controller and no mux registered by dwc3-qcom, pmic_glink_altmode defers its probe indefinitely.

Tested on a Lenovo Y700 Gen 5 (TB323FU, Kaanapali) with the series backported to v7.3, plus [2] and [3]. A USB-C monitor ran over 4-lane HBR3. Its USB 2.0 hub worked after 10 replugs and after a plug-in during s2idle. In the s2idle case the mux state came after resume, so the deferred clock switch was not exercised. With the monitor unplugged, a USB 3 stick enumerated at SuperSpeed. Quick replugs (under a second) worked 9 times out of 10. The other time no PD contract was made, so no alternate mode was entered.

Changes in v2:
- Patch 1: use the common usb-switch schema
- Patch 2: switch back to the PIPE clock in the mux callback, when a USB state follows the safe state. v1 waited for the next role change, which can come before the mux state (Sashiko)
- Patch 2: keep the UTMI clock on a change of pin assignment while DisplayPort is active, as the PHY keeps its mode then
- Patch 2: while the glue is suspended for system sleep, only record the mux state and select the clock on resume
- Patch 2: depend on TYPEC || TYPEC=n. Skip the mux without CONFIG_TYPEC. The arm64 defconfig has USB_DWC3_QCOM=y and TYPEC=m, which failed to link (Sashiko). It now builds the glue as a module
- Patch 2: no change to the role notifier
- Patch 3: note the dependency on [1] for the PHY's "mode-switch"
- Patch 3: add Reviewed-by from Abel
- Link to v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

Joonhoe Kim (3):
dt-bindings: usb: qcom,snps-dwc3: Add mode-switch
usb: dwc3: qcom: Use the UTMI clock as PIPE clock in DisplayPort-only
modes
arm64: dts: qcom: kaanapali: Mark the USB controller as a Type-C mode
switch

 .../bindings/usb/qcom,snps-dwc3.yaml          |   3 +
 arch/arm64/boot/dts/qcom/kaanapali.dtsi       |   1 +
 drivers/usb/dwc3/Kconfig                      |   1 +
 drivers/usb/dwc3/dwc3-qcom.c                  | 103 +++++++++++++++---
 4 files changed, 95 insertions(+), 13 deletions(-)

base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c

Signature · 1 line
2.43.0
Signature · 2 lines
Thanks,
Peter Chen
#15 lore raw
Quoted 4 lines · Peter Chen

We did an internal discussion for this use case, we may prefer the solution that let the PHY notify the controller this PHY lane is going to change from USB to DP (4lane) event, it could keep driver independent with dts for this feature.

Thanks, Peter. I kept the mode switch in v4 and explained why in its cover letter. The Type-C mux framework already calls each mode switch linked from the connector, and with the usual graph (HS port to the controller, SS port to the PHY) the controller is called before the PHY changes lanes, so no new interface between the PHY and the controller is needed. The cost is a "mode-switch" property on each controller node, which a notification from the PHY would avoid. If you settle on that, the clock selection in patch 2 can be driven from it instead.

v4: https://lore.kernel.org/all/[email protected]/

Thanks,
Joonhoe Kim