[PATCH v18 6/7] phy: rockchip: usbdp: Add USB-C state without DP enabled

sashiko-bot at kernel.org sashiko-bot at kernel.org
Thu Nov 19 12:02:41 PST 2026


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 at 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



More information about the linux-phy mailing list