gpio.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef __LINUX_GPIO_H
  2. #define __LINUX_GPIO_H
  3. #include <linux/errno.h>
  4. /* see Documentation/gpio/gpio-legacy.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. /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
  61. struct device;
  62. int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
  63. int devm_gpio_request_one(struct device *dev, unsigned gpio,
  64. unsigned long flags, const char *label);
  65. void devm_gpio_free(struct device *dev, unsigned int gpio);
  66. #else /* ! CONFIG_GPIOLIB */
  67. #include <linux/kernel.h>
  68. #include <linux/types.h>
  69. #include <linux/bug.h>
  70. #include <linux/pinctrl/pinctrl.h>
  71. struct device;
  72. struct gpio_chip;
  73. static inline bool gpio_is_valid(int number)
  74. {
  75. return false;
  76. }
  77. static inline int gpio_request(unsigned gpio, const char *label)
  78. {
  79. return -ENOSYS;
  80. }
  81. static inline int gpio_request_one(unsigned gpio,
  82. unsigned long flags, const char *label)
  83. {
  84. return -ENOSYS;
  85. }
  86. static inline int gpio_request_array(const struct gpio *array, size_t num)
  87. {
  88. return -ENOSYS;
  89. }
  90. static inline void gpio_free(unsigned gpio)
  91. {
  92. might_sleep();
  93. /* GPIO can never have been requested */
  94. WARN_ON(1);
  95. }
  96. static inline void gpio_free_array(const struct gpio *array, size_t num)
  97. {
  98. might_sleep();
  99. /* GPIO can never have been requested */
  100. WARN_ON(1);
  101. }
  102. static inline int gpio_direction_input(unsigned gpio)
  103. {
  104. return -ENOSYS;
  105. }
  106. static inline int gpio_direction_output(unsigned gpio, int value)
  107. {
  108. return -ENOSYS;
  109. }
  110. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  111. {
  112. return -ENOSYS;
  113. }
  114. static inline int gpio_get_value(unsigned gpio)
  115. {
  116. /* GPIO can never have been requested or set as {in,out}put */
  117. WARN_ON(1);
  118. return 0;
  119. }
  120. static inline void gpio_set_value(unsigned gpio, int value)
  121. {
  122. /* GPIO can never have been requested or set as output */
  123. WARN_ON(1);
  124. }
  125. static inline int gpio_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 int gpio_get_value_cansleep(unsigned gpio)
  132. {
  133. /* GPIO can never have been requested or set as {in,out}put */
  134. WARN_ON(1);
  135. return 0;
  136. }
  137. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  138. {
  139. /* GPIO can never have been requested or set as output */
  140. WARN_ON(1);
  141. }
  142. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  143. {
  144. /* GPIO can never have been requested or set as {in,out}put */
  145. WARN_ON(1);
  146. return -EINVAL;
  147. }
  148. static inline int gpio_export_link(struct device *dev, const char *name,
  149. unsigned gpio)
  150. {
  151. /* GPIO can never have been exported */
  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 gpiochip_lock_as_irq(struct gpio_chip *chip,
  167. unsigned int offset)
  168. {
  169. WARN_ON(1);
  170. return -EINVAL;
  171. }
  172. static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
  173. unsigned int offset)
  174. {
  175. WARN_ON(1);
  176. }
  177. static inline int irq_to_gpio(unsigned irq)
  178. {
  179. /* irq can never have been returned from gpio_to_irq() */
  180. WARN_ON(1);
  181. return -EINVAL;
  182. }
  183. static inline int
  184. gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
  185. unsigned int gpio_offset, unsigned int pin_offset,
  186. unsigned int npins)
  187. {
  188. WARN_ON(1);
  189. return -EINVAL;
  190. }
  191. static inline int
  192. gpiochip_add_pingroup_range(struct gpio_chip *chip,
  193. struct pinctrl_dev *pctldev,
  194. unsigned int gpio_offset, const char *pin_group)
  195. {
  196. WARN_ON(1);
  197. return -EINVAL;
  198. }
  199. static inline void
  200. gpiochip_remove_pin_ranges(struct gpio_chip *chip)
  201. {
  202. WARN_ON(1);
  203. }
  204. static inline int devm_gpio_request(struct device *dev, unsigned gpio,
  205. const char *label)
  206. {
  207. WARN_ON(1);
  208. return -EINVAL;
  209. }
  210. static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
  211. unsigned long flags, const char *label)
  212. {
  213. WARN_ON(1);
  214. return -EINVAL;
  215. }
  216. static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
  217. {
  218. WARN_ON(1);
  219. }
  220. #endif /* ! CONFIG_GPIOLIB */
  221. #endif /* __LINUX_GPIO_H */