Re: [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled

From: Jerome Brunet

Date: Sun Nov 22 2026 - 06:50:58 EST


On 2026-11-22 07:48 +0800, Inochi Amaoto wrote:
> On Sun, Nov 22, 2026 at 02:18:05AM +0800, Han Gao via B4 Relay wrote:
> > From: Han Gao <gaohan@xxxxxxxxxxx>
> >
> > On Milk-V Pioneer, EFI runtime services use I2C0 and the serial flash,
> > while Linux drives other devices behind the same gates. When those
> > devices runtime-suspend, the gates are turned off under the firmware.
> >
> > Mark gates listed in protected-clocks as critical. Unlike qcom, still
> > register them, since Linux devices use them too.
> >
> > Suggested-by: Yao Zi <me@xxxxxxxx>
> > Signed-off-by: Han Gao <gaohan@xxxxxxxxxxx>
> > ---
> > drivers/clk/sophgo/clk-sg2042-clkgen.c | 16 ++++++++++++++--
> > 1 file changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/clk/sophgo/clk-sg2042-clkgen.c b/drivers/clk/sophgo/clk-sg2042-clkgen.c
> > index 6abc2c973c49..65ab18f701e1 100644
> > --- a/drivers/clk/sophgo/clk-sg2042-clkgen.c
> > +++ b/drivers/clk/sophgo/clk-sg2042-clkgen.c
> > @@ -840,6 +840,18 @@ static int sg2042_clk_register_divs(struct device *dev,
> > return ret;
> > }
> >
> > +static unsigned long sg2042_gate_flags(struct device *dev,
> > + const struct sg2042_gate_clock *gate)
> > +{
> > + u32 id;
> > +
> > + of_property_for_each_u32(dev->of_node, "protected-clocks", id)
> > + if (id == gate->id)

If you are going to do it this way, restricting to gates looks like a
pitfall that would difficult to anticipate from the DT side.

> > + return gate->hw.init->flags | CLK_IS_CRITICAL;
> > +
> > + return gate->hw.init->flags;
> > +}
> > +
>
> I have a question on this: since a procteded clock should not be touched
> by a driver. Is this logic necessary? I guess this is a shared clock
> topology between the kernel and the firmare?
>
> Regards,
> Inochi

It depends what the intent is with protected-clocks here. This apparently
starte as a qcom specific flag and it might, unfortunately, be a bit
confusing with CCF existing concept of clock protection.

CCF concept of protected (or exlusive) clock is basically a clock that do not
tolerate rate change or glitch, resulting from a direct rate change of the
clock from another consumer or one of its parents. Essentially, all the tree
leading to the related clock gets locked.

This is accessed with the consumer API clk_rate_exclusive_get/put().
CLK_IS_CRITICAL is special case where the clock is locked and protected by
the provider, even in the absence of a consumer. Consumer can still get
the clock, enable or disable it but it won't ever result in the HW actually
turning the clock off. clk_set_rate() will error out if the request would
result in a disallowed glitch.

Apparently Qcom use of the flag is to skip the registration of clock,
presumably because they've got something else controlling the clock.
An alternative to this is register the clock with RO ops and NO_CACHE,
this way CCF still expose the clock but does not touch it and you can
still get it in drivers if need be.

--
Jerome