]> git.karo-electronics.de Git - linux-beck.git/commitdiff
pwm: Add pwmchip_add_with_polarity() API
authorTim Kryger <tim.kryger@gmail.com>
Tue, 26 May 2015 20:08:16 +0000 (13:08 -0700)
committerThierry Reding <thierry.reding@gmail.com>
Fri, 12 Jun 2015 09:36:30 +0000 (11:36 +0200)
Add a new function to register a PWM chip with channels that have their
initial polarity as specified by an additional parameter. This benefits
drivers of controllers that by default operate with inversed polarity
by removing the need to modify the polarity during initialization.

Signed-off-by: Tim Kryger <tim.kryger@gmail.com>
Signed-off-by: Jonathan Richardson <jonathar@broadcom.com>
[thierry.reding@gmail.com: export pwmchip_add_with_polarity()]
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/core.c
include/linux/pwm.h

index 27cd58d16881265e61e6a1c73f15789189040f23..3a7769fe53dee4f3c4c5f0bdca3e829e0fa8d5b6 100644 (file)
@@ -223,13 +223,16 @@ void *pwm_get_chip_data(struct pwm_device *pwm)
 EXPORT_SYMBOL_GPL(pwm_get_chip_data);
 
 /**
- * pwmchip_add() - register a new PWM chip
+ * pwmchip_add_with_polarity() - register a new PWM chip
  * @chip: the PWM chip to add
+ * @polarity: initial polarity of PWM channels
  *
  * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
- * will be used.
+ * will be used. The initial polarity for all channels is specified by the
+ * @polarity parameter.
  */
-int pwmchip_add(struct pwm_chip *chip)
+int pwmchip_add_with_polarity(struct pwm_chip *chip,
+                             enum pwm_polarity polarity)
 {
        struct pwm_device *pwm;
        unsigned int i;
@@ -259,6 +262,7 @@ int pwmchip_add(struct pwm_chip *chip)
                pwm->chip = chip;
                pwm->pwm = chip->base + i;
                pwm->hwpwm = i;
+               pwm->polarity = polarity;
 
                radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
        }
@@ -279,6 +283,19 @@ out:
        mutex_unlock(&pwm_lock);
        return ret;
 }
+EXPORT_SYMBOL_GPL(pwmchip_add_with_polarity);
+
+/**
+ * pwmchip_add() - register a new PWM chip
+ * @chip: the PWM chip to add
+ *
+ * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
+ * will be used. The initial polarity for all channels is normal.
+ */
+int pwmchip_add(struct pwm_chip *chip)
+{
+       return pwmchip_add_with_polarity(chip, PWM_POLARITY_NORMAL);
+}
 EXPORT_SYMBOL_GPL(pwmchip_add);
 
 /**
index cfe2d8df5be062ee6d63a60f36e6a5ba84356fad..36262d08a9dad8aca7eaea494e30348c0b26cb5b 100644 (file)
@@ -182,6 +182,8 @@ struct pwm_chip {
 int pwm_set_chip_data(struct pwm_device *pwm, void *data);
 void *pwm_get_chip_data(struct pwm_device *pwm);
 
+int pwmchip_add_with_polarity(struct pwm_chip *chip,
+                             enum pwm_polarity polarity);
 int pwmchip_add(struct pwm_chip *chip);
 int pwmchip_remove(struct pwm_chip *chip);
 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
@@ -217,6 +219,11 @@ static inline int pwmchip_add(struct pwm_chip *chip)
        return -EINVAL;
 }
 
+static inline int pwmchip_add_inversed(struct pwm_chip *chip)
+{
+       return -EINVAL;
+}
+
 static inline int pwmchip_remove(struct pwm_chip *chip)
 {
        return -EINVAL;