@@ -226,6 +226,12 @@ int gpiod_get_direction(struct gpio_desc *desc)
ret = chip->get_direction(chip, offset);
if (ret > 0) {
/* GPIOF_DIR_IN, or other positive */
+ if (ret != GPIO_LINE_DIRECTION_IN) {
+ struct gpio_device *gdev = chip->gpiodev;
+
+ dev_warn(&gdev->dev,
+ "drivers should use GPIO_LINE_DIRECTION_IN\n");
+ }
ret = 1;
clear_bit(FLAG_IS_OUT, &desc->flags);
}
@@ -1389,12 +1395,18 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
for (i = 0; i < chip->ngpio; i++) {
struct gpio_desc *desc = &gdev->descs[i];
+ int dir;
if (chip->get_direction && gpiochip_line_is_valid(chip, i)) {
- if (!chip->get_direction(chip, i))
+ dir = chip->get_direction(chip, i);
+ if (!dir) {
set_bit(FLAG_IS_OUT, &desc->flags);
- else
+ } else {
+ if (dir != GPIO_LINE_DIRECTION_IN)
+ dev_warn(&gdev->dev,
+ "drivers should use GPIO_LINE_DIRECTION_IN\n");
clear_bit(FLAG_IS_OUT, &desc->flags);
+ }
} else {
if (!chip->direction_input)
set_bit(FLAG_IS_OUT, &desc->flags);
It seems that bunch of drivers put some effort (namely use !! or ! when converting GPIO direction register value to direction) to only return 1 or 0 for direction INPUT/UOTPUT. Others do just return any positive value they happen to read from register for INPUT. Let's try iron out this habit by nagging if our cool new definitions GPIO_LINE_DIRECTION_IN and GPIO_LINE_DIRECTION_OUT are not used. Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> --- drivers/gpio/gpiolib.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)