Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef __LINUX_GPIO_CONSUMER_H |
| 3 | #define __LINUX_GPIO_CONSUMER_H |
| 4 | |
| 5 | #include <linux/bug.h> |
| 6 | #include <linux/err.h> |
| 7 | #include <linux/kernel.h> |
| 8 | |
| 9 | struct device; |
| 10 | |
| 11 | /** |
| 12 | * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are |
| 13 | * preferable to the old integer-based handles. |
| 14 | * |
| 15 | * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid |
| 16 | * until the GPIO is released. |
| 17 | */ |
| 18 | struct gpio_desc; |
| 19 | |
| 20 | /** |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 21 | * Opaque descriptor for a structure of GPIO array attributes. This structure |
| 22 | * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be |
| 23 | * passed back to get/set array functions in order to activate fast processing |
| 24 | * path if applicable. |
| 25 | */ |
| 26 | struct gpio_array; |
| 27 | |
| 28 | /** |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | * Struct containing an array of descriptors that can be obtained using |
| 30 | * gpiod_get_array(). |
| 31 | */ |
| 32 | struct gpio_descs { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 33 | struct gpio_array *info; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 34 | unsigned int ndescs; |
| 35 | struct gpio_desc *desc[]; |
| 36 | }; |
| 37 | |
| 38 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
| 39 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
| 40 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
| 41 | #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 42 | #define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Optional flags that can be passed to one of gpiod_* to configure direction |
| 46 | * and output value. These values cannot be OR'd. |
| 47 | */ |
| 48 | enum gpiod_flags { |
| 49 | GPIOD_ASIS = 0, |
| 50 | GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, |
| 51 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, |
| 52 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
| 53 | GPIOD_FLAGS_BIT_DIR_VAL, |
| 54 | GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
| 55 | GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
| 56 | }; |
| 57 | |
| 58 | #ifdef CONFIG_GPIOLIB |
| 59 | |
| 60 | /* Return the number of GPIOs associated with a device / function */ |
| 61 | int gpiod_count(struct device *dev, const char *con_id); |
| 62 | |
| 63 | /* Acquire and dispose GPIOs */ |
| 64 | struct gpio_desc *__must_check gpiod_get(struct device *dev, |
| 65 | const char *con_id, |
| 66 | enum gpiod_flags flags); |
| 67 | struct gpio_desc *__must_check gpiod_get_index(struct device *dev, |
| 68 | const char *con_id, |
| 69 | unsigned int idx, |
| 70 | enum gpiod_flags flags); |
| 71 | struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, |
| 72 | const char *con_id, |
| 73 | enum gpiod_flags flags); |
| 74 | struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, |
| 75 | const char *con_id, |
| 76 | unsigned int index, |
| 77 | enum gpiod_flags flags); |
| 78 | struct gpio_descs *__must_check gpiod_get_array(struct device *dev, |
| 79 | const char *con_id, |
| 80 | enum gpiod_flags flags); |
| 81 | struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, |
| 82 | const char *con_id, |
| 83 | enum gpiod_flags flags); |
| 84 | void gpiod_put(struct gpio_desc *desc); |
| 85 | void gpiod_put_array(struct gpio_descs *descs); |
| 86 | |
| 87 | struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, |
| 88 | const char *con_id, |
| 89 | enum gpiod_flags flags); |
| 90 | struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, |
| 91 | const char *con_id, |
| 92 | unsigned int idx, |
| 93 | enum gpiod_flags flags); |
| 94 | struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, |
| 95 | const char *con_id, |
| 96 | enum gpiod_flags flags); |
| 97 | struct gpio_desc *__must_check |
| 98 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 99 | unsigned int index, enum gpiod_flags flags); |
| 100 | struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, |
| 101 | const char *con_id, |
| 102 | enum gpiod_flags flags); |
| 103 | struct gpio_descs *__must_check |
| 104 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 105 | enum gpiod_flags flags); |
| 106 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 107 | void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 108 | void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); |
| 109 | |
| 110 | int gpiod_get_direction(struct gpio_desc *desc); |
| 111 | int gpiod_direction_input(struct gpio_desc *desc); |
| 112 | int gpiod_direction_output(struct gpio_desc *desc, int value); |
| 113 | int gpiod_direction_output_raw(struct gpio_desc *desc, int value); |
| 114 | |
| 115 | /* Value get/set from non-sleeping context */ |
| 116 | int gpiod_get_value(const struct gpio_desc *desc); |
| 117 | int gpiod_get_array_value(unsigned int array_size, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 118 | struct gpio_desc **desc_array, |
| 119 | struct gpio_array *array_info, |
| 120 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 121 | void gpiod_set_value(struct gpio_desc *desc, int value); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 122 | int gpiod_set_array_value(unsigned int array_size, |
| 123 | struct gpio_desc **desc_array, |
| 124 | struct gpio_array *array_info, |
| 125 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 126 | int gpiod_get_raw_value(const struct gpio_desc *desc); |
| 127 | int gpiod_get_raw_array_value(unsigned int array_size, |
| 128 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 129 | struct gpio_array *array_info, |
| 130 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 131 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); |
| 132 | int gpiod_set_raw_array_value(unsigned int array_size, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 133 | struct gpio_desc **desc_array, |
| 134 | struct gpio_array *array_info, |
| 135 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 136 | |
| 137 | /* Value get/set from sleeping context */ |
| 138 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); |
| 139 | int gpiod_get_array_value_cansleep(unsigned int array_size, |
| 140 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 141 | struct gpio_array *array_info, |
| 142 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 143 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 144 | int gpiod_set_array_value_cansleep(unsigned int array_size, |
| 145 | struct gpio_desc **desc_array, |
| 146 | struct gpio_array *array_info, |
| 147 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 148 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
| 149 | int gpiod_get_raw_array_value_cansleep(unsigned int array_size, |
| 150 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 151 | struct gpio_array *array_info, |
| 152 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 153 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
| 154 | int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 155 | struct gpio_desc **desc_array, |
| 156 | struct gpio_array *array_info, |
| 157 | unsigned long *value_bitmap); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 158 | |
| 159 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
| 160 | int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 161 | void gpiod_toggle_active_low(struct gpio_desc *desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 162 | |
| 163 | int gpiod_is_active_low(const struct gpio_desc *desc); |
| 164 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 165 | |
| 166 | int gpiod_to_irq(const struct gpio_desc *desc); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 167 | int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 168 | |
| 169 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 170 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| 171 | int desc_to_gpio(const struct gpio_desc *desc); |
| 172 | |
| 173 | /* Child properties interface */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 174 | struct fwnode_handle; |
| 175 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 176 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
| 177 | const char *propname, int index, |
| 178 | enum gpiod_flags dflags, |
| 179 | const char *label); |
| 180 | struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, |
| 181 | const char *con_id, int index, |
| 182 | struct fwnode_handle *child, |
| 183 | enum gpiod_flags flags, |
| 184 | const char *label); |
| 185 | |
| 186 | #else /* CONFIG_GPIOLIB */ |
| 187 | |
| 188 | static inline int gpiod_count(struct device *dev, const char *con_id) |
| 189 | { |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, |
| 194 | const char *con_id, |
| 195 | enum gpiod_flags flags) |
| 196 | { |
| 197 | return ERR_PTR(-ENOSYS); |
| 198 | } |
| 199 | static inline struct gpio_desc *__must_check |
| 200 | gpiod_get_index(struct device *dev, |
| 201 | const char *con_id, |
| 202 | unsigned int idx, |
| 203 | enum gpiod_flags flags) |
| 204 | { |
| 205 | return ERR_PTR(-ENOSYS); |
| 206 | } |
| 207 | |
| 208 | static inline struct gpio_desc *__must_check |
| 209 | gpiod_get_optional(struct device *dev, const char *con_id, |
| 210 | enum gpiod_flags flags) |
| 211 | { |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | static inline struct gpio_desc *__must_check |
| 216 | gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 217 | unsigned int index, enum gpiod_flags flags) |
| 218 | { |
| 219 | return NULL; |
| 220 | } |
| 221 | |
| 222 | static inline struct gpio_descs *__must_check |
| 223 | gpiod_get_array(struct device *dev, const char *con_id, |
| 224 | enum gpiod_flags flags) |
| 225 | { |
| 226 | return ERR_PTR(-ENOSYS); |
| 227 | } |
| 228 | |
| 229 | static inline struct gpio_descs *__must_check |
| 230 | gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 231 | enum gpiod_flags flags) |
| 232 | { |
| 233 | return NULL; |
| 234 | } |
| 235 | |
| 236 | static inline void gpiod_put(struct gpio_desc *desc) |
| 237 | { |
| 238 | might_sleep(); |
| 239 | |
| 240 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 241 | WARN_ON(desc); |
| 242 | } |
| 243 | |
| 244 | static inline void devm_gpiod_unhinge(struct device *dev, |
| 245 | struct gpio_desc *desc) |
| 246 | { |
| 247 | might_sleep(); |
| 248 | |
| 249 | /* GPIO can never have been requested */ |
| 250 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static inline void gpiod_put_array(struct gpio_descs *descs) |
| 254 | { |
| 255 | might_sleep(); |
| 256 | |
| 257 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 258 | WARN_ON(descs); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static inline struct gpio_desc *__must_check |
| 262 | devm_gpiod_get(struct device *dev, |
| 263 | const char *con_id, |
| 264 | enum gpiod_flags flags) |
| 265 | { |
| 266 | return ERR_PTR(-ENOSYS); |
| 267 | } |
| 268 | static inline |
| 269 | struct gpio_desc *__must_check |
| 270 | devm_gpiod_get_index(struct device *dev, |
| 271 | const char *con_id, |
| 272 | unsigned int idx, |
| 273 | enum gpiod_flags flags) |
| 274 | { |
| 275 | return ERR_PTR(-ENOSYS); |
| 276 | } |
| 277 | |
| 278 | static inline struct gpio_desc *__must_check |
| 279 | devm_gpiod_get_optional(struct device *dev, const char *con_id, |
| 280 | enum gpiod_flags flags) |
| 281 | { |
| 282 | return NULL; |
| 283 | } |
| 284 | |
| 285 | static inline struct gpio_desc *__must_check |
| 286 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 287 | unsigned int index, enum gpiod_flags flags) |
| 288 | { |
| 289 | return NULL; |
| 290 | } |
| 291 | |
| 292 | static inline struct gpio_descs *__must_check |
| 293 | devm_gpiod_get_array(struct device *dev, const char *con_id, |
| 294 | enum gpiod_flags flags) |
| 295 | { |
| 296 | return ERR_PTR(-ENOSYS); |
| 297 | } |
| 298 | |
| 299 | static inline struct gpio_descs *__must_check |
| 300 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 301 | enum gpiod_flags flags) |
| 302 | { |
| 303 | return NULL; |
| 304 | } |
| 305 | |
| 306 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 307 | { |
| 308 | might_sleep(); |
| 309 | |
| 310 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 311 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static inline void devm_gpiod_put_array(struct device *dev, |
| 315 | struct gpio_descs *descs) |
| 316 | { |
| 317 | might_sleep(); |
| 318 | |
| 319 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 320 | WARN_ON(descs); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
| 324 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 325 | { |
| 326 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 327 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 328 | return -ENOSYS; |
| 329 | } |
| 330 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 331 | { |
| 332 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 333 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 334 | return -ENOSYS; |
| 335 | } |
| 336 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 337 | { |
| 338 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 339 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 340 | return -ENOSYS; |
| 341 | } |
| 342 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 343 | { |
| 344 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 345 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 346 | return -ENOSYS; |
| 347 | } |
| 348 | |
| 349 | |
| 350 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 351 | { |
| 352 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 353 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | static inline int gpiod_get_array_value(unsigned int array_size, |
| 357 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 358 | struct gpio_array *array_info, |
| 359 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 360 | { |
| 361 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 362 | WARN_ON(desc_array); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 363 | return 0; |
| 364 | } |
| 365 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 366 | { |
| 367 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 368 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 369 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 370 | static inline int gpiod_set_array_value(unsigned int array_size, |
| 371 | struct gpio_desc **desc_array, |
| 372 | struct gpio_array *array_info, |
| 373 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 374 | { |
| 375 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 376 | WARN_ON(desc_array); |
| 377 | return 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 378 | } |
| 379 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
| 380 | { |
| 381 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 382 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 383 | return 0; |
| 384 | } |
| 385 | static inline int gpiod_get_raw_array_value(unsigned int array_size, |
| 386 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 387 | struct gpio_array *array_info, |
| 388 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 389 | { |
| 390 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 391 | WARN_ON(desc_array); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 395 | { |
| 396 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 397 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 398 | } |
| 399 | static inline int gpiod_set_raw_array_value(unsigned int array_size, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 400 | struct gpio_desc **desc_array, |
| 401 | struct gpio_array *array_info, |
| 402 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 403 | { |
| 404 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 405 | WARN_ON(desc_array); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 410 | { |
| 411 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 412 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | static inline int gpiod_get_array_value_cansleep(unsigned int array_size, |
| 416 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 417 | struct gpio_array *array_info, |
| 418 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 419 | { |
| 420 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 421 | WARN_ON(desc_array); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 425 | { |
| 426 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 427 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 428 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 429 | static inline int gpiod_set_array_value_cansleep(unsigned int array_size, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 430 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 431 | struct gpio_array *array_info, |
| 432 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 433 | { |
| 434 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 435 | WARN_ON(desc_array); |
| 436 | return 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 437 | } |
| 438 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 439 | { |
| 440 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 441 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, |
| 445 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 446 | struct gpio_array *array_info, |
| 447 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 448 | { |
| 449 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 450 | WARN_ON(desc_array); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 454 | int value) |
| 455 | { |
| 456 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 457 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 458 | } |
| 459 | static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
| 460 | struct gpio_desc **desc_array, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 461 | struct gpio_array *array_info, |
| 462 | unsigned long *value_bitmap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 463 | { |
| 464 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 465 | WARN_ON(desc_array); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 470 | { |
| 471 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 472 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 473 | return -ENOSYS; |
| 474 | } |
| 475 | |
| 476 | static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) |
| 477 | { |
| 478 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 479 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 480 | return -ENOSYS; |
| 481 | } |
| 482 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 483 | static inline void gpiod_toggle_active_low(struct gpio_desc *desc) |
| 484 | { |
| 485 | /* GPIO can never have been requested */ |
| 486 | WARN_ON(desc); |
| 487 | } |
| 488 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 489 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 490 | { |
| 491 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 492 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 496 | { |
| 497 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 498 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 503 | { |
| 504 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 505 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 506 | return -EINVAL; |
| 507 | } |
| 508 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 509 | static inline int gpiod_set_consumer_name(struct gpio_desc *desc, |
| 510 | const char *name) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 511 | { |
| 512 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 513 | WARN_ON(desc); |
| 514 | return -EINVAL; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 518 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 519 | return NULL; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 523 | { |
| 524 | /* GPIO can never have been requested */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 525 | WARN_ON(desc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 526 | return -EINVAL; |
| 527 | } |
| 528 | |
| 529 | /* Child properties interface */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 530 | struct fwnode_handle; |
| 531 | |
| 532 | static inline |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 533 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
| 534 | const char *propname, int index, |
| 535 | enum gpiod_flags dflags, |
| 536 | const char *label) |
| 537 | { |
| 538 | return ERR_PTR(-ENOSYS); |
| 539 | } |
| 540 | |
| 541 | static inline |
| 542 | struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, |
| 543 | const char *con_id, int index, |
| 544 | struct fwnode_handle *child, |
| 545 | enum gpiod_flags flags, |
| 546 | const char *label) |
| 547 | { |
| 548 | return ERR_PTR(-ENOSYS); |
| 549 | } |
| 550 | |
| 551 | #endif /* CONFIG_GPIOLIB */ |
| 552 | |
| 553 | static inline |
| 554 | struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, |
| 555 | const char *con_id, |
| 556 | struct fwnode_handle *child, |
| 557 | enum gpiod_flags flags, |
| 558 | const char *label) |
| 559 | { |
| 560 | return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child, |
| 561 | flags, label); |
| 562 | } |
| 563 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 564 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO) |
| 565 | struct device_node; |
| 566 | |
| 567 | struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, |
| 568 | const char *propname, int index, |
| 569 | enum gpiod_flags dflags, |
| 570 | const char *label); |
| 571 | |
| 572 | #else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */ |
| 573 | |
| 574 | struct device_node; |
| 575 | |
| 576 | static inline |
| 577 | struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, |
| 578 | const char *propname, int index, |
| 579 | enum gpiod_flags dflags, |
| 580 | const char *label) |
| 581 | { |
| 582 | return ERR_PTR(-ENOSYS); |
| 583 | } |
| 584 | |
| 585 | #endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */ |
| 586 | |
| 587 | #ifdef CONFIG_GPIOLIB |
| 588 | struct device_node; |
| 589 | |
| 590 | struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, |
| 591 | struct device_node *node, |
| 592 | const char *propname, int index, |
| 593 | enum gpiod_flags dflags, |
| 594 | const char *label); |
| 595 | |
| 596 | #else /* CONFIG_GPIOLIB */ |
| 597 | |
| 598 | struct device_node; |
| 599 | |
| 600 | static inline |
| 601 | struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, |
| 602 | struct device_node *node, |
| 603 | const char *propname, int index, |
| 604 | enum gpiod_flags dflags, |
| 605 | const char *label) |
| 606 | { |
| 607 | return ERR_PTR(-ENOSYS); |
| 608 | } |
| 609 | |
| 610 | #endif /* CONFIG_GPIOLIB */ |
| 611 | |
| 612 | struct acpi_gpio_params { |
| 613 | unsigned int crs_entry_index; |
| 614 | unsigned int line_index; |
| 615 | bool active_low; |
| 616 | }; |
| 617 | |
| 618 | struct acpi_gpio_mapping { |
| 619 | const char *name; |
| 620 | const struct acpi_gpio_params *data; |
| 621 | unsigned int size; |
| 622 | |
| 623 | /* Ignore IoRestriction field */ |
| 624 | #define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0) |
| 625 | /* |
| 626 | * When ACPI GPIO mapping table is in use the index parameter inside it |
| 627 | * refers to the GPIO resource in _CRS method. That index has no |
| 628 | * distinction of actual type of the resource. When consumer wants to |
| 629 | * get GpioIo type explicitly, this quirk may be used. |
| 630 | */ |
| 631 | #define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1) |
| 632 | |
| 633 | unsigned int quirks; |
| 634 | }; |
| 635 | |
| 636 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI) |
| 637 | |
| 638 | struct acpi_device; |
| 639 | |
| 640 | int acpi_dev_add_driver_gpios(struct acpi_device *adev, |
| 641 | const struct acpi_gpio_mapping *gpios); |
| 642 | void acpi_dev_remove_driver_gpios(struct acpi_device *adev); |
| 643 | |
| 644 | int devm_acpi_dev_add_driver_gpios(struct device *dev, |
| 645 | const struct acpi_gpio_mapping *gpios); |
| 646 | void devm_acpi_dev_remove_driver_gpios(struct device *dev); |
| 647 | |
| 648 | #else /* CONFIG_GPIOLIB && CONFIG_ACPI */ |
| 649 | |
| 650 | struct acpi_device; |
| 651 | |
| 652 | static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev, |
| 653 | const struct acpi_gpio_mapping *gpios) |
| 654 | { |
| 655 | return -ENXIO; |
| 656 | } |
| 657 | static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {} |
| 658 | |
| 659 | static inline int devm_acpi_dev_add_driver_gpios(struct device *dev, |
| 660 | const struct acpi_gpio_mapping *gpios) |
| 661 | { |
| 662 | return -ENXIO; |
| 663 | } |
| 664 | static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {} |
| 665 | |
| 666 | #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */ |
| 667 | |
| 668 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 669 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 670 | |
| 671 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
| 672 | int gpiod_export_link(struct device *dev, const char *name, |
| 673 | struct gpio_desc *desc); |
| 674 | void gpiod_unexport(struct gpio_desc *desc); |
| 675 | |
| 676 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 677 | |
| 678 | static inline int gpiod_export(struct gpio_desc *desc, |
| 679 | bool direction_may_change) |
| 680 | { |
| 681 | return -ENOSYS; |
| 682 | } |
| 683 | |
| 684 | static inline int gpiod_export_link(struct device *dev, const char *name, |
| 685 | struct gpio_desc *desc) |
| 686 | { |
| 687 | return -ENOSYS; |
| 688 | } |
| 689 | |
| 690 | static inline void gpiod_unexport(struct gpio_desc *desc) |
| 691 | { |
| 692 | } |
| 693 | |
| 694 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 695 | |
| 696 | #endif |