gpio.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #else /* ! CONFIG_GPIOLIB */
  77. #include <linux/kernel.h>
  78. #include <linux/types.h>
  79. #include <linux/bug.h>
  80. struct device;
  81. struct gpio_chip;
  82. static inline bool gpio_is_valid(int number)
  83. {
  84. return false;
  85. }
  86. static inline int gpio_request(unsigned gpio, const char *label)
  87. {
  88. return -ENOSYS;
  89. }
  90. static inline int gpio_request_one(unsigned gpio,
  91. unsigned long flags, const char *label)
  92. {
  93. return -ENOSYS;
  94. }
  95. static inline int gpio_request_array(const struct gpio *array, size_t num)
  96. {
  97. return -ENOSYS;
  98. }
  99. static inline void gpio_free(unsigned gpio)
  100. {
  101. might_sleep();
  102. /* GPIO can never have been requested */
  103. WARN_ON(1);
  104. }
  105. static inline void gpio_free_array(const struct gpio *array, size_t num)
  106. {
  107. might_sleep();
  108. /* GPIO can never have been requested */
  109. WARN_ON(1);
  110. }
  111. static inline int gpio_direction_input(unsigned gpio)
  112. {
  113. return -ENOSYS;
  114. }
  115. static inline int gpio_direction_output(unsigned gpio, int value)
  116. {
  117. return -ENOSYS;
  118. }
  119. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  120. {
  121. return -ENOSYS;
  122. }
  123. static inline int gpio_get_value(unsigned gpio)
  124. {
  125. /* GPIO can never have been requested or set as {in,out}put */
  126. WARN_ON(1);
  127. return 0;
  128. }
  129. static inline void gpio_set_value(unsigned gpio, int value)
  130. {
  131. /* GPIO can never have been requested or set as output */
  132. WARN_ON(1);
  133. }
  134. static inline int gpio_cansleep(unsigned gpio)
  135. {
  136. /* GPIO can never have been requested or set as {in,out}put */
  137. WARN_ON(1);
  138. return 0;
  139. }
  140. static inline int gpio_get_value_cansleep(unsigned gpio)
  141. {
  142. /* GPIO can never have been requested or set as {in,out}put */
  143. WARN_ON(1);
  144. return 0;
  145. }
  146. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  147. {
  148. /* GPIO can never have been requested or set as output */
  149. WARN_ON(1);
  150. }
  151. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  152. {
  153. /* GPIO can never have been requested or set as {in,out}put */
  154. WARN_ON(1);
  155. return -EINVAL;
  156. }
  157. static inline int gpio_export_link(struct device *dev, const char *name,
  158. unsigned gpio)
  159. {
  160. /* GPIO can never have been exported */
  161. WARN_ON(1);
  162. return -EINVAL;
  163. }
  164. static inline void gpio_unexport(unsigned gpio)
  165. {
  166. /* GPIO can never have been exported */
  167. WARN_ON(1);
  168. }
  169. static inline int gpio_to_irq(unsigned gpio)
  170. {
  171. /* GPIO can never have been requested or set as input */
  172. WARN_ON(1);
  173. return -EINVAL;
  174. }
  175. static inline int irq_to_gpio(unsigned irq)
  176. {
  177. /* irq can never have been returned from gpio_to_irq() */
  178. WARN_ON(1);
  179. return -EINVAL;
  180. }
  181. static inline int devm_gpio_request(struct device *dev, unsigned gpio,
  182. const char *label)
  183. {
  184. WARN_ON(1);
  185. return -EINVAL;
  186. }
  187. static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
  188. unsigned long flags, const char *label)
  189. {
  190. WARN_ON(1);
  191. return -EINVAL;
  192. }
  193. #endif /* ! CONFIG_GPIOLIB */
  194. #endif /* __LINUX_GPIO_H */