Re: [PATCH v4 2/7] clk: qcom: Add generic clkref_en support

From: Qiang Yu

Date: Mon Jun 15 2026 - 04:47:26 EST


On Tue, Jun 09, 2026 at 02:57:52PM +0200, Konrad Dybcio wrote:
> On 5/28/26 4:29 AM, Qiang Yu wrote:
> > Before XO refclk is distributed to PCIe/USB/eDP PHYs, it passes through
> > a QREF block. QREF is powered by dedicated LDO rails, and the clkref_en
> > register controls whether refclk is gated through to the PHY side.
> >
> > These clkref controls are different from typical GCC branch clocks:
> > - only a single enable bit is present, without branch-style config bits
> > - regulators must be voted before enable and unvoted after disable
> >
> > Model this as a dedicated clk_ref clock type with custom clk_ops instead
> > of reusing struct clk_branch semantics.
> >
> > Also provide a common registration/probe API so the same clkref model
> > can be reused regardless of where clkref_en registers are placed, e.g.
> > TCSR on glymur and TLMM on SM8750.
> >
> > Signed-off-by: Qiang Yu <qiang.yu@xxxxxxxxxxxxxxxx>
> > ---
>
> [...]
>
> > +static int qcom_clk_ref_enable(struct clk_hw *hw)
> > +{
> > + struct qcom_clk_ref *rclk = to_qcom_clk_ref(hw);
> > + int ret;
> > +
> > + ret = regmap_update_bits(rclk->regmap, rclk->desc.offset, QCOM_CLK_REF_EN_MASK,
> > + QCOM_CLK_REF_EN_MASK);
>
> regmap_set_bits()
>
> > + if (ret)
> > + return ret;
> > +
> > + udelay(10);
> > +
> > + return 0;
> > +}
> > +
> > +static void qcom_clk_ref_disable(struct clk_hw *hw)
> > +{
> > + struct qcom_clk_ref *rclk = to_qcom_clk_ref(hw);
> > +
> > + regmap_update_bits(rclk->regmap, rclk->desc.offset, QCOM_CLK_REF_EN_MASK, 0);
>
> regmap_clear_bits()
>
> [...]
>

Will use regmap_clear_bits in next version.

> > +static int qcom_clk_ref_register(struct device *dev, struct regmap *regmap,
> > + struct qcom_clk_ref *clk_refs,
> > + const struct qcom_clk_ref_desc *descs,
> > + size_t num_clk_refs)
> > +{
> > + const struct qcom_clk_ref_desc *desc;
> > + struct qcom_clk_ref *clk_ref;
> > + size_t clk_idx;
> > + unsigned int i;
> > + int ret;
> > +
> > + for (clk_idx = 0; clk_idx < num_clk_refs; clk_idx++) {
> > + clk_ref = &clk_refs[clk_idx];
> > + desc = &descs[clk_idx];
> > +
> > + if (!desc->name)
> > + continue;
>
> // this allows "holes" in dt-bindings for $reasons
> if (!desc)
> continue;
>
> // this makes sure the programmer did not omit something important
> // while not taking the entire system down
> if (WARN_ON(!desc->name)
> continue;
>
The NULL name check is intentional - the descriptor array is indexed by
clock ID, and mahua has fewer clocks than glymur, leaving holes at
certain indices. So this is expected at runtime. WARN_ON would be noise
log here.

- Qiang Yu
>
> Konrad