Commit c3a1aabc authored by Marijn Suijten's avatar Marijn Suijten Committed by Dmitry Baryshkov

drm/msm/dsi: Migrate to drm_dsc_compute_rc_parameters()

As per the FIXME this code is entirely duplicate with what is already
provided inside drm_dsc_compute_rc_parameters(), supposedly because that
function was yielding "incorrect" results while in reality the panel
driver(s?) used for testing were providing incorrect parameters.

For example, this code from downstream assumed dsc->bits_per_pixel to
contain an integer value, whereas the upstream drm_dsc_config struct
stores it with 4 fractional bits.  drm_dsc_compute_rc_parameters()
already accounts for this feat while the panel driver used for testing
[1] wasn't, hence making drm_dsc_compute_rc_parameters() seem like it
was returning an incorrect result.
Other users of dsc->bits_per_pixel inside dsi_populate_dsc_params() also
treat it in the same erroneous way, and will be addressed in a separate
patch.
In the end, using drm_dsc_compute_rc_parameters() spares both a lot of
duplicate code and erratic behaviour.

[1]: https://git.linaro.org/people/vinod.koul/kernel.git/commit/?h=topic/pixel3_5.18-rc1&id=1d7d98ad564f1ec69e7525e07418918d90f247a1

Fixes: b9080324 ("drm/msm/dsi: add support for dsc data")
Reviewed-by: default avatarAbhinav Kumar <quic_abhinavk@quicinc.com>
Signed-off-by: default avatarMarijn Suijten <marijn.suijten@somainline.org>
Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/508939/
Link: https://lore.kernel.org/r/20221026182824.876933-7-marijn.suijten@somainline.orgSigned-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
parent 0ca870ca
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <video/mipi_display.h> #include <video/mipi_display.h>
#include <drm/display/drm_dsc_helper.h>
#include <drm/drm_of.h> #include <drm/drm_of.h>
#include "dsi.h" #include "dsi.h"
...@@ -1749,14 +1750,6 @@ static char bpg_offset[DSC_NUM_BUF_RANGES] = { ...@@ -1749,14 +1750,6 @@ static char bpg_offset[DSC_NUM_BUF_RANGES] = {
static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) static int dsi_populate_dsc_params(struct drm_dsc_config *dsc)
{ {
int mux_words_size;
int groups_per_line, groups_total;
int min_rate_buffer_size;
int hrd_delay;
int pre_num_extra_mux_bits, num_extra_mux_bits;
int slice_bits;
int data;
int final_value, final_scale;
int i; int i;
dsc->rc_model_size = 8192; dsc->rc_model_size = 8192;
...@@ -1782,11 +1775,11 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) ...@@ -1782,11 +1775,11 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc)
if (dsc->bits_per_pixel != 8) if (dsc->bits_per_pixel != 8)
dsc->initial_offset = 2048; /* bpp = 12 */ dsc->initial_offset = 2048; /* bpp = 12 */
mux_words_size = 48; /* bpc == 8/10 */ if (dsc->bits_per_component <= 10)
if (dsc->bits_per_component == 12) dsc->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
mux_words_size = 64; else
dsc->mux_word_size = DSC_MUX_WORD_SIZE_12_BPC;
dsc->mux_word_size = mux_words_size;
dsc->initial_xmit_delay = 512; dsc->initial_xmit_delay = 512;
dsc->initial_scale_value = 32; dsc->initial_scale_value = 32;
dsc->first_line_bpg_offset = 12; dsc->first_line_bpg_offset = 12;
...@@ -1798,52 +1791,7 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) ...@@ -1798,52 +1791,7 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc)
dsc->rc_quant_incr_limit0 = 11; dsc->rc_quant_incr_limit0 = 11;
dsc->rc_quant_incr_limit1 = 11; dsc->rc_quant_incr_limit1 = 11;
/* FIXME: need to call drm_dsc_compute_rc_parameters() so that rest of return drm_dsc_compute_rc_parameters(dsc);
* params are calculated
*/
groups_per_line = DIV_ROUND_UP(dsc->slice_width, 3);
dsc->slice_chunk_size = DIV_ROUND_UP(dsc->slice_width * dsc->bits_per_pixel, 8);
/* rbs-min */
min_rate_buffer_size = dsc->rc_model_size - dsc->initial_offset +
dsc->initial_xmit_delay * dsc->bits_per_pixel +
groups_per_line * dsc->first_line_bpg_offset;
hrd_delay = DIV_ROUND_UP(min_rate_buffer_size, dsc->bits_per_pixel);
dsc->initial_dec_delay = hrd_delay - dsc->initial_xmit_delay;
dsc->initial_scale_value = 8 * dsc->rc_model_size /
(dsc->rc_model_size - dsc->initial_offset);
slice_bits = 8 * dsc->slice_chunk_size * dsc->slice_height;
groups_total = groups_per_line * dsc->slice_height;
data = dsc->first_line_bpg_offset * 2048;
dsc->nfl_bpg_offset = DIV_ROUND_UP(data, (dsc->slice_height - 1));
pre_num_extra_mux_bits = 3 * (mux_words_size + (4 * dsc->bits_per_component + 4) - 2);
num_extra_mux_bits = pre_num_extra_mux_bits - (mux_words_size -
((slice_bits - pre_num_extra_mux_bits) % mux_words_size));
data = 2048 * (dsc->rc_model_size - dsc->initial_offset + num_extra_mux_bits);
dsc->slice_bpg_offset = DIV_ROUND_UP(data, groups_total);
data = dsc->initial_xmit_delay * dsc->bits_per_pixel;
final_value = dsc->rc_model_size - data + num_extra_mux_bits;
dsc->final_offset = final_value;
final_scale = 8 * dsc->rc_model_size / (dsc->rc_model_size - final_value);
data = (final_scale - 9) * (dsc->nfl_bpg_offset + dsc->slice_bpg_offset);
dsc->scale_increment_interval = (2048 * dsc->final_offset) / data;
dsc->scale_decrement_interval = groups_per_line / (dsc->initial_scale_value - 8);
return 0;
} }
static int dsi_host_parse_dt(struct msm_dsi_host *msm_host) static int dsi_host_parse_dt(struct msm_dsi_host *msm_host)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment