[PATCH 036/108] drm/i915/dp_link_caps: Move link config helpers to link caps

Imre Deak
2026-04-28T12:53:50Z

Move the helpers handling link configurations to intel_dp_link_caps.c.
Their functionality is part of the link capability logic and will be
updated to use the link capability state in follow-up changes.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
drivers/gpu/drm/i915/display/intel_dp.c | 101 -----------------
drivers/gpu/drm/i915/display/intel_dp.h | 2 -
.../gpu/drm/i915/display/intel_dp_link_caps.c | 102 ++++++++++++++++++
.../gpu/drm/i915/display/intel_dp_link_caps.h | 5 +
4 files changed, 107 insertions(+), 103 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index 52d843b05c38c..25f8ac21ce60c 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -33,7 +33,6 @@
#include <linux/notifier.h>
#include <linux/seq_buf.h>
#include <linux/slab.h>
-#include <linux/sort.h>
#include <linux/string_helpers.h>
#include <linux/timekeeping.h>
#include <linux/types.h>
@@ -666,106 +665,6 @@ int intel_dp_rate_index(const int *rates, int len, int rate)
return -1;
}

-static int intel_dp_link_config_rate(struct intel_dp *intel_dp,
- const struct intel_dp_link_config_entry *lc)
-{
- return intel_dp_common_rate(intel_dp, lc->link_rate_idx);
-}
-
-static int intel_dp_link_config_lane_count(const struct intel_dp_link_config_entry *lc)
-{
- return 1 << lc->lane_count_exp;
-}
-
-static int intel_dp_link_config_bw(struct intel_dp *intel_dp,
- const struct intel_dp_link_config_entry *lc)
-{
- return drm_dp_max_dprx_data_rate(intel_dp_link_config_rate(intel_dp, lc),
- intel_dp_link_config_lane_count(lc));
-}
-
-static int link_config_cmp_by_bw(const void *a, const void *b, const void *p)
-{
- struct intel_dp *intel_dp = (struct intel_dp *)p; /* remove const */
- const struct intel_dp_link_config_entry *lc_a = a;
- const struct intel_dp_link_config_entry *lc_b = b;
- int bw_a = intel_dp_link_config_bw(intel_dp, lc_a);
- int bw_b = intel_dp_link_config_bw(intel_dp, lc_b);
-
- if (bw_a != bw_b)
- return bw_a - bw_b;
-
- return intel_dp_link_config_rate(intel_dp, lc_a) -
- intel_dp_link_config_rate(intel_dp, lc_b);
-}
-
-static void intel_dp_link_config_init(struct intel_dp *intel_dp)
-{
- struct intel_display *display = to_intel_display(intel_dp);
- struct intel_dp_link_config_entry *lc;
- int num_common_lane_configs;
- int i;
- int j;
-
- if (drm_WARN_ON(display->drm, !is_power_of_2(intel_dp_max_common_lane_count(intel_dp))))
- return;
-
- num_common_lane_configs = ilog2(intel_dp_max_common_lane_count(intel_dp)) + 1;
-
- if (drm_WARN_ON(display->drm, intel_dp->num_common_rates * num_common_lane_configs >
- ARRAY_SIZE(intel_dp->link.configs)))
- return;
-
- intel_dp->link.num_configs = intel_dp->num_common_rates * num_common_lane_configs;
-
- lc = &intel_dp->link.configs[0];
- for (i = 0; i < intel_dp->num_common_rates; i++) {
- for (j = 0; j < num_common_lane_configs; j++) {
- lc->lane_count_exp = j;
- lc->link_rate_idx = i;
-
- lc++;
- }
- }
-
- sort_r(intel_dp->link.configs, intel_dp->link.num_configs,
- sizeof(intel_dp->link.configs[0]),
- link_config_cmp_by_bw, NULL,
- intel_dp);
-}
-
-void intel_dp_link_config_get(struct intel_dp *intel_dp, int idx, int *link_rate, int *lane_count)
-{
- struct intel_display *display = to_intel_display(intel_dp);
- const struct intel_dp_link_config_entry *lc;
-
- if (drm_WARN_ON(display->drm, idx < 0 || idx >= intel_dp->link.num_configs))
- idx = 0;
-
- lc = &intel_dp->link.configs[idx];
-
- *link_rate = intel_dp_link_config_rate(intel_dp, lc);
- *lane_count = intel_dp_link_config_lane_count(lc);
-}
-
-int intel_dp_link_config_index(struct intel_dp *intel_dp, int link_rate, int lane_count)
-{
- int link_rate_idx = intel_dp_rate_index(intel_dp->common_rates, intel_dp->num_common_rates,
- link_rate);
- int lane_count_exp = ilog2(lane_count);
- int i;
-
- for (i = 0; i < intel_dp->link.num_configs; i++) {
- const struct intel_dp_link_config_entry *lc = &intel_dp->link.configs[i];
-
- if (lc->lane_count_exp == lane_count_exp &&
- lc->link_rate_idx == link_rate_idx)
- return i;
- }
-
- return -1;
-}
-
static bool current_common_caps_match(struct intel_dp *intel_dp,
const int *rates, int num_rates)
{
diff --git a/drivers/gpu/drm/i915/display/intel_dp.h b/drivers/gpu/drm/i915/display/intel_dp.h
index 8f7607dc412d0..363907d463486 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.h
+++ b/drivers/gpu/drm/i915/display/intel_dp.h
@@ -105,8 +105,6 @@ int intel_dp_config_required_rate(const struct intel_crtc_state *crtc_state);
int intel_dp_rate_select(struct intel_dp *intel_dp, int rate);
int intel_dp_max_common_lane_count(struct intel_dp *intel_dp);
int intel_dp_rate_index(const int *rates, int len, int rate);
-int intel_dp_link_config_index(struct intel_dp *intel_dp, int link_rate, int lane_count);
-void intel_dp_link_config_get(struct intel_dp *intel_dp, int idx, int *link_rate, int *lane_count);
void intel_dp_update_sink_caps(struct intel_dp *intel_dp);
void intel_dp_reset_link_params(struct intel_dp *intel_dp);

diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
index e11a36ea2d178..9fadab008e8ee 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
@@ -4,7 +4,9 @@
*/

#include <linux/debugfs.h>
+#include <linux/log2.h>
#include <linux/slab.h>
+#include <linux/sort.h>

#include <drm/drm_print.h>

@@ -81,6 +83,106 @@ void intel_dp_link_caps_get_forced_params(struct intel_dp_link_caps *link_caps,
forced_params->lane_count = forced_lane_count(link_caps->dp);
}

+static int intel_dp_link_config_rate(struct intel_dp *intel_dp,
+ const struct intel_dp_link_config_entry *lc)
+{
+ return intel_dp_common_rate(intel_dp, lc->link_rate_idx);
+}
+
+static int intel_dp_link_config_lane_count(const struct intel_dp_link_config_entry *lc)
+{
+ return 1 << lc->lane_count_exp;
+}
+
+static int intel_dp_link_config_bw(struct intel_dp *intel_dp,
+ const struct intel_dp_link_config_entry *lc)
+{
+ return drm_dp_max_dprx_data_rate(intel_dp_link_config_rate(intel_dp, lc),
+ intel_dp_link_config_lane_count(lc));
+}
+
+static int link_config_cmp_by_bw(const void *a, const void *b, const void *p)
+{
+ struct intel_dp *intel_dp = (struct intel_dp *)p; /* remove const */
+ const struct intel_dp_link_config_entry *lc_a = a;
+ const struct intel_dp_link_config_entry *lc_b = b;
+ int bw_a = intel_dp_link_config_bw(intel_dp, lc_a);
+ int bw_b = intel_dp_link_config_bw(intel_dp, lc_b);
+
+ if (bw_a != bw_b)
+ return bw_a - bw_b;
+
+ return intel_dp_link_config_rate(intel_dp, lc_a) -
+ intel_dp_link_config_rate(intel_dp, lc_b);
+}
+
+void intel_dp_link_config_init(struct intel_dp *intel_dp)
+{
+ struct intel_display *display = to_intel_display(intel_dp);
+ struct intel_dp_link_config_entry *lc;
+ int num_common_lane_configs;
+ int i;
+ int j;
+
+ if (drm_WARN_ON(display->drm, !is_power_of_2(intel_dp_max_common_lane_count(intel_dp))))
+ return;
+
+ num_common_lane_configs = ilog2(intel_dp_max_common_lane_count(intel_dp)) + 1;
+
+ if (drm_WARN_ON(display->drm, intel_dp->num_common_rates * num_common_lane_configs >
+ ARRAY_SIZE(intel_dp->link.configs)))
+ return;
+
+ intel_dp->link.num_configs = intel_dp->num_common_rates * num_common_lane_configs;
+
+ lc = &intel_dp->link.configs[0];
+ for (i = 0; i < intel_dp->num_common_rates; i++) {
+ for (j = 0; j < num_common_lane_configs; j++) {
+ lc->lane_count_exp = j;
+ lc->link_rate_idx = i;
+
+ lc++;
+ }
+ }
+
+ sort_r(intel_dp->link.configs, intel_dp->link.num_configs,
+ sizeof(intel_dp->link.configs[0]),
+ link_config_cmp_by_bw, NULL,
+ intel_dp);
+}
+
+void intel_dp_link_config_get(struct intel_dp *intel_dp, int idx, int *link_rate, int *lane_count)
+{
+ struct intel_display *display = to_intel_display(intel_dp);
+ const struct intel_dp_link_config_entry *lc;
+
+ if (drm_WARN_ON(display->drm, idx < 0 || idx >= intel_dp->link.num_configs))
+ idx = 0;
+
+ lc = &intel_dp->link.configs[idx];
+
+ *link_rate = intel_dp_link_config_rate(intel_dp, lc);
+ *lane_count = intel_dp_link_config_lane_count(lc);
+}
+
+int intel_dp_link_config_index(struct intel_dp *intel_dp, int link_rate, int lane_count)
+{
+ int link_rate_idx = intel_dp_rate_index(intel_dp->common_rates, intel_dp->num_common_rates,
+ link_rate);
+ int lane_count_exp = ilog2(lane_count);
+ int i;
+
+ for (i = 0; i < intel_dp->link.num_configs; i++) {
+ const struct intel_dp_link_config_entry *lc = &intel_dp->link.configs[i];
+
+ if (lc->lane_count_exp == lane_count_exp &&
+ lc->link_rate_idx == link_rate_idx)
+ return i;
+ }
+
+ return -1;
+}
+
static int i915_dp_force_link_rate_show(struct seq_file *m, void *data)
{
struct intel_connector *connector = to_intel_connector(m->private);
diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
index c6a84891db464..dab956e804b95 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
@@ -17,6 +17,11 @@ int intel_dp_max_common_rate(struct intel_dp *intel_dp);
void intel_dp_link_caps_get_forced_params(struct intel_dp_link_caps *link_caps,
struct intel_dp_link_config *forced_params);

+int intel_dp_link_config_index(struct intel_dp *intel_dp, int link_rate, int lane_count);
+void intel_dp_link_config_get(struct intel_dp *intel_dp, int idx, int *link_rate, int *lane_count);
+
+void intel_dp_link_config_init(struct intel_dp *intel_dp);
+
void intel_dp_link_caps_debugfs_add(struct intel_connector *connector);

struct intel_dp_link_caps *intel_dp_link_caps_init(struct intel_dp *intel_dp);
--
2.49.1