David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 1 | #ifndef __LINUX_GPIO_H |
| 2 | #define __LINUX_GPIO_H |
| 3 | |
| 4 | /* see Documentation/gpio.txt */ |
| 5 | |
Randy Dunlap | c001fb7 | 2011-06-14 17:05:11 -0700 | [diff] [blame] | 6 | /* make these flag values available regardless of GPIO kconfig options */ |
| 7 | #define GPIOF_DIR_OUT (0 << 0) |
| 8 | #define GPIOF_DIR_IN (1 << 0) |
| 9 | |
| 10 | #define GPIOF_INIT_LOW (0 << 1) |
| 11 | #define GPIOF_INIT_HIGH (1 << 1) |
| 12 | |
| 13 | #define GPIOF_IN (GPIOF_DIR_IN) |
| 14 | #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) |
| 15 | #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) |
| 16 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 17 | #ifdef CONFIG_GENERIC_GPIO |
| 18 | #include <asm/gpio.h> |
| 19 | |
| 20 | #else |
| 21 | |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
David Brownell | 6ea0205 | 2008-05-23 13:04:58 -0700 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | #include <linux/errno.h> |
| 25 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 26 | struct device; |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 27 | struct gpio; |
Anton Vorontsov | 4e4438b | 2010-09-01 08:55:24 -0600 | [diff] [blame] | 28 | struct gpio_chip; |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 29 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 30 | /* |
| 31 | * Some platforms don't support the GPIO programming interface. |
| 32 | * |
| 33 | * In case some driver uses it anyway (it should normally have |
| 34 | * depended on GENERIC_GPIO), these routines help the compiler |
| 35 | * optimize out much GPIO-related code ... or trigger a runtime |
| 36 | * warning when something is wrongly called. |
| 37 | */ |
| 38 | |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 39 | static inline bool gpio_is_valid(int number) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 40 | { |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 41 | return false; |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 44 | static inline int gpio_request(unsigned gpio, const char *label) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 45 | { |
| 46 | return -ENOSYS; |
| 47 | } |
| 48 | |
Wolfram Sang | 323b7fe | 2011-01-14 09:34:29 +0100 | [diff] [blame] | 49 | static inline int gpio_request_one(unsigned gpio, |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 50 | unsigned long flags, const char *label) |
| 51 | { |
| 52 | return -ENOSYS; |
| 53 | } |
| 54 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 55 | static inline int gpio_request_array(const struct gpio *array, size_t num) |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 56 | { |
| 57 | return -ENOSYS; |
| 58 | } |
| 59 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 60 | static inline void gpio_free(unsigned gpio) |
| 61 | { |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 62 | might_sleep(); |
| 63 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 64 | /* GPIO can never have been requested */ |
| 65 | WARN_ON(1); |
| 66 | } |
| 67 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 68 | static inline void gpio_free_array(const struct gpio *array, size_t num) |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 69 | { |
| 70 | might_sleep(); |
| 71 | |
| 72 | /* GPIO can never have been requested */ |
| 73 | WARN_ON(1); |
| 74 | } |
| 75 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 76 | static inline int gpio_direction_input(unsigned gpio) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 77 | { |
| 78 | return -ENOSYS; |
| 79 | } |
| 80 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 81 | static inline int gpio_direction_output(unsigned gpio, int value) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 82 | { |
| 83 | return -ENOSYS; |
| 84 | } |
| 85 | |
Felipe Balbi | c4b5be9 | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 86 | static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) |
| 87 | { |
| 88 | return -ENOSYS; |
| 89 | } |
| 90 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 91 | static inline int gpio_get_value(unsigned gpio) |
| 92 | { |
| 93 | /* GPIO can never have been requested or set as {in,out}put */ |
| 94 | WARN_ON(1); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static inline void gpio_set_value(unsigned gpio, int value) |
| 99 | { |
| 100 | /* GPIO can never have been requested or set as output */ |
| 101 | WARN_ON(1); |
| 102 | } |
| 103 | |
| 104 | static inline int gpio_cansleep(unsigned gpio) |
| 105 | { |
| 106 | /* GPIO can never have been requested or set as {in,out}put */ |
| 107 | WARN_ON(1); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static inline int gpio_get_value_cansleep(unsigned gpio) |
| 112 | { |
| 113 | /* GPIO can never have been requested or set as {in,out}put */ |
| 114 | WARN_ON(1); |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static inline void gpio_set_value_cansleep(unsigned gpio, int value) |
| 119 | { |
| 120 | /* GPIO can never have been requested or set as output */ |
| 121 | WARN_ON(1); |
| 122 | } |
| 123 | |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 124 | static inline int gpio_export(unsigned gpio, bool direction_may_change) |
| 125 | { |
| 126 | /* GPIO can never have been requested or set as {in,out}put */ |
| 127 | WARN_ON(1); |
| 128 | return -EINVAL; |
| 129 | } |
| 130 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 131 | static inline int gpio_export_link(struct device *dev, const char *name, |
| 132 | unsigned gpio) |
| 133 | { |
| 134 | /* GPIO can never have been exported */ |
| 135 | WARN_ON(1); |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
Jani Nikula | 0769746 | 2009-12-15 16:46:20 -0800 | [diff] [blame] | 139 | static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) |
| 140 | { |
| 141 | /* GPIO can never have been requested */ |
| 142 | WARN_ON(1); |
| 143 | return -EINVAL; |
| 144 | } |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 145 | |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 146 | static inline void gpio_unexport(unsigned gpio) |
| 147 | { |
| 148 | /* GPIO can never have been exported */ |
| 149 | WARN_ON(1); |
| 150 | } |
| 151 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 152 | static inline int gpio_to_irq(unsigned gpio) |
| 153 | { |
| 154 | /* GPIO can never have been requested or set as input */ |
| 155 | WARN_ON(1); |
| 156 | return -EINVAL; |
| 157 | } |
| 158 | |
| 159 | static inline int irq_to_gpio(unsigned irq) |
| 160 | { |
| 161 | /* irq can never have been returned from gpio_to_irq() */ |
| 162 | WARN_ON(1); |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
| 166 | #endif |
| 167 | |
| 168 | #endif /* __LINUX_GPIO_H */ |