Skip to contentSkip to conversation

mxc: Make gpio_get_value() use PSR

PATCH New Benoît Thébaudeau 2 participants 3 messages Aug 20, 2012 – Aug 23, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mxc: Make gpio_get_value() use PSR

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.

---
This patch depends on http://patchwork.ozlabs.org/patch/178694/ .

 .../drivers/gpio/mxc_gpio.c                        |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/mxc_gpio.c +1 -1
index 6615535..e9bf278 100644
@@ -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;
 }
#1 lore raw

PATCH 1/1 mxc: Make gpio_get_value() use PSR

Quoted 19 lines · Beno?t Th?baudeau

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.

---
This patch depends on http://patchwork.ozlabs.org/patch/178694/ .

 .../drivers/gpio/mxc_gpio.c                        |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/mxc_gpio.c +0 -0
index 6615535..e9bf278 100644

drivers/gpio/mxc_gpio.c int gpio_get_value(unsigned gpio) · line 122

Quoted 8 lines
drivers/gpio/mxc_gpio.c +1 -1
@@ -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.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#2 lore raw

PATCH 1/1 mxc: Make gpio_get_value() use PSR

In reply to Benoît Thébaudeau
Quoted 19 lines · Beno?t Th?baudeau

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.

---
This patch depends on http://patchwork.ozlabs.org/patch/178694/ .

 .../drivers/gpio/mxc_gpio.c                        |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/mxc_gpio.c +0 -0
index 6615535..e9bf278 100644

drivers/gpio/mxc_gpio.c int gpio_get_value(unsigned gpio) · line 122

Quoted 8 lines
drivers/gpio/mxc_gpio.c +1 -1
@@ -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

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================