Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP
@ 2026-11-19 19:40 Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 1/7] phy: rockchip: usbdp: Disable USB3 port during normal power-on Sebastian Reichel
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel, Yury Smirnov

This (final) cleanup part depends on new DWC3 glue driver series:

https://lore.kernel.org/linux-phy/20261114-b4-rockchip-dwc3-rockchip-glue-v19-0-b79fb5f4b42a@collabora.com/

Changes in v18:
- Link to v17: https://patch.msgid.link/20261114-b4-rockchip-usbdp-cleanup-part3-v17-0-1af5f566408e@collabora.com
- Ignore Sashiko report that rk_udphy_u3_port_disable() is not called
  when rk_udphy_usb3_phy_exit() is called. This path ensures dwc3 no
  longer accesses registers (Sashiko)
- Ignore Sashiko report that the orientation switch event should also
  update the power state for setups with orientation switch enabled, but
  mode switch disabled. Currently upstream has two DTs doing that and
  both are incorrect (i.e. mode-switch should be added). Considering this
  is a pre-existing "bug", it's better to fix these DTs (independent of
  this series). The mux is necessary to support 4 lane DP mode anyway.
  Basically orientation-switch without mode-switch makes no sense for
  this PHY, because orientation-switch already requires that all 4 SS
  lanes are routed. DP AltMode also requires the SBU lanes in addition,
  but there is no reason not to route them when the other lanes are
  already assigned. In the unlikely case a HW vendor failed to route
  them, adding the mode-switch is still fine (e.g. it also allows
  switching between SAFE and USB) anyway. (Sashiko)
- Fix PHY clock leak for high-speed only mode (Sashiko)
- Ignore errors in rk_udphy_dp_phy_power_off() and
  rk_udphy_usb3_phy_exit(); when PHY is powered off, no failures can
  happen and when PHY needs a re-init after the exit, the error is
  effectively for the other PHY. Thus avoid propagating the error
  (Sashiko)
- Default to TYPEC_STATE_SAFE to avoid one extra useless mode change
  (Sashiko)

Changes in v17:
- Link to v16: https://patch.msgid.link/20260930-b4-rockchip-usbdp-cleanup-part3-v16-0-bc144f80afc4@collabora.com
- Rebase to v7.4-rc1 and v19 of the glue driver series. This drops
  the first patch, as the PHY reset notifier has been replaced by
  direct calls added in the glue series, which now also introduces
  sw_mode.
- Add one more patch to gracefully handle DP lane remuxing after cable
  orientation change when the DP controller kept the display output (and
  thus PHY) enabled even with HPD=0. This can apparently happen with
  some DRM compositors.

Changes in v16:
- Link to v15: https://patch.msgid.link/20260915-b4-rockchip-usbdp-cleanup-part3-v15-0-9ad90a456953@collabora.com
- Split out "Disable USB3 port during normal power-on" from first patch
- Collect R-b tags from Mani

Changes in v15:
 - Link to v14: https://patch.msgid.link/20260813-rockchip-usbdp-cleanup-v14-0-b5ad9c68fa11@collabora.com
 - Split the series, no patch changes in this part

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
Sebastian Reichel (7):
      phy: rockchip: usbdp: Disable USB3 port during normal power-on
      phy: rockchip: usbdp: Drop -EPROBE_DEFER hack
      phy: rockchip: usbdp: Rename mode to hw_mode
      phy: rockchip: usbdp: Fix power state handling
      phy: rockchip: usbdp: Re-init PHY on mux change
      phy: rockchip: usbdp: Add USB-C state without DP enabled
      phy: rockchip: usbdp: Add DP lane setup to power state update

 drivers/phy/rockchip/phy-rockchip-usbdp.c | 240 +++++++++++++++++-------------
 1 file changed, 139 insertions(+), 101 deletions(-)
---
base-commit: bc71431221f5ba8bb33918399552636e059c2c45
change-id: 20260914-b4-rockchip-usbdp-cleanup-part3-cca70383ebe3
prerequisite-message-id: 20261114-b4-rockchip-dwc3-rockchip-glue-v19-0-b79fb5f4b42a@collabora.com
prerequisite-patch-id: 4fa3aae8ccfa5383522070179c8777302411082c
prerequisite-patch-id: 0cfab94fd67b6304cd303a9810981aaca328c651
prerequisite-patch-id: c2e1c453454a7589a691fe391dc79e86f09ca7b7
prerequisite-patch-id: dadeaf9e369e04d8b3329493a1a0756ddd6140f0
prerequisite-patch-id: 2c727b8400980c760ca8f1e5fd989a3bf9404020
prerequisite-patch-id: cf4e7d51c77a5eccda6c687730eddd3135d94d91

Best regards,
--  
Sebastian Reichel <sebastian.reichel@collabora.com>


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 1/7] phy: rockchip: usbdp: Disable USB3 port during normal power-on
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 2/7] phy: rockchip: usbdp: Drop -EPROBE_DEFER hack Sebastian Reichel
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel

In the reset path, the USB3 port is disabled. This re-routes the clock
going from the PHY to the USB3 controller. This adds the same to the
normal power-on path, so that it behaves exactly the same (except that
the clocks routed to the PHY stay enabled in the reset path).

This hasn't been done so far, as it requires the recently introduced
PHY reset infrastructure to avoid the PHY PLL not locking during
startup.

Tested-by: Igor Paunovic <royalnet026@gmail.com> # Orange Pi 5 Plus
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index 9c6d921b9191..d01a819bf794 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -1051,6 +1051,9 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
 	if (udphy->status == UDPHY_MODE_NONE) {
 		rk_udphy_run_reset_handler(udphy, true);
 
+		rk_udphy_u3_port_disable(udphy, true);
+		udelay(10);
+
 		ret = rk_udphy_setup(udphy);
 		if (ret) {
 			rk_udphy_run_reset_handler(udphy, false);

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 2/7] phy: rockchip: usbdp: Drop -EPROBE_DEFER hack
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 1/7] phy: rockchip: usbdp: Disable USB3 port during normal power-on Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 3/7] phy: rockchip: usbdp: Rename mode to hw_mode Sebastian Reichel
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel

The hack to return -EPROBE_DEFER when the lcpll lock timeouts is no
longer needed. The driver now does a reset during its PHY init, which
avoids the problem.

Since rk_udphy_status_check() is called after the probe, it should not
return -EPROBE_DEFER.

Tested-by: Igor Paunovic <royalnet026@gmail.com> # Orange Pi 5 Plus
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index d01a819bf794..025c8d52d72c 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -754,17 +754,7 @@ static int rk_udphy_status_check(struct rk_udphy *udphy)
 					       (val & CMN_ANA_LCPLL_LOCK_DONE), 200, 100000);
 		if (ret) {
 			dev_err(udphy->dev, "cmn ana lcpll lock timeout\n");
-			/*
-			 * If earlier software (U-Boot) enabled USB once already
-			 * the PLL may have problems locking on the first try.
-			 * It will be successful on the second try, so for the
-			 * time being a -EPROBE_DEFER will solve the issue.
-			 *
-			 * This requires further investigation to understand the
-			 * root cause, especially considering that the driver is
-			 * asserting all reset lines at probe time.
-			 */
-			return -EPROBE_DEFER;
+			return ret;
 		}
 
 		if (!udphy->flip) {

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 3/7] phy: rockchip: usbdp: Rename mode to hw_mode
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 1/7] phy: rockchip: usbdp: Disable USB3 port during normal power-on Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 2/7] phy: rockchip: usbdp: Drop -EPROBE_DEFER hack Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 4/7] phy: rockchip: usbdp: Fix power state handling Sebastian Reichel
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel

Rename mode field to hw_mode to make clear that this is the modes
currently supported by the hardware, but not necessarily requested
by software. I.e. it is only set by either the USB-C state machine
or device-tree if the PHY is used in a fixed routing setup.

Tested-by: Igor Paunovic <royalnet026@gmail.com> # Orange Pi 5 Plus
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 48 +++++++++++++++----------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index 025c8d52d72c..de8f01bd0467 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -174,7 +174,7 @@ struct rk_udphy {
 	/* PHY status management */
 	bool flip;
 	bool phy_needs_reinit;
-	u8 mode;
+	u8 hw_mode; /* modes currently supported by hardware */
 	u8 status;
 	u8 sw_mode; /* modes currently requested */
 
@@ -583,18 +583,18 @@ static void rk_udphy_dp_lane_enable(struct rk_udphy *udphy, int dp_lanes)
 				   CMN_DP_CMN_RSTN, FIELD_PREP(CMN_DP_CMN_RSTN, 0x0));
 }
 
-static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 mode)
+static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 hw_mode)
 {
-	if (udphy->mode == mode)
+	if (udphy->hw_mode == hw_mode)
 		return;
 
 	udphy->phy_needs_reinit = true;
-	udphy->mode = mode;
+	udphy->hw_mode = hw_mode;
 }
 
 static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state)
 {
-	u8 mode;
+	u8 hw_mode;
 
 	switch (state) {
 	case TYPEC_DP_STATE_C:
@@ -603,7 +603,7 @@ static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state
 		udphy->lane_mux_sel[1] = PHY_LANE_MUX_DP;
 		udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
 		udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
-		mode = UDPHY_MODE_DP;
+		hw_mode = UDPHY_MODE_DP;
 		udphy->dp_lanes = 4;
 		break;
 
@@ -620,12 +620,12 @@ static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state
 			udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
 			udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
 		}
-		mode = UDPHY_MODE_DP_USB;
+		hw_mode = UDPHY_MODE_DP_USB;
 		udphy->dp_lanes = 2;
 		break;
 	}
 
-	rk_udphy_mode_set(udphy, mode);
+	rk_udphy_mode_set(udphy, hw_mode);
 }
 
 static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy)
@@ -748,7 +748,7 @@ static int rk_udphy_status_check(struct rk_udphy *udphy)
 	int ret;
 
 	/* LCPLL check */
-	if (udphy->mode & UDPHY_MODE_USB) {
+	if (udphy->hw_mode & UDPHY_MODE_USB) {
 		ret = regmap_read_poll_timeout(udphy->pma_regmap, CMN_ANA_LCPLL_DONE_OFFSET,
 					       val, (val & CMN_ANA_LCPLL_AFC_DONE) &&
 					       (val & CMN_ANA_LCPLL_LOCK_DONE), 200, 100000);
@@ -783,15 +783,15 @@ static int rk_udphy_init(struct rk_udphy *udphy)
 	int ret;
 
 	dev_dbg(udphy->dev, "reinit PHY with USB3=%s and DP=%s (%u lanes) flipped=%s\n",
-		str_on_off(udphy->mode & UDPHY_MODE_USB),
-		str_on_off(udphy->mode & UDPHY_MODE_DP),
+		str_on_off(udphy->hw_mode & UDPHY_MODE_USB),
+		str_on_off(udphy->hw_mode & UDPHY_MODE_DP),
 		udphy->dp_lanes, str_yes_no(udphy->flip));
 
 	rk_udphy_reset_assert_all(udphy);
 	usleep_range(10000, 11000);
 
 	/* enable rx lfps for usb */
-	if (udphy->mode & UDPHY_MODE_USB)
+	if (udphy->hw_mode & UDPHY_MODE_USB)
 		rk_udphy_grfreg_write(udphy->udphygrf, &cfg->grfcfg.rx_lfps, true);
 
 	/* Step 1: power on pma and deassert apb rstn */
@@ -828,13 +828,13 @@ static int rk_udphy_init(struct rk_udphy *udphy)
 			   FIELD_PREP(CMN_DP_LANE_EN_ALL, 0));
 
 	/* Step 4: deassert init rstn and wait for 200ns from datasheet */
-	if (udphy->mode & UDPHY_MODE_USB) {
+	if (udphy->hw_mode & UDPHY_MODE_USB) {
 		ret = rk_udphy_reset_deassert(udphy, "init");
 		if (ret)
 			goto assert_resets;
 	}
 
-	if (udphy->mode & UDPHY_MODE_DP) {
+	if (udphy->hw_mode & UDPHY_MODE_DP) {
 		regmap_update_bits(udphy->pma_regmap, CMN_DP_RSTN_OFFSET,
 				   CMN_DP_INIT_RSTN,
 				   FIELD_PREP(CMN_DP_INIT_RSTN, 0x1));
@@ -843,7 +843,7 @@ static int rk_udphy_init(struct rk_udphy *udphy)
 	udelay(1);
 
 	/*  Step 5: deassert cmn/lane rstn */
-	if (udphy->mode & UDPHY_MODE_USB) {
+	if (udphy->hw_mode & UDPHY_MODE_USB) {
 		ret = rk_udphy_reset_deassert(udphy, "cmn");
 		if (ret)
 			goto assert_resets;
@@ -902,7 +902,7 @@ static int rk_udphy_parse_lane_mux_data(struct rk_udphy *udphy)
 	num_lanes = device_property_count_u32(udphy->dev, "rockchip,dp-lane-mux");
 	if (num_lanes < 0) {
 		dev_dbg(udphy->dev, "no dp-lane-mux, following dp alt mode\n");
-		udphy->mode = UDPHY_MODE_USB;
+		udphy->hw_mode = UDPHY_MODE_USB;
 		return 0;
 	}
 
@@ -931,10 +931,10 @@ static int rk_udphy_parse_lane_mux_data(struct rk_udphy *udphy)
 		}
 	}
 
-	udphy->mode = UDPHY_MODE_DP;
+	udphy->hw_mode = UDPHY_MODE_DP;
 	udphy->dp_lanes = num_lanes;
 	if (num_lanes == 1 || num_lanes == 2) {
-		udphy->mode |= UDPHY_MODE_USB;
+		udphy->hw_mode |= UDPHY_MODE_USB;
 		udphy->flip = (udphy->lane_mux_sel[0] == PHY_LANE_MUX_DP) ||
 			      (udphy->lane_mux_sel[1] == PHY_LANE_MUX_DP);
 	}
@@ -1033,7 +1033,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
 {
 	int ret;
 
-	if (!(udphy->mode & mode)) {
+	if (!(udphy->hw_mode & mode)) {
 		dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
 		return 0;
 	}
@@ -1050,7 +1050,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
 			return ret;
 		}
 
-		if (!udphy->hs && udphy->mode & UDPHY_MODE_USB)
+		if (!udphy->hs && udphy->hw_mode & UDPHY_MODE_USB)
 			rk_udphy_u3_port_disable(udphy, false);
 		udphy->phy_needs_reinit = false;
 
@@ -1067,7 +1067,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
 			return ret;
 		}
 
-		if (!udphy->hs && udphy->mode & UDPHY_MODE_USB)
+		if (!udphy->hs && udphy->hw_mode & UDPHY_MODE_USB)
 			rk_udphy_u3_port_disable(udphy, false);
 		udphy->phy_needs_reinit = false;
 
@@ -1081,7 +1081,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
 
 static void rk_udphy_power_off(struct rk_udphy *udphy, u8 mode)
 {
-	if (!(udphy->mode & mode)) {
+	if (!(udphy->hw_mode & mode)) {
 		dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
 		return;
 	}
@@ -1349,7 +1349,7 @@ static int rk_udphy_usb3_phy_init(struct phy *phy)
 	udphy->sw_mode |= UDPHY_MODE_USB;
 
 	/* DP only or high-speed, disable U3 port */
-	if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs) {
+	if (!(udphy->hw_mode & UDPHY_MODE_USB) || udphy->hs) {
 		rk_udphy_u3_port_disable(udphy, true);
 		return 0;
 	}
@@ -1372,7 +1372,7 @@ static int rk_udphy_usb3_phy_exit(struct phy *phy)
 	udphy->sw_mode &= ~UDPHY_MODE_USB;
 
 	/* DP only or high-speed */
-	if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs)
+	if (!(udphy->hw_mode & UDPHY_MODE_USB) || udphy->hs)
 		return 0;
 
 	rk_udphy_power_off(udphy, UDPHY_MODE_USB);

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 4/7] phy: rockchip: usbdp: Fix power state handling
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
                   ` (2 preceding siblings ...)
  2026-11-19 19:40 ` [PATCH v18 3/7] phy: rockchip: usbdp: Rename mode to hw_mode Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  2026-11-19 20:02   ` sashiko-bot
  2026-11-19 19:40 ` [PATCH v18 5/7] phy: rockchip: usbdp: Re-init PHY on mux change Sebastian Reichel
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel

Restructure power state handling, so that the function uses sw_mode and
hw_mode to figure out the actual required hardware state. This allows
any path updating either of those modes to simply call
rk_udphy_update_power_state() to get the right hardware state.

This makes it a lot more obvious what is going on and also fixes a few
potential resource leaks identified by Sashiko as a side-effect. For
example if USB3 is requested by software while the USB-C is in DP-only
mode, things are decently handled after this.

Exiting/power off the PHY will ignore errors from the power state
update. A full power down will never error out. If re-init fails,
the error should not be propagated to the PHY framework, because
it is effectively for the other PHY.

Tested-by: Igor Paunovic <royalnet026@gmail.com> # Orange Pi 5 Plus
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 128 +++++++++++++++++-------------
 1 file changed, 75 insertions(+), 53 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index de8f01bd0467..140bec887a5e 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -173,10 +173,10 @@ struct rk_udphy {
 
 	/* PHY status management */
 	bool flip;
-	bool phy_needs_reinit;
+	bool phy_needs_reinit; /* lane mux changed */
 	u8 hw_mode; /* modes currently supported by hardware */
-	u8 status;
 	u8 sw_mode; /* modes currently requested */
+	u8 status;
 
 	/* utilized for USB */
 	bool hs; /* flag for high-speed */
@@ -1029,70 +1029,93 @@ void rk_udphy_register_reset_handler(struct phy *phy,
 }
 EXPORT_SYMBOL_GPL(rk_udphy_register_reset_handler);
 
-static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
+static int rk_udphy_update_power_state(struct rk_udphy *udphy)
 {
+	bool usb3_port_enable;
+	u8 target_mode;
 	int ret;
 
-	if (!(udphy->hw_mode & mode)) {
-		dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
+	/*
+	 * Initialize PHY mode according to the hardware setup (either described
+	 * in DT or negotiated via the Type-C controller) instead of requesting
+	 * only the needed PHY side, because that would break the USB/DP data
+	 * streams when the other PHY is being requested. This is not an issue
+	 * during the Type-C negotiation as that happens during the hotplug phase
+	 * and not during normal operation. Also disable everything if the
+	 * software has not requested anything, as there shouldn't be any active
+	 * data streams in that case.
+	 */
+	target_mode = udphy->hw_mode;
+	if (udphy->sw_mode == UDPHY_MODE_NONE)
+		target_mode = UDPHY_MODE_NONE;
+
+	usb3_port_enable = !udphy->hs && (target_mode & UDPHY_MODE_USB);
+
+	if (!udphy->phy_needs_reinit && udphy->status == target_mode) {
+		if (udphy->sw_mode & UDPHY_MODE_USB)
+			rk_udphy_u3_port_disable(udphy, !usb3_port_enable);
 		return 0;
 	}
 
-	if (udphy->status == UDPHY_MODE_NONE) {
-		rk_udphy_run_reset_handler(udphy, true);
+	/* Avoid to re-init disabled PHY */
+	if (udphy->status == target_mode && target_mode == UDPHY_MODE_NONE)
+		return 0;
+
+	/*
+	 * Inform DWC3 driver, that we are about to reset the PHY, so that it can
+	 * assert its PIPE reset lines and avoid DWC3 getting into a buggy state.
+	 * This is intentionally done for a PHY disable, since that also changes
+	 * the clocks routed to the PHY.
+	 */
+	rk_udphy_run_reset_handler(udphy, true);
 
+	/*
+	 * Disable USB3 port, which among other things re-routes a DWC3 clock to
+	 * avoid SErrors when the DWC3 registers are accessed while the PHY is
+	 * disabled. This is only done, when the DWC3 is running as the accessed
+	 * GRF registers and in PD_USB.
+	 */
+	if (udphy->sw_mode & UDPHY_MODE_USB) {
 		rk_udphy_u3_port_disable(udphy, true);
 		udelay(10);
+	}
 
+	if (udphy->status == UDPHY_MODE_NONE) {
+		/* Power up (incl. clocks) */
 		ret = rk_udphy_setup(udphy);
 		if (ret) {
 			rk_udphy_run_reset_handler(udphy, false);
 			return ret;
 		}
-
-		if (!udphy->hs && udphy->hw_mode & UDPHY_MODE_USB)
-			rk_udphy_u3_port_disable(udphy, false);
-		udphy->phy_needs_reinit = false;
-
-		rk_udphy_run_reset_handler(udphy, false);
-	} else if (udphy->phy_needs_reinit) {
-		rk_udphy_run_reset_handler(udphy, true);
-
-		rk_udphy_u3_port_disable(udphy, true);
-		udelay(10);
-
+	} else if (target_mode == UDPHY_MODE_NONE) {
+		/* Power down (incl. clocks) */
+		rk_udphy_disable(udphy);
+	} else {
+		/* Mode change => re-init */
 		ret = rk_udphy_init(udphy);
 		if (ret) {
 			rk_udphy_run_reset_handler(udphy, false);
 			return ret;
 		}
-
-		if (!udphy->hs && udphy->hw_mode & UDPHY_MODE_USB)
-			rk_udphy_u3_port_disable(udphy, false);
-		udphy->phy_needs_reinit = false;
-
-		rk_udphy_run_reset_handler(udphy, false);
 	}
 
-	udphy->status |= mode;
-
-	return 0;
-}
-
-static void rk_udphy_power_off(struct rk_udphy *udphy, u8 mode)
-{
-	if (!(udphy->hw_mode & mode)) {
-		dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
-		return;
-	}
+	/* Ensure USB3 support is enabled when supported */
+	if (udphy->sw_mode & UDPHY_MODE_USB)
+		rk_udphy_u3_port_disable(udphy, !usb3_port_enable);
 
-	if (!udphy->status)
-		return;
+	/*
+	 * Inform DWC3, that we are done with the reset, so that it can deassert
+	 * its PIPE reset line. This is sent in pair with a PRE_RESET allowing
+	 * consumer driver to do paired resource requests (e.g. clocks) in their
+	 * notification handlers. As we reroute the clocks, its also fine to
+	 * send this after completely disabling the PHY.
+	 */
+	rk_udphy_run_reset_handler(udphy, false);
 
-	udphy->status &= ~mode;
+	udphy->status = target_mode;
+	udphy->phy_needs_reinit = false;
 
-	if (udphy->status == UDPHY_MODE_NONE)
-		rk_udphy_disable(udphy);
+	return 0;
 }
 
 static int rk_udphy_dp_phy_power_on(struct phy *phy)
@@ -1105,7 +1128,7 @@ static int rk_udphy_dp_phy_power_on(struct phy *phy)
 
 		phy_set_bus_width(phy, udphy->dp_lanes);
 
-		ret = rk_udphy_power_on(udphy, UDPHY_MODE_DP);
+		ret = rk_udphy_update_power_state(udphy);
 		if (ret) {
 			udphy->sw_mode &= ~UDPHY_MODE_DP;
 			return ret;
@@ -1135,7 +1158,7 @@ static int rk_udphy_dp_phy_power_off(struct phy *phy)
 	udphy->sw_mode &= ~UDPHY_MODE_DP;
 
 	rk_udphy_dp_lane_enable(udphy, 0);
-	rk_udphy_power_off(udphy, UDPHY_MODE_DP);
+	rk_udphy_update_power_state(udphy);
 
 	return 0;
 }
@@ -1346,15 +1369,15 @@ static int rk_udphy_usb3_phy_init(struct phy *phy)
 
 	guard(mutex)(&udphy->mutex);
 
-	udphy->sw_mode |= UDPHY_MODE_USB;
-
-	/* DP only or high-speed, disable U3 port */
-	if (!(udphy->hw_mode & UDPHY_MODE_USB) || udphy->hs) {
+	/* high-speed only, disable U3 port */
+	if (udphy->hs) {
 		rk_udphy_u3_port_disable(udphy, true);
 		return 0;
 	}
 
-	ret = rk_udphy_power_on(udphy, UDPHY_MODE_USB);
+	udphy->sw_mode |= UDPHY_MODE_USB;
+
+	ret = rk_udphy_update_power_state(udphy);
 	if (ret) {
 		udphy->sw_mode &= ~UDPHY_MODE_USB;
 		return ret;
@@ -1369,13 +1392,12 @@ static int rk_udphy_usb3_phy_exit(struct phy *phy)
 
 	guard(mutex)(&udphy->mutex);
 
-	udphy->sw_mode &= ~UDPHY_MODE_USB;
-
-	/* DP only or high-speed */
-	if (!(udphy->hw_mode & UDPHY_MODE_USB) || udphy->hs)
+	if (udphy->hs)
 		return 0;
 
-	rk_udphy_power_off(udphy, UDPHY_MODE_USB);
+	udphy->sw_mode &= ~UDPHY_MODE_USB;
+
+	rk_udphy_update_power_state(udphy);
 
 	return 0;
 }

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 5/7] phy: rockchip: usbdp: Re-init PHY on mux change
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
                   ` (3 preceding siblings ...)
  2026-11-19 19:40 ` [PATCH v18 4/7] phy: rockchip: usbdp: Fix power state handling Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  2026-11-19 19:54   ` sashiko-bot
  2026-11-19 19:40 ` [PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled Sebastian Reichel
  2026-11-19 19:40 ` [PATCH v18 7/7] phy: rockchip: usbdp: Add DP lane setup to power state update Sebastian Reichel
  6 siblings, 1 reply; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel

Ensure that the right part of the PHY are powered up when the
mode changes. This ensures the PHY is re-initialized in the
following two scenarios, which are currently broken:

 - cable orientation changes without DP being involved
 - switching from DP-only into a mode with USB support

Fixes: 2f70bbddeb45 ("phy: rockchip: add usbdp combo phy driver")
Tested-by: Igor Paunovic <royalnet026@gmail.com> # Orange Pi 5 Plus
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index 140bec887a5e..e4bbcb4edeae 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -1438,7 +1438,7 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux,
 
 	rk_udphy_set_typec_state(udphy, state->mode);
 
-	return 0;
+	return rk_udphy_update_power_state(udphy);
 }
 
 static void rk_udphy_typec_mux_unregister(void *data)

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
                   ` (4 preceding siblings ...)
  2026-11-19 19:40 ` [PATCH v18 5/7] phy: rockchip: usbdp: Re-init PHY on mux change Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  2026-11-19 20:02   ` sashiko-bot
  2026-11-19 19:40 ` [PATCH v18 7/7] phy: rockchip: usbdp: Add DP lane setup to power state update Sebastian Reichel
  6 siblings, 1 reply; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel

The driver currently only differs between 4 lanes DP mode or combined DP
+ USB3 mode. This makes sense from a lane routing point of view, as the
hardware only has 2 lanes of USB3.

But adding a separate state for USB-only helps with power management,
since we always power up all PHY parts according to the current hardware
setup to avoid data stream interruptions. Even if some lanes are muxed
to the DP controller there is no need to keep the DP side enabled if
something without DP AltMode is plugged into USB-C.

This potentially triggers some more USB reconnections during the PD
AltMode negotiation when switching from USB-only to combined USB+DP
mode. This should be fine, as the cable is freshly plugged at this
point.

Tested-by: Igor Paunovic <royalnet026@gmail.com> # Orange Pi 5 Plus
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 68 +++++++++++++++++++------------
 1 file changed, 42 insertions(+), 26 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index e4bbcb4edeae..e72752ed4968 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -583,32 +583,14 @@ static void rk_udphy_dp_lane_enable(struct rk_udphy *udphy, int dp_lanes)
 				   CMN_DP_CMN_RSTN, FIELD_PREP(CMN_DP_CMN_RSTN, 0x0));
 }
 
-static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 hw_mode)
+static void rk_udphy_set_lane_mux(struct rk_udphy *udphy)
 {
-	if (udphy->hw_mode == hw_mode)
-		return;
-
-	udphy->phy_needs_reinit = true;
-	udphy->hw_mode = hw_mode;
-}
-
-static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state)
-{
-	u8 hw_mode;
-
-	switch (state) {
-	case TYPEC_DP_STATE_C:
-	case TYPEC_DP_STATE_E:
+	if (udphy->dp_lanes == 4) {
 		udphy->lane_mux_sel[0] = PHY_LANE_MUX_DP;
 		udphy->lane_mux_sel[1] = PHY_LANE_MUX_DP;
 		udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
 		udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
-		hw_mode = UDPHY_MODE_DP;
-		udphy->dp_lanes = 4;
-		break;
-
-	case TYPEC_DP_STATE_D:
-	default:
+	} else {
 		if (udphy->flip) {
 			udphy->lane_mux_sel[0] = PHY_LANE_MUX_DP;
 			udphy->lane_mux_sel[1] = PHY_LANE_MUX_DP;
@@ -620,12 +602,39 @@ static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state
 			udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
 			udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
 		}
-		hw_mode = UDPHY_MODE_DP_USB;
-		udphy->dp_lanes = 2;
+	}
+}
+
+static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 hw_mode, u8 dp_lanes)
+{
+	if (udphy->hw_mode == hw_mode && udphy->dp_lanes == dp_lanes)
+		return;
+
+	udphy->phy_needs_reinit = true;
+	udphy->hw_mode = hw_mode;
+	udphy->dp_lanes = dp_lanes;
+}
+
+static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state)
+{
+	switch (state) {
+	case TYPEC_DP_STATE_C:
+	case TYPEC_DP_STATE_E:
+		rk_udphy_mode_set(udphy, UDPHY_MODE_DP, 4);
+		break;
+
+	case TYPEC_DP_STATE_D:
+		rk_udphy_mode_set(udphy, UDPHY_MODE_DP_USB, 2);
+		break;
+
+	case TYPEC_STATE_SAFE:
+	case TYPEC_STATE_USB:
+	default:
+		rk_udphy_mode_set(udphy, UDPHY_MODE_USB, 0);
 		break;
 	}
 
-	rk_udphy_mode_set(udphy, hw_mode);
+	rk_udphy_set_lane_mux(udphy);
 }
 
 static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy)
@@ -650,8 +659,15 @@ static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy)
 		gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 1);
 	}
 
-	/* default to USB3 + DP as 4 lane USB is not supported */
-	rk_udphy_set_typec_state(udphy, TYPEC_DP_STATE_D);
+	/*
+	 * default to safe mode (USB only) when mux is available to
+	 * avoid unnecessary mode changes; otherwise default to 2+2
+	 * mode, considering HW can effectively only do 2+2 or DP-only
+	 */
+	if (udphy->mux)
+		rk_udphy_set_typec_state(udphy, TYPEC_STATE_SAFE);
+	else
+		rk_udphy_set_typec_state(udphy, TYPEC_DP_STATE_D);
 }
 
 static int rk_udphy_orien_sw_set(struct typec_switch_dev *sw,

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* [PATCH v18 7/7] phy: rockchip: usbdp: Add DP lane setup to power state update
  2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
                   ` (5 preceding siblings ...)
  2026-11-19 19:40 ` [PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled Sebastian Reichel
@ 2026-11-19 19:40 ` Sebastian Reichel
  6 siblings, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2026-11-19 19:40 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Heiko Stuebner,
	Zhang Yubing, Frank Wang
  Cc: Igor Paunovic, Manivannan Sadhasivam, Alexey Charkov, Chaoyi Chen,
	linux-phy, linux-arm-kernel, linux-rockchip, linux-kernel, kernel,
	Sebastian Reichel, Yury Smirnov

DP lane map and AUX orientation are only configured in the DP PHY
power_on callback right now. This means when the DP controller keeps
the display enabled after a cable is unplugged, it will not come back
properly with the cable re-plugged in swapped orientation.

To fix the issue, we update the DP lane mux configuration in the power
state update. This gets some special handling, because calling
rk_udphy_dp_lane_select() accesses the VOGRF which needs the DP
controller's power domain enabled. It is active while the DP controller
has the PHY powered on.

Apart from that VOGRF may lose its state when the DP controller is
disabled, so we keep the DP PHY power hook as-is instead of fully
relying on the power state update function.

Reported-by: Yury Smirnov <yurymonzon@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-usbdp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index e72752ed4968..7a37b63ea51d 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -1115,6 +1115,13 @@ static int rk_udphy_update_power_state(struct rk_udphy *udphy)
 		}
 	}
 
+	/* Setup DP lanes and the AUX polarity */
+	if ((target_mode & UDPHY_MODE_DP) && (udphy->sw_mode & UDPHY_MODE_DP)) {
+		phy_set_bus_width(udphy->phy_dp, udphy->dp_lanes);
+		rk_udphy_dp_lane_enable(udphy, udphy->dp_lanes);
+		rk_udphy_dp_lane_select(udphy);
+	}
+
 	/* Ensure USB3 support is enabled when supported */
 	if (udphy->sw_mode & UDPHY_MODE_USB)
 		rk_udphy_u3_port_disable(udphy, !usb3_port_enable);

-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH v18 5/7] phy: rockchip: usbdp: Re-init PHY on mux change
  2026-11-19 19:40 ` [PATCH v18 5/7] phy: rockchip: usbdp: Re-init PHY on mux change Sebastian Reichel
@ 2026-11-19 19:54   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-19 19:54 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-phy, vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: rockchip: usbdp: missing PHY re-init in
  rk_udphy_orien_sw_set()
--

commit d39ec87ebe55de6d04fd645f2dc5add42612f593
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

phy: rockchip: usbdp: Re-init PHY on mux change

This commit calls rk_udphy_update_power_state() in rk_udphy_typec_mux_set()
to re-initialize the PHY when the Type-C mux state changes.

> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> index 140bec887a5ef..e4bbcb4edeae6 100644
> --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> @@ -1438,7 +1438,7 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux,
>  
>  	rk_udphy_set_typec_state(udphy, state->mode);
>  
> -	return 0;
> +	return rk_udphy_update_power_state(udphy);
>  }
>  
>  static void rk_udphy_typec_mux_unregister(void *data)

[Severity: Medium]
Should rk_udphy_orien_sw_set() also call rk_udphy_update_power_state()?

When cable orientation changes, rk_udphy_orien_sw_set() sets
udphy->phy_needs_reinit = true and updates udphy->lane_mux_sel and
udphy->hw_mode via rk_udphy_set_typec_default_mapping(), but returns 0
without re-initializing the PHY:

drivers/phy/rockchip/phy-rockchip-usbdp.c:rk_udphy_orien_sw_set() {
    ...
	if (udphy->flip != flipped) {
		dev_dbg(udphy->dev, "cable orientation changed, PHY re-init required.\n");
		udphy->phy_needs_reinit = true;
	}

	udphy->flip = flipped;
	rk_udphy_set_typec_default_mapping(udphy);
	rk_udphy_usb_bvalid_enable(udphy, true);

	return 0;
}

On boards that specify orientation-switch without mode-switch (such as
rk3588-jaguar.dts), or with Type-C controller drivers that do not call
typec_set_mode() after typec_set_orientation(), rk_udphy_typec_mux_set()
is not invoked after the orientation change and the PHY is never
re-initialized for the new lane mapping.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-b4-rockchip-usbdp-cleanup-part3-v18-0-fb325e336494@collabora.com?part=5

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH v18 4/7] phy: rockchip: usbdp: Fix power state handling
  2026-11-19 19:40 ` [PATCH v18 4/7] phy: rockchip: usbdp: Fix power state handling Sebastian Reichel
@ 2026-11-19 20:02   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-19 20:02 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-phy, vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] phy: rockchip: usbdp: skipped port disable in
  rk_udphy_usb3_phy_exit()
--

commit ba46047a3c1d57adb2502e31c9007c6898aa6365
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

phy: rockchip: usbdp: Fix power state handling

This commit replaces rk_udphy_power_on() and rk_udphy_power_off() with a
single rk_udphy_update_power_state() helper that derives the target PHY
state from udphy->hw_mode and udphy->sw_mode.

> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> index de8f01bd04672..140bec887a5ef 100644
> --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c

[ ... ]

> @@ -1029,70 +1029,93 @@ void rk_udphy_register_reset_handler(struct phy *phy,
>  }
>  EXPORT_SYMBOL_GPL(rk_udphy_register_reset_handler);
>  
> -static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
> +static int rk_udphy_update_power_state(struct rk_udphy *udphy)
>  {
> +	bool usb3_port_enable;
> +	u8 target_mode;
>  	int ret;
>  
> -	if (!(udphy->hw_mode & mode)) {
> -		dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
> +	/*
> +	 * Initialize PHY mode according to the hardware setup (either described
> +	 * in DT or negotiated via the Type-C controller) instead of requesting
> +	 * only the needed PHY side, because that would break the USB/DP data
> +	 * streams when the other PHY is being requested. This is not an issue
> +	 * during the Type-C negotiation as that happens during the hotplug phase
> +	 * and not during normal operation. Also disable everything if the
> +	 * software has not requested anything, as there shouldn't be any active
> +	 * data streams in that case.
> +	 */
> +	target_mode = udphy->hw_mode;
> +	if (udphy->sw_mode == UDPHY_MODE_NONE)
> +		target_mode = UDPHY_MODE_NONE;
> +
> +	usb3_port_enable = !udphy->hs && (target_mode & UDPHY_MODE_USB);
> +
> +	if (!udphy->phy_needs_reinit && udphy->status == target_mode) {
> +		if (udphy->sw_mode & UDPHY_MODE_USB)
> +			rk_udphy_u3_port_disable(udphy, !usb3_port_enable);
>  		return 0;
>  	}
>  
> -	if (udphy->status == UDPHY_MODE_NONE) {
> -		rk_udphy_run_reset_handler(udphy, true);
> +	/* Avoid to re-init disabled PHY */
> +	if (udphy->status == target_mode && target_mode == UDPHY_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Inform DWC3 driver, that we are about to reset the PHY, so that it can
> +	 * assert its PIPE reset lines and avoid DWC3 getting into a buggy state.
> +	 * This is intentionally done for a PHY disable, since that also changes
> +	 * the clocks routed to the PHY.
> +	 */
> +	rk_udphy_run_reset_handler(udphy, true);
>  
> +	/*
> +	 * Disable USB3 port, which among other things re-routes a DWC3 clock to
> +	 * avoid SErrors when the DWC3 registers are accessed while the PHY is
> +	 * disabled. This is only done, when the DWC3 is running as the accessed
> +	 * GRF registers and in PD_USB.
> +	 */
> +	if (udphy->sw_mode & UDPHY_MODE_USB) {
>  		rk_udphy_u3_port_disable(udphy, true);
>  		udelay(10);
> +	}
>  
> +	if (udphy->status == UDPHY_MODE_NONE) {
> +		/* Power up (incl. clocks) */
>  		ret = rk_udphy_setup(udphy);
>  		if (ret) {
>  			rk_udphy_run_reset_handler(udphy, false);
>  			return ret;
>  		}
> -
> -		if (!udphy->hs && udphy->hw_mode & UDPHY_MODE_USB)
> -			rk_udphy_u3_port_disable(udphy, false);
> -		udphy->phy_needs_reinit = false;
> -
> -		rk_udphy_run_reset_handler(udphy, false);
> -	} else if (udphy->phy_needs_reinit) {
> -		rk_udphy_run_reset_handler(udphy, true);
> -
> -		rk_udphy_u3_port_disable(udphy, true);
> -		udelay(10);
> -
> +	} else if (target_mode == UDPHY_MODE_NONE) {
> +		/* Power down (incl. clocks) */
> +		rk_udphy_disable(udphy);

[ ... ]

> @@ -1369,13 +1392,12 @@ static int rk_udphy_usb3_phy_exit(struct phy *phy)
>  
>  	guard(mutex)(&udphy->mutex);
>  
> -	udphy->sw_mode &= ~UDPHY_MODE_USB;
> -
> -	/* DP only or high-speed */
> -	if (!(udphy->hw_mode & UDPHY_MODE_USB) || udphy->hs)
> +	if (udphy->hs)
>  		return 0;
>  
> -	rk_udphy_power_off(udphy, UDPHY_MODE_USB);
> +	udphy->sw_mode &= ~UDPHY_MODE_USB;
> +
> +	rk_udphy_update_power_state(udphy);
>  
>  	return 0;
>  }

[Severity: High]
Does clearing UDPHY_MODE_USB from udphy->sw_mode before calling
rk_udphy_update_power_state() cause rk_udphy_run_reset_handler() and
rk_udphy_u3_port_disable(udphy, true) to be skipped on USB3 exit and PHY
disable?

Both rk_udphy_run_reset_handler() and the rk_udphy_u3_port_disable() calls
in rk_udphy_update_power_state() check udphy->sw_mode & UDPHY_MODE_USB.
Because UDPHY_MODE_USB is already cleared here (and target_mode ==
UDPHY_MODE_NONE is only reached when udphy->sw_mode == UDPHY_MODE_NONE),
those checks are always false when exiting the USB3 PHY or powering down
the PHY via rk_udphy_disable().  That leaves the USB3 port enabled in
usbgrf without notifying DWC3 or re-routing the DWC3 PIPE clock away from
the disabled PHY, which can trigger an SError when DWC3 registers are
accessed while the PHY is powered down.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-b4-rockchip-usbdp-cleanup-part3-v18-0-fb325e336494@collabora.com?part=4

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled
  2026-11-19 19:40 ` [PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled Sebastian Reichel
@ 2026-11-19 20:02   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-19 20:02 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-phy, vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: rockchip: usbdp: missing power state update in
  rk_udphy_orien_sw_set()
--

commit 8cfb31a083620f391bf963a14254a3d4d3b77ee1
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

phy: rockchip: usbdp: Add USB-C state without DP enabled

This commit adds a dedicated USB-only hardware mode for TYPEC_STATE_SAFE
and TYPEC_STATE_USB so that the DisplayPort side of the PHY is not kept
enabled when a USB-C device without DP AltMode is connected.

> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> index e4bbcb4edeae6..e72752ed49689 100644
> --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> @@ -583,32 +583,14 @@ static void rk_udphy_dp_lane_enable(struct rk_udphy *udphy, int dp_lanes)
>  				   CMN_DP_CMN_RSTN, FIELD_PREP(CMN_DP_CMN_RSTN, 0x0));
>  }
>  
> -static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 hw_mode)
> +static void rk_udphy_set_lane_mux(struct rk_udphy *udphy)
>  {
> -	if (udphy->hw_mode == hw_mode)
> -		return;
> -
> -	udphy->phy_needs_reinit = true;
> -	udphy->hw_mode = hw_mode;
> -}
> -
> -static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state)
> -{
> -	u8 hw_mode;
> -
> -	switch (state) {
> -	case TYPEC_DP_STATE_C:
> -	case TYPEC_DP_STATE_E:
> +	if (udphy->dp_lanes == 4) {
>  		udphy->lane_mux_sel[0] = PHY_LANE_MUX_DP;
>  		udphy->lane_mux_sel[1] = PHY_LANE_MUX_DP;
>  		udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
>  		udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
> -		hw_mode = UDPHY_MODE_DP;
> -		udphy->dp_lanes = 4;
> -		break;
> -
> -	case TYPEC_DP_STATE_D:
> -	default:
> +	} else {
>  		if (udphy->flip) {
>  			udphy->lane_mux_sel[0] = PHY_LANE_MUX_DP;
>  			udphy->lane_mux_sel[1] = PHY_LANE_MUX_DP;
> @@ -620,12 +602,39 @@ static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state
>  			udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
>  			udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
>  		}
> -		hw_mode = UDPHY_MODE_DP_USB;
> -		udphy->dp_lanes = 2;
> +	}
> +}
> +
> +static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 hw_mode, u8 dp_lanes)
> +{
> +	if (udphy->hw_mode == hw_mode && udphy->dp_lanes == dp_lanes)
> +		return;
> +
> +	udphy->phy_needs_reinit = true;
> +	udphy->hw_mode = hw_mode;
> +	udphy->dp_lanes = dp_lanes;
> +}
> +
> +static void rk_udphy_set_typec_state(struct rk_udphy *udphy, unsigned long state)
> +{
> +	switch (state) {
> +	case TYPEC_DP_STATE_C:
> +	case TYPEC_DP_STATE_E:
> +		rk_udphy_mode_set(udphy, UDPHY_MODE_DP, 4);
> +		break;
> +
> +	case TYPEC_DP_STATE_D:
> +		rk_udphy_mode_set(udphy, UDPHY_MODE_DP_USB, 2);
> +		break;
> +
> +	case TYPEC_STATE_SAFE:
> +	case TYPEC_STATE_USB:
> +	default:
> +		rk_udphy_mode_set(udphy, UDPHY_MODE_USB, 0);
>  		break;
>  	}
>  
> -	rk_udphy_mode_set(udphy, hw_mode);
> +	rk_udphy_set_lane_mux(udphy);
>  }
>  
>  static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy)
> @@ -650,8 +659,15 @@ static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy)
>  		gpiod_set_value_cansleep(udphy->sbu2_dc_gpio, 1);
>  	}
>  
> -	/* default to USB3 + DP as 4 lane USB is not supported */
> -	rk_udphy_set_typec_state(udphy, TYPEC_DP_STATE_D);
> +	/*
> +	 * default to safe mode (USB only) when mux is available to
> +	 * avoid unnecessary mode changes; otherwise default to 2+2
> +	 * mode, considering HW can effectively only do 2+2 or DP-only
> +	 */
> +	if (udphy->mux)
> +		rk_udphy_set_typec_state(udphy, TYPEC_STATE_SAFE);
> +	else
> +		rk_udphy_set_typec_state(udphy, TYPEC_DP_STATE_D);
>  }

[Severity: Medium]
Does rk_udphy_orien_sw_set() need to call rk_udphy_update_power_state()
after rk_udphy_set_typec_default_mapping()?

When udphy->mux is NULL (the else branch above, on boards with an
orientation-switch but no mode-switch), rk_udphy_typec_mux_set() is never
called after rk_udphy_orien_sw_set():

drivers/phy/rockchip/phy-rockchip-usbdp.c:rk_udphy_orien_sw_set() {
    ...
	if (udphy->flip != flipped) {
		dev_dbg(udphy->dev, "cable orientation changed, PHY re-init required.\n");
		udphy->phy_needs_reinit = true;
	}

	udphy->flip = flipped;
	rk_udphy_set_typec_default_mapping(udphy);
	rk_udphy_usb_bvalid_enable(udphy, true);

	return 0;
}

Because dwc3 initializes phy_u3 at probe time and keeps it powered across
cable plug events, setting udphy->flip, udphy->hw_mode, udphy->dp_lanes
and udphy->phy_needs_reinit without calling rk_udphy_update_power_state()
leaves the PHY hardware unprogrammed for the new orientation and
TYPEC_DP_STATE_D mode, breaking USB3 on flipped cables and leaving DP
disabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-b4-rockchip-usbdp-cleanup-part3-v18-0-fb325e336494@collabora.com?part=6

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

end of thread, other threads:[~2026-11-19 20:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:40 [PATCH v18 0/7] phy: rockchip: usbdp: Fix runtime muxing between USB3 and DP Sebastian Reichel
2026-11-19 19:40 ` [PATCH v18 1/7] phy: rockchip: usbdp: Disable USB3 port during normal power-on Sebastian Reichel
2026-11-19 19:40 ` [PATCH v18 2/7] phy: rockchip: usbdp: Drop -EPROBE_DEFER hack Sebastian Reichel
2026-11-19 19:40 ` [PATCH v18 3/7] phy: rockchip: usbdp: Rename mode to hw_mode Sebastian Reichel
2026-11-19 19:40 ` [PATCH v18 4/7] phy: rockchip: usbdp: Fix power state handling Sebastian Reichel
2026-11-19 20:02   ` sashiko-bot
2026-11-19 19:40 ` [PATCH v18 5/7] phy: rockchip: usbdp: Re-init PHY on mux change Sebastian Reichel
2026-11-19 19:54   ` sashiko-bot
2026-11-19 19:40 ` [PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled Sebastian Reichel
2026-11-19 20:02   ` sashiko-bot
2026-11-19 19:40 ` [PATCH v18 7/7] phy: rockchip: usbdp: Add DP lane setup to power state update Sebastian Reichel

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