* [PATCH v2 1/2] dt-bindings: clock: sophgo: Allow protected gate clocks on SG2042
2026-11-21 18:18 [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled Han Gao via B4 Relay
@ 2026-11-21 18:18 ` Han Gao via B4 Relay
2026-11-21 18:18 ` [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled Han Gao via B4 Relay
2026-11-27 15:01 ` [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled Jerome Brunet
2 siblings, 0 replies; 13+ messages in thread
From: Han Gao via B4 Relay @ 2026-11-21 18:18 UTC (permalink / raw)
To: Stephen Boyd, Brian Masney, Jerome Brunet, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi
Cc: Chen Wang, Han Gao, linux-clk, devicetree, sophgo, linux-kernel,
Han Gao
From: Han Gao <gaohan@iscas.ac.cn>
Firmware may need some gates kept on for its runtime services, such as
the APB I2C gate for the EFI RTC and the AHB serial flash gate for EFI
variables. Which ones depends on the firmware, not the SoC, so let
firmware list them in protected-clocks.
Suggested-by: Yao Zi <me@ziyao.cc>
Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
---
Documentation/devicetree/bindings/clock/sophgo,sg2042-clkgen.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/clock/sophgo,sg2042-clkgen.yaml b/Documentation/devicetree/bindings/clock/sophgo,sg2042-clkgen.yaml
index e7a9255bcb58..76f123b84309 100644
--- a/Documentation/devicetree/bindings/clock/sophgo,sg2042-clkgen.yaml
+++ b/Documentation/devicetree/bindings/clock/sophgo,sg2042-clkgen.yaml
@@ -30,6 +30,8 @@ properties:
- const: dpll0
- const: dpll1
+ protected-clocks: true
+
'#clock-cells':
const: 1
description:
--
2.55.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled
2026-11-21 18:18 [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled Han Gao via B4 Relay
2026-11-21 18:18 ` [PATCH v2 1/2] dt-bindings: clock: sophgo: Allow protected gate clocks on SG2042 Han Gao via B4 Relay
@ 2026-11-21 18:18 ` Han Gao via B4 Relay
2026-11-21 23:48 ` Inochi Amaoto
2026-11-27 15:01 ` [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled Jerome Brunet
2 siblings, 1 reply; 13+ messages in thread
From: Han Gao via B4 Relay @ 2026-11-21 18:18 UTC (permalink / raw)
To: Stephen Boyd, Brian Masney, Jerome Brunet, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi
Cc: Chen Wang, Han Gao, linux-clk, devicetree, sophgo, linux-kernel,
Han Gao
From: Han Gao <gaohan@iscas.ac.cn>
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@ziyao.cc>
Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
---
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)
+ return gate->hw.init->flags | CLK_IS_CRITICAL;
+
+ return gate->hw.init->flags;
+}
+
static int sg2042_clk_register_gates(struct device *dev,
struct sg2042_clk_data *clk_data,
const struct sg2042_gate_clock gate_clks[],
@@ -858,7 +870,7 @@ static int sg2042_clk_register_gates(struct device *dev,
NULL,
gate->hw.init->parent_hws[0],
NULL,
- gate->hw.init->flags,
+ sg2042_gate_flags(dev, gate),
clk_data->iobase + gate->offset_enable,
gate->bit_idx,
0,
@@ -900,7 +912,7 @@ static int sg2042_clk_register_gates_fw(struct device *dev,
(dev,
gate->hw.init->name,
gate->hw.init->parent_data,
- gate->hw.init->flags,
+ sg2042_gate_flags(dev, gate),
clk_data->iobase + gate->offset_enable,
gate->bit_idx,
0,
--
2.55.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled
2026-11-21 18:18 ` [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled Han Gao via B4 Relay
@ 2026-11-21 23:48 ` Inochi Amaoto
2026-11-22 11:50 ` Jerome Brunet
0 siblings, 1 reply; 13+ messages in thread
From: Inochi Amaoto @ 2026-11-21 23:48 UTC (permalink / raw)
To: gaohan, Stephen Boyd, Brian Masney, Jerome Brunet, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi
Cc: Chen Wang, Han Gao, linux-clk, devicetree, sophgo, linux-kernel
On Sun, Nov 22, 2026 at 02:18:05AM +0800, Han Gao via B4 Relay wrote:
> From: Han Gao <gaohan@iscas.ac.cn>
>
> 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@ziyao.cc>
> Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> ---
> 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)
> + 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
> static int sg2042_clk_register_gates(struct device *dev,
> struct sg2042_clk_data *clk_data,
> const struct sg2042_gate_clock gate_clks[],
> @@ -858,7 +870,7 @@ static int sg2042_clk_register_gates(struct device *dev,
> NULL,
> gate->hw.init->parent_hws[0],
> NULL,
> - gate->hw.init->flags,
> + sg2042_gate_flags(dev, gate),
> clk_data->iobase + gate->offset_enable,
> gate->bit_idx,
> 0,
> @@ -900,7 +912,7 @@ static int sg2042_clk_register_gates_fw(struct device *dev,
> (dev,
> gate->hw.init->name,
> gate->hw.init->parent_data,
> - gate->hw.init->flags,
> + sg2042_gate_flags(dev, gate),
> clk_data->iobase + gate->offset_enable,
> gate->bit_idx,
> 0,
>
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled
2026-11-21 23:48 ` Inochi Amaoto
@ 2026-11-22 11:50 ` Jerome Brunet
0 siblings, 0 replies; 13+ messages in thread
From: Jerome Brunet @ 2026-11-22 11:50 UTC (permalink / raw)
To: Inochi Amaoto
Cc: gaohan, Stephen Boyd, Brian Masney, Jerome Brunet, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Yao Zi, Chen Wang,
Han Gao, linux-clk, devicetree, sophgo, linux-kernel,
Jerome Brunet
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@iscas.ac.cn>
> >
> > 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@ziyao.cc>
> > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > ---
> > 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-11-21 18:18 [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled Han Gao via B4 Relay
2026-11-21 18:18 ` [PATCH v2 1/2] dt-bindings: clock: sophgo: Allow protected gate clocks on SG2042 Han Gao via B4 Relay
2026-11-21 18:18 ` [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled Han Gao via B4 Relay
@ 2026-11-27 15:01 ` Jerome Brunet
2026-12-02 14:50 ` Rob Herring
2 siblings, 1 reply; 13+ messages in thread
From: Jerome Brunet @ 2026-11-27 15:01 UTC (permalink / raw)
To: Han Gao
Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree, sophgo,
linux-kernel, Jerome Brunet
> On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> flash for its own image and EFI variables. Both sit behind clock gates
> shared with devices Linux drives, so runtime PM on the Linux side can
> turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
>
> Let firmware list such gates in protected-clocks on the clkgen node,
> and keep them enabled.
>
> qcom, the only current user of protected-clocks, does not register such
> clocks at all. That would break the I2C controllers Linux uses, as the
> DesignWare driver needs the clock rate, so here they stay registered and
> are only kept on. I'm not sure this fits the intended use; suggestions
> welcome.
>
> Tested on Milk-V Pioneer.
>
> Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> ---
> Changes in v2:
> - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> - Use protected-clocks instead of scanning reserved nodes under /soc
> (Krzysztof)
Hey Krzysztof,
Using protected-clocks in the way proposed in this series would give it a different
behavior/meaning compared to what introduced it in Qcom:
- Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
- SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
A consumer gets a valid clock handle, can read its rate, but releasing its enable
reference won’t turn off the hardware gate.
Having different meaning for the same property is not ideal, is it ?
Eventually that might be something we could fold into the framework, but that can only
happen if the meaning is consistent.
IMO what they are trying to do here might be more appropriate, but Qcom was there first.
OTOH, actually registering the clock in Qcom would not be a breaking change DT wise, the driver
would start returning a handle where it would previously have returned NULL.
What is your view on this ?
--
Jerome
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-11-27 15:01 ` [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled Jerome Brunet
@ 2026-12-02 14:50 ` Rob Herring
2026-12-02 16:29 ` Icenowy Zheng
0 siblings, 1 reply; 13+ messages in thread
From: Rob Herring @ 2026-12-02 14:50 UTC (permalink / raw)
To: Jerome Brunet
Cc: Han Gao, Stephen Boyd, Brian Masney, Jerome Brunet,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree, sophgo,
linux-kernel
On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > flash for its own image and EFI variables. Both sit behind clock gates
> > shared with devices Linux drives, so runtime PM on the Linux side can
> > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> >
> > Let firmware list such gates in protected-clocks on the clkgen node,
> > and keep them enabled.
> >
> > qcom, the only current user of protected-clocks, does not register such
> > clocks at all. That would break the I2C controllers Linux uses, as the
> > DesignWare driver needs the clock rate, so here they stay registered and
> > are only kept on. I'm not sure this fits the intended use; suggestions
> > welcome.
> >
> > Tested on Milk-V Pioneer.
> >
> > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > ---
> > Changes in v2:
> > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > - Use protected-clocks instead of scanning reserved nodes under /soc
> > (Krzysztof)
>
> Hey Krzysztof,
>
> Using protected-clocks in the way proposed in this series would give it a different
> behavior/meaning compared to what introduced it in Qcom:
>
> - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> A consumer gets a valid clock handle, can read its rate, but releasing its enable
> reference won’t turn off the hardware gate.
>
> Having different meaning for the same property is not ideal, is it ?
> Eventually that might be something we could fold into the framework, but that can only
> happen if the meaning is consistent.
>
> IMO what they are trying to do here might be more appropriate, but Qcom was there first.
> OTOH, actually registering the clock in Qcom would not be a breaking change DT wise, the driver
> would start returning a handle where it would previously have returned NULL.
>
> What is your view on this ?
From a DT perspective, I don't think it matters too much if the OS
behavior varies in the way you describe. It would be nice if the
framework handled it rather than individual drivers though and providing
read-only clocks seems more useful than hiding the clocks.
Rob
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-12-02 14:50 ` Rob Herring
@ 2026-12-02 16:29 ` Icenowy Zheng
2026-12-02 19:33 ` Jerome Brunet
2026-12-03 18:06 ` Yao Zi
0 siblings, 2 replies; 13+ messages in thread
From: Icenowy Zheng @ 2026-12-02 16:29 UTC (permalink / raw)
To: Rob Herring, Jerome Brunet
Cc: Han Gao, Stephen Boyd, Brian Masney, Jerome Brunet,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree, sophgo,
linux-kernel
在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > flash for its own image and EFI variables. Both sit behind clock gates
> > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > >
> > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > and keep them enabled.
> > >
> > > qcom, the only current user of protected-clocks, does not register such
> > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > DesignWare driver needs the clock rate, so here they stay registered and
> > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > welcome.
> > >
> > > Tested on Milk-V Pioneer.
> > >
> > > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > > ---
> > > Changes in v2:
> > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > (Krzysztof)
> >
> > Hey Krzysztof,
> >
> > Using protected-clocks in the way proposed in this series would give it a different
> > behavior/meaning compared to what introduced it in Qcom:
> >
> > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > reference won’t turn off the hardware gate.
> >
> > Having different meaning for the same property is not ideal, is it ?
> > Eventually that might be something we could fold into the framework, but that can only
> > happen if the meaning is consistent.
Well in fact the purpose isn't the same on QCOM and SG2042 here:
- On Qualcomm platforms, all resources specified as "protected" in DT is
really protected by the TEE. If Linux even dare to touch these resources,
the TEE will consider this as tamper of TEE security and hang the system,
so these resources should never be touched by Linux.
- On SG2042, there's no security enforcement on these resources, and Linux
has the permission to access them. However this will render some part of
the EFI runtime service unavailable, so for the sake of EFI runtime service
availability these resources need to be kept on by Linux.
These two behaviors are not possible to be unified, although the latter
isn't restricted to SG2042 and is common on EFI-booted embedded systems.
Maybe a new name (instead of protected-*) could be chosen for the latter
behavior. Considering it would behaves like the `assigned-clock*` family
when in the clock framework, maybe something like `assigned-clock-on = <0>
/* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
*/;` ?
Thanks,
Icenowy
> >
> > IMO what they are trying to do here might be more appropriate, but Qcom was there first.
> > OTOH, actually registering the clock in Qcom would not be a breaking change DT wise, the driver
> > would start returning a handle where it would previously have returned NULL.
> >
> > What is your view on this ?
>
> > From a DT perspective, I don't think it matters too much if the OS
> behavior varies in the way you describe. It would be nice if the
> framework handled it rather than individual drivers though and providing
> read-only clocks seems more useful than hiding the clocks.
>
> Rob
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-12-02 16:29 ` Icenowy Zheng
@ 2026-12-02 19:33 ` Jerome Brunet
2026-12-03 10:02 ` Icenowy Zheng
2026-12-03 13:41 ` Inochi Amaoto
2026-12-03 18:06 ` Yao Zi
1 sibling, 2 replies; 13+ messages in thread
From: Jerome Brunet @ 2026-12-02 19:33 UTC (permalink / raw)
To: Icenowy Zheng
Cc: Rob Herring, Jerome Brunet, Han Gao, Stephen Boyd, Brian Masney,
Jerome Brunet, Krzysztof Kozlowski, Conor Dooley, Chen Wang,
Inochi Amaoto, Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree,
sophgo, linux-kernel
On 2026-12-03 00:29 +0800, Icenowy Zheng wrote:
> 在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> > On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > > flash for its own image and EFI variables. Both sit behind clock gates
> > > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > > >
> > > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > > and keep them enabled.
> > > >
> > > > qcom, the only current user of protected-clocks, does not register such
> > > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > > DesignWare driver needs the clock rate, so here they stay registered and
> > > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > > welcome.
> > > >
> > > > Tested on Milk-V Pioneer.
> > > >
> > > > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > > > ---
> > > > Changes in v2:
> > > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > > (Krzysztof)
> > >
> > > Hey Krzysztof,
> > >
> > > Using protected-clocks in the way proposed in this series would give it a different
> > > behavior/meaning compared to what introduced it in Qcom:
> > >
> > > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > > reference won’t turn off the hardware gate.
> > >
> > > Having different meaning for the same property is not ideal, is it ?
> > > Eventually that might be something we could fold into the framework, but that can only
> > > happen if the meaning is consistent.
>
> Well in fact the purpose isn't the same on QCOM and SG2042 here:
>
> - On Qualcomm platforms, all resources specified as "protected" in DT is
> really protected by the TEE. If Linux even dare to touch these resources,
> the TEE will consider this as tamper of TEE security and hang the system,
> so these resources should never be touched by Linux.
> - On SG2042, there's no security enforcement on these resources, and Linux
> has the permission to access them. However this will render some part of
> the EFI runtime service unavailable, so for the sake of EFI runtime service
> availability these resources need to be kept on by Linux.
>
> These two behaviors are not possible to be unified, although the latter
> isn't restricted to SG2042 and is common on EFI-booted embedded systems.
>
> Maybe a new name (instead of protected-*) could be chosen for the latter
> behavior. Considering it would behaves like the `assigned-clock*` family
> when in the clock framework, maybe something like `assigned-clock-on = <0>
> /* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
> */;` ?
For sure, It'd prefer if a property had single meaning regardless of the SoC so
not protected-clocks please.
I thought this reminded me of something and we have been down that road before:
https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/tree/drivers/clk/clk.c?h=clk-next#n5600
So apparently there was good reason not to do this 10y ago but I don't have
the history on it. I'll try to dig.
--
Jerome
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-12-02 19:33 ` Jerome Brunet
@ 2026-12-03 10:02 ` Icenowy Zheng
2026-12-03 13:41 ` Inochi Amaoto
1 sibling, 0 replies; 13+ messages in thread
From: Icenowy Zheng @ 2026-12-03 10:02 UTC (permalink / raw)
To: Jerome Brunet
Cc: Rob Herring, Han Gao, Stephen Boyd, Brian Masney, Jerome Brunet,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree, sophgo,
linux-kernel
在 2026-12-02三的 20:33 +0100,Jerome Brunet写道:
> On 2026-12-03 00:29 +0800, Icenowy Zheng wrote:
> > 在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> > > On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > > > flash for its own image and EFI variables. Both sit behind clock gates
> > > > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > > > >
> > > > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > > > and keep them enabled.
> > > > >
> > > > > qcom, the only current user of protected-clocks, does not register such
> > > > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > > > DesignWare driver needs the clock rate, so here they stay registered and
> > > > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > > > welcome.
> > > > >
> > > > > Tested on Milk-V Pioneer.
> > > > >
> > > > > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > > > > ---
> > > > > Changes in v2:
> > > > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > > > (Krzysztof)
> > > >
> > > > Hey Krzysztof,
> > > >
> > > > Using protected-clocks in the way proposed in this series would give it a different
> > > > behavior/meaning compared to what introduced it in Qcom:
> > > >
> > > > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > > > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > > > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > > > reference won’t turn off the hardware gate.
> > > >
> > > > Having different meaning for the same property is not ideal, is it ?
> > > > Eventually that might be something we could fold into the framework, but that can only
> > > > happen if the meaning is consistent.
> >
> > Well in fact the purpose isn't the same on QCOM and SG2042 here:
> >
> > - On Qualcomm platforms, all resources specified as "protected" in DT is
> > really protected by the TEE. If Linux even dare to touch these resources,
> > the TEE will consider this as tamper of TEE security and hang the system,
> > so these resources should never be touched by Linux.
> > - On SG2042, there's no security enforcement on these resources, and Linux
> > has the permission to access them. However this will render some part of
> > the EFI runtime service unavailable, so for the sake of EFI runtime service
> > availability these resources need to be kept on by Linux.
> >
> > These two behaviors are not possible to be unified, although the latter
> > isn't restricted to SG2042 and is common on EFI-booted embedded systems.
> >
> > Maybe a new name (instead of protected-*) could be chosen for the latter
> > behavior. Considering it would behaves like the `assigned-clock*` family
> > when in the clock framework, maybe something like `assigned-clock-on = <0>
> > /* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
> > */;` ?
>
>
> For sure, It'd prefer if a property had single meaning regardless of the SoC so
> not protected-clocks please.
>
> I thought this reminded me of something and we have been down that road before:
> https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/tree/drivers/clk/clk.c?h=clk-next#n5600
Well I think the real deprecated thing here is one-clock-per-node bindings
instead of specifying critical clocks in the DT.
/me remembered the transition of sunxi clock drivers to sunxi-ng clock
drivers.
Thanks,
Icenowy
>
> So apparently there was good reason not to do this 10y ago but I don't have
> the history on it. I'll try to dig.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-12-02 19:33 ` Jerome Brunet
2026-12-03 10:02 ` Icenowy Zheng
@ 2026-12-03 13:41 ` Inochi Amaoto
1 sibling, 0 replies; 13+ messages in thread
From: Inochi Amaoto @ 2026-12-03 13:41 UTC (permalink / raw)
To: Jerome Brunet, Icenowy Zheng
Cc: Rob Herring, Han Gao, Stephen Boyd, Brian Masney, Jerome Brunet,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree, sophgo,
linux-kernel
On Wed, Dec 02, 2026 at 08:33:24PM +0100, Jerome Brunet wrote:
> On 2026-12-03 00:29 +0800, Icenowy Zheng wrote:
> > 在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> > > On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > > > flash for its own image and EFI variables. Both sit behind clock gates
> > > > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > > > >
> > > > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > > > and keep them enabled.
> > > > >
> > > > > qcom, the only current user of protected-clocks, does not register such
> > > > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > > > DesignWare driver needs the clock rate, so here they stay registered and
> > > > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > > > welcome.
> > > > >
> > > > > Tested on Milk-V Pioneer.
> > > > >
> > > > > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > > > > ---
> > > > > Changes in v2:
> > > > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > > > (Krzysztof)
> > > >
> > > > Hey Krzysztof,
> > > >
> > > > Using protected-clocks in the way proposed in this series would give it a different
> > > > behavior/meaning compared to what introduced it in Qcom:
> > > >
> > > > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > > > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > > > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > > > reference won’t turn off the hardware gate.
> > > >
> > > > Having different meaning for the same property is not ideal, is it ?
> > > > Eventually that might be something we could fold into the framework, but that can only
> > > > happen if the meaning is consistent.
> >
> > Well in fact the purpose isn't the same on QCOM and SG2042 here:
> >
> > - On Qualcomm platforms, all resources specified as "protected" in DT is
> > really protected by the TEE. If Linux even dare to touch these resources,
> > the TEE will consider this as tamper of TEE security and hang the system,
> > so these resources should never be touched by Linux.
> > - On SG2042, there's no security enforcement on these resources, and Linux
> > has the permission to access them. However this will render some part of
> > the EFI runtime service unavailable, so for the sake of EFI runtime service
> > availability these resources need to be kept on by Linux.
> >
> > These two behaviors are not possible to be unified, although the latter
> > isn't restricted to SG2042 and is common on EFI-booted embedded systems.
> >
> > Maybe a new name (instead of protected-*) could be chosen for the latter
> > behavior. Considering it would behaves like the `assigned-clock*` family
> > when in the clock framework, maybe something like `assigned-clock-on = <0>
> > /* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
> > */;` ?
>
>
> For sure, It'd prefer if a property had single meaning regardless of the SoC so
> not protected-clocks please.
>
> I thought this reminded me of something and we have been down that road before:
> https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/tree/drivers/clk/clk.c?h=clk-next#n5600
>
> So apparently there was good reason not to do this 10y ago but I don't have
> the history on it. I'll try to dig.
>
> --
> Jerome
>
Hi Jerome,
A new name could be a better option. My understanding is that the
protected-clocks is more like requirement from the firmware, so the
kernel must ignore it, whether it will hang the system or not.
The usage on SG2042 is more like a negotiation between the firmware
and kernel. The clock can be referenced by the kernel, but it is
still controlled by the firmware. Maybe we also need a new clock
flag to mark it. Mark it critial does not tell the kernel that it
is controlled by others like firmware.
Regards,
Inochi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-12-02 16:29 ` Icenowy Zheng
2026-12-02 19:33 ` Jerome Brunet
@ 2026-12-03 18:06 ` Yao Zi
2026-12-03 18:34 ` Jerome Brunet
1 sibling, 1 reply; 13+ messages in thread
From: Yao Zi @ 2026-12-03 18:06 UTC (permalink / raw)
To: Icenowy Zheng, Rob Herring, Jerome Brunet
Cc: Han Gao, Stephen Boyd, Brian Masney, Jerome Brunet,
Krzysztof Kozlowski, Conor Dooley, Chen Wang, Inochi Amaoto,
Yao Zi, Chen Wang, Han Gao, linux-clk, devicetree, sophgo,
linux-kernel
On Thu, Dec 03, 2026 at 12:29:33AM +0800, Icenowy Zheng wrote:
> 在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> > On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > > flash for its own image and EFI variables. Both sit behind clock gates
> > > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > > >
> > > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > > and keep them enabled.
> > > >
> > > > qcom, the only current user of protected-clocks, does not register such
> > > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > > DesignWare driver needs the clock rate, so here they stay registered and
> > > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > > welcome.
> > > >
> > > > Tested on Milk-V Pioneer.
> > > >
> > > > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > > > ---
> > > > Changes in v2:
> > > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > > (Krzysztof)
> > >
> > > Hey Krzysztof,
> > >
> > > Using protected-clocks in the way proposed in this series would give it a different
> > > behavior/meaning compared to what introduced it in Qcom:
> > >
> > > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > > reference won’t turn off the hardware gate.
> > >
> > > Having different meaning for the same property is not ideal, is it ?
> > > Eventually that might be something we could fold into the framework, but that can only
> > > happen if the meaning is consistent.
>
> Well in fact the purpose isn't the same on QCOM and SG2042 here:
>
> - On Qualcomm platforms, all resources specified as "protected" in DT is
> really protected by the TEE. If Linux even dare to touch these resources,
> the TEE will consider this as tamper of TEE security and hang the system,
> so these resources should never be touched by Linux.
> - On SG2042, there's no security enforcement on these resources, and Linux
> has the permission to access them. However this will render some part of
> the EFI runtime service unavailable, so for the sake of EFI runtime service
> availability these resources need to be kept on by Linux.
>
> These two behaviors are not possible to be unified, although the latter
> isn't restricted to SG2042 and is common on EFI-booted embedded systems.
>
> Maybe a new name (instead of protected-*) could be chosen for the latter
> behavior. Considering it would behaves like the `assigned-clock*` family
> when in the clock framework, maybe something like `assigned-clock-on = <0>
> /* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
> */;` ?
If we are introducing a property to protect clocks used by firmware,
it should probably protect all its states from changing, e.g., rate.
The firmware might expect a specific rate for the clock, and if its rate
is changed by requests to sibling clocks sharing the same parent, the
firmware wouldn't be able to restore the expected state without racing
with the kernel.
assigned-clock-rates/parents aren't a solution here, since they're only
initial settings and not exclusive.
> Thanks,
> Icenowy
[...]
--
Thanks,
Yao Zi
Meow-mrrp-mrow, I'm a cat.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
2026-12-03 18:06 ` Yao Zi
@ 2026-12-03 18:34 ` Jerome Brunet
0 siblings, 0 replies; 13+ messages in thread
From: Jerome Brunet @ 2026-12-03 18:34 UTC (permalink / raw)
To: Yao Zi
Cc: Icenowy Zheng, Rob Herring, Jerome Brunet, Han Gao, Stephen Boyd,
Brian Masney, Jerome Brunet, Krzysztof Kozlowski, Conor Dooley,
Chen Wang, Inochi Amaoto, Chen Wang, Han Gao, linux-clk,
devicetree, sophgo, linux-kernel
On 2026-12-03 18:06 +0000, Yao Zi wrote:
> On Thu, Dec 03, 2026 at 12:29:33AM +0800, Icenowy Zheng wrote:
> > 在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> > > On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > > > flash for its own image and EFI variables. Both sit behind clock gates
> > > > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > > > >
> > > > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > > > and keep them enabled.
> > > > >
> > > > > qcom, the only current user of protected-clocks, does not register such
> > > > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > > > DesignWare driver needs the clock rate, so here they stay registered and
> > > > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > > > welcome.
> > > > >
> > > > > Tested on Milk-V Pioneer.
> > > > >
> > > > > Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> > > > > ---
> > > > > Changes in v2:
> > > > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > > > (Krzysztof)
> > > >
> > > > Hey Krzysztof,
> > > >
> > > > Using protected-clocks in the way proposed in this series would give it a different
> > > > behavior/meaning compared to what introduced it in Qcom:
> > > >
> > > > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > > > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > > > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > > > reference won’t turn off the hardware gate.
> > > >
> > > > Having different meaning for the same property is not ideal, is it ?
> > > > Eventually that might be something we could fold into the framework, but that can only
> > > > happen if the meaning is consistent.
> >
> > Well in fact the purpose isn't the same on QCOM and SG2042 here:
> >
> > - On Qualcomm platforms, all resources specified as "protected" in DT is
> > really protected by the TEE. If Linux even dare to touch these resources,
> > the TEE will consider this as tamper of TEE security and hang the system,
> > so these resources should never be touched by Linux.
> > - On SG2042, there's no security enforcement on these resources, and Linux
> > has the permission to access them. However this will render some part of
> > the EFI runtime service unavailable, so for the sake of EFI runtime service
> > availability these resources need to be kept on by Linux.
> >
> > These two behaviors are not possible to be unified, although the latter
> > isn't restricted to SG2042 and is common on EFI-booted embedded systems.
> >
> > Maybe a new name (instead of protected-*) could be chosen for the latter
> > behavior. Considering it would behaves like the `assigned-clock*` family
> > when in the clock framework, maybe something like `assigned-clock-on = <0>
> > /* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
> > */;` ?
>
> If we are introducing a property to protect clocks used by firmware,
> it should probably protect all its states from changing, e.g., rate.
>
> The firmware might expect a specific rate for the clock, and if its rate
> is changed by requests to sibling clocks sharing the same parent, the
> firmware wouldn't be able to restore the expected state without racing
> with the kernel.
>
> assigned-clock-rates/parents aren't a solution here, since they're only
> initial settings and not exclusive.
Maybe something on the same model as gpio-hog ? the use-case looks very similar.
--
Jerome
^ permalink raw reply [flat|nested] 13+ messages in thread