[U-Boot] [PATCH 1/3] MX31: add accessor function to get a gpio

Stefano Babic sbabic at denx.de
Tue Apr 13 12:28:59 CEST 2010


The patch adds an accessor function to get the value of a gpio.

Signed-off-by: Stefano Babic <sbabic at denx.de>
---
 arch/arm/include/asm/arch-mx31/mx31.h |    5 +++++
 drivers/gpio/mx31_gpio.c              |   15 +++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/arch-mx31/mx31.h b/arch/arm/include/asm/arch-mx31/mx31.h
index 3cc4b35..f702d26 100644
--- a/arch/arm/include/asm/arch-mx31/mx31.h
+++ b/arch/arm/include/asm/arch-mx31/mx31.h
@@ -37,12 +37,17 @@ enum mx31_gpio_direction {
 extern int mx31_gpio_direction(unsigned int gpio,
 			       enum mx31_gpio_direction direction);
 extern void mx31_gpio_set(unsigned int gpio, unsigned int value);
+extern int mx31_gpio_get(unsigned int gpio);
 #else
 static inline int mx31_gpio_direction(unsigned int gpio,
 				      enum mx31_gpio_direction direction)
 {
 	return 1;
 }
+static inline int mx31_gpio_get(unsigned int gpio)
+{
+	return 1;
+}
 static inline void mx31_gpio_set(unsigned int gpio, unsigned int value)
 {
 }
diff --git a/drivers/gpio/mx31_gpio.c b/drivers/gpio/mx31_gpio.c
index 737aafa..b07f038 100644
--- a/drivers/gpio/mx31_gpio.c
+++ b/drivers/gpio/mx31_gpio.c
@@ -71,3 +71,18 @@ void mx31_gpio_set(unsigned int gpio, unsigned int value)
 		l &= ~(1 << gpio);
 	__REG(gpio_ports[port] + GPIO_DR) = l;
 }
+
+int mx31_gpio_get(unsigned int gpio)
+{
+	unsigned int port = gpio >> 5;
+	u32 l;
+
+	if (port >= ARRAY_SIZE(gpio_ports))
+		return -1;
+
+	gpio &= 0x1f;
+
+	l = (__REG(gpio_ports[port] + GPIO_DR) >> gpio) & 0x01;
+
+	return l;
+}
-- 
1.6.3.3



More information about the U-Boot mailing list