Skip to content

Commit 574c795

Browse files
ukleinekbebarino
authored andcommitted
clk: pwm: Convert to use pwm_apply_might_sleep()
pwm_config() is an old function that I'd like to remove. So convert this driver to use pwm_apply_might_sleep(). There is a minor change in behaviour as the explicitly calculated duty_cycle used an uprounding division while pwm_set_relative_duty_cycle() rounds down. I don't expect that difference to matter in practice though. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/f194fad5ee8bdd3fda6159324524979729683653.1746006578.git.ukleinek@baylibre.com Signed-off-by: Stephen Boyd <[email protected]>
1 parent 6ae97be commit 574c795

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/clk/clk-pwm.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
struct clk_pwm {
1515
struct clk_hw hw;
1616
struct pwm_device *pwm;
17+
struct pwm_state state;
1718
u32 fixed_rate;
1819
};
1920

@@ -26,7 +27,7 @@ static int clk_pwm_prepare(struct clk_hw *hw)
2627
{
2728
struct clk_pwm *clk_pwm = to_clk_pwm(hw);
2829

29-
return pwm_enable(clk_pwm->pwm);
30+
return pwm_apply_might_sleep(clk_pwm->pwm, &clk_pwm->state);
3031
}
3132

3233
static void clk_pwm_unprepare(struct clk_hw *hw)
@@ -106,15 +107,16 @@ static int clk_pwm_probe(struct platform_device *pdev)
106107
return -EINVAL;
107108
}
108109

109-
/*
110-
* FIXME: pwm_apply_args() should be removed when switching to the
111-
* atomic PWM API.
112-
*/
113-
pwm_apply_args(pwm);
114-
ret = pwm_config(pwm, (pargs.period + 1) >> 1, pargs.period);
110+
pwm_init_state(pwm, &clk_pwm->state);
111+
pwm_set_relative_duty_cycle(&clk_pwm->state, 1, 2);
112+
113+
ret = pwm_apply_might_sleep(pwm, &clk_pwm->state);
115114
if (ret < 0)
116115
return ret;
117116

117+
/* set enabled only now to not enable output above */
118+
clk_pwm->state.enabled = true;
119+
118120
clk_name = node->name;
119121
of_property_read_string(node, "clock-output-names", &clk_name);
120122

0 commit comments

Comments
 (0)