dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vladimir Bely" <vlwwwwww@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/msm/dsi: phy_28nm: return exact PLL-achievable VCO rate in determine_rate
Date: Sun, 29 Nov 2026 10:49:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-239529@kernel.org> (raw)
In-Reply-To: <20261129103004.357862-1-vlwwwwww@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/msm/dsi: upward VCO rounding in
  dsi_pll_28nm_calc_vco_rate() breaks RCG/PLL
--

commit 04136cd645856db1e70c20fc070ead60e3649cdf
Author: Vladimir Bely <vlwwwwww@gmail.com>

drm/msm/dsi: phy_28nm: return exact PLL-achievable VCO rate in determine_rate

This commit updates dsi_pll_28nm_clk_determine_rate() and
dsi_pll_28nm_clk_set_rate() to compute the 16-bit fractional-N divider and
resulting VCO rate via a shared dsi_pll_28nm_calc_vco_rate() helper, and
enables closest-rate rounding on analog_postdiv and byte_mux.

> diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> index d00e415b9a991..2d4a29b546c18 100644
> --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> @@ -114,31 +115,101 @@ static void pll_28nm_software_reset(struct dsi_pll_28nm *pll_28nm)
>  /*
>   * Clock Callbacks
>   */
> +static unsigned long dsi_pll_28nm_calc_vco_rate(struct dsi_pll_28nm *pll_28nm,
> +						unsigned long rate,
> +						u32 *div_fb, u32 *frac_n,
> +						bool *frac_n_mode)
> +{
> +	unsigned long min_rate = pll_28nm->phy->cfg->min_pll_rate;
> +	unsigned long max_rate = pll_28nm->phy->cfg->max_pll_rate;
> +	unsigned long actual;
> +	u32 ref_clk, div, frac;
> +
> +	rate = clamp_t(unsigned long, rate, min_rate, max_rate);
> +
> +	if (rate % VCO_REF_CLK_RATE == 0) {
> +		if (frac_n_mode)
> +			*frac_n_mode = false;
> +		if (div_fb)
> +			*div_fb = rate / VCO_REF_CLK_RATE;
> +		if (frac_n)
> +			*frac_n = 0;
> +		return rate;
> +	}
> +
> +	ref_clk = VCO_REF_CLK_RATE * 2;
> +	div = rate / ref_clk;
> +	frac = DIV_ROUND_CLOSEST_ULL((u64)(rate % ref_clk) << 16, ref_clk);

[ ... ]

> @@ -650,7 +704,7 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **prov
>  			&pll_28nm->clk_hw, CLK_SET_RATE_PARENT,
>  			pll_28nm->phy->pll_base +
>  				REG_DSI_28nm_PHY_PLL_POSTDIV1_CFG,
> -			0, 4, 0, NULL);
> +			0, 4, CLK_DIVIDER_ROUND_CLOSEST, NULL);
>  	if (IS_ERR(analog_postdiv))
>  		return PTR_ERR(analog_postdiv);
>  
> @@ -675,7 +729,8 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **prov
>  				&pll_28nm->clk_hw,
>  				indirect_path_div2,
>  			}), 2, CLK_SET_RATE_PARENT, pll_28nm->phy->pll_base +
> -				REG_DSI_28nm_PHY_PLL_VREG_CFG, 1, 1, 0, NULL);
> +				REG_DSI_28nm_PHY_PLL_VREG_CFG, 1, 1,
> +			CLK_MUX_ROUND_CLOSEST, NULL);
>  	if (IS_ERR(byte_mux))
>  		return PTR_ERR(byte_mux);

[Severity: High]
Can rounding frac up with DIV_ROUND_CLOSEST_ULL() in
dsi_pll_28nm_calc_vco_rate(), combined with CLK_DIVIDER_ROUND_CLOSEST and
CLK_MUX_ROUND_CLOSEST, cause the downstream byte and pixel RCGs to pick the
wrong dividers when the VCO rate rounds above the requested rate?

Whenever rate % ref_clk lies in the upper half of an SDM step,
dsi_pll_28nm_calc_vco_rate() returns an actual VCO rate up to 292 Hz above
the requested rate.  With closest-rate rounding enabled on analog_postdiv
and byte_mux, dsiNpllbyte can return parent_rate > rate to the downstream
byte RCG:

drivers/clk/qcom/clk-rcg2.c:clk_byte2_determine_rate() {
	p = req->best_parent_hw;
	req->best_parent_rate = parent_rate = clk_hw_round_rate(p, rate);

	div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
	div = min_t(u32, div, mask);

	req->rate = calc_rate(parent_rate, 0, 0, 0, div);
}

When parent_rate exceeds rate by even 1 Hz, DIV_ROUND_UP(2 * parent_rate,
rate) - 1 jumps from 1 (1:1 bypass) to 2 (a 1.5x pre-divider), so
clk_round_rate(msm_host->byte_clk, ...) drops msm_host->byte_clk_rate to
2/3 of the target panel byte clock (for example, on
s6d7aa0_lsl080al02_mode where byte_clk_rate is 55986750 Hz, VCO rounds up
by 140 Hz to 447894140 Hz, dsi0pllbyte returns 55986767 Hz, and the byte
RCG drops to 37324511 Hz).

In addition, dsiNpll (REG_DSI_28nm_PHY_PLL_POSTDIV3_CFG) is registered in
pll_28nm_register() without CLK_DIVIDER_ROUND_CLOSEST.  When the VCO is
rounded up even by 1 Hz above M * pixel_clk_rate, dsiNpll's
_div_round_up() increments the POSTDIV3 divider from M to M + 1, causing
clk_pixel_determine_rate() to miss the 100 kHz delta window and fail
clk_set_rate(msm_host->pixel_clk, ...) with -EINVAL.

Truncating frac downward instead of using DIV_ROUND_CLOSEST_ULL() keeps the
achieved VCO rate at or below the target rate while still matching
recalc_rate() once clk_round_rate() has quantized byte_clk_rate.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129103004.357862-1-vlwwwwww@gmail.com?part=1

      reply	other threads:[~2026-11-29 10:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 10:30 [PATCH] drm/msm/dsi: phy_28nm: return exact PLL-achievable VCO rate in determine_rate Vladimir Bely
2026-11-29 10:49 ` sashiko-bot [this message]

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=sashiko-outbox-239529@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vlwwwwww@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox