Skip to content

Commit

Permalink
pwm: Move the enabled/disabled info into pwm_state
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Boris Brezillon authored and Thierry Reding committed May 17, 2016
1 parent 43a276b commit 09a7e4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
11 changes: 8 additions & 3 deletions include/linux/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,21 @@ struct pwm_args {

enum {
PWMF_REQUESTED = 1 << 0,
PWMF_ENABLED = 1 << 1,
PWMF_EXPORTED = 1 << 2,
PWMF_EXPORTED = 1 << 1,
};

/*
* struct pwm_state - state of a PWM channel
* @period: PWM period (in nanoseconds)
* @duty_cycle: PWM duty cycle (in nanoseconds)
* @polarity: PWM polarity
* @enabled: PWM enabled status
*/
struct pwm_state {
unsigned int period;
unsigned int duty_cycle;
enum pwm_polarity polarity;
bool enabled;
};

/**
Expand Down Expand Up @@ -146,7 +147,11 @@ static inline void pwm_get_state(const struct pwm_device *pwm,

static inline bool pwm_is_enabled(const struct pwm_device *pwm)
{
return test_bit(PWMF_ENABLED, &pwm->flags);
struct pwm_state state;

pwm_get_state(pwm, &state);

return state.enabled;
}

static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
Expand Down

0 comments on commit 09a7e4a

Please sign in to comment.