John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/gpio/devres.c - managed gpio resources |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 |
| 6 | * as published by the Free Software Foundation. |
| 7 | * |
| 8 | * You should have received a copy of the GNU General Public License |
| 9 | * along with this program; if not, write to the Free Software |
| 10 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 11 | * |
| 12 | * This file is based on kernel/irq/devres.c |
| 13 | * |
| 14 | * Copyright (c) 2011 John Crispin <blogic@openwrt.org> |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
Alexandre Courbot | 3c2c628 | 2013-10-20 15:14:58 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> |
Alexandre Courbot | 3c2c628 | 2013-10-20 15:14:58 -0700 | [diff] [blame] | 20 | #include <linux/gpio/consumer.h> |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 21 | #include <linux/device.h> |
| 22 | #include <linux/gfp.h> |
| 23 | |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 24 | static void devm_gpiod_release(struct device *dev, void *res) |
| 25 | { |
| 26 | struct gpio_desc **desc = res; |
| 27 | |
| 28 | gpiod_put(*desc); |
| 29 | } |
| 30 | |
| 31 | static int devm_gpiod_match(struct device *dev, void *res, void *data) |
| 32 | { |
| 33 | struct gpio_desc **this = res, **gpio = data; |
| 34 | |
| 35 | return *this == *gpio; |
| 36 | } |
| 37 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 38 | static void devm_gpiod_release_array(struct device *dev, void *res) |
| 39 | { |
| 40 | struct gpio_descs **descs = res; |
| 41 | |
| 42 | gpiod_put_array(*descs); |
| 43 | } |
| 44 | |
| 45 | static int devm_gpiod_match_array(struct device *dev, void *res, void *data) |
| 46 | { |
| 47 | struct gpio_descs **this = res, **gpios = data; |
| 48 | |
| 49 | return *this == *gpios; |
| 50 | } |
| 51 | |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 52 | /** |
| 53 | * devm_gpiod_get - Resource-managed gpiod_get() |
| 54 | * @dev: GPIO consumer |
| 55 | * @con_id: function within the GPIO consumer |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 56 | * @flags: optional GPIO initialization flags |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 57 | * |
| 58 | * Managed gpiod_get(). GPIO descriptors returned from this function are |
| 59 | * automatically disposed on driver detach. See gpiod_get() for detailed |
| 60 | * information about behavior and return values. |
| 61 | */ |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 62 | struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 63 | const char *con_id, |
| 64 | enum gpiod_flags flags) |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 65 | { |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 66 | return devm_gpiod_get_index(dev, con_id, 0, flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 67 | } |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 68 | EXPORT_SYMBOL(devm_gpiod_get); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 71 | * devm_gpiod_get_optional - Resource-managed gpiod_get_optional() |
| 72 | * @dev: GPIO consumer |
| 73 | * @con_id: function within the GPIO consumer |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 74 | * @flags: optional GPIO initialization flags |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 75 | * |
| 76 | * Managed gpiod_get_optional(). GPIO descriptors returned from this function |
| 77 | * are automatically disposed on driver detach. See gpiod_get_optional() for |
| 78 | * detailed information about behavior and return values. |
| 79 | */ |
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 | { |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 84 | return devm_gpiod_get_index_optional(dev, con_id, 0, flags); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 85 | } |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 86 | EXPORT_SYMBOL(devm_gpiod_get_optional); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 87 | |
| 88 | /** |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 89 | * devm_gpiod_get_index - Resource-managed gpiod_get_index() |
| 90 | * @dev: GPIO consumer |
| 91 | * @con_id: function within the GPIO consumer |
| 92 | * @idx: index of the GPIO to obtain in the consumer |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 93 | * @flags: optional GPIO initialization flags |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 94 | * |
| 95 | * Managed gpiod_get_index(). GPIO descriptors returned from this function are |
| 96 | * automatically disposed on driver detach. See gpiod_get_index() for detailed |
| 97 | * information about behavior and return values. |
| 98 | */ |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 99 | struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 100 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 101 | unsigned int idx, |
| 102 | enum gpiod_flags flags) |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 103 | { |
| 104 | struct gpio_desc **dr; |
| 105 | struct gpio_desc *desc; |
| 106 | |
Julia Lawall | 0f05a3a | 2014-07-29 17:16:48 +0200 | [diff] [blame] | 107 | dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 108 | GFP_KERNEL); |
| 109 | if (!dr) |
| 110 | return ERR_PTR(-ENOMEM); |
| 111 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 112 | desc = gpiod_get_index(dev, con_id, idx, flags); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 113 | if (IS_ERR(desc)) { |
| 114 | devres_free(dr); |
| 115 | return desc; |
| 116 | } |
| 117 | |
| 118 | *dr = desc; |
| 119 | devres_add(dev, dr); |
| 120 | |
Alexandre Courbot | 5fcdb9d | 2013-10-20 15:14:57 -0700 | [diff] [blame] | 121 | return desc; |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 122 | } |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 123 | EXPORT_SYMBOL(devm_gpiod_get_index); |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 126 | * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node |
| 127 | * @dev: GPIO consumer |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 128 | * @con_id: function within the GPIO consumer |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 129 | * @child: firmware node (child of @dev) |
| 130 | * |
| 131 | * GPIO descriptors returned from this function are automatically disposed on |
| 132 | * driver detach. |
| 133 | */ |
| 134 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 135 | const char *con_id, |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 136 | struct fwnode_handle *child) |
| 137 | { |
Linus Walleij | b620285 | 2015-03-11 12:21:17 +0100 | [diff] [blame] | 138 | static const char * const suffixes[] = { "gpios", "gpio" }; |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 139 | char prop_name[32]; /* 32 is max size of property name */ |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 140 | struct gpio_desc **dr; |
| 141 | struct gpio_desc *desc; |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 142 | unsigned int i; |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 143 | |
| 144 | dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), |
| 145 | GFP_KERNEL); |
| 146 | if (!dr) |
| 147 | return ERR_PTR(-ENOMEM); |
| 148 | |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 149 | for (i = 0; i < ARRAY_SIZE(suffixes); i++) { |
| 150 | if (con_id) |
| 151 | snprintf(prop_name, sizeof(prop_name), "%s-%s", |
| 152 | con_id, suffixes[i]); |
| 153 | else |
| 154 | snprintf(prop_name, sizeof(prop_name), "%s", |
| 155 | suffixes[i]); |
| 156 | |
| 157 | desc = fwnode_get_named_gpiod(child, prop_name); |
Geert Uytterhoeven | 40c8eab | 2016-02-19 11:00:50 +0100 | [diff] [blame] | 158 | if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) |
Olliver Schinagl | 1feb57a | 2015-01-21 22:33:46 +0100 | [diff] [blame] | 159 | break; |
| 160 | } |
Mika Westerberg | 40b7318 | 2014-10-21 13:33:59 +0200 | [diff] [blame] | 161 | if (IS_ERR(desc)) { |
| 162 | devres_free(dr); |
| 163 | return desc; |
| 164 | } |
| 165 | |
| 166 | *dr = desc; |
| 167 | devres_add(dev, dr); |
| 168 | |
| 169 | return desc; |
| 170 | } |
| 171 | EXPORT_SYMBOL(devm_get_gpiod_from_child); |
| 172 | |
| 173 | /** |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 174 | * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() |
| 175 | * @dev: GPIO consumer |
| 176 | * @con_id: function within the GPIO consumer |
| 177 | * @index: index of the GPIO to obtain in the consumer |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 178 | * @flags: optional GPIO initialization flags |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 179 | * |
| 180 | * Managed gpiod_get_index_optional(). GPIO descriptors returned from this |
| 181 | * function are automatically disposed on driver detach. See |
| 182 | * gpiod_get_index_optional() for detailed information about behavior and |
| 183 | * return values. |
| 184 | */ |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 185 | struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 186 | const char *con_id, |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 187 | unsigned int index, |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 188 | enum gpiod_flags flags) |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 189 | { |
| 190 | struct gpio_desc *desc; |
| 191 | |
Alexandre Courbot | 39b2bbe | 2014-07-25 23:38:36 +0900 | [diff] [blame] | 192 | desc = devm_gpiod_get_index(dev, con_id, index, flags); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 193 | if (IS_ERR(desc)) { |
| 194 | if (PTR_ERR(desc) == -ENOENT) |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | return desc; |
| 199 | } |
Uwe Kleine-König | b17d1bf | 2015-02-11 11:52:37 +0100 | [diff] [blame] | 200 | EXPORT_SYMBOL(devm_gpiod_get_index_optional); |
Thierry Reding | 29a1f233 | 2014-04-25 17:10:06 +0200 | [diff] [blame] | 201 | |
| 202 | /** |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 203 | * devm_gpiod_get_array - Resource-managed gpiod_get_array() |
| 204 | * @dev: GPIO consumer |
| 205 | * @con_id: function within the GPIO consumer |
| 206 | * @flags: optional GPIO initialization flags |
| 207 | * |
| 208 | * Managed gpiod_get_array(). GPIO descriptors returned from this function are |
| 209 | * automatically disposed on driver detach. See gpiod_get_array() for detailed |
| 210 | * information about behavior and return values. |
| 211 | */ |
| 212 | struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, |
| 213 | const char *con_id, |
| 214 | enum gpiod_flags flags) |
| 215 | { |
| 216 | struct gpio_descs **dr; |
| 217 | struct gpio_descs *descs; |
| 218 | |
| 219 | dr = devres_alloc(devm_gpiod_release_array, |
| 220 | sizeof(struct gpio_descs *), GFP_KERNEL); |
| 221 | if (!dr) |
| 222 | return ERR_PTR(-ENOMEM); |
| 223 | |
| 224 | descs = gpiod_get_array(dev, con_id, flags); |
| 225 | if (IS_ERR(descs)) { |
| 226 | devres_free(dr); |
| 227 | return descs; |
| 228 | } |
| 229 | |
| 230 | *dr = descs; |
| 231 | devres_add(dev, dr); |
| 232 | |
| 233 | return descs; |
| 234 | } |
| 235 | EXPORT_SYMBOL(devm_gpiod_get_array); |
| 236 | |
| 237 | /** |
| 238 | * devm_gpiod_get_array_optional - Resource-managed gpiod_get_array_optional() |
| 239 | * @dev: GPIO consumer |
| 240 | * @con_id: function within the GPIO consumer |
| 241 | * @flags: optional GPIO initialization flags |
| 242 | * |
| 243 | * Managed gpiod_get_array_optional(). GPIO descriptors returned from this |
| 244 | * function are automatically disposed on driver detach. |
| 245 | * See gpiod_get_array_optional() for detailed information about behavior and |
| 246 | * return values. |
| 247 | */ |
| 248 | struct gpio_descs *__must_check |
| 249 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, |
| 250 | enum gpiod_flags flags) |
| 251 | { |
| 252 | struct gpio_descs *descs; |
| 253 | |
| 254 | descs = devm_gpiod_get_array(dev, con_id, flags); |
| 255 | if (IS_ERR(descs) && (PTR_ERR(descs) == -ENOENT)) |
| 256 | return NULL; |
| 257 | |
| 258 | return descs; |
| 259 | } |
| 260 | EXPORT_SYMBOL(devm_gpiod_get_array_optional); |
| 261 | |
| 262 | /** |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 263 | * devm_gpiod_put - Resource-managed gpiod_put() |
| 264 | * @desc: GPIO descriptor to dispose of |
| 265 | * |
| 266 | * Dispose of a GPIO descriptor obtained with devm_gpiod_get() or |
| 267 | * devm_gpiod_get_index(). Normally this function will not be called as the GPIO |
| 268 | * will be disposed of by the resource management code. |
| 269 | */ |
| 270 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
| 271 | { |
| 272 | WARN_ON(devres_release(dev, devm_gpiod_release, devm_gpiod_match, |
| 273 | &desc)); |
| 274 | } |
| 275 | EXPORT_SYMBOL(devm_gpiod_put); |
| 276 | |
Rojhalat Ibrahim | 331758e | 2015-02-11 17:28:02 +0100 | [diff] [blame] | 277 | /** |
| 278 | * devm_gpiod_put_array - Resource-managed gpiod_put_array() |
| 279 | * @descs: GPIO descriptor array to dispose of |
| 280 | * |
| 281 | * Dispose of an array of GPIO descriptors obtained with devm_gpiod_get_array(). |
| 282 | * Normally this function will not be called as the GPIOs will be disposed of |
| 283 | * by the resource management code. |
| 284 | */ |
| 285 | void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs) |
| 286 | { |
| 287 | WARN_ON(devres_release(dev, devm_gpiod_release_array, |
| 288 | devm_gpiod_match_array, &descs)); |
| 289 | } |
| 290 | EXPORT_SYMBOL(devm_gpiod_put_array); |
| 291 | |
Alexandre Courbot | bae48da | 2013-10-17 10:21:38 -0700 | [diff] [blame] | 292 | |
| 293 | |
| 294 | |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 295 | static void devm_gpio_release(struct device *dev, void *res) |
| 296 | { |
| 297 | unsigned *gpio = res; |
| 298 | |
| 299 | gpio_free(*gpio); |
| 300 | } |
| 301 | |
| 302 | static int devm_gpio_match(struct device *dev, void *res, void *data) |
| 303 | { |
| 304 | unsigned *this = res, *gpio = data; |
| 305 | |
| 306 | return *this == *gpio; |
| 307 | } |
| 308 | |
| 309 | /** |
Wolfram Sang | 713b7ef | 2013-06-04 17:48:36 +0200 | [diff] [blame] | 310 | * devm_gpio_request - request a GPIO for a managed device |
| 311 | * @dev: device to request the GPIO for |
| 312 | * @gpio: GPIO to allocate |
| 313 | * @label: the name of the requested GPIO |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 314 | * |
| 315 | * Except for the extra @dev argument, this function takes the |
| 316 | * same arguments and performs the same function as |
| 317 | * gpio_request(). GPIOs requested with this function will be |
| 318 | * automatically freed on driver detach. |
| 319 | * |
| 320 | * If an GPIO allocated with this function needs to be freed |
| 321 | * separately, devm_gpio_free() must be used. |
| 322 | */ |
| 323 | |
| 324 | int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) |
| 325 | { |
| 326 | unsigned *dr; |
| 327 | int rc; |
| 328 | |
| 329 | dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); |
| 330 | if (!dr) |
| 331 | return -ENOMEM; |
| 332 | |
| 333 | rc = gpio_request(gpio, label); |
| 334 | if (rc) { |
| 335 | devres_free(dr); |
| 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | *dr = gpio; |
| 340 | devres_add(dev, dr); |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | EXPORT_SYMBOL(devm_gpio_request); |
| 345 | |
| 346 | /** |
Mark Brown | 09d71ff | 2012-05-02 12:46:46 +0100 | [diff] [blame] | 347 | * devm_gpio_request_one - request a single GPIO with initial setup |
| 348 | * @dev: device to request for |
| 349 | * @gpio: the GPIO number |
| 350 | * @flags: GPIO configuration as specified by GPIOF_* |
| 351 | * @label: a literal description string of this GPIO |
| 352 | */ |
| 353 | int devm_gpio_request_one(struct device *dev, unsigned gpio, |
| 354 | unsigned long flags, const char *label) |
| 355 | { |
| 356 | unsigned *dr; |
| 357 | int rc; |
| 358 | |
| 359 | dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); |
| 360 | if (!dr) |
| 361 | return -ENOMEM; |
| 362 | |
| 363 | rc = gpio_request_one(gpio, flags, label); |
| 364 | if (rc) { |
| 365 | devres_free(dr); |
| 366 | return rc; |
| 367 | } |
| 368 | |
| 369 | *dr = gpio; |
| 370 | devres_add(dev, dr); |
| 371 | |
| 372 | return 0; |
| 373 | } |
Stephen Warren | 3996bfc | 2012-06-07 17:56:09 -0600 | [diff] [blame] | 374 | EXPORT_SYMBOL(devm_gpio_request_one); |
Mark Brown | 09d71ff | 2012-05-02 12:46:46 +0100 | [diff] [blame] | 375 | |
| 376 | /** |
Wolfram Sang | 713b7ef | 2013-06-04 17:48:36 +0200 | [diff] [blame] | 377 | * devm_gpio_free - free a GPIO |
| 378 | * @dev: device to free GPIO for |
| 379 | * @gpio: GPIO to free |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 380 | * |
| 381 | * Except for the extra @dev argument, this function takes the |
| 382 | * same arguments and performs the same function as gpio_free(). |
| 383 | * This function instead of gpio_free() should be used to manually |
| 384 | * free GPIOs allocated with devm_gpio_request(). |
| 385 | */ |
| 386 | void devm_gpio_free(struct device *dev, unsigned int gpio) |
| 387 | { |
| 388 | |
Mark Brown | a85990b | 2012-05-03 18:15:14 +0100 | [diff] [blame] | 389 | WARN_ON(devres_release(dev, devm_gpio_release, devm_gpio_match, |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 390 | &gpio)); |
John Crispin | 1a0703e | 2011-12-20 21:40:21 +0100 | [diff] [blame] | 391 | } |
| 392 | EXPORT_SYMBOL(devm_gpio_free); |