Skip to contentSkip to conversation

drm/bridge: tc358767: Improve DPI output pixel clock accuracy

PATCH Superseded Marek Vasut 3 participants 3 messages Oct 26, 2024 – Oct 28, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: tc358767: Improve DPI output pixel clock accuracy

The Pixel PLL is not very capable and may come up with wildly inaccurate clock. Since DPI panels are often tolerant to slightly higher pixel clock without being operated outside of specification, calculate two Pixel PLL settings for DPI output, one for desired output pixel clock and one for output pixel clock with 1% increase, and then pick the result which is closer to the desired pixel clock and use it as the Pixel PLL settings.

For the Chefree CH101 panel with 13 MHz Xtal input clock, the frequency without this patch is 65 MHz which is out of the panel specification of 68.9..73.4 MHz, while with this patch it is 71.5 MHz which is well within the specification and far more accurate.

---
Cc: Andrzej Hajda <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Simona Vetter <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]

---
 drivers/gpu/drm/bridge/tc358767.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +26 -2
index 0d523322fdd8e..7e1a7322cec70 100644
@@ -1682,15 +1682,39 @@ static int tc_dpi_atomic_check(struct drm_bridge *bridge,
 			       struct drm_connector_state *conn_state)
 {
 	struct tc_data *tc = bridge_to_tc(bridge);
-	int adjusted_clock = 0;
+	int adjusted_clock_0p = 0;
+	int adjusted_clock_1p = 0;
+	int adjusted_clock;
 	int ret;
 
+	/*
+	 * Calculate adjusted clock pixel and find out what the PLL can
+	 * produce. The PLL is limited, so the clock might be inaccurate.
+	 */
 	ret = tc_pxl_pll_calc(tc, clk_get_rate(tc->refclk),
 			      crtc_state->mode.clock * 1000,
-			      &adjusted_clock, NULL);
+			      &adjusted_clock_0p, NULL);
+	if (ret)
+		return ret;
+
+	/*
+	 * Calculate adjusted pixel clock with 1% faster requested pixel
+	 * clock and find out what the PLL can produce. This may in fact
+	 * be closer to the expected pixel clock of the output.
+	 */
+	ret = tc_pxl_pll_calc(tc, clk_get_rate(tc->refclk),
+			      crtc_state->mode.clock * 1010,
+			      &adjusted_clock_1p, NULL);
 	if (ret)
 		return ret;
 
+	/* Pick the more accurate of the two calculated results. */
+	if (crtc_state->mode.clock * 1010 - adjusted_clock_1p <
+	    crtc_state->mode.clock * 1000 - adjusted_clock_0p)
+		adjusted_clock = adjusted_clock_1p;
+	else
+		adjusted_clock = adjusted_clock_0p;
+
 	crtc_state->adjusted_mode.clock = adjusted_clock / 1000;
 
 	/* DSI->DPI interface clock limitation: upto 100 MHz */
Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 6 lines · Marek Vasut

The Pixel PLL is not very capable and may come up with wildly inaccurate clock. Since DPI panels are often tolerant to slightly higher pixel clock without being operated outside of specification, calculate two Pixel PLL settings for DPI output, one for desired output pixel clock and one for output pixel clock with 1% increase, and then pick the result which is closer to the desired pixel clock and use it as the Pixel PLL settings.

The typical tolerance we've used is .5%, which is recommended by VESA in several specs. Differing from it for a good reason is ok I guess, but you need to document why.

Maxime

maintainer
#2 lore raw
In reply to Marek Vasut
Quoted 66 lines · Marek Vasut

The Pixel PLL is not very capable and may come up with wildly inaccurate clock. Since DPI panels are often tolerant to slightly higher pixel clock without being operated outside of specification, calculate two Pixel PLL settings for DPI output, one for desired output pixel clock and one for output pixel clock with 1% increase, and then pick the result which is closer to the desired pixel clock and use it as the Pixel PLL settings.

For the Chefree CH101 panel with 13 MHz Xtal input clock, the frequency without this patch is 65 MHz which is out of the panel specification of 68.9..73.4 MHz, while with this patch it is 71.5 MHz which is well within the specification and far more accurate.

---
Cc: Andrzej Hajda <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Simona Vetter <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]

---
  drivers/gpu/drm/bridge/tc358767.c | 28 ++++++++++++++++++++++++++--
  1 file changed, 26 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +19 -2
index 0d523322fdd8e..7e1a7322cec70 100644
@@ -1682,15 +1682,39 @@ static int tc_dpi_atomic_check(struct drm_bridge *bridge,
  			       struct drm_connector_state *conn_state)
  {
  	struct tc_data *tc = bridge_to_tc(bridge);
-	int adjusted_clock = 0;
+	int adjusted_clock_0p = 0;
+	int adjusted_clock_1p = 0;
+	int adjusted_clock;
  	int ret;
 
+	/*
+	 * Calculate adjusted clock pixel and find out what the PLL can
+	 * produce. The PLL is limited, so the clock might be inaccurate.
+	 */
  	ret = tc_pxl_pll_calc(tc, clk_get_rate(tc->refclk),
  			      crtc_state->mode.clock * 1000,
-			      &adjusted_clock, NULL);
+			      &adjusted_clock_0p, NULL);
+	if (ret)
+		return ret;
+
+	/*
+	 * Calculate adjusted pixel clock with 1% faster requested pixel
+	 * clock and find out what the PLL can produce. This may in fact
+	 * be closer to the expected pixel clock of the output.
+	 */
+	ret = tc_pxl_pll_calc(tc, clk_get_rate(tc->refclk),
+			      crtc_state->mode.clock * 1010,
+			      &adjusted_clock_1p, NULL);
  	if (ret)
  		return ret;
 

drivers/gpu/drm/bridge/tc358767.c static int tc_dpi_atomic_check(struct drm_bridge *bridge, · line 1720

Quoted 10 lines
drivers/gpu/drm/bridge/tc358767.c +7 -0
+	/* Pick the more accurate of the two calculated results. */
+	if (crtc_state->mode.clock * 1010 - adjusted_clock_1p <
+	    crtc_state->mode.clock * 1000 - adjusted_clock_0p)
+		adjusted_clock = adjusted_clock_1p;
+	else
+		adjusted_clock = adjusted_clock_0p;
+
  	crtc_state->adjusted_mode.clock = adjusted_clock / 1000;
 
  	/* DSI->DPI interface clock limitation: upto 100 MHz */

It looks like you want to go around a not very well written tc_pxl_pll_calc()

Seems the functions would either need a rewrite or perhaps use CCF instead by declaring all the pre-div/PLL/post-div.

Neil