Commit | Line | Data |
---|---|---|
1a189b97 RK |
1 | #ifndef __LINUX_PWM_H |
2 | #define __LINUX_PWM_H | |
3 | ||
7299ab70 TR |
4 | #include <linux/of.h> |
5 | ||
1a189b97 | 6 | struct pwm_device; |
62099abf | 7 | struct seq_file; |
1a189b97 RK |
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 | ||
0c2498f1 SH |
34 | #ifdef CONFIG_PWM |
35 | struct pwm_chip; | |
36 | ||
0aa0869c PA |
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 | ||
f051c466 TR |
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 | ||
0aa0869c PA |
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 | ||
0c2498f1 SH |
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 | |
0aa0869c | 88 | * @set_polarity: configure the polarity of this PWM |
0c2498f1 SH |
89 | * @enable: enable PWM output toggling |
90 | * @disable: disable PWM output toggling | |
62099abf | 91 | * @dbg_show: optional routine to show contents in debugfs |
0c2498f1 SH |
92 | * @owner: helps prevent removal of modules exporting active PWMs |
93 | */ | |
94 | struct pwm_ops { | |
f051c466 TR |
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); | |
0aa0869c PA |
102 | int (*set_polarity)(struct pwm_chip *chip, |
103 | struct pwm_device *pwm, | |
104 | enum pwm_polarity polarity); | |
f051c466 TR |
105 | int (*enable)(struct pwm_chip *chip, |
106 | struct pwm_device *pwm); | |
107 | void (*disable)(struct pwm_chip *chip, | |
108 | struct pwm_device *pwm); | |
62099abf TR |
109 | #ifdef CONFIG_DEBUG_FS |
110 | void (*dbg_show)(struct pwm_chip *chip, | |
111 | struct seq_file *s); | |
112 | #endif | |
0c2498f1 SH |
113 | struct module *owner; |
114 | }; | |
115 | ||
116 | /** | |
f051c466 TR |
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 | |
0c2498f1 SH |
124 | */ |
125 | struct pwm_chip { | |
f051c466 TR |
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; | |
7299ab70 TR |
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; | |
0c2498f1 SH |
137 | }; |
138 | ||
f051c466 TR |
139 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); |
140 | void *pwm_get_chip_data(struct pwm_device *pwm); | |
141 | ||
0c2498f1 SH |
142 | int pwmchip_add(struct pwm_chip *chip); |
143 | int pwmchip_remove(struct pwm_chip *chip); | |
f051c466 TR |
144 | struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, |
145 | unsigned int index, | |
146 | const char *label); | |
8138d2dd TR |
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 | ||
0c2498f1 SH |
169 | #endif |
170 | ||
5243ef8b | 171 | #endif /* __LINUX_PWM_H */ |