pwm: Move the enabled/disabled info into pwm_state

Prepare the transition to PWM atomic update by moving the enabled and
disabled state into the pwm_state struct. This way we can easily update
the whole PWM state by copying the new state in the ->state field.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
Boris Brezillon
2016-04-14 21:17:39 +02:00
committed by Thierry Reding
parent 43a276b003
commit 09a7e4a3d9
2 changed files with 17 additions and 7 deletions

View File

@@ -499,10 +499,10 @@ int pwm_enable(struct pwm_device *pwm)
if (!pwm)
return -EINVAL;
if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) {
if (!pwm_is_enabled(pwm)) {
err = pwm->chip->ops->enable(pwm->chip, pwm);
if (err)
clear_bit(PWMF_ENABLED, &pwm->flags);
if (!err)
pwm->state.enabled = true;
}
return err;
@@ -515,8 +515,13 @@ EXPORT_SYMBOL_GPL(pwm_enable);
*/
void pwm_disable(struct pwm_device *pwm)
{
if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
if (!pwm)
return;
if (pwm_is_enabled(pwm)) {
pwm->chip->ops->disable(pwm->chip, pwm);
pwm->state.enabled = false;
}
}
EXPORT_SYMBOL_GPL(pwm_disable);