gpio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef __LINUX_GPIO_H
  2. #define __LINUX_GPIO_H
  3. /* see Documentation/gpio.txt */
  4. /* make these flag values available regardless of GPIO kconfig options */
  5. #define GPIOF_DIR_OUT (0 << 0)
  6. #define GPIOF_DIR_IN (1 << 0)
  7. #define GPIOF_INIT_LOW (0 << 1)
  8. #define GPIOF_INIT_HIGH (1 << 1)
  9. #define GPIOF_IN (GPIOF_DIR_IN)
  10. #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
  11. #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
  12. /* Gpio pin is open drain */
  13. #define GPIOF_OPEN_DRAIN (1 << 2)
  14. /* Gpio pin is open source */
  15. #define GPIOF_OPEN_SOURCE (1 << 3)
  16. /**
  17. * struct gpio - a structure describing a GPIO with configuration
  18. * @gpio: the GPIO number
  19. * @flags: GPIO configuration as specified by GPIOF_*
  20. * @label: a literal description string of this GPIO
  21. */
  22. struct gpio {
  23. unsigned gpio;
  24. unsigned long flags;
  25. const char *label;
  26. };
  27. #ifdef CONFIG_GENERIC_GPIO
  28. #include <asm/gpio.h>
  29. #else
  30. #include <linux/kernel.h>
  31. #include <linux/types.h>
  32. #include <linux/errno.h>
  33. struct device;
  34. struct gpio_chip;
  35. static inline bool gpio_is_valid(int number)
  36. {
  37. return false;
  38. }
  39. static inline int gpio_request(unsigned gpio, const char *label)
  40. {
  41. return -ENOSYS;
  42. }
  43. static inline int gpio_request_one(unsigned gpio,
  44. unsigned long flags, const char *label)
  45. {
  46. return -ENOSYS;
  47. }
  48. static inline int gpio_request_array(const struct gpio *array, size_t num)
  49. {
  50. return -ENOSYS;
  51. }
  52. static inline void gpio_free(unsigned gpio)
  53. {
  54. might_sleep();
  55. /* GPIO can never have been requested */
  56. WARN_ON(1);
  57. }
  58. static inline void gpio_free_array(const struct gpio *array, size_t num)
  59. {
  60. might_sleep();
  61. /* GPIO can never have been requested */
  62. WARN_ON(1);
  63. }
  64. static inline int gpio_direction_input(unsigned gpio)
  65. {
  66. return -ENOSYS;
  67. }
  68. static inline int gpio_direction_output(unsigned gpio, int value)
  69. {
  70. return -ENOSYS;
  71. }
  72. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  73. {
  74. return -ENOSYS;
  75. }
  76. static inline int gpio_get_value(unsigned gpio)
  77. {
  78. /* GPIO can never have been requested or set as {in,out}put */
  79. WARN_ON(1);
  80. return 0;
  81. }
  82. static inline void gpio_set_value(unsigned gpio, int value)
  83. {
  84. /* GPIO can never have been requested or set as output */
  85. WARN_ON(1);
  86. }
  87. static inline int gpio_cansleep(unsigned gpio)
  88. {
  89. /* GPIO can never have been requested or set as {in,out}put */
  90. WARN_ON(1);
  91. return 0;
  92. }
  93. static inline int gpio_get_value_cansleep(unsigned gpio)
  94. {
  95. /* GPIO can never have been requested or set as {in,out}put */
  96. WARN_ON(1);
  97. return 0;
  98. }
  99. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  100. {
  101. /* GPIO can never have been requested or set as output */
  102. WARN_ON(1);
  103. }
  104. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  105. {
  106. /* GPIO can never have been requested or set as {in,out}put */
  107. WARN_ON(1);
  108. return -EINVAL;
  109. }
  110. static inline int gpio_export_link(struct device *dev, const char *name,
  111. unsigned gpio)
  112. {
  113. /* GPIO can never have been exported */
  114. WARN_ON(1);
  115. return -EINVAL;
  116. }
  117. static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
  118. {
  119. /* GPIO can never have been requested */
  120. WARN_ON(1);
  121. return -EINVAL;
  122. }
  123. static inline void gpio_unexport(unsigned gpio)
  124. {
  125. /* GPIO can never have been exported */
  126. WARN_ON(1);
  127. }
  128. static inline int gpio_to_irq(unsigned gpio)
  129. {
  130. /* GPIO can never have been requested or set as input */
  131. WARN_ON(1);
  132. return -EINVAL;
  133. }
  134. static inline int irq_to_gpio(unsigned irq)
  135. {
  136. /* irq can never have been returned from gpio_to_irq() */
  137. WARN_ON(1);
  138. return -EINVAL;
  139. }
  140. #endif
  141. #endif /* __LINUX_GPIO_H */