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