gpio: Add helpers for optional GPIOs
authorThierry Reding <treding@nvidia.com>
Fri, 25 Apr 2014 15:10:06 +0000 (17:10 +0200)
committerSimon Horman <horms+renesas@verge.net.au>
Fri, 5 Dec 2014 04:19:24 +0000 (13:19 +0900)
commit43fd7b19845667fb66cc7f80641c1387c5b1494e
tree2ca5b8b9e51b17b44062b5743776e0fcc3a36b65
parent8cff9030fe1f67bc76af0ce624c837b1d83ca740
gpio: Add helpers for optional GPIOs

Introduce gpiod_get_optional() and gpiod_get_index_optional() helpers
that make it easier for drivers to handle optional GPIOs.

Currently in order to handle optional GPIOs, a driver needs to special
case error handling for -ENOENT, such as this:

gpio = gpiod_get(dev, "foo");
if (IS_ERR(gpio)) {
if (PTR_ERR(gpio) != -ENOENT)
return PTR_ERR(gpio);

gpio = NULL;
}

if (gpio) {
/* set up GPIO */
}

With these new helpers the above is reduced to:

gpio = gpiod_get_optional(dev, "foo");
if (IS_ERR(gpio))
return PTR_ERR(gpio);

if (gpio) {
/* set up GPIO */
}

While at it, device-managed variants of these functions are also
provided.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
(cherry picked from commit 29a1f2333e07bbbecb920cc78fd035fe8f53207a)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Documentation/driver-model/devres.txt
drivers/gpio/devres.c
drivers/gpio/gpiolib.c
include/linux/gpio/consumer.h