Mention branches and keyring.
[releases.git] / linux / gpio / consumer.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_GPIO_CONSUMER_H
3 #define __LINUX_GPIO_CONSUMER_H
4
5 #include <linux/bits.h>
6 #include <linux/bug.h>
7 #include <linux/compiler_types.h>
8 #include <linux/err.h>
9
10 struct device;
11 struct gpio_desc;
12 struct gpio_array;
13
14 /**
15  * struct gpio_descs - Struct containing an array of descriptors that can be
16  *                     obtained using gpiod_get_array()
17  *
18  * @info:       Pointer to the opaque gpio_array structure
19  * @ndescs:     Number of held descriptors
20  * @desc:       Array of pointers to GPIO descriptors
21  */
22 struct gpio_descs {
23         struct gpio_array *info;
24         unsigned int ndescs;
25         struct gpio_desc *desc[];
26 };
27
28 #define GPIOD_FLAGS_BIT_DIR_SET         BIT(0)
29 #define GPIOD_FLAGS_BIT_DIR_OUT         BIT(1)
30 #define GPIOD_FLAGS_BIT_DIR_VAL         BIT(2)
31 #define GPIOD_FLAGS_BIT_OPEN_DRAIN      BIT(3)
32 #define GPIOD_FLAGS_BIT_NONEXCLUSIVE    BIT(4)
33
34 /**
35  * enum gpiod_flags - Optional flags that can be passed to one of gpiod_* to
36  *                    configure direction and output value. These values
37  *                    cannot be OR'd.
38  *
39  * @GPIOD_ASIS:                 Don't change anything
40  * @GPIOD_IN:                   Set lines to input mode
41  * @GPIOD_OUT_LOW:              Set lines to output and drive them low
42  * @GPIOD_OUT_HIGH:             Set lines to output and drive them high
43  * @GPIOD_OUT_LOW_OPEN_DRAIN:   Set lines to open-drain output and drive them low
44  * @GPIOD_OUT_HIGH_OPEN_DRAIN:  Set lines to open-drain output and drive them high
45  */
46 enum gpiod_flags {
47         GPIOD_ASIS      = 0,
48         GPIOD_IN        = GPIOD_FLAGS_BIT_DIR_SET,
49         GPIOD_OUT_LOW   = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
50         GPIOD_OUT_HIGH  = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
51                           GPIOD_FLAGS_BIT_DIR_VAL,
52         GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
53         GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
54 };
55
56 #ifdef CONFIG_GPIOLIB
57
58 /* Return the number of GPIOs associated with a device / function */
59 int gpiod_count(struct device *dev, const char *con_id);
60
61 /* Acquire and dispose GPIOs */
62 struct gpio_desc *__must_check gpiod_get(struct device *dev,
63                                          const char *con_id,
64                                          enum gpiod_flags flags);
65 struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
66                                                const char *con_id,
67                                                unsigned int idx,
68                                                enum gpiod_flags flags);
69 struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
70                                                   const char *con_id,
71                                                   enum gpiod_flags flags);
72 struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
73                                                         const char *con_id,
74                                                         unsigned int index,
75                                                         enum gpiod_flags flags);
76 struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
77                                                 const char *con_id,
78                                                 enum gpiod_flags flags);
79 struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
80                                                         const char *con_id,
81                                                         enum gpiod_flags flags);
82 void gpiod_put(struct gpio_desc *desc);
83 void gpiod_put_array(struct gpio_descs *descs);
84
85 struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
86                                               const char *con_id,
87                                               enum gpiod_flags flags);
88 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
89                                                     const char *con_id,
90                                                     unsigned int idx,
91                                                     enum gpiod_flags flags);
92 struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
93                                                        const char *con_id,
94                                                        enum gpiod_flags flags);
95 struct gpio_desc *__must_check
96 devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
97                               unsigned int index, enum gpiod_flags flags);
98 struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
99                                                      const char *con_id,
100                                                      enum gpiod_flags flags);
101 struct gpio_descs *__must_check
102 devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
103                               enum gpiod_flags flags);
104 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
105 void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
106 void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
107
108 int gpiod_get_direction(struct gpio_desc *desc);
109 int gpiod_direction_input(struct gpio_desc *desc);
110 int gpiod_direction_output(struct gpio_desc *desc, int value);
111 int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
112 int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
113 int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
114
115 /* Value get/set from non-sleeping context */
116 int gpiod_get_value(const struct gpio_desc *desc);
117 int gpiod_get_array_value(unsigned int array_size,
118                           struct gpio_desc **desc_array,
119                           struct gpio_array *array_info,
120                           unsigned long *value_bitmap);
121 void gpiod_set_value(struct gpio_desc *desc, int value);
122 int 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);
126 int gpiod_get_raw_value(const struct gpio_desc *desc);
127 int gpiod_get_raw_array_value(unsigned int array_size,
128                               struct gpio_desc **desc_array,
129                               struct gpio_array *array_info,
130                               unsigned long *value_bitmap);
131 void gpiod_set_raw_value(struct gpio_desc *desc, int value);
132 int gpiod_set_raw_array_value(unsigned int array_size,
133                               struct gpio_desc **desc_array,
134                               struct gpio_array *array_info,
135                               unsigned long *value_bitmap);
136
137 /* Value get/set from sleeping context */
138 int gpiod_get_value_cansleep(const struct gpio_desc *desc);
139 int gpiod_get_array_value_cansleep(unsigned int array_size,
140                                    struct gpio_desc **desc_array,
141                                    struct gpio_array *array_info,
142                                    unsigned long *value_bitmap);
143 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
144 int 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);
148 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
149 int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
150                                        struct gpio_desc **desc_array,
151                                        struct gpio_array *array_info,
152                                        unsigned long *value_bitmap);
153 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
154 int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
155                                        struct gpio_desc **desc_array,
156                                        struct gpio_array *array_info,
157                                        unsigned long *value_bitmap);
158
159 int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
160 int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce);
161 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
162 void gpiod_toggle_active_low(struct gpio_desc *desc);
163
164 int gpiod_is_active_low(const struct gpio_desc *desc);
165 int gpiod_cansleep(const struct gpio_desc *desc);
166
167 int gpiod_to_irq(const struct gpio_desc *desc);
168 int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
169
170 /* Convert between the old gpio_ and new gpiod_ interfaces */
171 struct gpio_desc *gpio_to_desc(unsigned gpio);
172 int desc_to_gpio(const struct gpio_desc *desc);
173
174 /* Child properties interface */
175 struct fwnode_handle;
176
177 struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
178                                          const char *propname, int index,
179                                          enum gpiod_flags dflags,
180                                          const char *label);
181 struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
182                                          const char *con_id, int index,
183                                          enum gpiod_flags flags,
184                                          const char *label);
185 struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
186                                               struct fwnode_handle *child,
187                                               const char *con_id, int index,
188                                               enum gpiod_flags flags,
189                                               const char *label);
190
191 #else /* CONFIG_GPIOLIB */
192
193 #include <linux/kernel.h>
194
195 static inline int gpiod_count(struct device *dev, const char *con_id)
196 {
197         return 0;
198 }
199
200 static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
201                                                        const char *con_id,
202                                                        enum gpiod_flags flags)
203 {
204         return ERR_PTR(-ENOSYS);
205 }
206 static inline struct gpio_desc *__must_check
207 gpiod_get_index(struct device *dev,
208                 const char *con_id,
209                 unsigned int idx,
210                 enum gpiod_flags flags)
211 {
212         return ERR_PTR(-ENOSYS);
213 }
214
215 static inline struct gpio_desc *__must_check
216 gpiod_get_optional(struct device *dev, const char *con_id,
217                    enum gpiod_flags flags)
218 {
219         return NULL;
220 }
221
222 static inline struct gpio_desc *__must_check
223 gpiod_get_index_optional(struct device *dev, const char *con_id,
224                          unsigned int index, enum gpiod_flags flags)
225 {
226         return NULL;
227 }
228
229 static inline struct gpio_descs *__must_check
230 gpiod_get_array(struct device *dev, const char *con_id,
231                 enum gpiod_flags flags)
232 {
233         return ERR_PTR(-ENOSYS);
234 }
235
236 static inline struct gpio_descs *__must_check
237 gpiod_get_array_optional(struct device *dev, const char *con_id,
238                          enum gpiod_flags flags)
239 {
240         return NULL;
241 }
242
243 static inline void gpiod_put(struct gpio_desc *desc)
244 {
245         might_sleep();
246
247         /* GPIO can never have been requested */
248         WARN_ON(desc);
249 }
250
251 static inline void devm_gpiod_unhinge(struct device *dev,
252                                       struct gpio_desc *desc)
253 {
254         might_sleep();
255
256         /* GPIO can never have been requested */
257         WARN_ON(desc);
258 }
259
260 static inline void gpiod_put_array(struct gpio_descs *descs)
261 {
262         might_sleep();
263
264         /* GPIO can never have been requested */
265         WARN_ON(descs);
266 }
267
268 static inline struct gpio_desc *__must_check
269 devm_gpiod_get(struct device *dev,
270                  const char *con_id,
271                  enum gpiod_flags flags)
272 {
273         return ERR_PTR(-ENOSYS);
274 }
275 static inline
276 struct gpio_desc *__must_check
277 devm_gpiod_get_index(struct device *dev,
278                        const char *con_id,
279                        unsigned int idx,
280                        enum gpiod_flags flags)
281 {
282         return ERR_PTR(-ENOSYS);
283 }
284
285 static inline struct gpio_desc *__must_check
286 devm_gpiod_get_optional(struct device *dev, const char *con_id,
287                           enum gpiod_flags flags)
288 {
289         return NULL;
290 }
291
292 static inline struct gpio_desc *__must_check
293 devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
294                                 unsigned int index, enum gpiod_flags flags)
295 {
296         return NULL;
297 }
298
299 static inline struct gpio_descs *__must_check
300 devm_gpiod_get_array(struct device *dev, const char *con_id,
301                      enum gpiod_flags flags)
302 {
303         return ERR_PTR(-ENOSYS);
304 }
305
306 static inline struct gpio_descs *__must_check
307 devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
308                               enum gpiod_flags flags)
309 {
310         return NULL;
311 }
312
313 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
314 {
315         might_sleep();
316
317         /* GPIO can never have been requested */
318         WARN_ON(desc);
319 }
320
321 static inline void devm_gpiod_put_array(struct device *dev,
322                                         struct gpio_descs *descs)
323 {
324         might_sleep();
325
326         /* GPIO can never have been requested */
327         WARN_ON(descs);
328 }
329
330
331 static inline int gpiod_get_direction(const struct gpio_desc *desc)
332 {
333         /* GPIO can never have been requested */
334         WARN_ON(desc);
335         return -ENOSYS;
336 }
337 static inline int gpiod_direction_input(struct gpio_desc *desc)
338 {
339         /* GPIO can never have been requested */
340         WARN_ON(desc);
341         return -ENOSYS;
342 }
343 static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
344 {
345         /* GPIO can never have been requested */
346         WARN_ON(desc);
347         return -ENOSYS;
348 }
349 static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
350 {
351         /* GPIO can never have been requested */
352         WARN_ON(desc);
353         return -ENOSYS;
354 }
355 static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc,
356                                                unsigned long flags)
357 {
358         WARN_ON(desc);
359         return -ENOSYS;
360 }
361 static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc,
362                                                 unsigned long flags)
363 {
364         WARN_ON(desc);
365         return -ENOSYS;
366 }
367 static inline int gpiod_get_value(const struct gpio_desc *desc)
368 {
369         /* GPIO can never have been requested */
370         WARN_ON(desc);
371         return 0;
372 }
373 static inline int gpiod_get_array_value(unsigned int array_size,
374                                         struct gpio_desc **desc_array,
375                                         struct gpio_array *array_info,
376                                         unsigned long *value_bitmap)
377 {
378         /* GPIO can never have been requested */
379         WARN_ON(desc_array);
380         return 0;
381 }
382 static inline void gpiod_set_value(struct gpio_desc *desc, int value)
383 {
384         /* GPIO can never have been requested */
385         WARN_ON(desc);
386 }
387 static inline int gpiod_set_array_value(unsigned int array_size,
388                                         struct gpio_desc **desc_array,
389                                         struct gpio_array *array_info,
390                                         unsigned long *value_bitmap)
391 {
392         /* GPIO can never have been requested */
393         WARN_ON(desc_array);
394         return 0;
395 }
396 static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
397 {
398         /* GPIO can never have been requested */
399         WARN_ON(desc);
400         return 0;
401 }
402 static inline int gpiod_get_raw_array_value(unsigned int array_size,
403                                             struct gpio_desc **desc_array,
404                                             struct gpio_array *array_info,
405                                             unsigned long *value_bitmap)
406 {
407         /* GPIO can never have been requested */
408         WARN_ON(desc_array);
409         return 0;
410 }
411 static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
412 {
413         /* GPIO can never have been requested */
414         WARN_ON(desc);
415 }
416 static inline int gpiod_set_raw_array_value(unsigned int array_size,
417                                             struct gpio_desc **desc_array,
418                                             struct gpio_array *array_info,
419                                             unsigned long *value_bitmap)
420 {
421         /* GPIO can never have been requested */
422         WARN_ON(desc_array);
423         return 0;
424 }
425
426 static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
427 {
428         /* GPIO can never have been requested */
429         WARN_ON(desc);
430         return 0;
431 }
432 static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
433                                      struct gpio_desc **desc_array,
434                                      struct gpio_array *array_info,
435                                      unsigned long *value_bitmap)
436 {
437         /* GPIO can never have been requested */
438         WARN_ON(desc_array);
439         return 0;
440 }
441 static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
442 {
443         /* GPIO can never have been requested */
444         WARN_ON(desc);
445 }
446 static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
447                                             struct gpio_desc **desc_array,
448                                             struct gpio_array *array_info,
449                                             unsigned long *value_bitmap)
450 {
451         /* GPIO can never have been requested */
452         WARN_ON(desc_array);
453         return 0;
454 }
455 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
456 {
457         /* GPIO can never have been requested */
458         WARN_ON(desc);
459         return 0;
460 }
461 static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
462                                                struct gpio_desc **desc_array,
463                                                struct gpio_array *array_info,
464                                                unsigned long *value_bitmap)
465 {
466         /* GPIO can never have been requested */
467         WARN_ON(desc_array);
468         return 0;
469 }
470 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
471                                                 int value)
472 {
473         /* GPIO can never have been requested */
474         WARN_ON(desc);
475 }
476 static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
477                                                 struct gpio_desc **desc_array,
478                                                 struct gpio_array *array_info,
479                                                 unsigned long *value_bitmap)
480 {
481         /* GPIO can never have been requested */
482         WARN_ON(desc_array);
483         return 0;
484 }
485
486 static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
487 {
488         /* GPIO can never have been requested */
489         WARN_ON(desc);
490         return -ENOSYS;
491 }
492
493 static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce)
494 {
495         /* GPIO can never have been requested */
496         WARN_ON(desc);
497         return -ENOSYS;
498 }
499
500 static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
501 {
502         /* GPIO can never have been requested */
503         WARN_ON(desc);
504         return -ENOSYS;
505 }
506
507 static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
508 {
509         /* GPIO can never have been requested */
510         WARN_ON(desc);
511 }
512
513 static inline int gpiod_is_active_low(const struct gpio_desc *desc)
514 {
515         /* GPIO can never have been requested */
516         WARN_ON(desc);
517         return 0;
518 }
519 static inline int gpiod_cansleep(const struct gpio_desc *desc)
520 {
521         /* GPIO can never have been requested */
522         WARN_ON(desc);
523         return 0;
524 }
525
526 static inline int gpiod_to_irq(const struct gpio_desc *desc)
527 {
528         /* GPIO can never have been requested */
529         WARN_ON(desc);
530         return -EINVAL;
531 }
532
533 static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
534                                           const char *name)
535 {
536         /* GPIO can never have been requested */
537         WARN_ON(desc);
538         return -EINVAL;
539 }
540
541 static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
542 {
543         return NULL;
544 }
545
546 static inline int desc_to_gpio(const struct gpio_desc *desc)
547 {
548         /* GPIO can never have been requested */
549         WARN_ON(desc);
550         return -EINVAL;
551 }
552
553 /* Child properties interface */
554 struct fwnode_handle;
555
556 static inline
557 struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
558                                          const char *propname, int index,
559                                          enum gpiod_flags dflags,
560                                          const char *label)
561 {
562         return ERR_PTR(-ENOSYS);
563 }
564
565 static inline
566 struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
567                                          const char *con_id, int index,
568                                          enum gpiod_flags flags,
569                                          const char *label)
570 {
571         return ERR_PTR(-ENOSYS);
572 }
573
574 static inline
575 struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
576                                               struct fwnode_handle *fwnode,
577                                               const char *con_id, int index,
578                                               enum gpiod_flags flags,
579                                               const char *label)
580 {
581         return ERR_PTR(-ENOSYS);
582 }
583
584 #endif /* CONFIG_GPIOLIB */
585
586 static inline
587 struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
588                                         struct fwnode_handle *fwnode,
589                                         const char *con_id,
590                                         enum gpiod_flags flags,
591                                         const char *label)
592 {
593         return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
594                                            flags, label);
595 }
596
597 static inline
598 struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
599                                                 const char *con_id, int index,
600                                                 struct fwnode_handle *child,
601                                                 enum gpiod_flags flags,
602                                                 const char *label)
603 {
604         return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
605                                            flags, label);
606 }
607
608 static inline
609 struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
610                                                    const char *con_id,
611                                                    struct fwnode_handle *child,
612                                                    enum gpiod_flags flags,
613                                                    const char *label)
614 {
615         return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
616 }
617
618 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
619 struct device_node;
620
621 struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
622                                          const char *propname, int index,
623                                          enum gpiod_flags dflags,
624                                          const char *label);
625
626 #else  /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
627
628 struct device_node;
629
630 static inline
631 struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
632                                          const char *propname, int index,
633                                          enum gpiod_flags dflags,
634                                          const char *label)
635 {
636         return ERR_PTR(-ENOSYS);
637 }
638
639 #endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
640
641 #ifdef CONFIG_GPIOLIB
642 struct device_node;
643
644 struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
645                                               const struct device_node *node,
646                                               const char *propname, int index,
647                                               enum gpiod_flags dflags,
648                                               const char *label);
649
650 #else  /* CONFIG_GPIOLIB */
651
652 struct device_node;
653
654 static inline
655 struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
656                                               const struct device_node *node,
657                                               const char *propname, int index,
658                                               enum gpiod_flags dflags,
659                                               const char *label)
660 {
661         return ERR_PTR(-ENOSYS);
662 }
663
664 #endif /* CONFIG_GPIOLIB */
665
666 struct acpi_gpio_params {
667         unsigned int crs_entry_index;
668         unsigned int line_index;
669         bool active_low;
670 };
671
672 struct acpi_gpio_mapping {
673         const char *name;
674         const struct acpi_gpio_params *data;
675         unsigned int size;
676
677 /* Ignore IoRestriction field */
678 #define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION       BIT(0)
679 /*
680  * When ACPI GPIO mapping table is in use the index parameter inside it
681  * refers to the GPIO resource in _CRS method. That index has no
682  * distinction of actual type of the resource. When consumer wants to
683  * get GpioIo type explicitly, this quirk may be used.
684  */
685 #define ACPI_GPIO_QUIRK_ONLY_GPIOIO             BIT(1)
686 /* Use given pin as an absolute GPIO number in the system */
687 #define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER         BIT(2)
688
689         unsigned int quirks;
690 };
691
692 struct acpi_device;
693
694 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
695
696 int acpi_dev_add_driver_gpios(struct acpi_device *adev,
697                               const struct acpi_gpio_mapping *gpios);
698 void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
699
700 int devm_acpi_dev_add_driver_gpios(struct device *dev,
701                                    const struct acpi_gpio_mapping *gpios);
702
703 struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label);
704
705 #else  /* CONFIG_GPIOLIB && CONFIG_ACPI */
706
707 static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
708                               const struct acpi_gpio_mapping *gpios)
709 {
710         return -ENXIO;
711 }
712 static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
713
714 static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
715                               const struct acpi_gpio_mapping *gpios)
716 {
717         return -ENXIO;
718 }
719
720 static inline struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin,
721                                                            char *label)
722 {
723         return ERR_PTR(-ENOSYS);
724 }
725
726 #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
727
728
729 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
730
731 int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
732 int gpiod_export_link(struct device *dev, const char *name,
733                       struct gpio_desc *desc);
734 void gpiod_unexport(struct gpio_desc *desc);
735
736 #else  /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
737
738 static inline int gpiod_export(struct gpio_desc *desc,
739                                bool direction_may_change)
740 {
741         return -ENOSYS;
742 }
743
744 static inline int gpiod_export_link(struct device *dev, const char *name,
745                                     struct gpio_desc *desc)
746 {
747         return -ENOSYS;
748 }
749
750 static inline void gpiod_unexport(struct gpio_desc *desc)
751 {
752 }
753
754 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
755
756 #endif