Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 2 | #ifndef __LINUX_GPIO_CONSUMER_H |
| 3 | #define __LINUX_GPIO_CONSUMER_H |
| 4 | |
Arnd Bergmann | cdf86cd2 | 2014-05-08 15:42:25 +0200 | [diff] [blame] | 5 | #include <linux/bug.h> |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 6 | #include <linux/err.h> |
| 7 | #include <linux/kernel.h> |
| 8 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 9 | struct device; |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 10 | |
| 11 | /** |
| 12 | * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are |
| 13 | * preferable to the old integer-based handles. |
| 14 | * |
| 15 | * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid |
| 16 | * until the GPIO is released. |
| 17 | */ |
| 18 | struct gpio_desc; |
| 19 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 20 | /** |
| 21 | * Struct containing an array of descriptors that can be obtained using |
| 22 | * gpiod_get_array(). |
| 23 | */ |
| 24 | struct gpio_descs { |
| 25 | unsigned int ndescs; |
| 26 | struct gpio_desc *desc[]; |
| 27 | }; |
| 28 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 29 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
| 30 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
| 31 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
Linus Walleij | f926dfc | 2017-09-10 19:26:22 +0200 | [diff] [blame] | 32 | #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Optional flags that can be passed to one of gpiod_* to configure direction |
| 36 | * and output value. These values cannot be OR'd. |
| 37 | */ |
| 38 | enum gpiod_flags { |
| 39 | GPIOD_ASIS = 0, |
| 40 | GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, |
| 41 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, |
| 42 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
| 43 | GPIOD_FLAGS_BIT_DIR_VAL, |
Andy Shevchenko | 0969a20 | 2018-07-27 17:47:01 +0300 | [diff] [blame] | 44 | GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
| 45 | GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 46 | }; |
| 47 | |
Linus Walleij | 58b84f6 | 2014-08-19 12:00:53 -0500 | [diff] [blame] | 48 | #ifdef CONFIG_GPIOLIB |
| 49 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 50 | /* Return the number of GPIOs associated with a device / function */ |
| 51 | int gpiod_count(struct device *dev, const char *con_id); |
| 52 | |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 53 | /* Acquire and dispose GPIOs */ |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 54 | struct gpio_desc *__must_check gpiod_get(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 55 | const char *con_id, |
| 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_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 58 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 59 | unsigned int idx, |
| 60 | enum gpiod_flags flags); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 61 | struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 62 | const char *con_id, |
| 63 | enum gpiod_flags flags); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 64 | struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 65 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 66 | unsigned int index, |
| 67 | enum gpiod_flags flags); |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 68 | struct gpio_descs *__must_check gpiod_get_array(struct device *dev, |
| 69 | const char *con_id, |
| 70 | enum gpiod_flags flags); |
| 71 | struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, |
| 72 | const char *con_id, |
| 73 | enum gpiod_flags flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 74 | void gpiod_put(struct gpio_desc *desc); |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 75 | void gpiod_put_array(struct gpio_descs *descs); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 76 | |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 77 | struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 78 | const char *con_id, |
| 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_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 81 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 82 | unsigned int idx, |
| 83 | enum gpiod_flags flags); |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 84 | struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 85 | const char *con_id, |
| 86 | enum gpiod_flags flags); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 87 | struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 88 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 89 | unsigned int index, enum gpiod_flags flags); |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 90 | struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, |
| 91 | const char *con_id, |
| 92 | enum gpiod_flags flags); |
| 93 | struct gpio_descs *__must_check |
| 94 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 95 | enum gpiod_flags flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 96 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 97 | void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 98 | |
Alexandre Courbot | 8e53b0f | 2014-11-25 17:16:31 +0900 | [diff] [blame] | 99 | int gpiod_get_direction(struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 100 | int gpiod_direction_input(struct gpio_desc *desc); |
| 101 | int gpiod_direction_output(struct gpio_desc *desc, int value); |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 102 | int gpiod_direction_output_raw(struct gpio_desc *desc, int value); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* Value get/set from non-sleeping context */ |
| 105 | int gpiod_get_value(const struct gpio_desc *desc); |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 106 | int gpiod_get_array_value(unsigned int array_size, |
| 107 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 108 | void gpiod_set_value(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 109 | void gpiod_set_array_value(unsigned int array_size, |
| 110 | struct gpio_desc **desc_array, int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 111 | int gpiod_get_raw_value(const struct gpio_desc *desc); |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 112 | int gpiod_get_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 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 116 | int gpiod_set_raw_array_value(unsigned int array_size, |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 117 | struct gpio_desc **desc_array, |
| 118 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* Value get/set from sleeping context */ |
| 121 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 122 | int gpiod_get_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 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 126 | void gpiod_set_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 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 130 | int gpiod_get_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 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 134 | int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 135 | struct gpio_desc **desc_array, |
| 136 | int *value_array); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 137 | |
| 138 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); |
Andrew Jeffery | e10f72b | 2017-11-30 14:25:24 +1030 | [diff] [blame] | 139 | int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 140 | |
| 141 | int gpiod_is_active_low(const struct gpio_desc *desc); |
| 142 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 143 | |
| 144 | int gpiod_to_irq(const struct gpio_desc *desc); |
Linus Walleij | 90b3940 | 2018-06-01 13:21:27 +0200 | [diff] [blame] | 145 | void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 146 | |
| 147 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 148 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| 149 | int desc_to_gpio(const struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 150 | |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 151 | /* Child properties interface */ |
Linus Walleij | 92542ed | 2017-12-29 22:52:02 +0100 | [diff] [blame] | 152 | struct device_node; |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 153 | struct fwnode_handle; |
| 154 | |
Linus Walleij | 92542ed | 2017-12-29 22:52:02 +0100 | [diff] [blame] | 155 | struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, |
| 156 | struct device_node *node, |
| 157 | const char *propname, int index, |
| 158 | enum gpiod_flags dflags, |
| 159 | const char *label); |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 160 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
Boris Brezillon | 537b94d | 2017-02-02 14:53:11 +0100 | [diff] [blame] | 161 | const char *propname, int index, |
Alexander Stein | b2987d7 | 2017-01-12 17:39:24 +0100 | [diff] [blame] | 162 | enum gpiod_flags dflags, |
| 163 | const char *label); |
Boris Brezillon | 537b94d | 2017-02-02 14:53:11 +0100 | [diff] [blame] | 164 | struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, |
| 165 | const char *con_id, int index, |
| 166 | struct fwnode_handle *child, |
| 167 | enum gpiod_flags flags, |
| 168 | const char *label); |
Linus Walleij | 3498d86 | 2017-02-21 14:19:45 +0100 | [diff] [blame] | 169 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 170 | #else /* CONFIG_GPIOLIB */ |
| 171 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 172 | static inline int gpiod_count(struct device *dev, const char *con_id) |
| 173 | { |
| 174 | return 0; |
| 175 | } |
| 176 | |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 177 | static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, |
| 178 | const char *con_id, |
| 179 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 180 | { |
| 181 | return ERR_PTR(-ENOSYS); |
| 182 | } |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 183 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 184 | gpiod_get_index(struct device *dev, |
| 185 | const char *con_id, |
| 186 | unsigned int idx, |
| 187 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 188 | { |
| 189 | return ERR_PTR(-ENOSYS); |
| 190 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 191 | |
| 192 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 193 | gpiod_get_optional(struct device *dev, const char *con_id, |
| 194 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 195 | { |
Dmitry Torokhov | 22c4036 | 2017-02-12 17:13:55 -0800 | [diff] [blame] | 196 | return NULL; |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 200 | gpiod_get_index_optional(struct device *dev, const char *con_id, |
| 201 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 202 | { |
Dmitry Torokhov | 22c4036 | 2017-02-12 17:13:55 -0800 | [diff] [blame] | 203 | return NULL; |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 206 | static inline struct gpio_descs *__must_check |
| 207 | gpiod_get_array(struct device *dev, const char *con_id, |
| 208 | enum gpiod_flags flags) |
| 209 | { |
| 210 | return ERR_PTR(-ENOSYS); |
| 211 | } |
| 212 | |
| 213 | static inline struct gpio_descs *__must_check |
| 214 | gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 215 | enum gpiod_flags flags) |
| 216 | { |
Dmitry Torokhov | 22c4036 | 2017-02-12 17:13:55 -0800 | [diff] [blame] | 217 | return NULL; |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 220 | static inline void gpiod_put(struct gpio_desc *desc) |
| 221 | { |
| 222 | might_sleep(); |
| 223 | |
| 224 | /* GPIO can never have been requested */ |
| 225 | WARN_ON(1); |
| 226 | } |
| 227 | |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 228 | static inline void gpiod_put_array(struct gpio_descs *descs) |
| 229 | { |
| 230 | might_sleep(); |
| 231 | |
| 232 | /* GPIO can never have been requested */ |
| 233 | WARN_ON(1); |
| 234 | } |
| 235 | |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 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(struct device *dev, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 238 | const char *con_id, |
| 239 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 240 | { |
| 241 | return ERR_PTR(-ENOSYS); |
| 242 | } |
| 243 | static inline |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 244 | struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 245 | devm_gpiod_get_index(struct device *dev, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 246 | const char *con_id, |
| 247 | unsigned int idx, |
| 248 | enum gpiod_flags flags) |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 249 | { |
| 250 | return ERR_PTR(-ENOSYS); |
| 251 | } |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 252 | |
| 253 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 254 | devm_gpiod_get_optional(struct device *dev, const char *con_id, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 255 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 256 | { |
Dmitry Torokhov | 22c4036 | 2017-02-12 17:13:55 -0800 | [diff] [blame] | 257 | return NULL; |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static inline struct gpio_desc *__must_check |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 261 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
Linus Walleij | 0dbc8b7 | 2014-09-01 15:15:40 +0200 | [diff] [blame] | 262 | unsigned int index, enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 263 | { |
Dmitry Torokhov | 22c4036 | 2017-02-12 17:13:55 -0800 | [diff] [blame] | 264 | return NULL; |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 265 | } |
| 266 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 267 | static inline struct gpio_descs *__must_check |
| 268 | devm_gpiod_get_array(struct device *dev, const char *con_id, |
| 269 | enum gpiod_flags flags) |
| 270 | { |
| 271 | return ERR_PTR(-ENOSYS); |
| 272 | } |
| 273 | |
| 274 | static inline struct gpio_descs *__must_check |
| 275 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 276 | enum gpiod_flags flags) |
| 277 | { |
Dmitry Torokhov | 22c4036 | 2017-02-12 17:13:55 -0800 | [diff] [blame] | 278 | return NULL; |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 281 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 282 | { |
| 283 | might_sleep(); |
| 284 | |
| 285 | /* GPIO can never have been requested */ |
| 286 | WARN_ON(1); |
| 287 | } |
| 288 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 289 | static inline void devm_gpiod_put_array(struct device *dev, |
| 290 | struct gpio_descs *descs) |
| 291 | { |
| 292 | might_sleep(); |
| 293 | |
| 294 | /* GPIO can never have been requested */ |
| 295 | WARN_ON(1); |
| 296 | } |
| 297 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 298 | |
| 299 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 300 | { |
| 301 | /* GPIO can never have been requested */ |
| 302 | WARN_ON(1); |
| 303 | return -ENOSYS; |
| 304 | } |
| 305 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 306 | { |
| 307 | /* GPIO can never have been requested */ |
| 308 | WARN_ON(1); |
| 309 | return -ENOSYS; |
| 310 | } |
| 311 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 312 | { |
| 313 | /* GPIO can never have been requested */ |
| 314 | WARN_ON(1); |
| 315 | return -ENOSYS; |
| 316 | } |
Philipp Zabel | ef70bbe | 2014-01-07 12:34:11 +0100 | [diff] [blame] | 317 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 318 | { |
| 319 | /* GPIO can never have been requested */ |
| 320 | WARN_ON(1); |
| 321 | return -ENOSYS; |
| 322 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 323 | |
| 324 | |
| 325 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 326 | { |
| 327 | /* GPIO can never have been requested */ |
| 328 | WARN_ON(1); |
| 329 | return 0; |
| 330 | } |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 331 | static inline int gpiod_get_array_value(unsigned int array_size, |
| 332 | struct gpio_desc **desc_array, |
| 333 | int *value_array) |
| 334 | { |
| 335 | /* GPIO can never have been requested */ |
| 336 | WARN_ON(1); |
| 337 | return 0; |
| 338 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 339 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 340 | { |
| 341 | /* GPIO can never have been requested */ |
| 342 | WARN_ON(1); |
| 343 | } |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 344 | static inline void gpiod_set_array_value(unsigned int array_size, |
| 345 | struct gpio_desc **desc_array, |
| 346 | int *value_array) |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 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(const struct gpio_desc *desc) |
| 352 | { |
| 353 | /* GPIO can never have been requested */ |
| 354 | WARN_ON(1); |
| 355 | return 0; |
| 356 | } |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 357 | static inline int gpiod_get_raw_array_value(unsigned int array_size, |
| 358 | struct gpio_desc **desc_array, |
| 359 | int *value_array) |
| 360 | { |
| 361 | /* GPIO can never have been requested */ |
| 362 | WARN_ON(1); |
| 363 | return 0; |
| 364 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 365 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 366 | { |
| 367 | /* GPIO can never have been requested */ |
| 368 | WARN_ON(1); |
| 369 | } |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 370 | static inline int gpiod_set_raw_array_value(unsigned int array_size, |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 371 | struct gpio_desc **desc_array, |
| 372 | int *value_array) |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 373 | { |
| 374 | /* GPIO can never have been requested */ |
| 375 | WARN_ON(1); |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 376 | return 0; |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 377 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 378 | |
| 379 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 380 | { |
| 381 | /* GPIO can never have been requested */ |
| 382 | WARN_ON(1); |
| 383 | return 0; |
| 384 | } |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 385 | static inline int gpiod_get_array_value_cansleep(unsigned int array_size, |
| 386 | struct gpio_desc **desc_array, |
| 387 | int *value_array) |
| 388 | { |
| 389 | /* GPIO can never have been requested */ |
| 390 | WARN_ON(1); |
| 391 | return 0; |
| 392 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 393 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 394 | { |
| 395 | /* GPIO can never have been requested */ |
| 396 | WARN_ON(1); |
| 397 | } |
Rojhalat Ibrahim | 3fff99b | 2015-05-13 11:04:56 +0200 | [diff] [blame] | 398 | static inline void gpiod_set_array_value_cansleep(unsigned int array_size, |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 399 | struct gpio_desc **desc_array, |
| 400 | int *value_array) |
| 401 | { |
| 402 | /* GPIO can never have been requested */ |
| 403 | WARN_ON(1); |
| 404 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 405 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 406 | { |
| 407 | /* GPIO can never have been requested */ |
| 408 | WARN_ON(1); |
| 409 | return 0; |
| 410 | } |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 411 | static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, |
| 412 | struct gpio_desc **desc_array, |
| 413 | int *value_array) |
| 414 | { |
| 415 | /* GPIO can never have been requested */ |
| 416 | WARN_ON(1); |
| 417 | return 0; |
| 418 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 419 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 420 | int value) |
| 421 | { |
| 422 | /* GPIO can never have been requested */ |
| 423 | WARN_ON(1); |
| 424 | } |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 425 | static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 426 | struct gpio_desc **desc_array, |
| 427 | int *value_array) |
| 428 | { |
| 429 | /* GPIO can never have been requested */ |
| 430 | WARN_ON(1); |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 431 | return 0; |
Rojhalat Ibrahim | 5f42424 | 2014-11-04 17:12:06 +0100 | [diff] [blame] | 432 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 433 | |
| 434 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 435 | { |
| 436 | /* GPIO can never have been requested */ |
| 437 | WARN_ON(1); |
| 438 | return -ENOSYS; |
| 439 | } |
| 440 | |
Andrew Jeffery | e10f72b | 2017-11-30 14:25:24 +1030 | [diff] [blame] | 441 | static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) |
| 442 | { |
| 443 | /* GPIO can never have been requested */ |
| 444 | WARN_ON(1); |
| 445 | return -ENOSYS; |
| 446 | } |
| 447 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 448 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 449 | { |
| 450 | /* GPIO can never have been requested */ |
| 451 | WARN_ON(1); |
| 452 | return 0; |
| 453 | } |
| 454 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 455 | { |
| 456 | /* GPIO can never have been requested */ |
| 457 | WARN_ON(1); |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 462 | { |
| 463 | /* GPIO can never have been requested */ |
| 464 | WARN_ON(1); |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | |
Linus Walleij | 90b3940 | 2018-06-01 13:21:27 +0200 | [diff] [blame] | 468 | static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) |
| 469 | { |
| 470 | /* GPIO can never have been requested */ |
| 471 | WARN_ON(1); |
| 472 | } |
| 473 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 474 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 475 | { |
| 476 | return ERR_PTR(-EINVAL); |
| 477 | } |
Markus Pargmann | c0017ed | 2015-08-14 16:10:59 +0200 | [diff] [blame] | 478 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 479 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 480 | { |
| 481 | /* GPIO can never have been requested */ |
| 482 | WARN_ON(1); |
| 483 | return -EINVAL; |
| 484 | } |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 485 | |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 486 | /* Child properties interface */ |
Linus Walleij | 92542ed | 2017-12-29 22:52:02 +0100 | [diff] [blame] | 487 | struct device_node; |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 488 | struct fwnode_handle; |
| 489 | |
Andy Shevchenko | a264d10 | 2017-01-09 16:02:28 +0200 | [diff] [blame] | 490 | static inline |
Linus Walleij | 92542ed | 2017-12-29 22:52:02 +0100 | [diff] [blame] | 491 | struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, |
| 492 | struct device_node *node, |
| 493 | const char *propname, int index, |
| 494 | enum gpiod_flags dflags, |
| 495 | const char *label) |
| 496 | { |
| 497 | return ERR_PTR(-ENOSYS); |
| 498 | } |
| 499 | |
| 500 | static inline |
Andy Shevchenko | a264d10 | 2017-01-09 16:02:28 +0200 | [diff] [blame] | 501 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
Boris Brezillon | 537b94d | 2017-02-02 14:53:11 +0100 | [diff] [blame] | 502 | const char *propname, int index, |
Alexander Stein | b2987d7 | 2017-01-12 17:39:24 +0100 | [diff] [blame] | 503 | enum gpiod_flags dflags, |
| 504 | const char *label) |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 505 | { |
| 506 | return ERR_PTR(-ENOSYS); |
| 507 | } |
| 508 | |
Andy Shevchenko | a264d10 | 2017-01-09 16:02:28 +0200 | [diff] [blame] | 509 | static inline |
Boris Brezillon | 537b94d | 2017-02-02 14:53:11 +0100 | [diff] [blame] | 510 | struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, |
| 511 | const char *con_id, int index, |
| 512 | struct fwnode_handle *child, |
| 513 | enum gpiod_flags flags, |
| 514 | const char *label) |
| 515 | { |
| 516 | return ERR_PTR(-ENOSYS); |
| 517 | } |
| 518 | |
| 519 | #endif /* CONFIG_GPIOLIB */ |
| 520 | |
| 521 | static inline |
Boris Brezillon | 4b09479 | 2017-02-02 14:53:10 +0100 | [diff] [blame] | 522 | struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, |
| 523 | const char *con_id, |
| 524 | struct fwnode_handle *child, |
| 525 | enum gpiod_flags flags, |
| 526 | const char *label) |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 527 | { |
Boris Brezillon | 537b94d | 2017-02-02 14:53:11 +0100 | [diff] [blame] | 528 | return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child, |
| 529 | flags, label); |
Geert Uytterhoeven | 496e7ce | 2015-05-07 01:08:08 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 532 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
| 533 | |
| 534 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
| 535 | int gpiod_export_link(struct device *dev, const char *name, |
| 536 | struct gpio_desc *desc); |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 537 | void gpiod_unexport(struct gpio_desc *desc); |
| 538 | |
| 539 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 540 | |
| 541 | static inline int gpiod_export(struct gpio_desc *desc, |
| 542 | bool direction_may_change) |
| 543 | { |
| 544 | return -ENOSYS; |
| 545 | } |
| 546 | |
| 547 | static inline int gpiod_export_link(struct device *dev, const char *name, |
| 548 | struct gpio_desc *desc) |
| 549 | { |
| 550 | return -ENOSYS; |
| 551 | } |
| 552 | |
Alexandre Courbot | 79a9bec | 2013-10-17 10:21:36 -0700 | [diff] [blame] | 553 | static inline void gpiod_unexport(struct gpio_desc *desc) |
| 554 | { |
| 555 | } |
| 556 | |
| 557 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
| 558 | |
| 559 | #endif |