Re: [PATCH] serial: sc16is7xx: implement gpio get_direction() callback

Bartosz Golaszewski <[email protected]>
Newsgroups org.kernel.vger.linux-serial,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel
Message-ID <CAMRc=MerwHnK5sdw7JRyzkhrRZF_2vSjcpOJ6R=Lz9rbKGE5JQ@mail.gmail.com>
On Thu, 16 Jul 2026 23:08:09 +0200, Hugo Villeneuve <[email protected]> said:
> From: Hugo Villeneuve <[email protected]>
>
> 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: [email protected]
> Signed-off-by: Hugo Villeneuve <[email protected]>
> ---
> Inspired by a similar patch for max310x: commit a483b1a91b33
> ("serial: max310x: implement gpio_chip::get_direction()").
> ---
>  drivers/tty/serial/sc16is7xx.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> index 2498f9da2bf77..943be318de410 100644
> --- a/drivers/tty/serial/sc16is7xx.c
> +++ b/drivers/tty/serial/sc16is7xx.c
> @@ -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;
>
> base-commit: da7b5fd4e17f8e44c5590f2d603c01d499f056e6
> --
> 2.47.3
>
>

Acked-by: Bartosz Golaszewski <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.