From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6970E25B1D2; Fri, 23 Jan 2026 15:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769181762; cv=none; b=kZ40PVyEw5RfIMD27xwaDX+VH4QEcMMH745W6P71Xs1xlhy0HqliDW4s4ezuXIyekf4fwkLcE2aQMKx8+6NMnFfqqgD/pGR0drqt5pUIuG7xXO4cFk2XFThnL9hFvT6qJt0ZflDBiGJZEegPk23HxficCJ5A6U2F4/h1CCcVjgE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769181762; c=relaxed/simple; bh=RlWol9UsYbbYEsR5X0M1jiANdJTLLyIN5+ubpdC6tJ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=slInpXpFLY4neRK9rATwBsgmaLsjzvlXw2pXbAKXj96ANa2e0t4eLOjnbWS6j5xi7SMlQTENzy/rZEVEzXMHAqQD/Wr7kXcRmHJGcM+SpVGfEkheWN20flMt2z6SUY4JZO89b/+li5mL5EiWFYOAz94OAgqtIzY/xqtE/uLZTTU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=MEO24Nzr; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MEO24Nzr" Received: from pendragon.ideasonboard.com (2001-14ba-703d-e500--2a1.rev.dnainternet.fi [IPv6:2001:14ba:703d:e500::2a1]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id DF6E414C7; Fri, 23 Jan 2026 16:22:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1769181724; bh=RlWol9UsYbbYEsR5X0M1jiANdJTLLyIN5+ubpdC6tJ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MEO24Nzr+qaFUIkZbsAoz4vipNvTAxVLizfJXgAczkgiBhO7dWf8GthE/C0KkxpbX lhcU2bAux+kmew5EiIjPERa6TYK39xz2Sl1cc9ma9Mch1RDVr69WtHlinPWhbDvkD6 KoLZLHWecutYnlqUZGCr2zH+HvIdZjYGTQtW9o9c= Date: Fri, 23 Jan 2026 17:22:35 +0200 From: Laurent Pinchart To: Marek Vasut Cc: dri-devel@lists.freedesktop.org, kernel test robot , David Airlie , Geert Uytterhoeven , Kieran Bingham , Maarten Lankhorst , Magnus Damm , Maxime Ripard , Simona Vetter , Thomas Zimmermann , Tomi Valkeinen , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: Re: [PATCH v2] drm/rcar-du: dsi: Clean up VCLK divider calculation Message-ID: <20260123152235.GJ215800@killaraus> References: <20260105175250.64309-1-marek.vasut+renesas@mailbox.org> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 > 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 Reviewed-by: Laurent Pinchart Tomi, could you please push this to drm-misc ? > --- > Cc: David Airlie > Cc: Geert Uytterhoeven > Cc: Kieran Bingham > Cc: Laurent Pinchart > Cc: Maarten Lankhorst > Cc: Magnus Damm > Cc: Maxime Ripard > Cc: Simona Vetter > Cc: Thomas Zimmermann > Cc: Tomi Valkeinen > 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