gpio.h 5.3 KB

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