aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-10 07:15:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-10 07:15:24 -0400
commit2474542f64432398f503373f53bdf620491bcfa8 (patch)
tree3c9744b138c2158757530814b35c23eed31cf6ce /include
parentc7a6ced9d8e8411bdafe83998474d185a79badc3 (diff)
parent85f8879ca4f3d26a7f473522101fb74a79bda3f2 (diff)
Merge tag 'for-3.7-rc1' of git://gitorious.org/linux-pwm/linux-pwm
Pull pwm changes from Thierry Reding: "All legacy PWM providers have now been moved to the PWM subsystem. The plan for 3.8 is to adapt all board files to provide a lookup table for PWM devices in order to get rid of the global namespace. Subsequently, users of the legacy pwm_request() and pwm_free() functions can be migrated to the new pwm_get() and pwm_put() functions. Once this has been completed, the legacy API and the compatibility code in the core can be removed. In addition to the above, these changes also add support for configuring the polarity of a PWM signal (currently only supported on ECAP and EHRPWM) and include a much needed rework of the i.MX driver. Managed functions to obtain and release a PWM device (devm_pwm_get() and devm_pwm_put()) have been added and the pwm-backlight driver has been updated to use them. If the PWM subsystem hasn't been enabled, dummy functions are provided that allow the subsystem to safely compile out. Some common checks on input parameters have been moved to the core and removed from the drivers. Finally, a small fix corrects the description of the PWM specifier's second cell in the device tree representation." * tag 'for-3.7-rc1' of git://gitorious.org/linux-pwm/linux-pwm: (23 commits) pwm: dt: Fix description of second PWM cell pwm: Check for negative duty-cycle and period pwm: Add Ingenic JZ4740 support MIPS: JZ4740: Export timer API pwm: Move PUV3 PWM driver to PWM framework unicore32: pwm: Use managed resource allocations unicore32: pwm: Remove unnecessary indirection unicore32: pwm: Use module_platform_driver() unicore32: pwm: Properly remap memory-mapped registers pwm-backlight: Use devm_pwm_get() instead of pwm_get() pwm: Move AB8500 PWM driver to PWM framework pwm: Fix compilation error when CONFIG_PWM is not defined pwm: i.MX: fix clock lookup pwm: i.MX: use per clock unconditionally pwm: i.MX: add devicetree support pwm: i.MX: Use module_platform_driver pwm: i.MX: add functions to enable/disable pwm. pwm: i.MX: remove unnecessary if in pwm_[en|dis]able pwm: i.MX: factor out SoC specific functions pwm: pwm-tiehrpwm: Add support for configuring polarity of PWM ...
Diffstat (limited to 'include')
-rw-r--r--include/linux/pwm.h108
1 files changed, 106 insertions, 2 deletions
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 21d076c5089e..112b31436848 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -1,11 +1,13 @@
1#ifndef __LINUX_PWM_H 1#ifndef __LINUX_PWM_H
2#define __LINUX_PWM_H 2#define __LINUX_PWM_H
3 3
4#include <linux/err.h>
4#include <linux/of.h> 5#include <linux/of.h>
5 6
6struct pwm_device; 7struct pwm_device;
7struct seq_file; 8struct seq_file;
8 9
10#if IS_ENABLED(CONFIG_PWM) || IS_ENABLED(CONFIG_HAVE_PWM)
9/* 11/*
10 * pwm_request - request a PWM device 12 * pwm_request - request a PWM device
11 */ 13 */
@@ -30,10 +32,47 @@ int pwm_enable(struct pwm_device *pwm);
30 * pwm_disable - stop a PWM output toggling 32 * pwm_disable - stop a PWM output toggling
31 */ 33 */
32void pwm_disable(struct pwm_device *pwm); 34void pwm_disable(struct pwm_device *pwm);
35#else
36static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
37{
38 return ERR_PTR(-ENODEV);
39}
40
41static inline void pwm_free(struct pwm_device *pwm)
42{
43}
44
45static inline int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
46{
47 return -EINVAL;
48}
49
50static inline int pwm_enable(struct pwm_device *pwm)
51{
52 return -EINVAL;
53}
54
55static inline void pwm_disable(struct pwm_device *pwm)
56{
57}
58#endif
33 59
34#ifdef CONFIG_PWM
35struct pwm_chip; 60struct pwm_chip;
36 61
62/**
63 * enum pwm_polarity - polarity of a PWM signal
64 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
65 * cycle, followed by a low signal for the remainder of the pulse
66 * period
67 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
68 * cycle, followed by a high signal for the remainder of the pulse
69 * period
70 */
71enum pwm_polarity {
72 PWM_POLARITY_NORMAL,
73 PWM_POLARITY_INVERSED,
74};
75
37enum { 76enum {
38 PWMF_REQUESTED = 1 << 0, 77 PWMF_REQUESTED = 1 << 0,
39 PWMF_ENABLED = 1 << 1, 78 PWMF_ENABLED = 1 << 1,
@@ -61,11 +100,17 @@ static inline unsigned int pwm_get_period(struct pwm_device *pwm)
61 return pwm ? pwm->period : 0; 100 return pwm ? pwm->period : 0;
62} 101}
63 102
103/*
104 * pwm_set_polarity - configure the polarity of a PWM signal
105 */
106int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
107
64/** 108/**
65 * struct pwm_ops - PWM controller operations 109 * struct pwm_ops - PWM controller operations
66 * @request: optional hook for requesting a PWM 110 * @request: optional hook for requesting a PWM
67 * @free: optional hook for freeing a PWM 111 * @free: optional hook for freeing a PWM
68 * @config: configure duty cycles and period length for this PWM 112 * @config: configure duty cycles and period length for this PWM
113 * @set_polarity: configure the polarity of this PWM
69 * @enable: enable PWM output toggling 114 * @enable: enable PWM output toggling
70 * @disable: disable PWM output toggling 115 * @disable: disable PWM output toggling
71 * @dbg_show: optional routine to show contents in debugfs 116 * @dbg_show: optional routine to show contents in debugfs
@@ -79,6 +124,9 @@ struct pwm_ops {
79 int (*config)(struct pwm_chip *chip, 124 int (*config)(struct pwm_chip *chip,
80 struct pwm_device *pwm, 125 struct pwm_device *pwm,
81 int duty_ns, int period_ns); 126 int duty_ns, int period_ns);
127 int (*set_polarity)(struct pwm_chip *chip,
128 struct pwm_device *pwm,
129 enum pwm_polarity polarity);
82 int (*enable)(struct pwm_chip *chip, 130 int (*enable)(struct pwm_chip *chip,
83 struct pwm_device *pwm); 131 struct pwm_device *pwm);
84 void (*disable)(struct pwm_chip *chip, 132 void (*disable)(struct pwm_chip *chip,
@@ -113,6 +161,7 @@ struct pwm_chip {
113 unsigned int of_pwm_n_cells; 161 unsigned int of_pwm_n_cells;
114}; 162};
115 163
164#if IS_ENABLED(CONFIG_PWM)
116int pwm_set_chip_data(struct pwm_device *pwm, void *data); 165int pwm_set_chip_data(struct pwm_device *pwm, void *data);
117void *pwm_get_chip_data(struct pwm_device *pwm); 166void *pwm_get_chip_data(struct pwm_device *pwm);
118 167
@@ -125,6 +174,57 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
125struct pwm_device *pwm_get(struct device *dev, const char *consumer); 174struct pwm_device *pwm_get(struct device *dev, const char *consumer);
126void pwm_put(struct pwm_device *pwm); 175void pwm_put(struct pwm_device *pwm);
127 176
177struct pwm_device *devm_pwm_get(struct device *dev, const char *consumer);
178void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
179#else
180static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
181{
182 return -EINVAL;
183}
184
185static inline void *pwm_get_chip_data(struct pwm_device *pwm)
186{
187 return NULL;
188}
189
190static inline int pwmchip_add(struct pwm_chip *chip)
191{
192 return -EINVAL;
193}
194
195static inline int pwmchip_remove(struct pwm_chip *chip)
196{
197 return -EINVAL;
198}
199
200static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
201 unsigned int index,
202 const char *label)
203{
204 return ERR_PTR(-ENODEV);
205}
206
207static inline struct pwm_device *pwm_get(struct device *dev,
208 const char *consumer)
209{
210 return ERR_PTR(-ENODEV);
211}
212
213static inline void pwm_put(struct pwm_device *pwm)
214{
215}
216
217static inline struct pwm_device *devm_pwm_get(struct device *dev,
218 const char *consumer)
219{
220 return ERR_PTR(-ENODEV);
221}
222
223static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
224{
225}
226#endif
227
128struct pwm_lookup { 228struct pwm_lookup {
129 struct list_head list; 229 struct list_head list;
130 const char *provider; 230 const char *provider;
@@ -141,8 +241,12 @@ struct pwm_lookup {
141 .con_id = _con_id, \ 241 .con_id = _con_id, \
142 } 242 }
143 243
244#if IS_ENABLED(CONFIG_PWM)
144void pwm_add_table(struct pwm_lookup *table, size_t num); 245void pwm_add_table(struct pwm_lookup *table, size_t num);
145 246#else
247static inline void pwm_add_table(struct pwm_lookup *table, size_t num)
248{
249}
146#endif 250#endif
147 251
148#endif /* __LINUX_PWM_H */ 252#endif /* __LINUX_PWM_H */