1#ifndef __LINUX_GPIO_CONSUMER_H
2#define __LINUX_GPIO_CONSUMER_H
3
4#include <linux/err.h>
5#include <linux/kernel.h>
6
7struct device;
8struct gpio_chip;
9
10
11
12
13
14
15
16
17struct gpio_desc;
18
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
25
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
35#ifdef CONFIG_GPIOLIB
36
37
38struct gpio_desc *__must_check __gpiod_get(struct device *dev,
39 const char *con_id,
40 enum gpiod_flags flags);
41struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
42 const char *con_id,
43 unsigned int idx,
44 enum gpiod_flags flags);
45struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev,
46 const char *con_id,
47 enum gpiod_flags flags);
48struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
49 const char *con_id,
50 unsigned int index,
51 enum gpiod_flags flags);
52void gpiod_put(struct gpio_desc *desc);
53
54struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
55 const char *con_id,
56 enum gpiod_flags flags);
57struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
58 const char *con_id,
59 unsigned int idx,
60 enum gpiod_flags flags);
61struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev,
62 const char *con_id,
63 enum gpiod_flags flags);
64struct gpio_desc *__must_check
65__devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
66 unsigned int index, enum gpiod_flags flags);
67void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
68
69int gpiod_get_direction(const struct gpio_desc *desc);
70int gpiod_direction_input(struct gpio_desc *desc);
71int gpiod_direction_output(struct gpio_desc *desc, int value);
72
73
74int gpiod_get_value(const struct gpio_desc *desc);
75void gpiod_set_value(struct gpio_desc *desc, int value);
76int gpiod_get_raw_value(const struct gpio_desc *desc);
77void gpiod_set_raw_value(struct gpio_desc *desc, int value);
78
79
80int gpiod_get_value_cansleep(const struct gpio_desc *desc);
81void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
82int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
83void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
84
85int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
86
87int gpiod_is_active_low(const struct gpio_desc *desc);
88int gpiod_cansleep(const struct gpio_desc *desc);
89
90int gpiod_to_irq(const struct gpio_desc *desc);
91
92
93struct gpio_desc *gpio_to_desc(unsigned gpio);
94int desc_to_gpio(const struct gpio_desc *desc);
95struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
96
97#else
98
99static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev,
100 const char *con_id,
101 enum gpiod_flags flags)
102{
103 return ERR_PTR(-ENOSYS);
104}
105static inline struct gpio_desc *__must_check
106__gpiod_get_index(struct device *dev,
107 const char *con_id,
108 unsigned int idx,
109 enum gpiod_flags flags)
110{
111 return ERR_PTR(-ENOSYS);
112}
113
114static inline struct gpio_desc *__must_check
115__gpiod_get_optional(struct device *dev, const char *con_id,
116 enum gpiod_flags flags)
117{
118 return ERR_PTR(-ENOSYS);
119}
120
121static inline struct gpio_desc *__must_check
122__gpiod_get_index_optional(struct device *dev, const char *con_id,
123 unsigned int index, enum gpiod_flags flags)
124{
125 return ERR_PTR(-ENOSYS);
126}
127
128static inline void gpiod_put(struct gpio_desc *desc)
129{
130 might_sleep();
131
132
133 WARN_ON(1);
134}
135
136static inline struct gpio_desc *__must_check
137__devm_gpiod_get(struct device *dev,
138 const char *con_id,
139 enum gpiod_flags flags)
140{
141 return ERR_PTR(-ENOSYS);
142}
143static inline
144struct gpio_desc *__must_check
145__devm_gpiod_get_index(struct device *dev,
146 const char *con_id,
147 unsigned int idx,
148 enum gpiod_flags flags)
149{
150 return ERR_PTR(-ENOSYS);
151}
152
153static inline struct gpio_desc *__must_check
154__devm_gpiod_get_optional(struct device *dev, const char *con_id,
155 enum gpiod_flags flags)
156{
157 return ERR_PTR(-ENOSYS);
158}
159
160static inline struct gpio_desc *__must_check
161__devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
162 unsigned int index, enum gpiod_flags flags)
163{
164 return ERR_PTR(-ENOSYS);
165}
166
167static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
168{
169 might_sleep();
170
171
172 WARN_ON(1);
173}
174
175
176static inline int gpiod_get_direction(const struct gpio_desc *desc)
177{
178
179 WARN_ON(1);
180 return -ENOSYS;
181}
182static inline int gpiod_direction_input(struct gpio_desc *desc)
183{
184
185 WARN_ON(1);
186 return -ENOSYS;
187}
188static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
189{
190
191 WARN_ON(1);
192 return -ENOSYS;
193}
194
195
196static inline int gpiod_get_value(const struct gpio_desc *desc)
197{
198
199 WARN_ON(1);
200 return 0;
201}
202static inline void gpiod_set_value(struct gpio_desc *desc, int value)
203{
204
205 WARN_ON(1);
206}
207static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
208{
209
210 WARN_ON(1);
211 return 0;
212}
213static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
214{
215
216 WARN_ON(1);
217}
218
219static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
220{
221
222 WARN_ON(1);
223 return 0;
224}
225static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
226{
227
228 WARN_ON(1);
229}
230static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
231{
232
233 WARN_ON(1);
234 return 0;
235}
236static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
237 int value)
238{
239
240 WARN_ON(1);
241}
242
243static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
244{
245
246 WARN_ON(1);
247 return -ENOSYS;
248}
249
250static inline int gpiod_is_active_low(const struct gpio_desc *desc)
251{
252
253 WARN_ON(1);
254 return 0;
255}
256static inline int gpiod_cansleep(const struct gpio_desc *desc)
257{
258
259 WARN_ON(1);
260 return 0;
261}
262
263static inline int gpiod_to_irq(const struct gpio_desc *desc)
264{
265
266 WARN_ON(1);
267 return -EINVAL;
268}
269
270static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
271{
272 return ERR_PTR(-EINVAL);
273}
274static inline int desc_to_gpio(const struct gpio_desc *desc)
275{
276
277 WARN_ON(1);
278 return -EINVAL;
279}
280static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
281{
282
283 WARN_ON(1);
284 return ERR_PTR(-ENODEV);
285}
286
287#endif
288
289
290
291
292
293
294
295
296
297#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
298#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
299#define __gpiod_get_index(dev, con_id, index, flags, ...) \
300 __gpiod_get_index(dev, con_id, index, flags)
301#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
302#define __gpiod_get_optional(dev, con_id, flags, ...) \
303 __gpiod_get_optional(dev, con_id, flags)
304#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
305#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
306 __gpiod_get_index_optional(dev, con_id, index, flags)
307#define gpiod_get_index_optional(varargs...) \
308 __gpiod_get_index_optional(varargs, 0)
309#define __devm_gpiod_get(dev, con_id, flags, ...) \
310 __devm_gpiod_get(dev, con_id, flags)
311#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
312#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
313 __devm_gpiod_get_index(dev, con_id, index, flags)
314#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
315#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
316 __devm_gpiod_get_optional(dev, con_id, flags)
317#define devm_gpiod_get_optional(varargs...) \
318 __devm_gpiod_get_optional(varargs, 0)
319#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
320 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
321#define devm_gpiod_get_index_optional(varargs...) \
322 __devm_gpiod_get_index_optional(varargs, 0)
323
324#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
325
326int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
327int gpiod_export_link(struct device *dev, const char *name,
328 struct gpio_desc *desc);
329int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);
330void gpiod_unexport(struct gpio_desc *desc);
331
332#else
333
334static inline int gpiod_export(struct gpio_desc *desc,
335 bool direction_may_change)
336{
337 return -ENOSYS;
338}
339
340static inline int gpiod_export_link(struct device *dev, const char *name,
341 struct gpio_desc *desc)
342{
343 return -ENOSYS;
344}
345
346static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value)
347{
348 return -ENOSYS;
349}
350
351static inline void gpiod_unexport(struct gpio_desc *desc)
352{
353}
354
355#endif
356
357#endif
358