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 <[email protected]>

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/[email protected]?part=1

Reply via email to