Home | History | Annotate | Line # | Download | only in drm
drm_dsc.c revision 1.1
      1  1.1  riastrad /*	$NetBSD: drm_dsc.c,v 1.1 2021/12/18 20:11:01 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad // SPDX-License-Identifier: MIT
      4  1.1  riastrad /*
      5  1.1  riastrad  * Copyright  2018 Intel Corp
      6  1.1  riastrad  *
      7  1.1  riastrad  * Author:
      8  1.1  riastrad  * Manasi Navare <manasi.d.navare (at) intel.com>
      9  1.1  riastrad  */
     10  1.1  riastrad 
     11  1.1  riastrad #include <sys/cdefs.h>
     12  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_dsc.c,v 1.1 2021/12/18 20:11:01 riastradh Exp $");
     13  1.1  riastrad 
     14  1.1  riastrad #include <linux/kernel.h>
     15  1.1  riastrad #include <linux/module.h>
     16  1.1  riastrad #include <linux/init.h>
     17  1.1  riastrad #include <linux/errno.h>
     18  1.1  riastrad #include <linux/byteorder/generic.h>
     19  1.1  riastrad #include <drm/drm_print.h>
     20  1.1  riastrad #include <drm/drm_dp_helper.h>
     21  1.1  riastrad #include <drm/drm_dsc.h>
     22  1.1  riastrad 
     23  1.1  riastrad /**
     24  1.1  riastrad  * DOC: dsc helpers
     25  1.1  riastrad  *
     26  1.1  riastrad  * VESA specification for DP 1.4 adds a new feature called Display Stream
     27  1.1  riastrad  * Compression (DSC) used to compress the pixel bits before sending it on
     28  1.1  riastrad  * DP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existing
     29  1.1  riastrad  * display interfaces can support high resolutions at higher frames rates uisng
     30  1.1  riastrad  * the maximum available link capacity of these interfaces.
     31  1.1  riastrad  *
     32  1.1  riastrad  * These functions contain some common logic and helpers to deal with VESA
     33  1.1  riastrad  * Display Stream Compression standard required for DSC on Display Port/eDP or
     34  1.1  riastrad  * MIPI display interfaces.
     35  1.1  riastrad  */
     36  1.1  riastrad 
     37  1.1  riastrad /**
     38  1.1  riastrad  * drm_dsc_dp_pps_header_init() - Initializes the PPS Header
     39  1.1  riastrad  * for DisplayPort as per the DP 1.4 spec.
     40  1.1  riastrad  * @pps_header: Secondary data packet header for DSC Picture
     41  1.1  riastrad  *              Parameter Set as defined in &struct dp_sdp_header
     42  1.1  riastrad  *
     43  1.1  riastrad  * DP 1.4 spec defines the secondary data packet for sending the
     44  1.1  riastrad  * picture parameter infoframes from the source to the sink.
     45  1.1  riastrad  * This function populates the SDP header defined in
     46  1.1  riastrad  * &struct dp_sdp_header.
     47  1.1  riastrad  */
     48  1.1  riastrad void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header)
     49  1.1  riastrad {
     50  1.1  riastrad 	memset(pps_header, 0, sizeof(*pps_header));
     51  1.1  riastrad 
     52  1.1  riastrad 	pps_header->HB1 = DP_SDP_PPS;
     53  1.1  riastrad 	pps_header->HB2 = DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1;
     54  1.1  riastrad }
     55  1.1  riastrad EXPORT_SYMBOL(drm_dsc_dp_pps_header_init);
     56  1.1  riastrad 
     57  1.1  riastrad /**
     58  1.1  riastrad  * drm_dsc_pps_payload_pack() - Populates the DSC PPS
     59  1.1  riastrad  *
     60  1.1  riastrad  * @pps_payload:
     61  1.1  riastrad  * Bitwise struct for DSC Picture Parameter Set. This is defined
     62  1.1  riastrad  * by &struct drm_dsc_picture_parameter_set
     63  1.1  riastrad  * @dsc_cfg:
     64  1.1  riastrad  * DSC Configuration data filled by driver as defined by
     65  1.1  riastrad  * &struct drm_dsc_config
     66  1.1  riastrad  *
     67  1.1  riastrad  * DSC source device sends a picture parameter set (PPS) containing the
     68  1.1  riastrad  * information required by the sink to decode the compressed frame. Driver
     69  1.1  riastrad  * populates the DSC PPS struct using the DSC configuration parameters in
     70  1.1  riastrad  * the order expected by the DSC Display Sink device. For the DSC, the sink
     71  1.1  riastrad  * device expects the PPS payload in big endian format for fields
     72  1.1  riastrad  * that span more than 1 byte.
     73  1.1  riastrad  */
     74  1.1  riastrad void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload,
     75  1.1  riastrad 				const struct drm_dsc_config *dsc_cfg)
     76  1.1  riastrad {
     77  1.1  riastrad 	int i;
     78  1.1  riastrad 
     79  1.1  riastrad 	/* Protect against someone accidently changing struct size */
     80  1.1  riastrad 	BUILD_BUG_ON(sizeof(*pps_payload) !=
     81  1.1  riastrad 		     DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1 + 1);
     82  1.1  riastrad 
     83  1.1  riastrad 	memset(pps_payload, 0, sizeof(*pps_payload));
     84  1.1  riastrad 
     85  1.1  riastrad 	/* PPS 0 */
     86  1.1  riastrad 	pps_payload->dsc_version =
     87  1.1  riastrad 		dsc_cfg->dsc_version_minor |
     88  1.1  riastrad 		dsc_cfg->dsc_version_major << DSC_PPS_VERSION_MAJOR_SHIFT;
     89  1.1  riastrad 
     90  1.1  riastrad 	/* PPS 1, 2 is 0 */
     91  1.1  riastrad 
     92  1.1  riastrad 	/* PPS 3 */
     93  1.1  riastrad 	pps_payload->pps_3 =
     94  1.1  riastrad 		dsc_cfg->line_buf_depth |
     95  1.1  riastrad 		dsc_cfg->bits_per_component << DSC_PPS_BPC_SHIFT;
     96  1.1  riastrad 
     97  1.1  riastrad 	/* PPS 4 */
     98  1.1  riastrad 	pps_payload->pps_4 =
     99  1.1  riastrad 		((dsc_cfg->bits_per_pixel & DSC_PPS_BPP_HIGH_MASK) >>
    100  1.1  riastrad 		 DSC_PPS_MSB_SHIFT) |
    101  1.1  riastrad 		dsc_cfg->vbr_enable << DSC_PPS_VBR_EN_SHIFT |
    102  1.1  riastrad 		dsc_cfg->simple_422 << DSC_PPS_SIMPLE422_SHIFT |
    103  1.1  riastrad 		dsc_cfg->convert_rgb << DSC_PPS_CONVERT_RGB_SHIFT |
    104  1.1  riastrad 		dsc_cfg->block_pred_enable << DSC_PPS_BLOCK_PRED_EN_SHIFT;
    105  1.1  riastrad 
    106  1.1  riastrad 	/* PPS 5 */
    107  1.1  riastrad 	pps_payload->bits_per_pixel_low =
    108  1.1  riastrad 		(dsc_cfg->bits_per_pixel & DSC_PPS_LSB_MASK);
    109  1.1  riastrad 
    110  1.1  riastrad 	/*
    111  1.1  riastrad 	 * The DSC panel expects the PPS packet to have big endian format
    112  1.1  riastrad 	 * for data spanning 2 bytes. Use a macro cpu_to_be16() to convert
    113  1.1  riastrad 	 * to big endian format. If format is little endian, it will swap
    114  1.1  riastrad 	 * bytes to convert to Big endian else keep it unchanged.
    115  1.1  riastrad 	 */
    116  1.1  riastrad 
    117  1.1  riastrad 	/* PPS 6, 7 */
    118  1.1  riastrad 	pps_payload->pic_height = cpu_to_be16(dsc_cfg->pic_height);
    119  1.1  riastrad 
    120  1.1  riastrad 	/* PPS 8, 9 */
    121  1.1  riastrad 	pps_payload->pic_width = cpu_to_be16(dsc_cfg->pic_width);
    122  1.1  riastrad 
    123  1.1  riastrad 	/* PPS 10, 11 */
    124  1.1  riastrad 	pps_payload->slice_height = cpu_to_be16(dsc_cfg->slice_height);
    125  1.1  riastrad 
    126  1.1  riastrad 	/* PPS 12, 13 */
    127  1.1  riastrad 	pps_payload->slice_width = cpu_to_be16(dsc_cfg->slice_width);
    128  1.1  riastrad 
    129  1.1  riastrad 	/* PPS 14, 15 */
    130  1.1  riastrad 	pps_payload->chunk_size = cpu_to_be16(dsc_cfg->slice_chunk_size);
    131  1.1  riastrad 
    132  1.1  riastrad 	/* PPS 16 */
    133  1.1  riastrad 	pps_payload->initial_xmit_delay_high =
    134  1.1  riastrad 		((dsc_cfg->initial_xmit_delay &
    135  1.1  riastrad 		  DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK) >>
    136  1.1  riastrad 		 DSC_PPS_MSB_SHIFT);
    137  1.1  riastrad 
    138  1.1  riastrad 	/* PPS 17 */
    139  1.1  riastrad 	pps_payload->initial_xmit_delay_low =
    140  1.1  riastrad 		(dsc_cfg->initial_xmit_delay & DSC_PPS_LSB_MASK);
    141  1.1  riastrad 
    142  1.1  riastrad 	/* PPS 18, 19 */
    143  1.1  riastrad 	pps_payload->initial_dec_delay =
    144  1.1  riastrad 		cpu_to_be16(dsc_cfg->initial_dec_delay);
    145  1.1  riastrad 
    146  1.1  riastrad 	/* PPS 20 is 0 */
    147  1.1  riastrad 
    148  1.1  riastrad 	/* PPS 21 */
    149  1.1  riastrad 	pps_payload->initial_scale_value =
    150  1.1  riastrad 		dsc_cfg->initial_scale_value;
    151  1.1  riastrad 
    152  1.1  riastrad 	/* PPS 22, 23 */
    153  1.1  riastrad 	pps_payload->scale_increment_interval =
    154  1.1  riastrad 		cpu_to_be16(dsc_cfg->scale_increment_interval);
    155  1.1  riastrad 
    156  1.1  riastrad 	/* PPS 24 */
    157  1.1  riastrad 	pps_payload->scale_decrement_interval_high =
    158  1.1  riastrad 		((dsc_cfg->scale_decrement_interval &
    159  1.1  riastrad 		  DSC_PPS_SCALE_DEC_INT_HIGH_MASK) >>
    160  1.1  riastrad 		 DSC_PPS_MSB_SHIFT);
    161  1.1  riastrad 
    162  1.1  riastrad 	/* PPS 25 */
    163  1.1  riastrad 	pps_payload->scale_decrement_interval_low =
    164  1.1  riastrad 		(dsc_cfg->scale_decrement_interval & DSC_PPS_LSB_MASK);
    165  1.1  riastrad 
    166  1.1  riastrad 	/* PPS 26[7:0], PPS 27[7:5] RESERVED */
    167  1.1  riastrad 
    168  1.1  riastrad 	/* PPS 27 */
    169  1.1  riastrad 	pps_payload->first_line_bpg_offset =
    170  1.1  riastrad 		dsc_cfg->first_line_bpg_offset;
    171  1.1  riastrad 
    172  1.1  riastrad 	/* PPS 28, 29 */
    173  1.1  riastrad 	pps_payload->nfl_bpg_offset =
    174  1.1  riastrad 		cpu_to_be16(dsc_cfg->nfl_bpg_offset);
    175  1.1  riastrad 
    176  1.1  riastrad 	/* PPS 30, 31 */
    177  1.1  riastrad 	pps_payload->slice_bpg_offset =
    178  1.1  riastrad 		cpu_to_be16(dsc_cfg->slice_bpg_offset);
    179  1.1  riastrad 
    180  1.1  riastrad 	/* PPS 32, 33 */
    181  1.1  riastrad 	pps_payload->initial_offset =
    182  1.1  riastrad 		cpu_to_be16(dsc_cfg->initial_offset);
    183  1.1  riastrad 
    184  1.1  riastrad 	/* PPS 34, 35 */
    185  1.1  riastrad 	pps_payload->final_offset = cpu_to_be16(dsc_cfg->final_offset);
    186  1.1  riastrad 
    187  1.1  riastrad 	/* PPS 36 */
    188  1.1  riastrad 	pps_payload->flatness_min_qp = dsc_cfg->flatness_min_qp;
    189  1.1  riastrad 
    190  1.1  riastrad 	/* PPS 37 */
    191  1.1  riastrad 	pps_payload->flatness_max_qp = dsc_cfg->flatness_max_qp;
    192  1.1  riastrad 
    193  1.1  riastrad 	/* PPS 38, 39 */
    194  1.1  riastrad 	pps_payload->rc_model_size =
    195  1.1  riastrad 		cpu_to_be16(DSC_RC_MODEL_SIZE_CONST);
    196  1.1  riastrad 
    197  1.1  riastrad 	/* PPS 40 */
    198  1.1  riastrad 	pps_payload->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
    199  1.1  riastrad 
    200  1.1  riastrad 	/* PPS 41 */
    201  1.1  riastrad 	pps_payload->rc_quant_incr_limit0 =
    202  1.1  riastrad 		dsc_cfg->rc_quant_incr_limit0;
    203  1.1  riastrad 
    204  1.1  riastrad 	/* PPS 42 */
    205  1.1  riastrad 	pps_payload->rc_quant_incr_limit1 =
    206  1.1  riastrad 		dsc_cfg->rc_quant_incr_limit1;
    207  1.1  riastrad 
    208  1.1  riastrad 	/* PPS 43 */
    209  1.1  riastrad 	pps_payload->rc_tgt_offset = DSC_RC_TGT_OFFSET_LO_CONST |
    210  1.1  riastrad 		DSC_RC_TGT_OFFSET_HI_CONST << DSC_PPS_RC_TGT_OFFSET_HI_SHIFT;
    211  1.1  riastrad 
    212  1.1  riastrad 	/* PPS 44 - 57 */
    213  1.1  riastrad 	for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
    214  1.1  riastrad 		pps_payload->rc_buf_thresh[i] =
    215  1.1  riastrad 			dsc_cfg->rc_buf_thresh[i];
    216  1.1  riastrad 
    217  1.1  riastrad 	/* PPS 58 - 87 */
    218  1.1  riastrad 	/*
    219  1.1  riastrad 	 * For DSC sink programming the RC Range parameter fields
    220  1.1  riastrad 	 * are as follows: Min_qp[15:11], max_qp[10:6], offset[5:0]
    221  1.1  riastrad 	 */
    222  1.1  riastrad 	for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
    223  1.1  riastrad 		pps_payload->rc_range_parameters[i] =
    224  1.1  riastrad 			cpu_to_be16((dsc_cfg->rc_range_params[i].range_min_qp <<
    225  1.1  riastrad 				     DSC_PPS_RC_RANGE_MINQP_SHIFT) |
    226  1.1  riastrad 				    (dsc_cfg->rc_range_params[i].range_max_qp <<
    227  1.1  riastrad 				     DSC_PPS_RC_RANGE_MAXQP_SHIFT) |
    228  1.1  riastrad 				    (dsc_cfg->rc_range_params[i].range_bpg_offset));
    229  1.1  riastrad 	}
    230  1.1  riastrad 
    231  1.1  riastrad 	/* PPS 88 */
    232  1.1  riastrad 	pps_payload->native_422_420 = dsc_cfg->native_422 |
    233  1.1  riastrad 		dsc_cfg->native_420 << DSC_PPS_NATIVE_420_SHIFT;
    234  1.1  riastrad 
    235  1.1  riastrad 	/* PPS 89 */
    236  1.1  riastrad 	pps_payload->second_line_bpg_offset =
    237  1.1  riastrad 		dsc_cfg->second_line_bpg_offset;
    238  1.1  riastrad 
    239  1.1  riastrad 	/* PPS 90, 91 */
    240  1.1  riastrad 	pps_payload->nsl_bpg_offset =
    241  1.1  riastrad 		cpu_to_be16(dsc_cfg->nsl_bpg_offset);
    242  1.1  riastrad 
    243  1.1  riastrad 	/* PPS 92, 93 */
    244  1.1  riastrad 	pps_payload->second_line_offset_adj =
    245  1.1  riastrad 		cpu_to_be16(dsc_cfg->second_line_offset_adj);
    246  1.1  riastrad 
    247  1.1  riastrad 	/* PPS 94 - 127 are O */
    248  1.1  riastrad }
    249  1.1  riastrad EXPORT_SYMBOL(drm_dsc_pps_payload_pack);
    250  1.1  riastrad 
    251  1.1  riastrad /**
    252  1.1  riastrad  * drm_dsc_compute_rc_parameters() - Write rate control
    253  1.1  riastrad  * parameters to the dsc configuration defined in
    254  1.1  riastrad  * &struct drm_dsc_config in accordance with the DSC 1.2
    255  1.1  riastrad  * specification. Some configuration fields must be present
    256  1.1  riastrad  * beforehand.
    257  1.1  riastrad  *
    258  1.1  riastrad  * @vdsc_cfg:
    259  1.1  riastrad  * DSC Configuration data partially filled by driver
    260  1.1  riastrad  */
    261  1.1  riastrad int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg)
    262  1.1  riastrad {
    263  1.1  riastrad 	unsigned long groups_per_line = 0;
    264  1.1  riastrad 	unsigned long groups_total = 0;
    265  1.1  riastrad 	unsigned long num_extra_mux_bits = 0;
    266  1.1  riastrad 	unsigned long slice_bits = 0;
    267  1.1  riastrad 	unsigned long hrd_delay = 0;
    268  1.1  riastrad 	unsigned long final_scale = 0;
    269  1.1  riastrad 	unsigned long rbs_min = 0;
    270  1.1  riastrad 
    271  1.1  riastrad 	if (vdsc_cfg->native_420 || vdsc_cfg->native_422) {
    272  1.1  riastrad 		/* Number of groups used to code each line of a slice */
    273  1.1  riastrad 		groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width / 2,
    274  1.1  riastrad 					       DSC_RC_PIXELS_PER_GROUP);
    275  1.1  riastrad 
    276  1.1  riastrad 		/* chunksize in Bytes */
    277  1.1  riastrad 		vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width / 2 *
    278  1.1  riastrad 							  vdsc_cfg->bits_per_pixel,
    279  1.1  riastrad 							  (8 * 16));
    280  1.1  riastrad 	} else {
    281  1.1  riastrad 		/* Number of groups used to code each line of a slice */
    282  1.1  riastrad 		groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width,
    283  1.1  riastrad 					       DSC_RC_PIXELS_PER_GROUP);
    284  1.1  riastrad 
    285  1.1  riastrad 		/* chunksize in Bytes */
    286  1.1  riastrad 		vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width *
    287  1.1  riastrad 							  vdsc_cfg->bits_per_pixel,
    288  1.1  riastrad 							  (8 * 16));
    289  1.1  riastrad 	}
    290  1.1  riastrad 
    291  1.1  riastrad 	if (vdsc_cfg->convert_rgb)
    292  1.1  riastrad 		num_extra_mux_bits = 3 * (vdsc_cfg->mux_word_size +
    293  1.1  riastrad 					  (4 * vdsc_cfg->bits_per_component + 4)
    294  1.1  riastrad 					  - 2);
    295  1.1  riastrad 	else if (vdsc_cfg->native_422)
    296  1.1  riastrad 		num_extra_mux_bits = 4 * vdsc_cfg->mux_word_size +
    297  1.1  riastrad 			(4 * vdsc_cfg->bits_per_component + 4) +
    298  1.1  riastrad 			3 * (4 * vdsc_cfg->bits_per_component) - 2;
    299  1.1  riastrad 	else
    300  1.1  riastrad 		num_extra_mux_bits = 3 * vdsc_cfg->mux_word_size +
    301  1.1  riastrad 			(4 * vdsc_cfg->bits_per_component + 4) +
    302  1.1  riastrad 			2 * (4 * vdsc_cfg->bits_per_component) - 2;
    303  1.1  riastrad 	/* Number of bits in one Slice */
    304  1.1  riastrad 	slice_bits = 8 * vdsc_cfg->slice_chunk_size * vdsc_cfg->slice_height;
    305  1.1  riastrad 
    306  1.1  riastrad 	while ((num_extra_mux_bits > 0) &&
    307  1.1  riastrad 	       ((slice_bits - num_extra_mux_bits) % vdsc_cfg->mux_word_size))
    308  1.1  riastrad 		num_extra_mux_bits--;
    309  1.1  riastrad 
    310  1.1  riastrad 	if (groups_per_line < vdsc_cfg->initial_scale_value - 8)
    311  1.1  riastrad 		vdsc_cfg->initial_scale_value = groups_per_line + 8;
    312  1.1  riastrad 
    313  1.1  riastrad 	/* scale_decrement_interval calculation according to DSC spec 1.11 */
    314  1.1  riastrad 	if (vdsc_cfg->initial_scale_value > 8)
    315  1.1  riastrad 		vdsc_cfg->scale_decrement_interval = groups_per_line /
    316  1.1  riastrad 			(vdsc_cfg->initial_scale_value - 8);
    317  1.1  riastrad 	else
    318  1.1  riastrad 		vdsc_cfg->scale_decrement_interval = DSC_SCALE_DECREMENT_INTERVAL_MAX;
    319  1.1  riastrad 
    320  1.1  riastrad 	vdsc_cfg->final_offset = vdsc_cfg->rc_model_size -
    321  1.1  riastrad 		(vdsc_cfg->initial_xmit_delay *
    322  1.1  riastrad 		 vdsc_cfg->bits_per_pixel + 8) / 16 + num_extra_mux_bits;
    323  1.1  riastrad 
    324  1.1  riastrad 	if (vdsc_cfg->final_offset >= vdsc_cfg->rc_model_size) {
    325  1.1  riastrad 		DRM_DEBUG_KMS("FinalOfs < RcModelSze for this InitialXmitDelay\n");
    326  1.1  riastrad 		return -ERANGE;
    327  1.1  riastrad 	}
    328  1.1  riastrad 
    329  1.1  riastrad 	final_scale = (vdsc_cfg->rc_model_size * 8) /
    330  1.1  riastrad 		(vdsc_cfg->rc_model_size - vdsc_cfg->final_offset);
    331  1.1  riastrad 	if (vdsc_cfg->slice_height > 1)
    332  1.1  riastrad 		/*
    333  1.1  riastrad 		 * NflBpgOffset is 16 bit value with 11 fractional bits
    334  1.1  riastrad 		 * hence we multiply by 2^11 for preserving the
    335  1.1  riastrad 		 * fractional part
    336  1.1  riastrad 		 */
    337  1.1  riastrad 		vdsc_cfg->nfl_bpg_offset = DIV_ROUND_UP((vdsc_cfg->first_line_bpg_offset << 11),
    338  1.1  riastrad 							(vdsc_cfg->slice_height - 1));
    339  1.1  riastrad 	else
    340  1.1  riastrad 		vdsc_cfg->nfl_bpg_offset = 0;
    341  1.1  riastrad 
    342  1.1  riastrad 	/* Number of groups used to code the entire slice */
    343  1.1  riastrad 	groups_total = groups_per_line * vdsc_cfg->slice_height;
    344  1.1  riastrad 
    345  1.1  riastrad 	/* slice_bpg_offset is 16 bit value with 11 fractional bits */
    346  1.1  riastrad 	vdsc_cfg->slice_bpg_offset = DIV_ROUND_UP(((vdsc_cfg->rc_model_size -
    347  1.1  riastrad 						    vdsc_cfg->initial_offset +
    348  1.1  riastrad 						    num_extra_mux_bits) << 11),
    349  1.1  riastrad 						  groups_total);
    350  1.1  riastrad 
    351  1.1  riastrad 	if (final_scale > 9) {
    352  1.1  riastrad 		/*
    353  1.1  riastrad 		 * ScaleIncrementInterval =
    354  1.1  riastrad 		 * finaloffset/((NflBpgOffset + SliceBpgOffset)*8(finalscale - 1.125))
    355  1.1  riastrad 		 * as (NflBpgOffset + SliceBpgOffset) has 11 bit fractional value,
    356  1.1  riastrad 		 * we need divide by 2^11 from pstDscCfg values
    357  1.1  riastrad 		 */
    358  1.1  riastrad 		vdsc_cfg->scale_increment_interval =
    359  1.1  riastrad 				(vdsc_cfg->final_offset * (1 << 11)) /
    360  1.1  riastrad 				((vdsc_cfg->nfl_bpg_offset +
    361  1.1  riastrad 				vdsc_cfg->slice_bpg_offset) *
    362  1.1  riastrad 				(final_scale - 9));
    363  1.1  riastrad 	} else {
    364  1.1  riastrad 		/*
    365  1.1  riastrad 		 * If finalScaleValue is less than or equal to 9, a value of 0 should
    366  1.1  riastrad 		 * be used to disable the scale increment at the end of the slice
    367  1.1  riastrad 		 */
    368  1.1  riastrad 		vdsc_cfg->scale_increment_interval = 0;
    369  1.1  riastrad 	}
    370  1.1  riastrad 
    371  1.1  riastrad 	/*
    372  1.1  riastrad 	 * DSC spec mentions that bits_per_pixel specifies the target
    373  1.1  riastrad 	 * bits/pixel (bpp) rate that is used by the encoder,
    374  1.1  riastrad 	 * in steps of 1/16 of a bit per pixel
    375  1.1  riastrad 	 */
    376  1.1  riastrad 	rbs_min = vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset +
    377  1.1  riastrad 		DIV_ROUND_UP(vdsc_cfg->initial_xmit_delay *
    378  1.1  riastrad 			     vdsc_cfg->bits_per_pixel, 16) +
    379  1.1  riastrad 		groups_per_line * vdsc_cfg->first_line_bpg_offset;
    380  1.1  riastrad 
    381  1.1  riastrad 	hrd_delay = DIV_ROUND_UP((rbs_min * 16), vdsc_cfg->bits_per_pixel);
    382  1.1  riastrad 	vdsc_cfg->rc_bits = (hrd_delay * vdsc_cfg->bits_per_pixel) / 16;
    383  1.1  riastrad 	vdsc_cfg->initial_dec_delay = hrd_delay - vdsc_cfg->initial_xmit_delay;
    384  1.1  riastrad 
    385  1.1  riastrad 	return 0;
    386  1.1  riastrad }
    387  1.1  riastrad EXPORT_SYMBOL(drm_dsc_compute_rc_parameters);
    388