[PATCH 5/8] drm/dp: Move DP sink link rates reading helper out of i915

From: Kory Maincent

Date: Wed Nov 18 2026 - 05:37:20 EST


Move the DP sink link rates reading function out of the i915 driver
into the generic DRM helpers. This function provides everything needed
to properly extract link rate capabilities from the DPCD, limited by
the capabilities of the LTTPRs or the DP tunnel when present.

No functional change intended.

Signed-off-by: Kory Maincent <kory.maincent@xxxxxxxxxxx>
---
drivers/gpu/drm/display/drm_dp_helper.c | 89 +++++++++++++++++++++++++++++++++
drivers/gpu/drm/i915/display/intel_dp.c | 82 ++++++++----------------------
include/drm/display/drm_dp.h | 1 +
include/drm/display/drm_dp_helper.h | 8 +++
4 files changed, 118 insertions(+), 62 deletions(-)

diff --git a/drivers/gpu/drm/display/drm_dp_helper.c b/drivers/gpu/drm/display/drm_dp_helper.c
index a0afb5eff5bb4..e06264c52bf5e 100644
--- a/drivers/gpu/drm/display/drm_dp_helper.c
+++ b/drivers/gpu/drm/display/drm_dp_helper.c
@@ -5001,3 +5001,92 @@ drm_dp_get_128b132b_link_rates(const u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SI
return i;
}
EXPORT_SYMBOL_GPL(drm_dp_get_128b132b_link_rates);
+
+/**
+ * drm_dp_read_dpcd_sink_rates() - read the sink rates from the DPCD
+ * @aux: DisplayPort AUX channel
+ * @dpcd: DPCD receiver capabilities
+ * @lttpr_common_caps: LTTPR common capabilities
+ * @desc: DisplayPort sink descriptor
+ * @tunnel: Tunnel object (NULL if not supported)
+ * @sink_rates: Array of DP_MAX_SUPPORTED_RATES entries to store the sink rates
+ *
+ * Read the link rates supported by a DisplayPort sink from the DPCD
+ * DP_MAX_LINK_RATE and DP_128B132B_SUPPORTED_LINK_RATES registers, limited by
+ * the capabilities of the LTTPRs or the tunnel if any is present.
+ * The rates are stored in @sink_rates in ascending order.
+ *
+ * The DPCD receiver capabilities, the LTTPR common capabilities, the tunnel
+ * and the sink descriptor are passed by the caller instead of being read
+ * from the DPCD. Drivers which already read them, like i915, can pass them
+ * to avoid duplicate DPCD reads.
+ *
+ * Returns: The number of supported sink rates.
+ */
+int drm_dp_read_dpcd_sink_rates(struct drm_dp_aux *aux,
+ const u8 dpcd[DP_RECEIVER_CAP_SIZE],
+ const u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE],
+ const struct drm_dp_desc *desc,
+ const struct drm_dp_tunnel *tunnel,
+ int sink_rates[DP_MAX_SUPPORTED_RATES])
+{
+ static const int dp_rates[] = {
+ 162000, 270000, 540000, 810000
+ };
+ int max_rate, max_lttpr_rate = 0, ret, i;
+ u8 uhbr_rates = 0;
+
+ BUILD_BUG_ON(ARRAY_SIZE(dp_rates) + DP_MAX_128B132B_SUPPORTED_RATES >
+ DP_MAX_SUPPORTED_RATES);
+
+ if (drm_dp_has_quirk(desc, DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS)) {
+ /* Needed, e.g., for Apple MBP 2017, 15 inch eDP Retina panel */
+ static const int quirk_rates[] = { 162000, 270000, 324000 };
+
+ memcpy(sink_rates, quirk_rates, sizeof(quirk_rates));
+
+ return ARRAY_SIZE(quirk_rates);
+ }
+
+ /*
+ * Sink rates for 8b/10b.
+ */
+ max_rate = drm_dprx_max_rate(tunnel, dpcd);
+ if (lttpr_common_caps && lttpr_common_caps[0] >= DP_LTTPR_REV_SUP_8B10B)
+ max_lttpr_rate = drm_dp_lttpr_max_link_rate(lttpr_common_caps);
+
+ if (max_lttpr_rate)
+ max_rate = min(max_rate, max_lttpr_rate);
+
+ for (i = 0; i < ARRAY_SIZE(dp_rates); i++) {
+ if (dp_rates[i] > max_rate)
+ break;
+ sink_rates[i] = dp_rates[i];
+ }
+
+ /*
+ * The following register must be read unconditionally for the later
+ * DP tunnel 128b132b detection to work, see DP Standard v2.1 5.14.3 .
+ */
+ ret = drm_dp_dpcd_read_byte(aux, DP_128B132B_SUPPORTED_LINK_RATES,
+ &uhbr_rates);
+ if (ret < 0) {
+ drm_dbg_kms(aux->drm_dev,
+ "%s: Failed to read DPCD 128B/132B supported link rates (%d)\n",
+ aux->name, ret);
+ uhbr_rates = 0;
+ }
+
+ /*
+ * Sink rates for 128b/132b. If set, sink should support all 8b/10b
+ * rates and 10 Gbps.
+ */
+ if (drm_dprx_supports_128b132b(tunnel, dpcd))
+ i += drm_dp_get_128b132b_link_rates(lttpr_common_caps,
+ tunnel,
+ uhbr_rates,
+ &sink_rates[i]);
+
+ return i;
+}
+EXPORT_SYMBOL_GPL(drm_dp_read_dpcd_sink_rates);
diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index 7ef06e68878d4..8fee2d195c944 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -176,70 +176,18 @@ static void intel_dp_set_default_sink_rates(struct intel_dp *intel_dp)
/* update sink rates from dpcd */
static void intel_dp_set_dpcd_sink_rates(struct intel_dp *intel_dp)
{
- struct intel_display *display = to_intel_display(intel_dp);
- static const int dp_rates[] = {
- 162000, 270000, 540000, 810000
- };
- int i, max_rate;
- int max_lttpr_rate;
- u8 uhbr_rates = 0;
-
- if (drm_dp_has_quirk(&intel_dp->desc, DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS)) {
- /* Needed, e.g., for Apple MBP 2017, 15 inch eDP Retina panel */
- static const int quirk_rates[] = { 162000, 270000, 324000 };
-
- memcpy(intel_dp->sink_rates, quirk_rates, sizeof(quirk_rates));
- intel_dp->num_sink_rates = ARRAY_SIZE(quirk_rates);
-
- return;
- }
-
- /*
- * Sink rates for 8b/10b.
- */
- max_rate = drm_dprx_max_rate(intel_dp->tunnel, intel_dp->dpcd);
-
- /*
- * Some platforms + eDP panels may not reliably support HBR3
- * due to signal integrity limitations, despite advertising it.
- * Cap the link rate to HBR2 to avoid unstable configurations for the
- * known machines.
- */
- if (intel_dp_is_edp(intel_dp) && intel_has_quirk(display, QUIRK_EDP_LIMIT_RATE_HBR2))
- max_rate = min(max_rate, 540000);
-
- max_lttpr_rate = drm_dp_lttpr_max_link_rate(intel_dp->lttpr_common_caps);
- if (max_lttpr_rate)
- max_rate = min(max_rate, max_lttpr_rate);
+ int num_sink_rates;

- for (i = 0; i < ARRAY_SIZE(dp_rates); i++) {
- if (dp_rates[i] > max_rate)
- break;
- intel_dp->sink_rates[i] = dp_rates[i];
- }
-
- /*
- * The following register must be read unconditionally for the later
- * DP tunnel 128b132b detection to work, see DP Standard v2.1 5.14.3 .
- */
- drm_dp_dpcd_read_byte(&intel_dp->aux, DP_128B132B_SUPPORTED_LINK_RATES, &uhbr_rates);
-
- /*
- * Sink rates for 128b/132b. If set, sink should support all 8b/10b
- * rates and 10 Gbps.
- */
- if (drm_dprx_supports_128b132b(intel_dp->tunnel, intel_dp->dpcd)) {
- BUILD_BUG_ON(ARRAY_SIZE(intel_dp->sink_rates) < ARRAY_SIZE(dp_rates) + 3);
-
- uhbr_rates = drm_dprx_128b132b_link_rates(intel_dp->tunnel, uhbr_rates);
-
- i += drm_dp_get_128b132b_link_rates(intel_dp->lttpr_common_caps,
- intel_dp->tunnel,
- uhbr_rates,
- &intel_dp->sink_rates[i]);
- }
+ num_sink_rates = drm_dp_read_dpcd_sink_rates(&intel_dp->aux,
+ intel_dp->dpcd,
+ intel_dp->lttpr_common_caps,
+ &intel_dp->desc,
+ intel_dp->tunnel,
+ intel_dp->sink_rates);
+ if (num_sink_rates < 0)
+ num_sink_rates = 0;

- intel_dp->num_sink_rates = i;
+ intel_dp->num_sink_rates = num_sink_rates;
}

static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
@@ -4921,6 +4869,16 @@ intel_edp_set_sink_rates(struct intel_dp *intel_dp)
else
intel_dp_set_sink_rates(intel_dp);

+ /*
+ * Some platforms cannot reliably drive HBR3 rates due to PHY limitations,
+ * even if the sink advertises support. Reject any sink rates above HBR2 on
+ * the known machines for stable output.
+ */
+ if (intel_dp->num_sink_rates && intel_has_quirk(display, QUIRK_EDP_LIMIT_RATE_HBR2))
+ intel_dp->num_sink_rates = intel_dp_rate_limit_len(intel_dp->sink_rates,
+ intel_dp->num_sink_rates,
+ 540000);
+
intel_edp_set_data_override_rates(intel_dp);
}

diff --git a/include/drm/display/drm_dp.h b/include/drm/display/drm_dp.h
index 7a4849695444c..6eacaef40eb0d 100644
--- a/include/drm/display/drm_dp.h
+++ b/include/drm/display/drm_dp.h
@@ -1529,6 +1529,7 @@

/* LTTPR: Link Training (LT)-tunable PHY Repeaters */
#define DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV 0xf0000 /* 1.3 */
+#define DP_LTTPR_REV_SUP_8B10B 0x14
#define DP_LTTPR_REV_SUP_128B132B 0x20
#define DP_MAX_LINK_RATE_PHY_REPEATER 0xf0001 /* 1.4a */
#define DP_PHY_REPEATER_CNT 0xf0002 /* 1.3 */
diff --git a/include/drm/display/drm_dp_helper.h b/include/drm/display/drm_dp_helper.h
index a8c382a2c916f..5c4cb57f0fc5e 100644
--- a/include/drm/display/drm_dp_helper.h
+++ b/include/drm/display/drm_dp_helper.h
@@ -34,6 +34,7 @@ struct drm_dp_aux;
struct drm_panel;
struct drm_printer;
struct drm_dp_tunnel;
+struct drm_dp_desc;

bool drm_dp_channel_eq_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
int lane_count);
@@ -713,6 +714,13 @@ int drm_dp_get_128b132b_link_rates(const u8 lttpr_common_caps[DP_LTTPR_COMMON_CA
u8 uhbr_rates,
int link_rates[DP_MAX_128B132B_SUPPORTED_RATES]);

+int drm_dp_read_dpcd_sink_rates(struct drm_dp_aux *aux,
+ const u8 dpcd[DP_RECEIVER_CAP_SIZE],
+ const u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE],
+ const struct drm_dp_desc *desc,
+ const struct drm_dp_tunnel *tunnel,
+ int sink_rates[DP_MAX_SUPPORTED_RATES]);
+
int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux,
u8 status[DP_LINK_STATUS_SIZE]);


--
2.43.0