summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZixun LI <[email protected]>2024-11-13 11:10:22 +0100
committerEugen Hristev <[email protected]>2024-11-29 12:59:27 +0200
commite4980192b6028a90524ba601bbed65fe662869c1 (patch)
treed935e6702f6ebfed00b7212083f711c9cc646f2f
parent11da3c67e36551a4cd207abb029fec3560cc4f88 (diff)
gpio: at91: Implement GPIOF_FUNC in get_function()
This patch adds support for determining whether a gpio pin is mapped as peripheral function. Signed-off-by: Zixun LI <[email protected]>
-rw-r--r--drivers/gpio/at91_gpio.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c
index 50a69815907..ee45aaf038a 100644
--- a/drivers/gpio/at91_gpio.c
+++ b/drivers/gpio/at91_gpio.c
@@ -219,6 +219,15 @@ static bool at91_get_port_output(struct at91_port *at91_port, int offset)
val = readl(&at91_port->osr);
return val & mask;
}
+
+static bool at91_is_port_gpio(struct at91_port *at91_port, int offset)
+{
+ u32 mask, val;
+
+ mask = 1 << offset;
+ val = readl(&at91_port->psr);
+ return !!(val & mask);
+}
#endif
static void at91_set_port_input(struct at91_port *at91_port, int offset,
@@ -549,7 +558,9 @@ static int at91_gpio_get_function(struct udevice *dev, unsigned offset)
{
struct at91_port_priv *port = dev_get_priv(dev);
- /* GPIOF_FUNC is not implemented yet */
+ if (!at91_is_port_gpio(port->regs, offset))
+ return GPIOF_FUNC;
+
if (at91_get_port_output(port->regs, offset))
return GPIOF_OUTPUT;
else