blob: fd1092729ed6d8f2bb98db8110bd20734dc18034 [file] [log] [blame]
Russell King1a189b92008-04-13 21:41:55 +01001#ifndef __LINUX_PWM_H
2#define __LINUX_PWM_H
3
Tushar Behera0bcf1682012-09-12 15:31:46 +05304#include <linux/err.h>
Jonathan Richardsond1cd2142015-10-16 17:40:58 -07005#include <linux/mutex.h>
Thierry Reding7299ab72011-12-14 11:10:32 +01006#include <linux/of.h>
7
Thierry Reding62099ab2012-03-26 09:31:48 +02008struct seq_file;
Sascha Hauer0c2498f2011-01-28 09:40:40 +01009struct pwm_chip;
10
Philip, Avinash0aa08692012-07-24 19:35:32 +053011/**
12 * enum pwm_polarity - polarity of a PWM signal
13 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
14 * cycle, followed by a low signal for the remainder of the pulse
15 * period
16 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
17 * cycle, followed by a high signal for the remainder of the pulse
18 * period
19 */
20enum pwm_polarity {
21 PWM_POLARITY_NORMAL,
22 PWM_POLARITY_INVERSED,
23};
24
Boris Brezillone39c0df2016-04-14 21:17:21 +020025/**
26 * struct pwm_args - board-dependent PWM arguments
27 * @period: reference period
28 * @polarity: reference polarity
29 *
30 * This structure describes board-dependent arguments attached to a PWM
31 * device. These arguments are usually retrieved from the PWM lookup table or
32 * device tree.
33 *
34 * Do not confuse this with the PWM state: PWM arguments represent the initial
35 * configuration that users want to use on this PWM device rather than the
36 * current PWM hardware state.
37 */
38struct pwm_args {
39 unsigned int period;
40 enum pwm_polarity polarity;
41};
42
Thierry Redingf051c462011-12-14 11:12:23 +010043enum {
44 PWMF_REQUESTED = 1 << 0,
Boris Brezillon09a7e4a2016-04-14 21:17:39 +020045 PWMF_EXPORTED = 1 << 1,
Thierry Redingf051c462011-12-14 11:12:23 +010046};
47
Boris Brezillon43a276b2016-04-14 21:17:38 +020048/*
49 * struct pwm_state - state of a PWM channel
50 * @period: PWM period (in nanoseconds)
51 * @duty_cycle: PWM duty cycle (in nanoseconds)
52 * @polarity: PWM polarity
Boris Brezillon09a7e4a2016-04-14 21:17:39 +020053 * @enabled: PWM enabled status
Boris Brezillon43a276b2016-04-14 21:17:38 +020054 */
55struct pwm_state {
56 unsigned int period;
57 unsigned int duty_cycle;
58 enum pwm_polarity polarity;
Boris Brezillon09a7e4a2016-04-14 21:17:39 +020059 bool enabled;
Boris Brezillon43a276b2016-04-14 21:17:38 +020060};
61
Thierry Reding04883802015-07-27 11:58:32 +020062/**
63 * struct pwm_device - PWM channel object
64 * @label: name of the PWM device
65 * @flags: flags associated with the PWM device
66 * @hwpwm: per-chip relative index of the PWM device
67 * @pwm: global index of the PWM device
68 * @chip: PWM chip providing this PWM device
69 * @chip_data: chip-private data associated with the PWM device
Boris Brezillone39c0df2016-04-14 21:17:21 +020070 * @args: PWM arguments
Boris Brezillon43a276b2016-04-14 21:17:38 +020071 * @state: curent PWM channel state
Thierry Reding04883802015-07-27 11:58:32 +020072 */
Thierry Redingf051c462011-12-14 11:12:23 +010073struct pwm_device {
Thierry Reding6bc70642015-07-27 11:57:28 +020074 const char *label;
75 unsigned long flags;
76 unsigned int hwpwm;
77 unsigned int pwm;
78 struct pwm_chip *chip;
79 void *chip_data;
Thierry Redingf051c462011-12-14 11:12:23 +010080
Boris Brezillone39c0df2016-04-14 21:17:21 +020081 struct pwm_args args;
Boris Brezillon43a276b2016-04-14 21:17:38 +020082 struct pwm_state state;
Thierry Redingf051c462011-12-14 11:12:23 +010083};
84
Boris Brezillon43a276b2016-04-14 21:17:38 +020085/**
86 * pwm_get_state() - retrieve the current PWM state
87 * @pwm: PWM device
88 * @state: state to fill with the current PWM state
89 */
90static inline void pwm_get_state(const struct pwm_device *pwm,
91 struct pwm_state *state)
92{
93 *state = pwm->state;
94}
95
Boris Brezillon5c312522015-07-01 10:21:47 +020096static inline bool pwm_is_enabled(const struct pwm_device *pwm)
97{
Boris Brezillon09a7e4a2016-04-14 21:17:39 +020098 struct pwm_state state;
99
100 pwm_get_state(pwm, &state);
101
102 return state.enabled;
Boris Brezillon5c312522015-07-01 10:21:47 +0200103}
104
Thierry Redingf051c462011-12-14 11:12:23 +0100105static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
106{
107 if (pwm)
Boris Brezillon43a276b2016-04-14 21:17:38 +0200108 pwm->state.period = period;
Thierry Redingf051c462011-12-14 11:12:23 +0100109}
110
Boris Brezillona1cf4212015-07-01 10:21:48 +0200111static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
Thierry Redingf051c462011-12-14 11:12:23 +0100112{
Boris Brezillon43a276b2016-04-14 21:17:38 +0200113 struct pwm_state state;
114
115 pwm_get_state(pwm, &state);
116
117 return state.period;
Thierry Redingf051c462011-12-14 11:12:23 +0100118}
119
H Hartley Sweeten76abbdde2013-06-11 10:38:59 -0700120static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
121{
122 if (pwm)
Boris Brezillon43a276b2016-04-14 21:17:38 +0200123 pwm->state.duty_cycle = duty;
H Hartley Sweeten76abbdde2013-06-11 10:38:59 -0700124}
125
Boris Brezillona1cf4212015-07-01 10:21:48 +0200126static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
H Hartley Sweeten76abbdde2013-06-11 10:38:59 -0700127{
Boris Brezillon43a276b2016-04-14 21:17:38 +0200128 struct pwm_state state;
129
130 pwm_get_state(pwm, &state);
131
132 return state.duty_cycle;
H Hartley Sweeten76abbdde2013-06-11 10:38:59 -0700133}
134
Boris Brezillon011e7632015-07-01 10:21:49 +0200135static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
136{
Boris Brezillon43a276b2016-04-14 21:17:38 +0200137 struct pwm_state state;
138
139 pwm_get_state(pwm, &state);
140
141 return state.polarity;
Boris Brezillon011e7632015-07-01 10:21:49 +0200142}
143
Boris Brezillone39c0df2016-04-14 21:17:21 +0200144static inline void pwm_get_args(const struct pwm_device *pwm,
145 struct pwm_args *args)
146{
147 *args = pwm->args;
148}
149
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100150/**
Boris Brezillona6a0dbb2016-06-14 11:13:09 +0200151 * pwm_init_state() - prepare a new state to be applied with pwm_apply_state()
152 * @pwm: PWM device
153 * @state: state to fill with the prepared PWM state
154 *
155 * This functions prepares a state that can later be tweaked and applied
156 * to the PWM device with pwm_apply_state(). This is a convenient function
157 * that first retrieves the current PWM state and the replaces the period
158 * and polarity fields with the reference values defined in pwm->args.
159 * Once the function returns, you can adjust the ->enabled and ->duty_cycle
160 * fields according to your needs before calling pwm_apply_state().
161 *
162 * ->duty_cycle is initially set to zero to avoid cases where the current
163 * ->duty_cycle value exceed the pwm_args->period one, which would trigger
164 * an error if the user calls pwm_apply_state() without adjusting ->duty_cycle
165 * first.
166 */
167static inline void pwm_init_state(const struct pwm_device *pwm,
168 struct pwm_state *state)
169{
170 struct pwm_args args;
171
172 /* First get the current state. */
173 pwm_get_state(pwm, state);
174
175 /* Then fill it with the reference config */
176 pwm_get_args(pwm, &args);
177
178 state->period = args.period;
179 state->polarity = args.polarity;
180 state->duty_cycle = 0;
181}
182
183/**
Boris Brezillonf6f3bdd2016-06-14 11:13:10 +0200184 * pwm_get_relative_duty_cycle() - Get a relative duty cycle value
185 * @state: PWM state to extract the duty cycle from
186 * @scale: target scale of the relative duty cycle
187 *
188 * This functions converts the absolute duty cycle stored in @state (expressed
189 * in nanosecond) into a value relative to the period.
190 *
191 * For example if you want to get the duty_cycle expressed in percent, call:
192 *
193 * pwm_get_state(pwm, &state);
194 * duty = pwm_get_relative_duty_cycle(&state, 100);
195 */
196static inline unsigned int
197pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale)
198{
199 if (!state->period)
200 return 0;
201
202 return DIV_ROUND_CLOSEST_ULL((u64)state->duty_cycle * scale,
203 state->period);
204}
205
206/**
207 * pwm_set_relative_duty_cycle() - Set a relative duty cycle value
208 * @state: PWM state to fill
209 * @duty_cycle: relative duty cycle value
210 * @scale: scale in which @duty_cycle is expressed
211 *
212 * This functions converts a relative into an absolute duty cycle (expressed
213 * in nanoseconds), and puts the result in state->duty_cycle.
214 *
215 * For example if you want to configure a 50% duty cycle, call:
216 *
217 * pwm_init_state(pwm, &state);
218 * pwm_set_relative_duty_cycle(&state, 50, 100);
219 * pwm_apply_state(pwm, &state);
220 *
221 * This functions returns -EINVAL if @duty_cycle and/or @scale are
222 * inconsistent (@scale == 0 or @duty_cycle > @scale).
223 */
224static inline int
225pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
226 unsigned int scale)
227{
228 if (!scale || duty_cycle > scale)
229 return -EINVAL;
230
231 state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle *
232 state->period,
233 scale);
234
235 return 0;
236}
237
238/**
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100239 * struct pwm_ops - PWM controller operations
240 * @request: optional hook for requesting a PWM
241 * @free: optional hook for freeing a PWM
242 * @config: configure duty cycles and period length for this PWM
Philip, Avinash0aa08692012-07-24 19:35:32 +0530243 * @set_polarity: configure the polarity of this PWM
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100244 * @enable: enable PWM output toggling
245 * @disable: disable PWM output toggling
Boris Brezillon5ec803e2016-04-14 21:17:41 +0200246 * @apply: atomically apply a new PWM config. The state argument
247 * should be adjusted with the real hardware config (if the
248 * approximate the period or duty_cycle value, state should
249 * reflect it)
Boris Brezillon15fa8a432016-04-14 21:17:40 +0200250 * @get_state: get the current PWM state. This function is only
251 * called once per PWM device when the PWM chip is
252 * registered.
Thierry Reding62099ab2012-03-26 09:31:48 +0200253 * @dbg_show: optional routine to show contents in debugfs
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100254 * @owner: helps prevent removal of modules exporting active PWMs
255 */
256struct pwm_ops {
Thierry Reding6bc70642015-07-27 11:57:28 +0200257 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
258 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
259 int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
260 int duty_ns, int period_ns);
261 int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
262 enum pwm_polarity polarity);
263 int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
264 void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
Boris Brezillon5ec803e2016-04-14 21:17:41 +0200265 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
266 struct pwm_state *state);
Boris Brezillon15fa8a432016-04-14 21:17:40 +0200267 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
268 struct pwm_state *state);
Thierry Reding62099ab2012-03-26 09:31:48 +0200269#ifdef CONFIG_DEBUG_FS
Thierry Reding6bc70642015-07-27 11:57:28 +0200270 void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
Thierry Reding62099ab2012-03-26 09:31:48 +0200271#endif
Thierry Reding6bc70642015-07-27 11:57:28 +0200272 struct module *owner;
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100273};
274
275/**
Thierry Redingf051c462011-12-14 11:12:23 +0100276 * struct pwm_chip - abstract a PWM controller
277 * @dev: device providing the PWMs
278 * @list: list node for internal use
279 * @ops: callbacks for this PWM controller
280 * @base: number of first PWM controlled by this chip
281 * @npwm: number of PWMs controlled by this chip
282 * @pwms: array of PWM devices allocated by the framework
Thierry Reding04883802015-07-27 11:58:32 +0200283 * @of_xlate: request a PWM device given a device tree PWM specifier
284 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
Florian Vaussard6e69ab12013-01-28 15:00:57 +0100285 * @can_sleep: must be true if the .config(), .enable() or .disable()
286 * operations may sleep
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100287 */
288struct pwm_chip {
Thierry Reding6bc70642015-07-27 11:57:28 +0200289 struct device *dev;
290 struct list_head list;
291 const struct pwm_ops *ops;
292 int base;
293 unsigned int npwm;
Thierry Redingf051c462011-12-14 11:12:23 +0100294
Thierry Reding6bc70642015-07-27 11:57:28 +0200295 struct pwm_device *pwms;
Thierry Reding7299ab72011-12-14 11:10:32 +0100296
Thierry Reding6bc70642015-07-27 11:57:28 +0200297 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
298 const struct of_phandle_args *args);
299 unsigned int of_pwm_n_cells;
300 bool can_sleep;
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100301};
302
Tushar Behera0bcf1682012-09-12 15:31:46 +0530303#if IS_ENABLED(CONFIG_PWM)
Boris Brezillon5ec803e2016-04-14 21:17:41 +0200304/* PWM user APIs */
305struct pwm_device *pwm_request(int pwm_id, const char *label);
306void pwm_free(struct pwm_device *pwm);
307int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state);
308int pwm_adjust_config(struct pwm_device *pwm);
309
310/**
311 * pwm_config() - change a PWM device configuration
312 * @pwm: PWM device
313 * @duty_ns: "on" time (in nanoseconds)
314 * @period_ns: duration (in nanoseconds) of one cycle
315 *
316 * Returns: 0 on success or a negative error code on failure.
317 */
318static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
319 int period_ns)
320{
321 struct pwm_state state;
322
323 if (!pwm)
324 return -EINVAL;
325
326 pwm_get_state(pwm, &state);
327 if (state.duty_cycle == duty_ns && state.period == period_ns)
328 return 0;
329
330 state.duty_cycle = duty_ns;
331 state.period = period_ns;
332 return pwm_apply_state(pwm, &state);
333}
334
335/**
336 * pwm_set_polarity() - configure the polarity of a PWM signal
337 * @pwm: PWM device
338 * @polarity: new polarity of the PWM signal
339 *
340 * Note that the polarity cannot be configured while the PWM device is
341 * enabled.
342 *
343 * Returns: 0 on success or a negative error code on failure.
344 */
345static inline int pwm_set_polarity(struct pwm_device *pwm,
346 enum pwm_polarity polarity)
347{
348 struct pwm_state state;
349
350 if (!pwm)
351 return -EINVAL;
352
353 pwm_get_state(pwm, &state);
354 if (state.polarity == polarity)
355 return 0;
356
357 /*
358 * Changing the polarity of a running PWM without adjusting the
359 * dutycycle/period value is a bit risky (can introduce glitches).
360 * Return -EBUSY in this case.
361 * Note that this is allowed when using pwm_apply_state() because
362 * the user specifies all the parameters.
363 */
364 if (state.enabled)
365 return -EBUSY;
366
367 state.polarity = polarity;
368 return pwm_apply_state(pwm, &state);
369}
370
371/**
372 * pwm_enable() - start a PWM output toggling
373 * @pwm: PWM device
374 *
375 * Returns: 0 on success or a negative error code on failure.
376 */
377static inline int pwm_enable(struct pwm_device *pwm)
378{
379 struct pwm_state state;
380
381 if (!pwm)
382 return -EINVAL;
383
384 pwm_get_state(pwm, &state);
385 if (state.enabled)
386 return 0;
387
388 state.enabled = true;
389 return pwm_apply_state(pwm, &state);
390}
391
392/**
393 * pwm_disable() - stop a PWM output toggling
394 * @pwm: PWM device
395 */
396static inline void pwm_disable(struct pwm_device *pwm)
397{
398 struct pwm_state state;
399
400 if (!pwm)
401 return;
402
403 pwm_get_state(pwm, &state);
404 if (!state.enabled)
405 return;
406
407 state.enabled = false;
408 pwm_apply_state(pwm, &state);
409}
410
411
412/* PWM provider APIs */
Thierry Redingf051c462011-12-14 11:12:23 +0100413int pwm_set_chip_data(struct pwm_device *pwm, void *data);
414void *pwm_get_chip_data(struct pwm_device *pwm);
415
Tim Krygerb6a00fa2015-05-26 13:08:16 -0700416int pwmchip_add_with_polarity(struct pwm_chip *chip,
417 enum pwm_polarity polarity);
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100418int pwmchip_add(struct pwm_chip *chip);
419int pwmchip_remove(struct pwm_chip *chip);
Thierry Redingf051c462011-12-14 11:12:23 +0100420struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
421 unsigned int index,
422 const char *label);
Thierry Reding8138d2d2012-03-26 08:42:48 +0200423
Philip, Avinash83af2402012-11-21 13:10:44 +0530424struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
425 const struct of_phandle_args *args);
426
Peter Ujfalusid4c0c472012-12-21 01:43:57 -0800427struct pwm_device *pwm_get(struct device *dev, const char *con_id);
Peter Ujfalusi8eb96122012-12-21 01:43:58 -0800428struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id);
Thierry Reding8138d2d2012-03-26 08:42:48 +0200429void pwm_put(struct pwm_device *pwm);
430
Peter Ujfalusid4c0c472012-12-21 01:43:57 -0800431struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
Peter Ujfalusi261a5ed2012-12-21 01:43:59 -0800432struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
433 const char *con_id);
Alexandre Courbot63543162012-08-01 19:20:58 +0900434void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
Florian Vaussard6e69ab12013-01-28 15:00:57 +0100435
436bool pwm_can_sleep(struct pwm_device *pwm);
Tushar Behera0bcf1682012-09-12 15:31:46 +0530437#else
Boris Brezillon5ec803e2016-04-14 21:17:41 +0200438static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
439{
440 return ERR_PTR(-ENODEV);
441}
442
443static inline void pwm_free(struct pwm_device *pwm)
444{
445}
446
447static inline int pwm_apply_state(struct pwm_device *pwm,
448 const struct pwm_state *state)
449{
450 return -ENOTSUPP;
451}
452
453static inline int pwm_adjust_config(struct pwm_device *pwm)
454{
455 return -ENOTSUPP;
456}
457
458static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
459 int period_ns)
460{
461 return -EINVAL;
462}
463
464static inline int pwm_set_polarity(struct pwm_device *pwm,
465 enum pwm_polarity polarity)
466{
467 return -ENOTSUPP;
468}
469
470static inline int pwm_enable(struct pwm_device *pwm)
471{
472 return -EINVAL;
473}
474
475static inline void pwm_disable(struct pwm_device *pwm)
476{
477}
478
Tushar Behera0bcf1682012-09-12 15:31:46 +0530479static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
480{
481 return -EINVAL;
482}
483
484static inline void *pwm_get_chip_data(struct pwm_device *pwm)
485{
486 return NULL;
487}
488
489static inline int pwmchip_add(struct pwm_chip *chip)
490{
491 return -EINVAL;
492}
493
Tim Krygerb6a00fa2015-05-26 13:08:16 -0700494static inline int pwmchip_add_inversed(struct pwm_chip *chip)
495{
496 return -EINVAL;
497}
498
Tushar Behera0bcf1682012-09-12 15:31:46 +0530499static inline int pwmchip_remove(struct pwm_chip *chip)
500{
501 return -EINVAL;
502}
503
504static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
505 unsigned int index,
506 const char *label)
507{
508 return ERR_PTR(-ENODEV);
509}
510
511static inline struct pwm_device *pwm_get(struct device *dev,
512 const char *consumer)
513{
514 return ERR_PTR(-ENODEV);
515}
516
Peter Ujfalusi8eb96122012-12-21 01:43:58 -0800517static inline struct pwm_device *of_pwm_get(struct device_node *np,
518 const char *con_id)
519{
520 return ERR_PTR(-ENODEV);
521}
522
Tushar Behera0bcf1682012-09-12 15:31:46 +0530523static inline void pwm_put(struct pwm_device *pwm)
524{
525}
526
527static inline struct pwm_device *devm_pwm_get(struct device *dev,
528 const char *consumer)
529{
530 return ERR_PTR(-ENODEV);
531}
532
Peter Ujfalusi261a5ed2012-12-21 01:43:59 -0800533static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
534 struct device_node *np,
535 const char *con_id)
536{
537 return ERR_PTR(-ENODEV);
538}
539
Tushar Behera0bcf1682012-09-12 15:31:46 +0530540static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
541{
542}
Florian Vaussard6e69ab12013-01-28 15:00:57 +0100543
544static inline bool pwm_can_sleep(struct pwm_device *pwm)
545{
546 return false;
547}
Tushar Behera0bcf1682012-09-12 15:31:46 +0530548#endif
Alexandre Courbot63543162012-08-01 19:20:58 +0900549
Boris Brezillon5ec803e2016-04-14 21:17:41 +0200550static inline void pwm_apply_args(struct pwm_device *pwm)
551{
552 /*
553 * PWM users calling pwm_apply_args() expect to have a fresh config
554 * where the polarity and period are set according to pwm_args info.
555 * The problem is, polarity can only be changed when the PWM is
556 * disabled.
557 *
558 * PWM drivers supporting hardware readout may declare the PWM device
559 * as enabled, and prevent polarity setting, which changes from the
560 * existing behavior, where all PWM devices are declared as disabled
561 * at startup (even if they are actually enabled), thus authorizing
562 * polarity setting.
563 *
564 * Instead of setting ->enabled to false, we call pwm_disable()
565 * before pwm_set_polarity() to ensure that everything is configured
566 * as expected, and the PWM is really disabled when the user request
567 * it.
568 *
569 * Note that PWM users requiring a smooth handover between the
570 * bootloader and the kernel (like critical regulators controlled by
571 * PWM devices) will have to switch to the atomic API and avoid calling
572 * pwm_apply_args().
573 */
574 pwm_disable(pwm);
575 pwm_set_polarity(pwm, pwm->args.polarity);
576}
577
Thierry Reding8138d2d2012-03-26 08:42:48 +0200578struct pwm_lookup {
579 struct list_head list;
580 const char *provider;
581 unsigned int index;
582 const char *dev_id;
583 const char *con_id;
Alexandre Belloni3796ce12014-05-19 22:42:32 +0200584 unsigned int period;
585 enum pwm_polarity polarity;
Thierry Reding8138d2d2012-03-26 08:42:48 +0200586};
587
Alexandre Belloni42844022014-05-19 22:42:37 +0200588#define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
Thierry Reding8138d2d2012-03-26 08:42:48 +0200589 { \
590 .provider = _provider, \
591 .index = _index, \
592 .dev_id = _dev_id, \
593 .con_id = _con_id, \
Alexandre Belloni42844022014-05-19 22:42:37 +0200594 .period = _period, \
595 .polarity = _polarity \
Thierry Reding8138d2d2012-03-26 08:42:48 +0200596 }
597
Tushar Behera0bcf1682012-09-12 15:31:46 +0530598#if IS_ENABLED(CONFIG_PWM)
Thierry Reding8138d2d2012-03-26 08:42:48 +0200599void pwm_add_table(struct pwm_lookup *table, size_t num);
Shobhit Kumarefb0de52015-05-05 15:04:18 +0530600void pwm_remove_table(struct pwm_lookup *table, size_t num);
Tushar Behera0bcf1682012-09-12 15:31:46 +0530601#else
602static inline void pwm_add_table(struct pwm_lookup *table, size_t num)
603{
604}
Shobhit Kumarefb0de52015-05-05 15:04:18 +0530605
606static inline void pwm_remove_table(struct pwm_lookup *table, size_t num)
607{
608}
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100609#endif
610
H Hartley Sweeten76abbdde2013-06-11 10:38:59 -0700611#ifdef CONFIG_PWM_SYSFS
612void pwmchip_sysfs_export(struct pwm_chip *chip);
613void pwmchip_sysfs_unexport(struct pwm_chip *chip);
614#else
615static inline void pwmchip_sysfs_export(struct pwm_chip *chip)
616{
617}
618
619static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip)
620{
621}
622#endif /* CONFIG_PWM_SYSFS */
623
Mark Vels5243ef82009-01-18 18:42:45 +0100624#endif /* __LINUX_PWM_H */