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