linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [RFC] drm/stm: Prefer faster display pixel clock over slower ones
@ 2020-09-09 18:58 Marek Vasut
  0 siblings, 0 replies; only message in thread
From: Marek Vasut @ 2020-09-09 18:58 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Marek Vasut, Alexandre Torgue, Philippe Cornu, dri-devel,
	Yannick Fertré,
	Maxime Coquelin, Vincent Abriou, linux-stm32, Benjamin Gaignard

If the delta between requested pixelclock and resulting pixelclock
is larger than the delta between requested pixelclock and the next
step in available pixelclock (limited to 10% of pixelclock to avoid
too much out-of-specification operation), use the faster pixelclock.

This fixes the condition where the resulting pixelclock is much
slower than the lowest clock rate supported by the display, while
the next available pixelclock are just slightly faster than the
highest clock rate supported by the display. Using the lower clock
rate leads e.g. to subtle artifacts barely visible on the display,
like flickering pixels. Using slightly faster clock leads to no
such effect.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Benjamin Gaignard <benjamin.gaignard@st.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Philippe Cornu <philippe.cornu@st.com>
Cc: Vincent Abriou <vincent.abriou@st.com>
Cc: Yannick Fertré <yannick.fertre@st.com>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
---
 drivers/gpu/drm/stm/ltdc.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
index 6e28f707092f..07c73079293c 100644
--- a/drivers/gpu/drm/stm/ltdc.c
+++ b/drivers/gpu/drm/stm/ltdc.c
@@ -507,6 +507,25 @@ static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
 {
 	struct ltdc_device *ldev = crtc_to_ltdc(crtc);
 	int rate = mode->clock * 1000;
+	int rate_min = clk_round_rate(ldev->pixel_clk, rate);
+	int rate_max = clk_round_rate(ldev->pixel_clk, rate + (rate / 10));
+
+	/*
+	 * If the delta between requested pixelclock and resulting pixelclock
+	 * is larger than the delta between requested pixelclock and the next
+	 * step in available pixelclock (limited to 10% of pixelclock to avoid
+	 * too much out-of-specification operation), use the faster pixelclock.
+	 *
+	 * This fixes the condition where the resulting pixelclock is much
+	 * slower than the lowest clock rate supported by the display, while
+	 * the next available pixelclock are just slightly faster than the
+	 * highest clock rate supported by the display. Using the lower clock
+	 * rate leads e.g. to subtle artifacts barely visible on the display,
+	 * like flickering pixels. Using slightly faster clock leads to no
+	 * such effect.
+	 */
+	if (rate - rate_min > rate_max - rate)
+		rate = rate_max;
 
 	if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
 		DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
-- 
2.28.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-09 19:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09 18:58 [PATCH] [RFC] drm/stm: Prefer faster display pixel clock over slower ones Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).