On imx8m it is more correct to read the data register than the pad status
register.

In output mode the pad status register does not contain the value being
output so we must read the DR for the value.

In input mode the DR will contain the same value as the PSR when the pad
mode is GPIO.

If the pad mode is not GPIO and the pin is an input then 0 is always
returned.

Signed-off-by: Angus Ainslie <an...@akkea.ca>
---
 drivers/gpio/mxc_gpio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 03471db9e80..0d9f6f44042 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -211,6 +211,9 @@ 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)
 {
+if (IS_ENABLED(CONFIG_IMX8M))
+       return (readl(&regs->gpio_dr) >> offset) & 0x01;
+else
        return (readl(&regs->gpio_psr) >> offset) & 0x01;
 }
 
-- 
2.25.1

Reply via email to