Skip to content

Commit c187900

Browse files
author
Bartosz Golaszewski
committed
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: a060b8c ("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>
1 parent 0f61b18 commit c187900

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

drivers/gpio/gpio-davinci.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
77
*/
88

9+
#include <linux/cleanup.h>
910
#include <linux/gpio/driver.h>
1011
#include <linux/errno.h>
1112
#include <linux/kernel.h>
@@ -109,6 +110,22 @@ davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
109110
return __davinci_direction(chip, offset, true, value);
110111
}
111112

113+
static int davinci_get_direction(struct gpio_chip *chip, unsigned int offset)
114+
{
115+
struct davinci_gpio_controller *d = gpiochip_get_data(chip);
116+
struct davinci_gpio_regs __iomem *g;
117+
u32 mask = __gpio_mask(offset), val;
118+
int bank = offset / 32;
119+
120+
g = d->regs[bank];
121+
122+
guard(spinlock_irqsave)(&d->lock);
123+
124+
val = readl_relaxed(&g->dir);
125+
126+
return (val & mask) ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
127+
}
128+
112129
/*
113130
* Read the pin's value (works even if it's set up as output);
114131
* returns zero/nonzero.
@@ -203,6 +220,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
203220
chips->chip.get = davinci_gpio_get;
204221
chips->chip.direction_output = davinci_direction_out;
205222
chips->chip.set = davinci_gpio_set;
223+
chips->chip.get_direction = davinci_get_direction;
206224

207225
chips->chip.ngpio = ngpio;
208226
chips->chip.base = -1;

0 commit comments

Comments
 (0)