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