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