aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/pwm/core.c13
-rw-r--r--include/linux/pwm.h11
2 files changed, 17 insertions, 7 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index f3f91e716a42..c240b5437145 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -499,10 +499,10 @@ int pwm_enable(struct pwm_device *pwm)
499 if (!pwm) 499 if (!pwm)
500 return -EINVAL; 500 return -EINVAL;
501 501
502 if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) { 502 if (!pwm_is_enabled(pwm)) {
503 err = pwm->chip->ops->enable(pwm->chip, pwm); 503 err = pwm->chip->ops->enable(pwm->chip, pwm);
504 if (err) 504 if (!err)
505 clear_bit(PWMF_ENABLED, &pwm->flags); 505 pwm->state.enabled = true;
506 } 506 }
507 507
508 return err; 508 return err;
@@ -515,8 +515,13 @@ EXPORT_SYMBOL_GPL(pwm_enable);
515 */ 515 */
516void pwm_disable(struct pwm_device *pwm) 516void pwm_disable(struct pwm_device *pwm)
517{ 517{
518 if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags)) 518 if (!pwm)
519 return;
520
521 if (pwm_is_enabled(pwm)) {
519 pwm->chip->ops->disable(pwm->chip, pwm); 522 pwm->chip->ops->disable(pwm->chip, pwm);
523 pwm->state.enabled = false;
524 }
520} 525}
521EXPORT_SYMBOL_GPL(pwm_disable); 526EXPORT_SYMBOL_GPL(pwm_disable);
522 527
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 51d4005418f9..150563a806d6 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -94,8 +94,7 @@ struct pwm_args {
94 94
95enum { 95enum {
96 PWMF_REQUESTED = 1 << 0, 96 PWMF_REQUESTED = 1 << 0,
97 PWMF_ENABLED = 1 << 1, 97 PWMF_EXPORTED = 1 << 1,
98 PWMF_EXPORTED = 1 << 2,
99}; 98};
100 99
101/* 100/*
@@ -103,11 +102,13 @@ enum {
103 * @period: PWM period (in nanoseconds) 102 * @period: PWM period (in nanoseconds)
104 * @duty_cycle: PWM duty cycle (in nanoseconds) 103 * @duty_cycle: PWM duty cycle (in nanoseconds)
105 * @polarity: PWM polarity 104 * @polarity: PWM polarity
105 * @enabled: PWM enabled status
106 */ 106 */
107struct pwm_state { 107struct pwm_state {
108 unsigned int period; 108 unsigned int period;
109 unsigned int duty_cycle; 109 unsigned int duty_cycle;
110 enum pwm_polarity polarity; 110 enum pwm_polarity polarity;
111 bool enabled;
111}; 112};
112 113
113/** 114/**
@@ -146,7 +147,11 @@ static inline void pwm_get_state(const struct pwm_device *pwm,
146 147
147static inline bool pwm_is_enabled(const struct pwm_device *pwm) 148static inline bool pwm_is_enabled(const struct pwm_device *pwm)
148{ 149{
149 return test_bit(PWMF_ENABLED, &pwm->flags); 150 struct pwm_state state;
151
152 pwm_get_state(pwm, &state);
153
154 return state.enabled;
150} 155}
151 156
152static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) 157static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)