[PATCH] gpio: mxc_gpio: Fix i.MX8M GPIO output status read

Harm Berntsen harm.berntsen at nedap.com
Fri Aug 13 16:34:50 CEST 2021


Currently the driver gets value from PSR register, but this register is
only for input mode. For output mode, it always returns 0, not the value
we set for output.

This patch changes to use DR register, which returns the DR value for
output mode, and PSR value for input mode.

This patch is based on code from Ye Li <ye.li at nxp.com>

Signed-off-by: Robert Krikke <robert.krikke at nedap.com>
Signed-off-by: Harm Berntsen <harm.berntsen at nedap.com>
CC: Ye Li <ye.li at nxp.com>
CC: Stefano Babic <sbabic at denx.de>
---

 drivers/gpio/mxc_gpio.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 06e6b2279f..c30246399c 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -36,6 +36,17 @@ struct mxc_bank_info {
 	struct gpio_regs *regs;
 };
 
+static int gpio_bank_get_value(struct gpio_regs *regs, int offset)
+{
+	u32 gpio_val;
+
+	if (IS_ENABLED(CONFIG_ARCH_IMX8M))
+		gpio_val = readl(&regs->gpio_dr);
+	else
+		gpio_val = readl(&regs->gpio_psr);
+	return (gpio_val >> offset) & 0x01;
+}
+
 #if !CONFIG_IS_ENABLED(DM_GPIO)
 #define GPIO_TO_PORT(n)		((n) / 32)
 
@@ -125,18 +136,13 @@ int gpio_get_value(unsigned gpio)
 {
 	unsigned int port = GPIO_TO_PORT(gpio);
 	struct gpio_regs *regs;
-	u32 val;
-
 	if (port >= ARRAY_SIZE(gpio_ports))
 		return -1;
 
 	gpio &= 0x1f;
 
 	regs = (struct gpio_regs *)gpio_ports[port];
-
-	val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
-
-	return val;
+	return gpio_bank_get_value(regs, gpio);
 }
 
 int gpio_request(unsigned gpio, const char *label)
@@ -211,7 +217,7 @@ static void mxc_gpio_bank_set_value(struct gpio_regs *regs, int offset,
 
 static int mxc_gpio_bank_get_value(struct gpio_regs *regs, int offset)
 {
-	return (readl(&regs->gpio_psr) >> offset) & 0x01;
+	return gpio_bank_get_value(regs, offset);
 }
 
 /* set GPIO pin 'gpio' as an input */
-- 
2.32.0



More information about the U-Boot mailing list