Re: [PATCH] serial: max310x: implement gpio_chip::get_direction()
From: Hugo Villeneuve
Date: Tue Jun 09 2026 - 15:52:49 EST
Hi Tapio,
On Tue, 02 Jun 2026 10:02:35 +0000
Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx> wrote:
> 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.
>
> The MAX310X keeps the GPIO direction in the GPIOCFG register (a set bit
> selects output), which the existing direction_input/output callbacks
> already program, so the current direction can be read back directly.
>
> Fixes: f65444187a66 ("serial: New serial driver MAX310X")
> Signed-off-by: Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>
> ---
> Found and HW-tested on an i.MX6 SoloX board with a MAX14830 over SPI:
> without this, "cat /sys/kernel/debug/gpio" triggers the gpiolib.c:429
> WARNING (tainting the kernel W) on each queried MAX14830 line; with it
> applied the lines report their in/out direction and the WARNING is gone.
> ---
> drivers/tty/serial/max310x.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index ac7d3f197c3a5ce3531d5607f48e21a807314021..96df54a90b009d1b547f7a639b0b9a4281daf073 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
> @@ -1212,6 +1212,18 @@ static int max310x_gpio_set(struct gpio_chip *chip, unsigned int offset,
> return 0;
> }
>
> +static int max310x_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
> +{
> + struct max310x_port *s = gpiochip_get_data(chip);
> + struct uart_port *port = &s->p[offset / 4].port;
> + unsigned int val;
> +
> + val = max310x_port_read(port, MAX310X_GPIOCFG_REG);
> +
> + return (val & (1 << (offset % 4))) ? GPIO_LINE_DIRECTION_OUT
> + : GPIO_LINE_DIRECTION_IN;
Small nit to improve readability:
... val & BIT(offset % 4) ...
you could also put this return statement on a single line (less than
100 columns).
> +}
> +
> static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
> {
> struct max310x_port *s = gpiochip_get_data(chip);
> @@ -1421,6 +1433,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
> s->gpio.owner = THIS_MODULE;
> s->gpio.parent = dev;
> s->gpio.label = devtype->name;
> + s->gpio.get_direction = max310x_gpio_get_direction;
> s->gpio.direction_input = max310x_gpio_direction_input;
> s->gpio.get = max310x_gpio_get;
> s->gpio.direction_output= max310x_gpio_direction_output;
>
> ---
> base-commit: e7ae89a0c97ce2b68b0983cd01eda67cf373517d
> change-id: 20260602-b4-serial-max310x-gpio-get-direction-b10ee5be4f24
>
> Best regards,
> --
> Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>
>
>
--
Hugo Villeneuve