[PATCH v2 2/2] clk: sophgo: Keep SG2042 gates listed in protected-clocks enabled
From: Han Gao via B4 Relay
Date: Sat Nov 21 2026 - 13:18:26 EST
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)
+ 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