gpio.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #ifndef __LINUX_GPIO_H
  2. #define __LINUX_GPIO_H
  3. #include <linux/errno.h>
  4. /* see Documentation/gpio.txt */
  5. /* make these flag values available regardless of GPIO kconfig options */
  6. #define GPIOF_DIR_OUT (0 << 0)
  7. #define GPIOF_DIR_IN (1 << 0)
  8. #define GPIOF_INIT_LOW (0 << 1)
  9. #define GPIOF_INIT_HIGH (1 << 1)
  10. #define GPIOF_IN (GPIOF_DIR_IN)
  11. #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
  12. #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
  13. /* Gpio pin is active-low */
  14. #define GPIOF_ACTIVE_LOW (1 << 2)
  15. /* Gpio pin is open drain */
  16. #define GPIOF_OPEN_DRAIN (1 << 3)
  17. /* Gpio pin is open source */
  18. #define GPIOF_OPEN_SOURCE (1 << 4)
  19. #define GPIOF_EXPORT (1 << 5)
  20. #define GPIOF_EXPORT_CHANGEABLE (1 << 6)
  21. #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
  22. #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
  23. /**
  24. * struct gpio - a structure describing a GPIO with configuration
  25. * @gpio: the GPIO number
  26. * @flags: GPIO configuration as specified by GPIOF_*
  27. * @label: a literal description string of this GPIO
  28. */
  29. struct gpio {
  30. unsigned gpio;
  31. unsigned long flags;
  32. const char *label;
  33. };
  34. #ifdef CONFIG_GPIOLIB
  35. #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
  36. #include <asm/gpio.h>
  37. #else
  38. #include <asm-generic/gpio.h>
  39. static inline int gpio_get_value(unsigned int gpio)
  40. {
  41. return __gpio_get_value(gpio);
  42. }
  43. static inline void gpio_set_value(unsigned int gpio, int value)
  44. {
  45. __gpio_set_value(gpio, value);
  46. }
  47. static inline int gpio_cansleep(unsigned int gpio)
  48. {
  49. return __gpio_cansleep(gpio);
  50. }
  51. static inline int gpio_to_irq(unsigned int gpio)
  52. {
  53. return __gpio_to_irq(gpio);
  54. }
  55. static inline int irq_to_gpio(unsigned int irq)
  56. {
  57. return -EINVAL;
  58. }
  59. #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
  60. #else /* ! CONFIG_GPIOLIB */
  61. #include <linux/kernel.h>
  62. #include <linux/types.h>
  63. #include <linux/errno.h>
  64. #include <linux/bug.h>
  65. struct device;
  66. struct gpio_chip;
  67. static inline bool gpio_is_valid(int number)
  68. {
  69. return false;
  70. }
  71. static inline int gpio_request(unsigned gpio, const char *label)
  72. {
  73. return -ENOSYS;
  74. }
  75. static inline int gpio_request_one(unsigned gpio,
  76. unsigned long flags, const char *label)
  77. {
  78. return -ENOSYS;
  79. }
  80. static inline int gpio_request_array(const struct gpio *array, size_t num)
  81. {
  82. return -ENOSYS;
  83. }
  84. static inline void gpio_free(unsigned gpio)
  85. {
  86. might_sleep();
  87. /* GPIO can never have been requested */
  88. WARN_ON(1);
  89. }
  90. static inline void gpio_free_array(const struct gpio *array, size_t num)
  91. {
  92. might_sleep();
  93. /* GPIO can never have been requested */
  94. WARN_ON(1);
  95. }
  96. static inline int gpio_direction_input(unsigned gpio)
  97. {
  98. return -ENOSYS;
  99. }
  100. static inline int gpio_direction_output(unsigned gpio, int value)
  101. {
  102. return -ENOSYS;
  103. }
  104. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  105. {
  106. return -ENOSYS;
  107. }
  108. static inline int gpio_get_value(unsigned gpio)
  109. {
  110. /* GPIO can never have been requested or set as {in,out}put */
  111. WARN_ON(1);
  112. return 0;
  113. }
  114. static inline void gpio_set_value(unsigned gpio, int value)
  115. {
  116. /* GPIO can never have been requested or set as output */
  117. WARN_ON(1);
  118. }
  119. static inline int gpio_cansleep(unsigned gpio)
  120. {
  121. /* GPIO can never have been requested or set as {in,out}put */
  122. WARN_ON(1);
  123. return 0;
  124. }
  125. static inline int gpio_get_value_cansleep(unsigned gpio)
  126. {
  127. /* GPIO can never have been requested or set as {in,out}put */
  128. WARN_ON(1);
  129. return 0;
  130. }
  131. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  132. {
  133. /* GPIO can never have been requested or set as output */
  134. WARN_ON(1);
  135. }
  136. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  137. {
  138. /* GPIO can never have been requested or set as {in,out}put */
  139. WARN_ON(1);
  140. return -EINVAL;
  141. }
  142. static inline int gpio_export_link(struct device *dev, const char *name,
  143. unsigned gpio)
  144. {
  145. /* GPIO can never have been exported */
  146. WARN_ON(1);
  147. return -EINVAL;
  148. }
  149. static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
  150. {
  151. /* GPIO can never have been requested */
  152. WARN_ON(1);
  153. return -EINVAL;
  154. }
  155. static inline void gpio_unexport(unsigned gpio)
  156. {
  157. /* GPIO can never have been exported */
  158. WARN_ON(1);
  159. }
  160. static inline int gpio_to_irq(unsigned gpio)
  161. {
  162. /* GPIO can never have been requested or set as input */
  163. WARN_ON(1);
  164. return -EINVAL;
  165. }
  166. static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
  167. {
  168. WARN_ON(1);
  169. return -EINVAL;
  170. }
  171. static inline void gpio_unlock_as_irq(struct gpio_chip *chip,
  172. unsigned int offset)
  173. {
  174. WARN_ON(1);
  175. }
  176. static inline int irq_to_gpio(unsigned irq)
  177. {
  178. /* irq can never have been returned from gpio_to_irq() */
  179. WARN_ON(1);
  180. return -EINVAL;
  181. }
  182. static inline int
  183. gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
  184. unsigned int gpio_offset, unsigned int pin_offset,
  185. unsigned int npins)
  186. {
  187. WARN_ON(1);
  188. return -EINVAL;
  189. }
  190. static inline void
  191. gpiochip_remove_pin_ranges(struct gpio_chip *chip)
  192. {
  193. WARN_ON(1);
  194. }
  195. #endif /* ! CONFIG_GPIOLIB */
  196. struct device;
  197. /* bindings for managed devices that want to request gpios */
  198. int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
  199. int devm_gpio_request_one(struct device *dev, unsigned gpio,
  200. unsigned long flags, const char *label);
  201. void devm_gpio_free(struct device *dev, unsigned int gpio);
  202. #endif /* __LINUX_GPIO_H */