* [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
@ 2026-11-21 18:18 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
` (2 more replies)
0 siblings, 3 replies; 7+ 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
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)
- Document protected-clocks in the binding
- Link to v1: https://patch.msgid.link/20261121-b4-sg2042-efi-rtc-v1-0-19898b8ad497@iscas.ac.cn
To: Stephen Boyd <sboyd@kernel.org>
To: Brian Masney <bmasney+clk@redhat.com>
To: Jerome Brunet <jbrunet+clk@baylibre.com>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Chen Wang <chen.wang@linux.dev>
To: Inochi Amaoto <inochiama@gmail.com>
Cc: Chen Wang <unicorn_wang@outlook.com>
Cc: linux-clk@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: sophgo@lists.linux.dev
Cc: linux-kernel@vger.kernel.org
---
Han Gao (2):
dt-bindings: clock: sophgo: Allow protected gate clocks on SG2042
clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled
.../devicetree/bindings/clock/sophgo,sg2042-clkgen.yaml | 2 ++
drivers/clk/sophgo/clk-sg2042-clkgen.c | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261121-b4-sg2042-efi-rtc-e4d5222513ae
Best regards,
--
Han Gao <gaohan@iscas.ac.cn>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [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; 7+ 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 [flat|nested] 7+ 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; 7+ 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 [flat|nested] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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
0 siblings, 0 replies; 7+ 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] 7+ messages in thread
end of thread, other threads:[~2026-12-02 14:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-21 23:48 ` Inochi Amaoto
2026-11-22 11:50 ` Jerome Brunet
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®