diff mbox

[U-Boot] mxc: Make gpio_get_value() use PSR

Message ID 1991832745.2612487.1345496141598.JavaMail.root@advansee.com
State Accepted
Commit 5dafa4543c399d329c7b01df1afa98437861cac0
Delegated to: Stefano Babic
Headers show

Commit Message

Benoît Thébaudeau Aug. 20, 2012, 8:55 p.m. UTC
gpio_get_value() should use PSR like Linux, not DR, because DR does not always
reflect the pin state, while PSR does. This is especially useful to detect a
short circuit on a GPIO pin configured as output, or to read the level of a pin
controlled by a non-GPIO IOMUX function.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Stefano Babic <sbabic@denx.de>
---
This patch depends on http://patchwork.ozlabs.org/patch/178694/ .

 .../drivers/gpio/mxc_gpio.c                        |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Babic Aug. 21, 2012, 6:20 a.m. UTC | #1
On 20/08/2012 22:55, Benoît Thébaudeau wrote:
> gpio_get_value() should use PSR like Linux, not DR, because DR does not always
> reflect the pin state, while PSR does. This is especially useful to detect a
> short circuit on a GPIO pin configured as output, or to read the level of a pin
> controlled by a non-GPIO IOMUX function.
> 
> Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
> This patch depends on http://patchwork.ozlabs.org/patch/178694/ .
> 
>  .../drivers/gpio/mxc_gpio.c                        |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git u-boot-imx-84ab1cb.orig/drivers/gpio/mxc_gpio.c u-boot-imx-84ab1cb/drivers/gpio/mxc_gpio.c
> index 6615535..e9bf278 100644
> --- u-boot-imx-84ab1cb.orig/drivers/gpio/mxc_gpio.c
> +++ u-boot-imx-84ab1cb/drivers/gpio/mxc_gpio.c
> @@ -116,7 +116,7 @@ int gpio_get_value(unsigned gpio)
>  
>  	regs = (struct gpio_regs *)gpio_ports[port];
>  
> -	val = (readl(&regs->gpio_dr) >> gpio) & 0x01;
> +	val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
>  
>  	return val;
>  }
> 

Kernel does the same.

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
Stefano Babic Aug. 23, 2012, 2:03 p.m. UTC | #2
On 20/08/2012 22:55, Benoît Thébaudeau wrote:
> gpio_get_value() should use PSR like Linux, not DR, because DR does not always
> reflect the pin state, while PSR does. This is especially useful to detect a
> short circuit on a GPIO pin configured as output, or to read the level of a pin
> controlled by a non-GPIO IOMUX function.
> 
> Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
> This patch depends on http://patchwork.ozlabs.org/patch/178694/ .
> 
>  .../drivers/gpio/mxc_gpio.c                        |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git u-boot-imx-84ab1cb.orig/drivers/gpio/mxc_gpio.c u-boot-imx-84ab1cb/drivers/gpio/mxc_gpio.c
> index 6615535..e9bf278 100644
> --- u-boot-imx-84ab1cb.orig/drivers/gpio/mxc_gpio.c
> +++ u-boot-imx-84ab1cb/drivers/gpio/mxc_gpio.c
> @@ -116,7 +116,7 @@ int gpio_get_value(unsigned gpio)
>  
>  	regs = (struct gpio_regs *)gpio_ports[port];
>  
> -	val = (readl(&regs->gpio_dr) >> gpio) & 0x01;
> +	val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
>  
>  	return val;
>  }
> 

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic
diff mbox

Patch

diff --git u-boot-imx-84ab1cb.orig/drivers/gpio/mxc_gpio.c u-boot-imx-84ab1cb/drivers/gpio/mxc_gpio.c
index 6615535..e9bf278 100644
--- u-boot-imx-84ab1cb.orig/drivers/gpio/mxc_gpio.c
+++ u-boot-imx-84ab1cb/drivers/gpio/mxc_gpio.c
@@ -116,7 +116,7 @@  int gpio_get_value(unsigned gpio)
 
 	regs = (struct gpio_regs *)gpio_ports[port];
 
-	val = (readl(&regs->gpio_dr) >> gpio) & 0x01;
+	val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
 
 	return val;
 }