]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
pwm: Introduce the pwm_args concept
authorBoris Brezillon <boris.brezillon@free-electrons.com>
Thu, 14 Apr 2016 19:17:21 +0000 (21:17 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Tue, 3 May 2016 11:44:37 +0000 (13:44 +0200)
Currently the PWM core mixes the current PWM state with the per-platform
reference config (specified through the PWM lookup table, DT definition
or directly hardcoded in PWM drivers).

Create a struct pwm_args to store this reference configuration, so that
PWM users can differentiate between the current and reference
configurations.

Patch all places where pwm->args should be initialized. We keep the
pwm_set_polarity/period() calls until all PWM users are patched to use
pwm_args instead of pwm_get_period/polarity().

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
[thierry.reding@gmail.com: reword kerneldoc comments]
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/core.c
drivers/pwm/pwm-clps711x.c
drivers/pwm/pwm-pxa.c
include/linux/pwm.h

index 7831bc6b51dddb66960f8ef97fde2da1ce33572a..680fbc795a0a350a9c55f5e10e10a7090a8bfaea 100644 (file)
@@ -128,6 +128,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
        set_bit(PWMF_REQUESTED, &pwm->flags);
        pwm->label = label;
 
+       /*
+        * FIXME: This should be removed once all PWM users properly make use
+        * of struct pwm_args to initialize the PWM device. As long as this is
+        * here, the PWM state and hardware state can get out of sync.
+        */
+       pwm_apply_args(pwm);
+
        return 0;
 }
 
@@ -146,12 +153,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
        if (IS_ERR(pwm))
                return pwm;
 
-       pwm_set_period(pwm, args->args[1]);
+       pwm->args.period = args->args[1];
 
        if (args->args[2] & PWM_POLARITY_INVERTED)
-               pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
+               pwm->args.polarity = PWM_POLARITY_INVERSED;
        else
-               pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+               pwm->args.polarity = PWM_POLARITY_NORMAL;
 
        return pwm;
 }
@@ -172,7 +179,7 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
        if (IS_ERR(pwm))
                return pwm;
 
-       pwm_set_period(pwm, args->args[1]);
+       pwm->args.period = args->args[1];
 
        return pwm;
 }
@@ -747,13 +754,13 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
        if (!chip)
                goto out;
 
+       pwm->args.period = chosen->period;
+       pwm->args.polarity = chosen->polarity;
+
        pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
        if (IS_ERR(pwm))
                goto out;
 
-       pwm_set_period(pwm, chosen->period);
-       pwm_set_polarity(pwm, chosen->polarity);
-
 out:
        mutex_unlock(&pwm_lookup_lock);
        return pwm;
index a80c10803636adbd24d79865ee2a1207df90cd5a..7d335422cfdac674dcefe3638c8fe82ac18631ec 100644 (file)
@@ -60,7 +60,7 @@ static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
                return -EINVAL;
 
        /* Store constant period value */
-       pwm_set_period(pwm, DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq));
+       pwm->args.period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq);
 
        return 0;
 }
index cb2f7024cf6846350dd2ac83846e8d0a7b26ee02..58b709f291302158bb1643fdd7f3f5d6dcbcea98 100644 (file)
@@ -160,7 +160,7 @@ pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
        if (IS_ERR(pwm))
                return pwm;
 
-       pwm_set_period(pwm, args->args[0]);
+       pwm->args.period = args->args[0];
 
        return pwm;
 }
index cfc3ed46cad20a26ffa131b51e25927ac6045f4c..b78d27c426290089b76546a8fc27d8b95f7216d0 100644 (file)
@@ -74,6 +74,24 @@ enum pwm_polarity {
        PWM_POLARITY_INVERSED,
 };
 
+/**
+ * struct pwm_args - board-dependent PWM arguments
+ * @period: reference period
+ * @polarity: reference polarity
+ *
+ * This structure describes board-dependent arguments attached to a PWM
+ * device. These arguments are usually retrieved from the PWM lookup table or
+ * device tree.
+ *
+ * Do not confuse this with the PWM state: PWM arguments represent the initial
+ * configuration that users want to use on this PWM device rather than the
+ * current PWM hardware state.
+ */
+struct pwm_args {
+       unsigned int period;
+       enum pwm_polarity polarity;
+};
+
 enum {
        PWMF_REQUESTED = 1 << 0,
        PWMF_ENABLED = 1 << 1,
@@ -92,6 +110,7 @@ enum {
  * @period: period of the PWM signal (in nanoseconds)
  * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
  * @polarity: polarity of the PWM signal
+ * @args: PWM arguments
  */
 struct pwm_device {
        const char *label;
@@ -105,6 +124,8 @@ struct pwm_device {
        unsigned int period;
        unsigned int duty_cycle;
        enum pwm_polarity polarity;
+
+       struct pwm_args args;
 };
 
 static inline bool pwm_is_enabled(const struct pwm_device *pwm)
@@ -144,6 +165,18 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
        return pwm ? pwm->polarity : PWM_POLARITY_NORMAL;
 }
 
+static inline void pwm_get_args(const struct pwm_device *pwm,
+                               struct pwm_args *args)
+{
+       *args = pwm->args;
+}
+
+static inline void pwm_apply_args(struct pwm_device *pwm)
+{
+       pwm_set_period(pwm, pwm->args.period);
+       pwm_set_polarity(pwm, pwm->args.polarity);
+}
+
 /**
  * struct pwm_ops - PWM controller operations
  * @request: optional hook for requesting a PWM