aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/pwm/core.c22
-rw-r--r--include/linux/pwm.h23
2 files changed, 45 insertions, 0 deletions
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
@@ -379,6 +379,28 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
379EXPORT_SYMBOL_GPL(pwm_config); 379EXPORT_SYMBOL_GPL(pwm_config);
380 380
381/** 381/**
382 * pwm_set_polarity() - configure the polarity of a PWM signal
383 * @pwm: PWM device
384 * @polarity: new polarity of the PWM signal
385 *
386 * Note that the polarity cannot be configured while the PWM device is enabled
387 */
388int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
389{
390 if (!pwm || !pwm->chip->ops)
391 return -EINVAL;
392
393 if (!pwm->chip->ops->set_polarity)
394 return -ENOSYS;
395
396 if (test_bit(PWMF_ENABLED, &pwm->flags))
397 return -EBUSY;
398
399 return pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
400}
401EXPORT_SYMBOL_GPL(pwm_set_polarity);
402
403/**
382 * pwm_enable() - start a PWM output toggling 404 * pwm_enable() - start a PWM output toggling
383 * @pwm: PWM device 405 * @pwm: PWM device
384 */ 406 */
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 21d076c5089e..354764cf5f7a 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -34,6 +34,20 @@ void pwm_disable(struct pwm_device *pwm);
34#ifdef CONFIG_PWM 34#ifdef CONFIG_PWM
35struct pwm_chip; 35struct pwm_chip;
36 36
37/**
38 * enum pwm_polarity - polarity of a PWM signal
39 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
40 * cycle, followed by a low signal for the remainder of the pulse
41 * period
42 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
43 * cycle, followed by a high signal for the remainder of the pulse
44 * period
45 */
46enum pwm_polarity {
47 PWM_POLARITY_NORMAL,
48 PWM_POLARITY_INVERSED,
49};
50
37enum { 51enum {
38 PWMF_REQUESTED = 1 << 0, 52 PWMF_REQUESTED = 1 << 0,
39 PWMF_ENABLED = 1 << 1, 53 PWMF_ENABLED = 1 << 1,
@@ -61,11 +75,17 @@ static inline unsigned int pwm_get_period(struct pwm_device *pwm)
61 return pwm ? pwm->period : 0; 75 return pwm ? pwm->period : 0;
62} 76}
63 77
78/*
79 * pwm_set_polarity - configure the polarity of a PWM signal
80 */
81int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
82
64/** 83/**
65 * struct pwm_ops - PWM controller operations 84 * struct pwm_ops - PWM controller operations
66 * @request: optional hook for requesting a PWM 85 * @request: optional hook for requesting a PWM
67 * @free: optional hook for freeing a PWM 86 * @free: optional hook for freeing a PWM
68 * @config: configure duty cycles and period length for this PWM 87 * @config: configure duty cycles and period length for this PWM
88 * @set_polarity: configure the polarity of this PWM
69 * @enable: enable PWM output toggling 89 * @enable: enable PWM output toggling
70 * @disable: disable PWM output toggling 90 * @disable: disable PWM output toggling
71 * @dbg_show: optional routine to show contents in debugfs 91 * @dbg_show: optional routine to show contents in debugfs
@@ -79,6 +99,9 @@ struct pwm_ops {
79 int (*config)(struct pwm_chip *chip, 99 int (*config)(struct pwm_chip *chip,
80 struct pwm_device *pwm, 100 struct pwm_device *pwm,
81 int duty_ns, int period_ns); 101 int duty_ns, int period_ns);
102 int (*set_polarity)(struct pwm_chip *chip,
103 struct pwm_device *pwm,
104 enum pwm_polarity polarity);
82 int (*enable)(struct pwm_chip *chip, 105 int (*enable)(struct pwm_chip *chip,
83 struct pwm_device *pwm); 106 struct pwm_device *pwm);
84 void (*disable)(struct pwm_chip *chip, 107 void (*disable)(struct pwm_chip *chip,