Skip to content

Commit 108d23e

Browse files
Timur Tabilinusw
authored andcommitted
gpiolib: request the gpio before querying its direction
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 <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent b2dc411 commit 108d23e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,14 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
12011201
struct gpio_desc *desc = &gdev->descs[i];
12021202

12031203
desc->gdev = gdev;
1204+
1205+
if (chip->request) {
1206+
status = chip->request(chip, i);
1207+
if (status < 0)
1208+
/* The GPIO is unavailable, so skip it */
1209+
continue;
1210+
}
1211+
12041212
/*
12051213
* REVISIT: most hardware initializes GPIOs as inputs
12061214
* (often with pullups enabled) so power usage is
@@ -1226,6 +1234,9 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
12261234
*/
12271235
set_bit(FLAG_IS_OUT, &desc->flags);
12281236
}
1237+
1238+
if (chip->free)
1239+
chip->free(chip, i);
12291240
}
12301241

12311242
#ifdef CONFIG_PINCTRL

0 commit comments

Comments
 (0)