gpio.h 4.6 KB

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