Merge tag 'probes-fixes-v6.16-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git...
[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>
91931af1 6#include <linux/err.h>
380c7ba3 7#include <linux/types.h>
79a9becd 8
5b191197 9struct acpi_device;
79a9becd 10struct device;
91e5ae95 11struct fwnode_handle;
380c7ba3 12
bf9346f5 13struct gpio_array;
380c7ba3 14struct gpio_desc;
bf9346f5 15
66858527 16/**
4398693a
BG
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
66858527
RI
23 */
24struct gpio_descs {
bf9346f5 25 struct gpio_array *info;
66858527
RI
26 unsigned int ndescs;
27 struct gpio_desc *desc[];
28};
29
39b2bbe3
AC
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)
f926dfc1 33#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
6deb8435 34/* GPIOD_FLAGS_BIT_NONEXCLUSIVE is DEPRECATED, don't use in new code. */
b0ce7b29 35#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
39b2bbe3
AC
36
37/**
4398693a
BG
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
39b2bbe3
AC
48 */
49enum 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,
0969a204
AS
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,
39b2bbe3
AC
57};
58
58b84f6a
LW
59#ifdef CONFIG_GPIOLIB
60
66858527
RI
61/* Return the number of GPIOs associated with a device / function */
62int gpiod_count(struct device *dev, const char *con_id);
63
bae48da2 64/* Acquire and dispose GPIOs */
b17d1bf1 65struct gpio_desc *__must_check gpiod_get(struct device *dev,
39b2bbe3
AC
66 const char *con_id,
67 enum gpiod_flags flags);
b17d1bf1 68struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
bae48da2 69 const char *con_id,
39b2bbe3
AC
70 unsigned int idx,
71 enum gpiod_flags flags);
b17d1bf1 72struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
39b2bbe3
AC
73 const char *con_id,
74 enum gpiod_flags flags);
b17d1bf1 75struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
29a1f233 76 const char *con_id,
39b2bbe3
AC
77 unsigned int index,
78 enum gpiod_flags flags);
66858527
RI
79struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
80 const char *con_id,
81 enum gpiod_flags flags);
82struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
83 const char *con_id,
84 enum gpiod_flags flags);
bae48da2 85void gpiod_put(struct gpio_desc *desc);
66858527 86void gpiod_put_array(struct gpio_descs *descs);
bae48da2 87
b17d1bf1 88struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
39b2bbe3
AC
89 const char *con_id,
90 enum gpiod_flags flags);
b17d1bf1 91struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
bae48da2 92 const char *con_id,
39b2bbe3
AC
93 unsigned int idx,
94 enum gpiod_flags flags);
b17d1bf1 95struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
39b2bbe3
AC
96 const char *con_id,
97 enum gpiod_flags flags);
29a1f233 98struct gpio_desc *__must_check
b17d1bf1 99devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
39b2bbe3 100 unsigned int index, enum gpiod_flags flags);
331758ee
RI
101struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
102 const char *con_id,
103 enum gpiod_flags flags);
104struct gpio_descs *__must_check
105devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
106 enum gpiod_flags flags);
bae48da2 107void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
891ddbc7 108void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
331758ee 109void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
bae48da2 110
8e53b0f1 111int gpiod_get_direction(struct gpio_desc *desc);
79a9becd
AC
112int gpiod_direction_input(struct gpio_desc *desc);
113int gpiod_direction_output(struct gpio_desc *desc, int value);
ef70bbe1 114int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
79a9becd
AC
115
116/* Value get/set from non-sleeping context */
117int gpiod_get_value(const struct gpio_desc *desc);
eec1d566 118int gpiod_get_array_value(unsigned int array_size,
b9762beb 119 struct gpio_desc **desc_array,
77588c14 120 struct gpio_array *array_info,
b9762beb 121 unsigned long *value_bitmap);
8ce258f6 122int gpiod_set_value(struct gpio_desc *desc, int value);
cf9af0d5
GU
123int 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);
79a9becd 127int gpiod_get_raw_value(const struct gpio_desc *desc);
eec1d566
LW
128int gpiod_get_raw_array_value(unsigned int array_size,
129 struct gpio_desc **desc_array,
77588c14 130 struct gpio_array *array_info,
b9762beb 131 unsigned long *value_bitmap);
8ce258f6 132int gpiod_set_raw_value(struct gpio_desc *desc, int value);
3027743f 133int gpiod_set_raw_array_value(unsigned int array_size,
3c940660
GU
134 struct gpio_desc **desc_array,
135 struct gpio_array *array_info,
136 unsigned long *value_bitmap);
79a9becd
AC
137
138/* Value get/set from sleeping context */
139int gpiod_get_value_cansleep(const struct gpio_desc *desc);
eec1d566
LW
140int gpiod_get_array_value_cansleep(unsigned int array_size,
141 struct gpio_desc **desc_array,
77588c14 142 struct gpio_array *array_info,
b9762beb 143 unsigned long *value_bitmap);
8ce258f6 144int gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
cf9af0d5
GU
145int 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);
79a9becd 149int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
eec1d566
LW
150int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
151 struct gpio_desc **desc_array,
77588c14 152 struct gpio_array *array_info,
b9762beb 153 unsigned long *value_bitmap);
8ce258f6 154int gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
3027743f 155int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
3c940660
GU
156 struct gpio_desc **desc_array,
157 struct gpio_array *array_info,
158 unsigned long *value_bitmap);
79a9becd 159
8ced32ff 160int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
13daf489 161int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce);
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
13949fa9
DT
174struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
175 const char *con_id, int index,
176 enum gpiod_flags flags,
177 const char *label);
2d2f116d
DT
178struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
179 struct fwnode_handle *child,
180 const char *con_id, int index,
181 enum gpiod_flags flags,
182 const char *label);
3498d869 183
265daffe
BG
184bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other);
185
79a9becd
AC
186#else /* CONFIG_GPIOLIB */
187
007094c8
BG
188#include <linux/bug.h>
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}
79a9becd
AC
351static inline int gpiod_get_value(const struct gpio_desc *desc)
352{
353 /* GPIO can never have been requested */
ffe0bbab 354 WARN_ON(desc);
79a9becd
AC
355 return 0;
356}
eec1d566
LW
357static inline int gpiod_get_array_value(unsigned int array_size,
358 struct gpio_desc **desc_array,
77588c14 359 struct gpio_array *array_info,
b9762beb 360 unsigned long *value_bitmap)
eec1d566
LW
361{
362 /* GPIO can never have been requested */
ffe0bbab 363 WARN_ON(desc_array);
eec1d566
LW
364 return 0;
365}
8ce258f6 366static inline int gpiod_set_value(struct gpio_desc *desc, int value)
79a9becd
AC
367{
368 /* GPIO can never have been requested */
ffe0bbab 369 WARN_ON(desc);
8ce258f6 370 return 0;
79a9becd 371}
cf9af0d5
GU
372static inline int gpiod_set_array_value(unsigned int array_size,
373 struct gpio_desc **desc_array,
374 struct gpio_array *array_info,
375 unsigned long *value_bitmap)
5f424243
RI
376{
377 /* GPIO can never have been requested */
ffe0bbab 378 WARN_ON(desc_array);
cf9af0d5 379 return 0;
5f424243 380}
79a9becd
AC
381static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
382{
383 /* GPIO can never have been requested */
ffe0bbab 384 WARN_ON(desc);
79a9becd
AC
385 return 0;
386}
eec1d566
LW
387static inline int gpiod_get_raw_array_value(unsigned int array_size,
388 struct gpio_desc **desc_array,
77588c14 389 struct gpio_array *array_info,
b9762beb 390 unsigned long *value_bitmap)
eec1d566
LW
391{
392 /* GPIO can never have been requested */
ffe0bbab 393 WARN_ON(desc_array);
eec1d566
LW
394 return 0;
395}
8ce258f6 396static inline int gpiod_set_raw_value(struct gpio_desc *desc, int value)
79a9becd
AC
397{
398 /* GPIO can never have been requested */
ffe0bbab 399 WARN_ON(desc);
8ce258f6 400 return 0;
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}
8ce258f6 427static inline int gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
79a9becd
AC
428{
429 /* GPIO can never have been requested */
ffe0bbab 430 WARN_ON(desc);
8ce258f6 431 return 0;
79a9becd 432}
cf9af0d5 433static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
5f424243 434 struct gpio_desc **desc_array,
77588c14 435 struct gpio_array *array_info,
b9762beb 436 unsigned long *value_bitmap)
5f424243
RI
437{
438 /* GPIO can never have been requested */
ffe0bbab 439 WARN_ON(desc_array);
cf9af0d5 440 return 0;
5f424243 441}
79a9becd
AC
442static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
443{
444 /* GPIO can never have been requested */
ffe0bbab 445 WARN_ON(desc);
79a9becd
AC
446 return 0;
447}
eec1d566
LW
448static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
449 struct gpio_desc **desc_array,
77588c14 450 struct gpio_array *array_info,
b9762beb 451 unsigned long *value_bitmap)
eec1d566
LW
452{
453 /* GPIO can never have been requested */
ffe0bbab 454 WARN_ON(desc_array);
eec1d566
LW
455 return 0;
456}
8ce258f6
BG
457static inline int gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
458 int value)
79a9becd
AC
459{
460 /* GPIO can never have been requested */
ffe0bbab 461 WARN_ON(desc);
8ce258f6 462 return 0;
79a9becd 463}
3027743f 464static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
5f424243 465 struct gpio_desc **desc_array,
77588c14 466 struct gpio_array *array_info,
b9762beb 467 unsigned long *value_bitmap)
5f424243
RI
468{
469 /* GPIO can never have been requested */
ffe0bbab 470 WARN_ON(desc_array);
3027743f 471 return 0;
5f424243 472}
79a9becd 473
8ced32ff
GU
474static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
475{
476 /* GPIO can never have been requested */
477 WARN_ON(desc);
478 return -ENOSYS;
479}
480
13daf489 481static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce)
79a9becd
AC
482{
483 /* GPIO can never have been requested */
ffe0bbab 484 WARN_ON(desc);
79a9becd
AC
485 return -ENOSYS;
486}
487
d3a5bcb4
MM
488static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
489{
490 /* GPIO can never have been requested */
491 WARN_ON(desc);
492}
493
79a9becd
AC
494static inline int gpiod_is_active_low(const struct gpio_desc *desc)
495{
496 /* GPIO can never have been requested */
ffe0bbab 497 WARN_ON(desc);
79a9becd
AC
498 return 0;
499}
500static inline int gpiod_cansleep(const struct gpio_desc *desc)
501{
502 /* GPIO can never have been requested */
ffe0bbab 503 WARN_ON(desc);
79a9becd
AC
504 return 0;
505}
506
507static inline int gpiod_to_irq(const struct gpio_desc *desc)
508{
509 /* GPIO can never have been requested */
ffe0bbab 510 WARN_ON(desc);
79a9becd
AC
511 return -EINVAL;
512}
513
18534df4
MS
514static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
515 const char *name)
90b39402
LW
516{
517 /* GPIO can never have been requested */
ffe0bbab 518 WARN_ON(desc);
18534df4 519 return -EINVAL;
90b39402
LW
520}
521
79a9becd
AC
522static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
523{
c5510b8d 524 return NULL;
79a9becd 525}
c0017ed7 526
79a9becd
AC
527static inline int desc_to_gpio(const struct gpio_desc *desc)
528{
529 /* GPIO can never have been requested */
ffe0bbab 530 WARN_ON(desc);
79a9becd
AC
531 return -EINVAL;
532}
79a9becd 533
13949fa9
DT
534static inline
535struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
536 const char *con_id, int index,
537 enum gpiod_flags flags,
538 const char *label)
539{
540 return ERR_PTR(-ENOSYS);
541}
542
2d2f116d
DT
543static inline
544struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
545 struct fwnode_handle *fwnode,
546 const char *con_id, int index,
547 enum gpiod_flags flags,
548 const char *label)
549{
550 return ERR_PTR(-ENOSYS);
551}
552
265daffe
BG
553static inline bool
554gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
555{
556 WARN_ON(desc || other);
557 return false;
558}
559
2d2f116d
DT
560#endif /* CONFIG_GPIOLIB */
561
63cdf624
BG
562#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_HTE)
563int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
564int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
565#else
007094c8
BG
566
567#include <linux/bug.h>
568
63cdf624
BG
569static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc,
570 unsigned long flags)
571{
572 if (!IS_ENABLED(CONFIG_GPIOLIB))
573 WARN_ON(desc);
574
575 return -ENOSYS;
576}
577static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc,
578 unsigned long flags)
579{
580 if (!IS_ENABLED(CONFIG_GPIOLIB))
581 WARN_ON(desc);
582
583 return -ENOSYS;
584}
585#endif /* CONFIG_GPIOLIB && CONFIG_HTE */
586
2d2f116d
DT
587static inline
588struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
589 struct fwnode_handle *fwnode,
590 const char *con_id,
591 enum gpiod_flags flags,
592 const char *label)
593{
594 return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
595 flags, label);
596}
597
2838bf94
AS
598struct acpi_gpio_params {
599 unsigned int crs_entry_index;
1be1cd03 600 unsigned short line_index;
2838bf94
AS
601 bool active_low;
602};
603
604struct acpi_gpio_mapping {
605 const char *name;
606 const struct acpi_gpio_params *data;
607 unsigned int size;
608
609/* Ignore IoRestriction field */
610#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
611/*
612 * When ACPI GPIO mapping table is in use the index parameter inside it
613 * refers to the GPIO resource in _CRS method. That index has no
614 * distinction of actual type of the resource. When consumer wants to
615 * get GpioIo type explicitly, this quirk may be used.
616 */
617#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
62d5247d
AS
618/* Use given pin as an absolute GPIO number in the system */
619#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER BIT(2)
2838bf94
AS
620
621 unsigned int quirks;
622};
623
b3907521
AS
624#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
625
2838bf94
AS
626int acpi_dev_add_driver_gpios(struct acpi_device *adev,
627 const struct acpi_gpio_mapping *gpios);
628void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
629
630int devm_acpi_dev_add_driver_gpios(struct device *dev,
631 const struct acpi_gpio_mapping *gpios);
2838bf94
AS
632
633#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
634
2838bf94
AS
635static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
636 const struct acpi_gpio_mapping *gpios)
637{
638 return -ENXIO;
639}
640static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
641
642static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
643 const struct acpi_gpio_mapping *gpios)
644{
645 return -ENXIO;
646}
2838bf94
AS
647
648#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
649
650
79a9becd
AC
651#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
652
653int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
654int gpiod_export_link(struct device *dev, const char *name,
655 struct gpio_desc *desc);
79a9becd
AC
656void gpiod_unexport(struct gpio_desc *desc);
657
658#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
659
660static inline int gpiod_export(struct gpio_desc *desc,
661 bool direction_may_change)
662{
663 return -ENOSYS;
664}
665
666static inline int gpiod_export_link(struct device *dev, const char *name,
667 struct gpio_desc *desc)
668{
669 return -ENOSYS;
670}
671
79a9becd
AC
672static inline void gpiod_unexport(struct gpio_desc *desc)
673{
674}
675
676#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
677
91931af1
DL
678static inline int gpiod_multi_set_value_cansleep(struct gpio_descs *descs,
679 unsigned long *value_bitmap)
680{
681 if (IS_ERR_OR_NULL(descs))
682 return PTR_ERR_OR_ZERO(descs);
683
684 return gpiod_set_array_value_cansleep(descs->ndescs, descs->desc,
685 descs->info, value_bitmap);
686}
687
79a9becd 688#endif