gpio: at91: Implement GPIOF_FUNC in get_function()
authorZixun LI <admin@hifiphile.com>
Wed, 13 Nov 2024 10:10:22 +0000 (11:10 +0100)
committerEugen Hristev <eugen.hristev@linaro.org>
Fri, 29 Nov 2024 10:59:27 +0000 (12:59 +0200)
This patch adds support for determining whether a gpio pin is mapped as
peripheral function.

Signed-off-by: Zixun LI <admin@hifiphile.com>
drivers/gpio/at91_gpio.c

index 50a6981..ee45aaf 100644 (file)
@@ -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