gpio.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef __LINUX_GPIO_H
  2. #define __LINUX_GPIO_H
  3. /* see Documentation/gpio.txt */
  4. /* make these flag values available regardless of GPIO kconfig options */
  5. #define GPIOF_DIR_OUT (0 << 0)
  6. #define GPIOF_DIR_IN (1 << 0)
  7. #define GPIOF_INIT_LOW (0 << 1)
  8. #define GPIOF_INIT_HIGH (1 << 1)
  9. #define GPIOF_IN (GPIOF_DIR_IN)
  10. #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
  11. #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
  12. /* Gpio pin is open drain */
  13. #define GPIOF_OPEN_DRAIN (1 << 2)
  14. /* Gpio pin is open source */
  15. #define GPIOF_OPEN_SOURCE (1 << 3)
  16. /**
  17. * struct gpio - a structure describing a GPIO with configuration
  18. * @gpio: the GPIO number
  19. * @flags: GPIO configuration as specified by GPIOF_*
  20. * @label: a literal description string of this GPIO
  21. */
  22. struct gpio {
  23. unsigned gpio;
  24. unsigned long flags;
  25. const char *label;
  26. };
  27. #ifdef CONFIG_GENERIC_GPIO
  28. #include <asm/gpio.h>
  29. #else
  30. #include <linux/kernel.h>
  31. #include <linux/types.h>
  32. #include <linux/errno.h>
  33. #include <linux/bug.h>
  34. struct device;
  35. struct gpio_chip;
  36. static inline bool gpio_is_valid(int number)
  37. {
  38. return false;
  39. }
  40. static inline int gpio_request(unsigned gpio, const char *label)
  41. {
  42. return -ENOSYS;
  43. }
  44. static inline int gpio_request_one(unsigned gpio,
  45. unsigned long flags, const char *label)
  46. {
  47. return -ENOSYS;
  48. }
  49. static inline int gpio_request_array(const struct gpio *array, size_t num)
  50. {
  51. return -ENOSYS;
  52. }
  53. static inline void gpio_free(unsigned gpio)
  54. {
  55. might_sleep();
  56. /* GPIO can never have been requested */
  57. WARN_ON(1);
  58. }
  59. static inline void gpio_free_array(const struct gpio *array, size_t num)
  60. {
  61. might_sleep();
  62. /* GPIO can never have been requested */
  63. WARN_ON(1);
  64. }
  65. static inline int gpio_direction_input(unsigned gpio)
  66. {
  67. return -ENOSYS;
  68. }
  69. static inline int gpio_direction_output(unsigned gpio, int value)
  70. {
  71. return -ENOSYS;
  72. }
  73. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  74. {
  75. return -ENOSYS;
  76. }
  77. static inline int gpio_get_value(unsigned gpio)
  78. {
  79. /* GPIO can never have been requested or set as {in,out}put */
  80. WARN_ON(1);
  81. return 0;
  82. }
  83. static inline void gpio_set_value(unsigned gpio, int value)
  84. {
  85. /* GPIO can never have been requested or set as output */
  86. WARN_ON(1);
  87. }
  88. static inline int gpio_cansleep(unsigned gpio)
  89. {
  90. /* GPIO can never have been requested or set as {in,out}put */
  91. WARN_ON(1);
  92. return 0;
  93. }
  94. static inline int gpio_get_value_cansleep(unsigned gpio)
  95. {
  96. /* GPIO can never have been requested or set as {in,out}put */
  97. WARN_ON(1);
  98. return 0;
  99. }
  100. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  101. {
  102. /* GPIO can never have been requested or set as output */
  103. WARN_ON(1);
  104. }
  105. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  106. {
  107. /* GPIO can never have been requested or set as {in,out}put */
  108. WARN_ON(1);
  109. return -EINVAL;
  110. }
  111. static inline int gpio_export_link(struct device *dev, const char *name,
  112. unsigned gpio)
  113. {
  114. /* GPIO can never have been exported */
  115. WARN_ON(1);
  116. return -EINVAL;
  117. }
  118. static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
  119. {
  120. /* GPIO can never have been requested */
  121. WARN_ON(1);
  122. return -EINVAL;
  123. }
  124. static inline void gpio_unexport(unsigned gpio)
  125. {
  126. /* GPIO can never have been exported */
  127. WARN_ON(1);
  128. }
  129. static inline int gpio_to_irq(unsigned gpio)
  130. {
  131. /* GPIO can never have been requested or set as input */
  132. WARN_ON(1);
  133. return -EINVAL;
  134. }
  135. static inline int irq_to_gpio(unsigned irq)
  136. {
  137. /* irq can never have been returned from gpio_to_irq() */
  138. WARN_ON(1);
  139. return -EINVAL;
  140. }
  141. #ifdef CONFIG_PINCTRL
  142. static inline int
  143. gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
  144. unsigned int pin_base, unsigned int npins)
  145. {
  146. }
  147. static inline void
  148. gpiochip_remove_pin_ranges(struct gpio_chip *chip)
  149. {
  150. }
  151. #endif /* CONFIG_PINCTRL */
  152. #endif /* ! CONFIG_GENERIC_GPIO */
  153. #endif /* __LINUX_GPIO_H */