Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915/alpm: Replace hardcoded LFPS cycle with proper calculation

Currently LFPS is hadcoded for different port clocks. Replace this with
proper calculation.

v2: replace hardcoded 20 with 2 * LFPS_CYCLE_COUNT

Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
Reviewed-by: Animesh Manna <animesh.manna@intel.com>
Link: https://lore.kernel.org/r/20250829053929.3585636-4-jouni.hogander@intel.com

+38 -52
+38 -52
drivers/gpu/drm/i915/display/intel_alpm.c
··· 58 58 1000 / 1000; 59 59 } 60 60 61 - /* 62 - * See Bspec: 71632 for the table 63 - * 64 - * Half cycle duration: 65 - * 66 - * Link rates 1.62 - 4.32 and tLFPS_Cycle = 70 ns 67 - * FLOOR( (Link Rate * tLFPS_Cycle) / (2 * 10) ) 68 - * 69 - * Link rates 5.4 - 8.1 70 - * PORT_ALPM_LFPS_CTL[ LFPS Cycle Count ] = 10 71 - * LFPS Period chosen is the mid-point of the min:max values from the table 72 - * FLOOR( LFPS Period in Symbol clocks / 73 - * (2 * PORT_ALPM_LFPS_CTL[ LFPS Cycle Count ]) ) 74 - */ 75 - static bool _lnl_get_lfps_half_cycle(int link_rate, int *lfps_half_cycle) 61 + static int get_lfps_cycle_min_max_time(const struct intel_crtc_state *crtc_state, 62 + int *min, int *max) 76 63 { 77 - switch (link_rate) { 78 - case 162000: 79 - *lfps_half_cycle = 5; 80 - break; 81 - case 216000: 82 - *lfps_half_cycle = 7; 83 - break; 84 - case 243000: 85 - *lfps_half_cycle = 8; 86 - break; 87 - case 270000: 88 - *lfps_half_cycle = 9; 89 - break; 90 - case 324000: 91 - *lfps_half_cycle = 11; 92 - break; 93 - case 432000: 94 - *lfps_half_cycle = 15; 95 - break; 96 - case 540000: 97 - *lfps_half_cycle = 12; 98 - break; 99 - case 648000: 100 - *lfps_half_cycle = 15; 101 - break; 102 - case 675000: 103 - *lfps_half_cycle = 15; 104 - break; 105 - case 810000: 106 - *lfps_half_cycle = 19; 107 - break; 108 - default: 109 - *lfps_half_cycle = -1; 110 - return false; 64 + if (crtc_state->port_clock < 540000) { 65 + *min = 65 * LFPS_CYCLE_COUNT; 66 + *max = 75 * LFPS_CYCLE_COUNT; 67 + } else if (crtc_state->port_clock <= 810000) { 68 + *min = 140; 69 + *max = 800; 70 + } else { 71 + *min = *max = -1; 72 + return -1; 111 73 } 112 - return true; 74 + 75 + return 0; 76 + } 77 + 78 + static int get_lfps_cycle_time(const struct intel_crtc_state *crtc_state) 79 + { 80 + int tlfps_cycle_min, tlfps_cycle_max, ret; 81 + 82 + ret = get_lfps_cycle_min_max_time(crtc_state, &tlfps_cycle_min, 83 + &tlfps_cycle_max); 84 + if (ret) 85 + return ret; 86 + 87 + return tlfps_cycle_min + (tlfps_cycle_max - tlfps_cycle_min) / 2; 88 + } 89 + 90 + static int get_lfps_half_cycle_clocks(const struct intel_crtc_state *crtc_state) 91 + { 92 + int lfps_cycle_time = get_lfps_cycle_time(crtc_state); 93 + 94 + if (lfps_cycle_time < 0) 95 + return -1; 96 + 97 + return lfps_cycle_time * crtc_state->port_clock / 1000 / 1000 / (2 * LFPS_CYCLE_COUNT); 113 98 } 114 99 115 100 /* ··· 146 161 aux_less_wake_lines = intel_usecs_to_scanlines(&crtc_state->hw.adjusted_mode, 147 162 aux_less_wake_time); 148 163 silence_period = get_silence_period_symbols(crtc_state); 149 - if (!_lnl_get_lfps_half_cycle(crtc_state->port_clock, 150 - &lfps_half_cycle)) 164 + 165 + lfps_half_cycle = get_lfps_half_cycle_clocks(crtc_state); 166 + if (lfps_half_cycle < 0) 151 167 return false; 152 168 153 169 if (aux_less_wake_lines > ALPM_CTL_AUX_LESS_WAKE_TIME_MASK ||