
From: Fabio Estevam fabio.estevam@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/...
Signed-off-by: Fabio Estevam fabio.estevam@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)