git: b98558e69b0a - main - aw_gpio: temporarily switch to input function if read in eint mode

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Sun, 18 Feb 2024 13:57:12 UTC
The branch main has been updated by avg:

URL: https://cgit.FreeBSD.org/src/commit/?id=b98558e69b0aefbb99120a8a6ca7efbb8cafab5b

commit b98558e69b0aefbb99120a8a6ca7efbb8cafab5b
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2024-02-18 13:55:20 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2024-02-18 13:55:20 +0000

    aw_gpio: temporarily switch to input function if read in eint mode
    
    This is needed for gpiokeys driver that needs to read input state after
    receiving an interrupt for either edge.
    
    PR:             248138
    MFC after:      1 month
---
 sys/arm/allwinner/aw_gpio.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/arm/allwinner/aw_gpio.c b/sys/arm/allwinner/aw_gpio.c
index cee2cf056f42..6ff0516acb3f 100644
--- a/sys/arm/allwinner/aw_gpio.c
+++ b/sys/arm/allwinner/aw_gpio.c
@@ -654,18 +654,30 @@ aw_gpio_pin_get_locked(struct aw_gpio_softc *sc,uint32_t pin,
     unsigned int *val)
 {
 	uint32_t bank, reg_data;
+	int32_t func;
+	int err;
 
 	AW_GPIO_LOCK_ASSERT(sc);
 
 	if (pin > sc->conf->padconf->npins)
 		return (EINVAL);
 
+	func = aw_gpio_get_function(sc, pin);
+	if (func == sc->conf->padconf->pins[pin].eint_func) {	/* "pl_eintX */
+		err = aw_gpio_set_function(sc, pin, AW_GPIO_INPUT);
+		if (err != 0)
+			return (err);
+	}
+
 	bank = sc->conf->padconf->pins[pin].port;
 	pin = sc->conf->padconf->pins[pin].pin;
 
 	reg_data = AW_GPIO_READ(sc, AW_GPIO_GP_DAT(bank));
 	*val = (reg_data & (1 << pin)) ? 1 : 0;
 
+	if (func == sc->conf->padconf->pins[pin].eint_func)
+		(void)aw_gpio_set_function(sc, pin, func);
+
 	return (0);
 }