gpio.h 5.1 KB

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