blob: 803bb63dd5ffbc4e2adae085b6a162f369c39973 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LINUX_GPIO_CONSUMER_H
3#define __LINUX_GPIO_CONSUMER_H
4
5#include <linux/bug.h>
6#include <linux/err.h>
7#include <linux/kernel.h>
8
9struct device;
10
11/**
12 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
13 * preferable to the old integer-based handles.
14 *
15 * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
16 * until the GPIO is released.
17 */
18struct gpio_desc;
19
20/**
David Brazdil0f672f62019-12-10 10:32:29 +000021 * Opaque descriptor for a structure of GPIO array attributes. This structure
22 * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be
23 * passed back to get/set array functions in order to activate fast processing
24 * path if applicable.
25 */
26struct gpio_array;
27
28/**
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029 * Struct containing an array of descriptors that can be obtained using
30 * gpiod_get_array().
31 */
32struct gpio_descs {
David Brazdil0f672f62019-12-10 10:32:29 +000033 struct gpio_array *info;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000034 unsigned int ndescs;
35 struct gpio_desc *desc[];
36};
37
38#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
39#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
40#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
41#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
David Brazdil0f672f62019-12-10 10:32:29 +000042#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000043
44/**
45 * Optional flags that can be passed to one of gpiod_* to configure direction
46 * and output value. These values cannot be OR'd.
47 */
48enum gpiod_flags {
49 GPIOD_ASIS = 0,
50 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
51 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
52 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
53 GPIOD_FLAGS_BIT_DIR_VAL,
54 GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
55 GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
56};
57
58#ifdef CONFIG_GPIOLIB
59
60/* Return the number of GPIOs associated with a device / function */
61int gpiod_count(struct device *dev, const char *con_id);
62
63/* Acquire and dispose GPIOs */
64struct gpio_desc *__must_check gpiod_get(struct device *dev,
65 const char *con_id,
66 enum gpiod_flags flags);
67struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
68 const char *con_id,
69 unsigned int idx,
70 enum gpiod_flags flags);
71struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
72 const char *con_id,
73 enum gpiod_flags flags);
74struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
75 const char *con_id,
76 unsigned int index,
77 enum gpiod_flags flags);
78struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
79 const char *con_id,
80 enum gpiod_flags flags);
81struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
82 const char *con_id,
83 enum gpiod_flags flags);
84void gpiod_put(struct gpio_desc *desc);
85void gpiod_put_array(struct gpio_descs *descs);
86
87struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
88 const char *con_id,
89 enum gpiod_flags flags);
90struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
91 const char *con_id,
92 unsigned int idx,
93 enum gpiod_flags flags);
94struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
95 const char *con_id,
96 enum gpiod_flags flags);
97struct gpio_desc *__must_check
98devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
99 unsigned int index, enum gpiod_flags flags);
100struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
101 const char *con_id,
102 enum gpiod_flags flags);
103struct gpio_descs *__must_check
104devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
105 enum gpiod_flags flags);
106void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
David Brazdil0f672f62019-12-10 10:32:29 +0000107void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000108void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
109
110int gpiod_get_direction(struct gpio_desc *desc);
111int gpiod_direction_input(struct gpio_desc *desc);
112int gpiod_direction_output(struct gpio_desc *desc, int value);
113int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
114
115/* Value get/set from non-sleeping context */
116int gpiod_get_value(const struct gpio_desc *desc);
117int gpiod_get_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000118 struct gpio_desc **desc_array,
119 struct gpio_array *array_info,
120 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000121void gpiod_set_value(struct gpio_desc *desc, int value);
David Brazdil0f672f62019-12-10 10:32:29 +0000122int gpiod_set_array_value(unsigned int array_size,
123 struct gpio_desc **desc_array,
124 struct gpio_array *array_info,
125 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000126int gpiod_get_raw_value(const struct gpio_desc *desc);
127int gpiod_get_raw_array_value(unsigned int array_size,
128 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000129 struct gpio_array *array_info,
130 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000131void gpiod_set_raw_value(struct gpio_desc *desc, int value);
132int gpiod_set_raw_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000133 struct gpio_desc **desc_array,
134 struct gpio_array *array_info,
135 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000136
137/* Value get/set from sleeping context */
138int gpiod_get_value_cansleep(const struct gpio_desc *desc);
139int gpiod_get_array_value_cansleep(unsigned int array_size,
140 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000141 struct gpio_array *array_info,
142 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000143void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
David Brazdil0f672f62019-12-10 10:32:29 +0000144int gpiod_set_array_value_cansleep(unsigned int array_size,
145 struct gpio_desc **desc_array,
146 struct gpio_array *array_info,
147 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000148int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
149int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
150 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000151 struct gpio_array *array_info,
152 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000153void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
154int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000155 struct gpio_desc **desc_array,
156 struct gpio_array *array_info,
157 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000158
159int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
160int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
Olivier Deprez0e641232021-09-23 10:07:05 +0200161void gpiod_toggle_active_low(struct gpio_desc *desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000162
163int gpiod_is_active_low(const struct gpio_desc *desc);
164int gpiod_cansleep(const struct gpio_desc *desc);
165
166int gpiod_to_irq(const struct gpio_desc *desc);
David Brazdil0f672f62019-12-10 10:32:29 +0000167int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000168
169/* Convert between the old gpio_ and new gpiod_ interfaces */
170struct gpio_desc *gpio_to_desc(unsigned gpio);
171int desc_to_gpio(const struct gpio_desc *desc);
172
173/* Child properties interface */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000174struct fwnode_handle;
175
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000176struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
177 const char *propname, int index,
178 enum gpiod_flags dflags,
179 const char *label);
180struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
181 const char *con_id, int index,
182 struct fwnode_handle *child,
183 enum gpiod_flags flags,
184 const char *label);
185
186#else /* CONFIG_GPIOLIB */
187
188static inline int gpiod_count(struct device *dev, const char *con_id)
189{
190 return 0;
191}
192
193static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
194 const char *con_id,
195 enum gpiod_flags flags)
196{
197 return ERR_PTR(-ENOSYS);
198}
199static inline struct gpio_desc *__must_check
200gpiod_get_index(struct device *dev,
201 const char *con_id,
202 unsigned int idx,
203 enum gpiod_flags flags)
204{
205 return ERR_PTR(-ENOSYS);
206}
207
208static inline struct gpio_desc *__must_check
209gpiod_get_optional(struct device *dev, const char *con_id,
210 enum gpiod_flags flags)
211{
212 return NULL;
213}
214
215static inline struct gpio_desc *__must_check
216gpiod_get_index_optional(struct device *dev, const char *con_id,
217 unsigned int index, enum gpiod_flags flags)
218{
219 return NULL;
220}
221
222static inline struct gpio_descs *__must_check
223gpiod_get_array(struct device *dev, const char *con_id,
224 enum gpiod_flags flags)
225{
226 return ERR_PTR(-ENOSYS);
227}
228
229static inline struct gpio_descs *__must_check
230gpiod_get_array_optional(struct device *dev, const char *con_id,
231 enum gpiod_flags flags)
232{
233 return NULL;
234}
235
236static inline void gpiod_put(struct gpio_desc *desc)
237{
238 might_sleep();
239
240 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000241 WARN_ON(desc);
242}
243
244static inline void devm_gpiod_unhinge(struct device *dev,
245 struct gpio_desc *desc)
246{
247 might_sleep();
248
249 /* GPIO can never have been requested */
250 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000251}
252
253static inline void gpiod_put_array(struct gpio_descs *descs)
254{
255 might_sleep();
256
257 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000258 WARN_ON(descs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000259}
260
261static inline struct gpio_desc *__must_check
262devm_gpiod_get(struct device *dev,
263 const char *con_id,
264 enum gpiod_flags flags)
265{
266 return ERR_PTR(-ENOSYS);
267}
268static inline
269struct gpio_desc *__must_check
270devm_gpiod_get_index(struct device *dev,
271 const char *con_id,
272 unsigned int idx,
273 enum gpiod_flags flags)
274{
275 return ERR_PTR(-ENOSYS);
276}
277
278static inline struct gpio_desc *__must_check
279devm_gpiod_get_optional(struct device *dev, const char *con_id,
280 enum gpiod_flags flags)
281{
282 return NULL;
283}
284
285static inline struct gpio_desc *__must_check
286devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
287 unsigned int index, enum gpiod_flags flags)
288{
289 return NULL;
290}
291
292static inline struct gpio_descs *__must_check
293devm_gpiod_get_array(struct device *dev, const char *con_id,
294 enum gpiod_flags flags)
295{
296 return ERR_PTR(-ENOSYS);
297}
298
299static inline struct gpio_descs *__must_check
300devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
301 enum gpiod_flags flags)
302{
303 return NULL;
304}
305
306static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
307{
308 might_sleep();
309
310 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000311 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000312}
313
314static inline void devm_gpiod_put_array(struct device *dev,
315 struct gpio_descs *descs)
316{
317 might_sleep();
318
319 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000320 WARN_ON(descs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000321}
322
323
324static inline int gpiod_get_direction(const struct gpio_desc *desc)
325{
326 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000327 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000328 return -ENOSYS;
329}
330static inline int gpiod_direction_input(struct gpio_desc *desc)
331{
332 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000333 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000334 return -ENOSYS;
335}
336static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
337{
338 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000339 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000340 return -ENOSYS;
341}
342static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
343{
344 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000345 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000346 return -ENOSYS;
347}
348
349
350static inline int gpiod_get_value(const struct gpio_desc *desc)
351{
352 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000353 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000354 return 0;
355}
356static inline int gpiod_get_array_value(unsigned int array_size,
357 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000358 struct gpio_array *array_info,
359 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000360{
361 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000362 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000363 return 0;
364}
365static inline void gpiod_set_value(struct gpio_desc *desc, int value)
366{
367 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000368 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000369}
David Brazdil0f672f62019-12-10 10:32:29 +0000370static inline int gpiod_set_array_value(unsigned int array_size,
371 struct gpio_desc **desc_array,
372 struct gpio_array *array_info,
373 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000374{
375 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000376 WARN_ON(desc_array);
377 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000378}
379static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
380{
381 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000382 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000383 return 0;
384}
385static inline int gpiod_get_raw_array_value(unsigned int array_size,
386 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000387 struct gpio_array *array_info,
388 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000389{
390 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000391 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000392 return 0;
393}
394static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
395{
396 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000397 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000398}
399static inline int gpiod_set_raw_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000400 struct gpio_desc **desc_array,
401 struct gpio_array *array_info,
402 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000403{
404 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000405 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000406 return 0;
407}
408
409static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
410{
411 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000412 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000413 return 0;
414}
415static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
416 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000417 struct gpio_array *array_info,
418 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000419{
420 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000421 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000422 return 0;
423}
424static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
425{
426 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000427 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000428}
David Brazdil0f672f62019-12-10 10:32:29 +0000429static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000430 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000431 struct gpio_array *array_info,
432 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000433{
434 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000435 WARN_ON(desc_array);
436 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000437}
438static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
439{
440 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000441 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000442 return 0;
443}
444static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
445 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000446 struct gpio_array *array_info,
447 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000448{
449 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000450 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000451 return 0;
452}
453static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
454 int value)
455{
456 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000457 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000458}
459static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
460 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000461 struct gpio_array *array_info,
462 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000463{
464 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000465 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000466 return 0;
467}
468
469static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
470{
471 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000472 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000473 return -ENOSYS;
474}
475
476static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
477{
478 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000479 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000480 return -ENOSYS;
481}
482
Olivier Deprez0e641232021-09-23 10:07:05 +0200483static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
484{
485 /* GPIO can never have been requested */
486 WARN_ON(desc);
487}
488
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000489static inline int gpiod_is_active_low(const struct gpio_desc *desc)
490{
491 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000492 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000493 return 0;
494}
495static inline int gpiod_cansleep(const struct gpio_desc *desc)
496{
497 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000498 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000499 return 0;
500}
501
502static inline int gpiod_to_irq(const struct gpio_desc *desc)
503{
504 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000505 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000506 return -EINVAL;
507}
508
David Brazdil0f672f62019-12-10 10:32:29 +0000509static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
510 const char *name)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000511{
512 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000513 WARN_ON(desc);
514 return -EINVAL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000515}
516
517static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
518{
David Brazdil0f672f62019-12-10 10:32:29 +0000519 return NULL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000520}
521
522static inline int desc_to_gpio(const struct gpio_desc *desc)
523{
524 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000525 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000526 return -EINVAL;
527}
528
529/* Child properties interface */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000530struct fwnode_handle;
531
532static inline
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000533struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
534 const char *propname, int index,
535 enum gpiod_flags dflags,
536 const char *label)
537{
538 return ERR_PTR(-ENOSYS);
539}
540
541static inline
542struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
543 const char *con_id, int index,
544 struct fwnode_handle *child,
545 enum gpiod_flags flags,
546 const char *label)
547{
548 return ERR_PTR(-ENOSYS);
549}
550
551#endif /* CONFIG_GPIOLIB */
552
553static inline
554struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
555 const char *con_id,
556 struct fwnode_handle *child,
557 enum gpiod_flags flags,
558 const char *label)
559{
560 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
561 flags, label);
562}
563
David Brazdil0f672f62019-12-10 10:32:29 +0000564#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
565struct device_node;
566
567struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
568 const char *propname, int index,
569 enum gpiod_flags dflags,
570 const char *label);
571
572#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
573
574struct device_node;
575
576static inline
577struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
578 const char *propname, int index,
579 enum gpiod_flags dflags,
580 const char *label)
581{
582 return ERR_PTR(-ENOSYS);
583}
584
585#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
586
587#ifdef CONFIG_GPIOLIB
588struct device_node;
589
590struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
591 struct device_node *node,
592 const char *propname, int index,
593 enum gpiod_flags dflags,
594 const char *label);
595
596#else /* CONFIG_GPIOLIB */
597
598struct device_node;
599
600static inline
601struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
602 struct device_node *node,
603 const char *propname, int index,
604 enum gpiod_flags dflags,
605 const char *label)
606{
607 return ERR_PTR(-ENOSYS);
608}
609
610#endif /* CONFIG_GPIOLIB */
611
612struct acpi_gpio_params {
613 unsigned int crs_entry_index;
614 unsigned int line_index;
615 bool active_low;
616};
617
618struct acpi_gpio_mapping {
619 const char *name;
620 const struct acpi_gpio_params *data;
621 unsigned int size;
622
623/* Ignore IoRestriction field */
624#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
625/*
626 * When ACPI GPIO mapping table is in use the index parameter inside it
627 * refers to the GPIO resource in _CRS method. That index has no
628 * distinction of actual type of the resource. When consumer wants to
629 * get GpioIo type explicitly, this quirk may be used.
630 */
631#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
632
633 unsigned int quirks;
634};
635
636#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
637
638struct acpi_device;
639
640int acpi_dev_add_driver_gpios(struct acpi_device *adev,
641 const struct acpi_gpio_mapping *gpios);
642void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
643
644int devm_acpi_dev_add_driver_gpios(struct device *dev,
645 const struct acpi_gpio_mapping *gpios);
646void devm_acpi_dev_remove_driver_gpios(struct device *dev);
647
648#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
649
650struct acpi_device;
651
652static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
653 const struct acpi_gpio_mapping *gpios)
654{
655 return -ENXIO;
656}
657static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
658
659static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
660 const struct acpi_gpio_mapping *gpios)
661{
662 return -ENXIO;
663}
664static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
665
666#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
667
668
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000669#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
670
671int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
672int gpiod_export_link(struct device *dev, const char *name,
673 struct gpio_desc *desc);
674void gpiod_unexport(struct gpio_desc *desc);
675
676#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
677
678static inline int gpiod_export(struct gpio_desc *desc,
679 bool direction_may_change)
680{
681 return -ENOSYS;
682}
683
684static inline int gpiod_export_link(struct device *dev, const char *name,
685 struct gpio_desc *desc)
686{
687 return -ENOSYS;
688}
689
690static inline void gpiod_unexport(struct gpio_desc *desc)
691{
692}
693
694#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
695
696#endif