Merge tag 'fs.xattr.simple.noaudit.v6.2' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-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
046e14af 5#include <linux/bits.h>
cdf86cd2 6#include <linux/bug.h>
046e14af 7#include <linux/compiler_types.h>
79a9becd 8#include <linux/err.h>
79a9becd 9
79a9becd 10struct device;
79a9becd 11struct gpio_desc;
bf9346f5
JK
12struct gpio_array;
13
66858527 14/**
4398693a
BG
15 * struct gpio_descs - Struct containing an array of descriptors that can be
16 * obtained using gpiod_get_array()
17 *
18 * @info: Pointer to the opaque gpio_array structure
19 * @ndescs: Number of held descriptors
20 * @desc: Array of pointers to GPIO descriptors
66858527
RI
21 */
22struct gpio_descs {
bf9346f5 23 struct gpio_array *info;
66858527
RI
24 unsigned int ndescs;
25 struct gpio_desc *desc[];
26};
27
39b2bbe3
AC
28#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
29#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
30#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
f926dfc1 31#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
b0ce7b29 32#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
39b2bbe3
AC
33
34/**
4398693a
BG
35 * enum gpiod_flags - Optional flags that can be passed to one of gpiod_* to
36 * configure direction and output value. These values
37 * cannot be OR'd.
38 *
39 * @GPIOD_ASIS: Don't change anything
40 * @GPIOD_IN: Set lines to input mode
41 * @GPIOD_OUT_LOW: Set lines to output and drive them low
42 * @GPIOD_OUT_HIGH: Set lines to output and drive them high
43 * @GPIOD_OUT_LOW_OPEN_DRAIN: Set lines to open-drain output and drive them low
44 * @GPIOD_OUT_HIGH_OPEN_DRAIN: Set lines to open-drain output and drive them high
39b2bbe3
AC
45 */
46enum gpiod_flags {
47 GPIOD_ASIS = 0,
48 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
49 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
50 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
51 GPIOD_FLAGS_BIT_DIR_VAL,
0969a204
AS
52 GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
53 GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
39b2bbe3
AC
54};
55
58b84f6a
LW
56#ifdef CONFIG_GPIOLIB
57
66858527
RI
58/* Return the number of GPIOs associated with a device / function */
59int gpiod_count(struct device *dev, const char *con_id);
60
bae48da2 61/* Acquire and dispose GPIOs */
b17d1bf1 62struct gpio_desc *__must_check gpiod_get(struct device *dev,
39b2bbe3
AC
63 const char *con_id,
64 enum gpiod_flags flags);
b17d1bf1 65struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
bae48da2 66 const char *con_id,
39b2bbe3
AC
67 unsigned int idx,
68 enum gpiod_flags flags);
b17d1bf1 69struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
39b2bbe3
AC
70 const char *con_id,
71 enum gpiod_flags flags);
b17d1bf1 72struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
29a1f233 73 const char *con_id,
39b2bbe3
AC
74 unsigned int index,
75 enum gpiod_flags flags);
66858527
RI
76struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
77 const char *con_id,
78 enum gpiod_flags flags);
79struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
80 const char *con_id,
81 enum gpiod_flags flags);
bae48da2 82void gpiod_put(struct gpio_desc *desc);
66858527 83void gpiod_put_array(struct gpio_descs *descs);
bae48da2 84
b17d1bf1 85struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
39b2bbe3
AC
86 const char *con_id,
87 enum gpiod_flags flags);
b17d1bf1 88struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
bae48da2 89 const char *con_id,
39b2bbe3
AC
90 unsigned int idx,
91 enum gpiod_flags flags);
b17d1bf1 92struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
39b2bbe3
AC
93 const char *con_id,
94 enum gpiod_flags flags);
29a1f233 95struct gpio_desc *__must_check
b17d1bf1 96devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
39b2bbe3 97 unsigned int index, enum gpiod_flags flags);
331758ee
RI
98struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
99 const char *con_id,
100 enum gpiod_flags flags);
101struct gpio_descs *__must_check
102devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
103 enum gpiod_flags flags);
bae48da2 104void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
891ddbc7 105void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
331758ee 106void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
bae48da2 107
8e53b0f1 108int gpiod_get_direction(struct gpio_desc *desc);
79a9becd
AC
109int gpiod_direction_input(struct gpio_desc *desc);
110int gpiod_direction_output(struct gpio_desc *desc, int value);
ef70bbe1 111int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
42112dd7
DP
112int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
113int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
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 158
8ced32ff 159int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
13daf489 160int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce);
e10f72bf 161int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
d3a5bcb4 162void gpiod_toggle_active_low(struct gpio_desc *desc);
79a9becd
AC
163
164int gpiod_is_active_low(const struct gpio_desc *desc);
165int gpiod_cansleep(const struct gpio_desc *desc);
166
167int gpiod_to_irq(const struct gpio_desc *desc);
18534df4 168int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
79a9becd
AC
169
170/* Convert between the old gpio_ and new gpiod_ interfaces */
171struct gpio_desc *gpio_to_desc(unsigned gpio);
172int desc_to_gpio(const struct gpio_desc *desc);
79a9becd 173
40b73183
MW
174/* Child properties interface */
175struct fwnode_handle;
176
13949fa9
DT
177struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
178 const char *con_id, int index,
179 enum gpiod_flags flags,
180 const char *label);
2d2f116d
DT
181struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
182 struct fwnode_handle *child,
183 const char *con_id, int index,
184 enum gpiod_flags flags,
185 const char *label);
3498d869 186
79a9becd
AC
187#else /* CONFIG_GPIOLIB */
188
046e14af
AS
189#include <linux/kernel.h>
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}
42112dd7
DP
351static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc,
352 unsigned long flags)
353{
354 WARN_ON(desc);
355 return -ENOSYS;
356}
357static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc,
358 unsigned long flags)
359{
360 WARN_ON(desc);
361 return -ENOSYS;
362}
79a9becd
AC
363static inline int gpiod_get_value(const struct gpio_desc *desc)
364{
365 /* GPIO can never have been requested */
ffe0bbab 366 WARN_ON(desc);
79a9becd
AC
367 return 0;
368}
eec1d566
LW
369static inline int gpiod_get_array_value(unsigned int array_size,
370 struct gpio_desc **desc_array,
77588c14 371 struct gpio_array *array_info,
b9762beb 372 unsigned long *value_bitmap)
eec1d566
LW
373{
374 /* GPIO can never have been requested */
ffe0bbab 375 WARN_ON(desc_array);
eec1d566
LW
376 return 0;
377}
79a9becd
AC
378static inline void gpiod_set_value(struct gpio_desc *desc, int value)
379{
380 /* GPIO can never have been requested */
ffe0bbab 381 WARN_ON(desc);
79a9becd 382}
cf9af0d5
GU
383static inline int gpiod_set_array_value(unsigned int array_size,
384 struct gpio_desc **desc_array,
385 struct gpio_array *array_info,
386 unsigned long *value_bitmap)
5f424243
RI
387{
388 /* GPIO can never have been requested */
ffe0bbab 389 WARN_ON(desc_array);
cf9af0d5 390 return 0;
5f424243 391}
79a9becd
AC
392static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
393{
394 /* GPIO can never have been requested */
ffe0bbab 395 WARN_ON(desc);
79a9becd
AC
396 return 0;
397}
eec1d566
LW
398static inline int gpiod_get_raw_array_value(unsigned int array_size,
399 struct gpio_desc **desc_array,
77588c14 400 struct gpio_array *array_info,
b9762beb 401 unsigned long *value_bitmap)
eec1d566
LW
402{
403 /* GPIO can never have been requested */
ffe0bbab 404 WARN_ON(desc_array);
eec1d566
LW
405 return 0;
406}
79a9becd
AC
407static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
408{
409 /* GPIO can never have been requested */
ffe0bbab 410 WARN_ON(desc);
79a9becd 411}
3027743f 412static inline int gpiod_set_raw_array_value(unsigned int array_size,
3c940660
GU
413 struct gpio_desc **desc_array,
414 struct gpio_array *array_info,
415 unsigned long *value_bitmap)
5f424243
RI
416{
417 /* GPIO can never have been requested */
ffe0bbab 418 WARN_ON(desc_array);
3027743f 419 return 0;
5f424243 420}
79a9becd
AC
421
422static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
423{
424 /* GPIO can never have been requested */
ffe0bbab 425 WARN_ON(desc);
79a9becd
AC
426 return 0;
427}
eec1d566
LW
428static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
429 struct gpio_desc **desc_array,
77588c14 430 struct gpio_array *array_info,
b9762beb 431 unsigned long *value_bitmap)
eec1d566
LW
432{
433 /* GPIO can never have been requested */
ffe0bbab 434 WARN_ON(desc_array);
eec1d566
LW
435 return 0;
436}
79a9becd
AC
437static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
438{
439 /* GPIO can never have been requested */
ffe0bbab 440 WARN_ON(desc);
79a9becd 441}
cf9af0d5 442static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
5f424243 443 struct gpio_desc **desc_array,
77588c14 444 struct gpio_array *array_info,
b9762beb 445 unsigned long *value_bitmap)
5f424243
RI
446{
447 /* GPIO can never have been requested */
ffe0bbab 448 WARN_ON(desc_array);
cf9af0d5 449 return 0;
5f424243 450}
79a9becd
AC
451static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
452{
453 /* GPIO can never have been requested */
ffe0bbab 454 WARN_ON(desc);
79a9becd
AC
455 return 0;
456}
eec1d566
LW
457static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
458 struct gpio_desc **desc_array,
77588c14 459 struct gpio_array *array_info,
b9762beb 460 unsigned long *value_bitmap)
eec1d566
LW
461{
462 /* GPIO can never have been requested */
ffe0bbab 463 WARN_ON(desc_array);
eec1d566
LW
464 return 0;
465}
79a9becd
AC
466static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
467 int value)
468{
469 /* GPIO can never have been requested */
ffe0bbab 470 WARN_ON(desc);
79a9becd 471}
3027743f 472static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
5f424243 473 struct gpio_desc **desc_array,
77588c14 474 struct gpio_array *array_info,
b9762beb 475 unsigned long *value_bitmap)
5f424243
RI
476{
477 /* GPIO can never have been requested */
ffe0bbab 478 WARN_ON(desc_array);
3027743f 479 return 0;
5f424243 480}
79a9becd 481
8ced32ff
GU
482static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
483{
484 /* GPIO can never have been requested */
485 WARN_ON(desc);
486 return -ENOSYS;
487}
488
13daf489 489static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce)
79a9becd
AC
490{
491 /* GPIO can never have been requested */
ffe0bbab 492 WARN_ON(desc);
79a9becd
AC
493 return -ENOSYS;
494}
495
e10f72bf
AJ
496static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
497{
498 /* GPIO can never have been requested */
ffe0bbab 499 WARN_ON(desc);
e10f72bf
AJ
500 return -ENOSYS;
501}
502
d3a5bcb4
MM
503static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
504{
505 /* GPIO can never have been requested */
506 WARN_ON(desc);
507}
508
79a9becd
AC
509static inline int gpiod_is_active_low(const struct gpio_desc *desc)
510{
511 /* GPIO can never have been requested */
ffe0bbab 512 WARN_ON(desc);
79a9becd
AC
513 return 0;
514}
515static inline int gpiod_cansleep(const struct gpio_desc *desc)
516{
517 /* GPIO can never have been requested */
ffe0bbab 518 WARN_ON(desc);
79a9becd
AC
519 return 0;
520}
521
522static inline int gpiod_to_irq(const struct gpio_desc *desc)
523{
524 /* GPIO can never have been requested */
ffe0bbab 525 WARN_ON(desc);
79a9becd
AC
526 return -EINVAL;
527}
528
18534df4
MS
529static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
530 const char *name)
90b39402
LW
531{
532 /* GPIO can never have been requested */
ffe0bbab 533 WARN_ON(desc);
18534df4 534 return -EINVAL;
90b39402
LW
535}
536
79a9becd
AC
537static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
538{
c5510b8d 539 return NULL;
79a9becd 540}
c0017ed7 541
79a9becd
AC
542static inline int desc_to_gpio(const struct gpio_desc *desc)
543{
544 /* GPIO can never have been requested */
ffe0bbab 545 WARN_ON(desc);
79a9becd
AC
546 return -EINVAL;
547}
79a9becd 548
496e7ce2
GU
549/* Child properties interface */
550struct fwnode_handle;
551
13949fa9
DT
552static inline
553struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
554 const char *con_id, int index,
555 enum gpiod_flags flags,
556 const char *label)
557{
558 return ERR_PTR(-ENOSYS);
559}
560
2d2f116d
DT
561static inline
562struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
563 struct fwnode_handle *fwnode,
564 const char *con_id, int index,
565 enum gpiod_flags flags,
566 const char *label)
567{
568 return ERR_PTR(-ENOSYS);
569}
570
571#endif /* CONFIG_GPIOLIB */
572
573static inline
574struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
575 struct fwnode_handle *fwnode,
576 const char *con_id,
577 enum gpiod_flags flags,
578 const char *label)
579{
580 return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
581 flags, label);
582}
583
537b94da
BB
584static inline
585struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
586 const char *con_id, int index,
587 struct fwnode_handle *child,
588 enum gpiod_flags flags,
589 const char *label)
590{
2d2f116d
DT
591 return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
592 flags, label);
537b94da
BB
593}
594
a264d10f 595static inline
4b094797
BB
596struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
597 const char *con_id,
598 struct fwnode_handle *child,
599 enum gpiod_flags flags,
600 const char *label)
496e7ce2 601{
2d2f116d 602 return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
496e7ce2
GU
603}
604
fce04b1c
AS
605#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
606struct device_node;
607
e6ae9a83 608struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
fce04b1c
AS
609 const char *propname, int index,
610 enum gpiod_flags dflags,
611 const char *label);
612
613#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
614
615struct device_node;
616
617static inline
e6ae9a83 618struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
fce04b1c
AS
619 const char *propname, int index,
620 enum gpiod_flags dflags,
621 const char *label)
622{
623 return ERR_PTR(-ENOSYS);
624}
625
626#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
627
628#ifdef CONFIG_GPIOLIB
629struct device_node;
630
631struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
e6ae9a83 632 const struct device_node *node,
fce04b1c
AS
633 const char *propname, int index,
634 enum gpiod_flags dflags,
635 const char *label);
636
637#else /* CONFIG_GPIOLIB */
638
639struct device_node;
640
641static inline
642struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
e6ae9a83 643 const struct device_node *node,
fce04b1c
AS
644 const char *propname, int index,
645 enum gpiod_flags dflags,
646 const char *label)
647{
648 return ERR_PTR(-ENOSYS);
649}
650
651#endif /* CONFIG_GPIOLIB */
652
2838bf94
AS
653struct acpi_gpio_params {
654 unsigned int crs_entry_index;
655 unsigned int line_index;
656 bool active_low;
657};
658
659struct acpi_gpio_mapping {
660 const char *name;
661 const struct acpi_gpio_params *data;
662 unsigned int size;
663
664/* Ignore IoRestriction field */
665#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
666/*
667 * When ACPI GPIO mapping table is in use the index parameter inside it
668 * refers to the GPIO resource in _CRS method. That index has no
669 * distinction of actual type of the resource. When consumer wants to
670 * get GpioIo type explicitly, this quirk may be used.
671 */
672#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
62d5247d
AS
673/* Use given pin as an absolute GPIO number in the system */
674#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER BIT(2)
2838bf94
AS
675
676 unsigned int quirks;
677};
678
2838bf94
AS
679struct acpi_device;
680
b3907521
AS
681#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
682
2838bf94
AS
683int acpi_dev_add_driver_gpios(struct acpi_device *adev,
684 const struct acpi_gpio_mapping *gpios);
685void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
686
687int devm_acpi_dev_add_driver_gpios(struct device *dev,
688 const struct acpi_gpio_mapping *gpios);
2838bf94 689
0c2cae09 690struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label);
43582f29 691
2838bf94
AS
692#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
693
2838bf94
AS
694static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
695 const struct acpi_gpio_mapping *gpios)
696{
697 return -ENXIO;
698}
699static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
700
701static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
702 const struct acpi_gpio_mapping *gpios)
703{
704 return -ENXIO;
705}
2838bf94 706
0c2cae09
AS
707static inline struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin,
708 char *label)
709{
710 return ERR_PTR(-ENOSYS);
711}
712
2838bf94
AS
713#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
714
715
79a9becd
AC
716#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
717
718int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
719int gpiod_export_link(struct device *dev, const char *name,
720 struct gpio_desc *desc);
79a9becd
AC
721void gpiod_unexport(struct gpio_desc *desc);
722
723#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
724
725static inline int gpiod_export(struct gpio_desc *desc,
726 bool direction_may_change)
727{
728 return -ENOSYS;
729}
730
731static inline int gpiod_export_link(struct device *dev, const char *name,
732 struct gpio_desc *desc)
733{
734 return -ENOSYS;
735}
736
79a9becd
AC
737static inline void gpiod_unexport(struct gpio_desc *desc)
738{
739}
740
741#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
742
743#endif