1*cd6b050fSriastradh /* $NetBSD: drm_dsc.c,v 1.3 2021/12/19 09:45:49 riastradh Exp $ */
24e390cabSriastradh
34e390cabSriastradh // SPDX-License-Identifier: MIT
44e390cabSriastradh /*
54e390cabSriastradh * Copyright © 2018 Intel Corp
64e390cabSriastradh *
74e390cabSriastradh * Author:
84e390cabSriastradh * Manasi Navare <manasi.d.navare@intel.com>
94e390cabSriastradh */
104e390cabSriastradh
114e390cabSriastradh #include <sys/cdefs.h>
12*cd6b050fSriastradh __KERNEL_RCSID(0, "$NetBSD: drm_dsc.c,v 1.3 2021/12/19 09:45:49 riastradh Exp $");
134e390cabSriastradh
14*cd6b050fSriastradh #include <linux/bug.h>
154e390cabSriastradh #include <linux/kernel.h>
164e390cabSriastradh #include <linux/module.h>
174e390cabSriastradh #include <linux/init.h>
184e390cabSriastradh #include <linux/errno.h>
194e390cabSriastradh #include <linux/byteorder/generic.h>
204e390cabSriastradh #include <drm/drm_print.h>
214e390cabSriastradh #include <drm/drm_dp_helper.h>
224e390cabSriastradh #include <drm/drm_dsc.h>
234e390cabSriastradh
244e390cabSriastradh /**
254e390cabSriastradh * DOC: dsc helpers
264e390cabSriastradh *
274e390cabSriastradh * VESA specification for DP 1.4 adds a new feature called Display Stream
284e390cabSriastradh * Compression (DSC) used to compress the pixel bits before sending it on
294e390cabSriastradh * DP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existing
304e390cabSriastradh * display interfaces can support high resolutions at higher frames rates uisng
314e390cabSriastradh * the maximum available link capacity of these interfaces.
324e390cabSriastradh *
334e390cabSriastradh * These functions contain some common logic and helpers to deal with VESA
344e390cabSriastradh * Display Stream Compression standard required for DSC on Display Port/eDP or
354e390cabSriastradh * MIPI display interfaces.
364e390cabSriastradh */
374e390cabSriastradh
384e390cabSriastradh /**
394e390cabSriastradh * drm_dsc_dp_pps_header_init() - Initializes the PPS Header
404e390cabSriastradh * for DisplayPort as per the DP 1.4 spec.
414e390cabSriastradh * @pps_header: Secondary data packet header for DSC Picture
424e390cabSriastradh * Parameter Set as defined in &struct dp_sdp_header
434e390cabSriastradh *
444e390cabSriastradh * DP 1.4 spec defines the secondary data packet for sending the
454e390cabSriastradh * picture parameter infoframes from the source to the sink.
464e390cabSriastradh * This function populates the SDP header defined in
474e390cabSriastradh * &struct dp_sdp_header.
484e390cabSriastradh */
drm_dsc_dp_pps_header_init(struct dp_sdp_header * pps_header)494e390cabSriastradh void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header)
504e390cabSriastradh {
514e390cabSriastradh memset(pps_header, 0, sizeof(*pps_header));
524e390cabSriastradh
534e390cabSriastradh pps_header->HB1 = DP_SDP_PPS;
544e390cabSriastradh pps_header->HB2 = DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1;
554e390cabSriastradh }
564e390cabSriastradh EXPORT_SYMBOL(drm_dsc_dp_pps_header_init);
574e390cabSriastradh
584e390cabSriastradh /**
594e390cabSriastradh * drm_dsc_pps_payload_pack() - Populates the DSC PPS
604e390cabSriastradh *
614e390cabSriastradh * @pps_payload:
624e390cabSriastradh * Bitwise struct for DSC Picture Parameter Set. This is defined
634e390cabSriastradh * by &struct drm_dsc_picture_parameter_set
644e390cabSriastradh * @dsc_cfg:
654e390cabSriastradh * DSC Configuration data filled by driver as defined by
664e390cabSriastradh * &struct drm_dsc_config
674e390cabSriastradh *
684e390cabSriastradh * DSC source device sends a picture parameter set (PPS) containing the
694e390cabSriastradh * information required by the sink to decode the compressed frame. Driver
704e390cabSriastradh * populates the DSC PPS struct using the DSC configuration parameters in
714e390cabSriastradh * the order expected by the DSC Display Sink device. For the DSC, the sink
724e390cabSriastradh * device expects the PPS payload in big endian format for fields
734e390cabSriastradh * that span more than 1 byte.
744e390cabSriastradh */
drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set * pps_payload,const struct drm_dsc_config * dsc_cfg)754e390cabSriastradh void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload,
764e390cabSriastradh const struct drm_dsc_config *dsc_cfg)
774e390cabSriastradh {
784e390cabSriastradh int i;
794e390cabSriastradh
804e390cabSriastradh /* Protect against someone accidently changing struct size */
814e390cabSriastradh BUILD_BUG_ON(sizeof(*pps_payload) !=
824e390cabSriastradh DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1 + 1);
834e390cabSriastradh
844e390cabSriastradh memset(pps_payload, 0, sizeof(*pps_payload));
854e390cabSriastradh
864e390cabSriastradh /* PPS 0 */
874e390cabSriastradh pps_payload->dsc_version =
884e390cabSriastradh dsc_cfg->dsc_version_minor |
894e390cabSriastradh dsc_cfg->dsc_version_major << DSC_PPS_VERSION_MAJOR_SHIFT;
904e390cabSriastradh
914e390cabSriastradh /* PPS 1, 2 is 0 */
924e390cabSriastradh
934e390cabSriastradh /* PPS 3 */
944e390cabSriastradh pps_payload->pps_3 =
954e390cabSriastradh dsc_cfg->line_buf_depth |
964e390cabSriastradh dsc_cfg->bits_per_component << DSC_PPS_BPC_SHIFT;
974e390cabSriastradh
984e390cabSriastradh /* PPS 4 */
994e390cabSriastradh pps_payload->pps_4 =
1004e390cabSriastradh ((dsc_cfg->bits_per_pixel & DSC_PPS_BPP_HIGH_MASK) >>
1014e390cabSriastradh DSC_PPS_MSB_SHIFT) |
1024e390cabSriastradh dsc_cfg->vbr_enable << DSC_PPS_VBR_EN_SHIFT |
1034e390cabSriastradh dsc_cfg->simple_422 << DSC_PPS_SIMPLE422_SHIFT |
1044e390cabSriastradh dsc_cfg->convert_rgb << DSC_PPS_CONVERT_RGB_SHIFT |
1054e390cabSriastradh dsc_cfg->block_pred_enable << DSC_PPS_BLOCK_PRED_EN_SHIFT;
1064e390cabSriastradh
1074e390cabSriastradh /* PPS 5 */
1084e390cabSriastradh pps_payload->bits_per_pixel_low =
1094e390cabSriastradh (dsc_cfg->bits_per_pixel & DSC_PPS_LSB_MASK);
1104e390cabSriastradh
1114e390cabSriastradh /*
1124e390cabSriastradh * The DSC panel expects the PPS packet to have big endian format
1134e390cabSriastradh * for data spanning 2 bytes. Use a macro cpu_to_be16() to convert
1144e390cabSriastradh * to big endian format. If format is little endian, it will swap
1154e390cabSriastradh * bytes to convert to Big endian else keep it unchanged.
1164e390cabSriastradh */
1174e390cabSriastradh
1184e390cabSriastradh /* PPS 6, 7 */
1194e390cabSriastradh pps_payload->pic_height = cpu_to_be16(dsc_cfg->pic_height);
1204e390cabSriastradh
1214e390cabSriastradh /* PPS 8, 9 */
1224e390cabSriastradh pps_payload->pic_width = cpu_to_be16(dsc_cfg->pic_width);
1234e390cabSriastradh
1244e390cabSriastradh /* PPS 10, 11 */
1254e390cabSriastradh pps_payload->slice_height = cpu_to_be16(dsc_cfg->slice_height);
1264e390cabSriastradh
1274e390cabSriastradh /* PPS 12, 13 */
1284e390cabSriastradh pps_payload->slice_width = cpu_to_be16(dsc_cfg->slice_width);
1294e390cabSriastradh
1304e390cabSriastradh /* PPS 14, 15 */
1314e390cabSriastradh pps_payload->chunk_size = cpu_to_be16(dsc_cfg->slice_chunk_size);
1324e390cabSriastradh
1334e390cabSriastradh /* PPS 16 */
1344e390cabSriastradh pps_payload->initial_xmit_delay_high =
1354e390cabSriastradh ((dsc_cfg->initial_xmit_delay &
1364e390cabSriastradh DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK) >>
1374e390cabSriastradh DSC_PPS_MSB_SHIFT);
1384e390cabSriastradh
1394e390cabSriastradh /* PPS 17 */
1404e390cabSriastradh pps_payload->initial_xmit_delay_low =
1414e390cabSriastradh (dsc_cfg->initial_xmit_delay & DSC_PPS_LSB_MASK);
1424e390cabSriastradh
1434e390cabSriastradh /* PPS 18, 19 */
1444e390cabSriastradh pps_payload->initial_dec_delay =
1454e390cabSriastradh cpu_to_be16(dsc_cfg->initial_dec_delay);
1464e390cabSriastradh
1474e390cabSriastradh /* PPS 20 is 0 */
1484e390cabSriastradh
1494e390cabSriastradh /* PPS 21 */
1504e390cabSriastradh pps_payload->initial_scale_value =
1514e390cabSriastradh dsc_cfg->initial_scale_value;
1524e390cabSriastradh
1534e390cabSriastradh /* PPS 22, 23 */
1544e390cabSriastradh pps_payload->scale_increment_interval =
1554e390cabSriastradh cpu_to_be16(dsc_cfg->scale_increment_interval);
1564e390cabSriastradh
1574e390cabSriastradh /* PPS 24 */
1584e390cabSriastradh pps_payload->scale_decrement_interval_high =
1594e390cabSriastradh ((dsc_cfg->scale_decrement_interval &
1604e390cabSriastradh DSC_PPS_SCALE_DEC_INT_HIGH_MASK) >>
1614e390cabSriastradh DSC_PPS_MSB_SHIFT);
1624e390cabSriastradh
1634e390cabSriastradh /* PPS 25 */
1644e390cabSriastradh pps_payload->scale_decrement_interval_low =
1654e390cabSriastradh (dsc_cfg->scale_decrement_interval & DSC_PPS_LSB_MASK);
1664e390cabSriastradh
1674e390cabSriastradh /* PPS 26[7:0], PPS 27[7:5] RESERVED */
1684e390cabSriastradh
1694e390cabSriastradh /* PPS 27 */
1704e390cabSriastradh pps_payload->first_line_bpg_offset =
1714e390cabSriastradh dsc_cfg->first_line_bpg_offset;
1724e390cabSriastradh
1734e390cabSriastradh /* PPS 28, 29 */
1744e390cabSriastradh pps_payload->nfl_bpg_offset =
1754e390cabSriastradh cpu_to_be16(dsc_cfg->nfl_bpg_offset);
1764e390cabSriastradh
1774e390cabSriastradh /* PPS 30, 31 */
1784e390cabSriastradh pps_payload->slice_bpg_offset =
1794e390cabSriastradh cpu_to_be16(dsc_cfg->slice_bpg_offset);
1804e390cabSriastradh
1814e390cabSriastradh /* PPS 32, 33 */
1824e390cabSriastradh pps_payload->initial_offset =
1834e390cabSriastradh cpu_to_be16(dsc_cfg->initial_offset);
1844e390cabSriastradh
1854e390cabSriastradh /* PPS 34, 35 */
1864e390cabSriastradh pps_payload->final_offset = cpu_to_be16(dsc_cfg->final_offset);
1874e390cabSriastradh
1884e390cabSriastradh /* PPS 36 */
1894e390cabSriastradh pps_payload->flatness_min_qp = dsc_cfg->flatness_min_qp;
1904e390cabSriastradh
1914e390cabSriastradh /* PPS 37 */
1924e390cabSriastradh pps_payload->flatness_max_qp = dsc_cfg->flatness_max_qp;
1934e390cabSriastradh
1944e390cabSriastradh /* PPS 38, 39 */
1954e390cabSriastradh pps_payload->rc_model_size =
1964e390cabSriastradh cpu_to_be16(DSC_RC_MODEL_SIZE_CONST);
1974e390cabSriastradh
1984e390cabSriastradh /* PPS 40 */
1994e390cabSriastradh pps_payload->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
2004e390cabSriastradh
2014e390cabSriastradh /* PPS 41 */
2024e390cabSriastradh pps_payload->rc_quant_incr_limit0 =
2034e390cabSriastradh dsc_cfg->rc_quant_incr_limit0;
2044e390cabSriastradh
2054e390cabSriastradh /* PPS 42 */
2064e390cabSriastradh pps_payload->rc_quant_incr_limit1 =
2074e390cabSriastradh dsc_cfg->rc_quant_incr_limit1;
2084e390cabSriastradh
2094e390cabSriastradh /* PPS 43 */
2104e390cabSriastradh pps_payload->rc_tgt_offset = DSC_RC_TGT_OFFSET_LO_CONST |
2114e390cabSriastradh DSC_RC_TGT_OFFSET_HI_CONST << DSC_PPS_RC_TGT_OFFSET_HI_SHIFT;
2124e390cabSriastradh
2134e390cabSriastradh /* PPS 44 - 57 */
2144e390cabSriastradh for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
2154e390cabSriastradh pps_payload->rc_buf_thresh[i] =
2164e390cabSriastradh dsc_cfg->rc_buf_thresh[i];
2174e390cabSriastradh
2184e390cabSriastradh /* PPS 58 - 87 */
2194e390cabSriastradh /*
2204e390cabSriastradh * For DSC sink programming the RC Range parameter fields
2214e390cabSriastradh * are as follows: Min_qp[15:11], max_qp[10:6], offset[5:0]
2224e390cabSriastradh */
2234e390cabSriastradh for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
2244e390cabSriastradh pps_payload->rc_range_parameters[i] =
2254e390cabSriastradh cpu_to_be16((dsc_cfg->rc_range_params[i].range_min_qp <<
2264e390cabSriastradh DSC_PPS_RC_RANGE_MINQP_SHIFT) |
2274e390cabSriastradh (dsc_cfg->rc_range_params[i].range_max_qp <<
2284e390cabSriastradh DSC_PPS_RC_RANGE_MAXQP_SHIFT) |
2294e390cabSriastradh (dsc_cfg->rc_range_params[i].range_bpg_offset));
2304e390cabSriastradh }
2314e390cabSriastradh
2324e390cabSriastradh /* PPS 88 */
2334e390cabSriastradh pps_payload->native_422_420 = dsc_cfg->native_422 |
2344e390cabSriastradh dsc_cfg->native_420 << DSC_PPS_NATIVE_420_SHIFT;
2354e390cabSriastradh
2364e390cabSriastradh /* PPS 89 */
2374e390cabSriastradh pps_payload->second_line_bpg_offset =
2384e390cabSriastradh dsc_cfg->second_line_bpg_offset;
2394e390cabSriastradh
2404e390cabSriastradh /* PPS 90, 91 */
2414e390cabSriastradh pps_payload->nsl_bpg_offset =
2424e390cabSriastradh cpu_to_be16(dsc_cfg->nsl_bpg_offset);
2434e390cabSriastradh
2444e390cabSriastradh /* PPS 92, 93 */
2454e390cabSriastradh pps_payload->second_line_offset_adj =
2464e390cabSriastradh cpu_to_be16(dsc_cfg->second_line_offset_adj);
2474e390cabSriastradh
2484e390cabSriastradh /* PPS 94 - 127 are O */
2494e390cabSriastradh }
2504e390cabSriastradh EXPORT_SYMBOL(drm_dsc_pps_payload_pack);
2514e390cabSriastradh
2524e390cabSriastradh /**
2534e390cabSriastradh * drm_dsc_compute_rc_parameters() - Write rate control
2544e390cabSriastradh * parameters to the dsc configuration defined in
2554e390cabSriastradh * &struct drm_dsc_config in accordance with the DSC 1.2
2564e390cabSriastradh * specification. Some configuration fields must be present
2574e390cabSriastradh * beforehand.
2584e390cabSriastradh *
2594e390cabSriastradh * @vdsc_cfg:
2604e390cabSriastradh * DSC Configuration data partially filled by driver
2614e390cabSriastradh */
drm_dsc_compute_rc_parameters(struct drm_dsc_config * vdsc_cfg)2624e390cabSriastradh int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg)
2634e390cabSriastradh {
2644e390cabSriastradh unsigned long groups_per_line = 0;
2654e390cabSriastradh unsigned long groups_total = 0;
2664e390cabSriastradh unsigned long num_extra_mux_bits = 0;
2674e390cabSriastradh unsigned long slice_bits = 0;
2684e390cabSriastradh unsigned long hrd_delay = 0;
2694e390cabSriastradh unsigned long final_scale = 0;
2704e390cabSriastradh unsigned long rbs_min = 0;
2714e390cabSriastradh
2724e390cabSriastradh if (vdsc_cfg->native_420 || vdsc_cfg->native_422) {
2734e390cabSriastradh /* Number of groups used to code each line of a slice */
2744e390cabSriastradh groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width / 2,
2754e390cabSriastradh DSC_RC_PIXELS_PER_GROUP);
2764e390cabSriastradh
2774e390cabSriastradh /* chunksize in Bytes */
2784e390cabSriastradh vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width / 2 *
2794e390cabSriastradh vdsc_cfg->bits_per_pixel,
2804e390cabSriastradh (8 * 16));
2814e390cabSriastradh } else {
2824e390cabSriastradh /* Number of groups used to code each line of a slice */
2834e390cabSriastradh groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width,
2844e390cabSriastradh DSC_RC_PIXELS_PER_GROUP);
2854e390cabSriastradh
2864e390cabSriastradh /* chunksize in Bytes */
2874e390cabSriastradh vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width *
2884e390cabSriastradh vdsc_cfg->bits_per_pixel,
2894e390cabSriastradh (8 * 16));
2904e390cabSriastradh }
2914e390cabSriastradh
2924e390cabSriastradh if (vdsc_cfg->convert_rgb)
2934e390cabSriastradh num_extra_mux_bits = 3 * (vdsc_cfg->mux_word_size +
2944e390cabSriastradh (4 * vdsc_cfg->bits_per_component + 4)
2954e390cabSriastradh - 2);
2964e390cabSriastradh else if (vdsc_cfg->native_422)
2974e390cabSriastradh num_extra_mux_bits = 4 * vdsc_cfg->mux_word_size +
2984e390cabSriastradh (4 * vdsc_cfg->bits_per_component + 4) +
2994e390cabSriastradh 3 * (4 * vdsc_cfg->bits_per_component) - 2;
3004e390cabSriastradh else
3014e390cabSriastradh num_extra_mux_bits = 3 * vdsc_cfg->mux_word_size +
3024e390cabSriastradh (4 * vdsc_cfg->bits_per_component + 4) +
3034e390cabSriastradh 2 * (4 * vdsc_cfg->bits_per_component) - 2;
3044e390cabSriastradh /* Number of bits in one Slice */
3054e390cabSriastradh slice_bits = 8 * vdsc_cfg->slice_chunk_size * vdsc_cfg->slice_height;
3064e390cabSriastradh
3074e390cabSriastradh while ((num_extra_mux_bits > 0) &&
3084e390cabSriastradh ((slice_bits - num_extra_mux_bits) % vdsc_cfg->mux_word_size))
3094e390cabSriastradh num_extra_mux_bits--;
3104e390cabSriastradh
3114e390cabSriastradh if (groups_per_line < vdsc_cfg->initial_scale_value - 8)
3124e390cabSriastradh vdsc_cfg->initial_scale_value = groups_per_line + 8;
3134e390cabSriastradh
3144e390cabSriastradh /* scale_decrement_interval calculation according to DSC spec 1.11 */
3154e390cabSriastradh if (vdsc_cfg->initial_scale_value > 8)
3164e390cabSriastradh vdsc_cfg->scale_decrement_interval = groups_per_line /
3174e390cabSriastradh (vdsc_cfg->initial_scale_value - 8);
3184e390cabSriastradh else
3194e390cabSriastradh vdsc_cfg->scale_decrement_interval = DSC_SCALE_DECREMENT_INTERVAL_MAX;
3204e390cabSriastradh
3214e390cabSriastradh vdsc_cfg->final_offset = vdsc_cfg->rc_model_size -
3224e390cabSriastradh (vdsc_cfg->initial_xmit_delay *
3234e390cabSriastradh vdsc_cfg->bits_per_pixel + 8) / 16 + num_extra_mux_bits;
3244e390cabSriastradh
3254e390cabSriastradh if (vdsc_cfg->final_offset >= vdsc_cfg->rc_model_size) {
3264e390cabSriastradh DRM_DEBUG_KMS("FinalOfs < RcModelSze for this InitialXmitDelay\n");
3274e390cabSriastradh return -ERANGE;
3284e390cabSriastradh }
3294e390cabSriastradh
3304e390cabSriastradh final_scale = (vdsc_cfg->rc_model_size * 8) /
3314e390cabSriastradh (vdsc_cfg->rc_model_size - vdsc_cfg->final_offset);
3324e390cabSriastradh if (vdsc_cfg->slice_height > 1)
3334e390cabSriastradh /*
3344e390cabSriastradh * NflBpgOffset is 16 bit value with 11 fractional bits
3354e390cabSriastradh * hence we multiply by 2^11 for preserving the
3364e390cabSriastradh * fractional part
3374e390cabSriastradh */
3384e390cabSriastradh vdsc_cfg->nfl_bpg_offset = DIV_ROUND_UP((vdsc_cfg->first_line_bpg_offset << 11),
3394e390cabSriastradh (vdsc_cfg->slice_height - 1));
3404e390cabSriastradh else
3414e390cabSriastradh vdsc_cfg->nfl_bpg_offset = 0;
3424e390cabSriastradh
3434e390cabSriastradh /* Number of groups used to code the entire slice */
3444e390cabSriastradh groups_total = groups_per_line * vdsc_cfg->slice_height;
3454e390cabSriastradh
3464e390cabSriastradh /* slice_bpg_offset is 16 bit value with 11 fractional bits */
3474e390cabSriastradh vdsc_cfg->slice_bpg_offset = DIV_ROUND_UP(((vdsc_cfg->rc_model_size -
3484e390cabSriastradh vdsc_cfg->initial_offset +
3494e390cabSriastradh num_extra_mux_bits) << 11),
3504e390cabSriastradh groups_total);
3514e390cabSriastradh
3524e390cabSriastradh if (final_scale > 9) {
3534e390cabSriastradh /*
3544e390cabSriastradh * ScaleIncrementInterval =
3554e390cabSriastradh * finaloffset/((NflBpgOffset + SliceBpgOffset)*8(finalscale - 1.125))
3564e390cabSriastradh * as (NflBpgOffset + SliceBpgOffset) has 11 bit fractional value,
3574e390cabSriastradh * we need divide by 2^11 from pstDscCfg values
3584e390cabSriastradh */
3594e390cabSriastradh vdsc_cfg->scale_increment_interval =
3604e390cabSriastradh (vdsc_cfg->final_offset * (1 << 11)) /
3614e390cabSriastradh ((vdsc_cfg->nfl_bpg_offset +
3624e390cabSriastradh vdsc_cfg->slice_bpg_offset) *
3634e390cabSriastradh (final_scale - 9));
3644e390cabSriastradh } else {
3654e390cabSriastradh /*
3664e390cabSriastradh * If finalScaleValue is less than or equal to 9, a value of 0 should
3674e390cabSriastradh * be used to disable the scale increment at the end of the slice
3684e390cabSriastradh */
3694e390cabSriastradh vdsc_cfg->scale_increment_interval = 0;
3704e390cabSriastradh }
3714e390cabSriastradh
3724e390cabSriastradh /*
3734e390cabSriastradh * DSC spec mentions that bits_per_pixel specifies the target
3744e390cabSriastradh * bits/pixel (bpp) rate that is used by the encoder,
3754e390cabSriastradh * in steps of 1/16 of a bit per pixel
3764e390cabSriastradh */
3774e390cabSriastradh rbs_min = vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset +
3784e390cabSriastradh DIV_ROUND_UP(vdsc_cfg->initial_xmit_delay *
3794e390cabSriastradh vdsc_cfg->bits_per_pixel, 16) +
3804e390cabSriastradh groups_per_line * vdsc_cfg->first_line_bpg_offset;
3814e390cabSriastradh
3824e390cabSriastradh hrd_delay = DIV_ROUND_UP((rbs_min * 16), vdsc_cfg->bits_per_pixel);
3834e390cabSriastradh vdsc_cfg->rc_bits = (hrd_delay * vdsc_cfg->bits_per_pixel) / 16;
3844e390cabSriastradh vdsc_cfg->initial_dec_delay = hrd_delay - vdsc_cfg->initial_xmit_delay;
3854e390cabSriastradh
3864e390cabSriastradh return 0;
3874e390cabSriastradh }
3884e390cabSriastradh EXPORT_SYMBOL(drm_dsc_compute_rc_parameters);
389