Skip to content

Commit

Permalink
gpiolib: request the gpio before querying its direction
Browse files Browse the repository at this point in the history
Before querying a GPIO to determine its direction, the GPIO should be
formally requested.  This allows the GPIO driver to block access to
unavailable GPIOs, which makes it easier for some drivers to support
sparse GPIO maps.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Timur Tabi authored and Linus Walleij committed Aug 14, 2017
1 parent b2dc411 commit 108d23e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,14 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
struct gpio_desc *desc = &gdev->descs[i];

desc->gdev = gdev;

if (chip->request) {
status = chip->request(chip, i);
if (status < 0)
/* The GPIO is unavailable, so skip it */
continue;
}

/*
* REVISIT: most hardware initializes GPIOs as inputs
* (often with pullups enabled) so power usage is
Expand All @@ -1226,6 +1234,9 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
*/
set_bit(FLAG_IS_OUT, &desc->flags);
}

if (chip->free)
chip->free(chip, i);
}

#ifdef CONFIG_PINCTRL
Expand Down

0 comments on commit 108d23e

Please sign in to comment.