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 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 19 | /** |
| 20 | * Struct containing an array of descriptors that can be obtained using |
| 21 | * gpiod_get_array(). |
| 22 | */ |
| 23 | struct gpio_descs { |
| 24 | unsigned int ndescs; |
| 25 | struct gpio_desc *desc[]; |
| 26 | }; |
| 27 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 28 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
| 29 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
| 30 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
| 31 | |
| 32 | /** |
| 33 | * Optional flags that can be passed to one of gpiod_* to configure direction |
| 34 | * and output value. These values cannot be OR'd. |
| 35 | */ |
| 36 | enum gpiod_flags { |
| 37 | GPIOD_ASIS = 0, |
| 38 | GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, |
| 39 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, |
| 40 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
| 41 | GPIOD_FLAGS_BIT_DIR_VAL, |
| 42 | }; |
| 43 | |
Linus Walleij | 58b84f6 | 2014-08-19 12:00:53 -0500 | [diff] [blame] | 44 | #ifdef CONFIG_GPIOLIB |
| 45 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 46 | /* Return the number of GPIOs associated with a device / function */ |
| 47 | int gpiod_count(struct device *dev, const char *con_id); |
| 48 | |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 49 | /* Acquire and dispose GPIOs */ |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 50 | struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 51 | const char *con_id, |
| 52 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 53 | struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 54 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 55 | unsigned int idx, |
| 56 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 57 | struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, |
| 58 | const char *con_id, |
| 59 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 60 | struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 61 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 62 | unsigned int index, |
| 63 | enum gpiod_flags flags); |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 64 | struct gpio_descs *__must_check gpiod_get_array(struct device *dev, |
| 65 | const char *con_id, |
| 66 | enum gpiod_flags flags); |
| 67 | struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, |
| 68 | const char *con_id, |
| 69 | enum gpiod_flags flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 70 | void gpiod_put(struct gpio_desc *desc); |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 71 | void gpiod_put_array(struct gpio_descs *descs); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 72 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 73 | struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, |
| 74 | const char *con_id, |
| 75 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 76 | struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 77 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 78 | unsigned int idx, |
| 79 | enum gpiod_flags flags); |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 80 | struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, |
| 81 | const char *con_id, |
| 82 | enum gpiod_flags flags); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 83 | struct gpio_desc *__must_check |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 84 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 85 | unsigned int index, enum gpiod_flags flags); |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 86 | struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, |
| 87 | const char *con_id, |
| 88 | enum gpiod_flags flags); |
| 89 | struct gpio_descs *__must_check |
| 90 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 91 | enum gpiod_flags flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 92 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 93 | void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 94 | |
Alexandre Courbot | 8e53b0f | 2014-11-25 17:16:31 +0900 | [diff] [blame] | 95 | int gpiod_get_direction(struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 96 | int gpiod_direction_input(struct gpio_desc *desc); |
| 97 | int gpiod_direction_output(struct gpio_desc *desc, int value); |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 98 | int gpiod_direction_output_raw(struct gpio_desc *desc, int value); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* Value get/set from non-sleeping context */ |
| 101 | int gpiod_get_value(const struct gpio_desc *desc); |
| 102 | void gpiod_set_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 103 | void gpiod_set_array(unsigned int array_size, |
| 104 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 105 | int gpiod_get_raw_value(const struct gpio_desc *desc); |
| 106 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 107 | void gpiod_set_raw_array(unsigned int array_size, |
| 108 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 109 | |
| 110 | /* Value get/set from sleeping context */ |
| 111 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); |
| 112 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 113 | void gpiod_set_array_cansleep(unsigned int array_size, |
| 114 | struct gpio_desc **desc_array, |
| 115 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 116 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
| 117 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 118 | void gpiod_set_raw_array_cansleep(unsigned int array_size, |
| 119 | struct gpio_desc **desc_array, |
| 120 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 121 | |
| 122 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
| 123 | |
| 124 | int gpiod_is_active_low(const struct gpio_desc *desc); |
| 125 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 126 | |
| 127 | int gpiod_to_irq(const struct gpio_desc *desc); |
| 128 | |
| 129 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 130 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| 131 | int desc_to_gpio(const struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 132 | |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 133 | /* Child properties interface */ |
| 134 | struct fwnode_handle; |
| 135 | |
| 136 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
| 137 | const char *propname); |
| 138 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 139 | const char *con_id, |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 140 | struct fwnode_handle *child); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 141 | #else /* CONFIG_GPIOLIB */ |
| 142 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 143 | static inline int gpiod_count(struct device *dev, const char *con_id) |
| 144 | { |
| 145 | return 0; |
| 146 | } |
| 147 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 148 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 149 | const char *con_id, |
| 150 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 151 | { |
| 152 | return ERR_PTR(-ENOSYS); |
| 153 | } |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 154 | static inline struct gpio_desc *__must_check |
| 155 | __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 | __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 | __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 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 177 | static inline struct gpio_descs *__must_check |
| 178 | gpiod_get_array(struct device *dev, const char *con_id, |
| 179 | enum gpiod_flags flags) |
| 180 | { |
| 181 | return ERR_PTR(-ENOSYS); |
| 182 | } |
| 183 | |
| 184 | static inline struct gpio_descs *__must_check |
| 185 | gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 186 | enum gpiod_flags flags) |
| 187 | { |
| 188 | return ERR_PTR(-ENOSYS); |
| 189 | } |
| 190 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 191 | static inline void gpiod_put(struct gpio_desc *desc) |
| 192 | { |
| 193 | might_sleep(); |
| 194 | |
| 195 | /* GPIO can never have been requested */ |
| 196 | WARN_ON(1); |
| 197 | } |
| 198 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 199 | static inline void gpiod_put_array(struct gpio_descs *descs) |
| 200 | { |
| 201 | might_sleep(); |
| 202 | |
| 203 | /* GPIO can never have been requested */ |
| 204 | WARN_ON(1); |
| 205 | } |
| 206 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 207 | static inline struct gpio_desc *__must_check |
| 208 | __devm_gpiod_get(struct device *dev, |
| 209 | const char *con_id, |
| 210 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 211 | { |
| 212 | return ERR_PTR(-ENOSYS); |
| 213 | } |
| 214 | static inline |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 215 | struct gpio_desc *__must_check |
| 216 | __devm_gpiod_get_index(struct device *dev, |
| 217 | const char *con_id, |
| 218 | unsigned int idx, |
| 219 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 220 | { |
| 221 | return ERR_PTR(-ENOSYS); |
| 222 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 223 | |
| 224 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 225 | __devm_gpiod_get_optional(struct device *dev, const char *con_id, |
| 226 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 227 | { |
| 228 | return ERR_PTR(-ENOSYS); |
| 229 | } |
| 230 | |
| 231 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 232 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 233 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 234 | { |
| 235 | return ERR_PTR(-ENOSYS); |
| 236 | } |
| 237 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 238 | static inline struct gpio_descs *__must_check |
| 239 | devm_gpiod_get_array(struct device *dev, const char *con_id, |
| 240 | enum gpiod_flags flags) |
| 241 | { |
| 242 | return ERR_PTR(-ENOSYS); |
| 243 | } |
| 244 | |
| 245 | static inline struct gpio_descs *__must_check |
| 246 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 247 | enum gpiod_flags flags) |
| 248 | { |
| 249 | return ERR_PTR(-ENOSYS); |
| 250 | } |
| 251 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 252 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 253 | { |
| 254 | might_sleep(); |
| 255 | |
| 256 | /* GPIO can never have been requested */ |
| 257 | WARN_ON(1); |
| 258 | } |
| 259 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 260 | static inline void devm_gpiod_put_array(struct device *dev, |
| 261 | struct gpio_descs *descs) |
| 262 | { |
| 263 | might_sleep(); |
| 264 | |
| 265 | /* GPIO can never have been requested */ |
| 266 | WARN_ON(1); |
| 267 | } |
| 268 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 269 | |
| 270 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 271 | { |
| 272 | /* GPIO can never have been requested */ |
| 273 | WARN_ON(1); |
| 274 | return -ENOSYS; |
| 275 | } |
| 276 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 277 | { |
| 278 | /* GPIO can never have been requested */ |
| 279 | WARN_ON(1); |
| 280 | return -ENOSYS; |
| 281 | } |
| 282 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 283 | { |
| 284 | /* GPIO can never have been requested */ |
| 285 | WARN_ON(1); |
| 286 | return -ENOSYS; |
| 287 | } |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 288 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 289 | { |
| 290 | /* GPIO can never have been requested */ |
| 291 | WARN_ON(1); |
| 292 | return -ENOSYS; |
| 293 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 294 | |
| 295 | |
| 296 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 297 | { |
| 298 | /* GPIO can never have been requested */ |
| 299 | WARN_ON(1); |
| 300 | return 0; |
| 301 | } |
| 302 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 303 | { |
| 304 | /* GPIO can never have been requested */ |
| 305 | WARN_ON(1); |
| 306 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 307 | static inline void gpiod_set_array(unsigned int array_size, |
| 308 | struct gpio_desc **desc_array, |
| 309 | int *value_array) |
| 310 | { |
| 311 | /* GPIO can never have been requested */ |
| 312 | WARN_ON(1); |
| 313 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 314 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
| 315 | { |
| 316 | /* GPIO can never have been requested */ |
| 317 | WARN_ON(1); |
| 318 | return 0; |
| 319 | } |
| 320 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 321 | { |
| 322 | /* GPIO can never have been requested */ |
| 323 | WARN_ON(1); |
| 324 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 325 | static inline void gpiod_set_raw_array(unsigned int array_size, |
| 326 | struct gpio_desc **desc_array, |
| 327 | int *value_array) |
| 328 | { |
| 329 | /* GPIO can never have been requested */ |
| 330 | WARN_ON(1); |
| 331 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 332 | |
| 333 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 334 | { |
| 335 | /* GPIO can never have been requested */ |
| 336 | WARN_ON(1); |
| 337 | return 0; |
| 338 | } |
| 339 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 340 | { |
| 341 | /* GPIO can never have been requested */ |
| 342 | WARN_ON(1); |
| 343 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 344 | static inline void gpiod_set_array_cansleep(unsigned int array_size, |
| 345 | struct gpio_desc **desc_array, |
| 346 | int *value_array) |
| 347 | { |
| 348 | /* GPIO can never have been requested */ |
| 349 | WARN_ON(1); |
| 350 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 351 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 352 | { |
| 353 | /* GPIO can never have been requested */ |
| 354 | WARN_ON(1); |
| 355 | return 0; |
| 356 | } |
| 357 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 358 | int value) |
| 359 | { |
| 360 | /* GPIO can never have been requested */ |
| 361 | WARN_ON(1); |
| 362 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 363 | static inline void gpiod_set_raw_array_cansleep(unsigned int array_size, |
| 364 | struct gpio_desc **desc_array, |
| 365 | int *value_array) |
| 366 | { |
| 367 | /* GPIO can never have been requested */ |
| 368 | WARN_ON(1); |
| 369 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 370 | |
| 371 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 372 | { |
| 373 | /* GPIO can never have been requested */ |
| 374 | WARN_ON(1); |
| 375 | return -ENOSYS; |
| 376 | } |
| 377 | |
| 378 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 379 | { |
| 380 | /* GPIO can never have been requested */ |
| 381 | WARN_ON(1); |
| 382 | return 0; |
| 383 | } |
| 384 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 385 | { |
| 386 | /* GPIO can never have been requested */ |
| 387 | WARN_ON(1); |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 392 | { |
| 393 | /* GPIO can never have been requested */ |
| 394 | WARN_ON(1); |
| 395 | return -EINVAL; |
| 396 | } |
| 397 | |
| 398 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 399 | { |
| 400 | return ERR_PTR(-EINVAL); |
| 401 | } |
| 402 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 403 | { |
| 404 | /* GPIO can never have been requested */ |
| 405 | WARN_ON(1); |
| 406 | return -EINVAL; |
| 407 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 408 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 409 | #endif /* CONFIG_GPIOLIB */ |
| 410 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 411 | /* |
| 412 | * Vararg-hacks! This is done to transition the kernel to always pass |
| 413 | * the options flags argument to the below functions. During a transition |
| 414 | * phase these vararg macros make both old-and-newstyle code compile, |
| 415 | * but when all calls to the elder API are removed, these should go away |
| 416 | * and the __gpiod_get() etc functions above be renamed just gpiod_get() |
| 417 | * etc. |
| 418 | */ |
| 419 | #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 420 | #define gpiod_get(varargs...) __gpiod_get(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 421 | #define __gpiod_get_index(dev, con_id, index, flags, ...) \ |
| 422 | __gpiod_get_index(dev, con_id, index, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 423 | #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 424 | #define __gpiod_get_optional(dev, con_id, flags, ...) \ |
| 425 | __gpiod_get_optional(dev, con_id, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 426 | #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 427 | #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \ |
| 428 | __gpiod_get_index_optional(dev, con_id, index, flags) |
| 429 | #define gpiod_get_index_optional(varargs...) \ |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 430 | __gpiod_get_index_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 431 | #define __devm_gpiod_get(dev, con_id, flags, ...) \ |
| 432 | __devm_gpiod_get(dev, con_id, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 433 | #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 434 | #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \ |
| 435 | __devm_gpiod_get_index(dev, con_id, index, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 436 | #define devm_gpiod_get_index(varargs...) \ |
| 437 | __devm_gpiod_get_index(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 438 | #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \ |
| 439 | __devm_gpiod_get_optional(dev, con_id, flags) |
| 440 | #define devm_gpiod_get_optional(varargs...) \ |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 441 | __devm_gpiod_get_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 442 | #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \ |
| 443 | __devm_gpiod_get_index_optional(dev, con_id, index, flags) |
| 444 | #define devm_gpiod_get_index_optional(varargs...) \ |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 445 | __devm_gpiod_get_index_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 446 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 447 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 448 | |
| 449 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
| 450 | int gpiod_export_link(struct device *dev, const char *name, |
| 451 | struct gpio_desc *desc); |
| 452 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); |
| 453 | void gpiod_unexport(struct gpio_desc *desc); |
| 454 | |
| 455 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 456 | |
| 457 | static inline int gpiod_export(struct gpio_desc *desc, |
| 458 | bool direction_may_change) |
| 459 | { |
| 460 | return -ENOSYS; |
| 461 | } |
| 462 | |
| 463 | static inline int gpiod_export_link(struct device *dev, const char *name, |
| 464 | struct gpio_desc *desc) |
| 465 | { |
| 466 | return -ENOSYS; |
| 467 | } |
| 468 | |
| 469 | static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) |
| 470 | { |
| 471 | return -ENOSYS; |
| 472 | } |
| 473 | |
| 474 | static inline void gpiod_unexport(struct gpio_desc *desc) |
| 475 | { |
| 476 | } |
| 477 | |
| 478 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 479 | |
| 480 | #endif |