public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mx6: gpio: read data register if direction is out
@ 2014-06-23  6:35 Klaus Goger
  2014-06-24 13:07 ` Stefano Babic
  0 siblings, 1 reply; 4+ messages in thread
From: Klaus Goger @ 2014-06-23  6:35 UTC (permalink / raw)
  To: u-boot

On i.MX6 GPIOx_PSR does not reflect the current output value if the
direction is set to output. Instead we should read GPIOx_DR.

Signed-off-by: Klaus Goger <klaus.goger@theobroma-systems.com>
---
 drivers/gpio/mxc_gpio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 6a572d5..5838fc2 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -101,8 +101,16 @@ int gpio_get_value(unsigned gpio)
 	gpio &= 0x1f;
 
 	regs = (struct gpio_regs *)gpio_ports[port];
-
+#if defined(CONFIG_MX6)
+	/* if the direction is set to output we will always read 0 as pad status.
+	 * so we have to read the data register to get the current output state */
+	if (readl(&regs->gpio_dir) >> gpio & 0x01)
+		val = (readl(&regs->gpio_dr) >> gpio & 0x01);
+	else
+		val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
+#else
 	val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
+#endif
 
 	return val;
 }
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-24 14:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-23  6:35 [U-Boot] [PATCH] mx6: gpio: read data register if direction is out Klaus Goger
2014-06-24 13:07 ` Stefano Babic
2014-06-24 13:13   ` Fabio Estevam
2014-06-24 14:17     ` Klaus Goger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox