1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2026 Intel Corporation 4 * 5 */ 6 7 #include <drm/drm_print.h> 8 9 #include "intel_de.h" 10 #include "intel_dip.h" 11 #include "intel_dip_regs.h" 12 #include "intel_display_types.h" 13 #include "intel_hdmi.h" 14 15 static int intel_dip_get_as_sdp_transmission_line(const struct intel_crtc_state *crtc_state) 16 { 17 struct intel_display *display = to_intel_display(crtc_state); 18 19 if (!HAS_EMP_AS_SDP_TL(display)) 20 return 0; 21 22 /* 23 * EMP_AS_SDP_TL defines the T1 position as the default AS SDP 24 * Transmission Line, which corresponds to the start of the 25 * VSYNC pulse. 26 * 27 * Use the T1 position for now. 28 */ 29 return crtc_state->vrr.vsync_start; 30 } 31 32 u16 intel_dip_read_emp_as_sdp_tl(const struct intel_crtc_state *crtc_state) 33 { 34 struct intel_display *display = to_intel_display(crtc_state); 35 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 36 u32 val; 37 38 if (!HAS_EMP_AS_SDP_TL(display)) 39 return 0; 40 41 val = intel_de_read(display, EMP_AS_SDP_TL(display, cpu_transcoder)); 42 return REG_FIELD_GET(EMP_AS_SDP_DB_TL_MASK, val); 43 } 44 45 void intel_dip_write_emp_as_sdp_tl(const struct intel_crtc_state *crtc_state) 46 { 47 struct intel_display *display = to_intel_display(crtc_state); 48 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 49 50 if (!HAS_EMP_AS_SDP_TL(display)) 51 return; 52 53 intel_de_write(display, 54 EMP_AS_SDP_TL(display, cpu_transcoder), 55 EMP_AS_SDP_DB_TL(crtc_state->dip.emp_as_sdp_tl)); 56 } 57 58 static int intel_dip_sdp_stagger_to_tl(struct intel_crtc_state *crtc_state, 59 int stagger) 60 { 61 return crtc_state->dip.cmn_sdp_tl + stagger; 62 } 63 64 static 65 void intel_dip_cmn_sdp_tl_compute_config_late(struct intel_crtc_state *crtc_state) 66 { 67 struct intel_display *display = to_intel_display(crtc_state); 68 bool as_sdp; 69 70 if (!HAS_COMMON_SDP_TL(display)) 71 return; 72 73 as_sdp = crtc_state->infoframes.enable & 74 intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC); 75 /* 76 * When AS SDP is enabled : 77 * - The common SDP Transmission Line matches the EMP SDP Transmission Line. 78 * 79 * When AS SDP is disabled: 80 * - Bspec mentions the positions as lines of delayed vblank. 81 * - Guardband = 1st line of delayed vblank 82 * - Common SDP Transmission line is set to 2nd line of delayed vblank. 83 */ 84 85 if (as_sdp) 86 crtc_state->dip.cmn_sdp_tl = crtc_state->dip.emp_as_sdp_tl; 87 else 88 crtc_state->dip.cmn_sdp_tl = crtc_state->vrr.guardband - 1; 89 90 if (drm_WARN_ON(display->drm, 91 crtc_state->dip.cmn_sdp_tl >= 92 crtc_state->vrr.guardband + crtc_state->set_context_latency)) 93 return; 94 95 /* 96 * Currently we are programming the default stagger values, but these 97 * can be optimized if required, based on number of SDPs enabled. 98 * 99 * Default values of the Transmission lines for SDPs other than AS SDP: 100 * VSC : CMN SDP Transmission line 101 * GMP : CMN SDP Transmission line 102 * PPS : CMN SDP Transmission line + 1 103 * VSC_EXT: CMN SDP Transmission line + 2 104 */ 105 crtc_state->dip.vsc_sdp_tl = crtc_state->dip.cmn_sdp_tl; 106 crtc_state->dip.gmp_sdp_tl = 107 intel_dip_sdp_stagger_to_tl(crtc_state, GMP_STAGGER_DEFAULT); 108 crtc_state->dip.pps_sdp_tl = 109 intel_dip_sdp_stagger_to_tl(crtc_state, PPS_STAGGER_DEFAULT); 110 crtc_state->dip.vsc_ext_sdp_tl = 111 intel_dip_sdp_stagger_to_tl(crtc_state, VSC_EXT_STAGGER_DEFAULT); 112 } 113 114 void intel_dip_sdp_tl_compute_config_late(struct intel_crtc_state *crtc_state) 115 { 116 crtc_state->dip.emp_as_sdp_tl = intel_dip_get_as_sdp_transmission_line(crtc_state); 117 118 intel_dip_cmn_sdp_tl_compute_config_late(crtc_state); 119 } 120 121 static 122 void intel_dip_cmn_sdp_transmission_line_get_config(struct intel_crtc_state *crtc_state) 123 { 124 struct intel_display *display = to_intel_display(crtc_state); 125 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 126 u16 vsc_ext_stagger, pps_stagger, gmp_stagger; 127 u32 val; 128 129 if (!HAS_COMMON_SDP_TL(display)) 130 return; 131 132 val = intel_de_read(display, CMN_SDP_TL(display, cpu_transcoder)); 133 134 if (!(val & TRANSMISSION_LINE_ENABLE)) 135 return; 136 137 crtc_state->dip.cmn_sdp_tl = REG_FIELD_GET(BASE_TRANSMISSION_LINE_MASK, val); 138 139 /* SDP VSC uses same transmission line as CMN base transmission line */ 140 crtc_state->dip.vsc_sdp_tl = crtc_state->dip.cmn_sdp_tl; 141 142 val = intel_de_read(display, CMN_SDP_TL_STGR_CTL(display, cpu_transcoder)); 143 144 vsc_ext_stagger = REG_FIELD_GET(VSC_EXT_STAGGER_MASK, val); 145 pps_stagger = REG_FIELD_GET(PPS_STAGGER_MASK, val); 146 gmp_stagger = REG_FIELD_GET(GMP_STAGGER_MASK, val); 147 148 crtc_state->dip.vsc_ext_sdp_tl = 149 intel_dip_sdp_stagger_to_tl(crtc_state, vsc_ext_stagger); 150 crtc_state->dip.pps_sdp_tl = 151 intel_dip_sdp_stagger_to_tl(crtc_state, pps_stagger); 152 crtc_state->dip.gmp_sdp_tl = 153 intel_dip_sdp_stagger_to_tl(crtc_state, gmp_stagger); 154 } 155 156 void intel_dip_sdp_transmission_line_get_config(struct intel_crtc_state *crtc_state) 157 { 158 crtc_state->dip.emp_as_sdp_tl = intel_dip_read_emp_as_sdp_tl(crtc_state); 159 160 intel_dip_cmn_sdp_transmission_line_get_config(crtc_state); 161 } 162 163 static int intel_dip_sdp_tl_to_stagger(const struct intel_crtc_state *crtc_state, 164 u16 sdp_transmission_line) 165 { 166 return sdp_transmission_line - crtc_state->dip.cmn_sdp_tl; 167 } 168 169 void intel_dip_cmn_sdp_transmission_line_enable(const struct intel_crtc_state *crtc_state) 170 { 171 struct intel_display *display = to_intel_display(crtc_state); 172 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 173 int gmp_stagger; 174 int pps_stagger; 175 int vsc_ext_stagger; 176 177 if (!HAS_COMMON_SDP_TL(display)) 178 return; 179 180 gmp_stagger = intel_dip_sdp_tl_to_stagger(crtc_state, 181 crtc_state->dip.gmp_sdp_tl); 182 183 pps_stagger = intel_dip_sdp_tl_to_stagger(crtc_state, 184 crtc_state->dip.pps_sdp_tl); 185 186 vsc_ext_stagger = intel_dip_sdp_tl_to_stagger(crtc_state, 187 crtc_state->dip.vsc_ext_sdp_tl); 188 189 if (drm_WARN_ON(display->drm, gmp_stagger < 0)) 190 return; 191 if (drm_WARN_ON(display->drm, pps_stagger < 0)) 192 return; 193 if (drm_WARN_ON(display->drm, vsc_ext_stagger < 0)) 194 return; 195 196 intel_de_write(display, CMN_SDP_TL_STGR_CTL(display, cpu_transcoder), 197 GMP_STAGGER(gmp_stagger) | 198 PPS_STAGGER(pps_stagger) | 199 VSC_EXT_STAGGER(vsc_ext_stagger)); 200 201 intel_de_write(display, CMN_SDP_TL(display, cpu_transcoder), 202 TRANSMISSION_LINE_ENABLE | 203 BASE_TRANSMISSION_LINE(crtc_state->dip.cmn_sdp_tl)); 204 } 205 206 void intel_dip_cmn_sdp_transmission_line_disable(const struct intel_crtc_state *old_crtc_state) 207 { 208 struct intel_display *display = to_intel_display(old_crtc_state); 209 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 210 211 if (!HAS_COMMON_SDP_TL(display)) 212 return; 213 214 intel_de_write(display, CMN_SDP_TL(display, cpu_transcoder), 0); 215 } 216