Skip to contentSkip to conversation

drm/msm/dsi: improve/fix dsc pclk calculation

PATCH Superseded Jonathan Marek 3 participants 6 messages Oct 5, 2024 – Oct 6, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 185d7de0bf376..1205aa398e445 100644
@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
 
 	int 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
#1 lore raw

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
index 1205aa398e445..a98d24b7cb00b 100644
@@ -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
#2 lore raw

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 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.

Fixes?

Quoted 21 lines
---
 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
index 1205aa398e445..a98d24b7cb00b 100644
@@ -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
#3 lore raw
In reply to Jonathan Marek
Quoted 12 lines · Jonathan Marek

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 +0 -0
index 185d7de0bf376..1205aa398e445 100644

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_mo
 
 	int 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

#4 lore raw
Quoted 16 lines · Konrad Dybcio
Quoted 15 lines · Jonathan Marek

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 +0 -0
index 185d7de0bf376..1205aa398e445 100644
@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
 
  	int 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.

#5 lore raw
In reply to Jonathan Marek
Quoted 2 lines · Jonathan Marek

drm_mode_vrefresh() can introduce a large rounding error, avoid it.

Fixes?

Quoted 21 lines
---
 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
index 185d7de0bf376..1205aa398e445 100644
@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
 
 	int 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