drm/msm/dsi: improve/fix dsc pclk calculation
PATCH 1/2 drm/msm/dsi: improve/fix dsc pclk calculation
drm_mode_vrefresh() can introduce a large rounding error, avoid it.
--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_moint new_htotal = mode->htotal - mode->hdisplay + new_hdisplay; -return new_htotal * mode->vtotal *drm_mode_vrefresh (mode); +return mult_frac (mode->clock *1000u , new_htotal, mode->htotal); } static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode,
Signature · 1 line
2.45.1
PATCH 2/2 drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation
When (mode->clock * 1000) is larger than (1<<31), int to unsigned long conversion will sign extend the int to 64 bits and the pclk_rate value will be incorrect.
Fix this by making the result of the multiplication unsigned.
Note that above (1<<32) would still be broken and require more changes, but its unlikely anyone will need that anytime soon.
--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -550,7 +550,7 @@ static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode, {unsigned long pclk_rate; - pclk_rate = mode->clock *1000 ; + pclk_rate = mode->clock *1000u ;if (dsc) pclk_rate =dsi_adjust_pclk_for_compression (mode, dsc);
Signature · 1 line
2.45.1
Re: [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation
Quoted 9 lines · Jonathan Marek
When (
mode->clock* 1000) is larger than (1<<31), int to unsigned long conversion will sign extend the int to 64 bits and thepclk_ratevalue will be incorrect.Fix this by making the result of the multiplication unsigned.
Note that above (1<<32) would still be broken and require more changes, but its unlikely anyone will need that anytime soon.
Fixes?
Quoted 21 lines
Signed-off-by Jonathan Marek <[email protected]>--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/dsi/dsi_host.c +1
-1@@ -550,7 +550,7 @@ static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode, {unsigned long pclk_rate; - pclk_rate = mode->clock *1000 ; + pclk_rate = mode->clock *1000u ;if (dsc) pclk_rate =dsi_adjust_pclk_for_compression (mode, dsc);Signature · 1 line
2.45.1
Signature · 2 lines
With best wishes Dmitry
Quoted 12 lines · Jonathan Marek
drm_mode_vrefresh()can introduce a large rounding error, avoid it.Signed-off-by Jonathan Marek <[email protected]>--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/dsi/dsi_host.c +0
-0
drivers/gpu/drm/msm/dsi/dsi_host.c static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo · line 545
Quoted 5 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1
-1@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_moint new_htotal = mode->htotal - mode->hdisplay + new_hdisplay; -return new_htotal * mode->vtotal *drm_mode_vrefresh (mode); +return mult_frac (mode->clock *1000u , new_htotal, mode->htotal);
This seems to ignore mult/div by two on certain mode flags.. is that intended?
Konrad
Quoted 16 lines · Konrad Dybcio
Quoted 15 lines · Jonathan Marek
drm_mode_vrefresh()can introduce a large rounding error, avoid it.Signed-off-by Jonathan Marek <[email protected]>--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/dsi/dsi_host.c +0
-0@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_moint new_htotal = mode->htotal - mode->hdisplay + new_hdisplay;
Quoted 8 lines
drivers/gpu/drm/msm/dsi/dsi_host.c static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo · line 545
Quoted 2 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1
-1-return new_htotal * mode->vtotal *drm_mode_vrefresh (mode); +return mult_frac (mode->clock *1000u , new_htotal, mode->htotal);This seems to ignore mult/div by two on certain mode flags.. is that intended?
Konrad
It is intended - those flags are not relevant to DSI panels, and DSC pclk adjustment is only about how DSC affects htotal.
Quoted 2 lines · Jonathan Marek
drm_mode_vrefresh()can introduce a large rounding error, avoid it.
Fixes?
Quoted 21 lines
Signed-off-by Jonathan Marek <[email protected]>--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/dsi/dsi_host.c +1
-1@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_moint new_htotal = mode->htotal - mode->hdisplay + new_hdisplay; -return new_htotal * mode->vtotal *drm_mode_vrefresh (mode); +return mult_frac (mode->clock *1000u , new_htotal, mode->htotal); } static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode,Signature · 1 line
2.45.1
Signature · 2 lines
With best wishes Dmitry