Skip to contentSkip to conversation

drm/stm: ltdc: use crtc_mode_fixup to update adjusted_mode clock

PATCH In review Philippe Cornu 4 participants 5 messages Jan 25, 2018 – Jan 29, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/stm: ltdc: use crtc_mode_fixup to update adjusted_mode clock

There is a difference between the panel/bridge requested pixel clock value and the real one due to the hw platform clock preciseness (pll, dividers...). This patch updates the adjusted_mode clock value with the real hw clock value so then attached encoder & connector can use it for precise timing computations.

---
 drivers/gpu/drm/stm/ltdc.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/stm/ltdc.c +25 -10
index b48589343ae1..90b3de516c91 100644
@@ -428,12 +428,35 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc,
 	reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR);
 }
 
+static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
+				 const struct drm_display_mode *mode,
+				 struct drm_display_mode *adjusted_mode)
+{
+	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+	int rate = mode->clock * 1000;
+
+	/*
+	 * TODO clk_round_rate() does not work yet. When ready, it can
+	 * be used instead of clk_set_rate() then clk_get_rate().
+	 */
+
+	clk_disable(ldev->pixel_clk);
+	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
+		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
+		return false;
+	}
+	clk_enable(ldev->pixel_clk);
+
+	adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000;
+
+	return true;
+}
+
 static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
 	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
 	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
 	struct videomode vm;
-	int rate = mode->clock * 1000;
 	u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h;
 	u32 total_width, total_height;
 	u32 val;
@@ -456,15 +479,6 @@ static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
 	total_width = accum_act_w + vm.hfront_porch;
 	total_height = accum_act_h + vm.vfront_porch;
 
-	clk_disable(ldev->pixel_clk);
-
-	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
-		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
-		return;
-	}
-
-	clk_enable(ldev->pixel_clk);
-
 	/* Configures the HS, VS, DE and PC polarities. Default Active Low */
 	val = 0;
 
@@ -528,6 +542,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
 }
 
 static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
+	.mode_fixup = ltdc_crtc_mode_fixup,
 	.mode_set_nofb = ltdc_crtc_mode_set_nofb,
 	.atomic_flush = ltdc_crtc_atomic_flush,
 	.atomic_enable = ltdc_crtc_atomic_enable,
Signature · 6 lines
2.15.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Philippe Cornu

There is a difference between the panel/bridge requested pixel clock value and the real one due to the hw platform clock preciseness (pll, dividers...). This patch updates the adjusted_mode clock value with the real hw clock value so then attached encoder & connector can use it for precise timing computations.

Quoted 63 lines
---
  drivers/gpu/drm/stm/ltdc.c | 35 +++++++++++++++++++++++++----------
  1 file changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/stm/ltdc.c +24 -10
index b48589343ae1..90b3de516c91 100644
@@ -428,12 +428,35 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc,
  	reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR);
  }
 
+static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
+				 const struct drm_display_mode *mode,
+				 struct drm_display_mode *adjusted_mode)
+{
+	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+	int rate = mode->clock * 1000;
+
+	/*
+	 * TODO clk_round_rate() does not work yet. When ready, it can
+	 * be used instead of clk_set_rate() then clk_get_rate().
+	 */
+
+	clk_disable(ldev->pixel_clk);
+	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
+		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
+		return false;
+	}
+	clk_enable(ldev->pixel_clk);
+
+	adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000;
+
+	return true;
+}
+
  static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
  {
  	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
  	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
  	struct videomode vm;
-	int rate = mode->clock * 1000;
  	u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h;
  	u32 total_width, total_height;
  	u32 val;
@@ -456,15 +479,6 @@ static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
  	total_width = accum_act_w + vm.hfront_porch;
  	total_height = accum_act_h + vm.vfront_porch;
 
-	clk_disable(ldev->pixel_clk);
-
-	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
-		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
-		return;
-	}
-
-	clk_enable(ldev->pixel_clk);
-
  	/* Configures the HS, VS, DE and PC polarities. Default Active Low */
  	val = 0;
 

drivers/gpu/drm/stm/ltdc.c static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc, · line 548

Quoted 7 lines
drivers/gpu/drm/stm/ltdc.c +1 -0
@@ -528,6 +542,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
  }
 
  static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
+	.mode_fixup = ltdc_crtc_mode_fixup,
  	.mode_set_nofb = ltdc_crtc_mode_set_nofb,
  	.atomic_flush = ltdc_crtc_atomic_flush,
  	.atomic_enable = ltdc_crtc_atomic_enable,

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

2018-01-29 10:46 GMT+01:00 Yannick FERTRE <[email protected]>:

Quoted 8 lines · Philippe Cornu
Quoted 5 lines

There is a difference between the panel/bridge requested pixel clock value and the real one due to the hw platform clock preciseness (pll, dividers...). This patch updates the adjusted_mode clock value with the real hw clock value so then attached encoder & connector can use it for precise timing computations.

Quoted 1 line

Applied on drm-misc-next.

Regards,
Benjamin

Quoted 61 lines
Quoted 61 lines
---
  drivers/gpu/drm/stm/ltdc.c | 35 +++++++++++++++++++++++++----------
  1 file changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/stm/ltdc.c +24 -10
index b48589343ae1..90b3de516c91 100644
@@ -428,12 +428,35 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc,
      reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR);
  }
 
+static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
+                              const struct drm_display_mode *mode,
+                              struct drm_display_mode *adjusted_mode)
+{
+     struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+     int rate = mode->clock * 1000;
+
+     /*
+      * TODO clk_round_rate() does not work yet. When ready, it can
+      * be used instead of clk_set_rate() then clk_get_rate().
+      */
+
+     clk_disable(ldev->pixel_clk);
+     if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
+             DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
+             return false;
+     }
+     clk_enable(ldev->pixel_clk);
+
+     adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000;
+
+     return true;
+}
+
  static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
  {
      struct ltdc_device *ldev = crtc_to_ltdc(crtc);
      struct drm_display_mode *mode = &crtc->state->adjusted_mode;
      struct videomode vm;
-     int rate = mode->clock * 1000;
      u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h;
      u32 total_width, total_height;
      u32 val;
@@ -456,15 +479,6 @@ static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
      total_width = accum_act_w + vm.hfront_porch;
      total_height = accum_act_h + vm.vfront_porch;
 
-     clk_disable(ldev->pixel_clk);
-
-     if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
-             DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
-             return;
-     }
-
-     clk_enable(ldev->pixel_clk);
-
      /* Configures the HS, VS, DE and PC polarities. Default Active Low */
      val = 0;
 
Quoted 8 lines

drivers/gpu/drm/stm/ltdc.c static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc, · line 548

Quoted 8 lines
drivers/gpu/drm/stm/ltdc.c +1 -0
@@ -528,6 +542,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
  }
 
  static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
+     .mode_fixup = ltdc_crtc_mode_fixup,
      .mode_set_nofb = ltdc_crtc_mode_set_nofb,
      .atomic_flush = ltdc_crtc_atomic_flush,
      .atomic_enable = ltdc_crtc_atomic_enable,

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
In reply to Philippe Cornu

Hi Philippe,

Quoted 20 lines · On Thursday, 25 January 2018 18:01:01 EET Philippe Cornu wrote:

There is a difference between the panel/bridge requested pixel clock value and the real one due to the hw platform clock preciseness (pll, dividers...). This patch updates the adjusted_mode clock value with the real hw clock value so then attached encoder & connector can use it for precise timing computations.

---
 drivers/gpu/drm/stm/ltdc.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/stm/ltdc.c +1 -0
index b48589343ae1..90b3de516c91 100644
@@ -428,12 +428,35 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc
 *crtc, reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR);
 }
 
+static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,

drivers/gpu/drm/stm/ltdc.c static void ltdc_crtc_atomic_disable(struct drm_crtc · line 441

Quoted 10 lines
drivers/gpu/drm/stm/ltdc.c +10 -0
+				 const struct drm_display_mode *mode,
+				 struct drm_display_mode *adjusted_mode)
+{
+	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+	int rate = mode->clock * 1000;
+
+	/*
+	 * TODO clk_round_rate() does not work yet. When ready, it can
+	 * be used instead of clk_set_rate() then clk_get_rate().
+	 */

Why does it fail ? Is it due to the STM clock source implementation ? This looks like a big hack, I'd rather see clk_round_rate() being fixed.

Quoted 45 lines
drivers/gpu/drm/stm/ltdc.c +13 -10
+	clk_disable(ldev->pixel_clk);
+	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
+		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
+		return false;
+	}
+	clk_enable(ldev->pixel_clk);
+
+	adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000;
+
+	return true;
+}
+
 static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
 	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
 	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
 	struct videomode vm;
-	int rate = mode->clock * 1000;
 	u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h;
 	u32 total_width, total_height;
 	u32 val;
@@ -456,15 +479,6 @@ static void ltdc_crtc_mode_set_nofb(struct drm_crtc
 *crtc) total_width = accum_act_w + vm.hfront_porch;
 	total_height = accum_act_h + vm.vfront_porch;
 
-	clk_disable(ldev->pixel_clk);
-
-	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
-		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
-		return;
-	}
-
-	clk_enable(ldev->pixel_clk);
-
 	/* Configures the HS, VS, DE and PC polarities. Default Active Low */
 	val = 0;
 
@@ -528,6 +542,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc
 *crtc, }
 
 static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
+	.mode_fixup = ltdc_crtc_mode_fixup,
 	.mode_set_nofb = ltdc_crtc_mode_set_nofb,
 	.atomic_flush = ltdc_crtc_atomic_flush,
 	.atomic_enable = ltdc_crtc_atomic_enable,
Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

2018-01-29 11:43 GMT+01:00 Laurent Pinchart <[email protected]>:

Quoted 22 lines

Hi Philippe,

Quoted 19 lines · On Thursday, 25 January 2018 18:01:01 EET Philippe Cornu wrote:

There is a difference between the panel/bridge requested pixel clock value and the real one due to the hw platform clock preciseness (pll, dividers...). This patch updates the adjusted_mode clock value with the real hw clock value so then attached encoder & connector can use it for precise timing computations.

---
 drivers/gpu/drm/stm/ltdc.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/stm/ltdc.c +0 -0
index b48589343ae1..90b3de516c91 100644
@@ -428,12 +428,35 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc
 *crtc, reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR);
 }
 
Quoted 14 lines

drivers/gpu/drm/stm/ltdc.c static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc, · line 441

Quoted 11 lines
drivers/gpu/drm/stm/ltdc.c +11 -0
+static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
+                              const struct drm_display_mode *mode,
+                              struct drm_display_mode *adjusted_mode)
+{
+     struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+     int rate = mode->clock * 1000;
+
+     /*
+      * TODO clk_round_rate() does not work yet. When ready, it can
+      * be used instead of clk_set_rate() then clk_get_rate().
+      */

Why does it fail ? Is it due to the STM clock source implementation ? This looks like a big hack, I'd rather see clk_round_rate() being fixed.

We have log the point and we will investigate it asap.

Regards,
Benjamin

Quoted 52 lines
Quoted 39 lines
drivers/gpu/drm/stm/ltdc.c +12 -10
+     clk_disable(ldev->pixel_clk);
+     if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
+             DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
+             return false;
+     }
+     clk_enable(ldev->pixel_clk);
+
+     adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000;
+
+     return true;
+}
+
 static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
      struct ltdc_device *ldev = crtc_to_ltdc(crtc);
      struct drm_display_mode *mode = &crtc->state->adjusted_mode;
      struct videomode vm;
-     int rate = mode->clock * 1000;
      u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h;
      u32 total_width, total_height;
      u32 val;
@@ -456,15 +479,6 @@ static void ltdc_crtc_mode_set_nofb(struct drm_crtc
 *crtc) total_width = accum_act_w + vm.hfront_porch;
      total_height = accum_act_h + vm.vfront_porch;
 
-     clk_disable(ldev->pixel_clk);
-
-     if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
-             DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
-             return;
-     }
-
-     clk_enable(ldev->pixel_clk);
-
      /* Configures the HS, VS, DE and PC polarities. Default Active Low */
      val = 0;
 

drivers/gpu/drm/stm/ltdc.c static void ltdc_crtc_atomic_flush(struct drm_crtc · line 548

Quoted 7 lines
drivers/gpu/drm/stm/ltdc.c +1 -0
@@ -528,6 +542,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc
 *crtc, }
 
 static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
+     .mode_fixup = ltdc_crtc_mode_fixup,
      .mode_set_nofb = ltdc_crtc_mode_set_nofb,
      .atomic_flush = ltdc_crtc_atomic_flush,
      .atomic_enable = ltdc_crtc_atomic_enable,

--
Regards,

Laurent Pinchart