consumer.h 20.8 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4
#ifndef __LINUX_GPIO_CONSUMER_H
#define __LINUX_GPIO_CONSUMER_H

5
#include <linux/bits.h>
6
#include <linux/bug.h>
7
#include <linux/compiler_types.h>
8 9 10 11
#include <linux/err.h>

struct device;
struct gpio_desc;
12 13
struct gpio_array;

14
/**
15 16 17 18 19 20
 * struct gpio_descs - Struct containing an array of descriptors that can be
 *                     obtained using gpiod_get_array()
 *
 * @info:	Pointer to the opaque gpio_array structure
 * @ndescs:	Number of held descriptors
 * @desc:	Array of pointers to GPIO descriptors
21 22
 */
struct gpio_descs {
23
	struct gpio_array *info;
24 25 26 27
	unsigned int ndescs;
	struct gpio_desc *desc[];
};

28 29 30
#define GPIOD_FLAGS_BIT_DIR_SET		BIT(0)
#define GPIOD_FLAGS_BIT_DIR_OUT		BIT(1)
#define GPIOD_FLAGS_BIT_DIR_VAL		BIT(2)
31
#define GPIOD_FLAGS_BIT_OPEN_DRAIN	BIT(3)
32
#define GPIOD_FLAGS_BIT_NONEXCLUSIVE	BIT(4)
33 34

/**
35 36 37 38 39 40 41 42 43 44
 * enum gpiod_flags - Optional flags that can be passed to one of gpiod_* to
 *                    configure direction and output value. These values
 *                    cannot be OR'd.
 *
 * @GPIOD_ASIS:			Don't change anything
 * @GPIOD_IN:			Set lines to input mode
 * @GPIOD_OUT_LOW:		Set lines to output and drive them low
 * @GPIOD_OUT_HIGH:		Set lines to output and drive them high
 * @GPIOD_OUT_LOW_OPEN_DRAIN:	Set lines to open-drain output and drive them low
 * @GPIOD_OUT_HIGH_OPEN_DRAIN:	Set lines to open-drain output and drive them high
45 46 47 48 49 50 51
 */
enum gpiod_flags {
	GPIOD_ASIS	= 0,
	GPIOD_IN	= GPIOD_FLAGS_BIT_DIR_SET,
	GPIOD_OUT_LOW	= GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
	GPIOD_OUT_HIGH	= GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
			  GPIOD_FLAGS_BIT_DIR_VAL,
52 53
	GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
	GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
54 55
};

56 57
#ifdef CONFIG_GPIOLIB

58 59 60
/* Return the number of GPIOs associated with a device / function */
int gpiod_count(struct device *dev, const char *con_id);

61
/* Acquire and dispose GPIOs */
62
struct gpio_desc *__must_check gpiod_get(struct device *dev,
63 64
					 const char *con_id,
					 enum gpiod_flags flags);
65
struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
66
					       const char *con_id,
67 68
					       unsigned int idx,
					       enum gpiod_flags flags);
69
struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
70 71
						  const char *con_id,
						  enum gpiod_flags flags);
72
struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
73
							const char *con_id,
74 75
							unsigned int index,
							enum gpiod_flags flags);
76 77 78 79 80 81
struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
						const char *con_id,
						enum gpiod_flags flags);
struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
							const char *con_id,
							enum gpiod_flags flags);
82
void gpiod_put(struct gpio_desc *desc);
83
void gpiod_put_array(struct gpio_descs *descs);
84

85
struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
86 87
					      const char *con_id,
					      enum gpiod_flags flags);
88
struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
89
						    const char *con_id,
90 91
						    unsigned int idx,
						    enum gpiod_flags flags);
92
struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
93 94
						       const char *con_id,
						       enum gpiod_flags flags);
95
struct gpio_desc *__must_check
96
devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
97
			      unsigned int index, enum gpiod_flags flags);
98 99 100 101 102 103
struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
						     const char *con_id,
						     enum gpiod_flags flags);
struct gpio_descs *__must_check
devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
			      enum gpiod_flags flags);
104
void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
L
Linus Walleij 已提交
105
void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
106
void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
107

108
int gpiod_get_direction(struct gpio_desc *desc);
109 110
int gpiod_direction_input(struct gpio_desc *desc);
int gpiod_direction_output(struct gpio_desc *desc, int value);
111
int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
D
Dipen Patel 已提交
112 113
int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
114 115 116

/* Value get/set from non-sleeping context */
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 123 124 125
int gpiod_set_array_value(unsigned int array_size,
			  struct gpio_desc **desc_array,
			  struct gpio_array *array_info,
			  unsigned long *value_bitmap);
126
int gpiod_get_raw_value(const struct gpio_desc *desc);
127 128
int gpiod_get_raw_array_value(unsigned int array_size,
			      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);
L
Laura Abbott 已提交
132
int gpiod_set_raw_array_value(unsigned int array_size,
133 134 135
			      struct gpio_desc **desc_array,
			      struct gpio_array *array_info,
			      unsigned long *value_bitmap);
136 137 138

/* Value get/set from sleeping context */
int gpiod_get_value_cansleep(const struct gpio_desc *desc);
139 140
int gpiod_get_array_value_cansleep(unsigned int array_size,
				   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 145 146 147
int gpiod_set_array_value_cansleep(unsigned int array_size,
				   struct gpio_desc **desc_array,
				   struct gpio_array *array_info,
				   unsigned long *value_bitmap);
148
int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
149 150
int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
				       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);
L
Laura Abbott 已提交
154
int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
155 156 157
				       struct gpio_desc **desc_array,
				       struct gpio_array *array_info,
				       unsigned long *value_bitmap);
158

159
int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
160
int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce);
161
int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
162
void gpiod_toggle_active_low(struct gpio_desc *desc);
163 164 165 166 167

int gpiod_is_active_low(const struct gpio_desc *desc);
int gpiod_cansleep(const struct gpio_desc *desc);

int gpiod_to_irq(const struct gpio_desc *desc);
168
int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
169 170 171 172 173

/* Convert between the old gpio_ and new gpiod_ interfaces */
struct gpio_desc *gpio_to_desc(unsigned gpio);
int desc_to_gpio(const struct gpio_desc *desc);

174 175 176 177
/* Child properties interface */
struct fwnode_handle;

struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
178
					 const char *propname, int index,
179 180
					 enum gpiod_flags dflags,
					 const char *label);
181 182 183 184
struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
					 const char *con_id, int index,
					 enum gpiod_flags flags,
					 const char *label);
185 186 187 188 189
struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
					      struct fwnode_handle *child,
					      const char *con_id, int index,
					      enum gpiod_flags flags,
					      const char *label);
190

191 192
#else /* CONFIG_GPIOLIB */

193 194
#include <linux/kernel.h>

195 196 197 198 199
static inline int gpiod_count(struct device *dev, const char *con_id)
{
	return 0;
}

200 201 202
static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
						       const char *con_id,
						       enum gpiod_flags flags)
203 204 205
{
	return ERR_PTR(-ENOSYS);
}
206
static inline struct gpio_desc *__must_check
207 208 209 210
gpiod_get_index(struct device *dev,
		const char *con_id,
		unsigned int idx,
		enum gpiod_flags flags)
211 212 213
{
	return ERR_PTR(-ENOSYS);
}
214 215

static inline struct gpio_desc *__must_check
216 217
gpiod_get_optional(struct device *dev, const char *con_id,
		   enum gpiod_flags flags)
218
{
219
	return NULL;
220 221 222
}

static inline struct gpio_desc *__must_check
223 224
gpiod_get_index_optional(struct device *dev, const char *con_id,
			 unsigned int index, enum gpiod_flags flags)
225
{
226
	return NULL;
227 228
}

229 230 231 232 233 234 235 236 237 238 239
static inline struct gpio_descs *__must_check
gpiod_get_array(struct device *dev, const char *con_id,
		enum gpiod_flags flags)
{
	return ERR_PTR(-ENOSYS);
}

static inline struct gpio_descs *__must_check
gpiod_get_array_optional(struct device *dev, const char *con_id,
			 enum gpiod_flags flags)
{
240
	return NULL;
241 242
}

243 244 245 246 247
static inline void gpiod_put(struct gpio_desc *desc)
{
	might_sleep();

	/* GPIO can never have been requested */
248
	WARN_ON(desc);
249 250
}

L
Linus Walleij 已提交
251 252 253 254 255 256
static inline void devm_gpiod_unhinge(struct device *dev,
				      struct gpio_desc *desc)
{
	might_sleep();

	/* GPIO can never have been requested */
257
	WARN_ON(desc);
L
Linus Walleij 已提交
258 259
}

260 261 262 263 264
static inline void gpiod_put_array(struct gpio_descs *descs)
{
	might_sleep();

	/* GPIO can never have been requested */
265
	WARN_ON(descs);
266 267
}

268
static inline struct gpio_desc *__must_check
269
devm_gpiod_get(struct device *dev,
270 271
		 const char *con_id,
		 enum gpiod_flags flags)
272 273 274 275
{
	return ERR_PTR(-ENOSYS);
}
static inline
276
struct gpio_desc *__must_check
277
devm_gpiod_get_index(struct device *dev,
278 279 280
		       const char *con_id,
		       unsigned int idx,
		       enum gpiod_flags flags)
281 282 283
{
	return ERR_PTR(-ENOSYS);
}
284 285

static inline struct gpio_desc *__must_check
286
devm_gpiod_get_optional(struct device *dev, const char *con_id,
287
			  enum gpiod_flags flags)
288
{
289
	return NULL;
290 291 292
}

static inline struct gpio_desc *__must_check
293
devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
294
				unsigned int index, enum gpiod_flags flags)
295
{
296
	return NULL;
297 298
}

299 300 301 302 303 304 305 306 307 308 309
static inline struct gpio_descs *__must_check
devm_gpiod_get_array(struct device *dev, const char *con_id,
		     enum gpiod_flags flags)
{
	return ERR_PTR(-ENOSYS);
}

static inline struct gpio_descs *__must_check
devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
			      enum gpiod_flags flags)
{
310
	return NULL;
311 312
}

313
static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
314 315 316 317
{
	might_sleep();

	/* GPIO can never have been requested */
318
	WARN_ON(desc);
319 320 321 322
}

static inline void devm_gpiod_put_array(struct device *dev,
					struct gpio_descs *descs)
323 324 325 326
{
	might_sleep();

	/* GPIO can never have been requested */
327
	WARN_ON(descs);
328 329 330 331 332 333
}


static inline int gpiod_get_direction(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
334
	WARN_ON(desc);
335 336 337 338 339
	return -ENOSYS;
}
static inline int gpiod_direction_input(struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
340
	WARN_ON(desc);
341 342 343 344 345
	return -ENOSYS;
}
static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
{
	/* GPIO can never have been requested */
346
	WARN_ON(desc);
347 348
	return -ENOSYS;
}
349 350 351
static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
{
	/* GPIO can never have been requested */
352
	WARN_ON(desc);
353 354
	return -ENOSYS;
}
D
Dipen Patel 已提交
355 356 357 358 359 360 361 362 363 364 365 366
static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc,
					       unsigned long flags)
{
	WARN_ON(desc);
	return -ENOSYS;
}
static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc,
						unsigned long flags)
{
	WARN_ON(desc);
	return -ENOSYS;
}
367 368 369
static inline int gpiod_get_value(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
370
	WARN_ON(desc);
371 372
	return 0;
}
373 374
static inline int gpiod_get_array_value(unsigned int array_size,
					struct gpio_desc **desc_array,
375
					struct gpio_array *array_info,
376
					unsigned long *value_bitmap)
377 378
{
	/* GPIO can never have been requested */
379
	WARN_ON(desc_array);
380 381
	return 0;
}
382 383 384
static inline void gpiod_set_value(struct gpio_desc *desc, int value)
{
	/* GPIO can never have been requested */
385
	WARN_ON(desc);
386
}
387 388 389 390
static inline int gpiod_set_array_value(unsigned int array_size,
					struct gpio_desc **desc_array,
					struct gpio_array *array_info,
					unsigned long *value_bitmap)
391 392
{
	/* GPIO can never have been requested */
393
	WARN_ON(desc_array);
394
	return 0;
395
}
396 397 398
static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
399
	WARN_ON(desc);
400 401
	return 0;
}
402 403
static inline int gpiod_get_raw_array_value(unsigned int array_size,
					    struct gpio_desc **desc_array,
404
					    struct gpio_array *array_info,
405
					    unsigned long *value_bitmap)
406 407
{
	/* GPIO can never have been requested */
408
	WARN_ON(desc_array);
409 410
	return 0;
}
411 412 413
static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
{
	/* GPIO can never have been requested */
414
	WARN_ON(desc);
415
}
L
Laura Abbott 已提交
416
static inline int gpiod_set_raw_array_value(unsigned int array_size,
417 418 419
					    struct gpio_desc **desc_array,
					    struct gpio_array *array_info,
					    unsigned long *value_bitmap)
420 421
{
	/* GPIO can never have been requested */
422
	WARN_ON(desc_array);
L
Laura Abbott 已提交
423
	return 0;
424
}
425 426 427 428

static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
429
	WARN_ON(desc);
430 431
	return 0;
}
432 433
static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
				     struct gpio_desc **desc_array,
434
				     struct gpio_array *array_info,
435
				     unsigned long *value_bitmap)
436 437
{
	/* GPIO can never have been requested */
438
	WARN_ON(desc_array);
439 440
	return 0;
}
441 442 443
static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
{
	/* GPIO can never have been requested */
444
	WARN_ON(desc);
445
}
446
static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
447
					    struct gpio_desc **desc_array,
448
					    struct gpio_array *array_info,
449
					    unsigned long *value_bitmap)
450 451
{
	/* GPIO can never have been requested */
452
	WARN_ON(desc_array);
453
	return 0;
454
}
455 456 457
static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
458
	WARN_ON(desc);
459 460
	return 0;
}
461 462
static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
					       struct gpio_desc **desc_array,
463
					       struct gpio_array *array_info,
464
					       unsigned long *value_bitmap)
465 466
{
	/* GPIO can never have been requested */
467
	WARN_ON(desc_array);
468 469
	return 0;
}
470 471 472 473
static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
						int value)
{
	/* GPIO can never have been requested */
474
	WARN_ON(desc);
475
}
L
Laura Abbott 已提交
476
static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
477
						struct gpio_desc **desc_array,
478
						struct gpio_array *array_info,
479
						unsigned long *value_bitmap)
480 481
{
	/* GPIO can never have been requested */
482
	WARN_ON(desc_array);
L
Laura Abbott 已提交
483
	return 0;
484
}
485

486 487 488 489 490 491 492
static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
{
	/* GPIO can never have been requested */
	WARN_ON(desc);
	return -ENOSYS;
}

493
static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce)
494 495
{
	/* GPIO can never have been requested */
496
	WARN_ON(desc);
497 498 499
	return -ENOSYS;
}

500 501 502
static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
{
	/* GPIO can never have been requested */
503
	WARN_ON(desc);
504 505 506
	return -ENOSYS;
}

507 508 509 510 511 512
static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
	WARN_ON(desc);
}

513 514 515
static inline int gpiod_is_active_low(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
516
	WARN_ON(desc);
517 518 519 520 521
	return 0;
}
static inline int gpiod_cansleep(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
522
	WARN_ON(desc);
523 524 525 526 527 528
	return 0;
}

static inline int gpiod_to_irq(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
529
	WARN_ON(desc);
530 531 532
	return -EINVAL;
}

533 534
static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
					  const char *name)
535 536
{
	/* GPIO can never have been requested */
537
	WARN_ON(desc);
538
	return -EINVAL;
539 540
}

541 542
static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
{
543
	return NULL;
544
}
545

546 547 548
static inline int desc_to_gpio(const struct gpio_desc *desc)
{
	/* GPIO can never have been requested */
549
	WARN_ON(desc);
550 551 552
	return -EINVAL;
}

553 554 555
/* Child properties interface */
struct fwnode_handle;

556 557
static inline
struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
558
					 const char *propname, int index,
559 560
					 enum gpiod_flags dflags,
					 const char *label)
561 562 563 564
{
	return ERR_PTR(-ENOSYS);
}

565 566 567 568 569 570 571 572 573
static inline
struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
					 const char *con_id, int index,
					 enum gpiod_flags flags,
					 const char *label)
{
	return ERR_PTR(-ENOSYS);
}

574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
static inline
struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
					      struct fwnode_handle *fwnode,
					      const char *con_id, int index,
					      enum gpiod_flags flags,
					      const char *label)
{
	return ERR_PTR(-ENOSYS);
}

#endif /* CONFIG_GPIOLIB */

static inline
struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
					struct fwnode_handle *fwnode,
					const char *con_id,
					enum gpiod_flags flags,
					const char *label)
{
	return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
					   flags, label);
}

597 598 599 600 601 602 603
static inline
struct gpio_desc *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)
{
604 605
	return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
					   flags, label);
606 607
}

608
static inline
609 610 611 612 613
struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
						   const char *con_id,
						   struct fwnode_handle *child,
						   enum gpiod_flags flags,
						   const char *label)
614
{
615
	return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
616 617
}

618 619 620
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
struct device_node;

621
struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
622 623 624 625 626 627 628 629 630
					 const char *propname, int index,
					 enum gpiod_flags dflags,
					 const char *label);

#else  /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */

struct device_node;

static inline
631
struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
632 633 634 635 636 637 638 639 640 641 642 643 644
					 const char *propname, int index,
					 enum gpiod_flags dflags,
					 const char *label)
{
	return ERR_PTR(-ENOSYS);
}

#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */

#ifdef CONFIG_GPIOLIB
struct device_node;

struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
645
					      const struct device_node *node,
646 647 648 649 650 651 652 653 654 655
					      const char *propname, int index,
					      enum gpiod_flags dflags,
					      const char *label);

#else  /* CONFIG_GPIOLIB */

struct device_node;

static inline
struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
656
					      const struct device_node *node,
657 658 659 660 661 662 663 664 665
					      const char *propname, int index,
					      enum gpiod_flags dflags,
					      const char *label)
{
	return ERR_PTR(-ENOSYS);
}

#endif /* CONFIG_GPIOLIB */

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
struct acpi_gpio_params {
	unsigned int crs_entry_index;
	unsigned int line_index;
	bool active_low;
};

struct acpi_gpio_mapping {
	const char *name;
	const struct acpi_gpio_params *data;
	unsigned int size;

/* Ignore IoRestriction field */
#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION	BIT(0)
/*
 * When ACPI GPIO mapping table is in use the index parameter inside it
 * refers to the GPIO resource in _CRS method. That index has no
 * distinction of actual type of the resource. When consumer wants to
 * get GpioIo type explicitly, this quirk may be used.
 */
#define ACPI_GPIO_QUIRK_ONLY_GPIOIO		BIT(1)
686 687
/* Use given pin as an absolute GPIO number in the system */
#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER		BIT(2)
688 689 690 691 692 693

	unsigned int quirks;
};

struct acpi_device;

694 695
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)

696 697 698 699 700 701 702
int acpi_dev_add_driver_gpios(struct acpi_device *adev,
			      const struct acpi_gpio_mapping *gpios);
void acpi_dev_remove_driver_gpios(struct acpi_device *adev);

int devm_acpi_dev_add_driver_gpios(struct device *dev,
				   const struct acpi_gpio_mapping *gpios);

703 704
struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label);

705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
#else  /* CONFIG_GPIOLIB && CONFIG_ACPI */

static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
			      const struct acpi_gpio_mapping *gpios)
{
	return -ENXIO;
}
static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}

static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
			      const struct acpi_gpio_mapping *gpios)
{
	return -ENXIO;
}

#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */


723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)

int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
int gpiod_export_link(struct device *dev, const char *name,
		      struct gpio_desc *desc);
void gpiod_unexport(struct gpio_desc *desc);

#else  /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */

static inline int gpiod_export(struct gpio_desc *desc,
			       bool direction_may_change)
{
	return -ENOSYS;
}

static inline int gpiod_export_link(struct device *dev, const char *name,
				    struct gpio_desc *desc)
{
	return -ENOSYS;
}

static inline void gpiod_unexport(struct gpio_desc *desc)
{
}

#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */

#endif