drm/bridge: analogix_dp: Fix PE/VS value shift mismatch during link training
Subsystems (3)
PATCH 1/1 drm/bridge: analogix_dp: Fix PE/VS value shift mismatch during link training
The values returned by drm_dp_get_adjust_request_voltage() and drm_dp_get_adjust_request_pre_emphasis() are raw unshifted 2-bit values, but DPCD_*_SET macros expect them to be shifted into their respective bit positions. Without right-shifting first, the combined training_lane register value becomes corrupted whenever pre-emphasis or voltage swing is non-zero, leading to failed link training and black screen.
Add right shift by DP_TRAIN_VOLTAGE_SWING_SHIFT and DP_TRAIN_PRE_EMPHASIS_SHIFT for both voltage swing and pre-emphasis values before constructing training_lane, in both the adjust training lane and clock recovery paths.
--- drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +4 -0
@@ -309,7 +309,9 @@ static void analogix_dp_get_adjust_training_lane(struct analogix_dp_device *dp, lane_count = dp->link_train.lane_count;for (lane =0 ; lane < lane_count; lane++) { voltage_swing =drm_dp_get_adjust_request_voltage (link_status, lane); + voltage_swing >>=DP_TRAIN_VOLTAGE_SWING_SHIFT ; pre_emphasis =drm_dp_get_adjust_request_pre_emphasis (link_status, lane); + pre_emphasis >>=DP_TRAIN_PRE_EMPHASIS_SHIFT ; training_lane =DPCD_VOLTAGE_SWING_SET (voltage_swing) |DPCD_PRE_EMPHASIS_SET (pre_emphasis);
@@ -355,7 +357,9 @@ static int analogix_dp_process_clock_recovery(struct analogix_dp_device *dp)for (lane =0 ; lane < lane_count; lane++) { training_lane =analogix_dp_get_lane_link_training (dp, lane); voltage_swing =drm_dp_get_adjust_request_voltage (link_status, lane); + voltage_swing >>=DP_TRAIN_VOLTAGE_SWING_SHIFT ; pre_emphasis =drm_dp_get_adjust_request_pre_emphasis (link_status, lane); + pre_emphasis >>=DP_TRAIN_PRE_EMPHASIS_SHIFT ;if (DPCD_VOLTAGE_SWING_GET (training_lane) == voltage_swing &&DPCD_PRE_EMPHASIS_GET (training_lane) == pre_emphasis)
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch activates a dormant logic bug that causes Clock Recovery to instantly fail if the DP sink requests maximum pre-emphasis.
- [High] The clock recovery loop counter cr_loop accumulates across different requested levels instead of tracking consecutive identical requests. --
commit 2ce38552c8226840ef5d2e4d8187e099b547ef5a
Author: Damon Ding <[email protected]>
drm/bridge: analogix_dp: Fix PE/VS value shift mismatch during link training
This commit fixes a missing bit-shift for voltage swing and pre-emphasis values during DP link training. It shifts the raw values returned by the drm_dp_get_adjust_request_* functions so they can be properly used with the DPCD_*_SET macros.
Quoted 4 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +0
-0
[ ... ]
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c static int analogix_dp_process_clock_recovery(struct analogix_dp_device *dp) · line 365
Quoted 10 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +2
-0@@ -355,7 +357,9 @@ static int analogix_dp_process_clock_recovery(struct analogix_dp_device *dp)for (lane =0 ; lane < lane_count; lane++) { training_lane =analogix_dp_get_lane_link_training (dp, lane); voltage_swing =drm_dp_get_adjust_request_voltage (link_status, lane); + voltage_swing >>=DP_TRAIN_VOLTAGE_SWING_SHIFT ; pre_emphasis =drm_dp_get_adjust_request_pre_emphasis (link_status, lane); + pre_emphasis >>=DP_TRAIN_PRE_EMPHASIS_SHIFT ;if (DPCD_VOLTAGE_SWING_GET (training_lane) == voltage_swing &&DPCD_PRE_EMPHASIS_GET (training_lane) == pre_emphasis)
[Severity: High]
This is a pre-existing issue, but does this lack of reset cause premature link training failures?
In analogix_dp_process_clock_recovery(), cr_loop[lane] is incremented when the requested levels match the applied levels. However, if the DP sink requests a new level, the counter is not reset to 0.
It appears to accumulate counts across different levels during the entire clock recovery phase. If the sink steps through multiple levels and hits the MAX_CR_LOOP limit in total (e.g., 2 loops at level 1, 2 loops at level 2, 1 loop at level 3), could it incorrectly trigger the abort condition below?
[Severity: High]
This isn't a bug introduced by this patch, but does fixing the shift logic activate a dormant bug right below this check?
Immediately after the snippet above in analogix_dp_process_clock_recovery(), the code checks:
if (dp->link_train.cr_loop[lane] == MAX_CR_LOOP ||
voltage_swing == VOLTAGE_LEVEL_3 ||
pre_emphasis == PRE_EMPHASIS_LEVEL_3) {
dev_err(dp->dev, "CR Max reached (%d,%d,%d)\n", ...);
analogix_dp_reduce_link_rate(dp);
return -EIO;
}Before this patch, pre_emphasis evaluated to 24, which bypassed this abort. Now that the value is properly shifted, if the sink legitimately requests PRE_EMPHASIS_LEVEL_3 (which evaluates to 3), won't the driver immediately return -EIO and abort clock recovery instead of applying the maximum level and setting the MAX_PRE_EMPHASIS_REACHED bit?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1