• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *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 
gpiod_count(struct device * dev,const char * con_id)188 static inline int gpiod_count(struct device *dev, const char *con_id)
189 {
190 	return 0;
191 }
192 
gpiod_get(struct device * dev,const char * con_id,enum gpiod_flags flags)193 static 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 }
199 static inline struct gpio_desc *__must_check
gpiod_get_index(struct device * dev,const char * con_id,unsigned int idx,enum gpiod_flags flags)200 gpiod_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 
208 static inline struct gpio_desc *__must_check
gpiod_get_optional(struct device * dev,const char * con_id,enum gpiod_flags flags)209 gpiod_get_optional(struct device *dev, const char *con_id,
210 		   enum gpiod_flags flags)
211 {
212 	return NULL;
213 }
214 
215 static inline struct gpio_desc *__must_check
gpiod_get_index_optional(struct device * dev,const char * con_id,unsigned int index,enum gpiod_flags flags)216 gpiod_get_index_optional(struct device *dev, const char *con_id,
217 			 unsigned int index, enum gpiod_flags flags)
218 {
219 	return NULL;
220 }
221 
222 static inline struct gpio_descs *__must_check
gpiod_get_array(struct device * dev,const char * con_id,enum gpiod_flags flags)223 gpiod_get_array(struct device *dev, const char *con_id,
224 		enum gpiod_flags flags)
225 {
226 	return ERR_PTR(-ENOSYS);
227 }
228 
229 static inline struct gpio_descs *__must_check
gpiod_get_array_optional(struct device * dev,const char * con_id,enum gpiod_flags flags)230 gpiod_get_array_optional(struct device *dev, const char *con_id,
231 			 enum gpiod_flags flags)
232 {
233 	return NULL;
234 }
235 
gpiod_put(struct gpio_desc * desc)236 static inline void gpiod_put(struct gpio_desc *desc)
237 {
238 	might_sleep();
239 
240 	/* GPIO can never have been requested */
241 	WARN_ON(desc);
242 }
243 
devm_gpiod_unhinge(struct device * dev,struct gpio_desc * desc)244 static 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);
251 }
252 
gpiod_put_array(struct gpio_descs * descs)253 static inline void gpiod_put_array(struct gpio_descs *descs)
254 {
255 	might_sleep();
256 
257 	/* GPIO can never have been requested */
258 	WARN_ON(descs);
259 }
260 
261 static inline struct gpio_desc *__must_check
devm_gpiod_get(struct device * dev,const char * con_id,enum gpiod_flags flags)262 devm_gpiod_get(struct device *dev,
263 		 const char *con_id,
264 		 enum gpiod_flags flags)
265 {
266 	return ERR_PTR(-ENOSYS);
267 }
268 static inline
269 struct gpio_desc *__must_check
devm_gpiod_get_index(struct device * dev,const char * con_id,unsigned int idx,enum gpiod_flags flags)270 devm_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 
278 static inline struct gpio_desc *__must_check
devm_gpiod_get_optional(struct device * dev,const char * con_id,enum gpiod_flags flags)279 devm_gpiod_get_optional(struct device *dev, const char *con_id,
280 			  enum gpiod_flags flags)
281 {
282 	return NULL;
283 }
284 
285 static inline struct gpio_desc *__must_check
devm_gpiod_get_index_optional(struct device * dev,const char * con_id,unsigned int index,enum gpiod_flags flags)286 devm_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 
292 static inline struct gpio_descs *__must_check
devm_gpiod_get_array(struct device * dev,const char * con_id,enum gpiod_flags flags)293 devm_gpiod_get_array(struct device *dev, const char *con_id,
294 		     enum gpiod_flags flags)
295 {
296 	return ERR_PTR(-ENOSYS);
297 }
298 
299 static inline struct gpio_descs *__must_check
devm_gpiod_get_array_optional(struct device * dev,const char * con_id,enum gpiod_flags flags)300 devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
301 			      enum gpiod_flags flags)
302 {
303 	return NULL;
304 }
305 
devm_gpiod_put(struct device * dev,struct gpio_desc * desc)306 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
307 {
308 	might_sleep();
309 
310 	/* GPIO can never have been requested */
311 	WARN_ON(desc);
312 }
313 
devm_gpiod_put_array(struct device * dev,struct gpio_descs * descs)314 static 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 */
320 	WARN_ON(descs);
321 }
322 
323 
gpiod_get_direction(const struct gpio_desc * desc)324 static inline int gpiod_get_direction(const struct gpio_desc *desc)
325 {
326 	/* GPIO can never have been requested */
327 	WARN_ON(desc);
328 	return -ENOSYS;
329 }
gpiod_direction_input(struct gpio_desc * desc)330 static inline int gpiod_direction_input(struct gpio_desc *desc)
331 {
332 	/* GPIO can never have been requested */
333 	WARN_ON(desc);
334 	return -ENOSYS;
335 }
gpiod_direction_output(struct gpio_desc * desc,int value)336 static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
337 {
338 	/* GPIO can never have been requested */
339 	WARN_ON(desc);
340 	return -ENOSYS;
341 }
gpiod_direction_output_raw(struct gpio_desc * desc,int value)342 static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
343 {
344 	/* GPIO can never have been requested */
345 	WARN_ON(desc);
346 	return -ENOSYS;
347 }
348 
349 
gpiod_get_value(const struct gpio_desc * desc)350 static inline int gpiod_get_value(const struct gpio_desc *desc)
351 {
352 	/* GPIO can never have been requested */
353 	WARN_ON(desc);
354 	return 0;
355 }
gpiod_get_array_value(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)356 static inline int gpiod_get_array_value(unsigned int array_size,
357 					struct gpio_desc **desc_array,
358 					struct gpio_array *array_info,
359 					unsigned long *value_bitmap)
360 {
361 	/* GPIO can never have been requested */
362 	WARN_ON(desc_array);
363 	return 0;
364 }
gpiod_set_value(struct gpio_desc * desc,int value)365 static inline void gpiod_set_value(struct gpio_desc *desc, int value)
366 {
367 	/* GPIO can never have been requested */
368 	WARN_ON(desc);
369 }
gpiod_set_array_value(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)370 static 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)
374 {
375 	/* GPIO can never have been requested */
376 	WARN_ON(desc_array);
377 	return 0;
378 }
gpiod_get_raw_value(const struct gpio_desc * desc)379 static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
380 {
381 	/* GPIO can never have been requested */
382 	WARN_ON(desc);
383 	return 0;
384 }
gpiod_get_raw_array_value(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)385 static inline int gpiod_get_raw_array_value(unsigned int array_size,
386 					    struct gpio_desc **desc_array,
387 					    struct gpio_array *array_info,
388 					    unsigned long *value_bitmap)
389 {
390 	/* GPIO can never have been requested */
391 	WARN_ON(desc_array);
392 	return 0;
393 }
gpiod_set_raw_value(struct gpio_desc * desc,int value)394 static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
395 {
396 	/* GPIO can never have been requested */
397 	WARN_ON(desc);
398 }
gpiod_set_raw_array_value(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)399 static inline int gpiod_set_raw_array_value(unsigned int array_size,
400 					    struct gpio_desc **desc_array,
401 					    struct gpio_array *array_info,
402 					    unsigned long *value_bitmap)
403 {
404 	/* GPIO can never have been requested */
405 	WARN_ON(desc_array);
406 	return 0;
407 }
408 
gpiod_get_value_cansleep(const struct gpio_desc * desc)409 static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
410 {
411 	/* GPIO can never have been requested */
412 	WARN_ON(desc);
413 	return 0;
414 }
gpiod_get_array_value_cansleep(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)415 static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
416 				     struct gpio_desc **desc_array,
417 				     struct gpio_array *array_info,
418 				     unsigned long *value_bitmap)
419 {
420 	/* GPIO can never have been requested */
421 	WARN_ON(desc_array);
422 	return 0;
423 }
gpiod_set_value_cansleep(struct gpio_desc * desc,int value)424 static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
425 {
426 	/* GPIO can never have been requested */
427 	WARN_ON(desc);
428 }
gpiod_set_array_value_cansleep(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)429 static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
430 					    struct gpio_desc **desc_array,
431 					    struct gpio_array *array_info,
432 					    unsigned long *value_bitmap)
433 {
434 	/* GPIO can never have been requested */
435 	WARN_ON(desc_array);
436 	return 0;
437 }
gpiod_get_raw_value_cansleep(const struct gpio_desc * desc)438 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
439 {
440 	/* GPIO can never have been requested */
441 	WARN_ON(desc);
442 	return 0;
443 }
gpiod_get_raw_array_value_cansleep(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)444 static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
445 					       struct gpio_desc **desc_array,
446 					       struct gpio_array *array_info,
447 					       unsigned long *value_bitmap)
448 {
449 	/* GPIO can never have been requested */
450 	WARN_ON(desc_array);
451 	return 0;
452 }
gpiod_set_raw_value_cansleep(struct gpio_desc * desc,int value)453 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
454 						int value)
455 {
456 	/* GPIO can never have been requested */
457 	WARN_ON(desc);
458 }
gpiod_set_raw_array_value_cansleep(unsigned int array_size,struct gpio_desc ** desc_array,struct gpio_array * array_info,unsigned long * value_bitmap)459 static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
460 						struct gpio_desc **desc_array,
461 						struct gpio_array *array_info,
462 						unsigned long *value_bitmap)
463 {
464 	/* GPIO can never have been requested */
465 	WARN_ON(desc_array);
466 	return 0;
467 }
468 
gpiod_set_debounce(struct gpio_desc * desc,unsigned debounce)469 static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
470 {
471 	/* GPIO can never have been requested */
472 	WARN_ON(desc);
473 	return -ENOSYS;
474 }
475 
gpiod_set_transitory(struct gpio_desc * desc,bool transitory)476 static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
477 {
478 	/* GPIO can never have been requested */
479 	WARN_ON(desc);
480 	return -ENOSYS;
481 }
482 
gpiod_toggle_active_low(struct gpio_desc * desc)483 static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
484 {
485 	/* GPIO can never have been requested */
486 	WARN_ON(desc);
487 }
488 
gpiod_is_active_low(const struct gpio_desc * desc)489 static inline int gpiod_is_active_low(const struct gpio_desc *desc)
490 {
491 	/* GPIO can never have been requested */
492 	WARN_ON(desc);
493 	return 0;
494 }
gpiod_cansleep(const struct gpio_desc * desc)495 static inline int gpiod_cansleep(const struct gpio_desc *desc)
496 {
497 	/* GPIO can never have been requested */
498 	WARN_ON(desc);
499 	return 0;
500 }
501 
gpiod_to_irq(const struct gpio_desc * desc)502 static inline int gpiod_to_irq(const struct gpio_desc *desc)
503 {
504 	/* GPIO can never have been requested */
505 	WARN_ON(desc);
506 	return -EINVAL;
507 }
508 
gpiod_set_consumer_name(struct gpio_desc * desc,const char * name)509 static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
510 					  const char *name)
511 {
512 	/* GPIO can never have been requested */
513 	WARN_ON(desc);
514 	return -EINVAL;
515 }
516 
gpio_to_desc(unsigned gpio)517 static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
518 {
519 	return NULL;
520 }
521 
desc_to_gpio(const struct gpio_desc * desc)522 static inline int desc_to_gpio(const struct gpio_desc *desc)
523 {
524 	/* GPIO can never have been requested */
525 	WARN_ON(desc);
526 	return -EINVAL;
527 }
528 
529 /* Child properties interface */
530 struct fwnode_handle;
531 
532 static inline
fwnode_get_named_gpiod(struct fwnode_handle * fwnode,const char * propname,int index,enum gpiod_flags dflags,const char * label)533 struct 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 
541 static inline
devm_fwnode_get_index_gpiod_from_child(struct device * dev,const char * con_id,int index,struct fwnode_handle * child,enum gpiod_flags flags,const char * label)542 struct 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 
553 static inline
devm_fwnode_get_gpiod_from_child(struct device * dev,const char * con_id,struct fwnode_handle * child,enum gpiod_flags flags,const char * label)554 struct 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 
564 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
565 struct device_node;
566 
567 struct 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 
574 struct device_node;
575 
576 static inline
gpiod_get_from_of_node(struct device_node * node,const char * propname,int index,enum gpiod_flags dflags,const char * label)577 struct 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
588 struct device_node;
589 
590 struct 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 
598 struct device_node;
599 
600 static inline
devm_gpiod_get_from_of_node(struct device * dev,struct device_node * node,const char * propname,int index,enum gpiod_flags dflags,const char * label)601 struct 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 
612 struct acpi_gpio_params {
613 	unsigned int crs_entry_index;
614 	unsigned int line_index;
615 	bool active_low;
616 };
617 
618 struct 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 
638 struct acpi_device;
639 
640 int acpi_dev_add_driver_gpios(struct acpi_device *adev,
641 			      const struct acpi_gpio_mapping *gpios);
642 void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
643 
644 int devm_acpi_dev_add_driver_gpios(struct device *dev,
645 				   const struct acpi_gpio_mapping *gpios);
646 void devm_acpi_dev_remove_driver_gpios(struct device *dev);
647 
648 #else  /* CONFIG_GPIOLIB && CONFIG_ACPI */
649 
650 struct acpi_device;
651 
acpi_dev_add_driver_gpios(struct acpi_device * adev,const struct acpi_gpio_mapping * gpios)652 static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
653 			      const struct acpi_gpio_mapping *gpios)
654 {
655 	return -ENXIO;
656 }
acpi_dev_remove_driver_gpios(struct acpi_device * adev)657 static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
658 
devm_acpi_dev_add_driver_gpios(struct device * dev,const struct acpi_gpio_mapping * gpios)659 static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
660 			      const struct acpi_gpio_mapping *gpios)
661 {
662 	return -ENXIO;
663 }
devm_acpi_dev_remove_driver_gpios(struct device * dev)664 static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
665 
666 #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
667 
668 
669 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
670 
671 int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
672 int gpiod_export_link(struct device *dev, const char *name,
673 		      struct gpio_desc *desc);
674 void gpiod_unexport(struct gpio_desc *desc);
675 
676 #else  /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
677 
gpiod_export(struct gpio_desc * desc,bool direction_may_change)678 static inline int gpiod_export(struct gpio_desc *desc,
679 			       bool direction_may_change)
680 {
681 	return -ENOSYS;
682 }
683 
gpiod_export_link(struct device * dev,const char * name,struct gpio_desc * desc)684 static inline int gpiod_export_link(struct device *dev, const char *name,
685 				    struct gpio_desc *desc)
686 {
687 	return -ENOSYS;
688 }
689 
gpiod_unexport(struct gpio_desc * desc)690 static inline void gpiod_unexport(struct gpio_desc *desc)
691 {
692 }
693 
694 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
695 
696 #endif
697