All of 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 v2] drm/msm/dsi: phy_28nm: return exact PLL-achievable VCO rate in determine_rate
Date: Sun, 29 Nov 2026 11:40:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-239550@kernel.org> (raw)
In-Reply-To: <20261129112408.533583-1-vlwwwwww@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/msm/dsi: byte divider remainder inflation breaks pixel
  clock rounding
--

commit 29c58c6743bba124f527b7bc99228a489fbd21db
Author: Vladimir Bely <vlwwwwww@gmail.com>

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

This commit quantizes the 28nm DSI PHY PLL VCO rate downward to the
fractional-N SDM grid in determine_rate() and set_rate(), and replaces the
byte-clock path dividers with custom clk_ops that propagate integer-division
remainders upstream.

> 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..61258f76a215e 100644
> --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c

[ ... ]

> @@ -615,6 +682,121 @@ static int dsi_28nm_pll_restore_state(struct msm_dsi_phy *phy)
>  	return 0;
>  }
>  
> +static unsigned long dsi_pll_28nm_fixed_div_recalc_rate(struct clk_hw *hw,
> +							unsigned long parent_rate)
> +{
> +	struct dsi_pll_28nm_fixed_div *fdiv = to_pll_28nm_fixed_div(hw);
> +
> +	return parent_rate / fdiv->div;
> +}
> +
> +static int dsi_pll_28nm_fixed_div_determine_rate(struct clk_hw *hw,
> +						 struct clk_rate_request *req)
> +{
> +	struct dsi_pll_28nm_fixed_div *fdiv = to_pll_28nm_fixed_div(hw);
> +	struct clk_hw *parent = clk_hw_get_parent(hw);
> +	unsigned long parent_req;
> +
> +	if (!parent)
> +		return -EINVAL;
> +
> +	/* Include remainder so floor(parent / div) stays idempotent */
> +	if (req->rate > (ULONG_MAX - (fdiv->div - 1)) / fdiv->div)
> +		parent_req = ULONG_MAX;
> +	else
> +		parent_req = req->rate * fdiv->div + fdiv->div - 1;
> +
> +	req->best_parent_rate = clk_hw_round_rate(parent, parent_req);
> +	req->rate = req->best_parent_rate / fdiv->div;
> +
> +	return 0;
> +}
> +
> +static int dsi_pll_28nm_fixed_div_set_rate(struct clk_hw *hw,
> +					   unsigned long rate,
> +					   unsigned long parent_rate)
> +{
> +	return 0;
> +}
> +
> +static const struct clk_ops dsi_pll_28nm_fixed_div_ops = {
> +	.recalc_rate = dsi_pll_28nm_fixed_div_recalc_rate,
> +	.determine_rate = dsi_pll_28nm_fixed_div_determine_rate,
> +	.set_rate = dsi_pll_28nm_fixed_div_set_rate,
> +};
> +
> +static unsigned long dsi_pll_28nm_postdiv1_recalc_rate(struct clk_hw *hw,
> +						       unsigned long parent_rate)
> +{
> +	struct dsi_pll_28nm_postdiv1 *pdiv = to_pll_28nm_postdiv1(hw);
> +	u32 div = (readl(pdiv->reg) & 0xf) + 1;
> +
> +	return parent_rate / div;
> +}
> +
> +static int dsi_pll_28nm_postdiv1_determine_rate(struct clk_hw *hw,
> +						struct clk_rate_request *req)
> +{
> +	struct clk_hw *parent = clk_hw_get_parent(hw);
> +	unsigned long best_rate = 0, best_parent = 0;
> +	unsigned long rate = req->rate ?: 1;
> +	u32 d;
> +
> +	if (!parent)
> +		return -EINVAL;
> +
> +	for (d = 1; d <= 16; d++) {
> +		unsigned long parent_req, p_rate, now;
> +
> +		if (rate > (ULONG_MAX - (d - 1)) / d)
> +			parent_req = ULONG_MAX;
> +		else
> +			parent_req = rate * d + d - 1;
> +
> +		p_rate = clk_hw_round_rate(parent, parent_req);
> +		now = p_rate / d;
> +		if (now <= rate && now > best_rate) {
> +			best_rate = now;
> +			best_parent = p_rate;
> +		}
> +	}

[Severity: High]
Can adding the division remainder (rate * div + div - 1) across
dsiNpllbyte, dsiNindirect_path_div2_clk, and dsiNanalog_postdiv_clk push
the selected VCO rate above the ideal pixel-clock multiple and cause
clk_set_rate(msm_host->pixel_clk, ...) to fail with -EINVAL?

On the first clk_round_rate(msm_host->byte_clk, B_0) call on the indirect
path, dsiNpllbyte (div = 4) and dsiNindirect_path_div2_clk (div = 2)
inflate B_0 to rate = 8 * B_0 + 7 at dsiNanalog_postdiv_clk, which then
requests parent_req = 8 * d * B_0 + (8 * d - 1) from the VCO and compares
now = p_rate / d against the inflated rate = 8 * B_0 + 7.  Whenever an SDM
step falls in [8 * d * B_0 + 1, 8 * d * B_0 + 8 * d - 1] (for example, a
4-lane RGB888 panel at 32018 kHz pixel clock / B_0 = 24013500 Hz, where
d = 3 hits an exact SDM step at 576324023 Hz, 23 Hz above 18 * 32018000 Hz),
the VCO locks slightly above M * pixel_clk_rate while floor(p_rate / (8 * d))
still truncates back to B_0.

Because dsiNpll (POSTDIV3) is registered as a default clk_divider with
flags = 0, _div_round_up() rounds the POSTDIV3 divider up from M to M + 1
when clk_pixel_determine_rate() queries it, missing pixel_clk_rate by
several MHz and failing every frac_table_pixel entry with -EINVAL during
modeset.

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

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 11:24 [PATCH v2] drm/msm/dsi: phy_28nm: return exact PLL-achievable VCO rate in determine_rate Vladimir Bely
2026-11-29 11:40 ` 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-239550@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 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.