gpio.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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/gpio/gpio-legacy.txt */
  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. #include <linux/pinctrl/pinctrl.h>
  82. struct device;
  83. struct gpio_chip;
  84. static inline bool gpio_is_valid(int number)
  85. {
  86. return false;
  87. }
  88. static inline int gpio_request(unsigned gpio, const char *label)
  89. {
  90. return -ENOSYS;
  91. }
  92. static inline int gpio_request_one(unsigned gpio,
  93. unsigned long flags, const char *label)
  94. {
  95. return -ENOSYS;
  96. }
  97. static inline int gpio_request_array(const struct gpio *array, size_t num)
  98. {
  99. return -ENOSYS;
  100. }
  101. static inline void gpio_free(unsigned gpio)
  102. {
  103. might_sleep();
  104. /* GPIO can never have been requested */
  105. WARN_ON(1);
  106. }
  107. static inline void gpio_free_array(const struct gpio *array, size_t num)
  108. {
  109. might_sleep();
  110. /* GPIO can never have been requested */
  111. WARN_ON(1);
  112. }
  113. static inline int gpio_direction_input(unsigned gpio)
  114. {
  115. return -ENOSYS;
  116. }
  117. static inline int gpio_direction_output(unsigned gpio, int value)
  118. {
  119. return -ENOSYS;
  120. }
  121. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  122. {
  123. return -ENOSYS;
  124. }
  125. static inline int gpio_get_value(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(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_cansleep(unsigned gpio)
  137. {
  138. /* GPIO can never have been requested or set as {in,out}put */
  139. WARN_ON(1);
  140. return 0;
  141. }
  142. static inline int gpio_get_value_cansleep(unsigned gpio)
  143. {
  144. /* GPIO can never have been requested or set as {in,out}put */
  145. WARN_ON(1);
  146. return 0;
  147. }
  148. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  149. {
  150. /* GPIO can never have been requested or set as output */
  151. WARN_ON(1);
  152. }
  153. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  154. {
  155. /* GPIO can never have been requested or set as {in,out}put */
  156. WARN_ON(1);
  157. return -EINVAL;
  158. }
  159. static inline int gpio_export_link(struct device *dev, const char *name,
  160. unsigned gpio)
  161. {
  162. /* GPIO can never have been exported */
  163. WARN_ON(1);
  164. return -EINVAL;
  165. }
  166. static inline void gpio_unexport(unsigned gpio)
  167. {
  168. /* GPIO can never have been exported */
  169. WARN_ON(1);
  170. }
  171. static inline int gpio_to_irq(unsigned gpio)
  172. {
  173. /* GPIO can never have been requested or set as input */
  174. WARN_ON(1);
  175. return -EINVAL;
  176. }
  177. static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
  178. unsigned int offset)
  179. {
  180. WARN_ON(1);
  181. return -EINVAL;
  182. }
  183. static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
  184. unsigned int offset)
  185. {
  186. WARN_ON(1);
  187. }
  188. static inline int irq_to_gpio(unsigned irq)
  189. {
  190. /* irq can never have been returned from gpio_to_irq() */
  191. WARN_ON(1);
  192. return -EINVAL;
  193. }
  194. static inline int
  195. gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
  196. unsigned int gpio_offset, unsigned int pin_offset,
  197. unsigned int npins)
  198. {
  199. WARN_ON(1);
  200. return -EINVAL;
  201. }
  202. static inline int
  203. gpiochip_add_pingroup_range(struct gpio_chip *chip,
  204. struct pinctrl_dev *pctldev,
  205. unsigned int gpio_offset, const char *pin_group)
  206. {
  207. WARN_ON(1);
  208. return -EINVAL;
  209. }
  210. static inline void
  211. gpiochip_remove_pin_ranges(struct gpio_chip *chip)
  212. {
  213. WARN_ON(1);
  214. }
  215. static inline int devm_gpio_request(struct device *dev, unsigned gpio,
  216. const char *label)
  217. {
  218. WARN_ON(1);
  219. return -EINVAL;
  220. }
  221. static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
  222. unsigned long flags, const char *label)
  223. {
  224. WARN_ON(1);
  225. return -EINVAL;
  226. }
  227. static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
  228. {
  229. WARN_ON(1);
  230. }
  231. #endif /* ! CONFIG_GPIOLIB */
  232. #endif /* __LINUX_GPIO_H */