From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Marek Vasut <marek.vasut+renesas@mailbox.org>
Cc: dri-devel@lists.freedesktop.org,
kernel test robot <lkp@intel.com>,
David Airlie <airlied@gmail.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Magnus Damm <magnus.damm@gmail.com>,
Maxime Ripard <mripard@kernel.org>,
Simona Vetter <simona@ffwll.ch>,
Thomas Zimmermann <tzimmermann@suse.de>,
Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>,
linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v2] drm/rcar-du: dsi: Clean up VCLK divider calculation
Date: Fri, 23 Jan 2026 17:22:35 +0200 [thread overview]
Message-ID: <20260123152235.GJ215800@killaraus> (raw)
In-Reply-To: <20260105175250.64309-1-marek.vasut+renesas@mailbox.org>
Hi Marek,
Thank you for the patch.
On Mon, Jan 05, 2026 at 06:52:04PM +0100, Marek Vasut wrote:
> Currently, in rcar_mipi_dsi_parameters_calc(), the VCLK divider is stored
> in setup_info structure as BIT(divider). The rcar_mipi_dsi_parameters_calc()
> is called at the early beginning of rcar_mipi_dsi_startup() function. Later,
> in the same rcar_mipi_dsi_startup() function, the stored BIT(divider) value
> is passed to __ffs() to calculate back the divider out of the value again.
>
> Factor out VCLK divider calculation into rcar_mipi_dsi_vclk_divider()
> function and call the function from both rcar_mipi_dsi_parameters_calc()
> and rcar_mipi_dsi_startup() to avoid this back and forth BIT() and _ffs()
> and avoid unnecessarily storing the divider value in setup_info at all.
>
> This rework has a slight side-effect, in that it should allow the compiler
> to better evaluate the code and avoid compiler warnings about variable
> value overflows, which can never happen.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202512051834.bESvhDiG-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512222321.TeY4VbvK-lkp@intel.com/
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tomi, could you please push this to drm-misc ?
> ---
> Cc: David Airlie <airlied@gmail.com>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Magnus Damm <magnus.damm@gmail.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: Simona Vetter <simona@ffwll.ch>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-renesas-soc@vger.kernel.org
> ---
> V2: Use BIT_U16()
> ---
> .../gpu/drm/renesas/rcar-du/rcar_mipi_dsi.c | 35 ++++++++++++++-----
> 1 file changed, 26 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_mipi_dsi.c b/drivers/gpu/drm/renesas/rcar-du/rcar_mipi_dsi.c
> index 4ef2e3c129ed7..508977b9e8926 100644
> --- a/drivers/gpu/drm/renesas/rcar-du/rcar_mipi_dsi.c
> +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_mipi_dsi.c
> @@ -84,7 +84,6 @@ struct dsi_setup_info {
> unsigned long fout;
> u16 m;
> u16 n;
> - u16 vclk_divider;
> const struct dsi_clk_config *clkset;
> };
>
> @@ -335,10 +334,24 @@ rcar_mipi_dsi_post_init_phtw_v4h(struct rcar_mipi_dsi *dsi,
> * Hardware Setup
> */
>
> +static unsigned int rcar_mipi_dsi_vclk_divider(struct rcar_mipi_dsi *dsi,
> + struct dsi_setup_info *setup_info)
> +{
> + switch (dsi->info->model) {
> + case RCAR_DSI_V3U:
> + default:
> + return (setup_info->clkset->vco_cntrl >> 4) & 0x3;
> +
> + case RCAR_DSI_V4H:
> + return (setup_info->clkset->vco_cntrl >> 3) & 0x7;
> + }
> +}
> +
> static void rcar_mipi_dsi_pll_calc(struct rcar_mipi_dsi *dsi,
> unsigned long fin_rate,
> unsigned long fout_target,
> - struct dsi_setup_info *setup_info)
> + struct dsi_setup_info *setup_info,
> + u16 vclk_divider)
> {
> unsigned int best_err = -1;
> const struct rcar_mipi_dsi_device_info *info = dsi->info;
> @@ -360,7 +373,7 @@ static void rcar_mipi_dsi_pll_calc(struct rcar_mipi_dsi *dsi,
> if (fout < info->fout_min || fout > info->fout_max)
> continue;
>
> - fout = div64_u64(fout, setup_info->vclk_divider);
> + fout = div64_u64(fout, vclk_divider);
>
> if (fout < setup_info->clkset->min_freq ||
> fout > setup_info->clkset->max_freq)
> @@ -390,7 +403,9 @@ static void rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi *dsi,
> unsigned long fout_target;
> unsigned long fin_rate;
> unsigned int i;
> + unsigned int div;
> unsigned int err;
> + u16 vclk_divider;
>
> /*
> * Calculate Fout = dot clock * ColorDepth / (2 * Lane Count)
> @@ -412,18 +427,20 @@ static void rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi *dsi,
>
> fin_rate = clk_get_rate(clk);
>
> + div = rcar_mipi_dsi_vclk_divider(dsi, setup_info);
> +
> switch (dsi->info->model) {
> case RCAR_DSI_V3U:
> default:
> - setup_info->vclk_divider = 1 << ((clk_cfg->vco_cntrl >> 4) & 0x3);
> + vclk_divider = BIT_U16(div);
> break;
>
> case RCAR_DSI_V4H:
> - setup_info->vclk_divider = 1 << (((clk_cfg->vco_cntrl >> 3) & 0x7) + 1);
> + vclk_divider = BIT_U16(div + 1);
> break;
> }
>
> - rcar_mipi_dsi_pll_calc(dsi, fin_rate, fout_target, setup_info);
> + rcar_mipi_dsi_pll_calc(dsi, fin_rate, fout_target, setup_info, vclk_divider);
>
> /* Find hsfreqrange */
> setup_info->hsfreq = setup_info->fout * 2;
> @@ -439,7 +456,7 @@ static void rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi *dsi,
> dev_dbg(dsi->dev,
> "Fout = %u * %lu / (%u * %u * %u) = %lu (target %lu Hz, error %d.%02u%%)\n",
> setup_info->m, fin_rate, dsi->info->n_mul, setup_info->n,
> - setup_info->vclk_divider, setup_info->fout, fout_target,
> + vclk_divider, setup_info->fout, fout_target,
> err / 100, err % 100);
>
> dev_dbg(dsi->dev,
> @@ -653,11 +670,11 @@ static int rcar_mipi_dsi_startup(struct rcar_mipi_dsi *dsi,
> switch (dsi->info->model) {
> case RCAR_DSI_V3U:
> default:
> - vclkset |= VCLKSET_DIV_V3U(__ffs(setup_info.vclk_divider));
> + vclkset |= VCLKSET_DIV_V3U(rcar_mipi_dsi_vclk_divider(dsi, &setup_info));
> break;
>
> case RCAR_DSI_V4H:
> - vclkset |= VCLKSET_DIV_V4H(__ffs(setup_info.vclk_divider) - 1);
> + vclkset |= VCLKSET_DIV_V4H(rcar_mipi_dsi_vclk_divider(dsi, &setup_info));
> break;
> }
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-01-23 15:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-05 17:52 [PATCH v2] drm/rcar-du: dsi: Clean up VCLK divider calculation Marek Vasut
2026-01-23 15:22 ` Laurent Pinchart [this message]
2026-01-27 11:26 ` Tomi Valkeinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260123152235.GJ215800@killaraus \
--to=laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=geert+renesas@glider.be \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=lkp@intel.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=magnus.damm@gmail.com \
--cc=marek.vasut+renesas@mailbox.org \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tomi.valkeinen+renesas@ideasonboard.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.