Commit 1695b421 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding

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: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tested-by: default avatarEmil Renner Berthing <emil.renner.berthing@canonical.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 3586b026
...@@ -168,24 +168,24 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -168,24 +168,24 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
} }
mutex_unlock(&ddata->lock); mutex_unlock(&ddata->lock);
ret = clk_enable(ddata->clk); /*
if (ret) { * If the PWM is enabled the clk is already on. So only enable it
dev_err(ddata->chip.dev, "Enable clk failed\n"); * conditionally to have it on exactly once afterwards independent of
return ret; * 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)); writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
if (state->enabled != enabled) { if (!state->enabled)
if (state->enabled) { clk_disable(ddata->clk);
if (clk_enable(ddata->clk))
dev_err(ddata->chip.dev, "Enable clk failed\n");
} else {
clk_disable(ddata->clk);
}
}
clk_disable(ddata->clk);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment