* [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
2026-11-21 18:18 ` [PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled Han Gao via B4 Relay
0 siblings, 2 replies; 4+ 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] 4+ 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 1 sibling, 0 replies; 4+ 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] 4+ 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 1 sibling, 1 reply; 4+ 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] 4+ 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 0 siblings, 0 replies; 4+ 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] 4+ messages in thread
end of thread, other threads:[~2026-11-21 23:48 UTC | newest] Thread overview: 4+ 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
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®