Skip to content

Commit f5f792f

Browse files
ukleinekbebarino
authored andcommitted
clk: pwm: Make use of non-sleeping PWMs
For some PWMs applying a configuration doesn't sleep. For these enabling and disabling can be done in the clk callbacks .enable() and .disable() instead of .prepare() and .unprepare(). Do that to possibly reduce the time the PWM is enabled and so save some energy. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/d2f748101194409fb410711380ea52ed33260644.1746006578.git.ukleinek@baylibre.com Signed-off-by: Stephen Boyd <[email protected]>
1 parent 91d1016 commit f5f792f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

drivers/clk/clk-pwm.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ static inline struct clk_pwm *to_clk_pwm(struct clk_hw *hw)
2323
return container_of(hw, struct clk_pwm, hw);
2424
}
2525

26+
static int clk_pwm_enable(struct clk_hw *hw)
27+
{
28+
struct clk_pwm *clk_pwm = to_clk_pwm(hw);
29+
30+
return pwm_apply_atomic(clk_pwm->pwm, &clk_pwm->state);
31+
}
32+
33+
static void clk_pwm_disable(struct clk_hw *hw)
34+
{
35+
struct clk_pwm *clk_pwm = to_clk_pwm(hw);
36+
struct pwm_state state = clk_pwm->state;
37+
38+
state.enabled = false;
39+
40+
pwm_apply_atomic(clk_pwm->pwm, &state);
41+
}
42+
2643
static int clk_pwm_prepare(struct clk_hw *hw)
2744
{
2845
struct clk_pwm *clk_pwm = to_clk_pwm(hw);
@@ -61,6 +78,13 @@ static int clk_pwm_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
6178
return 0;
6279
}
6380

81+
static const struct clk_ops clk_pwm_ops_atomic = {
82+
.enable = clk_pwm_enable,
83+
.disable = clk_pwm_disable,
84+
.recalc_rate = clk_pwm_recalc_rate,
85+
.get_duty_cycle = clk_pwm_get_duty_cycle,
86+
};
87+
6488
static const struct clk_ops clk_pwm_ops = {
6589
.prepare = clk_pwm_prepare,
6690
.unprepare = clk_pwm_unprepare,
@@ -115,7 +139,11 @@ static int clk_pwm_probe(struct platform_device *pdev)
115139
of_property_read_string(node, "clock-output-names", &clk_name);
116140

117141
init.name = clk_name;
118-
init.ops = &clk_pwm_ops;
142+
if (pwm_might_sleep(pwm))
143+
init.ops = &clk_pwm_ops;
144+
else
145+
init.ops = &clk_pwm_ops_atomic;
146+
119147
init.flags = 0;
120148
init.num_parents = 0;
121149

0 commit comments

Comments
 (0)