1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corporation
5 * Author: Gaurav K Singh <gaurav.k.singh@intel.com>
6 * Manasi Navare <manasi.d.navare@intel.com>
9 #include <drm/i915_drm.h>
11 #include "intel_drv.h"
22 enum COLUMN_INDEX_BPC {
23 COLUMN_INDEX_8BPC = 0,
31 #define DSC_SUPPORTED_VERSION_MIN 1
33 /* From DSC_v1.11 spec, rc_parameter_Set syntax element typically constant */
34 static u16 rc_buf_thresh[] = {
35 896, 1792, 2688, 3584, 4480, 5376, 6272, 6720, 7168, 7616,
36 7744, 7872, 8000, 8064
39 struct rc_parameters {
40 u16 initial_xmit_delay;
41 u8 first_line_bpg_offset;
45 u8 rc_quant_incr_limit0;
46 u8 rc_quant_incr_limit1;
47 struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];
51 * Selected Rate Control Related Parameter Recommended Values
52 * from DSC_v1.11 spec & C Model release: DSC_model_20161212
54 static struct rc_parameters rc_params[][MAX_COLUMN_INDEX] = {
57 { 768, 15, 6144, 3, 13, 11, 11, {
58 { 0, 4, 0 }, { 1, 6, -2 }, { 3, 8, -2 }, { 4, 8, -4 },
59 { 5, 9, -6 }, { 5, 9, -6 }, { 6, 9, -6 }, { 6, 10, -8 },
60 { 7, 11, -8 }, { 8, 12, -10 }, { 9, 12, -10 }, { 10, 12, -12 },
61 { 10, 12, -12 }, { 11, 12, -12 }, { 13, 14, -12 }
65 { 768, 15, 6144, 7, 17, 15, 15, {
66 { 0, 8, 0 }, { 3, 10, -2 }, { 7, 12, -2 }, { 8, 12, -4 },
67 { 9, 13, -6 }, { 9, 13, -6 }, { 10, 13, -6 }, { 10, 14, -8 },
68 { 11, 15, -8 }, { 12, 16, -10 }, { 13, 16, -10 },
69 { 14, 16, -12 }, { 14, 16, -12 }, { 15, 16, -12 },
74 { 768, 15, 6144, 11, 21, 19, 19, {
75 { 0, 12, 0 }, { 5, 14, -2 }, { 11, 16, -2 }, { 12, 16, -4 },
76 { 13, 17, -6 }, { 13, 17, -6 }, { 14, 17, -6 }, { 14, 18, -8 },
77 { 15, 19, -8 }, { 16, 20, -10 }, { 17, 20, -10 },
78 { 18, 20, -12 }, { 18, 20, -12 }, { 19, 20, -12 },
83 { 768, 15, 6144, 15, 25, 23, 27, {
84 { 0, 16, 0 }, { 7, 18, -2 }, { 15, 20, -2 }, { 16, 20, -4 },
85 { 17, 21, -6 }, { 17, 21, -6 }, { 18, 21, -6 }, { 18, 22, -8 },
86 { 19, 23, -8 }, { 20, 24, -10 }, { 21, 24, -10 },
87 { 22, 24, -12 }, { 22, 24, -12 }, { 23, 24, -12 },
92 { 768, 15, 6144, 19, 29, 27, 27, {
93 { 0, 20, 0 }, { 9, 22, -2 }, { 19, 24, -2 }, { 20, 24, -4 },
94 { 21, 25, -6 }, { 21, 25, -6 }, { 22, 25, -6 }, { 22, 26, -8 },
95 { 23, 27, -8 }, { 24, 28, -10 }, { 25, 28, -10 },
96 { 26, 28, -12 }, { 26, 28, -12 }, { 27, 28, -12 },
103 { 512, 12, 6144, 3, 12, 11, 11, {
104 { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
105 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
106 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 }, { 5, 12, -12 },
107 { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
111 { 512, 12, 6144, 7, 16, 15, 15, {
112 { 0, 4, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
113 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
114 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
115 { 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
119 { 512, 12, 6144, 11, 20, 19, 19, {
120 { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
121 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
122 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
123 { 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
128 { 512, 12, 6144, 15, 24, 23, 23, {
129 { 0, 12, 0 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
130 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
131 { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
132 { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
137 { 512, 12, 6144, 19, 28, 27, 27, {
138 { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
139 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
140 { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
141 { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
148 { 410, 15, 5632, 3, 12, 11, 11, {
149 { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
150 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
151 { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
152 { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
156 { 410, 15, 5632, 7, 16, 15, 15, {
157 { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
158 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
159 { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
160 { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
164 { 410, 15, 5632, 11, 20, 19, 19, {
165 { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
166 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
167 { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
168 { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
173 { 410, 15, 5632, 15, 24, 23, 23, {
174 { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
175 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
176 { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
177 { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
182 { 410, 15, 5632, 19, 28, 27, 27, {
183 { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
184 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
185 { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
186 { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
193 { 341, 15, 2048, 3, 12, 11, 11, {
194 { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
195 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
196 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 },
197 { 5, 12, -12 }, { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
201 { 341, 15, 2048, 7, 16, 15, 15, {
202 { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
203 { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
204 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
205 { 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
209 { 341, 15, 2048, 11, 20, 19, 19, {
210 { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
211 { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
212 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
213 { 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
218 { 341, 15, 2048, 15, 24, 23, 23, {
219 { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
220 { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
221 { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
222 { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
227 { 341, 15, 2048, 19, 28, 27, 27, {
228 { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
229 { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
230 { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
231 { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
238 { 273, 15, 2048, 3, 12, 11, 11, {
239 { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
240 { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
241 { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
242 { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
246 { 273, 15, 2048, 7, 16, 15, 15, {
247 { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
248 { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
249 { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
250 { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
254 { 273, 15, 2048, 11, 20, 19, 19, {
255 { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
256 { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
257 { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
258 { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
263 { 273, 15, 2048, 15, 24, 23, 23, {
264 { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
265 { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
266 { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
267 { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
272 { 273, 15, 2048, 19, 28, 27, 27, {
273 { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
274 { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
275 { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
276 { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
284 static int get_row_index_for_rc_params(u16 compressed_bpp)
286 switch (compressed_bpp) {
288 return ROW_INDEX_6BPP;
290 return ROW_INDEX_8BPP;
292 return ROW_INDEX_10BPP;
294 return ROW_INDEX_12BPP;
296 return ROW_INDEX_15BPP;
302 static int get_column_index_for_rc_params(u8 bits_per_component)
304 switch (bits_per_component) {
306 return COLUMN_INDEX_8BPC;
308 return COLUMN_INDEX_10BPC;
310 return COLUMN_INDEX_12BPC;
312 return COLUMN_INDEX_14BPC;
314 return COLUMN_INDEX_16BPC;
320 int intel_dp_compute_dsc_params(struct intel_dp *intel_dp,
321 struct intel_crtc_state *pipe_config)
323 struct drm_dsc_config *vdsc_cfg = &pipe_config->dp_dsc_cfg;
324 u16 compressed_bpp = pipe_config->dsc_params.compressed_bpp;
327 int column_index = 0;
328 u8 line_buf_depth = 0;
330 vdsc_cfg->pic_width = pipe_config->base.adjusted_mode.crtc_hdisplay;
331 vdsc_cfg->pic_height = pipe_config->base.adjusted_mode.crtc_vdisplay;
332 vdsc_cfg->slice_width = DIV_ROUND_UP(vdsc_cfg->pic_width,
333 pipe_config->dsc_params.slice_count);
335 * Slice Height of 8 works for all currently available panels. So start
336 * with that if pic_height is an integral multiple of 8.
337 * Eventually add logic to try multiple slice heights.
339 if (vdsc_cfg->pic_height % 8 == 0)
340 vdsc_cfg->slice_height = 8;
341 else if (vdsc_cfg->pic_height % 4 == 0)
342 vdsc_cfg->slice_height = 4;
344 vdsc_cfg->slice_height = 2;
346 /* Values filled from DSC Sink DPCD */
347 vdsc_cfg->dsc_version_major =
348 (intel_dp->dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] &
349 DP_DSC_MAJOR_MASK) >> DP_DSC_MAJOR_SHIFT;
350 vdsc_cfg->dsc_version_minor =
351 min(DSC_SUPPORTED_VERSION_MIN,
352 (intel_dp->dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] &
353 DP_DSC_MINOR_MASK) >> DP_DSC_MINOR_SHIFT);
355 vdsc_cfg->convert_rgb = intel_dp->dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] &
358 line_buf_depth = drm_dp_dsc_sink_line_buf_depth(intel_dp->dsc_dpcd);
359 if (!line_buf_depth) {
360 DRM_DEBUG_KMS("DSC Sink Line Buffer Depth invalid\n");
363 if (vdsc_cfg->dsc_version_minor == 2)
364 vdsc_cfg->line_buf_depth = (line_buf_depth == DSC_1_2_MAX_LINEBUF_DEPTH_BITS) ?
365 DSC_1_2_MAX_LINEBUF_DEPTH_VAL : line_buf_depth;
367 vdsc_cfg->line_buf_depth = (line_buf_depth > DSC_1_1_MAX_LINEBUF_DEPTH_BITS) ?
368 DSC_1_1_MAX_LINEBUF_DEPTH_BITS : line_buf_depth;
370 /* Gen 11 does not support YCbCr */
371 vdsc_cfg->simple_422 = false;
372 /* Gen 11 does not support VBR */
373 vdsc_cfg->vbr_enable = false;
374 vdsc_cfg->block_pred_enable =
375 intel_dp->dsc_dpcd[DP_DSC_BLK_PREDICTION_SUPPORT - DP_DSC_SUPPORT] &
376 DP_DSC_BLK_PREDICTION_IS_SUPPORTED;
378 /* Gen 11 only supports integral values of bpp */
379 vdsc_cfg->bits_per_pixel = compressed_bpp << 4;
380 vdsc_cfg->bits_per_component = pipe_config->pipe_bpp / 3;
382 for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++) {
384 * six 0s are appended to the lsb of each threshold value
386 * Only 8 bits are allowed for programming RcBufThreshold
388 vdsc_cfg->rc_buf_thresh[i] = rc_buf_thresh[i] >> 6;
392 * For 6bpp, RC Buffer threshold 12 and 13 need a different value
395 if (compressed_bpp == 6) {
396 vdsc_cfg->rc_buf_thresh[12] = 0x7C;
397 vdsc_cfg->rc_buf_thresh[13] = 0x7D;
400 row_index = get_row_index_for_rc_params(compressed_bpp);
402 get_column_index_for_rc_params(vdsc_cfg->bits_per_component);
404 if (row_index < 0 || column_index < 0)
407 vdsc_cfg->first_line_bpg_offset =
408 rc_params[row_index][column_index].first_line_bpg_offset;
409 vdsc_cfg->initial_xmit_delay =
410 rc_params[row_index][column_index].initial_xmit_delay;
411 vdsc_cfg->initial_offset =
412 rc_params[row_index][column_index].initial_offset;
413 vdsc_cfg->flatness_min_qp =
414 rc_params[row_index][column_index].flatness_min_qp;
415 vdsc_cfg->flatness_max_qp =
416 rc_params[row_index][column_index].flatness_max_qp;
417 vdsc_cfg->rc_quant_incr_limit0 =
418 rc_params[row_index][column_index].rc_quant_incr_limit0;
419 vdsc_cfg->rc_quant_incr_limit1 =
420 rc_params[row_index][column_index].rc_quant_incr_limit1;
422 for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
423 vdsc_cfg->rc_range_params[i].range_min_qp =
424 rc_params[row_index][column_index].rc_range_params[i].range_min_qp;
425 vdsc_cfg->rc_range_params[i].range_max_qp =
426 rc_params[row_index][column_index].rc_range_params[i].range_max_qp;
428 * Range BPG Offset uses 2's complement and is only a 6 bits. So
429 * mask it to get only 6 bits.
431 vdsc_cfg->rc_range_params[i].range_bpg_offset =
432 rc_params[row_index][column_index].rc_range_params[i].range_bpg_offset &
433 DSC_RANGE_BPG_OFFSET_MASK;
437 * BitsPerComponent value determines mux_word_size:
438 * When BitsPerComponent is 12bpc, muxWordSize will be equal to 64 bits
439 * When BitsPerComponent is 8 or 10bpc, muxWordSize will be equal to
442 if (vdsc_cfg->bits_per_component == 8 ||
443 vdsc_cfg->bits_per_component == 10)
444 vdsc_cfg->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
445 else if (vdsc_cfg->bits_per_component == 12)
446 vdsc_cfg->mux_word_size = DSC_MUX_WORD_SIZE_12_BPC;
448 /* RC_MODEL_SIZE is a constant across all configurations */
449 vdsc_cfg->rc_model_size = DSC_RC_MODEL_SIZE_CONST;
450 /* InitialScaleValue is a 6 bit value with 3 fractional bits (U3.3) */
451 vdsc_cfg->initial_scale_value = (vdsc_cfg->rc_model_size << 3) /
452 (vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset);
454 return drm_dsc_compute_rc_parameters(vdsc_cfg);
457 enum intel_display_power_domain
458 intel_dsc_power_domain(const struct intel_crtc_state *crtc_state)
460 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
463 * On ICL VDSC/joining for eDP transcoder uses a separate power well PW2
464 * This requires POWER_DOMAIN_TRANSCODER_EDP_VDSC power domain.
465 * For any other transcoder, VDSC/joining uses the power well associated
466 * with the pipe/transcoder in use. Hence another reference on the
467 * transcoder power domain will suffice.
469 if (cpu_transcoder == TRANSCODER_EDP)
470 return POWER_DOMAIN_TRANSCODER_EDP_VDSC;
472 return POWER_DOMAIN_TRANSCODER(cpu_transcoder);
475 static void intel_configure_pps_for_dsc_encoder(struct intel_encoder *encoder,
476 const struct intel_crtc_state *crtc_state)
478 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
479 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
480 const struct drm_dsc_config *vdsc_cfg = &crtc_state->dp_dsc_cfg;
481 enum pipe pipe = crtc->pipe;
482 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
484 u32 rc_buf_thresh_dword[4];
485 u32 rc_range_params_dword[8];
486 u8 num_vdsc_instances = (crtc_state->dsc_params.dsc_split) ? 2 : 1;
489 /* Populate PICTURE_PARAMETER_SET_0 registers */
490 pps_val = DSC_VER_MAJ | vdsc_cfg->dsc_version_minor <<
492 vdsc_cfg->bits_per_component << DSC_BPC_SHIFT |
493 vdsc_cfg->line_buf_depth << DSC_LINE_BUF_DEPTH_SHIFT;
494 if (vdsc_cfg->block_pred_enable)
495 pps_val |= DSC_BLOCK_PREDICTION;
496 if (vdsc_cfg->convert_rgb)
497 pps_val |= DSC_COLOR_SPACE_CONVERSION;
498 if (vdsc_cfg->simple_422)
499 pps_val |= DSC_422_ENABLE;
500 if (vdsc_cfg->vbr_enable)
501 pps_val |= DSC_VBR_ENABLE;
502 DRM_INFO("PPS0 = 0x%08x\n", pps_val);
503 if (cpu_transcoder == TRANSCODER_EDP) {
504 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_0, pps_val);
506 * If 2 VDSC instances are needed, configure PPS for second
509 if (crtc_state->dsc_params.dsc_split)
510 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_0, pps_val);
512 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_0(pipe), pps_val);
513 if (crtc_state->dsc_params.dsc_split)
514 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_0(pipe),
518 /* Populate PICTURE_PARAMETER_SET_1 registers */
520 pps_val |= DSC_BPP(vdsc_cfg->bits_per_pixel);
521 DRM_INFO("PPS1 = 0x%08x\n", pps_val);
522 if (cpu_transcoder == TRANSCODER_EDP) {
523 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_1, pps_val);
525 * If 2 VDSC instances are needed, configure PPS for second
528 if (crtc_state->dsc_params.dsc_split)
529 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_1, pps_val);
531 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_1(pipe), pps_val);
532 if (crtc_state->dsc_params.dsc_split)
533 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_1(pipe),
537 /* Populate PICTURE_PARAMETER_SET_2 registers */
539 pps_val |= DSC_PIC_HEIGHT(vdsc_cfg->pic_height) |
540 DSC_PIC_WIDTH(vdsc_cfg->pic_width / num_vdsc_instances);
541 DRM_INFO("PPS2 = 0x%08x\n", pps_val);
542 if (encoder->type == INTEL_OUTPUT_EDP) {
543 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_2, pps_val);
545 * If 2 VDSC instances are needed, configure PPS for second
548 if (crtc_state->dsc_params.dsc_split)
549 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_2, pps_val);
551 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_2(pipe), pps_val);
552 if (crtc_state->dsc_params.dsc_split)
553 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_2(pipe),
557 /* Populate PICTURE_PARAMETER_SET_3 registers */
559 pps_val |= DSC_SLICE_HEIGHT(vdsc_cfg->slice_height) |
560 DSC_SLICE_WIDTH(vdsc_cfg->slice_width);
561 DRM_INFO("PPS3 = 0x%08x\n", pps_val);
562 if (cpu_transcoder == TRANSCODER_EDP) {
563 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_3, pps_val);
565 * If 2 VDSC instances are needed, configure PPS for second
568 if (crtc_state->dsc_params.dsc_split)
569 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_3, pps_val);
571 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_3(pipe), pps_val);
572 if (crtc_state->dsc_params.dsc_split)
573 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_3(pipe),
577 /* Populate PICTURE_PARAMETER_SET_4 registers */
579 pps_val |= DSC_INITIAL_XMIT_DELAY(vdsc_cfg->initial_xmit_delay) |
580 DSC_INITIAL_DEC_DELAY(vdsc_cfg->initial_dec_delay);
581 DRM_INFO("PPS4 = 0x%08x\n", pps_val);
582 if (cpu_transcoder == TRANSCODER_EDP) {
583 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_4, pps_val);
585 * If 2 VDSC instances are needed, configure PPS for second
588 if (crtc_state->dsc_params.dsc_split)
589 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_4, pps_val);
591 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_4(pipe), pps_val);
592 if (crtc_state->dsc_params.dsc_split)
593 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_4(pipe),
597 /* Populate PICTURE_PARAMETER_SET_5 registers */
599 pps_val |= DSC_SCALE_INC_INT(vdsc_cfg->scale_increment_interval) |
600 DSC_SCALE_DEC_INT(vdsc_cfg->scale_decrement_interval);
601 DRM_INFO("PPS5 = 0x%08x\n", pps_val);
602 if (cpu_transcoder == TRANSCODER_EDP) {
603 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_5, pps_val);
605 * If 2 VDSC instances are needed, configure PPS for second
608 if (crtc_state->dsc_params.dsc_split)
609 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_5, pps_val);
611 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_5(pipe), pps_val);
612 if (crtc_state->dsc_params.dsc_split)
613 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_5(pipe),
617 /* Populate PICTURE_PARAMETER_SET_6 registers */
619 pps_val |= DSC_INITIAL_SCALE_VALUE(vdsc_cfg->initial_scale_value) |
620 DSC_FIRST_LINE_BPG_OFFSET(vdsc_cfg->first_line_bpg_offset) |
621 DSC_FLATNESS_MIN_QP(vdsc_cfg->flatness_min_qp) |
622 DSC_FLATNESS_MAX_QP(vdsc_cfg->flatness_max_qp);
623 DRM_INFO("PPS6 = 0x%08x\n", pps_val);
624 if (cpu_transcoder == TRANSCODER_EDP) {
625 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_6, pps_val);
627 * If 2 VDSC instances are needed, configure PPS for second
630 if (crtc_state->dsc_params.dsc_split)
631 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_6, pps_val);
633 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_6(pipe), pps_val);
634 if (crtc_state->dsc_params.dsc_split)
635 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_6(pipe),
639 /* Populate PICTURE_PARAMETER_SET_7 registers */
641 pps_val |= DSC_SLICE_BPG_OFFSET(vdsc_cfg->slice_bpg_offset) |
642 DSC_NFL_BPG_OFFSET(vdsc_cfg->nfl_bpg_offset);
643 DRM_INFO("PPS7 = 0x%08x\n", pps_val);
644 if (cpu_transcoder == TRANSCODER_EDP) {
645 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_7, pps_val);
647 * If 2 VDSC instances are needed, configure PPS for second
650 if (crtc_state->dsc_params.dsc_split)
651 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_7, pps_val);
653 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_7(pipe), pps_val);
654 if (crtc_state->dsc_params.dsc_split)
655 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_7(pipe),
659 /* Populate PICTURE_PARAMETER_SET_8 registers */
661 pps_val |= DSC_FINAL_OFFSET(vdsc_cfg->final_offset) |
662 DSC_INITIAL_OFFSET(vdsc_cfg->initial_offset);
663 DRM_INFO("PPS8 = 0x%08x\n", pps_val);
664 if (cpu_transcoder == TRANSCODER_EDP) {
665 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_8, pps_val);
667 * If 2 VDSC instances are needed, configure PPS for second
670 if (crtc_state->dsc_params.dsc_split)
671 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_8, pps_val);
673 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_8(pipe), pps_val);
674 if (crtc_state->dsc_params.dsc_split)
675 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_8(pipe),
679 /* Populate PICTURE_PARAMETER_SET_9 registers */
681 pps_val |= DSC_RC_MODEL_SIZE(DSC_RC_MODEL_SIZE_CONST) |
682 DSC_RC_EDGE_FACTOR(DSC_RC_EDGE_FACTOR_CONST);
683 DRM_INFO("PPS9 = 0x%08x\n", pps_val);
684 if (cpu_transcoder == TRANSCODER_EDP) {
685 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_9, pps_val);
687 * If 2 VDSC instances are needed, configure PPS for second
690 if (crtc_state->dsc_params.dsc_split)
691 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_9, pps_val);
693 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_9(pipe), pps_val);
694 if (crtc_state->dsc_params.dsc_split)
695 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_9(pipe),
699 /* Populate PICTURE_PARAMETER_SET_10 registers */
701 pps_val |= DSC_RC_QUANT_INC_LIMIT0(vdsc_cfg->rc_quant_incr_limit0) |
702 DSC_RC_QUANT_INC_LIMIT1(vdsc_cfg->rc_quant_incr_limit1) |
703 DSC_RC_TARGET_OFF_HIGH(DSC_RC_TGT_OFFSET_HI_CONST) |
704 DSC_RC_TARGET_OFF_LOW(DSC_RC_TGT_OFFSET_LO_CONST);
705 DRM_INFO("PPS10 = 0x%08x\n", pps_val);
706 if (cpu_transcoder == TRANSCODER_EDP) {
707 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_10, pps_val);
709 * If 2 VDSC instances are needed, configure PPS for second
712 if (crtc_state->dsc_params.dsc_split)
713 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_10, pps_val);
715 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_10(pipe), pps_val);
716 if (crtc_state->dsc_params.dsc_split)
717 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_10(pipe),
721 /* Populate Picture parameter set 16 */
723 pps_val |= DSC_SLICE_CHUNK_SIZE(vdsc_cfg->slice_chunk_size) |
724 DSC_SLICE_PER_LINE((vdsc_cfg->pic_width / num_vdsc_instances) /
725 vdsc_cfg->slice_width) |
726 DSC_SLICE_ROW_PER_FRAME(vdsc_cfg->pic_height /
727 vdsc_cfg->slice_height);
728 DRM_INFO("PPS16 = 0x%08x\n", pps_val);
729 if (cpu_transcoder == TRANSCODER_EDP) {
730 I915_WRITE(DSCA_PICTURE_PARAMETER_SET_16, pps_val);
732 * If 2 VDSC instances are needed, configure PPS for second
735 if (crtc_state->dsc_params.dsc_split)
736 I915_WRITE(DSCC_PICTURE_PARAMETER_SET_16, pps_val);
738 I915_WRITE(ICL_DSC0_PICTURE_PARAMETER_SET_16(pipe), pps_val);
739 if (crtc_state->dsc_params.dsc_split)
740 I915_WRITE(ICL_DSC1_PICTURE_PARAMETER_SET_16(pipe),
744 /* Populate the RC_BUF_THRESH registers */
745 memset(rc_buf_thresh_dword, 0, sizeof(rc_buf_thresh_dword));
746 for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++) {
747 rc_buf_thresh_dword[i / 4] |=
748 (u32)(vdsc_cfg->rc_buf_thresh[i] <<
749 BITS_PER_BYTE * (i % 4));
750 DRM_INFO(" RC_BUF_THRESH%d = 0x%08x\n", i,
751 rc_buf_thresh_dword[i / 4]);
753 if (cpu_transcoder == TRANSCODER_EDP) {
754 I915_WRITE(DSCA_RC_BUF_THRESH_0, rc_buf_thresh_dword[0]);
755 I915_WRITE(DSCA_RC_BUF_THRESH_0_UDW, rc_buf_thresh_dword[1]);
756 I915_WRITE(DSCA_RC_BUF_THRESH_1, rc_buf_thresh_dword[2]);
757 I915_WRITE(DSCA_RC_BUF_THRESH_1_UDW, rc_buf_thresh_dword[3]);
758 if (crtc_state->dsc_params.dsc_split) {
759 I915_WRITE(DSCC_RC_BUF_THRESH_0,
760 rc_buf_thresh_dword[0]);
761 I915_WRITE(DSCC_RC_BUF_THRESH_0_UDW,
762 rc_buf_thresh_dword[1]);
763 I915_WRITE(DSCC_RC_BUF_THRESH_1,
764 rc_buf_thresh_dword[2]);
765 I915_WRITE(DSCC_RC_BUF_THRESH_1_UDW,
766 rc_buf_thresh_dword[3]);
769 I915_WRITE(ICL_DSC0_RC_BUF_THRESH_0(pipe),
770 rc_buf_thresh_dword[0]);
771 I915_WRITE(ICL_DSC0_RC_BUF_THRESH_0_UDW(pipe),
772 rc_buf_thresh_dword[1]);
773 I915_WRITE(ICL_DSC0_RC_BUF_THRESH_1(pipe),
774 rc_buf_thresh_dword[2]);
775 I915_WRITE(ICL_DSC0_RC_BUF_THRESH_1_UDW(pipe),
776 rc_buf_thresh_dword[3]);
777 if (crtc_state->dsc_params.dsc_split) {
778 I915_WRITE(ICL_DSC1_RC_BUF_THRESH_0(pipe),
779 rc_buf_thresh_dword[0]);
780 I915_WRITE(ICL_DSC1_RC_BUF_THRESH_0_UDW(pipe),
781 rc_buf_thresh_dword[1]);
782 I915_WRITE(ICL_DSC1_RC_BUF_THRESH_1(pipe),
783 rc_buf_thresh_dword[2]);
784 I915_WRITE(ICL_DSC1_RC_BUF_THRESH_1_UDW(pipe),
785 rc_buf_thresh_dword[3]);
789 /* Populate the RC_RANGE_PARAMETERS registers */
790 memset(rc_range_params_dword, 0, sizeof(rc_range_params_dword));
791 for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
792 rc_range_params_dword[i / 2] |=
793 (u32)(((vdsc_cfg->rc_range_params[i].range_bpg_offset <<
794 RC_BPG_OFFSET_SHIFT) |
795 (vdsc_cfg->rc_range_params[i].range_max_qp <<
797 (vdsc_cfg->rc_range_params[i].range_min_qp <<
798 RC_MIN_QP_SHIFT)) << 16 * (i % 2));
799 DRM_INFO(" RC_RANGE_PARAM_%d = 0x%08x\n", i,
800 rc_range_params_dword[i / 2]);
802 if (cpu_transcoder == TRANSCODER_EDP) {
803 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_0,
804 rc_range_params_dword[0]);
805 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_0_UDW,
806 rc_range_params_dword[1]);
807 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_1,
808 rc_range_params_dword[2]);
809 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_1_UDW,
810 rc_range_params_dword[3]);
811 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_2,
812 rc_range_params_dword[4]);
813 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_2_UDW,
814 rc_range_params_dword[5]);
815 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_3,
816 rc_range_params_dword[6]);
817 I915_WRITE(DSCA_RC_RANGE_PARAMETERS_3_UDW,
818 rc_range_params_dword[7]);
819 if (crtc_state->dsc_params.dsc_split) {
820 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_0,
821 rc_range_params_dword[0]);
822 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_0_UDW,
823 rc_range_params_dword[1]);
824 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_1,
825 rc_range_params_dword[2]);
826 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_1_UDW,
827 rc_range_params_dword[3]);
828 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_2,
829 rc_range_params_dword[4]);
830 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_2_UDW,
831 rc_range_params_dword[5]);
832 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_3,
833 rc_range_params_dword[6]);
834 I915_WRITE(DSCC_RC_RANGE_PARAMETERS_3_UDW,
835 rc_range_params_dword[7]);
838 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_0(pipe),
839 rc_range_params_dword[0]);
840 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_0_UDW(pipe),
841 rc_range_params_dword[1]);
842 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_1(pipe),
843 rc_range_params_dword[2]);
844 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_1_UDW(pipe),
845 rc_range_params_dword[3]);
846 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_2(pipe),
847 rc_range_params_dword[4]);
848 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_2_UDW(pipe),
849 rc_range_params_dword[5]);
850 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_3(pipe),
851 rc_range_params_dword[6]);
852 I915_WRITE(ICL_DSC0_RC_RANGE_PARAMETERS_3_UDW(pipe),
853 rc_range_params_dword[7]);
854 if (crtc_state->dsc_params.dsc_split) {
855 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_0(pipe),
856 rc_range_params_dword[0]);
857 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_0_UDW(pipe),
858 rc_range_params_dword[1]);
859 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_1(pipe),
860 rc_range_params_dword[2]);
861 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_1_UDW(pipe),
862 rc_range_params_dword[3]);
863 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_2(pipe),
864 rc_range_params_dword[4]);
865 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_2_UDW(pipe),
866 rc_range_params_dword[5]);
867 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_3(pipe),
868 rc_range_params_dword[6]);
869 I915_WRITE(ICL_DSC1_RC_RANGE_PARAMETERS_3_UDW(pipe),
870 rc_range_params_dword[7]);
875 static void intel_dp_write_dsc_pps_sdp(struct intel_encoder *encoder,
876 const struct intel_crtc_state *crtc_state)
878 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
879 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
880 const struct drm_dsc_config *vdsc_cfg = &crtc_state->dp_dsc_cfg;
881 struct drm_dsc_pps_infoframe dp_dsc_pps_sdp;
883 /* Prepare DP SDP PPS header as per DP 1.4 spec, Table 2-123 */
884 drm_dsc_dp_pps_header_init(&dp_dsc_pps_sdp.pps_header);
886 /* Fill the PPS payload bytes as per DSC spec 1.2 Table 4-1 */
887 drm_dsc_pps_payload_pack(&dp_dsc_pps_sdp.pps_payload, vdsc_cfg);
889 intel_dig_port->write_infoframe(encoder, crtc_state,
890 DP_SDP_PPS, &dp_dsc_pps_sdp,
891 sizeof(dp_dsc_pps_sdp));
894 void intel_dsc_enable(struct intel_encoder *encoder,
895 const struct intel_crtc_state *crtc_state)
897 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
898 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
899 enum pipe pipe = crtc->pipe;
900 i915_reg_t dss_ctl1_reg, dss_ctl2_reg;
901 u32 dss_ctl1_val = 0;
902 u32 dss_ctl2_val = 0;
904 if (!crtc_state->dsc_params.compression_enable)
907 /* Enable Power wells for VDSC/joining */
908 intel_display_power_get(dev_priv,
909 intel_dsc_power_domain(crtc_state));
911 intel_configure_pps_for_dsc_encoder(encoder, crtc_state);
913 intel_dp_write_dsc_pps_sdp(encoder, crtc_state);
915 if (crtc_state->cpu_transcoder == TRANSCODER_EDP) {
916 dss_ctl1_reg = DSS_CTL1;
917 dss_ctl2_reg = DSS_CTL2;
919 dss_ctl1_reg = ICL_PIPE_DSS_CTL1(pipe);
920 dss_ctl2_reg = ICL_PIPE_DSS_CTL2(pipe);
922 dss_ctl2_val |= LEFT_BRANCH_VDSC_ENABLE;
923 if (crtc_state->dsc_params.dsc_split) {
924 dss_ctl2_val |= RIGHT_BRANCH_VDSC_ENABLE;
925 dss_ctl1_val |= JOINER_ENABLE;
927 I915_WRITE(dss_ctl1_reg, dss_ctl1_val);
928 I915_WRITE(dss_ctl2_reg, dss_ctl2_val);
931 void intel_dsc_disable(const struct intel_crtc_state *old_crtc_state)
933 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
934 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
935 enum pipe pipe = crtc->pipe;
936 i915_reg_t dss_ctl1_reg, dss_ctl2_reg;
937 u32 dss_ctl1_val = 0, dss_ctl2_val = 0;
939 if (!old_crtc_state->dsc_params.compression_enable)
942 if (old_crtc_state->cpu_transcoder == TRANSCODER_EDP) {
943 dss_ctl1_reg = DSS_CTL1;
944 dss_ctl2_reg = DSS_CTL2;
946 dss_ctl1_reg = ICL_PIPE_DSS_CTL1(pipe);
947 dss_ctl2_reg = ICL_PIPE_DSS_CTL2(pipe);
949 dss_ctl1_val = I915_READ(dss_ctl1_reg);
950 if (dss_ctl1_val & JOINER_ENABLE)
951 dss_ctl1_val &= ~JOINER_ENABLE;
952 I915_WRITE(dss_ctl1_reg, dss_ctl1_val);
954 dss_ctl2_val = I915_READ(dss_ctl2_reg);
955 if (dss_ctl2_val & LEFT_BRANCH_VDSC_ENABLE ||
956 dss_ctl2_val & RIGHT_BRANCH_VDSC_ENABLE)
957 dss_ctl2_val &= ~(LEFT_BRANCH_VDSC_ENABLE |
958 RIGHT_BRANCH_VDSC_ENABLE);
959 I915_WRITE(dss_ctl2_reg, dss_ctl2_val);
961 /* Disable Power wells for VDSC/joining */
962 intel_display_power_put_unchecked(dev_priv,
963 intel_dsc_power_domain(old_crtc_state));