Skip to contentSkip to conversation

phy: rockchip: usbdp: Check these parameters only when the corresponding set flags are set

PATCH In review Andy Yan 2 participants 5 messages Mar 6, 2025 – Mar 11, 2025

Subsystems (2)
lore
Share & tools
lore

Andy Yan

author
#0 lore raw

PATCH 1/1 phy: rockchip: usbdp: Check these parameters only when the corresponding set flags are set

From: Andy Yan <[email protected]>

According documentation of phy_configure_opts_dp, at the configure stage, we should only verify/configure the link_rate when set_rate flag is set, the same applies to lanes and voltage.

So we do it as the documentation says, also record the link rate and lanes in phy internal for set_voltate stage.

---

 drivers/phy/rockchip/phy-rockchip-usbdp.c | 63 +++++++++++------------
 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +31 -32
index c04cf64f8a35..d1bbdf382aa2 100644
@@ -187,6 +187,8 @@ struct rk_udphy {
 	u32 dp_aux_din_sel;
 	bool dp_sink_hpd_sel;
 	bool dp_sink_hpd_cfg;
+	unsigned int link_rate;
+	unsigned int lanes;
 	u8 bw;
 	int id;
 
@@ -1102,42 +1104,39 @@ static int rk_udphy_dp_phy_power_off(struct phy *phy)
 	return 0;
 }
 
-static int rk_udphy_dp_phy_verify_link_rate(unsigned int link_rate)
-{
-	switch (link_rate) {
-	case 1620:
-	case 2700:
-	case 5400:
-	case 8100:
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy,
 					 struct phy_configure_opts_dp *dp)
 {
-	int i, ret;
+	int i;
 
-	/* If changing link rate was required, verify it's supported. */
-	ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate);
-	if (ret)
-		return ret;
+	/* Verify link rate. */
+	if (dp->set_rate) {
+		switch (dp->link_rate) {
+		case 1620:
+		case 2700:
+		case 5400:
+		case 8100:
+			udphy->link_rate = dp->link_rate;
+			break;
+
+		default:
+			return -EINVAL;
+		}
+	}
 
 	/* Verify lane count. */
-	switch (dp->lanes) {
-	case 1:
-	case 2:
-	case 4:
-		/* valid lane count. */
-		break;
+	if (dp->set_lanes) {
+		switch (dp->lanes) {
+		case 1:
+		case 2:
+		case 4:
+			/* valid lane count. */
+			udphy->lanes = dp->lanes;
+			break;
 
-	default:
-		return -EINVAL;
+		default:
+			return -EINVAL;
+		}
 	}
 
 	/*
@@ -1146,7 +1145,7 @@ static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy,
 	 */
 	if (dp->set_voltages) {
 		/* Lane count verified previously. */
-		for (i = 0; i < dp->lanes; i++) {
+		for (i = 0; i < udphy->lanes; i++) {
 			if (dp->voltage[i] > 3 || dp->pre[i] > 3)
 				return -EINVAL;
 
@@ -1243,9 +1242,9 @@ static int rk_udphy_dp_phy_configure(struct phy *phy,
 	}
 
 	if (dp->set_voltages) {
-		for (i = 0; i < dp->lanes; i++) {
+		for (i = 0; i < udphy->lanes; i++) {
 			lane = udphy->dp_lane_sel[i];
-			switch (dp->link_rate) {
+			switch (udphy->link_rate) {
 			case 1620:
 			case 2700:
 				regmap_update_bits(udphy->pma_regmap,
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · Andy Yan

From: Andy Yan <[email protected]>

According documentation of phy_configure_opts_dp, at the configure stage, we should only verify/configure the link_rate when set_rate flag is set, the same applies to lanes and voltage.

So we do it as the documentation says, also record the link rate and lanes in phy internal for set_voltate stage.

Whenever you say also, that is a sign that it should be another patch!

Quoted 53 lines

---

 drivers/phy/rockchip/phy-rockchip-usbdp.c | 63 +++++++++++------------
 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +6 -21
index c04cf64f8a35..d1bbdf382aa2 100644
@@ -187,6 +187,8 @@ struct rk_udphy {
 	u32 dp_aux_din_sel;
 	bool dp_sink_hpd_sel;
 	bool dp_sink_hpd_cfg;
+	unsigned int link_rate;
+	unsigned int lanes;
 	u8 bw;
 	int id;
 
@@ -1102,42 +1104,39 @@ static int rk_udphy_dp_phy_power_off(struct phy *phy)
 	return 0;
 }
 
-static int rk_udphy_dp_phy_verify_link_rate(unsigned int link_rate)
-{
-	switch (link_rate) {
-	case 1620:
-	case 2700:
-	case 5400:
-	case 8100:
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy,
 					 struct phy_configure_opts_dp *dp)
 {
-	int i, ret;
+	int i;
 
-	/* If changing link rate was required, verify it's supported. */
-	ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate);
-	if (ret)
-		return ret;
+	/* Verify link rate. */
+	if (dp->set_rate) {
+		switch (dp->link_rate) {

drivers/phy/rockchip/phy-rockchip-usbdp.c static int rk_udphy_dp_phy_power_off(struct phy *phy) · line 1124

Quoted 10 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +10 -0
+		case 1620:
+		case 2700:
+		case 5400:
+		case 8100:
+			udphy->link_rate = dp->link_rate;
+			break;
+
+		default:
+			return -EINVAL;
+		}

why drop helper? Why not set the rate on success?

Quoted 13 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +5 -6
+	}
 
 	/* Verify lane count. */
-	switch (dp->lanes) {
-	case 1:
-	case 2:
-	case 4:
-		/* valid lane count. */
-		break;
+	if (dp->set_lanes) {
+		switch (dp->lanes) {
+		case 1:
+		case 2:

drivers/phy/rockchip/phy-rockchip-usbdp.c static int rk_udphy_dp_phy_power_off(struct phy *phy) · line 1139

Quoted 10 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +7 -2
+		case 4:
+			/* valid lane count. */
+			udphy->lanes = dp->lanes;
+			break;
 
-	default:
-		return -EINVAL;
+		default:
+			return -EINVAL;
+		}

another change where helper would have made this look better

Quoted 26 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +3 -3
 	}
 
 	/*
@@ -1146,7 +1145,7 @@ static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy,
 	 */
 	if (dp->set_voltages) {
 		/* Lane count verified previously. */
-		for (i = 0; i < dp->lanes; i++) {
+		for (i = 0; i < udphy->lanes; i++) {
 			if (dp->voltage[i] > 3 || dp->pre[i] > 3)
 				return -EINVAL;
 
@@ -1243,9 +1242,9 @@ static int rk_udphy_dp_phy_configure(struct phy *phy,
 	}
 
 	if (dp->set_voltages) {
-		for (i = 0; i < dp->lanes; i++) {
+		for (i = 0; i < udphy->lanes; i++) {
 			lane = udphy->dp_lane_sel[i];
-			switch (dp->link_rate) {
+			switch (udphy->link_rate) {
 			case 1620:
 			case 2700:
 				regmap_update_bits(udphy->pma_regmap,
Signature · 1 line
2.34.1
Signature · 1 line
~Vinod
author
#2 lore raw

Hi Vinod,

Quoted 11 lines · Vinod Koul
Quoted 8 lines · Andy Yan

From: Andy Yan <[email protected]>

According documentation of phy_configure_opts_dp, at the configure stage, we should only verify/configure the link_rate when set_rate flag is set, the same applies to lanes and voltage.

So we do it as the documentation says, also record the link rate and lanes in phy internal for set_voltate stage.

Whenever you say also, that is a sign that it should be another patch!

This patch is inspired by Dmitry's suggestion for DP/eDP driver which calls phy_configure[0][1]:
the phy driver should skip the values for which the .set_foo isn't set. So we should not set rates and lanes when we set_voltate, but the rates and lanes are needed for voltage set, this is why I record rates and lanes in this patch.
I can split the record to another patch, but then this patch will not work correctly itself, I'm not sure if this is suitable.

[0]https://patchwork.freedesktop.org/patch/629780/?series=141829&rev=3 [1]https://patchwork.freedesktop.org/patch/638961/?series=145286&rev=1

Quoted 58 lines
Quoted 58 lines

---

 drivers/phy/rockchip/phy-rockchip-usbdp.c | 63 +++++++++++------------
 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +10 -21
index c04cf64f8a35..d1bbdf382aa2 100644
@@ -187,6 +187,8 @@ struct rk_udphy {
 	u32 dp_aux_din_sel;
 	bool dp_sink_hpd_sel;
 	bool dp_sink_hpd_cfg;
+	unsigned int link_rate;
+	unsigned int lanes;
 	u8 bw;
 	int id;
 
@@ -1102,42 +1104,39 @@ static int rk_udphy_dp_phy_power_off(struct phy *phy)
 	return 0;
 }
 
-static int rk_udphy_dp_phy_verify_link_rate(unsigned int link_rate)
-{
-	switch (link_rate) {
-	case 1620:
-	case 2700:
-	case 5400:
-	case 8100:
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy,
 					 struct phy_configure_opts_dp *dp)
 {
-	int i, ret;
+	int i;
 
-	/* If changing link rate was required, verify it's supported. */
-	ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate);
-	if (ret)
-		return ret;
+	/* Verify link rate. */
+	if (dp->set_rate) {
+		switch (dp->link_rate) {
+		case 1620:
+		case 2700:
+		case 5400:
+		case 8100:
Quoted 8 lines

drivers/phy/rockchip/phy-rockchip-usbdp.c static int rk_udphy_dp_phy_power_off(struct phy *phy) · line 1124

Quoted 6 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +6 -0
+			udphy->link_rate = dp->link_rate;
+			break;
+
+		default:
+			return -EINVAL;
+		}

why drop helper? Why not set the rate on success?

I drop helper just because the flowing check for lanes and votages don't have helper.
The rate is set in rk_udphy_dp_phy_configure.

Quoted 19 lines
Quoted 19 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +9 -6
+	}
 
 	/* Verify lane count. */
-	switch (dp->lanes) {
-	case 1:
-	case 2:
-	case 4:
-		/* valid lane count. */
-		break;
+	if (dp->set_lanes) {
+		switch (dp->lanes) {
+		case 1:
+		case 2:
+		case 4:
+			/* valid lane count. */
+			udphy->lanes = dp->lanes;
+			break;
 
Quoted 7 lines

drivers/phy/rockchip/phy-rockchip-usbdp.c static int rk_udphy_dp_phy_power_off(struct phy *phy) · line 1124

Quoted 5 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +3 -2
-	default:
-		return -EINVAL;
+		default:
+			return -EINVAL;
+		}

another change where helper would have made this look better

Do you mean we should do it like this:

static int rk_udphy_dp_phy_configure(struct phy *phy,
union phy_configure_opts *opts)

{
        struct rk_udphy *udphy = phy_get_drvdata(phy);
        struct phy_configure_opts_dp *dp = &opts->dp;
        u32 i, val, lane;
        int ret;

       .............
      if (dp->set_rate)
           	ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate);
     if (dp->set_lanes)
                ret = rk_udphy_dp_phy_verify_link_lanes(dp->lanes);
     if (dp->set_voltates)
               ret = rk_udphy_dp_phy_verify_link_voltate(dp->voltate);

Add helper for each of them ?

Quoted 35 lines
Quoted 27 lines
drivers/phy/rockchip/phy-rockchip-usbdp.c +3 -3
 	}
 
 	/*
@@ -1146,7 +1145,7 @@ static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy,
 	 */
 	if (dp->set_voltages) {
 		/* Lane count verified previously. */
-		for (i = 0; i < dp->lanes; i++) {
+		for (i = 0; i < udphy->lanes; i++) {
 			if (dp->voltage[i] > 3 || dp->pre[i] > 3)
 				return -EINVAL;
 
@@ -1243,9 +1242,9 @@ static int rk_udphy_dp_phy_configure(struct phy *phy,
 	}
 
 	if (dp->set_voltages) {
-		for (i = 0; i < dp->lanes; i++) {
+		for (i = 0; i < udphy->lanes; i++) {
 			lane = udphy->dp_lane_sel[i];
-			switch (dp->link_rate) {
+			switch (udphy->link_rate) {
 			case 1620:
 			case 2700:
 				regmap_update_bits(udphy->pma_regmap,
Signature · 1 line
2.34.1
Signature · 6 lines
~Vinod

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
maintainer
#3 lore raw
Quoted 19 lines · Andy Yan

Do you mean we should do it like this:

static int rk_udphy_dp_phy_configure(struct phy *phy,
union phy_configure_opts *opts)

{
        struct rk_udphy *udphy = phy_get_drvdata(phy);
        struct phy_configure_opts_dp *dp = &opts->dp;
        u32 i, val, lane;
        int ret;

       .............
      if (dp->set_rate)
           	ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate);
     if (dp->set_lanes)
                ret = rk_udphy_dp_phy_verify_link_lanes(dp->lanes);
     if (dp->set_voltates)
               ret = rk_udphy_dp_phy_verify_link_voltate(dp->voltate);
Quoted 1 line

Add helper for each of them ?

That would look better for sure

Signature · 1 line
~Vinod
author
#4 lore raw

Hi Vinod,

Quoted 21 lines · Vinod Koul
Quoted 19 lines · Andy Yan

Do you mean we should do it like this:

static int rk_udphy_dp_phy_configure(struct phy *phy,
union phy_configure_opts *opts)

{
        struct rk_udphy *udphy = phy_get_drvdata(phy);
        struct phy_configure_opts_dp *dp = &opts->dp;
        u32 i, val, lane;
        int ret;

       .............
      if (dp->set_rate)
           	ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate);
     if (dp->set_lanes)
                ret = rk_udphy_dp_phy_verify_link_lanes(dp->lanes);
     if (dp->set_voltates)
               ret = rk_udphy_dp_phy_verify_link_voltate(dp->voltate);
Quoted 3 lines
Quoted 1 line

Add helper for each of them ?

That would look better for sure

I will do as that in V2.

Thanks

Quoted 3 lines
Signature · 2 lines
-- 
~Vinod