Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: davinci: implement .get_direction()

It's strongly recommended for GPIO drivers to always implement the
.get_direction() callback - even for fixed-direction controllers.

GPIO core will even emit a warning if the callback is missing, when
users try to read the direction of a pin.

Implement .get_direction() for gpio-davinci.

Reported-by: Michael Walle <mwalle@kernel.org>
Closes: https://lore.kernel.org/all/DFJAFK3DTBOZ.3G2P3A5IH34GF@kernel.org/
Reviewed-by: Linus Walleij <linusw@kernel.org>
Fixes: a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
Tested-by: Michael Walle <mwalle@kernel.org> # on sa67
Link: https://lore.kernel.org/r/20260109130832.27326-1-bartosz.golaszewski@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

+18
+18
drivers/gpio/gpio-davinci.c
··· 6 6 * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com> 7 7 */ 8 8 9 + #include <linux/cleanup.h> 9 10 #include <linux/gpio/driver.h> 10 11 #include <linux/errno.h> 11 12 #include <linux/kernel.h> ··· 110 109 return __davinci_direction(chip, offset, true, value); 111 110 } 112 111 112 + static int davinci_get_direction(struct gpio_chip *chip, unsigned int offset) 113 + { 114 + struct davinci_gpio_controller *d = gpiochip_get_data(chip); 115 + struct davinci_gpio_regs __iomem *g; 116 + u32 mask = __gpio_mask(offset), val; 117 + int bank = offset / 32; 118 + 119 + g = d->regs[bank]; 120 + 121 + guard(spinlock_irqsave)(&d->lock); 122 + 123 + val = readl_relaxed(&g->dir); 124 + 125 + return (val & mask) ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT; 126 + } 127 + 113 128 /* 114 129 * Read the pin's value (works even if it's set up as output); 115 130 * returns zero/nonzero. ··· 220 203 chips->chip.get = davinci_gpio_get; 221 204 chips->chip.direction_output = davinci_direction_out; 222 205 chips->chip.set = davinci_gpio_set; 206 + chips->chip.get_direction = davinci_get_direction; 223 207 224 208 chips->chip.ngpio = ngpio; 225 209 chips->chip.base = -1;