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