From 0aa0869c3c9b10338dd92a20fa4a9b6959f177b5 Mon Sep 17 00:00:00 2001 From: "Philip, Avinash" Date: Tue, 24 Jul 2012 19:35:32 +0530 Subject: pwm: Add support for configuring the PWM polarity Some hardware supports inverting the polarity of the PWM signal. This commit adds support to the PWM framework to allow users of the PWM API to configure the polarity. Note that in order to reduce complexity, changing the polarity of a PWM signal is only allowed while the PWM is disabled. A practical example where this can prove useful is to simulate inversion of the duty cycle. While inversion of polarity and duty cycle are not exactly the same, the differences for most use-cases are negligible. Signed-off-by: Philip, Avinash Signed-off-by: Thierry Reding --- drivers/pwm/core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'drivers/pwm') diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index c6e05078d3ad..85592e97ef2d 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -378,6 +378,28 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) } EXPORT_SYMBOL_GPL(pwm_config); +/** + * pwm_set_polarity() - configure the polarity of a PWM signal + * @pwm: PWM device + * @polarity: new polarity of the PWM signal + * + * Note that the polarity cannot be configured while the PWM device is enabled + */ +int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity) +{ + if (!pwm || !pwm->chip->ops) + return -EINVAL; + + if (!pwm->chip->ops->set_polarity) + return -ENOSYS; + + if (test_bit(PWMF_ENABLED, &pwm->flags)) + return -EBUSY; + + return pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity); +} +EXPORT_SYMBOL_GPL(pwm_set_polarity); + /** * pwm_enable() - start a PWM output toggling * @pwm: PWM device -- cgit v1.2.3