xref: /linux/drivers/gpu/drm/display/drm_dsc_helper.c (revision e871a70d8ccd6dbcb30f081f5d3d8854380422fe)
12a64b147SThomas Zimmermann // SPDX-License-Identifier: MIT
22a64b147SThomas Zimmermann /*
32a64b147SThomas Zimmermann  * Copyright © 2018 Intel Corp
42a64b147SThomas Zimmermann  *
52a64b147SThomas Zimmermann  * Author:
62a64b147SThomas Zimmermann  * Manasi Navare <manasi.d.navare@intel.com>
72a64b147SThomas Zimmermann  */
82a64b147SThomas Zimmermann 
92a64b147SThomas Zimmermann #include <linux/kernel.h>
102a64b147SThomas Zimmermann #include <linux/module.h>
112a64b147SThomas Zimmermann #include <linux/init.h>
122a64b147SThomas Zimmermann #include <linux/errno.h>
132a64b147SThomas Zimmermann #include <linux/byteorder/generic.h>
142a64b147SThomas Zimmermann 
152a64b147SThomas Zimmermann #include <drm/display/drm_dp_helper.h>
162a64b147SThomas Zimmermann #include <drm/display/drm_dsc_helper.h>
172a64b147SThomas Zimmermann #include <drm/drm_print.h>
182a64b147SThomas Zimmermann 
192a64b147SThomas Zimmermann /**
202a64b147SThomas Zimmermann  * DOC: dsc helpers
212a64b147SThomas Zimmermann  *
222a64b147SThomas Zimmermann  * VESA specification for DP 1.4 adds a new feature called Display Stream
232a64b147SThomas Zimmermann  * Compression (DSC) used to compress the pixel bits before sending it on
242a64b147SThomas Zimmermann  * DP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existing
252a64b147SThomas Zimmermann  * display interfaces can support high resolutions at higher frames rates uisng
262a64b147SThomas Zimmermann  * the maximum available link capacity of these interfaces.
272a64b147SThomas Zimmermann  *
282a64b147SThomas Zimmermann  * These functions contain some common logic and helpers to deal with VESA
292a64b147SThomas Zimmermann  * Display Stream Compression standard required for DSC on Display Port/eDP or
302a64b147SThomas Zimmermann  * MIPI display interfaces.
312a64b147SThomas Zimmermann  */
322a64b147SThomas Zimmermann 
332a64b147SThomas Zimmermann /**
342a64b147SThomas Zimmermann  * drm_dsc_dp_pps_header_init() - Initializes the PPS Header
352a64b147SThomas Zimmermann  * for DisplayPort as per the DP 1.4 spec.
362a64b147SThomas Zimmermann  * @pps_header: Secondary data packet header for DSC Picture
372a64b147SThomas Zimmermann  *              Parameter Set as defined in &struct dp_sdp_header
382a64b147SThomas Zimmermann  *
392a64b147SThomas Zimmermann  * DP 1.4 spec defines the secondary data packet for sending the
402a64b147SThomas Zimmermann  * picture parameter infoframes from the source to the sink.
412a64b147SThomas Zimmermann  * This function populates the SDP header defined in
422a64b147SThomas Zimmermann  * &struct dp_sdp_header.
432a64b147SThomas Zimmermann  */
442a64b147SThomas Zimmermann void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header)
452a64b147SThomas Zimmermann {
462a64b147SThomas Zimmermann 	memset(pps_header, 0, sizeof(*pps_header));
472a64b147SThomas Zimmermann 
482a64b147SThomas Zimmermann 	pps_header->HB1 = DP_SDP_PPS;
492a64b147SThomas Zimmermann 	pps_header->HB2 = DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1;
502a64b147SThomas Zimmermann }
512a64b147SThomas Zimmermann EXPORT_SYMBOL(drm_dsc_dp_pps_header_init);
522a64b147SThomas Zimmermann 
532a64b147SThomas Zimmermann /**
542a64b147SThomas Zimmermann  * drm_dsc_dp_rc_buffer_size - get rc buffer size in bytes
552a64b147SThomas Zimmermann  * @rc_buffer_block_size: block size code, according to DPCD offset 62h
562a64b147SThomas Zimmermann  * @rc_buffer_size: number of blocks - 1, according to DPCD offset 63h
572a64b147SThomas Zimmermann  *
582a64b147SThomas Zimmermann  * return:
592a64b147SThomas Zimmermann  * buffer size in bytes, or 0 on invalid input
602a64b147SThomas Zimmermann  */
612a64b147SThomas Zimmermann int drm_dsc_dp_rc_buffer_size(u8 rc_buffer_block_size, u8 rc_buffer_size)
622a64b147SThomas Zimmermann {
632a64b147SThomas Zimmermann 	int size = 1024 * (rc_buffer_size + 1);
642a64b147SThomas Zimmermann 
652a64b147SThomas Zimmermann 	switch (rc_buffer_block_size) {
662a64b147SThomas Zimmermann 	case DP_DSC_RC_BUF_BLK_SIZE_1:
672a64b147SThomas Zimmermann 		return 1 * size;
682a64b147SThomas Zimmermann 	case DP_DSC_RC_BUF_BLK_SIZE_4:
692a64b147SThomas Zimmermann 		return 4 * size;
702a64b147SThomas Zimmermann 	case DP_DSC_RC_BUF_BLK_SIZE_16:
712a64b147SThomas Zimmermann 		return 16 * size;
722a64b147SThomas Zimmermann 	case DP_DSC_RC_BUF_BLK_SIZE_64:
732a64b147SThomas Zimmermann 		return 64 * size;
742a64b147SThomas Zimmermann 	default:
752a64b147SThomas Zimmermann 		return 0;
762a64b147SThomas Zimmermann 	}
772a64b147SThomas Zimmermann }
782a64b147SThomas Zimmermann EXPORT_SYMBOL(drm_dsc_dp_rc_buffer_size);
792a64b147SThomas Zimmermann 
802a64b147SThomas Zimmermann /**
812a64b147SThomas Zimmermann  * drm_dsc_pps_payload_pack() - Populates the DSC PPS
822a64b147SThomas Zimmermann  *
832a64b147SThomas Zimmermann  * @pps_payload:
842a64b147SThomas Zimmermann  * Bitwise struct for DSC Picture Parameter Set. This is defined
852a64b147SThomas Zimmermann  * by &struct drm_dsc_picture_parameter_set
862a64b147SThomas Zimmermann  * @dsc_cfg:
872a64b147SThomas Zimmermann  * DSC Configuration data filled by driver as defined by
882a64b147SThomas Zimmermann  * &struct drm_dsc_config
892a64b147SThomas Zimmermann  *
902a64b147SThomas Zimmermann  * DSC source device sends a picture parameter set (PPS) containing the
912a64b147SThomas Zimmermann  * information required by the sink to decode the compressed frame. Driver
922a64b147SThomas Zimmermann  * populates the DSC PPS struct using the DSC configuration parameters in
932a64b147SThomas Zimmermann  * the order expected by the DSC Display Sink device. For the DSC, the sink
942a64b147SThomas Zimmermann  * device expects the PPS payload in big endian format for fields
952a64b147SThomas Zimmermann  * that span more than 1 byte.
962a64b147SThomas Zimmermann  */
972a64b147SThomas Zimmermann void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload,
982a64b147SThomas Zimmermann 				const struct drm_dsc_config *dsc_cfg)
992a64b147SThomas Zimmermann {
1002a64b147SThomas Zimmermann 	int i;
1012a64b147SThomas Zimmermann 
1022a64b147SThomas Zimmermann 	/* Protect against someone accidentally changing struct size */
1032a64b147SThomas Zimmermann 	BUILD_BUG_ON(sizeof(*pps_payload) !=
1042a64b147SThomas Zimmermann 		     DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1 + 1);
1052a64b147SThomas Zimmermann 
1062a64b147SThomas Zimmermann 	memset(pps_payload, 0, sizeof(*pps_payload));
1072a64b147SThomas Zimmermann 
1082a64b147SThomas Zimmermann 	/* PPS 0 */
1092a64b147SThomas Zimmermann 	pps_payload->dsc_version =
1102a64b147SThomas Zimmermann 		dsc_cfg->dsc_version_minor |
1112a64b147SThomas Zimmermann 		dsc_cfg->dsc_version_major << DSC_PPS_VERSION_MAJOR_SHIFT;
1122a64b147SThomas Zimmermann 
1132a64b147SThomas Zimmermann 	/* PPS 1, 2 is 0 */
1142a64b147SThomas Zimmermann 
1152a64b147SThomas Zimmermann 	/* PPS 3 */
1162a64b147SThomas Zimmermann 	pps_payload->pps_3 =
1172a64b147SThomas Zimmermann 		dsc_cfg->line_buf_depth |
1182a64b147SThomas Zimmermann 		dsc_cfg->bits_per_component << DSC_PPS_BPC_SHIFT;
1192a64b147SThomas Zimmermann 
1202a64b147SThomas Zimmermann 	/* PPS 4 */
1212a64b147SThomas Zimmermann 	pps_payload->pps_4 =
1222a64b147SThomas Zimmermann 		((dsc_cfg->bits_per_pixel & DSC_PPS_BPP_HIGH_MASK) >>
1232a64b147SThomas Zimmermann 		 DSC_PPS_MSB_SHIFT) |
1242a64b147SThomas Zimmermann 		dsc_cfg->vbr_enable << DSC_PPS_VBR_EN_SHIFT |
1252a64b147SThomas Zimmermann 		dsc_cfg->simple_422 << DSC_PPS_SIMPLE422_SHIFT |
1262a64b147SThomas Zimmermann 		dsc_cfg->convert_rgb << DSC_PPS_CONVERT_RGB_SHIFT |
1272a64b147SThomas Zimmermann 		dsc_cfg->block_pred_enable << DSC_PPS_BLOCK_PRED_EN_SHIFT;
1282a64b147SThomas Zimmermann 
1292a64b147SThomas Zimmermann 	/* PPS 5 */
1302a64b147SThomas Zimmermann 	pps_payload->bits_per_pixel_low =
1312a64b147SThomas Zimmermann 		(dsc_cfg->bits_per_pixel & DSC_PPS_LSB_MASK);
1322a64b147SThomas Zimmermann 
1332a64b147SThomas Zimmermann 	/*
1342a64b147SThomas Zimmermann 	 * The DSC panel expects the PPS packet to have big endian format
1352a64b147SThomas Zimmermann 	 * for data spanning 2 bytes. Use a macro cpu_to_be16() to convert
1362a64b147SThomas Zimmermann 	 * to big endian format. If format is little endian, it will swap
1372a64b147SThomas Zimmermann 	 * bytes to convert to Big endian else keep it unchanged.
1382a64b147SThomas Zimmermann 	 */
1392a64b147SThomas Zimmermann 
1402a64b147SThomas Zimmermann 	/* PPS 6, 7 */
1412a64b147SThomas Zimmermann 	pps_payload->pic_height = cpu_to_be16(dsc_cfg->pic_height);
1422a64b147SThomas Zimmermann 
1432a64b147SThomas Zimmermann 	/* PPS 8, 9 */
1442a64b147SThomas Zimmermann 	pps_payload->pic_width = cpu_to_be16(dsc_cfg->pic_width);
1452a64b147SThomas Zimmermann 
1462a64b147SThomas Zimmermann 	/* PPS 10, 11 */
1472a64b147SThomas Zimmermann 	pps_payload->slice_height = cpu_to_be16(dsc_cfg->slice_height);
1482a64b147SThomas Zimmermann 
1492a64b147SThomas Zimmermann 	/* PPS 12, 13 */
1502a64b147SThomas Zimmermann 	pps_payload->slice_width = cpu_to_be16(dsc_cfg->slice_width);
1512a64b147SThomas Zimmermann 
1522a64b147SThomas Zimmermann 	/* PPS 14, 15 */
1532a64b147SThomas Zimmermann 	pps_payload->chunk_size = cpu_to_be16(dsc_cfg->slice_chunk_size);
1542a64b147SThomas Zimmermann 
1552a64b147SThomas Zimmermann 	/* PPS 16 */
1562a64b147SThomas Zimmermann 	pps_payload->initial_xmit_delay_high =
1572a64b147SThomas Zimmermann 		((dsc_cfg->initial_xmit_delay &
1582a64b147SThomas Zimmermann 		  DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK) >>
1592a64b147SThomas Zimmermann 		 DSC_PPS_MSB_SHIFT);
1602a64b147SThomas Zimmermann 
1612a64b147SThomas Zimmermann 	/* PPS 17 */
1622a64b147SThomas Zimmermann 	pps_payload->initial_xmit_delay_low =
1632a64b147SThomas Zimmermann 		(dsc_cfg->initial_xmit_delay & DSC_PPS_LSB_MASK);
1642a64b147SThomas Zimmermann 
1652a64b147SThomas Zimmermann 	/* PPS 18, 19 */
1662a64b147SThomas Zimmermann 	pps_payload->initial_dec_delay =
1672a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->initial_dec_delay);
1682a64b147SThomas Zimmermann 
1692a64b147SThomas Zimmermann 	/* PPS 20 is 0 */
1702a64b147SThomas Zimmermann 
1712a64b147SThomas Zimmermann 	/* PPS 21 */
1722a64b147SThomas Zimmermann 	pps_payload->initial_scale_value =
1732a64b147SThomas Zimmermann 		dsc_cfg->initial_scale_value;
1742a64b147SThomas Zimmermann 
1752a64b147SThomas Zimmermann 	/* PPS 22, 23 */
1762a64b147SThomas Zimmermann 	pps_payload->scale_increment_interval =
1772a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->scale_increment_interval);
1782a64b147SThomas Zimmermann 
1792a64b147SThomas Zimmermann 	/* PPS 24 */
1802a64b147SThomas Zimmermann 	pps_payload->scale_decrement_interval_high =
1812a64b147SThomas Zimmermann 		((dsc_cfg->scale_decrement_interval &
1822a64b147SThomas Zimmermann 		  DSC_PPS_SCALE_DEC_INT_HIGH_MASK) >>
1832a64b147SThomas Zimmermann 		 DSC_PPS_MSB_SHIFT);
1842a64b147SThomas Zimmermann 
1852a64b147SThomas Zimmermann 	/* PPS 25 */
1862a64b147SThomas Zimmermann 	pps_payload->scale_decrement_interval_low =
1872a64b147SThomas Zimmermann 		(dsc_cfg->scale_decrement_interval & DSC_PPS_LSB_MASK);
1882a64b147SThomas Zimmermann 
1892a64b147SThomas Zimmermann 	/* PPS 26[7:0], PPS 27[7:5] RESERVED */
1902a64b147SThomas Zimmermann 
1912a64b147SThomas Zimmermann 	/* PPS 27 */
1922a64b147SThomas Zimmermann 	pps_payload->first_line_bpg_offset =
1932a64b147SThomas Zimmermann 		dsc_cfg->first_line_bpg_offset;
1942a64b147SThomas Zimmermann 
1952a64b147SThomas Zimmermann 	/* PPS 28, 29 */
1962a64b147SThomas Zimmermann 	pps_payload->nfl_bpg_offset =
1972a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->nfl_bpg_offset);
1982a64b147SThomas Zimmermann 
1992a64b147SThomas Zimmermann 	/* PPS 30, 31 */
2002a64b147SThomas Zimmermann 	pps_payload->slice_bpg_offset =
2012a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->slice_bpg_offset);
2022a64b147SThomas Zimmermann 
2032a64b147SThomas Zimmermann 	/* PPS 32, 33 */
2042a64b147SThomas Zimmermann 	pps_payload->initial_offset =
2052a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->initial_offset);
2062a64b147SThomas Zimmermann 
2072a64b147SThomas Zimmermann 	/* PPS 34, 35 */
2082a64b147SThomas Zimmermann 	pps_payload->final_offset = cpu_to_be16(dsc_cfg->final_offset);
2092a64b147SThomas Zimmermann 
2102a64b147SThomas Zimmermann 	/* PPS 36 */
2112a64b147SThomas Zimmermann 	pps_payload->flatness_min_qp = dsc_cfg->flatness_min_qp;
2122a64b147SThomas Zimmermann 
2132a64b147SThomas Zimmermann 	/* PPS 37 */
2142a64b147SThomas Zimmermann 	pps_payload->flatness_max_qp = dsc_cfg->flatness_max_qp;
2152a64b147SThomas Zimmermann 
2162a64b147SThomas Zimmermann 	/* PPS 38, 39 */
2172a64b147SThomas Zimmermann 	pps_payload->rc_model_size = cpu_to_be16(dsc_cfg->rc_model_size);
2182a64b147SThomas Zimmermann 
2192a64b147SThomas Zimmermann 	/* PPS 40 */
2202a64b147SThomas Zimmermann 	pps_payload->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
2212a64b147SThomas Zimmermann 
2222a64b147SThomas Zimmermann 	/* PPS 41 */
2232a64b147SThomas Zimmermann 	pps_payload->rc_quant_incr_limit0 =
2242a64b147SThomas Zimmermann 		dsc_cfg->rc_quant_incr_limit0;
2252a64b147SThomas Zimmermann 
2262a64b147SThomas Zimmermann 	/* PPS 42 */
2272a64b147SThomas Zimmermann 	pps_payload->rc_quant_incr_limit1 =
2282a64b147SThomas Zimmermann 		dsc_cfg->rc_quant_incr_limit1;
2292a64b147SThomas Zimmermann 
2302a64b147SThomas Zimmermann 	/* PPS 43 */
2312a64b147SThomas Zimmermann 	pps_payload->rc_tgt_offset = DSC_RC_TGT_OFFSET_LO_CONST |
2322a64b147SThomas Zimmermann 		DSC_RC_TGT_OFFSET_HI_CONST << DSC_PPS_RC_TGT_OFFSET_HI_SHIFT;
2332a64b147SThomas Zimmermann 
2342a64b147SThomas Zimmermann 	/* PPS 44 - 57 */
2352a64b147SThomas Zimmermann 	for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
2362a64b147SThomas Zimmermann 		pps_payload->rc_buf_thresh[i] =
2372a64b147SThomas Zimmermann 			dsc_cfg->rc_buf_thresh[i];
2382a64b147SThomas Zimmermann 
2392a64b147SThomas Zimmermann 	/* PPS 58 - 87 */
2402a64b147SThomas Zimmermann 	/*
2412a64b147SThomas Zimmermann 	 * For DSC sink programming the RC Range parameter fields
2422a64b147SThomas Zimmermann 	 * are as follows: Min_qp[15:11], max_qp[10:6], offset[5:0]
2432a64b147SThomas Zimmermann 	 */
2442a64b147SThomas Zimmermann 	for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
2452a64b147SThomas Zimmermann 		pps_payload->rc_range_parameters[i] =
2462a64b147SThomas Zimmermann 			cpu_to_be16((dsc_cfg->rc_range_params[i].range_min_qp <<
2472a64b147SThomas Zimmermann 				     DSC_PPS_RC_RANGE_MINQP_SHIFT) |
2482a64b147SThomas Zimmermann 				    (dsc_cfg->rc_range_params[i].range_max_qp <<
2492a64b147SThomas Zimmermann 				     DSC_PPS_RC_RANGE_MAXQP_SHIFT) |
2502a64b147SThomas Zimmermann 				    (dsc_cfg->rc_range_params[i].range_bpg_offset));
2512a64b147SThomas Zimmermann 	}
2522a64b147SThomas Zimmermann 
2532a64b147SThomas Zimmermann 	/* PPS 88 */
2542a64b147SThomas Zimmermann 	pps_payload->native_422_420 = dsc_cfg->native_422 |
2552a64b147SThomas Zimmermann 		dsc_cfg->native_420 << DSC_PPS_NATIVE_420_SHIFT;
2562a64b147SThomas Zimmermann 
2572a64b147SThomas Zimmermann 	/* PPS 89 */
2582a64b147SThomas Zimmermann 	pps_payload->second_line_bpg_offset =
2592a64b147SThomas Zimmermann 		dsc_cfg->second_line_bpg_offset;
2602a64b147SThomas Zimmermann 
2612a64b147SThomas Zimmermann 	/* PPS 90, 91 */
2622a64b147SThomas Zimmermann 	pps_payload->nsl_bpg_offset =
2632a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->nsl_bpg_offset);
2642a64b147SThomas Zimmermann 
2652a64b147SThomas Zimmermann 	/* PPS 92, 93 */
2662a64b147SThomas Zimmermann 	pps_payload->second_line_offset_adj =
2672a64b147SThomas Zimmermann 		cpu_to_be16(dsc_cfg->second_line_offset_adj);
2682a64b147SThomas Zimmermann 
2692a64b147SThomas Zimmermann 	/* PPS 94 - 127 are O */
2702a64b147SThomas Zimmermann }
2712a64b147SThomas Zimmermann EXPORT_SYMBOL(drm_dsc_pps_payload_pack);
2722a64b147SThomas Zimmermann 
273*e871a70dSDmitry Baryshkov /**
274*e871a70dSDmitry Baryshkov  * drm_dsc_set_const_params() - Set DSC parameters considered typically
275*e871a70dSDmitry Baryshkov  * constant across operation modes
276*e871a70dSDmitry Baryshkov  *
277*e871a70dSDmitry Baryshkov  * @vdsc_cfg:
278*e871a70dSDmitry Baryshkov  * DSC Configuration data partially filled by driver
279*e871a70dSDmitry Baryshkov  */
280*e871a70dSDmitry Baryshkov void drm_dsc_set_const_params(struct drm_dsc_config *vdsc_cfg)
281*e871a70dSDmitry Baryshkov {
282*e871a70dSDmitry Baryshkov 	if (!vdsc_cfg->rc_model_size)
283*e871a70dSDmitry Baryshkov 		vdsc_cfg->rc_model_size = DSC_RC_MODEL_SIZE_CONST;
284*e871a70dSDmitry Baryshkov 	vdsc_cfg->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
285*e871a70dSDmitry Baryshkov 	vdsc_cfg->rc_tgt_offset_high = DSC_RC_TGT_OFFSET_HI_CONST;
286*e871a70dSDmitry Baryshkov 	vdsc_cfg->rc_tgt_offset_low = DSC_RC_TGT_OFFSET_LO_CONST;
287*e871a70dSDmitry Baryshkov 
288*e871a70dSDmitry Baryshkov 	if (vdsc_cfg->bits_per_component <= 10)
289*e871a70dSDmitry Baryshkov 		vdsc_cfg->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
290*e871a70dSDmitry Baryshkov 	else
291*e871a70dSDmitry Baryshkov 		vdsc_cfg->mux_word_size = DSC_MUX_WORD_SIZE_12_BPC;
292*e871a70dSDmitry Baryshkov }
293*e871a70dSDmitry Baryshkov EXPORT_SYMBOL(drm_dsc_set_const_params);
294*e871a70dSDmitry Baryshkov 
29516921921SDmitry Baryshkov /* From DSC_v1.11 spec, rc_parameter_Set syntax element typically constant */
29616921921SDmitry Baryshkov static const u16 drm_dsc_rc_buf_thresh[] = {
29716921921SDmitry Baryshkov 	896, 1792, 2688, 3584, 4480, 5376, 6272, 6720, 7168, 7616,
29816921921SDmitry Baryshkov 	7744, 7872, 8000, 8064
29916921921SDmitry Baryshkov };
30016921921SDmitry Baryshkov 
30116921921SDmitry Baryshkov /**
30216921921SDmitry Baryshkov  * drm_dsc_set_rc_buf_thresh() - Set thresholds for the RC model
30316921921SDmitry Baryshkov  * in accordance with the DSC 1.2 specification.
30416921921SDmitry Baryshkov  *
30516921921SDmitry Baryshkov  * @vdsc_cfg: DSC Configuration data partially filled by driver
30616921921SDmitry Baryshkov  */
30716921921SDmitry Baryshkov void drm_dsc_set_rc_buf_thresh(struct drm_dsc_config *vdsc_cfg)
30816921921SDmitry Baryshkov {
30916921921SDmitry Baryshkov 	int i;
31016921921SDmitry Baryshkov 
31116921921SDmitry Baryshkov 	BUILD_BUG_ON(ARRAY_SIZE(drm_dsc_rc_buf_thresh) !=
31216921921SDmitry Baryshkov 		     DSC_NUM_BUF_RANGES - 1);
31316921921SDmitry Baryshkov 	BUILD_BUG_ON(ARRAY_SIZE(drm_dsc_rc_buf_thresh) !=
31416921921SDmitry Baryshkov 		     ARRAY_SIZE(vdsc_cfg->rc_buf_thresh));
31516921921SDmitry Baryshkov 
31616921921SDmitry Baryshkov 	for (i = 0; i < ARRAY_SIZE(drm_dsc_rc_buf_thresh); i++)
31716921921SDmitry Baryshkov 		vdsc_cfg->rc_buf_thresh[i] = drm_dsc_rc_buf_thresh[i] >> 6;
31816921921SDmitry Baryshkov 
31916921921SDmitry Baryshkov 	/*
32016921921SDmitry Baryshkov 	 * For 6bpp, RC Buffer threshold 12 and 13 need a different value
32116921921SDmitry Baryshkov 	 * as per C Model
32216921921SDmitry Baryshkov 	 */
32316921921SDmitry Baryshkov 	if (vdsc_cfg->bits_per_pixel == 6 << 4) {
32416921921SDmitry Baryshkov 		vdsc_cfg->rc_buf_thresh[12] = 7936 >> 6;
32516921921SDmitry Baryshkov 		vdsc_cfg->rc_buf_thresh[13] = 8000 >> 6;
32616921921SDmitry Baryshkov 	}
32716921921SDmitry Baryshkov }
32816921921SDmitry Baryshkov EXPORT_SYMBOL(drm_dsc_set_rc_buf_thresh);
32916921921SDmitry Baryshkov 
3302b470e55SDmitry Baryshkov struct rc_parameters {
3312b470e55SDmitry Baryshkov 	u16 initial_xmit_delay;
3322b470e55SDmitry Baryshkov 	u8 first_line_bpg_offset;
3332b470e55SDmitry Baryshkov 	u16 initial_offset;
3342b470e55SDmitry Baryshkov 	u8 flatness_min_qp;
3352b470e55SDmitry Baryshkov 	u8 flatness_max_qp;
3362b470e55SDmitry Baryshkov 	u8 rc_quant_incr_limit0;
3372b470e55SDmitry Baryshkov 	u8 rc_quant_incr_limit1;
3382b470e55SDmitry Baryshkov 	struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];
3392b470e55SDmitry Baryshkov };
3402b470e55SDmitry Baryshkov 
34174fe874cSDmitry Baryshkov struct rc_parameters_data {
34274fe874cSDmitry Baryshkov 	u8 bpp;
34374fe874cSDmitry Baryshkov 	u8 bpc;
34474fe874cSDmitry Baryshkov 	struct rc_parameters params;
34574fe874cSDmitry Baryshkov };
34674fe874cSDmitry Baryshkov 
34774fe874cSDmitry Baryshkov #define DSC_BPP(bpp)	((bpp) << 4)
34874fe874cSDmitry Baryshkov 
3492b470e55SDmitry Baryshkov /*
350e3290f88SDmitry Baryshkov  * Rate Control Related Parameter Recommended Values from DSC_v1.1 spec prior
351e3290f88SDmitry Baryshkov  * to DSC 1.1 fractional bpp underflow SCR (DSC_v1.1_E1.pdf)
352e3290f88SDmitry Baryshkov  *
353e3290f88SDmitry Baryshkov  * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
3542b470e55SDmitry Baryshkov  */
355e3290f88SDmitry Baryshkov static const struct rc_parameters_data rc_parameters_pre_scr[] = {
356e3290f88SDmitry Baryshkov 	{
3573b292112SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 8,
3583b292112SDmitry Baryshkov 		{ 683, 15, 6144, 3, 13, 11, 11, {
3593b292112SDmitry Baryshkov 			{ 0, 2, 0 }, { 1, 4, -2 }, { 3, 6, -2 }, { 4, 6, -4 },
3603b292112SDmitry Baryshkov 			{ 5, 7, -6 }, { 5, 7, -6 }, { 6, 7, -6 }, { 6, 8, -8 },
3613b292112SDmitry Baryshkov 			{ 7, 9, -8 }, { 8, 10, -10 }, { 9, 11, -10 }, { 10, 12, -12 },
3623b292112SDmitry Baryshkov 			{ 10, 13, -12 }, { 12, 14, -12 }, { 15, 15, -12 }
3633b292112SDmitry Baryshkov 			}
3643b292112SDmitry Baryshkov 		}
3653b292112SDmitry Baryshkov 	},
3663b292112SDmitry Baryshkov 	{
367e3290f88SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 8,
368e3290f88SDmitry Baryshkov 		{ 512, 12, 6144, 3, 12, 11, 11, {
369e3290f88SDmitry Baryshkov 			{ 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
370e3290f88SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
371e3290f88SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 }, { 5, 12, -12 },
372e3290f88SDmitry Baryshkov 			{ 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
373e3290f88SDmitry Baryshkov 			}
374e3290f88SDmitry Baryshkov 		}
375e3290f88SDmitry Baryshkov 	},
376e3290f88SDmitry Baryshkov 	{
377e3290f88SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 10,
378e3290f88SDmitry Baryshkov 		{ 512, 12, 6144, 7, 16, 15, 15, {
379e3290f88SDmitry Baryshkov 			/*
380e3290f88SDmitry Baryshkov 			 * DSC model/pre-SCR-cfg has 8 for range_max_qp[0], however
381e3290f88SDmitry Baryshkov 			 * VESA DSC 1.1 Table E-5 sets it to 4.
382e3290f88SDmitry Baryshkov 			 */
383e3290f88SDmitry Baryshkov 			{ 0, 4, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
384e3290f88SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
385e3290f88SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
386e3290f88SDmitry Baryshkov 			{ 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
387e3290f88SDmitry Baryshkov 			}
388e3290f88SDmitry Baryshkov 		}
389e3290f88SDmitry Baryshkov 	},
390e3290f88SDmitry Baryshkov 	{
391e3290f88SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 12,
392e3290f88SDmitry Baryshkov 		{ 512, 12, 6144, 11, 20, 19, 19, {
393e3290f88SDmitry Baryshkov 			{ 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
394e3290f88SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
395e3290f88SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
396e3290f88SDmitry Baryshkov 			{ 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
397e3290f88SDmitry Baryshkov 			{ 21, 23, -12 }
398e3290f88SDmitry Baryshkov 			}
399e3290f88SDmitry Baryshkov 		}
400e3290f88SDmitry Baryshkov 	},
401e3290f88SDmitry Baryshkov 	{
4023b292112SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 8,
4033b292112SDmitry Baryshkov 		{ 410, 12, 5632, 3, 12, 11, 11, {
4043b292112SDmitry Baryshkov 			{ 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
4053b292112SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
4063b292112SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 11, -10 },
4073b292112SDmitry Baryshkov 			{ 5, 12, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
4083b292112SDmitry Baryshkov 			}
4093b292112SDmitry Baryshkov 		}
4103b292112SDmitry Baryshkov 	},
4113b292112SDmitry Baryshkov 	{
4123b292112SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 10,
4133b292112SDmitry Baryshkov 		{ 410, 12, 5632, 7, 16, 15, 15, {
4143b292112SDmitry Baryshkov 			{ 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
4153b292112SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
4163b292112SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 15, -10 },
4173b292112SDmitry Baryshkov 			{ 9, 16, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
4183b292112SDmitry Baryshkov 			}
4193b292112SDmitry Baryshkov 		}
4203b292112SDmitry Baryshkov 	},
4213b292112SDmitry Baryshkov 	{
4223b292112SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 12,
4233b292112SDmitry Baryshkov 		{ 410, 12, 5632, 11, 20, 19, 19, {
4243b292112SDmitry Baryshkov 			{ 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
4253b292112SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
4263b292112SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
4273b292112SDmitry Baryshkov 			{ 13, 19, -10 }, { 13, 20, -12 }, { 15, 21, -12 },
4283b292112SDmitry Baryshkov 			{ 21, 23, -12 }
4293b292112SDmitry Baryshkov 			}
4303b292112SDmitry Baryshkov 		}
4313b292112SDmitry Baryshkov 	},
4323b292112SDmitry Baryshkov 	{
433e3290f88SDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 8,
434e3290f88SDmitry Baryshkov 		{ 341, 15, 2048, 3, 12, 11, 11, {
435e3290f88SDmitry Baryshkov 			{ 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
436e3290f88SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
437e3290f88SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 },
438e3290f88SDmitry Baryshkov 			{ 5, 12, -12 }, { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
439e3290f88SDmitry Baryshkov 			}
440e3290f88SDmitry Baryshkov 		}
441e3290f88SDmitry Baryshkov 	},
442e3290f88SDmitry Baryshkov 	{
443e3290f88SDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 10,
444e3290f88SDmitry Baryshkov 		{ 341, 15, 2048, 7, 16, 15, 15, {
445e3290f88SDmitry Baryshkov 			{ 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
446e3290f88SDmitry Baryshkov 			{ 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
447e3290f88SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
448e3290f88SDmitry Baryshkov 			{ 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
449e3290f88SDmitry Baryshkov 			}
450e3290f88SDmitry Baryshkov 		}
451e3290f88SDmitry Baryshkov 	},
452e3290f88SDmitry Baryshkov 	{
453e3290f88SDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 12,
454e3290f88SDmitry Baryshkov 		{ 341, 15, 2048, 11, 20, 19, 19, {
455e3290f88SDmitry Baryshkov 			{ 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
456e3290f88SDmitry Baryshkov 			{ 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
457e3290f88SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
458e3290f88SDmitry Baryshkov 			{ 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
459e3290f88SDmitry Baryshkov 			{ 21, 23, -12 }
460e3290f88SDmitry Baryshkov 			}
461e3290f88SDmitry Baryshkov 		}
462e3290f88SDmitry Baryshkov 	},
4633b292112SDmitry Baryshkov 	{
4643b292112SDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 8,
4653b292112SDmitry Baryshkov 		{ 273, 15, 2048, 3, 12, 11, 11, {
4663b292112SDmitry Baryshkov 			{ 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
4673b292112SDmitry Baryshkov 			{ 1, 2, 2 }, { 1, 3, 0 }, { 1, 4, -2 }, { 2, 4, -4 },
4683b292112SDmitry Baryshkov 			{ 3, 4, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 5, 7, -10 },
4693b292112SDmitry Baryshkov 			{ 5, 8, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
4703b292112SDmitry Baryshkov 			}
4713b292112SDmitry Baryshkov 		}
4723b292112SDmitry Baryshkov 	},
4733b292112SDmitry Baryshkov 	{
4743b292112SDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 10,
4753b292112SDmitry Baryshkov 		{ 273, 15, 2048, 7, 16, 15, 15, {
4763b292112SDmitry Baryshkov 			{ 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
4773b292112SDmitry Baryshkov 			{ 5, 6, 2 }, { 5, 7, 0 }, { 5, 8, -2 }, { 6, 8, -4 },
4783b292112SDmitry Baryshkov 			{ 7, 8, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 9, 11, -10 },
4793b292112SDmitry Baryshkov 			{ 9, 12, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
4803b292112SDmitry Baryshkov 			}
4813b292112SDmitry Baryshkov 		}
4823b292112SDmitry Baryshkov 	},
4833b292112SDmitry Baryshkov 	{
4843b292112SDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 12,
4853b292112SDmitry Baryshkov 		{ 273, 15, 2048, 11, 20, 19, 19, {
4863b292112SDmitry Baryshkov 			{ 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
4873b292112SDmitry Baryshkov 			{ 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
4883b292112SDmitry Baryshkov 			{ 11, 12, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
4893b292112SDmitry Baryshkov 			{ 13, 15, -10 }, { 13, 16, -12 }, { 15, 21, -12 },
4903b292112SDmitry Baryshkov 			{ 21, 23, -12 }
4913b292112SDmitry Baryshkov 			}
4923b292112SDmitry Baryshkov 		}
4933b292112SDmitry Baryshkov 	},
494e3290f88SDmitry Baryshkov 	{ /* sentinel */ }
495e3290f88SDmitry Baryshkov };
496e3290f88SDmitry Baryshkov 
497e3290f88SDmitry Baryshkov /*
498e3290f88SDmitry Baryshkov  * Selected Rate Control Related Parameter Recommended Values from DSC v1.2, v1.2a, v1.2b and
499e3290f88SDmitry Baryshkov  * DSC_v1.1_E1 specs.
500e3290f88SDmitry Baryshkov  *
501e3290f88SDmitry Baryshkov  * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
502e3290f88SDmitry Baryshkov  */
503e3290f88SDmitry Baryshkov static const struct rc_parameters_data rc_parameters_1_2_444[] = {
5042b470e55SDmitry Baryshkov 	{
50574fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 8,
5062b470e55SDmitry Baryshkov 		{ 768, 15, 6144, 3, 13, 11, 11, {
5072b470e55SDmitry Baryshkov 			{ 0, 4, 0 }, { 1, 6, -2 }, { 3, 8, -2 }, { 4, 8, -4 },
5082b470e55SDmitry Baryshkov 			{ 5, 9, -6 }, { 5, 9, -6 }, { 6, 9, -6 }, { 6, 10, -8 },
5092b470e55SDmitry Baryshkov 			{ 7, 11, -8 }, { 8, 12, -10 }, { 9, 12, -10 }, { 10, 12, -12 },
5102b470e55SDmitry Baryshkov 			{ 10, 12, -12 }, { 11, 12, -12 }, { 13, 14, -12 }
5112b470e55SDmitry Baryshkov 			}
51274fe874cSDmitry Baryshkov 		}
5132b470e55SDmitry Baryshkov 	},
51474fe874cSDmitry Baryshkov 	{
51574fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 10,
5162b470e55SDmitry Baryshkov 		{ 768, 15, 6144, 7, 17, 15, 15, {
5172b470e55SDmitry Baryshkov 			{ 0, 8, 0 }, { 3, 10, -2 }, { 7, 12, -2 }, { 8, 12, -4 },
5182b470e55SDmitry Baryshkov 			{ 9, 13, -6 }, { 9, 13, -6 }, { 10, 13, -6 }, { 10, 14, -8 },
5192b470e55SDmitry Baryshkov 			{ 11, 15, -8 }, { 12, 16, -10 }, { 13, 16, -10 },
5202b470e55SDmitry Baryshkov 			{ 14, 16, -12 }, { 14, 16, -12 }, { 15, 16, -12 },
5212b470e55SDmitry Baryshkov 			{ 17, 18, -12 }
5222b470e55SDmitry Baryshkov 			}
52374fe874cSDmitry Baryshkov 		}
5242b470e55SDmitry Baryshkov 	},
52574fe874cSDmitry Baryshkov 	{
52674fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 12,
5272b470e55SDmitry Baryshkov 		{ 768, 15, 6144, 11, 21, 19, 19, {
5282b470e55SDmitry Baryshkov 			{ 0, 12, 0 }, { 5, 14, -2 }, { 11, 16, -2 }, { 12, 16, -4 },
5292b470e55SDmitry Baryshkov 			{ 13, 17, -6 }, { 13, 17, -6 }, { 14, 17, -6 }, { 14, 18, -8 },
5302b470e55SDmitry Baryshkov 			{ 15, 19, -8 }, { 16, 20, -10 }, { 17, 20, -10 },
5312b470e55SDmitry Baryshkov 			{ 18, 20, -12 }, { 18, 20, -12 }, { 19, 20, -12 },
5322b470e55SDmitry Baryshkov 			{ 21, 22, -12 }
5332b470e55SDmitry Baryshkov 			}
53474fe874cSDmitry Baryshkov 		}
5352b470e55SDmitry Baryshkov 	},
53674fe874cSDmitry Baryshkov 	{
53774fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 14,
5382b470e55SDmitry Baryshkov 		{ 768, 15, 6144, 15, 25, 23, 23, {
5392b470e55SDmitry Baryshkov 			{ 0, 16, 0 }, { 7, 18, -2 }, { 15, 20, -2 }, { 16, 20, -4 },
5402b470e55SDmitry Baryshkov 			{ 17, 21, -6 }, { 17, 21, -6 }, { 18, 21, -6 }, { 18, 22, -8 },
5412b470e55SDmitry Baryshkov 			{ 19, 23, -8 }, { 20, 24, -10 }, { 21, 24, -10 },
5422b470e55SDmitry Baryshkov 			{ 22, 24, -12 }, { 22, 24, -12 }, { 23, 24, -12 },
5432b470e55SDmitry Baryshkov 			{ 25, 26, -12 }
5442b470e55SDmitry Baryshkov 			}
54574fe874cSDmitry Baryshkov 		}
5462b470e55SDmitry Baryshkov 	},
54774fe874cSDmitry Baryshkov 	{
54874fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 16,
5492b470e55SDmitry Baryshkov 		{ 768, 15, 6144, 19, 29, 27, 27, {
5502b470e55SDmitry Baryshkov 			{ 0, 20, 0 }, { 9, 22, -2 }, { 19, 24, -2 }, { 20, 24, -4 },
5512b470e55SDmitry Baryshkov 			{ 21, 25, -6 }, { 21, 25, -6 }, { 22, 25, -6 }, { 22, 26, -8 },
5522b470e55SDmitry Baryshkov 			{ 23, 27, -8 }, { 24, 28, -10 }, { 25, 28, -10 },
5532b470e55SDmitry Baryshkov 			{ 26, 28, -12 }, { 26, 28, -12 }, { 27, 28, -12 },
5542b470e55SDmitry Baryshkov 			{ 29, 30, -12 }
5552b470e55SDmitry Baryshkov 			}
55674fe874cSDmitry Baryshkov 		}
5572b470e55SDmitry Baryshkov 	},
5582b470e55SDmitry Baryshkov 	{
55974fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 8,
5602b470e55SDmitry Baryshkov 		{ 512, 12, 6144, 3, 12, 11, 11, {
5612b470e55SDmitry Baryshkov 			{ 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
5622b470e55SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
563e3290f88SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
564e3290f88SDmitry Baryshkov 			{ 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
5652b470e55SDmitry Baryshkov 			}
56674fe874cSDmitry Baryshkov 		}
5672b470e55SDmitry Baryshkov 	},
56874fe874cSDmitry Baryshkov 	{
56974fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 10,
5702b470e55SDmitry Baryshkov 		{ 512, 12, 6144, 7, 16, 15, 15, {
571e3290f88SDmitry Baryshkov 			{ 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
5722b470e55SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
573e3290f88SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
574e3290f88SDmitry Baryshkov 			{ 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
5752b470e55SDmitry Baryshkov 			}
57674fe874cSDmitry Baryshkov 		}
5772b470e55SDmitry Baryshkov 	},
57874fe874cSDmitry Baryshkov 	{
57974fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 12,
5802b470e55SDmitry Baryshkov 		{ 512, 12, 6144, 11, 20, 19, 19, {
5812b470e55SDmitry Baryshkov 			{ 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
5822b470e55SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
583e3290f88SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
584e3290f88SDmitry Baryshkov 			{ 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
585e3290f88SDmitry Baryshkov 			{ 20, 21, -12 }
5862b470e55SDmitry Baryshkov 			}
58774fe874cSDmitry Baryshkov 		}
5882b470e55SDmitry Baryshkov 	},
58974fe874cSDmitry Baryshkov 	{
59074fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 14,
5912b470e55SDmitry Baryshkov 		{ 512, 12, 6144, 15, 24, 23, 23, {
5922b470e55SDmitry Baryshkov 			{ 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
5932b470e55SDmitry Baryshkov 			{ 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
5942b470e55SDmitry Baryshkov 			{ 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
5952b470e55SDmitry Baryshkov 			{ 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
5962b470e55SDmitry Baryshkov 			{ 24, 25, -12 }
5972b470e55SDmitry Baryshkov 			}
59874fe874cSDmitry Baryshkov 		}
5992b470e55SDmitry Baryshkov 	},
60074fe874cSDmitry Baryshkov 	{
60174fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 16,
6022b470e55SDmitry Baryshkov 		{ 512, 12, 6144, 19, 28, 27, 27, {
6032b470e55SDmitry Baryshkov 			{ 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
6042b470e55SDmitry Baryshkov 			{ 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
6052b470e55SDmitry Baryshkov 			{ 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
6062b470e55SDmitry Baryshkov 			{ 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
6072b470e55SDmitry Baryshkov 			{ 28, 29, -12 }
6082b470e55SDmitry Baryshkov 			}
60974fe874cSDmitry Baryshkov 		}
6102b470e55SDmitry Baryshkov 	},
6112b470e55SDmitry Baryshkov 	{
61274fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 8,
6132b470e55SDmitry Baryshkov 		{ 410, 15, 5632, 3, 12, 11, 11, {
6142b470e55SDmitry Baryshkov 			{ 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
6152b470e55SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
6162b470e55SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
6172b470e55SDmitry Baryshkov 			{ 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
6182b470e55SDmitry Baryshkov 			}
61974fe874cSDmitry Baryshkov 		}
6202b470e55SDmitry Baryshkov 	},
62174fe874cSDmitry Baryshkov 	{
62274fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 10,
6232b470e55SDmitry Baryshkov 		{ 410, 15, 5632, 7, 16, 15, 15, {
6242b470e55SDmitry Baryshkov 			{ 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
6252b470e55SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
6262b470e55SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
6272b470e55SDmitry Baryshkov 			{ 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
6282b470e55SDmitry Baryshkov 			}
62974fe874cSDmitry Baryshkov 		}
6302b470e55SDmitry Baryshkov 	},
63174fe874cSDmitry Baryshkov 	{
63274fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 12,
6332b470e55SDmitry Baryshkov 		{ 410, 15, 5632, 11, 20, 19, 19, {
6342b470e55SDmitry Baryshkov 			{ 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
6352b470e55SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
6362b470e55SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
6372b470e55SDmitry Baryshkov 			{ 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
6382b470e55SDmitry Baryshkov 			{ 19, 20, -12 }
6392b470e55SDmitry Baryshkov 			}
64074fe874cSDmitry Baryshkov 		}
6412b470e55SDmitry Baryshkov 	},
64274fe874cSDmitry Baryshkov 	{
64374fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 14,
6442b470e55SDmitry Baryshkov 		{ 410, 15, 5632, 15, 24, 23, 23, {
6452b470e55SDmitry Baryshkov 			{ 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
6462b470e55SDmitry Baryshkov 			{ 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
6472b470e55SDmitry Baryshkov 			{ 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
6482b470e55SDmitry Baryshkov 			{ 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
6492b470e55SDmitry Baryshkov 			{ 23, 24, -12 }
6502b470e55SDmitry Baryshkov 			}
65174fe874cSDmitry Baryshkov 		}
6522b470e55SDmitry Baryshkov 	},
65374fe874cSDmitry Baryshkov 	{
65474fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 16,
6552b470e55SDmitry Baryshkov 		{ 410, 15, 5632, 19, 28, 27, 27, {
6562b470e55SDmitry Baryshkov 			{ 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
6572b470e55SDmitry Baryshkov 			{ 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
6582b470e55SDmitry Baryshkov 			{ 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
6592b470e55SDmitry Baryshkov 			{ 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
6602b470e55SDmitry Baryshkov 			{ 27, 28, -12 }
6612b470e55SDmitry Baryshkov 			}
66274fe874cSDmitry Baryshkov 		}
6632b470e55SDmitry Baryshkov 	},
6642b470e55SDmitry Baryshkov 	{
66574fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 8,
6662b470e55SDmitry Baryshkov 		{ 341, 15, 2048, 3, 12, 11, 11, {
6672b470e55SDmitry Baryshkov 			{ 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
6682b470e55SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
669e3290f88SDmitry Baryshkov 			{ 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
670e3290f88SDmitry Baryshkov 			{ 5, 9, -12 }, { 7, 10, -12 }, { 10, 11, -12 }
6712b470e55SDmitry Baryshkov 			}
67274fe874cSDmitry Baryshkov 		}
6732b470e55SDmitry Baryshkov 	},
67474fe874cSDmitry Baryshkov 	{
67574fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 10,
6762b470e55SDmitry Baryshkov 		{ 341, 15, 2048, 7, 16, 15, 15, {
6772b470e55SDmitry Baryshkov 			{ 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
6782b470e55SDmitry Baryshkov 			{ 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
679e3290f88SDmitry Baryshkov 			{ 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
680e3290f88SDmitry Baryshkov 			{ 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
6812b470e55SDmitry Baryshkov 			}
68274fe874cSDmitry Baryshkov 		}
6832b470e55SDmitry Baryshkov 	},
68474fe874cSDmitry Baryshkov 	{
68574fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 12,
6862b470e55SDmitry Baryshkov 		{ 341, 15, 2048, 11, 20, 19, 19, {
6872b470e55SDmitry Baryshkov 			{ 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
6882b470e55SDmitry Baryshkov 			{ 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
689e3290f88SDmitry Baryshkov 			{ 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
690e3290f88SDmitry Baryshkov 			{ 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
691e3290f88SDmitry Baryshkov 			{ 18, 19, -12 }
6922b470e55SDmitry Baryshkov 			}
69374fe874cSDmitry Baryshkov 		}
6942b470e55SDmitry Baryshkov 	},
69574fe874cSDmitry Baryshkov 	{
69674fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 14,
6972b470e55SDmitry Baryshkov 		{ 341, 15, 2048, 15, 24, 23, 23, {
6982b470e55SDmitry Baryshkov 			{ 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
6992b470e55SDmitry Baryshkov 			{ 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
7002b470e55SDmitry Baryshkov 			{ 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
7012b470e55SDmitry Baryshkov 			{ 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
7022b470e55SDmitry Baryshkov 			{ 22, 23, -12 }
7032b470e55SDmitry Baryshkov 			}
70474fe874cSDmitry Baryshkov 		}
7052b470e55SDmitry Baryshkov 	},
70674fe874cSDmitry Baryshkov 	{
70774fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(12), .bpc = 16,
7082b470e55SDmitry Baryshkov 		{ 341, 15, 2048, 19, 28, 27, 27, {
7092b470e55SDmitry Baryshkov 			{ 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
7102b470e55SDmitry Baryshkov 			{ 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
7112b470e55SDmitry Baryshkov 			{ 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
7122b470e55SDmitry Baryshkov 			{ 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
7132b470e55SDmitry Baryshkov 			{ 26, 27, -12 }
7142b470e55SDmitry Baryshkov 			}
71574fe874cSDmitry Baryshkov 		}
7162b470e55SDmitry Baryshkov 	},
7172b470e55SDmitry Baryshkov 	{
71874fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 8,
7192b470e55SDmitry Baryshkov 		{ 273, 15, 2048, 3, 12, 11, 11, {
7202b470e55SDmitry Baryshkov 			{ 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
7212b470e55SDmitry Baryshkov 			{ 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
7222b470e55SDmitry Baryshkov 			{ 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
7232b470e55SDmitry Baryshkov 			{ 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
7242b470e55SDmitry Baryshkov 			}
72574fe874cSDmitry Baryshkov 		}
7262b470e55SDmitry Baryshkov 	},
72774fe874cSDmitry Baryshkov 	{
72874fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 10,
7292b470e55SDmitry Baryshkov 		{ 273, 15, 2048, 7, 16, 15, 15, {
7302b470e55SDmitry Baryshkov 			{ 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
7312b470e55SDmitry Baryshkov 			{ 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
7322b470e55SDmitry Baryshkov 			{ 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
7332b470e55SDmitry Baryshkov 			{ 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
7342b470e55SDmitry Baryshkov 			}
73574fe874cSDmitry Baryshkov 		}
7362b470e55SDmitry Baryshkov 	},
73774fe874cSDmitry Baryshkov 	{
73874fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 12,
7392b470e55SDmitry Baryshkov 		{ 273, 15, 2048, 11, 20, 19, 19, {
7402b470e55SDmitry Baryshkov 			{ 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
7412b470e55SDmitry Baryshkov 			{ 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
7422b470e55SDmitry Baryshkov 			{ 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
7432b470e55SDmitry Baryshkov 			{ 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
7442b470e55SDmitry Baryshkov 			{ 16, 17, -12 }
7452b470e55SDmitry Baryshkov 			}
74674fe874cSDmitry Baryshkov 		}
7472b470e55SDmitry Baryshkov 	},
74874fe874cSDmitry Baryshkov 	{
74974fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 14,
7502b470e55SDmitry Baryshkov 		{ 273, 15, 2048, 15, 24, 23, 23, {
7512b470e55SDmitry Baryshkov 			{ 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
7522b470e55SDmitry Baryshkov 			{ 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
7532b470e55SDmitry Baryshkov 			{ 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
7542b470e55SDmitry Baryshkov 			{ 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
7552b470e55SDmitry Baryshkov 			{ 20, 21, -12 }
7562b470e55SDmitry Baryshkov 			}
75774fe874cSDmitry Baryshkov 		}
7582b470e55SDmitry Baryshkov 	},
75974fe874cSDmitry Baryshkov 	{
76074fe874cSDmitry Baryshkov 		.bpp = DSC_BPP(15), .bpc = 16,
7612b470e55SDmitry Baryshkov 		{ 273, 15, 2048, 19, 28, 27, 27, {
7622b470e55SDmitry Baryshkov 			{ 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
7632b470e55SDmitry Baryshkov 			{ 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
7642b470e55SDmitry Baryshkov 			{ 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
7652b470e55SDmitry Baryshkov 			{ 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
7662b470e55SDmitry Baryshkov 			{ 24, 25, -12 }
7672b470e55SDmitry Baryshkov 			}
7682b470e55SDmitry Baryshkov 		}
76974fe874cSDmitry Baryshkov 	},
77074fe874cSDmitry Baryshkov 	{ /* sentinel */ }
7712b470e55SDmitry Baryshkov };
7722b470e55SDmitry Baryshkov 
773d54fbea3SDmitry Baryshkov /*
774d54fbea3SDmitry Baryshkov  * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from
775d54fbea3SDmitry Baryshkov  * DSC v1.2, v1.2a, v1.2b
776d54fbea3SDmitry Baryshkov  *
777d54fbea3SDmitry Baryshkov  * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
778d54fbea3SDmitry Baryshkov  */
779d54fbea3SDmitry Baryshkov static const struct rc_parameters_data rc_parameters_1_2_422[] = {
780d54fbea3SDmitry Baryshkov 	{
781d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 8,
782d54fbea3SDmitry Baryshkov 		{ 512, 15, 6144, 3, 12, 11, 11, {
783d54fbea3SDmitry Baryshkov 			{ 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
784d54fbea3SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
785d54fbea3SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
786d54fbea3SDmitry Baryshkov 			{ 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
787d54fbea3SDmitry Baryshkov 			}
788d54fbea3SDmitry Baryshkov 		}
789d54fbea3SDmitry Baryshkov 	},
790d54fbea3SDmitry Baryshkov 	{
791d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 10,
792d54fbea3SDmitry Baryshkov 		{ 512, 15, 6144, 7, 16, 15, 15, {
793d54fbea3SDmitry Baryshkov 			{ 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
794d54fbea3SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
795d54fbea3SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
796d54fbea3SDmitry Baryshkov 			{ 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
797d54fbea3SDmitry Baryshkov 			}
798d54fbea3SDmitry Baryshkov 		}
799d54fbea3SDmitry Baryshkov 	},
800d54fbea3SDmitry Baryshkov 	{
801d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 12,
802d54fbea3SDmitry Baryshkov 		{ 512, 15, 6144, 11, 20, 19, 19, {
803d54fbea3SDmitry Baryshkov 			{ 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
804d54fbea3SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
805d54fbea3SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
806d54fbea3SDmitry Baryshkov 			{ 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
807d54fbea3SDmitry Baryshkov 			{ 20, 21, -12 }
808d54fbea3SDmitry Baryshkov 			}
809d54fbea3SDmitry Baryshkov 		}
810d54fbea3SDmitry Baryshkov 	},
811d54fbea3SDmitry Baryshkov 	{
812d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 14,
813d54fbea3SDmitry Baryshkov 		{ 512, 15, 6144, 15, 24, 23, 23, {
814d54fbea3SDmitry Baryshkov 			{ 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
815d54fbea3SDmitry Baryshkov 			{ 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
816d54fbea3SDmitry Baryshkov 			{ 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
817d54fbea3SDmitry Baryshkov 			{ 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
818d54fbea3SDmitry Baryshkov 			{ 24, 25, -12 }
819d54fbea3SDmitry Baryshkov 			}
820d54fbea3SDmitry Baryshkov 		}
821d54fbea3SDmitry Baryshkov 	},
822d54fbea3SDmitry Baryshkov 	{
823d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 16,
824d54fbea3SDmitry Baryshkov 		{ 512, 15, 6144, 19, 28, 27, 27, {
825d54fbea3SDmitry Baryshkov 			{ 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
826d54fbea3SDmitry Baryshkov 			{ 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
827d54fbea3SDmitry Baryshkov 			{ 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
828d54fbea3SDmitry Baryshkov 			{ 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
829d54fbea3SDmitry Baryshkov 			{ 28, 29, -12 }
830d54fbea3SDmitry Baryshkov 			}
831d54fbea3SDmitry Baryshkov 		}
832d54fbea3SDmitry Baryshkov 	},
833d54fbea3SDmitry Baryshkov 	{
834d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(7), .bpc = 8,
835d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 3, 12, 11, 11, {
836d54fbea3SDmitry Baryshkov 			{ 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
837d54fbea3SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
838d54fbea3SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
839d54fbea3SDmitry Baryshkov 			{ 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
840d54fbea3SDmitry Baryshkov 			}
841d54fbea3SDmitry Baryshkov 		}
842d54fbea3SDmitry Baryshkov 	},
843d54fbea3SDmitry Baryshkov 	{
844d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(7), .bpc = 10,
845d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 7, 16, 15, 15, {
846d54fbea3SDmitry Baryshkov 			{ 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
847d54fbea3SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
848d54fbea3SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
849d54fbea3SDmitry Baryshkov 			{ 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
850d54fbea3SDmitry Baryshkov 			}
851d54fbea3SDmitry Baryshkov 		}
852d54fbea3SDmitry Baryshkov 	},
853d54fbea3SDmitry Baryshkov 	{
854d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(7), .bpc = 12,
855d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 11, 20, 19, 19, {
856d54fbea3SDmitry Baryshkov 			{ 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
857d54fbea3SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
858d54fbea3SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
859d54fbea3SDmitry Baryshkov 			{ 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
860d54fbea3SDmitry Baryshkov 			{ 19, 20, -12 }
861d54fbea3SDmitry Baryshkov 			}
862d54fbea3SDmitry Baryshkov 		}
863d54fbea3SDmitry Baryshkov 	},
864d54fbea3SDmitry Baryshkov 	{
865d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(7), .bpc = 14,
866d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 15, 24, 23, 23, {
867d54fbea3SDmitry Baryshkov 			{ 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
868d54fbea3SDmitry Baryshkov 			{ 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
869d54fbea3SDmitry Baryshkov 			{ 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
870d54fbea3SDmitry Baryshkov 			{ 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
871d54fbea3SDmitry Baryshkov 			{ 23, 24, -12 }
872d54fbea3SDmitry Baryshkov 			}
873d54fbea3SDmitry Baryshkov 		}
874d54fbea3SDmitry Baryshkov 	},
875d54fbea3SDmitry Baryshkov 	{
876d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(7), .bpc = 16,
877d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 19, 28, 27, 27, {
878d54fbea3SDmitry Baryshkov 			{ 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
879d54fbea3SDmitry Baryshkov 			{ 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
880d54fbea3SDmitry Baryshkov 			{ 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
881d54fbea3SDmitry Baryshkov 			{ 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
882d54fbea3SDmitry Baryshkov 			{ 27, 28, -12 }
883d54fbea3SDmitry Baryshkov 			}
884d54fbea3SDmitry Baryshkov 		}
885d54fbea3SDmitry Baryshkov 	},
886d54fbea3SDmitry Baryshkov 	{
887d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 8,
888d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 3, 12, 11, 11, {
889d54fbea3SDmitry Baryshkov 			{ 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
890d54fbea3SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
891d54fbea3SDmitry Baryshkov 			{ 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
892d54fbea3SDmitry Baryshkov 			{ 5, 9, -12 }, { 7, 10, -12 }, { 10, 11, -12 }
893d54fbea3SDmitry Baryshkov 			}
894d54fbea3SDmitry Baryshkov 		}
895d54fbea3SDmitry Baryshkov 	},
896d54fbea3SDmitry Baryshkov 	{
897d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 10,
898d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 7, 16, 15, 15, {
899d54fbea3SDmitry Baryshkov 			{ 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
900d54fbea3SDmitry Baryshkov 			{ 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
901d54fbea3SDmitry Baryshkov 			{ 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
902d54fbea3SDmitry Baryshkov 			{ 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
903d54fbea3SDmitry Baryshkov 			}
904d54fbea3SDmitry Baryshkov 		}
905d54fbea3SDmitry Baryshkov 	},
906d54fbea3SDmitry Baryshkov 	{
907d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 12,
908d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 11, 20, 19, 19, {
909d54fbea3SDmitry Baryshkov 			{ 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
910d54fbea3SDmitry Baryshkov 			{ 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
911d54fbea3SDmitry Baryshkov 			{ 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
912d54fbea3SDmitry Baryshkov 			{ 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
913d54fbea3SDmitry Baryshkov 			{ 18, 19, -12 }
914d54fbea3SDmitry Baryshkov 			}
915d54fbea3SDmitry Baryshkov 		}
916d54fbea3SDmitry Baryshkov 	},
917d54fbea3SDmitry Baryshkov 	{
918d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 14,
919d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 15, 24, 23, 23, {
920d54fbea3SDmitry Baryshkov 			{ 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
921d54fbea3SDmitry Baryshkov 			{ 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
922d54fbea3SDmitry Baryshkov 			{ 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
923d54fbea3SDmitry Baryshkov 			{ 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
924d54fbea3SDmitry Baryshkov 			{ 22, 23, -12 }
925d54fbea3SDmitry Baryshkov 			}
926d54fbea3SDmitry Baryshkov 		}
927d54fbea3SDmitry Baryshkov 	},
928d54fbea3SDmitry Baryshkov 	{
929d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 16,
930d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 19, 28, 27, 27, {
931d54fbea3SDmitry Baryshkov 			{ 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
932d54fbea3SDmitry Baryshkov 			{ 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
933d54fbea3SDmitry Baryshkov 			{ 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
934d54fbea3SDmitry Baryshkov 			{ 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
935d54fbea3SDmitry Baryshkov 			{ 26, 27, -12 }
936d54fbea3SDmitry Baryshkov 			}
937d54fbea3SDmitry Baryshkov 		}
938d54fbea3SDmitry Baryshkov 	},
939d54fbea3SDmitry Baryshkov 	{
940d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 8,
941d54fbea3SDmitry Baryshkov 		{ 273, 15, 2048, 3, 12, 11, 11, {
942d54fbea3SDmitry Baryshkov 			{ 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
943d54fbea3SDmitry Baryshkov 			{ 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
944d54fbea3SDmitry Baryshkov 			{ 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
945d54fbea3SDmitry Baryshkov 			{ 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
946d54fbea3SDmitry Baryshkov 			}
947d54fbea3SDmitry Baryshkov 		}
948d54fbea3SDmitry Baryshkov 	},
949d54fbea3SDmitry Baryshkov 	{
950d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 10,
951d54fbea3SDmitry Baryshkov 		{ 273, 15, 2048, 7, 16, 15, 15, {
952d54fbea3SDmitry Baryshkov 			{ 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
953d54fbea3SDmitry Baryshkov 			{ 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
954d54fbea3SDmitry Baryshkov 			{ 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
955d54fbea3SDmitry Baryshkov 			{ 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
956d54fbea3SDmitry Baryshkov 			}
957d54fbea3SDmitry Baryshkov 		}
958d54fbea3SDmitry Baryshkov 	},
959d54fbea3SDmitry Baryshkov 	{
960d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 12,
961d54fbea3SDmitry Baryshkov 		{ 273, 15, 2048, 11, 20, 19, 19, {
962d54fbea3SDmitry Baryshkov 			{ 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
963d54fbea3SDmitry Baryshkov 			{ 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
964d54fbea3SDmitry Baryshkov 			{ 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
965d54fbea3SDmitry Baryshkov 			{ 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
966d54fbea3SDmitry Baryshkov 			{ 16, 17, -12 }
967d54fbea3SDmitry Baryshkov 			}
968d54fbea3SDmitry Baryshkov 		}
969d54fbea3SDmitry Baryshkov 	},
970d54fbea3SDmitry Baryshkov 	{
971d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 14,
972d54fbea3SDmitry Baryshkov 		{ 273, 15, 2048, 15, 24, 23, 23, {
973d54fbea3SDmitry Baryshkov 			{ 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
974d54fbea3SDmitry Baryshkov 			{ 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
975d54fbea3SDmitry Baryshkov 			{ 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
976d54fbea3SDmitry Baryshkov 			{ 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
977d54fbea3SDmitry Baryshkov 			{ 20, 21, -12 }
978d54fbea3SDmitry Baryshkov 			}
979d54fbea3SDmitry Baryshkov 		}
980d54fbea3SDmitry Baryshkov 	},
981d54fbea3SDmitry Baryshkov 	{
982d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(10), .bpc = 16,
983d54fbea3SDmitry Baryshkov 		{ 273, 15, 2048, 19, 28, 27, 27, {
984d54fbea3SDmitry Baryshkov 			{ 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
985d54fbea3SDmitry Baryshkov 			{ 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
986d54fbea3SDmitry Baryshkov 			{ 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
987d54fbea3SDmitry Baryshkov 			{ 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
988d54fbea3SDmitry Baryshkov 			{ 24, 25, -12 }
989d54fbea3SDmitry Baryshkov 			}
990d54fbea3SDmitry Baryshkov 		}
991d54fbea3SDmitry Baryshkov 	},
992d54fbea3SDmitry Baryshkov 	{ /* sentinel */ }
993d54fbea3SDmitry Baryshkov };
994d54fbea3SDmitry Baryshkov 
995d54fbea3SDmitry Baryshkov /*
996d54fbea3SDmitry Baryshkov  * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from
997d54fbea3SDmitry Baryshkov  * DSC v1.2, v1.2a, v1.2b
998d54fbea3SDmitry Baryshkov  *
999d54fbea3SDmitry Baryshkov  * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
1000d54fbea3SDmitry Baryshkov  */
1001d54fbea3SDmitry Baryshkov static const struct rc_parameters_data rc_parameters_1_2_420[] = {
1002d54fbea3SDmitry Baryshkov 	{
1003d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(4), .bpc = 8,
1004d54fbea3SDmitry Baryshkov 		{ 512, 12, 6144, 3, 12, 11, 11, {
1005d54fbea3SDmitry Baryshkov 			{ 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
1006d54fbea3SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
1007d54fbea3SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
1008d54fbea3SDmitry Baryshkov 			{ 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
1009d54fbea3SDmitry Baryshkov 			}
1010d54fbea3SDmitry Baryshkov 		}
1011d54fbea3SDmitry Baryshkov 	},
1012d54fbea3SDmitry Baryshkov 	{
1013d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(4), .bpc = 10,
1014d54fbea3SDmitry Baryshkov 		{ 512, 12, 6144, 7, 16, 15, 15, {
1015d54fbea3SDmitry Baryshkov 			{ 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
1016d54fbea3SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
1017d54fbea3SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
1018d54fbea3SDmitry Baryshkov 			{ 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
1019d54fbea3SDmitry Baryshkov 			}
1020d54fbea3SDmitry Baryshkov 		}
1021d54fbea3SDmitry Baryshkov 	},
1022d54fbea3SDmitry Baryshkov 	{
1023d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(4), .bpc = 12,
1024d54fbea3SDmitry Baryshkov 		{ 512, 12, 6144, 11, 20, 19, 19, {
1025d54fbea3SDmitry Baryshkov 			{ 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
1026d54fbea3SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
1027d54fbea3SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
1028d54fbea3SDmitry Baryshkov 			{ 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
1029d54fbea3SDmitry Baryshkov 			{ 20, 21, -12 }
1030d54fbea3SDmitry Baryshkov 			}
1031d54fbea3SDmitry Baryshkov 		}
1032d54fbea3SDmitry Baryshkov 	},
1033d54fbea3SDmitry Baryshkov 	{
1034d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(4), .bpc = 14,
1035d54fbea3SDmitry Baryshkov 		{ 512, 12, 6144, 15, 24, 23, 23, {
1036d54fbea3SDmitry Baryshkov 			{ 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
1037d54fbea3SDmitry Baryshkov 			{ 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
1038d54fbea3SDmitry Baryshkov 			{ 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
1039d54fbea3SDmitry Baryshkov 			{ 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
1040d54fbea3SDmitry Baryshkov 			{ 24, 25, -12 }
1041d54fbea3SDmitry Baryshkov 			}
1042d54fbea3SDmitry Baryshkov 		}
1043d54fbea3SDmitry Baryshkov 	},
1044d54fbea3SDmitry Baryshkov 	{
1045d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(4), .bpc = 16,
1046d54fbea3SDmitry Baryshkov 		{ 512, 12, 6144, 19, 28, 27, 27, {
1047d54fbea3SDmitry Baryshkov 			{ 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
1048d54fbea3SDmitry Baryshkov 			{ 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
1049d54fbea3SDmitry Baryshkov 			{ 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
1050d54fbea3SDmitry Baryshkov 			{ 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
1051d54fbea3SDmitry Baryshkov 			{ 28, 29, -12 }
1052d54fbea3SDmitry Baryshkov 			}
1053d54fbea3SDmitry Baryshkov 		}
1054d54fbea3SDmitry Baryshkov 	},
1055d54fbea3SDmitry Baryshkov 	{
1056d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(5), .bpc = 8,
1057d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 3, 12, 11, 11, {
1058d54fbea3SDmitry Baryshkov 			{ 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
1059d54fbea3SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
1060d54fbea3SDmitry Baryshkov 			{ 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
1061d54fbea3SDmitry Baryshkov 			{ 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
1062d54fbea3SDmitry Baryshkov 			}
1063d54fbea3SDmitry Baryshkov 		}
1064d54fbea3SDmitry Baryshkov 	},
1065d54fbea3SDmitry Baryshkov 	{
1066d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(5), .bpc = 10,
1067d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 7, 16, 15, 15, {
1068d54fbea3SDmitry Baryshkov 			{ 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
1069d54fbea3SDmitry Baryshkov 			{ 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
1070d54fbea3SDmitry Baryshkov 			{ 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
1071d54fbea3SDmitry Baryshkov 			{ 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
1072d54fbea3SDmitry Baryshkov 			}
1073d54fbea3SDmitry Baryshkov 		}
1074d54fbea3SDmitry Baryshkov 	},
1075d54fbea3SDmitry Baryshkov 	{
1076d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(5), .bpc = 12,
1077d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 11, 20, 19, 19, {
1078d54fbea3SDmitry Baryshkov 			{ 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
1079d54fbea3SDmitry Baryshkov 			{ 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
1080d54fbea3SDmitry Baryshkov 			{ 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
1081d54fbea3SDmitry Baryshkov 			{ 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
1082d54fbea3SDmitry Baryshkov 			{ 19, 20, -12 }
1083d54fbea3SDmitry Baryshkov 			}
1084d54fbea3SDmitry Baryshkov 		}
1085d54fbea3SDmitry Baryshkov 	},
1086d54fbea3SDmitry Baryshkov 	{
1087d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(5), .bpc = 14,
1088d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 15, 24, 23, 23, {
1089d54fbea3SDmitry Baryshkov 			{ 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
1090d54fbea3SDmitry Baryshkov 			{ 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
1091d54fbea3SDmitry Baryshkov 			{ 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
1092d54fbea3SDmitry Baryshkov 			{ 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
1093d54fbea3SDmitry Baryshkov 			{ 23, 24, -12 }
1094d54fbea3SDmitry Baryshkov 			}
1095d54fbea3SDmitry Baryshkov 		}
1096d54fbea3SDmitry Baryshkov 	},
1097d54fbea3SDmitry Baryshkov 	{
1098d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(5), .bpc = 16,
1099d54fbea3SDmitry Baryshkov 		{ 410, 15, 5632, 19, 28, 27, 27, {
1100d54fbea3SDmitry Baryshkov 			{ 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
1101d54fbea3SDmitry Baryshkov 			{ 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
1102d54fbea3SDmitry Baryshkov 			{ 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
1103d54fbea3SDmitry Baryshkov 			{ 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
1104d54fbea3SDmitry Baryshkov 			{ 27, 28, -12 }
1105d54fbea3SDmitry Baryshkov 			}
1106d54fbea3SDmitry Baryshkov 		}
1107d54fbea3SDmitry Baryshkov 	},
1108d54fbea3SDmitry Baryshkov 	{
1109d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 8,
1110d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 3, 12, 11, 11, {
1111d54fbea3SDmitry Baryshkov 			{ 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
1112d54fbea3SDmitry Baryshkov 			{ 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
1113d54fbea3SDmitry Baryshkov 			{ 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
1114d54fbea3SDmitry Baryshkov 			{ 5, 9, -12 }, { 7, 10, -12 }, { 10, 12, -12 }
1115d54fbea3SDmitry Baryshkov 			}
1116d54fbea3SDmitry Baryshkov 		}
1117d54fbea3SDmitry Baryshkov 	},
1118d54fbea3SDmitry Baryshkov 	{
1119d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 10,
1120d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 7, 16, 15, 15, {
1121d54fbea3SDmitry Baryshkov 			{ 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
1122d54fbea3SDmitry Baryshkov 			{ 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
1123d54fbea3SDmitry Baryshkov 			{ 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
1124d54fbea3SDmitry Baryshkov 			{ 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
1125d54fbea3SDmitry Baryshkov 			}
1126d54fbea3SDmitry Baryshkov 		}
1127d54fbea3SDmitry Baryshkov 	},
1128d54fbea3SDmitry Baryshkov 	{
1129d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 12,
1130d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 11, 20, 19, 19, {
1131d54fbea3SDmitry Baryshkov 			{ 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
1132d54fbea3SDmitry Baryshkov 			{ 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
1133d54fbea3SDmitry Baryshkov 			{ 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
1134d54fbea3SDmitry Baryshkov 			{ 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
1135d54fbea3SDmitry Baryshkov 			{ 18, 19, -12 }
1136d54fbea3SDmitry Baryshkov 			}
1137d54fbea3SDmitry Baryshkov 		}
1138d54fbea3SDmitry Baryshkov 	},
1139d54fbea3SDmitry Baryshkov 	{
1140d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 14,
1141d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 15, 24, 23, 23, {
1142d54fbea3SDmitry Baryshkov 			{ 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
1143d54fbea3SDmitry Baryshkov 			{ 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
1144d54fbea3SDmitry Baryshkov 			{ 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
1145d54fbea3SDmitry Baryshkov 			{ 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
1146d54fbea3SDmitry Baryshkov 			{ 22, 23, -12 }
1147d54fbea3SDmitry Baryshkov 			}
1148d54fbea3SDmitry Baryshkov 		}
1149d54fbea3SDmitry Baryshkov 	},
1150d54fbea3SDmitry Baryshkov 	{
1151d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(6), .bpc = 16,
1152d54fbea3SDmitry Baryshkov 		{ 341, 15, 2048, 19, 28, 27, 27, {
1153d54fbea3SDmitry Baryshkov 			{ 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
1154d54fbea3SDmitry Baryshkov 			{ 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
1155d54fbea3SDmitry Baryshkov 			{ 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
1156d54fbea3SDmitry Baryshkov 			{ 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
1157d54fbea3SDmitry Baryshkov 			{ 26, 27, -12 }
1158d54fbea3SDmitry Baryshkov 			}
1159d54fbea3SDmitry Baryshkov 		}
1160d54fbea3SDmitry Baryshkov 	},
1161d54fbea3SDmitry Baryshkov 	{
1162d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 8,
1163d54fbea3SDmitry Baryshkov 		{ 256, 15, 2048, 3, 12, 11, 11, {
1164d54fbea3SDmitry Baryshkov 			{ 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
1165d54fbea3SDmitry Baryshkov 			{ 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
1166d54fbea3SDmitry Baryshkov 			{ 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
1167d54fbea3SDmitry Baryshkov 			{ 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
1168d54fbea3SDmitry Baryshkov 			}
1169d54fbea3SDmitry Baryshkov 		}
1170d54fbea3SDmitry Baryshkov 	},
1171d54fbea3SDmitry Baryshkov 	{
1172d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 10,
1173d54fbea3SDmitry Baryshkov 		{ 256, 15, 2048, 7, 16, 15, 15, {
1174d54fbea3SDmitry Baryshkov 			{ 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
1175d54fbea3SDmitry Baryshkov 			{ 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
1176d54fbea3SDmitry Baryshkov 			{ 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
1177d54fbea3SDmitry Baryshkov 			{ 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
1178d54fbea3SDmitry Baryshkov 			}
1179d54fbea3SDmitry Baryshkov 		}
1180d54fbea3SDmitry Baryshkov 	},
1181d54fbea3SDmitry Baryshkov 	{
1182d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 12,
1183d54fbea3SDmitry Baryshkov 		{ 256, 15, 2048, 11, 20, 19, 19, {
1184d54fbea3SDmitry Baryshkov 			{ 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
1185d54fbea3SDmitry Baryshkov 			{ 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
1186d54fbea3SDmitry Baryshkov 			{ 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
1187d54fbea3SDmitry Baryshkov 			{ 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
1188d54fbea3SDmitry Baryshkov 			{ 16, 17, -12 }
1189d54fbea3SDmitry Baryshkov 			}
1190d54fbea3SDmitry Baryshkov 		}
1191d54fbea3SDmitry Baryshkov 	},
1192d54fbea3SDmitry Baryshkov 	{
1193d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 14,
1194d54fbea3SDmitry Baryshkov 		{ 256, 15, 2048, 15, 24, 23, 23, {
1195d54fbea3SDmitry Baryshkov 			{ 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
1196d54fbea3SDmitry Baryshkov 			{ 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
1197d54fbea3SDmitry Baryshkov 			{ 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
1198d54fbea3SDmitry Baryshkov 			{ 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
1199d54fbea3SDmitry Baryshkov 			{ 20, 21, -12 }
1200d54fbea3SDmitry Baryshkov 			}
1201d54fbea3SDmitry Baryshkov 		}
1202d54fbea3SDmitry Baryshkov 	},
1203d54fbea3SDmitry Baryshkov 	{
1204d54fbea3SDmitry Baryshkov 		.bpp = DSC_BPP(8), .bpc = 16,
1205d54fbea3SDmitry Baryshkov 		{ 256, 15, 2048, 19, 28, 27, 27, {
1206d54fbea3SDmitry Baryshkov 			{ 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
1207d54fbea3SDmitry Baryshkov 			{ 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
1208d54fbea3SDmitry Baryshkov 			{ 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
1209d54fbea3SDmitry Baryshkov 			{ 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
1210d54fbea3SDmitry Baryshkov 			{ 24, 25, -12 }
1211d54fbea3SDmitry Baryshkov 			}
1212d54fbea3SDmitry Baryshkov 		}
1213d54fbea3SDmitry Baryshkov 	},
1214d54fbea3SDmitry Baryshkov 	{ /* sentinel */ }
1215d54fbea3SDmitry Baryshkov };
1216d54fbea3SDmitry Baryshkov 
1217e3290f88SDmitry Baryshkov static const struct rc_parameters *get_rc_params(const struct rc_parameters_data *rc_parameters,
1218e3290f88SDmitry Baryshkov 						 u16 dsc_bpp,
12192b470e55SDmitry Baryshkov 						 u8 bits_per_component)
12202b470e55SDmitry Baryshkov {
122174fe874cSDmitry Baryshkov 	int i;
12222b470e55SDmitry Baryshkov 
122374fe874cSDmitry Baryshkov 	for (i = 0; rc_parameters[i].bpp; i++)
122474fe874cSDmitry Baryshkov 		if (rc_parameters[i].bpp == dsc_bpp &&
122574fe874cSDmitry Baryshkov 		    rc_parameters[i].bpc == bits_per_component)
122674fe874cSDmitry Baryshkov 			return &rc_parameters[i].params;
122774fe874cSDmitry Baryshkov 
12282b470e55SDmitry Baryshkov 	return NULL;
12292b470e55SDmitry Baryshkov }
12302b470e55SDmitry Baryshkov 
12312b470e55SDmitry Baryshkov /**
12322b470e55SDmitry Baryshkov  * drm_dsc_setup_rc_params() - Set parameters and limits for RC model in
12332b470e55SDmitry Baryshkov  * accordance with the DSC 1.1 or 1.2 specification and DSC C Model
12342b470e55SDmitry Baryshkov  * Required bits_per_pixel and bits_per_component to be set before calling this
12352b470e55SDmitry Baryshkov  * function.
12362b470e55SDmitry Baryshkov  *
12372b470e55SDmitry Baryshkov  * @vdsc_cfg: DSC Configuration data partially filled by driver
1238e3290f88SDmitry Baryshkov  * @type: operating mode and standard to follow
12392b470e55SDmitry Baryshkov  *
12402b470e55SDmitry Baryshkov  * Return: 0 or -error code in case of an error
12412b470e55SDmitry Baryshkov  */
1242e3290f88SDmitry Baryshkov int drm_dsc_setup_rc_params(struct drm_dsc_config *vdsc_cfg, enum drm_dsc_params_type type)
12432b470e55SDmitry Baryshkov {
1244e3290f88SDmitry Baryshkov 	const struct rc_parameters_data *data;
12452b470e55SDmitry Baryshkov 	const struct rc_parameters *rc_params;
12462b470e55SDmitry Baryshkov 	int i;
12472b470e55SDmitry Baryshkov 
12482b470e55SDmitry Baryshkov 	if (WARN_ON_ONCE(!vdsc_cfg->bits_per_pixel ||
12492b470e55SDmitry Baryshkov 			 !vdsc_cfg->bits_per_component))
12502b470e55SDmitry Baryshkov 		return -EINVAL;
12512b470e55SDmitry Baryshkov 
1252e3290f88SDmitry Baryshkov 	switch (type) {
1253e3290f88SDmitry Baryshkov 	case DRM_DSC_1_2_444:
1254e3290f88SDmitry Baryshkov 		data = rc_parameters_1_2_444;
1255e3290f88SDmitry Baryshkov 		break;
1256e3290f88SDmitry Baryshkov 	case DRM_DSC_1_1_PRE_SCR:
1257e3290f88SDmitry Baryshkov 		data = rc_parameters_pre_scr;
1258e3290f88SDmitry Baryshkov 		break;
1259d54fbea3SDmitry Baryshkov 	case DRM_DSC_1_2_422:
1260d54fbea3SDmitry Baryshkov 		data = rc_parameters_1_2_422;
1261d54fbea3SDmitry Baryshkov 		break;
1262d54fbea3SDmitry Baryshkov 	case DRM_DSC_1_2_420:
1263d54fbea3SDmitry Baryshkov 		data = rc_parameters_1_2_420;
1264d54fbea3SDmitry Baryshkov 		break;
1265e3290f88SDmitry Baryshkov 	default:
1266e3290f88SDmitry Baryshkov 		return -EINVAL;
1267e3290f88SDmitry Baryshkov 	}
1268e3290f88SDmitry Baryshkov 
1269e3290f88SDmitry Baryshkov 	rc_params = get_rc_params(data,
1270e3290f88SDmitry Baryshkov 				  vdsc_cfg->bits_per_pixel,
12712b470e55SDmitry Baryshkov 				  vdsc_cfg->bits_per_component);
12722b470e55SDmitry Baryshkov 	if (!rc_params)
12732b470e55SDmitry Baryshkov 		return -EINVAL;
12742b470e55SDmitry Baryshkov 
12752b470e55SDmitry Baryshkov 	vdsc_cfg->first_line_bpg_offset = rc_params->first_line_bpg_offset;
12762b470e55SDmitry Baryshkov 	vdsc_cfg->initial_xmit_delay = rc_params->initial_xmit_delay;
12772b470e55SDmitry Baryshkov 	vdsc_cfg->initial_offset = rc_params->initial_offset;
12782b470e55SDmitry Baryshkov 	vdsc_cfg->flatness_min_qp = rc_params->flatness_min_qp;
12792b470e55SDmitry Baryshkov 	vdsc_cfg->flatness_max_qp = rc_params->flatness_max_qp;
12802b470e55SDmitry Baryshkov 	vdsc_cfg->rc_quant_incr_limit0 = rc_params->rc_quant_incr_limit0;
12812b470e55SDmitry Baryshkov 	vdsc_cfg->rc_quant_incr_limit1 = rc_params->rc_quant_incr_limit1;
12822b470e55SDmitry Baryshkov 
12832b470e55SDmitry Baryshkov 	for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
12842b470e55SDmitry Baryshkov 		vdsc_cfg->rc_range_params[i].range_min_qp =
12852b470e55SDmitry Baryshkov 			rc_params->rc_range_params[i].range_min_qp;
12862b470e55SDmitry Baryshkov 		vdsc_cfg->rc_range_params[i].range_max_qp =
12872b470e55SDmitry Baryshkov 			rc_params->rc_range_params[i].range_max_qp;
12882b470e55SDmitry Baryshkov 		/*
12892b470e55SDmitry Baryshkov 		 * Range BPG Offset uses 2's complement and is only a 6 bits. So
12902b470e55SDmitry Baryshkov 		 * mask it to get only 6 bits.
12912b470e55SDmitry Baryshkov 		 */
12922b470e55SDmitry Baryshkov 		vdsc_cfg->rc_range_params[i].range_bpg_offset =
12932b470e55SDmitry Baryshkov 			rc_params->rc_range_params[i].range_bpg_offset &
12942b470e55SDmitry Baryshkov 			DSC_RANGE_BPG_OFFSET_MASK;
12952b470e55SDmitry Baryshkov 	}
12962b470e55SDmitry Baryshkov 
12972b470e55SDmitry Baryshkov 	return 0;
12982b470e55SDmitry Baryshkov }
12992b470e55SDmitry Baryshkov EXPORT_SYMBOL(drm_dsc_setup_rc_params);
13002b470e55SDmitry Baryshkov 
13012a64b147SThomas Zimmermann /**
13022a64b147SThomas Zimmermann  * drm_dsc_compute_rc_parameters() - Write rate control
13032a64b147SThomas Zimmermann  * parameters to the dsc configuration defined in
13042a64b147SThomas Zimmermann  * &struct drm_dsc_config in accordance with the DSC 1.2
13052a64b147SThomas Zimmermann  * specification. Some configuration fields must be present
13062a64b147SThomas Zimmermann  * beforehand.
13072a64b147SThomas Zimmermann  *
13082a64b147SThomas Zimmermann  * @vdsc_cfg:
13092a64b147SThomas Zimmermann  * DSC Configuration data partially filled by driver
13102a64b147SThomas Zimmermann  */
13112a64b147SThomas Zimmermann int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg)
13122a64b147SThomas Zimmermann {
13132a64b147SThomas Zimmermann 	unsigned long groups_per_line = 0;
13142a64b147SThomas Zimmermann 	unsigned long groups_total = 0;
13152a64b147SThomas Zimmermann 	unsigned long num_extra_mux_bits = 0;
13162a64b147SThomas Zimmermann 	unsigned long slice_bits = 0;
13172a64b147SThomas Zimmermann 	unsigned long hrd_delay = 0;
13182a64b147SThomas Zimmermann 	unsigned long final_scale = 0;
13192a64b147SThomas Zimmermann 	unsigned long rbs_min = 0;
13202a64b147SThomas Zimmermann 
13212a64b147SThomas Zimmermann 	if (vdsc_cfg->native_420 || vdsc_cfg->native_422) {
13222a64b147SThomas Zimmermann 		/* Number of groups used to code each line of a slice */
13232a64b147SThomas Zimmermann 		groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width / 2,
13242a64b147SThomas Zimmermann 					       DSC_RC_PIXELS_PER_GROUP);
13252a64b147SThomas Zimmermann 
13262a64b147SThomas Zimmermann 		/* chunksize in Bytes */
13272a64b147SThomas Zimmermann 		vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width / 2 *
13282a64b147SThomas Zimmermann 							  vdsc_cfg->bits_per_pixel,
13292a64b147SThomas Zimmermann 							  (8 * 16));
13302a64b147SThomas Zimmermann 	} else {
13312a64b147SThomas Zimmermann 		/* Number of groups used to code each line of a slice */
13322a64b147SThomas Zimmermann 		groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width,
13332a64b147SThomas Zimmermann 					       DSC_RC_PIXELS_PER_GROUP);
13342a64b147SThomas Zimmermann 
13352a64b147SThomas Zimmermann 		/* chunksize in Bytes */
13362a64b147SThomas Zimmermann 		vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width *
13372a64b147SThomas Zimmermann 							  vdsc_cfg->bits_per_pixel,
13382a64b147SThomas Zimmermann 							  (8 * 16));
13392a64b147SThomas Zimmermann 	}
13402a64b147SThomas Zimmermann 
13412a64b147SThomas Zimmermann 	if (vdsc_cfg->convert_rgb)
13422a64b147SThomas Zimmermann 		num_extra_mux_bits = 3 * (vdsc_cfg->mux_word_size +
13432a64b147SThomas Zimmermann 					  (4 * vdsc_cfg->bits_per_component + 4)
13442a64b147SThomas Zimmermann 					  - 2);
13452a64b147SThomas Zimmermann 	else if (vdsc_cfg->native_422)
13462a64b147SThomas Zimmermann 		num_extra_mux_bits = 4 * vdsc_cfg->mux_word_size +
13472a64b147SThomas Zimmermann 			(4 * vdsc_cfg->bits_per_component + 4) +
13482a64b147SThomas Zimmermann 			3 * (4 * vdsc_cfg->bits_per_component) - 2;
13492a64b147SThomas Zimmermann 	else
13502a64b147SThomas Zimmermann 		num_extra_mux_bits = 3 * vdsc_cfg->mux_word_size +
13512a64b147SThomas Zimmermann 			(4 * vdsc_cfg->bits_per_component + 4) +
13522a64b147SThomas Zimmermann 			2 * (4 * vdsc_cfg->bits_per_component) - 2;
13532a64b147SThomas Zimmermann 	/* Number of bits in one Slice */
13542a64b147SThomas Zimmermann 	slice_bits = 8 * vdsc_cfg->slice_chunk_size * vdsc_cfg->slice_height;
13552a64b147SThomas Zimmermann 
13562a64b147SThomas Zimmermann 	while ((num_extra_mux_bits > 0) &&
13572a64b147SThomas Zimmermann 	       ((slice_bits - num_extra_mux_bits) % vdsc_cfg->mux_word_size))
13582a64b147SThomas Zimmermann 		num_extra_mux_bits--;
13592a64b147SThomas Zimmermann 
13602a64b147SThomas Zimmermann 	if (groups_per_line < vdsc_cfg->initial_scale_value - 8)
13612a64b147SThomas Zimmermann 		vdsc_cfg->initial_scale_value = groups_per_line + 8;
13622a64b147SThomas Zimmermann 
13632a64b147SThomas Zimmermann 	/* scale_decrement_interval calculation according to DSC spec 1.11 */
13642a64b147SThomas Zimmermann 	if (vdsc_cfg->initial_scale_value > 8)
13652a64b147SThomas Zimmermann 		vdsc_cfg->scale_decrement_interval = groups_per_line /
13662a64b147SThomas Zimmermann 			(vdsc_cfg->initial_scale_value - 8);
13672a64b147SThomas Zimmermann 	else
13682a64b147SThomas Zimmermann 		vdsc_cfg->scale_decrement_interval = DSC_SCALE_DECREMENT_INTERVAL_MAX;
13692a64b147SThomas Zimmermann 
13702a64b147SThomas Zimmermann 	vdsc_cfg->final_offset = vdsc_cfg->rc_model_size -
13712a64b147SThomas Zimmermann 		(vdsc_cfg->initial_xmit_delay *
13722a64b147SThomas Zimmermann 		 vdsc_cfg->bits_per_pixel + 8) / 16 + num_extra_mux_bits;
13732a64b147SThomas Zimmermann 
13742a64b147SThomas Zimmermann 	if (vdsc_cfg->final_offset >= vdsc_cfg->rc_model_size) {
13752a64b147SThomas Zimmermann 		DRM_DEBUG_KMS("FinalOfs < RcModelSze for this InitialXmitDelay\n");
13762a64b147SThomas Zimmermann 		return -ERANGE;
13772a64b147SThomas Zimmermann 	}
13782a64b147SThomas Zimmermann 
13792a64b147SThomas Zimmermann 	final_scale = (vdsc_cfg->rc_model_size * 8) /
13802a64b147SThomas Zimmermann 		(vdsc_cfg->rc_model_size - vdsc_cfg->final_offset);
13812a64b147SThomas Zimmermann 	if (vdsc_cfg->slice_height > 1)
13822a64b147SThomas Zimmermann 		/*
13832a64b147SThomas Zimmermann 		 * NflBpgOffset is 16 bit value with 11 fractional bits
13842a64b147SThomas Zimmermann 		 * hence we multiply by 2^11 for preserving the
13852a64b147SThomas Zimmermann 		 * fractional part
13862a64b147SThomas Zimmermann 		 */
13872a64b147SThomas Zimmermann 		vdsc_cfg->nfl_bpg_offset = DIV_ROUND_UP((vdsc_cfg->first_line_bpg_offset << 11),
13882a64b147SThomas Zimmermann 							(vdsc_cfg->slice_height - 1));
13892a64b147SThomas Zimmermann 	else
13902a64b147SThomas Zimmermann 		vdsc_cfg->nfl_bpg_offset = 0;
13912a64b147SThomas Zimmermann 
13922a64b147SThomas Zimmermann 	/* Number of groups used to code the entire slice */
13932a64b147SThomas Zimmermann 	groups_total = groups_per_line * vdsc_cfg->slice_height;
13942a64b147SThomas Zimmermann 
13952a64b147SThomas Zimmermann 	/* slice_bpg_offset is 16 bit value with 11 fractional bits */
13962a64b147SThomas Zimmermann 	vdsc_cfg->slice_bpg_offset = DIV_ROUND_UP(((vdsc_cfg->rc_model_size -
13972a64b147SThomas Zimmermann 						    vdsc_cfg->initial_offset +
13982a64b147SThomas Zimmermann 						    num_extra_mux_bits) << 11),
13992a64b147SThomas Zimmermann 						  groups_total);
14002a64b147SThomas Zimmermann 
14012a64b147SThomas Zimmermann 	if (final_scale > 9) {
14022a64b147SThomas Zimmermann 		/*
14032a64b147SThomas Zimmermann 		 * ScaleIncrementInterval =
14042a64b147SThomas Zimmermann 		 * finaloffset/((NflBpgOffset + SliceBpgOffset)*8(finalscale - 1.125))
14052a64b147SThomas Zimmermann 		 * as (NflBpgOffset + SliceBpgOffset) has 11 bit fractional value,
14062a64b147SThomas Zimmermann 		 * we need divide by 2^11 from pstDscCfg values
14072a64b147SThomas Zimmermann 		 */
14082a64b147SThomas Zimmermann 		vdsc_cfg->scale_increment_interval =
14092a64b147SThomas Zimmermann 				(vdsc_cfg->final_offset * (1 << 11)) /
14102a64b147SThomas Zimmermann 				((vdsc_cfg->nfl_bpg_offset +
14112a64b147SThomas Zimmermann 				vdsc_cfg->slice_bpg_offset) *
14122a64b147SThomas Zimmermann 				(final_scale - 9));
14132a64b147SThomas Zimmermann 	} else {
14142a64b147SThomas Zimmermann 		/*
14152a64b147SThomas Zimmermann 		 * If finalScaleValue is less than or equal to 9, a value of 0 should
14162a64b147SThomas Zimmermann 		 * be used to disable the scale increment at the end of the slice
14172a64b147SThomas Zimmermann 		 */
14182a64b147SThomas Zimmermann 		vdsc_cfg->scale_increment_interval = 0;
14192a64b147SThomas Zimmermann 	}
14202a64b147SThomas Zimmermann 
14212a64b147SThomas Zimmermann 	/*
14222a64b147SThomas Zimmermann 	 * DSC spec mentions that bits_per_pixel specifies the target
14232a64b147SThomas Zimmermann 	 * bits/pixel (bpp) rate that is used by the encoder,
14242a64b147SThomas Zimmermann 	 * in steps of 1/16 of a bit per pixel
14252a64b147SThomas Zimmermann 	 */
14262a64b147SThomas Zimmermann 	rbs_min = vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset +
14272a64b147SThomas Zimmermann 		DIV_ROUND_UP(vdsc_cfg->initial_xmit_delay *
14282a64b147SThomas Zimmermann 			     vdsc_cfg->bits_per_pixel, 16) +
14292a64b147SThomas Zimmermann 		groups_per_line * vdsc_cfg->first_line_bpg_offset;
14302a64b147SThomas Zimmermann 
14312a64b147SThomas Zimmermann 	hrd_delay = DIV_ROUND_UP((rbs_min * 16), vdsc_cfg->bits_per_pixel);
14322a64b147SThomas Zimmermann 	vdsc_cfg->rc_bits = (hrd_delay * vdsc_cfg->bits_per_pixel) / 16;
14332a64b147SThomas Zimmermann 	vdsc_cfg->initial_dec_delay = hrd_delay - vdsc_cfg->initial_xmit_delay;
14342a64b147SThomas Zimmermann 
14352a64b147SThomas Zimmermann 	return 0;
14362a64b147SThomas Zimmermann }
14372a64b147SThomas Zimmermann EXPORT_SYMBOL(drm_dsc_compute_rc_parameters);
14387df1ed6dSJessica Zhang 
14397df1ed6dSJessica Zhang /**
14407df1ed6dSJessica Zhang  * drm_dsc_initial_scale_value() - Calculate the initial scale value for the given DSC config
14417df1ed6dSJessica Zhang  * @dsc: Pointer to DRM DSC config struct
14427df1ed6dSJessica Zhang  *
14437df1ed6dSJessica Zhang  * Return: Calculated initial scale value
14447df1ed6dSJessica Zhang  */
14457df1ed6dSJessica Zhang u8 drm_dsc_initial_scale_value(const struct drm_dsc_config *dsc)
14467df1ed6dSJessica Zhang {
14477df1ed6dSJessica Zhang 	return 8 * dsc->rc_model_size / (dsc->rc_model_size - dsc->initial_offset);
14487df1ed6dSJessica Zhang }
14497df1ed6dSJessica Zhang EXPORT_SYMBOL(drm_dsc_initial_scale_value);
14507df1ed6dSJessica Zhang 
14517df1ed6dSJessica Zhang /**
14527df1ed6dSJessica Zhang  * drm_dsc_flatness_det_thresh() - Calculate the flatness_det_thresh for the given DSC config
14537df1ed6dSJessica Zhang  * @dsc: Pointer to DRM DSC config struct
14547df1ed6dSJessica Zhang  *
14557df1ed6dSJessica Zhang  * Return: Calculated flatness det thresh value
14567df1ed6dSJessica Zhang  */
14577df1ed6dSJessica Zhang u32 drm_dsc_flatness_det_thresh(const struct drm_dsc_config *dsc)
14587df1ed6dSJessica Zhang {
14597df1ed6dSJessica Zhang 	return 2 << (dsc->bits_per_component - 8);
14607df1ed6dSJessica Zhang }
14617df1ed6dSJessica Zhang EXPORT_SYMBOL(drm_dsc_flatness_det_thresh);
1462