gpio: move GPIOD flags outside #ifdef
[linux-2.6-block.git] / include / linux / gpio / consumer.h
CommitLineData
79a9becd
AC
1#ifndef __LINUX_GPIO_CONSUMER_H
2#define __LINUX_GPIO_CONSUMER_H
3
cdf86cd2 4#include <linux/bug.h>
79a9becd
AC
5#include <linux/err.h>
6#include <linux/kernel.h>
7
79a9becd 8struct device;
79a9becd
AC
9
10/**
11 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
12 * preferable to the old integer-based handles.
13 *
14 * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
15 * until the GPIO is released.
16 */
17struct gpio_desc;
18
39b2bbe3
AC
19#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
20#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
21#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
22
23/**
24 * Optional flags that can be passed to one of gpiod_* to configure direction
25 * and output value. These values cannot be OR'd.
26 */
27enum gpiod_flags {
28 GPIOD_ASIS = 0,
29 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
30 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
31 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
32 GPIOD_FLAGS_BIT_DIR_VAL,
33};
34
58b84f6a
LW
35#ifdef CONFIG_GPIOLIB
36
bae48da2 37/* Acquire and dispose GPIOs */
39b2bbe3
AC
38struct gpio_desc *__must_check __gpiod_get(struct device *dev,
39 const char *con_id,
40 enum gpiod_flags flags);
41#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
42#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
43struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
bae48da2 44 const char *con_id,
39b2bbe3
AC
45 unsigned int idx,
46 enum gpiod_flags flags);
47#define __gpiod_get_index(dev, con_id, index, flags, ...) \
48 __gpiod_get_index(dev, con_id, index, flags)
49#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
50struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev,
51 const char *con_id,
52 enum gpiod_flags flags);
53#define __gpiod_get_optional(dev, con_id, flags, ...) \
54 __gpiod_get_optional(dev, con_id, flags)
55#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
56struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
29a1f233 57 const char *con_id,
39b2bbe3
AC
58 unsigned int index,
59 enum gpiod_flags flags);
60#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
61 __gpiod_get_index_optional(dev, con_id, index, flags)
62#define gpiod_get_index_optional(varargs...) \
63 __gpiod_get_index_optional(varargs, 0)
29a1f233 64
bae48da2
AC
65void gpiod_put(struct gpio_desc *desc);
66
39b2bbe3
AC
67struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
68 const char *con_id,
69 enum gpiod_flags flags);
70#define __devm_gpiod_get(dev, con_id, flags, ...) \
71 __devm_gpiod_get(dev, con_id, flags)
72#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
73struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
bae48da2 74 const char *con_id,
39b2bbe3
AC
75 unsigned int idx,
76 enum gpiod_flags flags);
77#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
78 __devm_gpiod_get_index(dev, con_id, index, flags)
79#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
80struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev,
81 const char *con_id,
82 enum gpiod_flags flags);
83#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
84 __devm_gpiod_get_optional(dev, con_id, flags)
85#define devm_gpiod_get_optional(varargs...) \
86 __devm_gpiod_get_optional(varargs, 0)
29a1f233 87struct gpio_desc *__must_check
39b2bbe3
AC
88__devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
89 unsigned int index, enum gpiod_flags flags);
90#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
91 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
92#define devm_gpiod_get_index_optional(varargs...) \
93 __devm_gpiod_get_index_optional(varargs, 0)
29a1f233 94
bae48da2
AC
95void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
96
79a9becd
AC
97int gpiod_get_direction(const struct gpio_desc *desc);
98int gpiod_direction_input(struct gpio_desc *desc);
99int gpiod_direction_output(struct gpio_desc *desc, int value);
ef70bbe1 100int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
79a9becd
AC
101
102/* Value get/set from non-sleeping context */
103int gpiod_get_value(const struct gpio_desc *desc);
104void gpiod_set_value(struct gpio_desc *desc, int value);
105int gpiod_get_raw_value(const struct gpio_desc *desc);
106void gpiod_set_raw_value(struct gpio_desc *desc, int value);
107
108/* Value get/set from sleeping context */
109int gpiod_get_value_cansleep(const struct gpio_desc *desc);
110void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
111int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
112void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
113
114int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
115
116int gpiod_is_active_low(const struct gpio_desc *desc);
117int gpiod_cansleep(const struct gpio_desc *desc);
118
119int gpiod_to_irq(const struct gpio_desc *desc);
120
121/* Convert between the old gpio_ and new gpiod_ interfaces */
122struct gpio_desc *gpio_to_desc(unsigned gpio);
123int desc_to_gpio(const struct gpio_desc *desc);
79a9becd
AC
124
125#else /* CONFIG_GPIOLIB */
126
127static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
128 const char *con_id)
129{
130 return ERR_PTR(-ENOSYS);
131}
132static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
133 const char *con_id,
134 unsigned int idx)
135{
136 return ERR_PTR(-ENOSYS);
137}
29a1f233
TR
138
139static inline struct gpio_desc *__must_check
140gpiod_get_optional(struct device *dev, const char *con_id)
141{
142 return ERR_PTR(-ENOSYS);
143}
144
145static inline struct gpio_desc *__must_check
146gpiod_get_index_optional(struct device *dev, const char *con_id,
147 unsigned int index)
148{
149 return ERR_PTR(-ENOSYS);
150}
151
79a9becd
AC
152static inline void gpiod_put(struct gpio_desc *desc)
153{
154 might_sleep();
155
156 /* GPIO can never have been requested */
157 WARN_ON(1);
158}
159
160static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
161 const char *con_id)
162{
163 return ERR_PTR(-ENOSYS);
164}
165static inline
166struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
167 const char *con_id,
168 unsigned int idx)
169{
170 return ERR_PTR(-ENOSYS);
171}
29a1f233
TR
172
173static inline struct gpio_desc *__must_check
174devm_gpiod_get_optional(struct device *dev, const char *con_id)
175{
176 return ERR_PTR(-ENOSYS);
177}
178
179static inline struct gpio_desc *__must_check
180devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
181 unsigned int index)
182{
183 return ERR_PTR(-ENOSYS);
184}
185
79a9becd
AC
186static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
187{
188 might_sleep();
189
190 /* GPIO can never have been requested */
191 WARN_ON(1);
192}
193
194
195static inline int gpiod_get_direction(const struct gpio_desc *desc)
196{
197 /* GPIO can never have been requested */
198 WARN_ON(1);
199 return -ENOSYS;
200}
201static inline int gpiod_direction_input(struct gpio_desc *desc)
202{
203 /* GPIO can never have been requested */
204 WARN_ON(1);
205 return -ENOSYS;
206}
207static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
208{
209 /* GPIO can never have been requested */
210 WARN_ON(1);
211 return -ENOSYS;
212}
ef70bbe1
PZ
213static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
214{
215 /* GPIO can never have been requested */
216 WARN_ON(1);
217 return -ENOSYS;
218}
79a9becd
AC
219
220
221static inline int gpiod_get_value(const struct gpio_desc *desc)
222{
223 /* GPIO can never have been requested */
224 WARN_ON(1);
225 return 0;
226}
227static inline void gpiod_set_value(struct gpio_desc *desc, int value)
228{
229 /* GPIO can never have been requested */
230 WARN_ON(1);
231}
232static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
233{
234 /* GPIO can never have been requested */
235 WARN_ON(1);
236 return 0;
237}
238static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
239{
240 /* GPIO can never have been requested */
241 WARN_ON(1);
242}
243
244static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
245{
246 /* GPIO can never have been requested */
247 WARN_ON(1);
248 return 0;
249}
250static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
251{
252 /* GPIO can never have been requested */
253 WARN_ON(1);
254}
255static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
256{
257 /* GPIO can never have been requested */
258 WARN_ON(1);
259 return 0;
260}
261static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
262 int value)
263{
264 /* GPIO can never have been requested */
265 WARN_ON(1);
266}
267
268static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
269{
270 /* GPIO can never have been requested */
271 WARN_ON(1);
272 return -ENOSYS;
273}
274
275static inline int gpiod_is_active_low(const struct gpio_desc *desc)
276{
277 /* GPIO can never have been requested */
278 WARN_ON(1);
279 return 0;
280}
281static inline int gpiod_cansleep(const struct gpio_desc *desc)
282{
283 /* GPIO can never have been requested */
284 WARN_ON(1);
285 return 0;
286}
287
288static inline int gpiod_to_irq(const struct gpio_desc *desc)
289{
290 /* GPIO can never have been requested */
291 WARN_ON(1);
292 return -EINVAL;
293}
294
295static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
296{
297 return ERR_PTR(-EINVAL);
298}
299static inline int desc_to_gpio(const struct gpio_desc *desc)
300{
301 /* GPIO can never have been requested */
302 WARN_ON(1);
303 return -EINVAL;
304}
79a9becd
AC
305
306
307#endif /* CONFIG_GPIOLIB */
308
309#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
310
311int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
312int gpiod_export_link(struct device *dev, const char *name,
313 struct gpio_desc *desc);
314int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);
315void gpiod_unexport(struct gpio_desc *desc);
316
317#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
318
319static inline int gpiod_export(struct gpio_desc *desc,
320 bool direction_may_change)
321{
322 return -ENOSYS;
323}
324
325static inline int gpiod_export_link(struct device *dev, const char *name,
326 struct gpio_desc *desc)
327{
328 return -ENOSYS;
329}
330
331static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value)
332{
333 return -ENOSYS;
334}
335
336static inline void gpiod_unexport(struct gpio_desc *desc)
337{
338}
339
340#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
341
342#endif