Skip to contentSkip to conversation

phy: qcom: qmp-combo: Leave the USB PCS alone in DP-only mode

PATCH Superseded Joonhoe Kim 3 participants 5 messages Oct 22 – Oct 23

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: qcom: qmp-combo: Leave the USB PCS alone in DP-only mode

In DP-only mode (DisplayPort pin assignments C and E) all four lanes belong to the DisplayPort PHY and the USB PCS stays powered down. The USB controller can still exit and re-init its PHY in this state, e.g. across a system suspend that loses power. qmp_combo_usb_init() then programs the USB serdes, lane and PCS tables over the DisplayPort configuration and times out waiting for PHYSTATUS, and qmp_combo_usb_exit() resets and powers down a PCS that is not in use.

In DP-only mode only take and drop the common reference, but keep counting the USB user, so that qmp_combo_reconfigure_phy() powers the USB PCS up when the port leaves DP-only mode.

On a Lenovo Y700 Gen 5 (TB323FU, Kaanapali) with a USB-C monitor in pin assignment C, resume from s2idle failed with "phy initialization timed-out", the dwc3 resume returned -110 and the following xHCI resume hung the system.

Fixes 896277138c13 ("phy: qcom: qmp-combo: register a typec mux to change the QMPPHY_MODE")

---
Tested on a 7.3-rc4 based tree, where the mux switch itself still drops usb_init_count when it enters DP-only mode, so the tested change skipped the count as well. This version follows the reworked mux path in phy-next and is build-tested only.

 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +11 -7
index 187f0cd11f6c..6e3406d519d2 100644
@@ -4459,10 +4459,12 @@ static int qmp_combo_usb_init(struct phy *phy)
 	if (ret)
 		return ret;
 
-	ret = qmp_combo_usb_power_on(phy);
-	if (ret) {
-		qmp_combo_com_exit(qmp, false);
-		return ret;
+	if (qmp->qmpphy_mode != QMPPHY_MODE_DP_ONLY) {
+		ret = qmp_combo_usb_power_on(phy);
+		if (ret) {
+			qmp_combo_com_exit(qmp, false);
+			return ret;
+		}
 	}
 
 	qmp->usb_init_count++;
@@ -4484,9 +4486,11 @@ static int qmp_combo_usb_exit(struct phy *phy)
 		return 0;
 	}
 
-	ret = qmp_combo_usb_power_off(phy);
-	if (ret)
-		return ret;
+	if (qmp->qmpphy_mode != QMPPHY_MODE_DP_ONLY) {
+		ret = qmp_combo_usb_power_off(phy);
+		if (ret)
+			return ret;
+	}
 
 	ret = qmp_combo_com_exit(qmp, false);
 	if (ret)

base-commit: 2efb7a11f1aa4d2dc285fe2680cca22cb9f72f64

Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] phy: qcom: qmp-combo: qmp_combo_typec_switch_set() powers USB in DP-only mode --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] phy: qcom: qmp-combo: qmp_combo_typec_switch_set() powers USB in DP-only mode --

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

phy: qcom: qmp-combo: Leave the USB PCS alone in DP-only mode

This commit skips powering on and off the USB PCS in qmp_combo_usb_init() and qmp_combo_usb_exit() when the PHY is in QMPPHY_MODE_DP_ONLY while continuing to track qmp->usb_init_count.

Quoted 26 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +6 -5
index 187f0cd11f6c3..6e3406d519d28 100644
@@ -4459,10 +4459,12 @@ static int qmp_combo_usb_init(struct phy *phy)
 	if (ret)
 		return ret;
 
-	ret = qmp_combo_usb_power_on(phy);
-	if (ret) {
-		qmp_combo_com_exit(qmp, false);
-		return ret;
+	if (qmp->qmpphy_mode != QMPPHY_MODE_DP_ONLY) {
+		ret = qmp_combo_usb_power_on(phy);
+		if (ret) {
+			qmp_combo_com_exit(qmp, false);
+			return ret;
+		}
 	}
 
 	qmp->usb_init_count++;
@@ -4484,9 +4486,11 @@ static int qmp_combo_usb_exit(struct phy *phy)
 		return 0;
 	}
 
-	ret = qmp_combo_usb_power_off(phy);

drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_usb_exit(struct phy *phy) · line 4496

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +5 -2
-	if (ret)
-		return ret;
+	if (qmp->qmpphy_mode != QMPPHY_MODE_DP_ONLY) {
+		ret = qmp_combo_usb_power_off(phy);
+		if (ret)
+			return ret;
+	}
 
 	ret = qmp_combo_com_exit(qmp, false);
 	if (ret)

[Severity: High]
With qmp_combo_usb_init() and qmp_combo_usb_exit() keeping qmp->usb_init_count non-zero in QMPPHY_MODE_DP_ONLY while leaving the USB PCS powered off, do qmp_combo_typec_switch_set() and qmp_combo_reconfigure_phy() in drivers/phy/qualcomm/phy-qcom-qmp-combo.c also need to check for QMPPHY_MODE_DP_ONLY before touching the USB PCS?

In drivers/phy/qualcomm/phy-qcom-qmp-combo.c, qmp_combo_typec_switch_set() checks qmp->usb_init_count without checking qmp->qmpphy_mode:

drivers/phy/qualcomm/phy-qcom-qmp-combo.c:qmp_combo_typec_switch_set() {
	...
	if (qmp->init_count) {
		if (qmp->usb_init_count || qmp->usb4_init_count)
			qmp_combo_usb_power_off(qmp->usb_phy);
		qmp_combo_com_exit(qmp, true);

		qmp_combo_com_init(qmp, true);
		if (qmp->usb_init_count || qmp->usb4_init_count)
			qmp_combo_usb_power_on(qmp->usb_phy);
		if (qmp->dp_init_count)
			cfg->dp_aux_init(qmp);
	}
	...
}

When a DP-only monitor (pin assignment C or E) is unplugged, qmp_combo_typec_switch_set() ignores TYPEC_ORIENTATION_NONE, and qmp_combo_typec_mux_set() delays the mode change if the Type-C unplug mux notification arrives before DRM powers off the DP PHY:

drivers/phy/qualcomm/phy-qcom-qmp-combo.c:qmp_combo_typec_mux_set() {
	...
	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;
	}
	...
}

This leaves qmp->qmpphy_mode set to QMPPHY_MODE_DP_ONLY while disconnected. On a subsequent connection in the opposite orientation, Type-C drivers (such as pmic_glink_altmode_worker(), ucsi_handle_connector_change(), tcpm_mux_set(), and cros_typec_configure_mux()) call typec_switch_set() before typec_mux_set().

When qmp_combo_typec_switch_set() runs with qmp->qmpphy_mode still set to QMPPHY_MODE_DP_ONLY and qmp->usb_init_count > 0, it calls qmp_combo_usb_power_off() on the unpowered USB PCS, re-runs qmp_combo_com_init() (which configures DP_MODE and leaves the USB3 PHY reset asserted), and then calls qmp_combo_usb_power_on(). Would this overwrite the serdes, lane, and PCS tables, time out waiting for PHYSTATUS, and call clk_disable_unprepare(qmp->pipe_clk) on the error path while qmp->init_count remains non-zero?

Similarly, when leaving QMPPHY_MODE_DP_ONLY with qmp->usb_init_count > 0, qmp_combo_reconfigure_phy() unconditionally powers off the USB PCS even though it was kept powered down in DP-only mode:

drivers/phy/qualcomm/phy-qcom-qmp-combo.c:qmp_combo_reconfigure_phy() {
	...
	if (qmp->usb_init_count || qmp->usb4_init_count)
		qmp_combo_usb_power_off(qmp->usb_phy);
	...
}

Should both qmp_combo_typec_switch_set() and the power-off path in qmp_combo_reconfigure_phy() also skip the USB PCS when qmp->qmpphy_mode is QMPPHY_MODE_DP_ONLY?

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

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#2 lore raw
Quoted 1 line · Sashiko AI review

- [High] phy: qcom: qmp-combo: qmp_combo_typec_switch_set() powers USB in DP-only mode

[...]

Quoted 3 lines

Would this overwrite the serdes, lane, and PCS tables, time out waiting for PHYSTATUS, and call clk_disable_unprepare(qmp->pipe_clk) on the error path while qmp->init_count remains non-zero?

[...]

Quoted 3 lines

Should both qmp_combo_typec_switch_set() and the power-off path in qmp_combo_reconfigure_phy() also skip the USB PCS when qmp->qmpphy_mode is QMPPHY_MODE_DP_ONLY?

Yes. Since 89563a152973 ("phy: qualcomm: qmp-combo: Add preliminary USB4 support") the mux keeps usb_init_count when it enters DP-only mode, so an orientation change in that mode already re-ran the USB PCS power-on over the DisplayPort configuration before this patch. v2 skips the USB PCS in qmp_combo_typec_switch_set() as well.

The power-off in qmp_combo_reconfigure_phy() when leaving DP-only mode only asserts SW_RESET, clears the start bits and puts the PCS into power-down, which it already is in DP-only mode, so it is harmless, but v2 skips it too for consistency.

The pipe_clk handling on the error path of qmp_combo_usb_power_on() is a separate issue: pipe_clk is enabled in qmp_combo_com_init() and disabled in qmp_combo_com_exit(), so disabling it on a PHYSTATUS timeout leaves it unbalanced whatever the mode. This patch does not change that.

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

Thanks,
Joonhoe Kim

#3 lore raw
In reply to Joonhoe Kim
Quoted 8 lines · Joonhoe Kim

In DP-only mode (DisplayPort pin assignments C and E) all four lanes belong to the DisplayPort PHY and the USB PCS stays powered down. The USB controller can still exit and re-init its PHY in this state, e.g. across a system suspend that loses power. qmp_combo_usb_init() then programs the USB serdes, lane and PCS tables over the DisplayPort configuration and times out waiting for PHYSTATUS, and qmp_combo_usb_exit() resets and powers down a PCS that is not in use.

Quoted 8 lines

In DP-only mode only take and drop the common reference, but keep counting the USB user, so that qmp_combo_reconfigure_phy() powers the USB PCS up when the port leaves DP-only mode.

On a Lenovo Y700 Gen 5 (TB323FU, Kaanapali) with a USB-C monitor in pin assignment C, resume from s2idle failed with "phy initialization timed-out", the dwc3 resume returned -110 and the following xHCI resume hung the system.

Good catch. I don't think I've seen system hangs from this on Hamoa, but I've had USB stop working on the ports where 4xDP+USB2 was left connected during suspend..

Quoted 20 lines
Fixes 896277138c13 ("phy: qcom: qmp-combo: register a typec mux to change the QMPPHY_MODE")

---
Tested on a 7.3-rc4 based tree, where the mux switch itself still drops usb_init_count when it enters DP-only mode, so the tested change skipped the count as well. This version follows the reworked mux path in phy-next and is build-tested only.

  drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +0 -1
index 187f0cd11f6c..6e3406d519d2 100644
@@ -4459,10 +4459,12 @@ static int qmp_combo_usb_init(struct phy *phy)
  	if (ret)
  		return ret;
 
-	ret = qmp_combo_usb_power_on(phy);

drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_usb_init(struct phy *phy) · line 4467

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +6 -3
-	if (ret) {
-		qmp_combo_com_exit(qmp, false);
-		return ret;
+	if (qmp->qmpphy_mode != QMPPHY_MODE_DP_ONLY) {
+		ret = qmp_combo_usb_power_on(phy);
+		if (ret) {
+			qmp_combo_com_exit(qmp, false);
+			return ret;
+		}
[..]

The USB4 chunk above (juuuust before the start of this diff's context) does a similar thing in a different style: it increments both init_count and usb_init_count and early-returns, skipping over qmp_combo_com_init as well.

I think both USB4 and DP should be written similarly but should qmp_combo_com_init be skipped here? No in both cases or does USB4 skip it for a good reason?

(I'm especially wondering about the impact of that on the USB HS PHY clock, since it's actually sourced from here without a properly modeled dependency right now…)

Thanks,
~val

#4 lore raw
Quoted 3 lines · Val Packett

Good catch. I don't think I've seen system hangs from this on Hamoa, but I've had USB stop working on the ports where 4xDP+USB2 was left connected during suspend..

That may be the same path: on resume the USB PHY init programs the USB tables over the DisplayPort configuration and times out. On the Y700 the xHCI resume that followed hung; a USB port that stays dead afterwards would fit as well. A "phy initialization timed-out" from the QMP PHY on resume would confirm it.

Quoted 5 lines

The USB4 chunk above (juuuust before the start of this diff's context) does a similar thing in a different style: it increments both init_count and usb_init_count and early-returns, skipping over qmp_combo_com_init as well.

Quoted 7 lines

I think both USB4 and DP should be written similarly but should qmp_combo_com_init be skipped here? No in both cases or does USB4 skip it for a good reason?

(I'm especially wondering about the impact of that on the USB HS PHY clock, since it's actually sourced from here without a properly modeled dependency right now…)

DP-only needs it, and USB4 does not really skip it: the bare init_count++ is exactly what qmp_combo_com_init(qmp, false) does when the count is already non-zero, and qmp_combo_usb4_init() holds that first reference. In DP-only mode nothing guarantees another holder: on resume the USB controller can init its PHY before DisplayPort does, and then qmp_combo_com_init() is what turns the clocks, resets and regulators on.

So I kept the two branches different: the USB4 one is a separate early return because it must not reprogram the PHY at all, while DP-only only leaves the USB PCS alone. The mux path already keeps the USB PCS powered down in DP-only mode; v2 makes usb_init/usb_exit match it, and the common block stays on while USB holds a reference, which looks like the safer side for the HS PHY clock.

v2 also skips the USB PCS in qmp_combo_typec_switch_set() and qmp_combo_reconfigure_phy() in DP-only mode, as Sashiko pointed out on v1:

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

Thanks,
Joonhoe Kim