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 */ |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 50 | struct gpio_desc *__must_check gpiod_get(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 51 | const char *con_id, |
| 52 | enum gpiod_flags flags); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [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); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 57 | struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 58 | const char *con_id, |
| 59 | enum gpiod_flags flags); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [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 | |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 73 | struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 74 | const char *con_id, |
| 75 | enum gpiod_flags flags); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [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); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 80 | struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 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 |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 84 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 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 | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 103 | void gpiod_set_array_value(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 | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 107 | void gpiod_set_raw_array_value(unsigned int array_size, |
| 108 | struct gpio_desc **desc_array, |
| 109 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* Value get/set from sleeping context */ |
| 112 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); |
| 113 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 114 | void gpiod_set_array_value_cansleep(unsigned int array_size, |
| 115 | struct gpio_desc **desc_array, |
| 116 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 117 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
| 118 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 119 | void gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
| 120 | struct gpio_desc **desc_array, |
| 121 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 122 | |
| 123 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
| 124 | |
| 125 | int gpiod_is_active_low(const struct gpio_desc *desc); |
| 126 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 127 | |
| 128 | int gpiod_to_irq(const struct gpio_desc *desc); |
| 129 | |
| 130 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 131 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| 132 | int desc_to_gpio(const struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 133 | |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 134 | /* Child properties interface */ |
| 135 | struct fwnode_handle; |
| 136 | |
| 137 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
Andy Shevchenko | a264d10 | 2017-01-09 16:02:28 +0200 | [diff] [blame] | 138 | const char *propname, |
Alexander Stein | b2987d7 | 2017-01-12 17:39:24 +0100 | [diff] [blame] | 139 | enum gpiod_flags dflags, |
| 140 | const char *label); |
Boris Brezillon | 4b09479 | 2017-02-02 14:53:10 +0100 | [diff] [blame^] | 141 | struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, |
| 142 | const char *con_id, |
| 143 | struct fwnode_handle *child, |
| 144 | enum gpiod_flags flags, |
| 145 | const char *label); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 146 | #else /* CONFIG_GPIOLIB */ |
| 147 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 148 | static inline int gpiod_count(struct device *dev, const char *con_id) |
| 149 | { |
| 150 | return 0; |
| 151 | } |
| 152 | |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 153 | static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, |
| 154 | const char *con_id, |
| 155 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 156 | { |
| 157 | return ERR_PTR(-ENOSYS); |
| 158 | } |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 159 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 160 | gpiod_get_index(struct device *dev, |
| 161 | const char *con_id, |
| 162 | unsigned int idx, |
| 163 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 164 | { |
| 165 | return ERR_PTR(-ENOSYS); |
| 166 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 167 | |
| 168 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 169 | gpiod_get_optional(struct device *dev, const char *con_id, |
| 170 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 171 | { |
| 172 | return ERR_PTR(-ENOSYS); |
| 173 | } |
| 174 | |
| 175 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 176 | gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 177 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 178 | { |
| 179 | return ERR_PTR(-ENOSYS); |
| 180 | } |
| 181 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 182 | static inline struct gpio_descs *__must_check |
| 183 | gpiod_get_array(struct device *dev, const char *con_id, |
| 184 | enum gpiod_flags flags) |
| 185 | { |
| 186 | return ERR_PTR(-ENOSYS); |
| 187 | } |
| 188 | |
| 189 | static inline struct gpio_descs *__must_check |
| 190 | gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 191 | enum gpiod_flags flags) |
| 192 | { |
| 193 | return ERR_PTR(-ENOSYS); |
| 194 | } |
| 195 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 196 | static inline void gpiod_put(struct gpio_desc *desc) |
| 197 | { |
| 198 | might_sleep(); |
| 199 | |
| 200 | /* GPIO can never have been requested */ |
| 201 | WARN_ON(1); |
| 202 | } |
| 203 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 204 | static inline void gpiod_put_array(struct gpio_descs *descs) |
| 205 | { |
| 206 | might_sleep(); |
| 207 | |
| 208 | /* GPIO can never have been requested */ |
| 209 | WARN_ON(1); |
| 210 | } |
| 211 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 212 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 213 | devm_gpiod_get(struct device *dev, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 214 | const char *con_id, |
| 215 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 216 | { |
| 217 | return ERR_PTR(-ENOSYS); |
| 218 | } |
| 219 | static inline |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 220 | struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 221 | devm_gpiod_get_index(struct device *dev, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 222 | const char *con_id, |
| 223 | unsigned int idx, |
| 224 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 225 | { |
| 226 | return ERR_PTR(-ENOSYS); |
| 227 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 228 | |
| 229 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 230 | devm_gpiod_get_optional(struct device *dev, const char *con_id, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 231 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 232 | { |
| 233 | return ERR_PTR(-ENOSYS); |
| 234 | } |
| 235 | |
| 236 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 237 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 238 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 239 | { |
| 240 | return ERR_PTR(-ENOSYS); |
| 241 | } |
| 242 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 243 | static inline struct gpio_descs *__must_check |
| 244 | devm_gpiod_get_array(struct device *dev, const char *con_id, |
| 245 | enum gpiod_flags flags) |
| 246 | { |
| 247 | return ERR_PTR(-ENOSYS); |
| 248 | } |
| 249 | |
| 250 | static inline struct gpio_descs *__must_check |
| 251 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 252 | enum gpiod_flags flags) |
| 253 | { |
| 254 | return ERR_PTR(-ENOSYS); |
| 255 | } |
| 256 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 257 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 258 | { |
| 259 | might_sleep(); |
| 260 | |
| 261 | /* GPIO can never have been requested */ |
| 262 | WARN_ON(1); |
| 263 | } |
| 264 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 265 | static inline void devm_gpiod_put_array(struct device *dev, |
| 266 | struct gpio_descs *descs) |
| 267 | { |
| 268 | might_sleep(); |
| 269 | |
| 270 | /* GPIO can never have been requested */ |
| 271 | WARN_ON(1); |
| 272 | } |
| 273 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 274 | |
| 275 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 276 | { |
| 277 | /* GPIO can never have been requested */ |
| 278 | WARN_ON(1); |
| 279 | return -ENOSYS; |
| 280 | } |
| 281 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 282 | { |
| 283 | /* GPIO can never have been requested */ |
| 284 | WARN_ON(1); |
| 285 | return -ENOSYS; |
| 286 | } |
| 287 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 288 | { |
| 289 | /* GPIO can never have been requested */ |
| 290 | WARN_ON(1); |
| 291 | return -ENOSYS; |
| 292 | } |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 293 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 294 | { |
| 295 | /* GPIO can never have been requested */ |
| 296 | WARN_ON(1); |
| 297 | return -ENOSYS; |
| 298 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 299 | |
| 300 | |
| 301 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 302 | { |
| 303 | /* GPIO can never have been requested */ |
| 304 | WARN_ON(1); |
| 305 | return 0; |
| 306 | } |
| 307 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 308 | { |
| 309 | /* GPIO can never have been requested */ |
| 310 | WARN_ON(1); |
| 311 | } |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 312 | static inline void gpiod_set_array_value(unsigned int array_size, |
| 313 | struct gpio_desc **desc_array, |
| 314 | int *value_array) |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 315 | { |
| 316 | /* GPIO can never have been requested */ |
| 317 | WARN_ON(1); |
| 318 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 319 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
| 320 | { |
| 321 | /* GPIO can never have been requested */ |
| 322 | WARN_ON(1); |
| 323 | return 0; |
| 324 | } |
| 325 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 326 | { |
| 327 | /* GPIO can never have been requested */ |
| 328 | WARN_ON(1); |
| 329 | } |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 330 | static inline void gpiod_set_raw_array_value(unsigned int array_size, |
| 331 | struct gpio_desc **desc_array, |
| 332 | int *value_array) |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 333 | { |
| 334 | /* GPIO can never have been requested */ |
| 335 | WARN_ON(1); |
| 336 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 337 | |
| 338 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 339 | { |
| 340 | /* GPIO can never have been requested */ |
| 341 | WARN_ON(1); |
| 342 | return 0; |
| 343 | } |
| 344 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 345 | { |
| 346 | /* GPIO can never have been requested */ |
| 347 | WARN_ON(1); |
| 348 | } |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 349 | static inline void gpiod_set_array_value_cansleep(unsigned int array_size, |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 350 | struct gpio_desc **desc_array, |
| 351 | int *value_array) |
| 352 | { |
| 353 | /* GPIO can never have been requested */ |
| 354 | WARN_ON(1); |
| 355 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 356 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 357 | { |
| 358 | /* GPIO can never have been requested */ |
| 359 | WARN_ON(1); |
| 360 | return 0; |
| 361 | } |
| 362 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 363 | int value) |
| 364 | { |
| 365 | /* GPIO can never have been requested */ |
| 366 | WARN_ON(1); |
| 367 | } |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 368 | static inline void gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 369 | struct gpio_desc **desc_array, |
| 370 | int *value_array) |
| 371 | { |
| 372 | /* GPIO can never have been requested */ |
| 373 | WARN_ON(1); |
| 374 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 375 | |
| 376 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 377 | { |
| 378 | /* GPIO can never have been requested */ |
| 379 | WARN_ON(1); |
| 380 | return -ENOSYS; |
| 381 | } |
| 382 | |
| 383 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 384 | { |
| 385 | /* GPIO can never have been requested */ |
| 386 | WARN_ON(1); |
| 387 | return 0; |
| 388 | } |
| 389 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 390 | { |
| 391 | /* GPIO can never have been requested */ |
| 392 | WARN_ON(1); |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 397 | { |
| 398 | /* GPIO can never have been requested */ |
| 399 | WARN_ON(1); |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | |
| 403 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 404 | { |
| 405 | return ERR_PTR(-EINVAL); |
| 406 | } |
Markus Pargmann | c0017ed | 2015-08-14 16:10:59 +0200 | [diff] [blame] | 407 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 408 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 409 | { |
| 410 | /* GPIO can never have been requested */ |
| 411 | WARN_ON(1); |
| 412 | return -EINVAL; |
| 413 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 414 | |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 415 | /* Child properties interface */ |
| 416 | struct fwnode_handle; |
| 417 | |
Andy Shevchenko | a264d10 | 2017-01-09 16:02:28 +0200 | [diff] [blame] | 418 | static inline |
| 419 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
| 420 | const char *propname, |
Alexander Stein | b2987d7 | 2017-01-12 17:39:24 +0100 | [diff] [blame] | 421 | enum gpiod_flags dflags, |
| 422 | const char *label) |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 423 | { |
| 424 | return ERR_PTR(-ENOSYS); |
| 425 | } |
| 426 | |
Andy Shevchenko | a264d10 | 2017-01-09 16:02:28 +0200 | [diff] [blame] | 427 | static inline |
Boris Brezillon | 4b09479 | 2017-02-02 14:53:10 +0100 | [diff] [blame^] | 428 | struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, |
| 429 | const char *con_id, |
| 430 | struct fwnode_handle *child, |
| 431 | enum gpiod_flags flags, |
| 432 | const char *label) |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 433 | { |
| 434 | return ERR_PTR(-ENOSYS); |
| 435 | } |
| 436 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 437 | #endif /* CONFIG_GPIOLIB */ |
| 438 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 439 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 440 | |
| 441 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
| 442 | int gpiod_export_link(struct device *dev, const char *name, |
| 443 | struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 444 | void gpiod_unexport(struct gpio_desc *desc); |
| 445 | |
| 446 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 447 | |
| 448 | static inline int gpiod_export(struct gpio_desc *desc, |
| 449 | bool direction_may_change) |
| 450 | { |
| 451 | return -ENOSYS; |
| 452 | } |
| 453 | |
| 454 | static inline int gpiod_export_link(struct device *dev, const char *name, |
| 455 | struct gpio_desc *desc) |
| 456 | { |
| 457 | return -ENOSYS; |
| 458 | } |
| 459 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 460 | static inline void gpiod_unexport(struct gpio_desc *desc) |
| 461 | { |
| 462 | } |
| 463 | |
| 464 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 465 | |
| 466 | #endif |