Skip to content

Commit 3edfb7b

Browse files
ribaldalinusw
authored andcommitted
gpiolib: Show correct direction from the beginning
Current code assumes that the direction is input if direction_input function is set. This might not be the case on GPIOs with programmable direction. Signed-off-by: Ricardo Ribalda Delgado <[email protected]> Tested-by: Jeffrey Hugo <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 6f0ec09 commit 3edfb7b

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

drivers/gpio/gpiolib.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,20 +1351,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
13511351

13521352
spin_unlock_irqrestore(&gpio_lock, flags);
13531353

1354-
for (i = 0; i < chip->ngpio; i++) {
1355-
struct gpio_desc *desc = &gdev->descs[i];
1356-
1357-
desc->gdev = gdev;
1358-
1359-
/* REVISIT: most hardware initializes GPIOs as inputs (often
1360-
* with pullups enabled) so power usage is minimized. Linux
1361-
* code should set the gpio direction first thing; but until
1362-
* it does, and in case chip->get_direction is not set, we may
1363-
* expose the wrong direction in sysfs.
1364-
*/
1365-
desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0;
1366-
}
1367-
13681354
#ifdef CONFIG_PINCTRL
13691355
INIT_LIST_HEAD(&gdev->pin_ranges);
13701356
#endif
@@ -1393,6 +1379,19 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
13931379
if (status)
13941380
goto err_remove_chip;
13951381

1382+
for (i = 0; i < chip->ngpio; i++) {
1383+
struct gpio_desc *desc = &gdev->descs[i];
1384+
1385+
desc->gdev = gdev;
1386+
1387+
if (chip->get_direction && gpiochip_line_is_valid(chip, i))
1388+
desc->flags = !chip->get_direction(chip, i) ?
1389+
(1 << FLAG_IS_OUT) : 0;
1390+
else
1391+
desc->flags = !chip->direction_input ?
1392+
(1 << FLAG_IS_OUT) : 0;
1393+
}
1394+
13961395
acpi_gpiochip_add(chip);
13971396

13981397
machine_gpiochip_add(chip);

0 commit comments

Comments
 (0)