Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: rockchip: usbdp: Only verify link rates/lanes/voltage when the corresponding set flags are set

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

So do it as the documentation says.
Because voltage setting depends on the lanes, link rates set
previously, so record the link rates and lanes at it's verify stage.

Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
Link: https://lore.kernel.org/r/20250312080041.524546-1-andyshrk@163.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Andy Yan and committed by
Vinod Koul
969a38be ebf198f1

+62 -43
+62 -43
drivers/phy/rockchip/phy-rockchip-usbdp.c
··· 187 187 u32 dp_aux_din_sel; 188 188 bool dp_sink_hpd_sel; 189 189 bool dp_sink_hpd_cfg; 190 + unsigned int link_rate; 191 + unsigned int lanes; 190 192 u8 bw; 191 193 int id; 192 194 ··· 1105 1103 return 0; 1106 1104 } 1107 1105 1108 - static int rk_udphy_dp_phy_verify_link_rate(unsigned int link_rate) 1106 + /* 1107 + * Verify link rate 1108 + */ 1109 + static int rk_udphy_dp_phy_verify_link_rate(struct rk_udphy *udphy, 1110 + struct phy_configure_opts_dp *dp) 1109 1111 { 1110 - switch (link_rate) { 1112 + switch (dp->link_rate) { 1111 1113 case 1620: 1112 1114 case 2700: 1113 1115 case 5400: 1114 1116 case 8100: 1117 + udphy->link_rate = dp->link_rate; 1118 + break; 1119 + default: 1120 + return -EINVAL; 1121 + } 1122 + 1123 + return 0; 1124 + } 1125 + 1126 + static int rk_udphy_dp_phy_verify_lanes(struct rk_udphy *udphy, 1127 + struct phy_configure_opts_dp *dp) 1128 + { 1129 + switch (dp->lanes) { 1130 + case 1: 1131 + case 2: 1132 + case 4: 1133 + /* valid lane count. */ 1134 + udphy->lanes = dp->lanes; 1115 1135 break; 1116 1136 1117 1137 default: ··· 1143 1119 return 0; 1144 1120 } 1145 1121 1146 - static int rk_udphy_dp_phy_verify_config(struct rk_udphy *udphy, 1147 - struct phy_configure_opts_dp *dp) 1122 + /* 1123 + * If changing voltages is required, check swing and pre-emphasis 1124 + * levels, per-lane. 1125 + */ 1126 + static int rk_udphy_dp_phy_verify_voltages(struct rk_udphy *udphy, 1127 + struct phy_configure_opts_dp *dp) 1148 1128 { 1149 - int i, ret; 1129 + int i; 1150 1130 1151 - /* If changing link rate was required, verify it's supported. */ 1152 - ret = rk_udphy_dp_phy_verify_link_rate(dp->link_rate); 1153 - if (ret) 1154 - return ret; 1131 + /* Lane count verified previously. */ 1132 + for (i = 0; i < udphy->lanes; i++) { 1133 + if (dp->voltage[i] > 3 || dp->pre[i] > 3) 1134 + return -EINVAL; 1155 1135 1156 - /* Verify lane count. */ 1157 - switch (dp->lanes) { 1158 - case 1: 1159 - case 2: 1160 - case 4: 1161 - /* valid lane count. */ 1162 - break; 1163 - 1164 - default: 1165 - return -EINVAL; 1166 - } 1167 - 1168 - /* 1169 - * If changing voltages is required, check swing and pre-emphasis 1170 - * levels, per-lane. 1171 - */ 1172 - if (dp->set_voltages) { 1173 - /* Lane count verified previously. */ 1174 - for (i = 0; i < dp->lanes; i++) { 1175 - if (dp->voltage[i] > 3 || dp->pre[i] > 3) 1176 - return -EINVAL; 1177 - 1178 - /* 1179 - * Sum of voltage swing and pre-emphasis levels cannot 1180 - * exceed 3. 1181 - */ 1182 - if (dp->voltage[i] + dp->pre[i] > 3) 1183 - return -EINVAL; 1184 - } 1136 + /* 1137 + * Sum of voltage swing and pre-emphasis levels cannot 1138 + * exceed 3. 1139 + */ 1140 + if (dp->voltage[i] + dp->pre[i] > 3) 1141 + return -EINVAL; 1185 1142 } 1186 1143 1187 1144 return 0; ··· 1202 1197 u32 i, val, lane; 1203 1198 int ret; 1204 1199 1205 - ret = rk_udphy_dp_phy_verify_config(udphy, dp); 1206 - if (ret) 1207 - return ret; 1200 + if (dp->set_rate) { 1201 + ret = rk_udphy_dp_phy_verify_link_rate(udphy, dp); 1202 + if (ret) 1203 + return ret; 1204 + } 1205 + 1206 + if (dp->set_lanes) { 1207 + ret = rk_udphy_dp_phy_verify_lanes(udphy, dp); 1208 + if (ret) 1209 + return ret; 1210 + } 1211 + 1212 + if (dp->set_voltages) { 1213 + ret = rk_udphy_dp_phy_verify_voltages(udphy, dp); 1214 + if (ret) 1215 + return ret; 1216 + } 1208 1217 1209 1218 if (dp->set_rate) { 1210 1219 regmap_update_bits(udphy->pma_regmap, CMN_DP_RSTN_OFFSET, ··· 1263 1244 } 1264 1245 1265 1246 if (dp->set_voltages) { 1266 - for (i = 0; i < dp->lanes; i++) { 1247 + for (i = 0; i < udphy->lanes; i++) { 1267 1248 lane = udphy->dp_lane_sel[i]; 1268 - switch (dp->link_rate) { 1249 + switch (udphy->link_rate) { 1269 1250 case 1620: 1270 1251 case 2700: 1271 1252 regmap_update_bits(udphy->pma_regmap,