diff mbox series

[PATCHv2,02/10] gpio: mxc_gpio: add support to read status of output gpios

Message ID 20200813082819.86973-3-sebastian.reichel@collabora.com
State Superseded
Delegated to: Stefano Babic
Headers show
Series Introduce B1x5v2 support | expand

Commit Message

Sebastian Reichel Aug. 13, 2020, 8:28 a.m. UTC
This is supported by the hardware when the pinmux is configured
correctly. Usually it is not, so this adds explicit code for this.
This fixes all GPIO regulators being shown as disabled.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/gpio/mxc_gpio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 88b920a0746b..ddf79c3bb2d0 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -209,6 +209,11 @@  static void mxc_gpio_bank_set_value(struct gpio_regs *regs, int offset,
 	writel(l, &regs->gpio_dr);
 }
 
+static int mxc_gpio_bank_get_out_value(struct gpio_regs *regs, int offset)
+{
+	return (readl(&regs->gpio_dr) >> offset) & 1;
+}
+
 static int mxc_gpio_bank_get_value(struct gpio_regs *regs, int offset)
 {
 	return (readl(&regs->gpio_psr) >> offset) & 0x01;
@@ -245,7 +250,10 @@  static int mxc_gpio_get_value(struct udevice *dev, unsigned offset)
 {
 	struct mxc_bank_info *bank = dev_get_priv(dev);
 
-	return mxc_gpio_bank_get_value(bank->regs, offset);
+	if (mxc_gpio_is_output(bank->regs, offset))
+		return mxc_gpio_bank_get_out_value(bank->regs, offset);
+	else
+		return mxc_gpio_bank_get_value(bank->regs, offset);
 }
 
 /* write GPIO OUT value to pin 'gpio' */