354764cf5f7a73428ff02ac4df72b23c7313e55b
[deliverable/linux.git] / include / linux / pwm.h
1 #ifndef __LINUX_PWM_H
2 #define __LINUX_PWM_H
3
4 #include <linux/of.h>
5
6 struct pwm_device;
7 struct seq_file;
8
9 /*
10 * pwm_request - request a PWM device
11 */
12 struct pwm_device *pwm_request(int pwm_id, const char *label);
13
14 /*
15 * pwm_free - free a PWM device
16 */
17 void pwm_free(struct pwm_device *pwm);
18
19 /*
20 * pwm_config - change a PWM device configuration
21 */
22 int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
23
24 /*
25 * pwm_enable - start a PWM output toggling
26 */
27 int pwm_enable(struct pwm_device *pwm);
28
29 /*
30 * pwm_disable - stop a PWM output toggling
31 */
32 void pwm_disable(struct pwm_device *pwm);
33
34 #ifdef CONFIG_PWM
35 struct pwm_chip;
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 */
46 enum pwm_polarity {
47 PWM_POLARITY_NORMAL,
48 PWM_POLARITY_INVERSED,
49 };
50
51 enum {
52 PWMF_REQUESTED = 1 << 0,
53 PWMF_ENABLED = 1 << 1,
54 };
55
56 struct pwm_device {
57 const char *label;
58 unsigned long flags;
59 unsigned int hwpwm;
60 unsigned int pwm;
61 struct pwm_chip *chip;
62 void *chip_data;
63
64 unsigned int period; /* in nanoseconds */
65 };
66
67 static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
68 {
69 if (pwm)
70 pwm->period = period;
71 }
72
73 static inline unsigned int pwm_get_period(struct pwm_device *pwm)
74 {
75 return pwm ? pwm->period : 0;
76 }
77
78 /*
79 * pwm_set_polarity - configure the polarity of a PWM signal
80 */
81 int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
82
83 /**
84 * struct pwm_ops - PWM controller operations
85 * @request: optional hook for requesting a PWM
86 * @free: optional hook for freeing a PWM
87 * @config: configure duty cycles and period length for this PWM
88 * @set_polarity: configure the polarity of this PWM
89 * @enable: enable PWM output toggling
90 * @disable: disable PWM output toggling
91 * @dbg_show: optional routine to show contents in debugfs
92 * @owner: helps prevent removal of modules exporting active PWMs
93 */
94 struct pwm_ops {
95 int (*request)(struct pwm_chip *chip,
96 struct pwm_device *pwm);
97 void (*free)(struct pwm_chip *chip,
98 struct pwm_device *pwm);
99 int (*config)(struct pwm_chip *chip,
100 struct pwm_device *pwm,
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);
105 int (*enable)(struct pwm_chip *chip,
106 struct pwm_device *pwm);
107 void (*disable)(struct pwm_chip *chip,
108 struct pwm_device *pwm);
109 #ifdef CONFIG_DEBUG_FS
110 void (*dbg_show)(struct pwm_chip *chip,
111 struct seq_file *s);
112 #endif
113 struct module *owner;
114 };
115
116 /**
117 * struct pwm_chip - abstract a PWM controller
118 * @dev: device providing the PWMs
119 * @list: list node for internal use
120 * @ops: callbacks for this PWM controller
121 * @base: number of first PWM controlled by this chip
122 * @npwm: number of PWMs controlled by this chip
123 * @pwms: array of PWM devices allocated by the framework
124 */
125 struct pwm_chip {
126 struct device *dev;
127 struct list_head list;
128 const struct pwm_ops *ops;
129 int base;
130 unsigned int npwm;
131
132 struct pwm_device *pwms;
133
134 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
135 const struct of_phandle_args *args);
136 unsigned int of_pwm_n_cells;
137 };
138
139 int pwm_set_chip_data(struct pwm_device *pwm, void *data);
140 void *pwm_get_chip_data(struct pwm_device *pwm);
141
142 int pwmchip_add(struct pwm_chip *chip);
143 int pwmchip_remove(struct pwm_chip *chip);
144 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
145 unsigned int index,
146 const char *label);
147
148 struct pwm_device *pwm_get(struct device *dev, const char *consumer);
149 void pwm_put(struct pwm_device *pwm);
150
151 struct pwm_lookup {
152 struct list_head list;
153 const char *provider;
154 unsigned int index;
155 const char *dev_id;
156 const char *con_id;
157 };
158
159 #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id) \
160 { \
161 .provider = _provider, \
162 .index = _index, \
163 .dev_id = _dev_id, \
164 .con_id = _con_id, \
165 }
166
167 void pwm_add_table(struct pwm_lookup *table, size_t num);
168
169 #endif
170
171 #endif /* __LINUX_PWM_H */
This page took 0.032582 seconds and 4 git commands to generate.