blob: 57103911f4c759a907ff827f7f028bfad9f4ce66 [file] [log] [blame]
Russell King1a189b92008-04-13 21:41:55 +01001#ifndef __LINUX_PWM_H
2#define __LINUX_PWM_H
3
4struct pwm_device;
5
6/*
7 * pwm_request - request a PWM device
8 */
9struct pwm_device *pwm_request(int pwm_id, const char *label);
10
11/*
12 * pwm_free - free a PWM device
13 */
14void pwm_free(struct pwm_device *pwm);
15
16/*
17 * pwm_config - change a PWM device configuration
18 */
19int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
20
21/*
22 * pwm_enable - start a PWM output toggling
23 */
24int pwm_enable(struct pwm_device *pwm);
25
26/*
27 * pwm_disable - stop a PWM output toggling
28 */
29void pwm_disable(struct pwm_device *pwm);
30
Sascha Hauer0c2498f2011-01-28 09:40:40 +010031#ifdef CONFIG_PWM
32struct pwm_chip;
33
Thierry Redingf051c462011-12-14 11:12:23 +010034enum {
35 PWMF_REQUESTED = 1 << 0,
36 PWMF_ENABLED = 1 << 1,
37};
38
39struct pwm_device {
40 const char *label;
41 unsigned long flags;
42 unsigned int hwpwm;
43 unsigned int pwm;
44 struct pwm_chip *chip;
45 void *chip_data;
46
47 unsigned int period; /* in nanoseconds */
48};
49
50static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
51{
52 if (pwm)
53 pwm->period = period;
54}
55
56static inline unsigned int pwm_get_period(struct pwm_device *pwm)
57{
58 return pwm ? pwm->period : 0;
59}
60
Sascha Hauer0c2498f2011-01-28 09:40:40 +010061/**
62 * struct pwm_ops - PWM controller operations
63 * @request: optional hook for requesting a PWM
64 * @free: optional hook for freeing a PWM
65 * @config: configure duty cycles and period length for this PWM
66 * @enable: enable PWM output toggling
67 * @disable: disable PWM output toggling
68 * @owner: helps prevent removal of modules exporting active PWMs
69 */
70struct pwm_ops {
Thierry Redingf051c462011-12-14 11:12:23 +010071 int (*request)(struct pwm_chip *chip,
72 struct pwm_device *pwm);
73 void (*free)(struct pwm_chip *chip,
74 struct pwm_device *pwm);
75 int (*config)(struct pwm_chip *chip,
76 struct pwm_device *pwm,
77 int duty_ns, int period_ns);
78 int (*enable)(struct pwm_chip *chip,
79 struct pwm_device *pwm);
80 void (*disable)(struct pwm_chip *chip,
81 struct pwm_device *pwm);
Sascha Hauer0c2498f2011-01-28 09:40:40 +010082 struct module *owner;
83};
84
85/**
Thierry Redingf051c462011-12-14 11:12:23 +010086 * struct pwm_chip - abstract a PWM controller
87 * @dev: device providing the PWMs
88 * @list: list node for internal use
89 * @ops: callbacks for this PWM controller
90 * @base: number of first PWM controlled by this chip
91 * @npwm: number of PWMs controlled by this chip
92 * @pwms: array of PWM devices allocated by the framework
Sascha Hauer0c2498f2011-01-28 09:40:40 +010093 */
94struct pwm_chip {
Thierry Redingf051c462011-12-14 11:12:23 +010095 struct device *dev;
96 struct list_head list;
97 const struct pwm_ops *ops;
98 int base;
99 unsigned int npwm;
100
101 struct pwm_device *pwms;
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100102};
103
Thierry Redingf051c462011-12-14 11:12:23 +0100104int pwm_set_chip_data(struct pwm_device *pwm, void *data);
105void *pwm_get_chip_data(struct pwm_device *pwm);
106
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100107int pwmchip_add(struct pwm_chip *chip);
108int pwmchip_remove(struct pwm_chip *chip);
Thierry Redingf051c462011-12-14 11:12:23 +0100109struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
110 unsigned int index,
111 const char *label);
Sascha Hauer0c2498f2011-01-28 09:40:40 +0100112#endif
113
Mark Vels5243ef82009-01-18 18:42:45 +0100114#endif /* __LINUX_PWM_H */