Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection
@ 2026-11-03 17:20 Prabhakar
  2026-11-03 17:20 ` [PATCH 1/4] clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider parameters Prabhakar
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Prabhakar @ 2026-11-03 17:20 UTC (permalink / raw)
  To: Geert Uytterhoeven, Stephen Boyd, Brian Masney, Jerome Brunet,
	Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: linux-renesas-soc, linux-clk, linux-kernel, dri-devel, Prabhakar,
	Fabrizio Castro, Lad Prabhakar

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Hi all,

On RZ/V2H(P) and RZ/V2N the DSI HS clock is derived from the pixel clock
produced by the CPG PLLDSI and its divider (HS clock = pixel clock *
bpp / lanes), and the PLL in the DSI block has to reproduce it to within
0.5 Hz. A display mode is usable only if a single set of CPG parameters
satisfies both the CPG and the DSI PLL constraints, but the two were
checked one after the other instead of together:

 - Mode validation took the CPG parameters with the smallest frequency
   error and only then checked the DSI PLL. A divider that lost on CPG
   error alone was never tried against the DSI PLL, so modes were
   rejected although another divider or PLL setting would have worked.
 - The PLLDSI divider's .determine_rate() runs its own search when the
   clock is set, so it can pick parameters other than the ones the DSI
   driver validated.

The first two patches add the clock-side support, the last two make the
DSI driver use it:

 1. Let the DSI driver cache the CPG divider parameters it validated,
    per PLLDSI instance, and have .determine_rate() reuse them when the
    requested rate matches.
 2. Add rzv2h_cpg_get_pll_pars_validate(), which offers each candidate
    to a callback and returns the first one it accepts.
    rzv2h_get_pll_pars() becomes a wrapper passing a NULL validator, so
    existing callers are unchanged.
 3. Evaluate every divider against the DSI PLL limits, keep the one with
    the smallest DSI PLL error and hand it to the CPG using the cache
    from patch 1.
 4. If no divider gives a usable pair, search again using patch 2 and
    take the first CPG candidate that is at most 50 Hz off at the PLLDSI
    output and gives a DSI HS clock error below 0.5 Hz. 50 Hz is at most
    2 ppm of the 25 MHz minimum PLLDSI output, so the pixel clock error
    stays negligible.

The cache in patch 1 is indexed by PLLDSI instance and shared by all CPG
instances, as the DSI driver only knows which instance it targets. If
there is a cleaner way to hand the parameters over to the CPG, I am
happy to rework it.

Testing
-------
"modetest -c" on [RZ/V2H EVK] (DSI -> ADV7535 -> HDMI, 4 lanes,
[monitor]) lists 27 modes instead of 21. No mode is lost, and these are
the newly usable ones:

  mode        refresh   pixel clock
  1920x1080   59.94 Hz  148352 kHz
  1280x720    59.94 Hz   74176 kHz
  720x480     60.00 Hz   27027 kHz
  640x480     60.00 Hz   25200 kHz
  640x480     59.94 Hz   25175 kHz
  720x400     70.08 Hz   28320 kHz

Dependencies
------------
Based on next-20261102 plus two patches from Tommaso that are not in
that tree:

  [1] clk: renesas: rzv2h: Forward PLLDSI mux rate requests to the parent
  [2] clk: renesas: rzv2h: Report the DSI duty cycle from the LVDS divider

[1] https://lore.kernel.org/all/20261029-tm-ssgrlpcsrc-2083-v5-clk-duty-fixes-v1-1-47f23de6bdb1@bp.renesas.com/
[2] https://lore.kernel.org/all/20261029-tm-ssgrlpcsrc-2083-v5-clk-duty-fixes-v1-2-47f23de6bdb1@bp.renesas.com/

Geert, Biju: I would suggest taking everything via renesas-clk
with an Ack from the DRM side, or providing an immutable branch with
patches 1-2 for the DRM tree. Please let me know which you prefer.

Cheers,
Prabhakar

Lad Prabhakar (4):
  clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider
    parameters
  clk: renesas: rzv2h-cpg: Add validation hook to PLL parameter search
  drm: renesas: rz-du: mipi_dsi: Improve DSI PLL parameter selection and
    cache results
  drm: renesas: rz-du: mipi_dsi: Add fallback CPG PLLDSI parameter
    search

 drivers/clk/renesas/rzv2h-cpg-lib.c           | 109 ++++++++++-
 drivers/clk/renesas/rzv2h-cpg.c               |  15 +-
 .../gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c    | 174 +++++++++++++++---
 include/linux/clk/renesas.h                   |  38 ++++
 4 files changed, 300 insertions(+), 36 deletions(-)

-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider parameters
  2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
@ 2026-11-03 17:20 ` Prabhakar
  2026-11-03 17:20 ` [PATCH 2/4] clk: renesas: rzv2h-cpg: Add validation hook to PLL parameter search Prabhakar
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Prabhakar @ 2026-11-03 17:20 UTC (permalink / raw)
  To: Geert Uytterhoeven, Stephen Boyd, Brian Masney, Jerome Brunet,
	Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: linux-renesas-soc, linux-clk, linux-kernel, dri-devel, Prabhakar,
	Fabrizio Castro, Lad Prabhakar, Tommaso Merciai

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

The CPG PLLDSI output feeds the PLLDSI inside the MIPI DSI block, so
the divider parameters selected by the CPG must also satisfy the DSI
PLL constraints. The DSI driver checks both sets of constraints during
mode validation, but the CPG's .determine_rate() callback performs its
own search and can select a different combination.

Allow the DSI driver to cache the selected divider parameters per DSI
PLL instance and reuse them in .determine_rate() when the requested
rate matches the cached frequency, including its error. Protect the
shared cache with a spinlock to avoid races between mode validation
and rate determination.

Move the maximum number of DSI PLL instances to the public header so
the CPG driver and library share the same limit.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
 drivers/clk/renesas/rzv2h-cpg-lib.c | 48 +++++++++++++++++++++++++++++
 drivers/clk/renesas/rzv2h-cpg.c     | 15 ++++++---
 include/linux/clk/renesas.h         | 16 ++++++++++
 3 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/renesas/rzv2h-cpg-lib.c b/drivers/clk/renesas/rzv2h-cpg-lib.c
index 124239c7327e..4b59bf60edb0 100644
--- a/drivers/clk/renesas/rzv2h-cpg-lib.c
+++ b/drivers/clk/renesas/rzv2h-cpg-lib.c
@@ -7,12 +7,60 @@
  *
  */
 
+#include <linux/bug.h>
+#include <linux/cleanup.h>
 #include <linux/clk/renesas.h>
 #include <linux/export.h>
 #include <linux/math.h>
+#include <linux/spinlock.h>
 #include <linux/types.h>
 #include <linux/units.h>
 
+/*
+ * Divider parameters handed over by the MIPI DSI driver, which evaluates both
+ * the CPG and the DSI PLL constraints before settling on a combination. They
+ * are indexed by DSI PLL instance, as the producer only knows the instance it
+ * targets, so they are shared by all CPG instances. The producer runs in the
+ * DSI mode validation path and the consumer in .determine_rate(), so the
+ * accesses are protected by a spinlock.
+ */
+static DEFINE_SPINLOCK(cache_pll_dsi_lock);
+static struct rzv2h_pll_div_pars cache_pll_dsi_pars[RZV2H_CPG_MAX_DSI_PLL];
+
+/**
+ * rzv2h_cpg_cache_pll_pars - Cache divider parameters for a PLLDSI instance
+ *
+ * @pars: PLL and divider parameters computed by the MIPI DSI driver
+ * @dsi_instance: PLLDSI instance the parameters are meant for
+ *
+ * Stores @pars so that the PLLDSI divider's .determine_rate() can use them
+ * instead of running its own search, when asked for the matching rate. The
+ * DSI driver needs this because the display clock is set before the DSI
+ * bridge is enabled, and the CPG alone does not know the DSI PLL constraints.
+ *
+ * A later call for the same @dsi_instance overwrites the previous entry.
+ * An out-of-range @dsi_instance is ignored with a warning.
+ */
+void rzv2h_cpg_cache_pll_pars(struct rzv2h_pll_div_pars pars,
+			      unsigned int dsi_instance)
+{
+	if (WARN_ON(dsi_instance >= RZV2H_CPG_MAX_DSI_PLL))
+		return;
+
+	guard(spinlock)(&cache_pll_dsi_lock);
+	cache_pll_dsi_pars[dsi_instance] = pars;
+}
+EXPORT_SYMBOL_NS_GPL(rzv2h_cpg_cache_pll_pars, "RZV2H_CPG");
+
+struct rzv2h_pll_div_pars rzv2h_cpg_get_cached_pll_pars(unsigned int dsi_instance)
+{
+	if (WARN_ON(dsi_instance >= RZV2H_CPG_MAX_DSI_PLL))
+		return (struct rzv2h_pll_div_pars){0};
+
+	guard(spinlock)(&cache_pll_dsi_lock);
+	return cache_pll_dsi_pars[dsi_instance];
+}
+
 /**
  * rzv2h_cpg_get_pll_pars - Finds the best combination of PLL parameters
  * for a given frequency.
diff --git a/drivers/clk/renesas/rzv2h-cpg.c b/drivers/clk/renesas/rzv2h-cpg.c
index 7ca2447fd811..e6f6a3fec449 100644
--- a/drivers/clk/renesas/rzv2h-cpg.c
+++ b/drivers/clk/renesas/rzv2h-cpg.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/bitfield.h>
+#include <linux/bug.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/clk/renesas.h>
@@ -72,9 +73,6 @@
 
 #define CPG_CLKSTATUS0		(0x700)
 
-/* On RZ/G3E SoC we have two DSI PLLs */
-#define MAX_CPG_DSI_PLL		2
-
 /**
  * struct rzv2h_pll_dsi_info - PLL DSI information, holds the limits and parameters
  *
@@ -123,7 +121,7 @@ struct rzv2h_cpg_priv {
 
 	struct reset_controller_dev rcdev;
 
-	struct rzv2h_pll_dsi_info pll_dsi_info[MAX_CPG_DSI_PLL];
+	struct rzv2h_pll_dsi_info pll_dsi_info[RZV2H_CPG_MAX_DSI_PLL];
 };
 
 #define rcdev_to_priv(x)	container_of(x, struct rzv2h_cpg_priv, rcdev)
@@ -235,6 +233,7 @@ static int rzv2h_cpg_plldsi_div_determine_rate(struct clk_hw *hw,
 {
 	struct rzv2h_plldsi_div_clk *dsi_div = to_plldsi_div_clk(hw);
 	struct pll_clk *pll_clk = to_pll(clk_hw_get_parent(hw));
+	struct rzv2h_pll_div_pars cached_dsi_parameters;
 	struct rzv2h_cpg_priv *priv = dsi_div->priv;
 	u8 table[RZV2H_MAX_DIV_TABLES] = { 0 };
 	struct rzv2h_pll_div_pars *dsi_params;
@@ -247,6 +246,14 @@ static int rzv2h_cpg_plldsi_div_determine_rate(struct clk_hw *hw,
 	dsi_params = &dsi_info->pll_dsi_parameters;
 
 	rate_millihz = mul_u32_u32(req->rate, MILLI);
+
+	cached_dsi_parameters = rzv2h_cpg_get_cached_pll_pars(pll_clk->pll.instance);
+	if (rate_millihz == cached_dsi_parameters.div.error_millihz +
+			    cached_dsi_parameters.div.freq_millihz) {
+		*dsi_params = cached_dsi_parameters;
+		goto exit_determine_rate;
+	}
+
 	if (rate_millihz == dsi_params->div.error_millihz + dsi_params->div.freq_millihz)
 		goto exit_determine_rate;
 
diff --git a/include/linux/clk/renesas.h b/include/linux/clk/renesas.h
index c9495558cd5c..c1582ed9bf69 100644
--- a/include/linux/clk/renesas.h
+++ b/include/linux/clk/renesas.h
@@ -159,6 +159,9 @@ struct rzv2h_pll_div_pars {
 	} div;
 };
 
+/* On RZ/G3E SoC we have two DSI PLLs */
+#define RZV2H_CPG_MAX_DSI_PLL		2
+
 #define RZV2H_CPG_PLL_DSI_LIMITS(name)					\
 	static const struct rzv2h_pll_limits (name) = {			\
 		.fout = { .min = 25 * MEGA, .max = 375 * MEGA },	\
@@ -196,6 +199,9 @@ bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
 bool rzv2h_cpg_get_pll_divs_pars(const struct rzv2h_pll_limits *limits,
 				 struct rzv2h_pll_div_pars *pars,
 				 const u8 *table, u8 table_size, u64 freq_millihz);
+void rzv2h_cpg_cache_pll_pars(struct rzv2h_pll_div_pars pars,
+			      unsigned int dsi_instance);
+struct rzv2h_pll_div_pars rzv2h_cpg_get_cached_pll_pars(unsigned int dsi_instance);
 #else
 static inline bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
 					  struct rzv2h_pll_pars *pars,
@@ -211,6 +217,16 @@ static inline bool rzv2h_cpg_get_pll_divs_pars(const struct rzv2h_pll_limits *li
 {
 	return false;
 }
+
+static inline void rzv2h_cpg_cache_pll_pars(struct rzv2h_pll_div_pars pars,
+					    unsigned int dsi_instance)
+{
+}
+
+static inline struct rzv2h_pll_div_pars rzv2h_cpg_get_cached_pll_pars(unsigned int dsi_instance)
+{
+	return (struct rzv2h_pll_div_pars){0};
+}
 #endif
 
 #define rzv2h_get_pll_pars	rzv2h_cpg_get_pll_pars
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] clk: renesas: rzv2h-cpg: Add validation hook to PLL parameter search
  2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
  2026-11-03 17:20 ` [PATCH 1/4] clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider parameters Prabhakar
@ 2026-11-03 17:20 ` Prabhakar
  2026-11-03 17:20 ` [PATCH 3/4] drm: renesas: rz-du: mipi_dsi: Improve DSI PLL parameter selection and cache results Prabhakar
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Prabhakar @ 2026-11-03 17:20 UTC (permalink / raw)
  To: Geert Uytterhoeven, Stephen Boyd, Brian Masney, Jerome Brunet,
	Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: linux-renesas-soc, linux-clk, linux-kernel, dri-devel, Prabhakar,
	Fabrizio Castro, Lad Prabhakar, Tommaso Merciai

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

rzv2h_get_pll_pars() returns the candidate with the smallest frequency
error, which can be unusable for callers whose constraints come from
downstream PLLs, such as the MIPI DSI driver.

Add rzv2h_cpg_get_pll_pars_validate(), which takes a callback and its
context. The callback is invoked for every candidate in search order and
the first one it accepts is returned, which is not necessarily the one
with the smallest error. Rejected candidates are never returned, so
false means none was accepted. rzv2h_get_pll_pars() becomes a wrapper
passing a NULL validator, so its behaviour is unchanged.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
 drivers/clk/renesas/rzv2h-cpg-lib.c | 61 +++++++++++++++++++++++++----
 include/linux/clk/renesas.h         | 22 +++++++++++
 2 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/renesas/rzv2h-cpg-lib.c b/drivers/clk/renesas/rzv2h-cpg-lib.c
index 4b59bf60edb0..a49add2f2fc3 100644
--- a/drivers/clk/renesas/rzv2h-cpg-lib.c
+++ b/drivers/clk/renesas/rzv2h-cpg-lib.c
@@ -62,31 +62,47 @@ struct rzv2h_pll_div_pars rzv2h_cpg_get_cached_pll_pars(unsigned int dsi_instanc
 }
 
 /**
- * rzv2h_cpg_get_pll_pars - Finds the best combination of PLL parameters
- * for a given frequency.
+ * rzv2h_cpg_get_pll_pars_validate - Finds a combination of PLL parameters
+ * for a given frequency, optionally accepted by a validation callback.
  *
  * @limits: Pointer to the structure containing the limits for the PLL parameters
- * @pars: Pointer to the structure where the best calculated PLL parameters values
+ * @pars: Pointer to the structure where the calculated PLL parameters values
  * will be stored
  * @freq_millihz: Target output frequency in millihertz
+ * @validator: Pointer to a structure containing a validation callback and
+ * context, or NULL
  *
- * This function calculates the best set of PLL parameters (M, K, P, S) to achieve
+ * This function calculates a set of PLL parameters (M, K, P, S) to achieve
  * the desired frequency.
  * There is no direct formula to calculate the PLL parameters, as it's an open
  * system of equations, therefore this function uses an iterative approach to
- * determine the best solution. The best solution is one that minimizes the error
- * (desired frequency - actual frequency).
+ * determine the solution.
+ *
+ * When validator is NULL, the function searches for the solution that minimizes
+ * the error (desired frequency - actual frequency) and returns the best match.
+ *
+ * When validator is provided, the callback is invoked for every candidate in
+ * search order and the first one it accepts is returned, even if it is not the
+ * one with the smallest error. Candidates the callback rejects are never
+ * returned, so false is returned when none is accepted. This allows additional
+ * constraints beyond frequency matching to be satisfied (e.g., derived PLL
+ * parameters must also meet certain criteria). The callback runs once per
+ * candidate, so it must be cheap and must not sleep.
  *
  * Return: true if a valid set of parameters values is found, false otherwise.
  */
-bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
-			    struct rzv2h_pll_pars *pars, u64 freq_millihz)
+bool rzv2h_cpg_get_pll_pars_validate(const struct rzv2h_pll_limits *limits,
+				     struct rzv2h_pll_pars *pars, u64 freq_millihz,
+				     const struct rzv2h_pll_validator *validator)
 {
 	unsigned long input_fref = limits->input_fref ?: (24 * MEGA);
 	u64 fout_min_millihz = mul_u32_u32(limits->fout.min, MILLI);
 	u64 fout_max_millihz = mul_u32_u32(limits->fout.max, MILLI);
 	struct rzv2h_pll_pars p, best;
 
+	if (WARN_ON(validator && !validator->validate))
+		return false;
+
 	if (freq_millihz > fout_max_millihz ||
 	    freq_millihz < fout_min_millihz)
 		return false;
@@ -191,6 +207,15 @@ bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
 				p.error_millihz = freq_millihz - output;
 				p.freq_millihz = output;
 
+				/* Take the first set the caller accepts */
+				if (validator) {
+					if (validator->validate(&p, validator->context)) {
+						*pars = p;
+						return true;
+					}
+					continue;
+				}
+
 				/* If an exact match is found, return immediately */
 				if (p.error_millihz == 0) {
 					*pars = p;
@@ -211,6 +236,26 @@ bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
 	*pars = best;
 	return true;
 }
+EXPORT_SYMBOL_NS_GPL(rzv2h_cpg_get_pll_pars_validate, "RZV2H_CPG");
+
+/**
+ * rzv2h_cpg_get_pll_pars - Finds the best combination of PLL parameters
+ * for a given frequency.
+ *
+ * @limits: Pointer to the structure containing the limits for the PLL parameters
+ * @pars: Pointer to the structure where the best calculated PLL parameters values
+ * will be stored
+ * @freq_millihz: Target output frequency in millihertz
+ *
+ * See rzv2h_cpg_get_pll_pars_validate() for more details.
+ *
+ * Return: true if a valid set of parameters values is found, false otherwise.
+ */
+bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
+			    struct rzv2h_pll_pars *pars, u64 freq_millihz)
+{
+	return rzv2h_cpg_get_pll_pars_validate(limits, pars, freq_millihz, NULL);
+}
 EXPORT_SYMBOL_NS_GPL(rzv2h_cpg_get_pll_pars, "RZV2H_CPG");
 
 /*
diff --git a/include/linux/clk/renesas.h b/include/linux/clk/renesas.h
index c1582ed9bf69..c846d926020c 100644
--- a/include/linux/clk/renesas.h
+++ b/include/linux/clk/renesas.h
@@ -192,10 +192,25 @@ struct rzv2h_pll_div_pars {
 		.k = { .min = -32768, .max = 32767 },			\
 	}								\
 
+/**
+ * struct rzv2h_pll_validator - Callback structure for custom PLL parameter validation
+ *
+ * @validate: Validation function that checks if the computed PLL parameters are acceptable
+ * @context: Opaque pointer to any data needed by the validation function
+ */
+struct rzv2h_pll_validator {
+	bool (*validate)(const struct rzv2h_pll_pars *pars, void *context);
+	void *context;
+};
+
 #ifdef CONFIG_CLK_RZV2H_CPG_LIB
 bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
 			    struct rzv2h_pll_pars *pars, u64 freq_millihz);
 
+bool rzv2h_cpg_get_pll_pars_validate(const struct rzv2h_pll_limits *limits,
+				     struct rzv2h_pll_pars *pars, u64 freq_millihz,
+				     const struct rzv2h_pll_validator *validator);
+
 bool rzv2h_cpg_get_pll_divs_pars(const struct rzv2h_pll_limits *limits,
 				 struct rzv2h_pll_div_pars *pars,
 				 const u8 *table, u8 table_size, u64 freq_millihz);
@@ -210,6 +225,13 @@ static inline bool rzv2h_cpg_get_pll_pars(const struct rzv2h_pll_limits *limits,
 	return false;
 }
 
+static inline bool rzv2h_cpg_get_pll_pars_validate(const struct rzv2h_pll_limits *limits,
+						   struct rzv2h_pll_pars *pars, u64 freq_millihz,
+						   const struct rzv2h_pll_validator *validator)
+{
+	return false;
+}
+
 static inline bool rzv2h_cpg_get_pll_divs_pars(const struct rzv2h_pll_limits *limits,
 					       struct rzv2h_pll_div_pars *pars,
 					       const u8 *table, u8 table_size,
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] drm: renesas: rz-du: mipi_dsi: Improve DSI PLL parameter selection and cache results
  2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
  2026-11-03 17:20 ` [PATCH 1/4] clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider parameters Prabhakar
  2026-11-03 17:20 ` [PATCH 2/4] clk: renesas: rzv2h-cpg: Add validation hook to PLL parameter search Prabhakar
@ 2026-11-03 17:20 ` Prabhakar
  2026-11-03 17:20 ` [PATCH 4/4] drm: renesas: rz-du: mipi_dsi: Add fallback CPG PLLDSI parameter search Prabhakar
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Prabhakar @ 2026-11-03 17:20 UTC (permalink / raw)
  To: Geert Uytterhoeven, Stephen Boyd, Brian Masney, Jerome Brunet,
	Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: linux-renesas-soc, linux-clk, linux-kernel, dri-devel, Prabhakar,
	Fabrizio Castro, Lad Prabhakar, Tommaso Merciai

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Mode validation searched the divider table once, kept the best CPG match
and only then checked the DSI PLL. A divider losing on CPG error alone
was never tried against it, so reachable modes were rejected.

Evaluate each divider on its own and keep the one with the smallest DSI
PLL error, handing it to the CPG via rzv2h_cpg_cache_pll_pars(). The
search also takes the PLLDSI instance as an argument and records it,
walking the instances described by the new num_limits field.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
 .../gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c    | 87 ++++++++++++++-----
 1 file changed, 66 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
index 5b257f5adf06..682bbb339bef 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
@@ -12,6 +12,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
+#include <linux/limits.h>
 #include <linux/math.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -55,6 +56,7 @@ struct rzg2l_mipi_dsi_hw_info {
 		const struct rzv2h_pll_limits **limits;
 		const u8 *table;
 		const u8 table_size;
+		const u8 num_limits;
 	} cpg_plldsi;
 	const struct rzg2l_mipi_dsi_timings *dsi_global_timings;
 	unsigned int num_dsi_global_timings;
@@ -69,7 +71,9 @@ struct rzg2l_mipi_dsi_hw_info {
 
 struct rzv2h_dsi_mode_calc {
 	unsigned long mode_freq_khz;
+	unsigned int pll_instance;
 	struct rzv2h_pll_pars dsi_parameters;
+	struct rzv2h_pll_div_pars cpg_dsi_div_parameters;
 };
 
 struct rzg2l_mipi_dsi {
@@ -671,43 +675,83 @@ static int rzg2l_dphy_conf_clks(struct rzg2l_mipi_dsi *dsi, unsigned long mode_f
 	return 0;
 }
 
-static unsigned int rzv2h_dphy_mode_clk_check(struct rzg2l_mipi_dsi *dsi,
-					      unsigned long mode_freq)
+static unsigned int rzv2h_dphy_check_instance(struct rzg2l_mipi_dsi *dsi,
+					      unsigned long mode_freq,
+					      unsigned int pll_instance)
 {
 	u64 hsfreq_millihz, mode_freq_hz, mode_freq_millihz;
+	struct rzv2h_pll_div_pars best_cpg_dsi_parameters;
 	struct rzv2h_pll_div_pars cpg_dsi_parameters;
+	struct rzv2h_pll_pars best_dsi_parameters;
 	struct rzv2h_pll_pars dsi_parameters;
+	bool found_valid_parameters = false;
 	bool parameters_found;
-	unsigned int bpp;
+	unsigned int bpp, i;
 
+	best_dsi_parameters.error_millihz = S64_MAX;
 	bpp = mipi_dsi_pixel_format_to_bpp(dsi->format);
 	mode_freq_hz = mul_u32_u32(mode_freq, KILO);
 	mode_freq_millihz = mode_freq_hz * MILLI;
-	parameters_found =
-		rzv2h_get_pll_divs_pars(dsi->info->cpg_plldsi.limits[0],
-					&cpg_dsi_parameters,
-					dsi->info->cpg_plldsi.table,
-					dsi->info->cpg_plldsi.table_size,
-					mode_freq_millihz);
-	if (!parameters_found)
-		return MODE_CLOCK_RANGE;
-
-	hsfreq_millihz = DIV_ROUND_CLOSEST_ULL(cpg_dsi_parameters.div.freq_millihz * bpp,
-					       dsi->lanes);
-	parameters_found = rzv2h_get_pll_pars(&rzv2h_plldsi_div_limits,
-					      &dsi_parameters, hsfreq_millihz);
-	if (!parameters_found)
-		return MODE_CLOCK_RANGE;
+	for (i = 0; i < dsi->info->cpg_plldsi.table_size; i++) {
+		parameters_found =
+			rzv2h_get_pll_divs_pars(dsi->info->cpg_plldsi.limits[pll_instance],
+						&cpg_dsi_parameters,
+						&dsi->info->cpg_plldsi.table[i], 1,
+						mode_freq_millihz);
+		if (!parameters_found)
+			continue;
+
+		hsfreq_millihz = DIV_ROUND_CLOSEST_ULL(cpg_dsi_parameters.div.freq_millihz * bpp,
+						       dsi->lanes);
+		parameters_found = rzv2h_get_pll_pars(&rzv2h_plldsi_div_limits,
+						      &dsi_parameters, hsfreq_millihz);
+		if (!parameters_found)
+			continue;
+
+		if (abs(dsi_parameters.error_millihz) >= 500)
+			continue;
+
+		if (abs(best_dsi_parameters.error_millihz) > abs(dsi_parameters.error_millihz)) {
+			best_cpg_dsi_parameters = cpg_dsi_parameters;
+			best_dsi_parameters = dsi_parameters;
+			found_valid_parameters = true;
+		}
+	}
 
-	if (abs(dsi_parameters.error_millihz) >= 500)
+	if (!found_valid_parameters)
 		return MODE_CLOCK_RANGE;
 
-	memcpy(&dsi->mode_calc.dsi_parameters, &dsi_parameters, sizeof(dsi_parameters));
+	memcpy(&dsi->mode_calc.dsi_parameters, &best_dsi_parameters,
+	       sizeof(best_dsi_parameters));
+	memcpy(&dsi->mode_calc.cpg_dsi_div_parameters, &best_cpg_dsi_parameters,
+	       sizeof(best_cpg_dsi_parameters));
 	dsi->mode_calc.mode_freq_khz = mode_freq;
+	dsi->mode_calc.pll_instance = pll_instance;
+
+	rzv2h_cpg_cache_pll_pars(best_cpg_dsi_parameters, pll_instance);
 
 	return MODE_OK;
 }
 
+static unsigned int rzv2h_dphy_mode_clk_check(struct rzg2l_mipi_dsi *dsi,
+					      unsigned long mode_freq)
+{
+	bool found = false;
+	unsigned int i;
+
+	/*
+	 * Check every instance instead of stopping at the first match, as
+	 * rzv2h_dphy_check_instance() hands the parameters it computes over to
+	 * the CPG, which needs them for whichever PLLDSI ends up feeding the
+	 * encoder.
+	 */
+	for (i = 0; i < dsi->info->cpg_plldsi.num_limits; i++)
+		if (rzv2h_dphy_check_instance(dsi, mode_freq, i) == MODE_OK)
+			found = true;
+
+	return found ? MODE_OK : MODE_CLOCK_RANGE;
+}
+
 static int rzv2h_dphy_conf_clks(struct rzg2l_mipi_dsi *dsi, unsigned long mode_freq,
 				u64 *hsfreq_millihz)
 {
@@ -715,7 +759,7 @@ static int rzv2h_dphy_conf_clks(struct rzg2l_mipi_dsi *dsi, unsigned long mode_f
 	unsigned long status;
 
 	if (dsi->mode_calc.mode_freq_khz != mode_freq) {
-		status = rzv2h_dphy_mode_clk_check(dsi, mode_freq);
+		status = rzv2h_dphy_check_instance(dsi, mode_freq, 0);
 		if (status != MODE_OK) {
 			dev_err(dsi->dev, "No PLL parameters found for mode clk %lu\n",
 				mode_freq);
@@ -1647,6 +1691,7 @@ static const struct rzg2l_mipi_dsi_hw_info rzv2h_mipi_dsi_info = {
 	.dphy_mode_clk_check = rzv2h_dphy_mode_clk_check,
 	.dphy_conf_clks = rzv2h_dphy_conf_clks,
 	.cpg_plldsi.limits = rzv2h_plldsi_limits,
+	.cpg_plldsi.num_limits = ARRAY_SIZE(rzv2h_plldsi_limits),
 	.cpg_plldsi.table = rzv2h_cpg_div_table,
 	.cpg_plldsi.table_size = ARRAY_SIZE(rzv2h_cpg_div_table),
 	.phy_reg_offset = 0x10000,
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] drm: renesas: rz-du: mipi_dsi: Add fallback CPG PLLDSI parameter search
  2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
                   ` (2 preceding siblings ...)
  2026-11-03 17:20 ` [PATCH 3/4] drm: renesas: rz-du: mipi_dsi: Improve DSI PLL parameter selection and cache results Prabhakar
@ 2026-11-03 17:20 ` Prabhakar
  2026-12-04  9:58 ` [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Tommaso Merciai
  2026-12-04 10:05 ` Biju Das
  5 siblings, 0 replies; 7+ messages in thread
From: Prabhakar @ 2026-11-03 17:20 UTC (permalink / raw)
  To: Geert Uytterhoeven, Stephen Boyd, Brian Masney, Jerome Brunet,
	Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: linux-renesas-soc, linux-clk, linux-kernel, dri-devel, Prabhakar,
	Fabrizio Castro, Lad Prabhakar, Tommaso Merciai

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

For each PLLDSI divider, rzv2h_dphy_check_instance() only considers the
CPG PLLDSI parameters with the smallest frequency error. If they do not
lead to a DSI PLL setting less than 0.5 Hz off the required HS clock,
the divider is skipped, even though a CPG setting with a slightly larger
error could work. Modes such as <mode, lanes, format> are therefore
rejected on RZ/V2H(P), RZ/V2N and RZ/G3E.

If no divider gives a usable pair, search again with
rzv2h_cpg_get_pll_pars_validate(), accepting CPG candidates up to 50 Hz
off the target whose DSI PLL setting is less than 0.5 Hz off the HS clock.
The first accepted pair is used, so the pixel clock may be slightly less
accurate, but the mode can be driven.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
 .../gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c    | 85 ++++++++++++++++++-
 1 file changed, 83 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
index 682bbb339bef..c23c7f43a560 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
@@ -42,6 +42,9 @@ MODULE_IMPORT_NS("RZV2H_CPG");
 #define RZ_MIPI_DSI_FEATURE_16BPP	BIT(0)
 #define RZ_MIPI_DSI_FEATURE_PWRRDY	BIT(1)
 
+#define RZV2H_DSI_PLL_MAX_ERR_MILLIHZ		500
+#define RZV2H_CPG_PLLDSI_MAX_ERR_MILLIHZ	(50 * MILLI)
+
 struct rzg2l_mipi_dsi;
 
 struct rzg2l_mipi_dsi_hw_info {
@@ -76,6 +79,13 @@ struct rzv2h_dsi_mode_calc {
 	struct rzv2h_pll_div_pars cpg_dsi_div_parameters;
 };
 
+struct rzv2h_dsi_validator_context {
+	struct rzv2h_pll_pars *dsi_pars;
+	unsigned int lanes;
+	unsigned int bpp;
+	u8 base_divider;
+};
+
 struct rzg2l_mipi_dsi {
 	struct device *dev;
 	void __iomem *mmio;
@@ -675,6 +685,67 @@ static int rzg2l_dphy_conf_clks(struct rzg2l_mipi_dsi *dsi, unsigned long mode_f
 	return 0;
 }
 
+static bool rzv2h_dsi_validate_pll_pars(const struct rzv2h_pll_pars *pars, void *context)
+{
+	struct rzv2h_dsi_validator_context *ctx = context;
+	u64 hsfreq_millihz;
+
+	/* Check error threshold for CPG PLL DSI */
+	if (abs(pars->error_millihz) > RZV2H_CPG_PLLDSI_MAX_ERR_MILLIHZ)
+		return false;
+
+	/* Calculate the required DSI frequency */
+	hsfreq_millihz = DIV_U64_ROUND_CLOSEST(pars->freq_millihz, ctx->base_divider);
+	hsfreq_millihz = DIV_ROUND_CLOSEST_ULL(hsfreq_millihz * ctx->bpp, ctx->lanes);
+
+	/* Find DSI PLL parameters */
+	if (!rzv2h_get_pll_pars(&rzv2h_plldsi_div_limits, ctx->dsi_pars, hsfreq_millihz))
+		return false;
+
+	/* Check DSI error threshold */
+	if (abs(ctx->dsi_pars->error_millihz) >= RZV2H_DSI_PLL_MAX_ERR_MILLIHZ)
+		return false;
+
+	return true;
+}
+
+static bool rzv2h_dsi_get_pll_divs_pars(const struct rzv2h_pll_limits *limits,
+					struct rzv2h_pll_div_pars *pars,
+					const u8 *table, u8 table_size, u64 freq_millihz,
+					unsigned int bpp, unsigned int lanes,
+					struct rzv2h_pll_pars *dsi_pars)
+{
+	struct rzv2h_pll_pars temp_dsi_pars;
+	struct rzv2h_dsi_validator_context ctx = {
+		.dsi_pars = &temp_dsi_pars,
+		.lanes = lanes,
+		.bpp = bpp,
+	};
+	struct rzv2h_pll_validator validator = {
+		.validate = rzv2h_dsi_validate_pll_pars,
+		.context = &ctx,
+	};
+	struct rzv2h_pll_div_pars p;
+
+	for (unsigned int i = 0; i < table_size; i++) {
+		ctx.base_divider = table[i];
+
+		if (!rzv2h_cpg_get_pll_pars_validate(limits, &p.pll,
+						     freq_millihz * table[i], &validator))
+			continue;
+
+		p.div.divider_value = table[i];
+		p.div.freq_millihz = DIV_U64_ROUND_CLOSEST(p.pll.freq_millihz, table[i]);
+		p.div.error_millihz = freq_millihz - p.div.freq_millihz;
+
+		*dsi_pars = temp_dsi_pars;
+		*pars = p;
+		return true;
+	}
+
+	return false;
+}
+
 static unsigned int rzv2h_dphy_check_instance(struct rzg2l_mipi_dsi *dsi,
 					      unsigned long mode_freq,
 					      unsigned int pll_instance)
@@ -718,8 +789,18 @@ static unsigned int rzv2h_dphy_check_instance(struct rzg2l_mipi_dsi *dsi,
 		}
 	}
 
-	if (!found_valid_parameters)
-		return MODE_CLOCK_RANGE;
+	if (!found_valid_parameters) {
+		parameters_found =
+			rzv2h_dsi_get_pll_divs_pars(dsi->info->cpg_plldsi.limits[pll_instance],
+						    &best_cpg_dsi_parameters,
+						    dsi->info->cpg_plldsi.table,
+						    dsi->info->cpg_plldsi.table_size,
+						    mode_freq_millihz,
+						    bpp, dsi->lanes,
+						    &best_dsi_parameters);
+		if (!parameters_found)
+			return MODE_CLOCK_RANGE;
+	}
 
 	memcpy(&dsi->mode_calc.dsi_parameters, &best_dsi_parameters,
 	       sizeof(best_dsi_parameters));
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection
  2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
                   ` (3 preceding siblings ...)
  2026-11-03 17:20 ` [PATCH 4/4] drm: renesas: rz-du: mipi_dsi: Add fallback CPG PLLDSI parameter search Prabhakar
@ 2026-12-04  9:58 ` Tommaso Merciai
  2026-12-04 10:05 ` Biju Das
  5 siblings, 0 replies; 7+ messages in thread
From: Tommaso Merciai @ 2026-12-04  9:58 UTC (permalink / raw)
  To: Prabhakar
  Cc: Geert Uytterhoeven, Stephen Boyd, Brian Masney, Jerome Brunet,
	Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, linux-renesas-soc, linux-clk,
	linux-kernel, dri-devel, Prabhakar, Fabrizio Castro,
	Lad Prabhakar

Hi Prabhakar,
Thanks for your series.

On Tue, Nov 03, 2026 at 05:20:53PM +0000, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> Hi all,
> 
> On RZ/V2H(P) and RZ/V2N the DSI HS clock is derived from the pixel clock
> produced by the CPG PLLDSI and its divider (HS clock = pixel clock *
> bpp / lanes), and the PLL in the DSI block has to reproduce it to within
> 0.5 Hz. A display mode is usable only if a single set of CPG parameters
> satisfies both the CPG and the DSI PLL constraints, but the two were
> checked one after the other instead of together:
> 
>  - Mode validation took the CPG parameters with the smallest frequency
>    error and only then checked the DSI PLL. A divider that lost on CPG
>    error alone was never tried against the DSI PLL, so modes were
>    rejected although another divider or PLL setting would have worked.
>  - The PLLDSI divider's .determine_rate() runs its own search when the
>    clock is set, so it can pick parameters other than the ones the DSI
>    driver validated.
> 
> The first two patches add the clock-side support, the last two make the
> DSI driver use it:
> 
>  1. Let the DSI driver cache the CPG divider parameters it validated,
>     per PLLDSI instance, and have .determine_rate() reuse them when the
>     requested rate matches.
>  2. Add rzv2h_cpg_get_pll_pars_validate(), which offers each candidate
>     to a callback and returns the first one it accepts.
>     rzv2h_get_pll_pars() becomes a wrapper passing a NULL validator, so
>     existing callers are unchanged.
>  3. Evaluate every divider against the DSI PLL limits, keep the one with
>     the smallest DSI PLL error and hand it to the CPG using the cache
>     from patch 1.
>  4. If no divider gives a usable pair, search again using patch 2 and
>     take the first CPG candidate that is at most 50 Hz off at the PLLDSI
>     output and gives a DSI HS clock error below 0.5 Hz. 50 Hz is at most
>     2 ppm of the 25 MHz minimum PLLDSI output, so the pixel clock error
>     stays negligible.
> 
> The cache in patch 1 is indexed by PLLDSI instance and shared by all CPG
> instances, as the DSI driver only knows which instance it targets. If
> there is a cleaner way to hand the parameters over to the CPG, I am
> happy to rework it.
> 
> Testing
> -------
> "modetest -c" on [RZ/V2H EVK] (DSI -> ADV7535 -> HDMI, 4 lanes,
> [monitor]) lists 27 modes instead of 21. No mode is lost, and these are
> the newly usable ones:
> 
>   mode        refresh   pixel clock
>   1920x1080   59.94 Hz  148352 kHz
>   1280x720    59.94 Hz   74176 kHz
>   720x480     60.00 Hz   27027 kHz
>   640x480     60.00 Hz   25200 kHz
>   640x480     59.94 Hz   25175 kHz
>   720x400     70.08 Hz   28320 kHz
> 
> Dependencies
> ------------
> Based on next-20261102 plus two patches from Tommaso that are not in
> that tree:
> 
>   [1] clk: renesas: rzv2h: Forward PLLDSI mux rate requests to the parent
>   [2] clk: renesas: rzv2h: Report the DSI duty cycle from the LVDS divider
> 
> [1] https://lore.kernel.org/all/20261029-tm-ssgrlpcsrc-2083-v5-clk-duty-fixes-v1-1-47f23de6bdb1@bp.renesas.com/
> [2] https://lore.kernel.org/all/20261029-tm-ssgrlpcsrc-2083-v5-clk-duty-fixes-v1-2-47f23de6bdb1@bp.renesas.com/
> 
> Geert, Biju: I would suggest taking everything via renesas-clk
> with an Ack from the DRM side, or providing an immutable branch with
> patches 1-2 for the DRM tree. Please let me know which you prefer.

I tested this series on my RZ/G3E display tree, where I have also DSI
support. Test was done using the following display pipeline:

	DU0 | DU1 -> DSI

All 29 modes of my display are working fine.
Here my results:

=== CRTC 45 (index 0, profile dsi)  .plldsi0 -> .plldsi0_csdiv -> .smux2_dsi0_clk -> dsi_0_vclk1, DU dot clock lcdc_0_clk_d ===

IDX MODE               REQUESTED[Hz]  plldsi0[Hz]  plldsi0_csdiv[Hz]  smux2_dsi0_clk[Hz]      dsi_0_vclk1[Hz] ERROR[Hz]  RESULT
  0 1920x1080-60.00        148500000    297000000          148500000           148500000            148500000         0    OK
  1 1920x1080-59.94        148352000    890111999          148352000           148352000            148352000         0    OK
  2 1920x1080-50.00        148500000    297000000          148500000           148500000            148500000         0    OK
  3 1680x1050-59.88        119000000    238000000          119000000           119000000            119000000         0    OK
  4 1600x900-60.00         108000000    216000000          108000000           108000000            108000000         0    OK
  5 1280x1024-75.02        135000000    270000000          135000000           135000000            135000000         0    OK
  6 1280x1024-60.02        108000000    216000000          108000000           108000000            108000000         0    OK
  7 1440x900-59.90          88750000    177500000           88750000            88750000             88750000         0    OK
  8 1280x800-59.91          71000000    142000000           71000000            71000000             71000000         0    OK
  9 1152x864-75.00         108000000    216000000          108000000           108000000            108000000         0    OK
10 1280x720-60.00          74250000    148500000           74250000            74250000             74250000          0    OK
11 1280x720-59.94          74176000    445056000           74176000            74176000             74176000          0    OK
12 1280x720-50.00          74250000    148500000           74250000            74250000             74250000          0    OK
13 1024x768-75.03          78750000    157500000           78750000            78750000             78750000          0    OK
14 1024x768-70.07          75000000    150000000           75000000            75000000             75000000          0    OK
15 1024x768-60.00          65000000    130000000           65000000            65000000             65000000          0    OK
16 832x624-74.55           57284000    114568001           57284001            57284001             57284001          1    OK
17 800x600-75.00           49500000     99000000           49500000            49500000             49500000          0    OK
18 800x600-72.19           50000000    100000000           50000000            50000000             50000000          0    OK
19 800x600-60.32           40000000     80000000           40000000            40000000             40000000          0    OK
20 800x600-56.25           36000000     72000000           36000000            36000000             36000000          0    OK
21 720x576-50.00           27000000     54000000           27000000            27000000             27000000          0    OK
22 720x480-60.00           27027000     54054001           27027001            27027001             27027001          1    OK
23 720x480-59.94           27000000     54000000           27000000            27000000             27000000          0    OK
24 640x480-75.00           31500000     63000000           31500000            31500000             31500000          0    OK
25 640x480-72.81           31500000     63000000           31500000            31500000             31500000          0    OK
26 640x480-66.67           30240000     60479999           30240000            30240000             30240000          0    OK
27 640x480-60.00           25200000    352799988           25199999            25199999             25199999          1    OK
28 640x480-59.94           25175000     50349998           25174999            25174999             25174999          1    OK
29 720x400-70.08           28320000    169919998           28320000            28320000             28320000          0    OK
lcdc_0_clk_d enable_count:

=== CRTC 60 (index 1, profile dsi)  .plldsi1 -> .plldsi1_csdiv -> .smux2_dsi1_clk -> dsi_0_vclk2, DU dot clock lcdc_1_clk_d ===

IDX MODE               REQUESTED[Hz]  plldsi1[Hz]  plldsi1_csdiv[Hz]  smux2_dsi1_clk[Hz]      dsi_0_vclk2[Hz] ERROR[Hz]  RESULT
  0 1920x1080-60.00        148500000    297000000          148500000           148500000            148500000         0  OK
  1 1920x1080-59.94        148352000    296704010          148352005           148352005            148352005         5  OK
  2 1920x1080-50.00        148500000    297000000          148500000           148500000            148500000         0  OK
  3 1680x1050-59.88        119000000    238000000          119000000           119000000            119000000         0  OK
  4 1600x900-60.00         108000000    216000000          108000000           108000000            108000000         0  OK
  5 1280x1024-75.02        135000000    270000000          135000000           135000000            135000000         0  OK
  6 1280x1024-60.02        108000000    216000000          108000000           108000000            108000000         0  OK
  7 1440x900-59.90          88750000    177500000           88750000            88750000             88750000         0  OK
  8 1280x800-59.91          71000000    142000000           71000000            71000000             71000000         0  OK
  9 1152x864-75.00         108000000    216000000          108000000           108000000            108000000         0  OK
10 1280x720-60.00          74250000    148500000           74250000            74250000             74250000          0  OK
11 1280x720-59.94          74176000    445056000           74176000            74176000             74176000          0  OK
12 1280x720-50.00          74250000    148500000           74250000            74250000             74250000          0  OK
13 1024x768-75.03          78750000    157500000           78750000            78750000             78750000          0  OK
14 1024x768-70.07          75000000    150000000           75000000            75000000             75000000          0  OK
15 1024x768-60.00          65000000    130000000           65000000            65000000             65000000          0  OK
16 832x624-74.55           57284000    114568001           57284001            57284001             57284001          1  OK
17 800x600-75.00           49500000     99000000           49500000            49500000             49500000          0  OK
18 800x600-72.19           50000000    100000000           50000000            50000000             50000000          0  OK
19 800x600-60.32           40000000     80000000           40000000            40000000             40000000          0  OK
20 800x600-56.25           36000000     72000000           36000000            36000000             36000000          0  OK
21 720x576-50.00           27000000     54000000           27000000            27000000             27000000          0  OK
22 720x480-60.00           27027000     54054001           27027001            27027001             27027001          1  OK
23 720x480-59.94           27000000     54000000           27000000            27000000             27000000          0  OK
24 640x480-75.00           31500000     63000000           31500000            31500000             31500000          0  OK
25 640x480-72.81           31500000     63000000           31500000            31500000             31500000          0  OK
26 640x480-66.67           30240000     60479999           30240000            30240000             30240000          0  OK
27 640x480-60.00           25200000    352799988           25199999            25199999             25199999          1  OK
28 640x480-59.94           25175000     50349998           25174999            25174999             25174999          1  OK
29 720x400-70.08           28320000    169919998           28320000            28320000             28320000          0  OK

For all the series: 

Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>

Kind regards,
Tommaso

> 
> Cheers,
> Prabhakar
> 
> Lad Prabhakar (4):
>   clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider
>     parameters
>   clk: renesas: rzv2h-cpg: Add validation hook to PLL parameter search
>   drm: renesas: rz-du: mipi_dsi: Improve DSI PLL parameter selection and
>     cache results
>   drm: renesas: rz-du: mipi_dsi: Add fallback CPG PLLDSI parameter
>     search
> 
>  drivers/clk/renesas/rzv2h-cpg-lib.c           | 109 ++++++++++-
>  drivers/clk/renesas/rzv2h-cpg.c               |  15 +-
>  .../gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c    | 174 +++++++++++++++---
>  include/linux/clk/renesas.h                   |  38 ++++
>  4 files changed, 300 insertions(+), 36 deletions(-)
> 
> -- 
> 2.56.0
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection
  2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
                   ` (4 preceding siblings ...)
  2026-12-04  9:58 ` [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Tommaso Merciai
@ 2026-12-04 10:05 ` Biju Das
  5 siblings, 0 replies; 7+ messages in thread
From: Biju Das @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Prabhakar, Geert Uytterhoeven, Stephen Boyd, Brian Masney,
	Jerome Brunet, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Prabhakar, Fabrizio Castro, Prabhakar Mahadev Lad

Hi,

> -----Original Message-----
> From: Prabhakar <prabhakar.csengg@gmail.com>
> Sent: 03 November 2026 17:21
> Subject: [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection
> 
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> Hi all,
> 
> On RZ/V2H(P) and RZ/V2N the DSI HS clock is derived from the pixel clock produced by the CPG PLLDSI
> and its divider (HS clock = pixel clock * bpp / lanes), and the PLL in the DSI block has to reproduce
> it to within
> 0.5 Hz. A display mode is usable only if a single set of CPG parameters satisfies both the CPG and the
> DSI PLL constraints, but the two were checked one after the other instead of together:
> 
>  - Mode validation took the CPG parameters with the smallest frequency
>    error and only then checked the DSI PLL. A divider that lost on CPG
>    error alone was never tried against the DSI PLL, so modes were
>    rejected although another divider or PLL setting would have worked.
>  - The PLLDSI divider's .determine_rate() runs its own search when the
>    clock is set, so it can pick parameters other than the ones the DSI
>    driver validated.
> 
> The first two patches add the clock-side support, the last two make the DSI driver use it:
> 
>  1. Let the DSI driver cache the CPG divider parameters it validated,
>     per PLLDSI instance, and have .determine_rate() reuse them when the
>     requested rate matches.
>  2. Add rzv2h_cpg_get_pll_pars_validate(), which offers each candidate
>     to a callback and returns the first one it accepts.
>     rzv2h_get_pll_pars() becomes a wrapper passing a NULL validator, so
>     existing callers are unchanged.
>  3. Evaluate every divider against the DSI PLL limits, keep the one with
>     the smallest DSI PLL error and hand it to the CPG using the cache
>     from patch 1.
>  4. If no divider gives a usable pair, search again using patch 2 and
>     take the first CPG candidate that is at most 50 Hz off at the PLLDSI
>     output and gives a DSI HS clock error below 0.5 Hz. 50 Hz is at most
>     2 ppm of the 25 MHz minimum PLLDSI output, so the pixel clock error
>     stays negligible.
> 
> The cache in patch 1 is indexed by PLLDSI instance and shared by all CPG instances, as the DSI driver
> only knows which instance it targets. If there is a cleaner way to hand the parameters over to the
> CPG, I am happy to rework it.
> 
> Testing
> -------
> "modetest -c" on [RZ/V2H EVK] (DSI -> ADV7535 -> HDMI, 4 lanes,
> [monitor]) lists 27 modes instead of 21. No mode is lost, and these are the newly usable ones:
> 
>   mode        refresh   pixel clock
>   1920x1080   59.94 Hz  148352 kHz
>   1280x720    59.94 Hz   74176 kHz
>   720x480     60.00 Hz   27027 kHz
>   640x480     60.00 Hz   25200 kHz
>   640x480     59.94 Hz   25175 kHz
>   720x400     70.08 Hz   28320 kHz
> 
> Dependencies
> ------------
> Based on next-20261102 plus two patches from Tommaso that are not in that tree:
> 
>   [1] clk: renesas: rzv2h: Forward PLLDSI mux rate requests to the parent
>   [2] clk: renesas: rzv2h: Report the DSI duty cycle from the LVDS divider
> 
> [1] https://lore.kernel.org/all/20261029-tm-ssgrlpcsrc-2083-v5-clk-duty-fixes-v1-1-
> 47f23de6bdb1@bp.renesas.com/
> [2] https://lore.kernel.org/all/20261029-tm-ssgrlpcsrc-2083-v5-clk-duty-fixes-v1-2-
> 47f23de6bdb1@bp.renesas.com/
> 
> Geert, Biju: I would suggest taking everything via renesas-clk with an Ack from the DRM side, or
> providing an immutable branch with patches 1-2 for the DRM tree. Please let me know which you prefer.

Acked-by: Biju Das <biju.das.jz@bp.renesas.com>

Cheers,
Biju

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 10:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-03 17:20 [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Prabhakar
2026-11-03 17:20 ` [PATCH 1/4] clk: renesas: rzv2h-cpg: Allow MIPI DSI to reuse PLL divider parameters Prabhakar
2026-11-03 17:20 ` [PATCH 2/4] clk: renesas: rzv2h-cpg: Add validation hook to PLL parameter search Prabhakar
2026-11-03 17:20 ` [PATCH 3/4] drm: renesas: rz-du: mipi_dsi: Improve DSI PLL parameter selection and cache results Prabhakar
2026-11-03 17:20 ` [PATCH 4/4] drm: renesas: rz-du: mipi_dsi: Add fallback CPG PLLDSI parameter search Prabhakar
2026-12-04  9:58 ` [PATCH 0/4] clk/drm: renesas: Improve RZ/V2H(P) MIPI DSI PLL parameter selection Tommaso Merciai
2026-12-04 10:05 ` Biju Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox