diff options
Diffstat (limited to 'include/linux/gpio/consumer.h')
| -rw-r--r-- | include/linux/gpio/consumer.h | 109 |
1 files changed, 62 insertions, 47 deletions
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index b7ce0c64c6f3..12f146fa6604 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
| @@ -16,8 +16,6 @@ struct device; | |||
| 16 | */ | 16 | */ |
| 17 | struct gpio_desc; | 17 | struct gpio_desc; |
| 18 | 18 | ||
| 19 | #ifdef CONFIG_GPIOLIB | ||
| 20 | |||
| 21 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) | 19 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
| 22 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) | 20 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
| 23 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) | 21 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
| @@ -34,64 +32,38 @@ enum gpiod_flags { | |||
| 34 | GPIOD_FLAGS_BIT_DIR_VAL, | 32 | GPIOD_FLAGS_BIT_DIR_VAL, |
| 35 | }; | 33 | }; |
| 36 | 34 | ||
| 35 | #ifdef CONFIG_GPIOLIB | ||
| 36 | |||
| 37 | /* Acquire and dispose GPIOs */ | 37 | /* Acquire and dispose GPIOs */ |
| 38 | struct gpio_desc *__must_check __gpiod_get(struct device *dev, | 38 | struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 39 | const char *con_id, | 39 | const char *con_id, |
| 40 | enum gpiod_flags flags); | 40 | enum gpiod_flags flags); |
| 41 | #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags) | ||
| 42 | #define gpiod_get(varargs...) __gpiod_get(varargs, 0) | ||
| 43 | struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, | 41 | struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, |
| 44 | const char *con_id, | 42 | const char *con_id, |
| 45 | unsigned int idx, | 43 | unsigned int idx, |
| 46 | enum gpiod_flags flags); | 44 | enum gpiod_flags flags); |
| 47 | #define __gpiod_get_index(dev, con_id, index, flags, ...) \ | ||
| 48 | __gpiod_get_index(dev, con_id, index, flags) | ||
| 49 | #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0) | ||
| 50 | struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, | 45 | struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, |
| 51 | const char *con_id, | 46 | const char *con_id, |
| 52 | enum gpiod_flags flags); | 47 | enum gpiod_flags flags); |
| 53 | #define __gpiod_get_optional(dev, con_id, flags, ...) \ | ||
| 54 | __gpiod_get_optional(dev, con_id, flags) | ||
| 55 | #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0) | ||
| 56 | struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, | 48 | struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, |
| 57 | const char *con_id, | 49 | const char *con_id, |
| 58 | unsigned int index, | 50 | unsigned int index, |
| 59 | enum gpiod_flags flags); | 51 | enum gpiod_flags flags); |
| 60 | #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \ | ||
| 61 | __gpiod_get_index_optional(dev, con_id, index, flags) | ||
| 62 | #define gpiod_get_index_optional(varargs...) \ | ||
| 63 | __gpiod_get_index_optional(varargs, 0) | ||
| 64 | |||
| 65 | void gpiod_put(struct gpio_desc *desc); | 52 | void gpiod_put(struct gpio_desc *desc); |
| 66 | 53 | ||
| 67 | struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, | 54 | struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, |
| 68 | const char *con_id, | 55 | const char *con_id, |
| 69 | enum gpiod_flags flags); | 56 | enum gpiod_flags flags); |
| 70 | #define __devm_gpiod_get(dev, con_id, flags, ...) \ | ||
| 71 | __devm_gpiod_get(dev, con_id, flags) | ||
| 72 | #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0) | ||
| 73 | struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, | 57 | struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, |
| 74 | const char *con_id, | 58 | const char *con_id, |
| 75 | unsigned int idx, | 59 | unsigned int idx, |
| 76 | enum gpiod_flags flags); | 60 | enum gpiod_flags flags); |
| 77 | #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \ | ||
| 78 | __devm_gpiod_get_index(dev, con_id, index, flags) | ||
| 79 | #define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0) | ||
| 80 | struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, | 61 | struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, |
| 81 | const char *con_id, | 62 | const char *con_id, |
| 82 | enum gpiod_flags flags); | 63 | enum gpiod_flags flags); |
| 83 | #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \ | ||
| 84 | __devm_gpiod_get_optional(dev, con_id, flags) | ||
| 85 | #define devm_gpiod_get_optional(varargs...) \ | ||
| 86 | __devm_gpiod_get_optional(varargs, 0) | ||
| 87 | struct gpio_desc *__must_check | 64 | struct gpio_desc *__must_check |
| 88 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, | 65 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 89 | unsigned int index, enum gpiod_flags flags); | 66 | unsigned int index, enum gpiod_flags flags); |
| 90 | #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \ | ||
| 91 | __devm_gpiod_get_index_optional(dev, con_id, index, flags) | ||
| 92 | #define devm_gpiod_get_index_optional(varargs...) \ | ||
| 93 | __devm_gpiod_get_index_optional(varargs, 0) | ||
| 94 | |||
| 95 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); | 67 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
| 96 | 68 | ||
| 97 | int gpiod_get_direction(const struct gpio_desc *desc); | 69 | int gpiod_get_direction(const struct gpio_desc *desc); |
| @@ -124,27 +96,31 @@ int desc_to_gpio(const struct gpio_desc *desc); | |||
| 124 | 96 | ||
| 125 | #else /* CONFIG_GPIOLIB */ | 97 | #else /* CONFIG_GPIOLIB */ |
| 126 | 98 | ||
| 127 | static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, | 99 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 128 | const char *con_id) | 100 | const char *con_id, |
| 101 | enum gpiod_flags flags) | ||
| 129 | { | 102 | { |
| 130 | return ERR_PTR(-ENOSYS); | 103 | return ERR_PTR(-ENOSYS); |
| 131 | } | 104 | } |
| 132 | static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev, | 105 | static inline struct gpio_desc *__must_check |
| 133 | const char *con_id, | 106 | __gpiod_get_index(struct device *dev, |
| 134 | unsigned int idx) | 107 | const char *con_id, |
| 108 | unsigned int idx, | ||
| 109 | enum gpiod_flags flags) | ||
| 135 | { | 110 | { |
| 136 | return ERR_PTR(-ENOSYS); | 111 | return ERR_PTR(-ENOSYS); |
| 137 | } | 112 | } |
| 138 | 113 | ||
| 139 | static inline struct gpio_desc *__must_check | 114 | static inline struct gpio_desc *__must_check |
| 140 | gpiod_get_optional(struct device *dev, const char *con_id) | 115 | __gpiod_get_optional(struct device *dev, const char *con_id, |
| 116 | enum gpiod_flags flags) | ||
| 141 | { | 117 | { |
| 142 | return ERR_PTR(-ENOSYS); | 118 | return ERR_PTR(-ENOSYS); |
| 143 | } | 119 | } |
| 144 | 120 | ||
| 145 | static inline struct gpio_desc *__must_check | 121 | static inline struct gpio_desc *__must_check |
| 146 | gpiod_get_index_optional(struct device *dev, const char *con_id, | 122 | __gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 147 | unsigned int index) | 123 | unsigned int index, enum gpiod_flags flags) |
| 148 | { | 124 | { |
| 149 | return ERR_PTR(-ENOSYS); | 125 | return ERR_PTR(-ENOSYS); |
| 150 | } | 126 | } |
| @@ -157,28 +133,33 @@ static inline void gpiod_put(struct gpio_desc *desc) | |||
| 157 | WARN_ON(1); | 133 | WARN_ON(1); |
| 158 | } | 134 | } |
| 159 | 135 | ||
| 160 | static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, | 136 | static inline struct gpio_desc *__must_check |
| 161 | const char *con_id) | 137 | __devm_gpiod_get(struct device *dev, |
| 138 | const char *con_id, | ||
| 139 | enum gpiod_flags flags) | ||
| 162 | { | 140 | { |
| 163 | return ERR_PTR(-ENOSYS); | 141 | return ERR_PTR(-ENOSYS); |
| 164 | } | 142 | } |
| 165 | static inline | 143 | static inline |
| 166 | struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, | 144 | struct gpio_desc *__must_check |
| 167 | const char *con_id, | 145 | __devm_gpiod_get_index(struct device *dev, |
| 168 | unsigned int idx) | 146 | const char *con_id, |
| 147 | unsigned int idx, | ||
| 148 | enum gpiod_flags flags) | ||
| 169 | { | 149 | { |
| 170 | return ERR_PTR(-ENOSYS); | 150 | return ERR_PTR(-ENOSYS); |
| 171 | } | 151 | } |
| 172 | 152 | ||
| 173 | static inline struct gpio_desc *__must_check | 153 | static inline struct gpio_desc *__must_check |
| 174 | devm_gpiod_get_optional(struct device *dev, const char *con_id) | 154 | __devm_gpiod_get_optional(struct device *dev, const char *con_id, |
| 155 | enum gpiod_flags flags) | ||
| 175 | { | 156 | { |
| 176 | return ERR_PTR(-ENOSYS); | 157 | return ERR_PTR(-ENOSYS); |
| 177 | } | 158 | } |
| 178 | 159 | ||
| 179 | static inline struct gpio_desc *__must_check | 160 | static inline struct gpio_desc *__must_check |
| 180 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, | 161 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 181 | unsigned int index) | 162 | unsigned int index, enum gpiod_flags flags) |
| 182 | { | 163 | { |
| 183 | return ERR_PTR(-ENOSYS); | 164 | return ERR_PTR(-ENOSYS); |
| 184 | } | 165 | } |
| @@ -303,9 +284,43 @@ static inline int desc_to_gpio(const struct gpio_desc *desc) | |||
| 303 | return -EINVAL; | 284 | return -EINVAL; |
| 304 | } | 285 | } |
| 305 | 286 | ||
| 306 | |||
| 307 | #endif /* CONFIG_GPIOLIB */ | 287 | #endif /* CONFIG_GPIOLIB */ |
| 308 | 288 | ||
| 289 | /* | ||
| 290 | * Vararg-hacks! This is done to transition the kernel to always pass | ||
| 291 | * the options flags argument to the below functions. During a transition | ||
| 292 | * phase these vararg macros make both old-and-newstyle code compile, | ||
| 293 | * but when all calls to the elder API are removed, these should go away | ||
| 294 | * and the __gpiod_get() etc functions above be renamed just gpiod_get() | ||
| 295 | * etc. | ||
| 296 | */ | ||
| 297 | #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags) | ||
| 298 | #define gpiod_get(varargs...) __gpiod_get(varargs, 0) | ||
| 299 | #define __gpiod_get_index(dev, con_id, index, flags, ...) \ | ||
| 300 | __gpiod_get_index(dev, con_id, index, flags) | ||
| 301 | #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0) | ||
| 302 | #define __gpiod_get_optional(dev, con_id, flags, ...) \ | ||
| 303 | __gpiod_get_optional(dev, con_id, flags) | ||
| 304 | #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0) | ||
| 305 | #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \ | ||
| 306 | __gpiod_get_index_optional(dev, con_id, index, flags) | ||
| 307 | #define gpiod_get_index_optional(varargs...) \ | ||
| 308 | __gpiod_get_index_optional(varargs, 0) | ||
| 309 | #define __devm_gpiod_get(dev, con_id, flags, ...) \ | ||
| 310 | __devm_gpiod_get(dev, con_id, flags) | ||
| 311 | #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0) | ||
| 312 | #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \ | ||
| 313 | __devm_gpiod_get_index(dev, con_id, index, flags) | ||
| 314 | #define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0) | ||
| 315 | #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \ | ||
| 316 | __devm_gpiod_get_optional(dev, con_id, flags) | ||
| 317 | #define devm_gpiod_get_optional(varargs...) \ | ||
| 318 | __devm_gpiod_get_optional(varargs, 0) | ||
| 319 | #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \ | ||
| 320 | __devm_gpiod_get_index_optional(dev, con_id, index, flags) | ||
| 321 | #define devm_gpiod_get_index_optional(varargs...) \ | ||
| 322 | __devm_gpiod_get_index_optional(varargs, 0) | ||
| 323 | |||
| 309 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) | 324 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 310 | 325 | ||
| 311 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); | 326 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
