Skip to contentSkip to conversation

gpio: at91: Implement GPIOF_FUNC in get_function()

PATCH In review Zixun LI 2 participants 2 messages Nov 13, 2024 – Nov 19, 2024

Subsystems (2)
lore
Share & tools
lore

Zixun LI

author
#0 lore raw

PATCH v2 1/3 gpio: at91: Implement GPIOF_FUNC in get_function()

This patch adds support for determining whether a gpio pin is mapped as peripheral function.

---
Changes in v2:
- Rename function

---
 drivers/gpio/at91_gpio.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpio/at91_gpio.c +12 -1
index 1409db5dc1..173315d45f 100644
@@ -220,6 +220,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,
@@ -550,7 +559,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

--
2.46.2

#1 lore raw

Applied patches to u-boot-at91/next, thanks !

Eugen

Quoted 45 lines · Zixun LI

This patch adds support for determining whether a gpio pin is mapped as peripheral function.

---
Changes in v2:
- Rename function

---
 drivers/gpio/at91_gpio.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpio/at91_gpio.c +12 -2
index 1409db5dc1..173315d45f 100644
@@ -220,6 +220,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,
@@ -550,7 +559,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
--

2.46.2