[PATCH] pio: add arch specific gpio_is_valid() function

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Nicolas Ferre
Date: Monday, August 23, 2010 - 8:01 am

Add a simple gpio_is_valid() function to replace
the standard one. It introduces the __HAVE_ARCH_GPIO_IS_VALID
macro to overload the generic code.
As an implementation example, it takes into account the AT91
pio numbering to check if a proper value is used.

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
Hi all,

I come back on this thread as I would like to implement the gpio_is_valid()
function for AT91. I have based this piece of code on comments from Ben and
Haavard and chose the  __HAVE_ARCH_* macro definition as it seems wide spread
in kernel code.
Please make comments and if it is ok for you, eventually accept for merging...


 arch/arm/mach-at91/include/mach/gpio.h |    9 +++++++++
 include/asm-generic/gpio.h             |    4 ++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-at91/include/mach/gpio.h b/arch/arm/mach-at91/include/mach/gpio.h
index 5cce2ed..103486d 100644
--- a/arch/arm/mach-at91/include/mach/gpio.h
+++ b/arch/arm/mach-at91/include/mach/gpio.h
@@ -188,6 +188,15 @@
 #define	AT91_PIN_PE31	(PIN_BASE + 0x80 + 31)
 
 #ifndef __ASSEMBLY__
+static inline int gpio_is_valid(int number)
+{
+	if (number >= PIN_BASE)
+		return 1;
+	return 0;
+}
+#define __HAVE_ARCH_GPIO_IS_VALID 1
+
+
 /* setup setup routines, called from board init or driver probe() */
 extern int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup);
 extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup);
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 4f3d75e..2840f35 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -22,11 +22,13 @@
 #define ARCH_NR_GPIOS		256
 #endif
 
+#ifndef __HAVE_ARCH_GPIO_IS_VALID
 static inline int gpio_is_valid(int number)
 {
 	/* only some non-negative numbers are valid */
 	return ((unsigned)number) < ARCH_NR_GPIOS;
 }
+#endif
 
 struct device;
 struct seq_file;
@@ -185,11 +187,13 @@ extern void gpio_unexport(unsigned gpio);
 
 #else	/* !CONFIG_HAVE_GPIO_LIB */
 
+#ifndef __HAVE_ARCH_GPIO_IS_VALID
 static inline int gpio_is_valid(int number)
 {
 	/* only non-negative numbers are valid */
 	return number >= 0;
 }
+#endif
 
 /* platforms that don't directly support access to GPIOs through I2C, SPI,
  * or other blocking infrastructure can use these wrappers.
-- 
1.5.6.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/2] atmel-mci: change use of dma slave interface, Nicolas Ferre, (Thu Sep 17, 9:29 am)
Re: [PATCH 1/2] atmel-mci: change use of dma slave interface, Haavard Skinnemoen, (Wed Sep 30, 6:55 am)
Re: [PATCH 3/3 v2] at91/atmel-mci: inclusion of sd/mmc dri ..., Haavard Skinnemoen, (Tue Oct 27, 5:35 pm)
Re: [PATCH 3/3 v2] at91/atmel-mci: inclusion of sd/mmc dri ..., =?ISO-8859-1?Q?Thiag ..., (Tue Oct 27, 5:53 pm)
Re: [PATCH 3/3 v2] at91/atmel-mci: inclusion of sd/mmc dri ..., Haavard Skinnemoen, (Tue Oct 27, 6:31 pm)
Re: [PATCH 3/3 v2] at91/atmel-mci: inclusion of sd/mmc dri ..., Haavard Skinnemoen, (Sat Nov 7, 4:20 am)
[PATCH] pio: add arch specific gpio_is_valid() function, Nicolas Ferre, (Mon Aug 23, 8:01 am)
Re: [PATCH] pio: add arch specific gpio_is_valid() function, Jean-Christophe PLAG ..., (Fri Sep 3, 9:41 am)