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