Skip to content

Commit a483b1a

Browse files
tapioreijonengregkh
authored andcommitted
serial: max310x: implement gpio_chip::get_direction()
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: f654441 ("serial: New serial driver MAX310X") Cc: stable <stable@kernel.org> Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Reviewed-by: Hugo Villeneuve <hvilleneuve@dimonoff.com> Link: https://patch.msgid.link/20260615-b4-serial-max310x-gpio-get-direction-v2-1-4704ba2b181a@vaisala.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dc59e4f commit a483b1a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

drivers/tty/serial/max310x.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,17 @@ static int max310x_gpio_set(struct gpio_chip *chip, unsigned int offset,
12441244
return 0;
12451245
}
12461246

1247+
static int max310x_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
1248+
{
1249+
struct max310x_port *s = gpiochip_get_data(chip);
1250+
struct uart_port *port = &s->p[offset / 4].port;
1251+
unsigned int val;
1252+
1253+
val = max310x_port_read(port, MAX310X_GPIOCFG_REG);
1254+
1255+
return val & BIT(offset % 4) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
1256+
}
1257+
12471258
static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
12481259
{
12491260
struct max310x_port *s = gpiochip_get_data(chip);
@@ -1447,6 +1458,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
14471458
s->gpio.owner = THIS_MODULE;
14481459
s->gpio.parent = dev;
14491460
s->gpio.label = devtype->name;
1461+
s->gpio.get_direction = max310x_gpio_get_direction;
14501462
s->gpio.direction_input = max310x_gpio_direction_input;
14511463
s->gpio.get = max310x_gpio_get;
14521464
s->gpio.direction_output= max310x_gpio_direction_output;

0 commit comments

Comments
 (0)