]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
clk: pwm: Convert to use pwm_apply_might_sleep()
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Wed, 30 Apr 2025 09:57:47 +0000 (11:57 +0200)
committerStephen Boyd <sboyd@kernel.org>
Fri, 20 Jun 2025 01:09:55 +0000 (18:09 -0700)
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 <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/f194fad5ee8bdd3fda6159324524979729683653.1746006578.git.ukleinek@baylibre.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clk-pwm.c

index 429150bba8cf021b947b875f435f68ad637b07fe..f5e6fef3f4d5dafde15183391667503640bd3f79 100644 (file)
@@ -14,6 +14,7 @@
 struct clk_pwm {
        struct clk_hw hw;
        struct pwm_device *pwm;
+       struct pwm_state state;
        u32 fixed_rate;
 };
 
@@ -26,7 +27,7 @@ static int clk_pwm_prepare(struct clk_hw *hw)
 {
        struct clk_pwm *clk_pwm = to_clk_pwm(hw);
 
-       return pwm_enable(clk_pwm->pwm);
+       return pwm_apply_might_sleep(clk_pwm->pwm, &clk_pwm->state);
 }
 
 static void clk_pwm_unprepare(struct clk_hw *hw)
@@ -106,15 +107,16 @@ static int clk_pwm_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       /*
-        * FIXME: pwm_apply_args() should be removed when switching to the
-        * atomic PWM API.
-        */
-       pwm_apply_args(pwm);
-       ret = pwm_config(pwm, (pargs.period + 1) >> 1, pargs.period);
+       pwm_init_state(pwm, &clk_pwm->state);
+       pwm_set_relative_duty_cycle(&clk_pwm->state, 1, 2);
+
+       ret = pwm_apply_might_sleep(pwm, &clk_pwm->state);
        if (ret < 0)
                return ret;
 
+       /* set enabled only now to not enable output above */
+       clk_pwm->state.enabled = true;
+
        clk_name = node->name;
        of_property_read_string(node, "clock-output-names", &clk_name);