Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_GPIO_CONSUMER_H |
| 2 | #define __LINUX_GPIO_CONSUMER_H |
| 3 | |
Arnd Bergmann | cdf86cd2 | 2014-05-08 15:42:25 +0200 | [diff] [blame] | 4 | #include <linux/bug.h> |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 5 | #include <linux/err.h> |
| 6 | #include <linux/kernel.h> |
| 7 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 8 | struct device; |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are |
| 12 | * preferable to the old integer-based handles. |
| 13 | * |
| 14 | * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid |
| 15 | * until the GPIO is released. |
| 16 | */ |
| 17 | struct gpio_desc; |
| 18 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 19 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
| 20 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
| 21 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
| 22 | |
| 23 | /** |
| 24 | * Optional flags that can be passed to one of gpiod_* to configure direction |
| 25 | * and output value. These values cannot be OR'd. |
| 26 | */ |
| 27 | enum gpiod_flags { |
| 28 | GPIOD_ASIS = 0, |
| 29 | GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, |
| 30 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, |
| 31 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
| 32 | GPIOD_FLAGS_BIT_DIR_VAL, |
| 33 | }; |
| 34 | |
Linus Walleij | 58b84f6 | 2014-08-19 12:00:53 -0500 | [diff] [blame] | 35 | #ifdef CONFIG_GPIOLIB |
| 36 | |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 37 | /* Acquire and dispose GPIOs */ |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 38 | struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 39 | const char *con_id, |
| 40 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 41 | struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 42 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 43 | unsigned int idx, |
| 44 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 45 | struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, |
| 46 | const char *con_id, |
| 47 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 48 | struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 49 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 50 | unsigned int index, |
| 51 | enum gpiod_flags flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 52 | void gpiod_put(struct gpio_desc *desc); |
| 53 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 54 | struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, |
| 55 | const char *con_id, |
| 56 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 57 | struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 58 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 59 | unsigned int idx, |
| 60 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 61 | struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, |
| 62 | const char *con_id, |
| 63 | enum gpiod_flags flags); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 64 | struct gpio_desc *__must_check |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 65 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 66 | unsigned int index, enum gpiod_flags flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 67 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
| 68 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 69 | int gpiod_get_direction(const struct gpio_desc *desc); |
| 70 | int gpiod_direction_input(struct gpio_desc *desc); |
| 71 | int gpiod_direction_output(struct gpio_desc *desc, int value); |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 72 | int gpiod_direction_output_raw(struct gpio_desc *desc, int value); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 73 | |
| 74 | /* Value get/set from non-sleeping context */ |
| 75 | int gpiod_get_value(const struct gpio_desc *desc); |
| 76 | void gpiod_set_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 77 | void gpiod_set_array(unsigned int array_size, |
| 78 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 79 | int gpiod_get_raw_value(const struct gpio_desc *desc); |
| 80 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 81 | void gpiod_set_raw_array(unsigned int array_size, |
| 82 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 83 | |
| 84 | /* Value get/set from sleeping context */ |
| 85 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); |
| 86 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 87 | void gpiod_set_array_cansleep(unsigned int array_size, |
| 88 | struct gpio_desc **desc_array, |
| 89 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 90 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
| 91 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 92 | void gpiod_set_raw_array_cansleep(unsigned int array_size, |
| 93 | struct gpio_desc **desc_array, |
| 94 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 95 | |
| 96 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
| 97 | |
| 98 | int gpiod_is_active_low(const struct gpio_desc *desc); |
| 99 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 100 | |
| 101 | int gpiod_to_irq(const struct gpio_desc *desc); |
| 102 | |
| 103 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 104 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| 105 | int desc_to_gpio(const struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 106 | |
| 107 | #else /* CONFIG_GPIOLIB */ |
| 108 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 109 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 110 | const char *con_id, |
| 111 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 112 | { |
| 113 | return ERR_PTR(-ENOSYS); |
| 114 | } |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 115 | static inline struct gpio_desc *__must_check |
| 116 | __gpiod_get_index(struct device *dev, |
| 117 | const char *con_id, |
| 118 | unsigned int idx, |
| 119 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 120 | { |
| 121 | return ERR_PTR(-ENOSYS); |
| 122 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 123 | |
| 124 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 125 | __gpiod_get_optional(struct device *dev, const char *con_id, |
| 126 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 127 | { |
| 128 | return ERR_PTR(-ENOSYS); |
| 129 | } |
| 130 | |
| 131 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 132 | __gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 133 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 134 | { |
| 135 | return ERR_PTR(-ENOSYS); |
| 136 | } |
| 137 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 138 | static inline void gpiod_put(struct gpio_desc *desc) |
| 139 | { |
| 140 | might_sleep(); |
| 141 | |
| 142 | /* GPIO can never have been requested */ |
| 143 | WARN_ON(1); |
| 144 | } |
| 145 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 146 | static inline struct gpio_desc *__must_check |
| 147 | __devm_gpiod_get(struct device *dev, |
| 148 | const char *con_id, |
| 149 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 150 | { |
| 151 | return ERR_PTR(-ENOSYS); |
| 152 | } |
| 153 | static inline |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 154 | struct gpio_desc *__must_check |
| 155 | __devm_gpiod_get_index(struct device *dev, |
| 156 | const char *con_id, |
| 157 | unsigned int idx, |
| 158 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 159 | { |
| 160 | return ERR_PTR(-ENOSYS); |
| 161 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 162 | |
| 163 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 164 | __devm_gpiod_get_optional(struct device *dev, const char *con_id, |
| 165 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 166 | { |
| 167 | return ERR_PTR(-ENOSYS); |
| 168 | } |
| 169 | |
| 170 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 171 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 172 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 173 | { |
| 174 | return ERR_PTR(-ENOSYS); |
| 175 | } |
| 176 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 177 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 178 | { |
| 179 | might_sleep(); |
| 180 | |
| 181 | /* GPIO can never have been requested */ |
| 182 | WARN_ON(1); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 187 | { |
| 188 | /* GPIO can never have been requested */ |
| 189 | WARN_ON(1); |
| 190 | return -ENOSYS; |
| 191 | } |
| 192 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 193 | { |
| 194 | /* GPIO can never have been requested */ |
| 195 | WARN_ON(1); |
| 196 | return -ENOSYS; |
| 197 | } |
| 198 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 199 | { |
| 200 | /* GPIO can never have been requested */ |
| 201 | WARN_ON(1); |
| 202 | return -ENOSYS; |
| 203 | } |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 204 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 205 | { |
| 206 | /* GPIO can never have been requested */ |
| 207 | WARN_ON(1); |
| 208 | return -ENOSYS; |
| 209 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 210 | |
| 211 | |
| 212 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 213 | { |
| 214 | /* GPIO can never have been requested */ |
| 215 | WARN_ON(1); |
| 216 | return 0; |
| 217 | } |
| 218 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 219 | { |
| 220 | /* GPIO can never have been requested */ |
| 221 | WARN_ON(1); |
| 222 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 223 | static inline void gpiod_set_array(unsigned int array_size, |
| 224 | struct gpio_desc **desc_array, |
| 225 | int *value_array) |
| 226 | { |
| 227 | /* GPIO can never have been requested */ |
| 228 | WARN_ON(1); |
| 229 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 230 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
| 231 | { |
| 232 | /* GPIO can never have been requested */ |
| 233 | WARN_ON(1); |
| 234 | return 0; |
| 235 | } |
| 236 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 237 | { |
| 238 | /* GPIO can never have been requested */ |
| 239 | WARN_ON(1); |
| 240 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 241 | static inline void gpiod_set_raw_array(unsigned int array_size, |
| 242 | struct gpio_desc **desc_array, |
| 243 | int *value_array) |
| 244 | { |
| 245 | /* GPIO can never have been requested */ |
| 246 | WARN_ON(1); |
| 247 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 248 | |
| 249 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 250 | { |
| 251 | /* GPIO can never have been requested */ |
| 252 | WARN_ON(1); |
| 253 | return 0; |
| 254 | } |
| 255 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 256 | { |
| 257 | /* GPIO can never have been requested */ |
| 258 | WARN_ON(1); |
| 259 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 260 | static inline void gpiod_set_array_cansleep(unsigned int array_size, |
| 261 | struct gpio_desc **desc_array, |
| 262 | int *value_array) |
| 263 | { |
| 264 | /* GPIO can never have been requested */ |
| 265 | WARN_ON(1); |
| 266 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 267 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 268 | { |
| 269 | /* GPIO can never have been requested */ |
| 270 | WARN_ON(1); |
| 271 | return 0; |
| 272 | } |
| 273 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 274 | int value) |
| 275 | { |
| 276 | /* GPIO can never have been requested */ |
| 277 | WARN_ON(1); |
| 278 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame^] | 279 | static inline void gpiod_set_raw_array_cansleep(unsigned int array_size, |
| 280 | struct gpio_desc **desc_array, |
| 281 | int *value_array) |
| 282 | { |
| 283 | /* GPIO can never have been requested */ |
| 284 | WARN_ON(1); |
| 285 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 286 | |
| 287 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 288 | { |
| 289 | /* GPIO can never have been requested */ |
| 290 | WARN_ON(1); |
| 291 | return -ENOSYS; |
| 292 | } |
| 293 | |
| 294 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 295 | { |
| 296 | /* GPIO can never have been requested */ |
| 297 | WARN_ON(1); |
| 298 | return 0; |
| 299 | } |
| 300 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 301 | { |
| 302 | /* GPIO can never have been requested */ |
| 303 | WARN_ON(1); |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 308 | { |
| 309 | /* GPIO can never have been requested */ |
| 310 | WARN_ON(1); |
| 311 | return -EINVAL; |
| 312 | } |
| 313 | |
| 314 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 315 | { |
| 316 | return ERR_PTR(-EINVAL); |
| 317 | } |
| 318 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 319 | { |
| 320 | /* GPIO can never have been requested */ |
| 321 | WARN_ON(1); |
| 322 | return -EINVAL; |
| 323 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 324 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 325 | #endif /* CONFIG_GPIOLIB */ |
| 326 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 327 | /* |
| 328 | * Vararg-hacks! This is done to transition the kernel to always pass |
| 329 | * the options flags argument to the below functions. During a transition |
| 330 | * phase these vararg macros make both old-and-newstyle code compile, |
| 331 | * but when all calls to the elder API are removed, these should go away |
| 332 | * and the __gpiod_get() etc functions above be renamed just gpiod_get() |
| 333 | * etc. |
| 334 | */ |
| 335 | #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags) |
| 336 | #define gpiod_get(varargs...) __gpiod_get(varargs, 0) |
| 337 | #define __gpiod_get_index(dev, con_id, index, flags, ...) \ |
| 338 | __gpiod_get_index(dev, con_id, index, flags) |
| 339 | #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0) |
| 340 | #define __gpiod_get_optional(dev, con_id, flags, ...) \ |
| 341 | __gpiod_get_optional(dev, con_id, flags) |
| 342 | #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0) |
| 343 | #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \ |
| 344 | __gpiod_get_index_optional(dev, con_id, index, flags) |
| 345 | #define gpiod_get_index_optional(varargs...) \ |
| 346 | __gpiod_get_index_optional(varargs, 0) |
| 347 | #define __devm_gpiod_get(dev, con_id, flags, ...) \ |
| 348 | __devm_gpiod_get(dev, con_id, flags) |
| 349 | #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0) |
| 350 | #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \ |
| 351 | __devm_gpiod_get_index(dev, con_id, index, flags) |
| 352 | #define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0) |
| 353 | #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \ |
| 354 | __devm_gpiod_get_optional(dev, con_id, flags) |
| 355 | #define devm_gpiod_get_optional(varargs...) \ |
| 356 | __devm_gpiod_get_optional(varargs, 0) |
| 357 | #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \ |
| 358 | __devm_gpiod_get_index_optional(dev, con_id, index, flags) |
| 359 | #define devm_gpiod_get_index_optional(varargs...) \ |
| 360 | __devm_gpiod_get_index_optional(varargs, 0) |
| 361 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 362 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 363 | |
| 364 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
| 365 | int gpiod_export_link(struct device *dev, const char *name, |
| 366 | struct gpio_desc *desc); |
| 367 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); |
| 368 | void gpiod_unexport(struct gpio_desc *desc); |
| 369 | |
| 370 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 371 | |
| 372 | static inline int gpiod_export(struct gpio_desc *desc, |
| 373 | bool direction_may_change) |
| 374 | { |
| 375 | return -ENOSYS; |
| 376 | } |
| 377 | |
| 378 | static inline int gpiod_export_link(struct device *dev, const char *name, |
| 379 | struct gpio_desc *desc) |
| 380 | { |
| 381 | return -ENOSYS; |
| 382 | } |
| 383 | |
| 384 | static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) |
| 385 | { |
| 386 | return -ENOSYS; |
| 387 | } |
| 388 | |
| 389 | static inline void gpiod_unexport(struct gpio_desc *desc) |
| 390 | { |
| 391 | } |
| 392 | |
| 393 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 394 | |
| 395 | #endif |