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