]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
serial: sc16is7xx: implement gpio get_direction() callback
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Thu, 16 Jul 2026 21:08:09 +0000 (17:08 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Jul 2026 11:07:32 +0000 (13:07 +0200)
It's strongly recommended for GPIO drivers to always implement the
.get_direction() callback - even when the direction is tracked in
software. The GPIO core emits a warning when the callback is missing
and a user reads the direction of a line, e.g. via
/sys/kernel/debug/gpio.

Fixes: dfeae619d781 ("serial: sc16is7xx")
Cc: stable <stable@kernel.org>
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260716210813.2582826-1-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/sc16is7xx.c

index daebd92f32c7733dcc0c67093c06aae891c9143b..6c97953d593b57e2abf121d2f01b541ed2784b3e 100644 (file)
@@ -1273,6 +1273,17 @@ static int sc16is7xx_gpio_set(struct gpio_chip *chip, unsigned int offset,
        return 0;
 }
 
+static int sc16is7xx_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+       struct sc16is7xx_port *s = gpiochip_get_data(chip);
+       struct uart_port *port = &s->p[0].port;
+       unsigned int val;
+
+       val = sc16is7xx_port_read(port, SC16IS7XX_IODIR_REG);
+
+       return val & BIT(offset) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
 static int sc16is7xx_gpio_direction_input(struct gpio_chip *chip,
                                          unsigned offset)
 {
@@ -1350,6 +1361,7 @@ static int sc16is7xx_setup_gpio_chip(struct sc16is7xx_port *s)
        s->gpio.parent           = dev;
        s->gpio.label            = dev_name(dev);
        s->gpio.init_valid_mask  = sc16is7xx_gpio_init_valid_mask;
+       s->gpio.get_direction    = sc16is7xx_gpio_get_direction;
        s->gpio.direction_input  = sc16is7xx_gpio_direction_input;
        s->gpio.get              = sc16is7xx_gpio_get;
        s->gpio.direction_output = sc16is7xx_gpio_direction_output;