On 11/23/26 8:51 PM, Taniya Das wrote:
> The PDM (Pulse Density Modulation) hardware block on Qualcomm SoCs > contains a GP_MN clock divider that produces a fractional output > frequency from a fixed input clock (typically TCXO4):
[...]
> +static int gp_mnd_clk_runtime_resume(struct clk_gp_mnd *gp) > +{ > + return pm_runtime_resume_and_get(gp->dev); > +} > + > +static void gp_mnd_clk_runtime_put(struct clk_gp_mnd *gp) > +{ > + pm_runtime_put(gp->dev); > +}
These wrappers are totally unnecessary and confusing, just call pm_runtime_... directly
> +static int gp_mnd_clk_set_rate(struct clk_hw *hw, unsigned long rate, > + unsigned long parent_rate) > +{ > + struct clk_gp_mnd *gp = to_clk_gp_mnd(hw); > + unsigned long m = 0, n = 0; > + unsigned int d_val, n_val; > + int ret; > + > + rational_best_approximation(rate, parent_rate, > + (unsigned long)GP_MND_MAX_M, > + (unsigned long)GP_MND_MAX_N, > + &m, &n); > + if (!m || !n) > + return -EINVAL; > + > + if (n <= 2 * m + 1) > + return -EINVAL; > + > + ret = gp_mnd_clk_runtime_resume(gp); > + if (ret) > + return ret;
Use PM_RUNTIME_ACQUIRE_IF_ENABLED() to shed all the gotos
> + > + ret = regmap_write(gp->regmap, GP_MND_MDIV_REG, m); > + if (ret) > + goto err_runtime_put; > + > + /* N divider holds the 1's complement of (N - M), N_WIDTH bits wide */ > + n_val = ~(n - m) & GP_MND_MAX_N;
FIELD_PREP, please [...]
> +static unsigned long gp_mnd_clk_recalc_rate(struct clk_hw *hw, > + unsigned long parent_rate) > +{ > + struct clk_gp_mnd *gp = to_clk_gp_mnd(hw); > + unsigned int m_val, n_val; > + int ret; > + > + ret = gp_mnd_clk_runtime_resume(gp); > + if (ret) > + return 0; > + > + ret = regmap_read(gp->regmap, GP_MND_MDIV_REG, &m_val); > + if (ret) > + goto out_runtime_put; > + > + m_val &= GP_MND_MAX_M;
Likewise, FIELD_GET and ACQUIRE [...]
> +static int clk_gp_mnd_probe(struct platform_device *pdev) > +{ > + struct clk_parent_data parent_data = { .index = 0 }; > + struct clk_init_data init = { > + .name = "gp_mn_clk",
Is there always at most one instance?
> + .ops = &clk_gp_mnd_ops, > + .parent_data = &parent_data, > + .num_parents = 1, > + .flags = CLK_GET_RATE_NOCACHE,
Is this really necessary? i.e. do we expect the rate to change without Linux knowing?
> + }; > + struct device *dev = &pdev->dev; > + struct clk_gp_mnd *gp; > + struct clk *clk; > + void __iomem *base; > + int ret;
nit: please keep a reverse-Christmas-tree sorting Konrad