UPSTREAM: pwm: Move the enabled/disabled info into pwm_state
authorBoris Brezillon <boris.brezillon@free-electrons.com>
Thu, 14 Apr 2016 19:17:39 +0000 (21:17 +0200)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 6 Mar 2017 10:28:40 +0000 (18:28 +0800)
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>
(cherry picked from commit 09a7e4a3d9fcb95ade2cb02167e85fbeb8315ce0)

Change-Id: I38808d868c7e73f0ffd49cfb6c0b4b45fa911613
Signed-off-by: David Wu <david.wu@rock-chips.com>
drivers/pwm/core.c
include/linux/pwm.h

index d2ea7f6ef6dd5ad454ee8fe1ce670d4575381673..932d4f7123ea9cd236ff2a0e5a7694efce3075d9 100644 (file)
@@ -502,10 +502,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;
@@ -518,8 +518,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);
 
index c17399a3b65433de7b15734092ee58dc7c68e629..c8348cd121211505103d378f08fbec45a4ebe998 100644 (file)
@@ -94,8 +94,7 @@ struct pwm_args {
 
 enum {
        PWMF_REQUESTED = 1 << 0,
-       PWMF_ENABLED = 1 << 1,
-       PWMF_EXPORTED = 1 << 2,
+       PWMF_EXPORTED = 1 << 1,
 };
 
 /*
@@ -103,11 +102,13 @@ enum {
  * @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;
 };
 
 /**
@@ -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)