Commit c1879001 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski
Browse files

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: default avatarMichael Walle <mwalle@kernel.org>
Closes: https://lore.kernel.org/all/DFJAFK3DTBOZ.3G2P3A5IH34GF@kernel.org/


Reviewed-by: default avatarLinus Walleij <linusw@kernel.org>
Fixes: a060b8c5 ("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: default avatarBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
parent 0f61b186
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
 */

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

static int davinci_get_direction(struct gpio_chip *chip, unsigned int offset)
{
	struct davinci_gpio_controller *d = gpiochip_get_data(chip);
	struct davinci_gpio_regs __iomem *g;
	u32 mask = __gpio_mask(offset), val;
	int bank = offset / 32;

	g = d->regs[bank];

	guard(spinlock_irqsave)(&d->lock);

	val = readl_relaxed(&g->dir);

	return (val & mask) ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
}

/*
 * Read the pin's value (works even if it's set up as output);
 * returns zero/nonzero.
@@ -203,6 +220,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
	chips->chip.get = davinci_gpio_get;
	chips->chip.direction_output = davinci_direction_out;
	chips->chip.set = davinci_gpio_set;
	chips->chip.get_direction = davinci_get_direction;

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