summaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2022-07-21 12:31:27 +0200
committerThierry Reding <thierry.reding@gmail.com>2022-07-29 13:40:58 +0200
commit1695b421e1b587caf7931eae927a9c5fb34a75f1 (patch)
treeedc3285a15e4031f5675311fdb154d828d0df10b /drivers/pwm
parent3586b02663f098a9b0a3df13bcb3ea2d67635562 (diff)
downloadlinux-1695b421e1b587caf7931eae927a9c5fb34a75f1.tar.gz
linux-1695b421e1b587caf7931eae927a9c5fb34a75f1.tar.bz2
linux-1695b421e1b587caf7931eae927a9c5fb34a75f1.zip
pwm: sifive: Simplify clk handling
The clk is necessary for both register access and (enabled) operation of the PWM. Instead of clk_enable() update_hw() if pwm_got_enabled(): clk_enable() elif pwm_got_disabled(): clk_disable() clk_disable() which is some cases only calls clk_enable() to immediately afterwards call clk_disable again, do: if (!prev_state.enabled) clk_enable() # clk enabled exactly once update_hw() if (!next_state.enabled) clk_disable() which is much easier. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Tested-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/pwm-sifive.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
index d833536b5e7a..34d23d56fa25 100644
--- a/drivers/pwm/pwm-sifive.c
+++ b/drivers/pwm/pwm-sifive.c
@@ -168,24 +168,24 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
}
mutex_unlock(&ddata->lock);
- ret = clk_enable(ddata->clk);
- if (ret) {
- dev_err(ddata->chip.dev, "Enable clk failed\n");
- return ret;
+ /*
+ * If the PWM is enabled the clk is already on. So only enable it
+ * conditionally to have it on exactly once afterwards independent of
+ * the PWM state.
+ */
+ if (!enabled) {
+ ret = clk_enable(ddata->clk);
+ if (ret) {
+ dev_err(ddata->chip.dev, "Enable clk failed\n");
+ return ret;
+ }
}
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
- if (state->enabled != enabled) {
- if (state->enabled) {
- if (clk_enable(ddata->clk))
- dev_err(ddata->chip.dev, "Enable clk failed\n");
- } else {
- clk_disable(ddata->clk);
- }
- }
+ if (!state->enabled)
+ clk_disable(ddata->clk);
- clk_disable(ddata->clk);
return 0;
}