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); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 86 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
| 87 | |
Alexandre Courbot | 8e53b0f | 2014-11-25 17:16:31 +0900 | [diff] [blame] | 88 | int gpiod_get_direction(struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 89 | int gpiod_direction_input(struct gpio_desc *desc); |
| 90 | int gpiod_direction_output(struct gpio_desc *desc, int value); |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 91 | int gpiod_direction_output_raw(struct gpio_desc *desc, int value); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* Value get/set from non-sleeping context */ |
| 94 | int gpiod_get_value(const struct gpio_desc *desc); |
| 95 | void gpiod_set_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 96 | void gpiod_set_array(unsigned int array_size, |
| 97 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 98 | int gpiod_get_raw_value(const struct gpio_desc *desc); |
| 99 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 100 | void gpiod_set_raw_array(unsigned int array_size, |
| 101 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* Value get/set from sleeping context */ |
| 104 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); |
| 105 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 106 | void gpiod_set_array_cansleep(unsigned int array_size, |
| 107 | struct gpio_desc **desc_array, |
| 108 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 109 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
| 110 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 111 | void gpiod_set_raw_array_cansleep(unsigned int array_size, |
| 112 | struct gpio_desc **desc_array, |
| 113 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 114 | |
| 115 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
| 116 | |
| 117 | int gpiod_is_active_low(const struct gpio_desc *desc); |
| 118 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 119 | |
| 120 | int gpiod_to_irq(const struct gpio_desc *desc); |
| 121 | |
| 122 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 123 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| 124 | int desc_to_gpio(const struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 125 | |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 126 | /* Child properties interface */ |
| 127 | struct fwnode_handle; |
| 128 | |
| 129 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
| 130 | const char *propname); |
| 131 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 132 | const char *con_id, |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 133 | struct fwnode_handle *child); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 134 | #else /* CONFIG_GPIOLIB */ |
| 135 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame^] | 136 | static inline int gpiod_count(struct device *dev, const char *con_id) |
| 137 | { |
| 138 | return 0; |
| 139 | } |
| 140 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 141 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
| 142 | const char *con_id, |
| 143 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 144 | { |
| 145 | return ERR_PTR(-ENOSYS); |
| 146 | } |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 147 | static inline struct gpio_desc *__must_check |
| 148 | __gpiod_get_index(struct device *dev, |
| 149 | const char *con_id, |
| 150 | unsigned int idx, |
| 151 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 152 | { |
| 153 | return ERR_PTR(-ENOSYS); |
| 154 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 155 | |
| 156 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 157 | __gpiod_get_optional(struct device *dev, const char *con_id, |
| 158 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 159 | { |
| 160 | return ERR_PTR(-ENOSYS); |
| 161 | } |
| 162 | |
| 163 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 164 | __gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 165 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 166 | { |
| 167 | return ERR_PTR(-ENOSYS); |
| 168 | } |
| 169 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame^] | 170 | static inline struct gpio_descs *__must_check |
| 171 | gpiod_get_array(struct device *dev, const char *con_id, |
| 172 | enum gpiod_flags flags) |
| 173 | { |
| 174 | return ERR_PTR(-ENOSYS); |
| 175 | } |
| 176 | |
| 177 | static inline struct gpio_descs *__must_check |
| 178 | gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 179 | enum gpiod_flags flags) |
| 180 | { |
| 181 | return ERR_PTR(-ENOSYS); |
| 182 | } |
| 183 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 184 | static inline void gpiod_put(struct gpio_desc *desc) |
| 185 | { |
| 186 | might_sleep(); |
| 187 | |
| 188 | /* GPIO can never have been requested */ |
| 189 | WARN_ON(1); |
| 190 | } |
| 191 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame^] | 192 | static inline void gpiod_put_array(struct gpio_descs *descs) |
| 193 | { |
| 194 | might_sleep(); |
| 195 | |
| 196 | /* GPIO can never have been requested */ |
| 197 | WARN_ON(1); |
| 198 | } |
| 199 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 200 | static inline struct gpio_desc *__must_check |
| 201 | __devm_gpiod_get(struct device *dev, |
| 202 | const char *con_id, |
| 203 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 204 | { |
| 205 | return ERR_PTR(-ENOSYS); |
| 206 | } |
| 207 | static inline |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 208 | struct gpio_desc *__must_check |
| 209 | __devm_gpiod_get_index(struct device *dev, |
| 210 | const char *con_id, |
| 211 | unsigned int idx, |
| 212 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 213 | { |
| 214 | return ERR_PTR(-ENOSYS); |
| 215 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 216 | |
| 217 | static inline struct gpio_desc *__must_check |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 218 | __devm_gpiod_get_optional(struct device *dev, const char *con_id, |
| 219 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 220 | { |
| 221 | return ERR_PTR(-ENOSYS); |
| 222 | } |
| 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_index_optional(struct device *dev, const char *con_id, |
| 226 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 227 | { |
| 228 | return ERR_PTR(-ENOSYS); |
| 229 | } |
| 230 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 231 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 232 | { |
| 233 | might_sleep(); |
| 234 | |
| 235 | /* GPIO can never have been requested */ |
| 236 | WARN_ON(1); |
| 237 | } |
| 238 | |
| 239 | |
| 240 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 241 | { |
| 242 | /* GPIO can never have been requested */ |
| 243 | WARN_ON(1); |
| 244 | return -ENOSYS; |
| 245 | } |
| 246 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 247 | { |
| 248 | /* GPIO can never have been requested */ |
| 249 | WARN_ON(1); |
| 250 | return -ENOSYS; |
| 251 | } |
| 252 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 253 | { |
| 254 | /* GPIO can never have been requested */ |
| 255 | WARN_ON(1); |
| 256 | return -ENOSYS; |
| 257 | } |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 258 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 259 | { |
| 260 | /* GPIO can never have been requested */ |
| 261 | WARN_ON(1); |
| 262 | return -ENOSYS; |
| 263 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 264 | |
| 265 | |
| 266 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 267 | { |
| 268 | /* GPIO can never have been requested */ |
| 269 | WARN_ON(1); |
| 270 | return 0; |
| 271 | } |
| 272 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 273 | { |
| 274 | /* GPIO can never have been requested */ |
| 275 | WARN_ON(1); |
| 276 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 277 | static inline void gpiod_set_array(unsigned int array_size, |
| 278 | struct gpio_desc **desc_array, |
| 279 | int *value_array) |
| 280 | { |
| 281 | /* GPIO can never have been requested */ |
| 282 | WARN_ON(1); |
| 283 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 284 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
| 285 | { |
| 286 | /* GPIO can never have been requested */ |
| 287 | WARN_ON(1); |
| 288 | return 0; |
| 289 | } |
| 290 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 291 | { |
| 292 | /* GPIO can never have been requested */ |
| 293 | WARN_ON(1); |
| 294 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 295 | static inline void gpiod_set_raw_array(unsigned int array_size, |
| 296 | struct gpio_desc **desc_array, |
| 297 | int *value_array) |
| 298 | { |
| 299 | /* GPIO can never have been requested */ |
| 300 | WARN_ON(1); |
| 301 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 302 | |
| 303 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 304 | { |
| 305 | /* GPIO can never have been requested */ |
| 306 | WARN_ON(1); |
| 307 | return 0; |
| 308 | } |
| 309 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 310 | { |
| 311 | /* GPIO can never have been requested */ |
| 312 | WARN_ON(1); |
| 313 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 314 | static inline void gpiod_set_array_cansleep(unsigned int array_size, |
| 315 | struct gpio_desc **desc_array, |
| 316 | int *value_array) |
| 317 | { |
| 318 | /* GPIO can never have been requested */ |
| 319 | WARN_ON(1); |
| 320 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 321 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 322 | { |
| 323 | /* GPIO can never have been requested */ |
| 324 | WARN_ON(1); |
| 325 | return 0; |
| 326 | } |
| 327 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 328 | int value) |
| 329 | { |
| 330 | /* GPIO can never have been requested */ |
| 331 | WARN_ON(1); |
| 332 | } |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 333 | static inline void gpiod_set_raw_array_cansleep(unsigned int array_size, |
| 334 | struct gpio_desc **desc_array, |
| 335 | int *value_array) |
| 336 | { |
| 337 | /* GPIO can never have been requested */ |
| 338 | WARN_ON(1); |
| 339 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 340 | |
| 341 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 342 | { |
| 343 | /* GPIO can never have been requested */ |
| 344 | WARN_ON(1); |
| 345 | return -ENOSYS; |
| 346 | } |
| 347 | |
| 348 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 349 | { |
| 350 | /* GPIO can never have been requested */ |
| 351 | WARN_ON(1); |
| 352 | return 0; |
| 353 | } |
| 354 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 355 | { |
| 356 | /* GPIO can never have been requested */ |
| 357 | WARN_ON(1); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 362 | { |
| 363 | /* GPIO can never have been requested */ |
| 364 | WARN_ON(1); |
| 365 | return -EINVAL; |
| 366 | } |
| 367 | |
| 368 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 369 | { |
| 370 | return ERR_PTR(-EINVAL); |
| 371 | } |
| 372 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 373 | { |
| 374 | /* GPIO can never have been requested */ |
| 375 | WARN_ON(1); |
| 376 | return -EINVAL; |
| 377 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 378 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 379 | #endif /* CONFIG_GPIOLIB */ |
| 380 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 381 | /* |
| 382 | * Vararg-hacks! This is done to transition the kernel to always pass |
| 383 | * the options flags argument to the below functions. During a transition |
| 384 | * phase these vararg macros make both old-and-newstyle code compile, |
| 385 | * but when all calls to the elder API are removed, these should go away |
| 386 | * and the __gpiod_get() etc functions above be renamed just gpiod_get() |
| 387 | * etc. |
| 388 | */ |
| 389 | #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] | 390 | #define gpiod_get(varargs...) __gpiod_get(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 391 | #define __gpiod_get_index(dev, con_id, index, flags, ...) \ |
| 392 | __gpiod_get_index(dev, con_id, index, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 393 | #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 394 | #define __gpiod_get_optional(dev, con_id, flags, ...) \ |
| 395 | __gpiod_get_optional(dev, con_id, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 396 | #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 397 | #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \ |
| 398 | __gpiod_get_index_optional(dev, con_id, index, flags) |
| 399 | #define gpiod_get_index_optional(varargs...) \ |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 400 | __gpiod_get_index_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 401 | #define __devm_gpiod_get(dev, con_id, flags, ...) \ |
| 402 | __devm_gpiod_get(dev, con_id, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 403 | #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 404 | #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \ |
| 405 | __devm_gpiod_get_index(dev, con_id, index, flags) |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 406 | #define devm_gpiod_get_index(varargs...) \ |
| 407 | __devm_gpiod_get_index(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 408 | #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \ |
| 409 | __devm_gpiod_get_optional(dev, con_id, flags) |
| 410 | #define devm_gpiod_get_optional(varargs...) \ |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 411 | __devm_gpiod_get_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 412 | #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \ |
| 413 | __devm_gpiod_get_index_optional(dev, con_id, index, flags) |
| 414 | #define devm_gpiod_get_index_optional(varargs...) \ |
Olliver Schinagl | d34541b | 2015-01-07 09:44:57 +0100 | [diff] [blame] | 415 | __devm_gpiod_get_index_optional(varargs, GPIOD_ASIS) |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 416 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 417 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 418 | |
| 419 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
| 420 | int gpiod_export_link(struct device *dev, const char *name, |
| 421 | struct gpio_desc *desc); |
| 422 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); |
| 423 | void gpiod_unexport(struct gpio_desc *desc); |
| 424 | |
| 425 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 426 | |
| 427 | static inline int gpiod_export(struct gpio_desc *desc, |
| 428 | bool direction_may_change) |
| 429 | { |
| 430 | return -ENOSYS; |
| 431 | } |
| 432 | |
| 433 | static inline int gpiod_export_link(struct device *dev, const char *name, |
| 434 | struct gpio_desc *desc) |
| 435 | { |
| 436 | return -ENOSYS; |
| 437 | } |
| 438 | |
| 439 | static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) |
| 440 | { |
| 441 | return -ENOSYS; |
| 442 | } |
| 443 | |
| 444 | static inline void gpiod_unexport(struct gpio_desc *desc) |
| 445 | { |
| 446 | } |
| 447 | |
| 448 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 449 | |
| 450 | #endif |