[U-Boot] [PATCH] gpio: mxc_gpio: Fix gpio_get_value() when the GPIO is an output
Fabio Estevam
festevam at gmail.com
Sat Sep 28 19:22:44 CEST 2013
From: Fabio Estevam <fabio.estevam at freescale.com>
When the GPIO is configured as an output, we should return the value from the DR
register.
This implements the same fix as in the following kernel commit from FSL BSP:
http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/commit/arch/arm/plat-mxc/gpio.c?h=imx_3.0.35_4.1.0&id=d6f32393eaf455ce3c32d4e9bafd34d9091eaf45
Signed-off-by: Fabio Estevam <fabio.estevam at freescale.com>
---
Otavio,
I don't have i.mx hardware access at the moment to try it, but this should fix
your LED problem.
drivers/gpio/mxc_gpio.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 6a572d5..debbecb 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -93,7 +93,7 @@ int gpio_get_value(unsigned gpio)
{
unsigned int port = GPIO_TO_PORT(gpio);
struct gpio_regs *regs;
- u32 val;
+ u32 direction;
if (port >= ARRAY_SIZE(gpio_ports))
return -1;
@@ -102,9 +102,12 @@ int gpio_get_value(unsigned gpio)
regs = (struct gpio_regs *)gpio_ports[port];
- val = (readl(®s->gpio_psr) >> gpio) & 0x01;
+ direction = readl(®s->gpio_dir);
- return val;
+ if ((direction >> gpio) & 1)
+ return (readl(®s->gpio_dr) >> gpio) & 1; /* output mode */
+ else
+ return (readl(®s->gpio_psr) >> gpio) & 1; /* input mode */
}
int gpio_request(unsigned gpio, const char *label)
--
1.8.1.2
More information about the U-Boot
mailing list