| .. | .. |
|---|
| 14 | 14 | static void cdn_dp_set_signal_levels(struct cdn_dp_device *dp) |
|---|
| 15 | 15 | { |
|---|
| 16 | 16 | struct cdn_dp_port *port = dp->port[dp->active_port]; |
|---|
| 17 | | - int rate = drm_dp_bw_code_to_link_rate(dp->link.rate); |
|---|
| 17 | + union phy_configure_opts phy_cfg = {0}; |
|---|
| 18 | 18 | u8 swing = (dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) >> |
|---|
| 19 | 19 | DP_TRAIN_VOLTAGE_SWING_SHIFT; |
|---|
| 20 | 20 | u8 pre_emphasis = (dp->train_set[0] & DP_TRAIN_PRE_EMPHASIS_MASK) |
|---|
| 21 | 21 | >> DP_TRAIN_PRE_EMPHASIS_SHIFT; |
|---|
| 22 | + unsigned int lane; |
|---|
| 22 | 23 | |
|---|
| 23 | | - tcphy_dp_set_phy_config(port->phy, rate, dp->link.num_lanes, |
|---|
| 24 | | - swing, pre_emphasis); |
|---|
| 24 | + for (lane = 0; lane < dp->max_lanes; lane++) { |
|---|
| 25 | + phy_cfg.dp.voltage[lane] = swing; |
|---|
| 26 | + phy_cfg.dp.pre[lane] = pre_emphasis; |
|---|
| 27 | + } |
|---|
| 28 | + |
|---|
| 29 | + phy_cfg.dp.lanes = dp->max_lanes; |
|---|
| 30 | + phy_cfg.dp.link_rate = drm_dp_bw_code_to_link_rate(dp->max_rate) / 100; |
|---|
| 31 | + phy_cfg.dp.set_lanes = false; |
|---|
| 32 | + phy_cfg.dp.set_rate = false; |
|---|
| 33 | + phy_cfg.dp.set_voltages = true; |
|---|
| 34 | + phy_configure(port->phy, &phy_cfg); |
|---|
| 25 | 35 | } |
|---|
| 26 | 36 | |
|---|
| 27 | 37 | static int cdn_dp_set_pattern(struct cdn_dp_device *dp, uint8_t dp_train_pat) |
|---|
| .. | .. |
|---|
| 30 | 40 | int ret; |
|---|
| 31 | 41 | uint8_t pattern = dp_train_pat & DP_TRAINING_PATTERN_MASK; |
|---|
| 32 | 42 | |
|---|
| 33 | | - global_config = NUM_LANES(dp->link.num_lanes - 1) | SST_MODE | |
|---|
| 43 | + global_config = NUM_LANES(dp->max_lanes - 1) | SST_MODE | |
|---|
| 34 | 44 | GLOBAL_EN | RG_EN | ENC_RST_DIS | WR_VHSYNC_FALL; |
|---|
| 35 | 45 | |
|---|
| 36 | 46 | phy_config = DP_TX_PHY_ENCODER_BYPASS(0) | |
|---|
| .. | .. |
|---|
| 63 | 73 | return ret; |
|---|
| 64 | 74 | } |
|---|
| 65 | 75 | |
|---|
| 66 | | - ret = cdn_dp_reg_write(dp, DPTX_LANE_EN, BIT(dp->link.num_lanes) - 1); |
|---|
| 76 | + ret = cdn_dp_reg_write(dp, DPTX_LANE_EN, BIT(dp->max_lanes) - 1); |
|---|
| 67 | 77 | if (ret) { |
|---|
| 68 | 78 | DRM_ERROR("fail to set DPTX_LANE_EN, error: %d\n", ret); |
|---|
| 69 | 79 | return ret; |
|---|
| .. | .. |
|---|
| 106 | 116 | uint8_t v = 0, p = 0; |
|---|
| 107 | 117 | uint8_t preemph_max; |
|---|
| 108 | 118 | |
|---|
| 109 | | - for (i = 0; i < dp->link.num_lanes; i++) { |
|---|
| 119 | + for (i = 0; i < dp->max_lanes; i++) { |
|---|
| 110 | 120 | v = max(v, drm_dp_get_adjust_request_voltage(link_status, i)); |
|---|
| 111 | 121 | p = max(p, drm_dp_get_adjust_request_pre_emphasis(link_status, |
|---|
| 112 | 122 | i)); |
|---|
| .. | .. |
|---|
| 119 | 129 | if (p >= preemph_max) |
|---|
| 120 | 130 | p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED; |
|---|
| 121 | 131 | |
|---|
| 122 | | - for (i = 0; i < dp->link.num_lanes; i++) |
|---|
| 132 | + for (i = 0; i < dp->max_lanes; i++) |
|---|
| 123 | 133 | dp->train_set[i] = v | p; |
|---|
| 124 | 134 | } |
|---|
| 125 | 135 | |
|---|
| .. | .. |
|---|
| 149 | 159 | { |
|---|
| 150 | 160 | int lane; |
|---|
| 151 | 161 | |
|---|
| 152 | | - for (lane = 0; lane < dp->link.num_lanes; lane++) |
|---|
| 162 | + for (lane = 0; lane < dp->max_lanes; lane++) |
|---|
| 153 | 163 | if ((dp->train_set[lane] & DP_TRAIN_MAX_SWING_REACHED) == 0) |
|---|
| 154 | 164 | return false; |
|---|
| 155 | 165 | |
|---|
| .. | .. |
|---|
| 163 | 173 | cdn_dp_set_signal_levels(dp); |
|---|
| 164 | 174 | |
|---|
| 165 | 175 | ret = drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, |
|---|
| 166 | | - dp->train_set, dp->link.num_lanes); |
|---|
| 167 | | - if (ret != dp->link.num_lanes) |
|---|
| 176 | + dp->train_set, dp->max_lanes); |
|---|
| 177 | + if (ret != dp->max_lanes) |
|---|
| 168 | 178 | return -EINVAL; |
|---|
| 169 | 179 | |
|---|
| 170 | 180 | return 0; |
|---|
| .. | .. |
|---|
| 183 | 193 | len = 1; |
|---|
| 184 | 194 | } else { |
|---|
| 185 | 195 | /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */ |
|---|
| 186 | | - memcpy(buf + 1, dp->train_set, dp->link.num_lanes); |
|---|
| 187 | | - len = dp->link.num_lanes + 1; |
|---|
| 196 | + memcpy(buf + 1, dp->train_set, dp->max_lanes); |
|---|
| 197 | + len = dp->max_lanes + 1; |
|---|
| 188 | 198 | } |
|---|
| 189 | 199 | |
|---|
| 190 | 200 | ret = drm_dp_dpcd_write(&dp->aux, DP_TRAINING_PATTERN_SET, |
|---|
| .. | .. |
|---|
| 237 | 247 | return -EINVAL; |
|---|
| 238 | 248 | } |
|---|
| 239 | 249 | |
|---|
| 240 | | - if (drm_dp_clock_recovery_ok(link_status, dp->link.num_lanes)) { |
|---|
| 250 | + if (drm_dp_clock_recovery_ok(link_status, dp->max_lanes)) { |
|---|
| 241 | 251 | DRM_DEBUG_KMS("clock recovery OK\n"); |
|---|
| 242 | 252 | return 0; |
|---|
| 243 | 253 | } |
|---|
| .. | .. |
|---|
| 301 | 311 | |
|---|
| 302 | 312 | /* Make sure clock is still ok */ |
|---|
| 303 | 313 | if (!drm_dp_clock_recovery_ok(link_status, |
|---|
| 304 | | - dp->link.num_lanes)) { |
|---|
| 314 | + dp->max_lanes)) { |
|---|
| 305 | 315 | DRM_DEBUG_KMS("Clock recovery check failed\n"); |
|---|
| 306 | 316 | break; |
|---|
| 307 | 317 | } |
|---|
| 308 | 318 | |
|---|
| 309 | | - if (drm_dp_channel_eq_ok(link_status, dp->link.num_lanes)) { |
|---|
| 319 | + if (drm_dp_channel_eq_ok(link_status, dp->max_lanes)) { |
|---|
| 310 | 320 | DRM_DEBUG_KMS("Channel EQ done\n"); |
|---|
| 311 | 321 | return 0; |
|---|
| 312 | 322 | } |
|---|
| .. | .. |
|---|
| 338 | 348 | |
|---|
| 339 | 349 | static int cdn_dp_get_lower_link_rate(struct cdn_dp_device *dp) |
|---|
| 340 | 350 | { |
|---|
| 341 | | - switch (dp->link.rate) { |
|---|
| 351 | + switch (dp->max_rate) { |
|---|
| 342 | 352 | case DP_LINK_BW_1_62: |
|---|
| 343 | 353 | return -EINVAL; |
|---|
| 344 | 354 | case DP_LINK_BW_2_7: |
|---|
| 345 | | - dp->link.rate = DP_LINK_BW_1_62; |
|---|
| 355 | + dp->max_rate = DP_LINK_BW_1_62; |
|---|
| 346 | 356 | break; |
|---|
| 347 | 357 | case DP_LINK_BW_5_4: |
|---|
| 348 | | - dp->link.rate = DP_LINK_BW_2_7; |
|---|
| 358 | + dp->max_rate = DP_LINK_BW_2_7; |
|---|
| 349 | 359 | break; |
|---|
| 350 | 360 | default: |
|---|
| 351 | | - dp->link.rate = DP_LINK_BW_5_4; |
|---|
| 361 | + dp->max_rate = DP_LINK_BW_5_4; |
|---|
| 352 | 362 | break; |
|---|
| 353 | 363 | } |
|---|
| 354 | 364 | |
|---|
| .. | .. |
|---|
| 372 | 382 | |
|---|
| 373 | 383 | source_max = dp->lanes; |
|---|
| 374 | 384 | sink_max = drm_dp_max_lane_count(dp->dpcd); |
|---|
| 375 | | - dp->link.num_lanes = min(source_max, sink_max); |
|---|
| 385 | + dp->max_lanes = min(source_max, sink_max); |
|---|
| 376 | 386 | |
|---|
| 377 | 387 | source_max = drm_dp_bw_code_to_link_rate(CDN_DP_MAX_LINK_RATE); |
|---|
| 378 | 388 | sink_max = drm_dp_max_link_rate(dp->dpcd); |
|---|
| 379 | 389 | rate = min(source_max, sink_max); |
|---|
| 380 | | - dp->link.rate = drm_dp_link_rate_to_bw_code(rate); |
|---|
| 390 | + dp->max_rate = drm_dp_link_rate_to_bw_code(rate); |
|---|
| 381 | 391 | |
|---|
| 382 | 392 | ssc_on = !!(dp->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5); |
|---|
| 383 | 393 | link_config[0] = ssc_on ? DP_SPREAD_AMP_0_5 : 0; |
|---|
| .. | .. |
|---|
| 387 | 397 | drm_dp_dpcd_write(&dp->aux, DP_DOWNSPREAD_CTRL, link_config, 2); |
|---|
| 388 | 398 | |
|---|
| 389 | 399 | while (true) { |
|---|
| 390 | | - ret = tcphy_dp_set_link_rate(port->phy, |
|---|
| 391 | | - drm_dp_bw_code_to_link_rate(dp->link.rate), |
|---|
| 392 | | - ssc_on); |
|---|
| 393 | | - if (ret) { |
|---|
| 394 | | - DRM_ERROR("failed to set link rate: %d\n", ret); |
|---|
| 395 | | - return ret; |
|---|
| 396 | | - } |
|---|
| 400 | + union phy_configure_opts phy_cfg = {0}; |
|---|
| 397 | 401 | |
|---|
| 398 | | - ret = tcphy_dp_set_lane_count(port->phy, dp->link.num_lanes); |
|---|
| 399 | | - if (ret) { |
|---|
| 400 | | - DRM_ERROR("failed to set lane count: %d\n", ret); |
|---|
| 402 | + phy_cfg.dp.lanes = dp->max_lanes; |
|---|
| 403 | + phy_cfg.dp.link_rate = drm_dp_bw_code_to_link_rate(dp->max_rate) / 100; |
|---|
| 404 | + phy_cfg.dp.ssc = ssc_on; |
|---|
| 405 | + phy_cfg.dp.set_lanes = true; |
|---|
| 406 | + phy_cfg.dp.set_rate = true; |
|---|
| 407 | + phy_cfg.dp.set_voltages = false; |
|---|
| 408 | + ret = phy_configure(port->phy, &phy_cfg); |
|---|
| 409 | + if (ret) |
|---|
| 401 | 410 | return ret; |
|---|
| 402 | | - } |
|---|
| 403 | 411 | |
|---|
| 404 | 412 | /* Write the link configuration data */ |
|---|
| 405 | | - link_config[0] = dp->link.rate; |
|---|
| 406 | | - link_config[1] = dp->link.num_lanes; |
|---|
| 413 | + link_config[0] = dp->max_rate; |
|---|
| 414 | + link_config[1] = dp->max_lanes; |
|---|
| 407 | 415 | if (drm_dp_enhanced_frame_cap(dp->dpcd)) |
|---|
| 408 | 416 | link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; |
|---|
| 409 | 417 | drm_dp_dpcd_write(&dp->aux, DP_LINK_BW_SET, link_config, 2); |
|---|