David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 1 | #ifndef __LINUX_GPIO_H |
| 2 | #define __LINUX_GPIO_H |
| 3 | |
Mark Brown | 7563bbf | 2012-04-15 10:52:54 +0100 | [diff] [blame] | 4 | #include <linux/errno.h> |
| 5 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 6 | /* see Documentation/gpio.txt */ |
| 7 | |
Randy Dunlap | c001fb7 | 2011-06-14 17:05:11 -0700 | [diff] [blame] | 8 | /* make these flag values available regardless of GPIO kconfig options */ |
| 9 | #define GPIOF_DIR_OUT (0 << 0) |
| 10 | #define GPIOF_DIR_IN (1 << 0) |
| 11 | |
| 12 | #define GPIOF_INIT_LOW (0 << 1) |
| 13 | #define GPIOF_INIT_HIGH (1 << 1) |
| 14 | |
| 15 | #define GPIOF_IN (GPIOF_DIR_IN) |
| 16 | #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) |
| 17 | #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) |
| 18 | |
Laxman Dewangan | aca5ce1 | 2012-02-17 20:26:21 +0530 | [diff] [blame] | 19 | /* Gpio pin is open drain */ |
| 20 | #define GPIOF_OPEN_DRAIN (1 << 2) |
| 21 | |
Laxman Dewangan | 25553ff | 2012-02-17 20:26:22 +0530 | [diff] [blame] | 22 | /* Gpio pin is open source */ |
| 23 | #define GPIOF_OPEN_SOURCE (1 << 3) |
| 24 | |
Laxman Dewangan | f567fde | 2012-06-20 14:14:05 +0530 | [diff] [blame] | 25 | #define GPIOF_EXPORT (1 << 4) |
| 26 | #define GPIOF_EXPORT_CHANGEABLE (1 << 5) |
Wolfram Sang | fc3a1f0 | 2011-12-13 18:34:01 +0100 | [diff] [blame] | 27 | #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) |
| 28 | #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) |
| 29 | |
Mark Brown | feb8369 | 2011-10-24 15:24:10 +0200 | [diff] [blame] | 30 | /** |
| 31 | * struct gpio - a structure describing a GPIO with configuration |
| 32 | * @gpio: the GPIO number |
| 33 | * @flags: GPIO configuration as specified by GPIOF_* |
| 34 | * @label: a literal description string of this GPIO |
| 35 | */ |
| 36 | struct gpio { |
| 37 | unsigned gpio; |
| 38 | unsigned long flags; |
| 39 | const char *label; |
| 40 | }; |
| 41 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 42 | #ifdef CONFIG_GENERIC_GPIO |
Mark Brown | 7563bbf | 2012-04-15 10:52:54 +0100 | [diff] [blame] | 43 | |
| 44 | #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 45 | #include <asm/gpio.h> |
Mark Brown | 7563bbf | 2012-04-15 10:52:54 +0100 | [diff] [blame] | 46 | #else |
| 47 | |
| 48 | #include <asm-generic/gpio.h> |
| 49 | |
| 50 | static inline int gpio_get_value(unsigned int gpio) |
| 51 | { |
| 52 | return __gpio_get_value(gpio); |
| 53 | } |
| 54 | |
| 55 | static inline void gpio_set_value(unsigned int gpio, int value) |
| 56 | { |
| 57 | __gpio_set_value(gpio, value); |
| 58 | } |
| 59 | |
| 60 | static inline int gpio_cansleep(unsigned int gpio) |
| 61 | { |
| 62 | return __gpio_cansleep(gpio); |
| 63 | } |
| 64 | |
| 65 | static inline int gpio_to_irq(unsigned int gpio) |
| 66 | { |
| 67 | return __gpio_to_irq(gpio); |
| 68 | } |
| 69 | |
| 70 | static inline int irq_to_gpio(unsigned int irq) |
| 71 | { |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 75 | #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 76 | |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 77 | #else /* ! CONFIG_GENERIC_GPIO */ |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 78 | |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 79 | #include <linux/kernel.h> |
David Brownell | 6ea0205 | 2008-05-23 13:04:58 -0700 | [diff] [blame] | 80 | #include <linux/types.h> |
| 81 | #include <linux/errno.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 82 | #include <linux/bug.h> |
David Brownell | 6ea0205 | 2008-05-23 13:04:58 -0700 | [diff] [blame] | 83 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 84 | struct device; |
Anton Vorontsov | 4e4438b | 2010-09-01 08:55:24 -0600 | [diff] [blame] | 85 | struct gpio_chip; |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 86 | |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 87 | static inline bool gpio_is_valid(int number) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 88 | { |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 89 | return false; |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 92 | static inline int gpio_request(unsigned gpio, const char *label) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 93 | { |
| 94 | return -ENOSYS; |
| 95 | } |
| 96 | |
Wolfram Sang | 323b7fe | 2011-01-14 09:34:29 +0100 | [diff] [blame] | 97 | static inline int gpio_request_one(unsigned gpio, |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 98 | unsigned long flags, const char *label) |
| 99 | { |
| 100 | return -ENOSYS; |
| 101 | } |
| 102 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 103 | 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] | 104 | { |
| 105 | return -ENOSYS; |
| 106 | } |
| 107 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 108 | static inline void gpio_free(unsigned gpio) |
| 109 | { |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 110 | might_sleep(); |
| 111 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 112 | /* GPIO can never have been requested */ |
| 113 | WARN_ON(1); |
| 114 | } |
| 115 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 116 | 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] | 117 | { |
| 118 | might_sleep(); |
| 119 | |
| 120 | /* GPIO can never have been requested */ |
| 121 | WARN_ON(1); |
| 122 | } |
| 123 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 124 | static inline int gpio_direction_input(unsigned gpio) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 125 | { |
| 126 | return -ENOSYS; |
| 127 | } |
| 128 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 129 | static inline int gpio_direction_output(unsigned gpio, int value) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 130 | { |
| 131 | return -ENOSYS; |
| 132 | } |
| 133 | |
Felipe Balbi | c4b5be9 | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 134 | static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) |
| 135 | { |
| 136 | return -ENOSYS; |
| 137 | } |
| 138 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 139 | static inline int gpio_get_value(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 | |
| 146 | static inline void gpio_set_value(unsigned gpio, int value) |
| 147 | { |
| 148 | /* GPIO can never have been requested or set as output */ |
| 149 | WARN_ON(1); |
| 150 | } |
| 151 | |
| 152 | static inline int gpio_cansleep(unsigned gpio) |
| 153 | { |
| 154 | /* GPIO can never have been requested or set as {in,out}put */ |
| 155 | WARN_ON(1); |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static inline int gpio_get_value_cansleep(unsigned gpio) |
| 160 | { |
| 161 | /* GPIO can never have been requested or set as {in,out}put */ |
| 162 | WARN_ON(1); |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static inline void gpio_set_value_cansleep(unsigned gpio, int value) |
| 167 | { |
| 168 | /* GPIO can never have been requested or set as output */ |
| 169 | WARN_ON(1); |
| 170 | } |
| 171 | |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 172 | static inline int gpio_export(unsigned gpio, bool direction_may_change) |
| 173 | { |
| 174 | /* GPIO can never have been requested or set as {in,out}put */ |
| 175 | WARN_ON(1); |
| 176 | return -EINVAL; |
| 177 | } |
| 178 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 179 | static inline int gpio_export_link(struct device *dev, const char *name, |
| 180 | unsigned gpio) |
| 181 | { |
| 182 | /* GPIO can never have been exported */ |
| 183 | WARN_ON(1); |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
Jani Nikula | 0769746 | 2009-12-15 16:46:20 -0800 | [diff] [blame] | 187 | static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) |
| 188 | { |
| 189 | /* GPIO can never have been requested */ |
| 190 | WARN_ON(1); |
| 191 | return -EINVAL; |
| 192 | } |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 193 | |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 194 | static inline void gpio_unexport(unsigned gpio) |
| 195 | { |
| 196 | /* GPIO can never have been exported */ |
| 197 | WARN_ON(1); |
| 198 | } |
| 199 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 200 | static inline int gpio_to_irq(unsigned gpio) |
| 201 | { |
| 202 | /* GPIO can never have been requested or set as input */ |
| 203 | WARN_ON(1); |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
| 207 | static inline int irq_to_gpio(unsigned irq) |
| 208 | { |
| 209 | /* irq can never have been returned from gpio_to_irq() */ |
| 210 | WARN_ON(1); |
| 211 | return -EINVAL; |
| 212 | } |
| 213 | |
Linus Walleij | 1e63d7b | 2012-11-06 16:03:35 +0100 | [diff] [blame] | 214 | static inline int |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 215 | gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, |
Linus Walleij | 316511c | 2012-11-21 08:48:09 +0100 | [diff] [blame] | 216 | unsigned int gpio_offset, unsigned int pin_offset, |
Linus Walleij | 3f0f867 | 2012-11-20 12:40:15 +0100 | [diff] [blame] | 217 | unsigned int npins) |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 218 | { |
Linus Walleij | 50309a9 | 2012-11-06 17:16:39 +0100 | [diff] [blame] | 219 | WARN_ON(1); |
| 220 | return -EINVAL; |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static inline void |
| 224 | gpiochip_remove_pin_ranges(struct gpio_chip *chip) |
| 225 | { |
Linus Walleij | 50309a9 | 2012-11-06 17:16:39 +0100 | [diff] [blame] | 226 | WARN_ON(1); |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Linus Walleij | 165adc9 | 2012-11-06 14:49:39 +0100 | [diff] [blame] | 229 | #endif /* ! CONFIG_GENERIC_GPIO */ |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 230 | |
Shawn Guo | 6a89a31 | 2013-01-18 15:57:46 +0800 | [diff] [blame] | 231 | struct device; |
| 232 | |
| 233 | /* bindings for managed devices that want to request gpios */ |
| 234 | int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); |
| 235 | int devm_gpio_request_one(struct device *dev, unsigned gpio, |
| 236 | unsigned long flags, const char *label); |
| 237 | void devm_gpio_free(struct device *dev, unsigned int gpio); |
| 238 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 239 | #endif /* __LINUX_GPIO_H */ |