]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/i915/display: Add helper function for fuzzy clock check
authorMika Kahola <mika.kahola@intel.com>
Mon, 19 Jan 2026 09:37:49 +0000 (09:37 +0000)
committerMika Kahola <mika.kahola@intel.com>
Tue, 20 Jan 2026 08:52:54 +0000 (10:52 +0200)
The hard coded clock rate stored in the PLL state will be removed by
a follow-up change. The clock is calculated instead of
using clock from the PLL divider values. Since this calculated clock
may vary due to fixed point rounding issues, a +-1 kHz variation is
allowed with the request clock rate against the calculated clock rate.

v2:
- Use the stricter +-1 kHz allowed difference.
- Derive the clock from PLL dividers in intel_cx0pll_enable().
- Move corresponding fuzzy check for LT PHY PLLs to this patch.

v3: Reword commit message (Suraj)
    Move clock check to intel_dpll and rename it (Suraj)

Signed-off-by: Mika Kahola <mika.kahola@intel.com>
Reviewed-by: Suraj Kandpal <suraj.kandpal@intel.com>
Link: https://patch.msgid.link/20260119093757.2850233-9-mika.kahola@intel.com
drivers/gpu/drm/i915/display/intel_cx0_phy.c
drivers/gpu/drm/i915/display/intel_dpll.c
drivers/gpu/drm/i915/display/intel_dpll.h
drivers/gpu/drm/i915/display/intel_lt_phy.c

index 8e780480f6c0be0e0ee52f4673f28298f156a3a6..26d3d41d41a732eb04241149f4724352f223997e 100644 (file)
@@ -18,6 +18,7 @@
 #include "intel_display_types.h"
 #include "intel_display_utils.h"
 #include "intel_dp.h"
+#include "intel_dpll.h"
 #include "intel_hdmi.h"
 #include "intel_lt_phy.h"
 #include "intel_panel.h"
@@ -2224,7 +2225,10 @@ static int intel_c10pll_calc_state_from_table(struct intel_encoder *encoder,
        int i;
 
        for (i = 0; tables[i].name; i++) {
-               if (port_clock == tables[i].clock_rate) {
+               int clock = intel_c10pll_calc_port_clock(tables[i].c10);
+
+               drm_WARN_ON(display->drm, !intel_dpll_clock_matches(clock, tables[i].clock_rate));
+               if (intel_dpll_clock_matches(port_clock, clock)) {
                        pll_state->c10 = *tables[i].c10;
                        intel_cx0pll_update_ssc(encoder, pll_state, is_dp);
                        intel_c10pll_update_pll(encoder, pll_state);
@@ -2710,6 +2714,7 @@ static const struct intel_cx0pll_params *
 intel_c20_pll_find_table(const struct intel_crtc_state *crtc_state,
                         struct intel_encoder *encoder)
 {
+       struct intel_display *display = to_intel_display(crtc_state);
        const struct intel_cx0pll_params *tables;
        int i;
 
@@ -2717,9 +2722,13 @@ intel_c20_pll_find_table(const struct intel_crtc_state *crtc_state,
        if (!tables)
                return NULL;
 
-       for (i = 0; tables[i].name; i++)
-               if (crtc_state->port_clock == tables[i].clock_rate)
+       for (i = 0; tables[i].name; i++) {
+               int clock = intel_c20pll_calc_port_clock(tables[i].c20);
+
+               drm_WARN_ON(display->drm, !intel_dpll_clock_matches(clock, tables[i].clock_rate));
+               if (intel_dpll_clock_matches(crtc_state->port_clock, clock))
                        return &tables[i];
+       }
 
        return NULL;
 }
@@ -3255,7 +3264,6 @@ static u32 intel_cx0_get_pclk_pll_ack(u8 lane_mask)
 static void intel_cx0pll_enable(struct intel_encoder *encoder,
                                const struct intel_cx0pll_state *pll_state)
 {
-       int port_clock = pll_state->use_c10 ? pll_state->c10.clock : pll_state->c20.clock;
        struct intel_display *display = to_intel_display(encoder);
        enum phy phy = intel_encoder_to_phy(encoder);
        struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
@@ -3263,6 +3271,12 @@ static void intel_cx0pll_enable(struct intel_encoder *encoder,
        u8 maxpclk_lane = lane_reversal ? INTEL_CX0_LANE1 :
                                          INTEL_CX0_LANE0;
        struct ref_tracker *wakeref = intel_cx0_phy_transaction_begin(encoder);
+       int port_clock;
+
+       if (pll_state->use_c10)
+               port_clock = intel_c10pll_calc_port_clock(&pll_state->c10);
+       else
+               port_clock = intel_c20pll_calc_port_clock(&pll_state->c20);
 
        /*
         * Lane reversal is never used in DP-alt mode, in that case the
index 1b5b18fa0a36bc8b39beee8de043d6dad3397ea2..8433e3ff0319f8435881ab2cc6208bc263e32bc8 100644 (file)
@@ -2334,3 +2334,8 @@ void assert_pll_disabled(struct intel_display *display, enum pipe pipe)
 {
        assert_pll(display, pipe, false);
 }
+
+bool intel_dpll_clock_matches(int clock1, int clock2)
+{
+       return abs(clock1 - clock2) <= 1;
+}
index 3444a2dd3166e5b73c1a23f8ebf5560ff152935c..8cd0d17e974e59d505676c374de150e818b39118 100644 (file)
@@ -48,5 +48,6 @@ void chv_crtc_clock_get(struct intel_crtc_state *crtc_state);
 
 void assert_pll_enabled(struct intel_display *display, enum pipe pipe);
 void assert_pll_disabled(struct intel_display *display, enum pipe pipe);
+bool intel_dpll_clock_matches(int clock1, int clock2);
 
 #endif
index a86ae6139ff0a2d0b6447f95bbe762f6db3aaac8..2790caba545793e16cb26bfec5c7e559eb3dfba4 100644 (file)
@@ -14,6 +14,7 @@
 #include "intel_display.h"
 #include "intel_display_types.h"
 #include "intel_display_utils.h"
+#include "intel_dpll.h"
 #include "intel_dpll_mgr.h"
 #include "intel_hdmi.h"
 #include "intel_lt_phy.h"
@@ -1796,6 +1797,7 @@ int
 intel_lt_phy_pll_calc_state(struct intel_crtc_state *crtc_state,
                            struct intel_encoder *encoder)
 {
+       struct intel_display *display = to_intel_display(crtc_state);
        const struct intel_lt_phy_pll_params *tables;
        int i;
 
@@ -1804,7 +1806,10 @@ intel_lt_phy_pll_calc_state(struct intel_crtc_state *crtc_state,
                return -EINVAL;
 
        for (i = 0; tables[i].name; i++) {
-               if (crtc_state->port_clock == tables[i].clock_rate) {
+               int clock = intel_lt_phy_calc_port_clock(display, tables[i].state);
+
+               drm_WARN_ON(display->drm, !intel_dpll_clock_matches(clock, tables[i].clock_rate));
+               if (intel_dpll_clock_matches(crtc_state->port_clock, clock)) {
                        crtc_state->dpll_hw_state.ltpll = *tables[i].state;
                        if (intel_crtc_has_dp_encoder(crtc_state)) {
                                if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))