aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Kryger <tim.kryger@gmail.com>2015-05-26 16:08:16 -0400
committerThierry Reding <thierry.reding@gmail.com>2015-06-12 05:36:30 -0400
commitb6a00fae9760a49114016e4764d09e522a5ba5b6 (patch)
tree88bb0e1cc5c1ca9c4eb66d8c7a2a3c54bf958387
parent472ac3dcac108d6648ee28616c6de1e3b0bb361f (diff)
pwm: Add pwmchip_add_with_polarity() API
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>
-rw-r--r--drivers/pwm/core.c23
-rw-r--r--include/linux/pwm.h7
2 files changed, 27 insertions, 3 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 27cd58d16881..3a7769fe53de 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -223,13 +223,16 @@ void *pwm_get_chip_data(struct pwm_device *pwm)
223EXPORT_SYMBOL_GPL(pwm_get_chip_data); 223EXPORT_SYMBOL_GPL(pwm_get_chip_data);
224 224
225/** 225/**
226 * pwmchip_add() - register a new PWM chip 226 * pwmchip_add_with_polarity() - register a new PWM chip
227 * @chip: the PWM chip to add 227 * @chip: the PWM chip to add
228 * @polarity: initial polarity of PWM channels
228 * 229 *
229 * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base 230 * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
230 * will be used. 231 * will be used. The initial polarity for all channels is specified by the
232 * @polarity parameter.
231 */ 233 */
232int pwmchip_add(struct pwm_chip *chip) 234int pwmchip_add_with_polarity(struct pwm_chip *chip,
235 enum pwm_polarity polarity)
233{ 236{
234 struct pwm_device *pwm; 237 struct pwm_device *pwm;
235 unsigned int i; 238 unsigned int i;
@@ -259,6 +262,7 @@ int pwmchip_add(struct pwm_chip *chip)
259 pwm->chip = chip; 262 pwm->chip = chip;
260 pwm->pwm = chip->base + i; 263 pwm->pwm = chip->base + i;
261 pwm->hwpwm = i; 264 pwm->hwpwm = i;
265 pwm->polarity = polarity;
262 266
263 radix_tree_insert(&pwm_tree, pwm->pwm, pwm); 267 radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
264 } 268 }
@@ -279,6 +283,19 @@ out:
279 mutex_unlock(&pwm_lock); 283 mutex_unlock(&pwm_lock);
280 return ret; 284 return ret;
281} 285}
286EXPORT_SYMBOL_GPL(pwmchip_add_with_polarity);
287
288/**
289 * pwmchip_add() - register a new PWM chip
290 * @chip: the PWM chip to add
291 *
292 * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
293 * will be used. The initial polarity for all channels is normal.
294 */
295int pwmchip_add(struct pwm_chip *chip)
296{
297 return pwmchip_add_with_polarity(chip, PWM_POLARITY_NORMAL);
298}
282EXPORT_SYMBOL_GPL(pwmchip_add); 299EXPORT_SYMBOL_GPL(pwmchip_add);
283 300
284/** 301/**
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index cfe2d8df5be0..36262d08a9da 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -182,6 +182,8 @@ struct pwm_chip {
182int pwm_set_chip_data(struct pwm_device *pwm, void *data); 182int pwm_set_chip_data(struct pwm_device *pwm, void *data);
183void *pwm_get_chip_data(struct pwm_device *pwm); 183void *pwm_get_chip_data(struct pwm_device *pwm);
184 184
185int pwmchip_add_with_polarity(struct pwm_chip *chip,
186 enum pwm_polarity polarity);
185int pwmchip_add(struct pwm_chip *chip); 187int pwmchip_add(struct pwm_chip *chip);
186int pwmchip_remove(struct pwm_chip *chip); 188int pwmchip_remove(struct pwm_chip *chip);
187struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, 189struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
@@ -217,6 +219,11 @@ static inline int pwmchip_add(struct pwm_chip *chip)
217 return -EINVAL; 219 return -EINVAL;
218} 220}
219 221
222static inline int pwmchip_add_inversed(struct pwm_chip *chip)
223{
224 return -EINVAL;
225}
226
220static inline int pwmchip_remove(struct pwm_chip *chip) 227static inline int pwmchip_remove(struct pwm_chip *chip)
221{ 228{
222 return -EINVAL; 229 return -EINVAL;