From 4c4ff6e38768f2431ed153f110f2d1fcce848af8 Mon Sep 17 00:00:00 2001 From: Diogo Ivo Date: Tue, 27 Jan 2026 18:52:42 +0000 Subject: [PATCH] gpio: max77620: Implement .get_direction() callback Add support for reporting the current GPIO line direction by implementing the .get_direction() callback for the MAX77620 GPIO controller. Signed-off-by: Diogo Ivo Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260127-smaug-spi_flash-v1-1-5fd334415118@tecnico.ulisboa.pt Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-max77620.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c index 02eca400b3077..e6c85411c695e 100644 --- a/drivers/gpio/gpio-max77620.c +++ b/drivers/gpio/gpio-max77620.c @@ -132,6 +132,24 @@ static const struct irq_chip max77620_gpio_irqchip = { GPIOCHIP_IRQ_RESOURCE_HELPERS, }; +static int max77620_gpio_get_dir(struct gpio_chip *gc, unsigned int offset) +{ + struct max77620_gpio *mgpio = gpiochip_get_data(gc); + unsigned int val; + int ret; + + ret = regmap_read(mgpio->rmap, GPIO_REG_ADDR(offset), &val); + if (ret < 0) { + dev_err(mgpio->dev, "CNFG_GPIOx read failed: %d\n", ret); + return ret; + } + + if (val & MAX77620_CNFG_GPIO_DIR_MASK) + return GPIO_LINE_DIRECTION_IN; + else + return GPIO_LINE_DIRECTION_OUT; +} + static int max77620_gpio_dir_input(struct gpio_chip *gc, unsigned int offset) { struct max77620_gpio *mgpio = gpiochip_get_data(gc); @@ -308,6 +326,7 @@ static int max77620_gpio_probe(struct platform_device *pdev) mgpio->gpio_chip.label = pdev->name; mgpio->gpio_chip.parent = pdev->dev.parent; + mgpio->gpio_chip.get_direction = max77620_gpio_get_dir; mgpio->gpio_chip.direction_input = max77620_gpio_dir_input; mgpio->gpio_chip.get = max77620_gpio_get; mgpio->gpio_chip.direction_output = max77620_gpio_dir_output; -- 2.47.3