[PATCH] gpio: viperboard: implement .get_direction()

From: YuanZhe Liu

Date: Sat Dec 05 2026 - 11:53:03 EST


The GPIO core warns in gpiochip_get_direction() when a user reads the
direction of an exported line and the chip does not provide the
.get_direction() callback:

WARNING: CPU: 0 PID: 3996 at drivers/gpio/gpiolib.c:431
gpiochip_get_direction
gpiod_get_direction
direction_show
dev_attr_show
sysfs_kf_seq_show

Reading the direction of an exported line is a normal operation, so it
must not emit a warning.

The viperboard driver already tracks the direction of every line in the
gpioa_out and gpiob_out bitmaps and its get() callbacks use them to tell
input from output lines. Report the tracked direction through
.get_direction() for both chips.

Fixes: 471e998c0e31 ("gpiolib: remove redundant callback check")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/gpio/gpio-viperboard.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c
index b8d6dff5b663..432071a25383 100644
--- a/drivers/gpio/gpio-viperboard.c
+++ b/drivers/gpio/gpio-viperboard.c
@@ -252,6 +252,15 @@ static int vprbrd_gpioa_direction_output(struct gpio_chip *chip,
return 0;
}

+static int vprbrd_gpioa_get_direction(struct gpio_chip *chip,
+ unsigned int offset)
+{
+ struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
+
+ return (gpio->gpioa_out & (1 << offset)) ? GPIO_LINE_DIRECTION_OUT :
+ GPIO_LINE_DIRECTION_IN;
+}
+
/* ----- end of gpio a chip ---------------------------------------------- */

/* ----- begin of gipo b chip -------------------------------------------- */
@@ -388,6 +397,15 @@ static int vprbrd_gpiob_direction_output(struct gpio_chip *chip,
return vprbrd_gpiob_set(chip, offset, value);
}

+static int vprbrd_gpiob_get_direction(struct gpio_chip *chip,
+ unsigned int offset)
+{
+ struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
+
+ return (gpio->gpiob_out & (1 << offset)) ? GPIO_LINE_DIRECTION_OUT :
+ GPIO_LINE_DIRECTION_IN;
+}
+
/* ----- end of gpio b chip ---------------------------------------------- */

static int vprbrd_gpio_probe(struct platform_device *pdev)
@@ -412,6 +430,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
vb_gpio->gpioa.get = vprbrd_gpioa_get;
vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input;
vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output;
+ vb_gpio->gpioa.get_direction = vprbrd_gpioa_get_direction;

ret = devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpioa, vb_gpio);
if (ret < 0)
@@ -428,6 +447,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
vb_gpio->gpiob.get = vprbrd_gpiob_get;
vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input;
vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output;
+ vb_gpio->gpiob.get_direction = vprbrd_gpiob_get_direction;

return devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpiob, vb_gpio);
}
--
2.34.1