Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: scmi: add is_prepared hook

Some clocks maybe default enabled by hardware. For clocks that don't
have users, that will be left in hardware default state, because prepare
count and enable count is zero,if there is no is_prepared hook to get
the hardware state. So add is_prepared hook to detect the hardware
state. Then when disabling the unused clocks, they can be simply
turned OFF to save power during kernel boot.

Reviewed-by: Dhruva Gole <d-gole@ti.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Link: https://lore.kernel.org/r/20240806145601.1184337-1-peng.fan@oss.nxp.com
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Peng Fan and committed by
Stephen Boyd
fc953d40 8400291e

+14 -2
+14 -2
drivers/clk/clk-scmi.c
··· 156 156 scmi_proto_clk_ops->disable(clk->ph, clk->id, ATOMIC); 157 157 } 158 158 159 - static int scmi_clk_atomic_is_enabled(struct clk_hw *hw) 159 + static int __scmi_clk_is_enabled(struct clk_hw *hw, bool atomic) 160 160 { 161 161 int ret; 162 162 bool enabled = false; 163 163 struct scmi_clk *clk = to_scmi_clk(hw); 164 164 165 - ret = scmi_proto_clk_ops->state_get(clk->ph, clk->id, &enabled, ATOMIC); 165 + ret = scmi_proto_clk_ops->state_get(clk->ph, clk->id, &enabled, atomic); 166 166 if (ret) 167 167 dev_warn(clk->dev, 168 168 "Failed to get state for clock ID %d\n", clk->id); 169 169 170 170 return !!enabled; 171 + } 172 + 173 + static int scmi_clk_atomic_is_enabled(struct clk_hw *hw) 174 + { 175 + return __scmi_clk_is_enabled(hw, ATOMIC); 176 + } 177 + 178 + static int scmi_clk_is_enabled(struct clk_hw *hw) 179 + { 180 + return __scmi_clk_is_enabled(hw, NOT_ATOMIC); 171 181 } 172 182 173 183 static int scmi_clk_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) ··· 295 285 296 286 if (feats_key & BIT(SCMI_CLK_ATOMIC_SUPPORTED)) 297 287 ops->is_enabled = scmi_clk_atomic_is_enabled; 288 + else 289 + ops->is_prepared = scmi_clk_is_enabled; 298 290 299 291 /* Rate ops */ 300 292 ops->recalc_rate = scmi_clk_recalc_rate;