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