linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
@ 2012-02-04 15:54 Mark Brown
  2012-02-04 17:06 ` Sam Ravnborg
  0 siblings, 1 reply; 17+ messages in thread
From: Mark Brown @ 2012-02-04 15:54 UTC (permalink / raw)
  To: Guan Xuetao, Russell King, Ralf Baechle, Paul Mundt,
	Geert Uytterhoeven, Mike Frysinger, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Grant Likely
  Cc: linux-arch, linux-mips, uclinux-dist-devel, linux-m68k,
	linux-kernel, linux-sh, Mark Brown

Rather than requiring architectures that use gpiolib but don't have any
need to define anything custom to copy an asm/gpio.h provide a Kconfig
symbol which architectures must select in order to include gpio.h and
for other architectures just provide the trivial implementation directly.

This makes it much easier to do gpiolib updates and is also a step towards
making gpiolib APIs available on every architecture.

For architectures with existing boilerplate code leave a stub header in
place which warns on direct inclusion of asm/gpio.h and includes
linux/gpio.h to catch code that's doing this.  Direct inclusion of
asm/gpio.h has long been deprecated.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---

Build tested on x86 which is one of the affected architectures.

 arch/alpha/include/asm/gpio.h      |   59 ++----------------------------
 arch/arm/Kconfig                   |    1 +
 arch/avr32/Kconfig                 |    1 +
 arch/blackfin/Kconfig              |    1 +
 arch/ia64/include/asm/gpio.h       |   59 ++----------------------------
 arch/m68k/Kconfig.cpu              |    1 +
 arch/microblaze/include/asm/gpio.h |   57 ++---------------------------
 arch/mips/Kconfig                  |    1 +
 arch/openrisc/include/asm/gpio.h   |   69 ++---------------------------------
 arch/powerpc/include/asm/gpio.h    |   57 ++---------------------------
 arch/sh/Kconfig                    |    1 +
 arch/sparc/include/asm/gpio.h      |   40 ++-------------------
 arch/unicore32/Kconfig             |    1 +
 arch/x86/include/asm/gpio.h        |   57 ++---------------------------
 arch/xtensa/include/asm/gpio.h     |   60 ++-----------------------------
 drivers/gpio/Kconfig               |    8 ++++
 include/linux/gpio.h               |   34 +++++++++++++++++
 17 files changed, 81 insertions(+), 426 deletions(-)

diff --git a/arch/alpha/include/asm/gpio.h b/arch/alpha/include/asm/gpio.h
index 7dc6a63..b3799d8 100644
--- a/arch/alpha/include/asm/gpio.h
+++ b/arch/alpha/include/asm/gpio.h
@@ -1,55 +1,4 @@
-/*
- * Generic GPIO API implementation for Alpha.
- *
- * A stright copy of that for PowerPC which was:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_ALPHA_GPIO_H
-#define _ASM_ALPHA_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_ALPHA_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a48aecc..dcf4187 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1,6 +1,7 @@
 config ARM
 	bool
 	default y
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_AOUT
 	select HAVE_DMA_API_DEBUG
 	select HAVE_IDE if PCI || ISA || PCMCIA
diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
index 197e96f..b2e3e58 100644
--- a/arch/avr32/Kconfig
+++ b/arch/avr32/Kconfig
@@ -10,6 +10,7 @@ config AVR32
 	select GENERIC_IRQ_PROBE
 	select HARDIRQS_SW_RESEND
 	select GENERIC_IRQ_SHOW
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	help
 	  AVR32 is a high-performance 32-bit RISC microprocessor core,
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index abe5a9e..c45ecdc 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -31,6 +31,7 @@ config BLACKFIN
 	select HAVE_KERNEL_LZO if RAMKERNEL
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_GENERIC_HARDIRQS
 	select GENERIC_ATOMIC64
diff --git a/arch/ia64/include/asm/gpio.h b/arch/ia64/include/asm/gpio.h
index 590a20d..b3799d8 100644
--- a/arch/ia64/include/asm/gpio.h
+++ b/arch/ia64/include/asm/gpio.h
@@ -1,55 +1,4 @@
-/*
- * Generic GPIO API implementation for IA-64.
- *
- * A stright copy of that for PowerPC which was:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_IA64_GPIO_H
-#define _ASM_IA64_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_IA64_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu
index 8a9c767..8941af1 100644
--- a/arch/m68k/Kconfig.cpu
+++ b/arch/m68k/Kconfig.cpu
@@ -24,6 +24,7 @@ config COLDFIRE
 	bool "Coldfire CPU family support"
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select CPU_HAS_NO_BITFIELDS
 	select CPU_HAS_NO_MULDIV64
 	select GENERIC_CSUM
diff --git a/arch/microblaze/include/asm/gpio.h b/arch/microblaze/include/asm/gpio.h
index 2b2c18b..b3799d8 100644
--- a/arch/microblaze/include/asm/gpio.h
+++ b/arch/microblaze/include/asm/gpio.h
@@ -1,53 +1,4 @@
-/*
- * Generic GPIO API implementation for PowerPC.
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_MICROBLAZE_GPIO_H
-#define _ASM_MICROBLAZE_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_MICROBLAZE_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index c4c1312..4918404 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -8,6 +8,7 @@ config MIPS
 	select HAVE_PERF_EVENTS
 	select PERF_USE_VMALLOC
 	select HAVE_ARCH_KGDB
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_DYNAMIC_FTRACE
diff --git a/arch/openrisc/include/asm/gpio.h b/arch/openrisc/include/asm/gpio.h
index 0b0d174..b3799d8 100644
--- a/arch/openrisc/include/asm/gpio.h
+++ b/arch/openrisc/include/asm/gpio.h
@@ -1,65 +1,4 @@
-/*
- * OpenRISC Linux
- *
- * Linux architectural port borrowing liberally from similar works of
- * others.  All original copyrights apply as per the original source
- * declaration.
- *
- * OpenRISC implementation:
- * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
- * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
- * et al.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __ASM_OPENRISC_GPIO_H
-#define __ASM_OPENRISC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * OpenRISC (or1k) does not have on-chip GPIO's so there is not really
- * any standardized implementation that makes sense here.  If passing
- * through gpiolib becomes a bottleneck then it may make sense, on a
- * case-by-case basis, to implement these inlined/rapid versions.
- *
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-/*
- * Not implemented, yet.
- */
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return -ENOSYS;
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_OPENRISC_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h
index 38762ed..b3799d8 100644
--- a/arch/powerpc/include/asm/gpio.h
+++ b/arch/powerpc/include/asm/gpio.h
@@ -1,53 +1,4 @@
-/*
- * Generic GPIO API implementation for PowerPC.
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __ASM_POWERPC_GPIO_H
-#define __ASM_POWERPC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_POWERPC_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 3c8db65..f15181d 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -12,6 +12,7 @@ config SUPERH
 	select HAVE_DMA_ATTRS
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select PERF_USE_VMALLOC
 	select HAVE_KERNEL_GZIP
diff --git a/arch/sparc/include/asm/gpio.h b/arch/sparc/include/asm/gpio.h
index a0e3ac0..b3799d8 100644
--- a/arch/sparc/include/asm/gpio.h
+++ b/arch/sparc/include/asm/gpio.h
@@ -1,36 +1,4 @@
-#ifndef __ASM_SPARC_GPIO_H
-#define __ASM_SPARC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return -ENOSYS;
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_SPARC_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
index eeb8054..7ff6d10 100644
--- a/arch/unicore32/Kconfig
+++ b/arch/unicore32/Kconfig
@@ -8,6 +8,7 @@ config UNICORE32
 	select HAVE_KERNEL_BZIP2
 	select HAVE_KERNEL_LZO
 	select HAVE_KERNEL_LZMA
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_IRQ_PROBE
 	select GENERIC_IRQ_SHOW
diff --git a/arch/x86/include/asm/gpio.h b/arch/x86/include/asm/gpio.h
index 91d915a..b3799d8 100644
--- a/arch/x86/include/asm/gpio.h
+++ b/arch/x86/include/asm/gpio.h
@@ -1,53 +1,4 @@
-/*
- * Generic GPIO API implementation for x86.
- *
- * Derived from the generic GPIO API for powerpc:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_X86_GPIO_H
-#define _ASM_X86_GPIO_H
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_X86_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/xtensa/include/asm/gpio.h b/arch/xtensa/include/asm/gpio.h
index a8c9fc4..b3799d8 100644
--- a/arch/xtensa/include/asm/gpio.h
+++ b/arch/xtensa/include/asm/gpio.h
@@ -1,56 +1,4 @@
-/*
- * Generic GPIO API implementation for xtensa.
- *
- * Stolen from x86, which is derived from the generic GPIO API for powerpc:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_XTENSA_GPIO_H
-#define _ASM_XTENSA_GPIO_H
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-/*
- * Not implemented, yet.
- */
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_XTENSA_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index d0c4118..81befc0 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -2,6 +2,14 @@
 # GPIO infrastructure and drivers
 #
 
+config ARCH_HAVE_CUSTOM_GPIO_H
+	bool
+	help
+	  Selecting this config option from the architecture Kconfig allows
+	  the architecture to provide a custom asm/gpio.h implementation
+	  overriding the default implementations.  New uses of this are
+	  strongly discouraged.
+
 config ARCH_WANT_OPTIONAL_GPIOLIB
 	bool
 	help
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 38ac48b..3149f68 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -1,6 +1,8 @@
 #ifndef __LINUX_GPIO_H
 #define __LINUX_GPIO_H
 
+#include <linux/errno.h>
+
 /* see Documentation/gpio.txt */
 
 /* make these flag values available regardless of GPIO kconfig options */
@@ -27,7 +29,39 @@ struct gpio {
 };
 
 #ifdef CONFIG_GENERIC_GPIO
+
+#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
 #include <asm/gpio.h>
+#else
+
+#include <asm-generic/gpio.h>
+
+static inline int gpio_get_value(unsigned int gpio)
+{
+	return __gpio_get_value(gpio);
+}
+
+static inline void gpio_set_value(unsigned int gpio, int value)
+{
+	__gpio_set_value(gpio, value);
+}
+
+static inline int gpio_cansleep(unsigned int gpio)
+{
+	return __gpio_cansleep(gpio);
+}
+
+static inline int gpio_to_irq(unsigned int gpio)
+{
+	return __gpio_to_irq(gpio);
+}
+
+static inline int irq_to_gpio(unsigned int irq)
+{
+	return -EINVAL;
+}
+
+#endif
 
 #else
 
-- 
1.7.9.rc1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-02-04 15:54 [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h Mark Brown
@ 2012-02-04 17:06 ` Sam Ravnborg
  2012-02-04 17:21   ` Mark Brown
  2012-02-04 17:41   ` Russell King - ARM Linux
  0 siblings, 2 replies; 17+ messages in thread
From: Sam Ravnborg @ 2012-02-04 17:06 UTC (permalink / raw)
  To: Mark Brown
  Cc: Guan Xuetao, Russell King, Ralf Baechle, Paul Mundt,
	Geert Uytterhoeven, Mike Frysinger, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Grant Likely, linux-arch, linux-mips,
	uclinux-dist-devel, linux-m68k, linux-kernel, linux-sh

On Sat, Feb 04, 2012 at 03:54:39PM +0000, Mark Brown wrote:
> Rather than requiring architectures that use gpiolib but don't have any
> need to define anything custom to copy an asm/gpio.h provide a Kconfig
> symbol which architectures must select in order to include gpio.h and
> for other architectures just provide the trivial implementation directly.

Hi Mark.

There is an even simpler solution.

For each arch that uses asm-generic/gpio.h add a line
to arch/$ARCH/include/asm/Kbuild like this:


    generic-y += gpio.h

This will then make this arch pick up the asm-generic version when
you do #include <asm/gpio.h>.

And you avoid the kconfig games.

iFor the archs which require their own asm/gpio.h file - just
add it to the asm/ dir - and do not add the generic-y assignment.

	Sam

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-02-04 17:06 ` Sam Ravnborg
@ 2012-02-04 17:21   ` Mark Brown
  2012-02-04 17:41   ` Russell King - ARM Linux
  1 sibling, 0 replies; 17+ messages in thread
From: Mark Brown @ 2012-02-04 17:21 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Guan Xuetao, Russell King, Ralf Baechle, Paul Mundt,
	Geert Uytterhoeven, Mike Frysinger, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Grant Likely, linux-arch, linux-mips,
	uclinux-dist-devel, linux-m68k, linux-kernel, linux-sh

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

On Sat, Feb 04, 2012 at 06:06:32PM +0100, Sam Ravnborg wrote:

> There is an even simpler solution.

> For each arch that uses asm-generic/gpio.h add a line
> to arch/$ARCH/include/asm/Kbuild like this:

>     generic-y += gpio.h

> This will then make this arch pick up the asm-generic version when
> you do #include <asm/gpio.h>.

> And you avoid the kconfig games.

Hrm, that would work but it does mean we still need to go round and
manually enable GPIO support on all architectures which is what I had
been trying to get away from.  It is a lot simpler though so it should
be much easier to persuade the architecture maintainers to do that.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-02-04 17:06 ` Sam Ravnborg
  2012-02-04 17:21   ` Mark Brown
@ 2012-02-04 17:41   ` Russell King - ARM Linux
  2012-02-06 11:37     ` Mark Brown
  1 sibling, 1 reply; 17+ messages in thread
From: Russell King - ARM Linux @ 2012-02-04 17:41 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Mark Brown, Guan Xuetao, Ralf Baechle, Paul Mundt,
	Geert Uytterhoeven, Mike Frysinger, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Grant Likely, linux-arch, linux-mips,
	uclinux-dist-devel, linux-m68k, linux-kernel, linux-sh

On Sat, Feb 04, 2012 at 06:06:32PM +0100, Sam Ravnborg wrote:
> On Sat, Feb 04, 2012 at 03:54:39PM +0000, Mark Brown wrote:
> > Rather than requiring architectures that use gpiolib but don't have any
> > need to define anything custom to copy an asm/gpio.h provide a Kconfig
> > symbol which architectures must select in order to include gpio.h and
> > for other architectures just provide the trivial implementation directly.
> 
> Hi Mark.
> 
> There is an even simpler solution.
> 
> For each arch that uses asm-generic/gpio.h add a line
> to arch/$ARCH/include/asm/Kbuild like this:
> 
> 
>     generic-y += gpio.h
> 
> This will then make this arch pick up the asm-generic version when
> you do #include <asm/gpio.h>.

You're assuming that asm-generic/gpio.h was invented to be a replacement
for an architecture asm/gpio.h.  Unfortunately, things aren't that
simple.

It would have been a lot better if asm-generic/gpio.h was tacked on the
bottom of linux/gpio.h - because that's what it really is.  It's core
code features, not platform stuff.

What's platform specific about asm/gpio.h is the number of GPIOs in
the system, and whether it wants to intercept the gpio_xxx() functions
to provide fast access to on-chip GPIOs.

What I'd suggest is moving asm-generic/gpio.h to linux/gpiolib.h, and
making asm-generic/gpio.h include that as a patch until stuff is fixed
for its new location.  That should result in a proper asm-generic/gpio.h
being:

/* The trivial gpiolib dispatchers */
#define gpio_get_value  __gpio_get_value
#define gpio_set_value  __gpio_set_value
#define gpio_cansleep   __gpio_cansleep
#define gpio_to_irq     __gpio_to_irq

and nothing else.

Alternatively, instead of linux/gpiolib.h, put it in linux/gpio.h instead,
but that gets more icky because of the mess of asm/gpio.h includes (which
I've been banging on for years about in ARM patches and they're _still_
coming.)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-02-04 17:41   ` Russell King - ARM Linux
@ 2012-02-06 11:37     ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2012-02-06 11:37 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Sam Ravnborg, Guan Xuetao, Ralf Baechle, Paul Mundt,
	Geert Uytterhoeven, Mike Frysinger, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Grant Likely, linux-arch, linux-mips,
	uclinux-dist-devel, linux-m68k, linux-kernel, linux-sh

[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]

On Sat, Feb 04, 2012 at 05:41:15PM +0000, Russell King - ARM Linux wrote:

> What's platform specific about asm/gpio.h is the number of GPIOs in
> the system, and whether it wants to intercept the gpio_xxx() functions
> to provide fast access to on-chip GPIOs.

Plus the fact that it might be a completely non-standard API, and might
totally override the gpiolib implementation.

> What I'd suggest is moving asm-generic/gpio.h to linux/gpiolib.h, and
> making asm-generic/gpio.h include that as a patch until stuff is fixed
> for its new location.  That should result in a proper asm-generic/gpio.h
> being:

> Alternatively, instead of linux/gpiolib.h, put it in linux/gpio.h instead,
> but that gets more icky because of the mess of asm/gpio.h includes (which
> I've been banging on for years about in ARM patches and they're _still_
> coming.)

Yeah, though it is a bit neater if it's all in gpio.h and everyone is
using gpiolib.  Perhaps something like the warnings I added on inclusion
of asm/gpio.h without linux/gpio.h would help, though I certainly
wouldn't expect it to solve anything.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-04-16  8:15   ` Mark Brown
  2012-04-16  8:26     ` Linus Walleij
@ 2012-05-12  0:08     ` Grant Likely
  1 sibling, 0 replies; 17+ messages in thread
From: Grant Likely @ 2012-05-12  0:08 UTC (permalink / raw)
  To: Mark Brown, Linus Walleij
  Cc: Grant Likely, Linus Walleij, linux-kernel, linux-arch,
	linux-alpha, linux-ia64, microblaze-uclinux, linux,
	linuxppc-dev@lists.ozlabs.org list, sparclinux, Chris Zankel

On Mon, 16 Apr 2012 09:15:32 +0100, Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:
> On Mon, Apr 16, 2012 at 09:21:58AM +0200, Linus Walleij wrote:
> 
> > This looks good but I think we need to page the alpha, ia64, m68k, microblaze,
> > openrisc etc subarch maintainers on this patch so they have their say.
> 
> That's why I CCed linux-arch, to get all the architecture maintainers
> included.  vger would get upset if I CCed everyone individually.

Meh; it's been long enough.  I'll build the major ones and then throw it into linux-next.

g.

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-04-15  9:52 Mark Brown
  2012-04-16  7:21 ` Linus Walleij
@ 2012-04-17 18:49 ` Tony Luck
  1 sibling, 0 replies; 17+ messages in thread
From: Tony Luck @ 2012-04-17 18:49 UTC (permalink / raw)
  To: Mark Brown; +Cc: Grant Likely, Linus Walleij, linux-kernel, linux-arch

On Sun, Apr 15, 2012 at 2:52 AM, Mark Brown
<broonie@opensource.wolfsonmicro.com> wrote:
> Rather than requiring architectures that use gpiolib but don't have any
> need to define anything custom to copy an asm/gpio.h provide a Kconfig
> symbol which architectures must select in order to include gpio.h and
> for other architectures just provide the trivial implementation directly.

ia64 parts:

Acked-by: Tony Luck <tony.luck@intel.com>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-04-16  8:15   ` Mark Brown
@ 2012-04-16  8:26     ` Linus Walleij
  2012-05-12  0:08     ` Grant Likely
  1 sibling, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2012-04-16  8:26 UTC (permalink / raw)
  To: Mark Brown
  Cc: Grant Likely, Linus Walleij, linux-kernel, linux-arch,
	linux-alpha, linux-ia64, microblaze-uclinux, linux,
	linuxppc-dev@lists.ozlabs.org list, sparclinux, Chris Zankel

On Mon, Apr 16, 2012 at 10:15 AM, Mark Brown
<broonie@opensource.wolfsonmicro.com> wrote:
> On Mon, Apr 16, 2012 at 09:21:58AM +0200, Linus Walleij wrote:
>
>> This looks good but I think we need to page the alpha, ia64, m68k, microblaze,
>> openrisc etc subarch maintainers on this patch so they have their say.
>
> That's why I CCed linux-arch, to get all the architecture maintainers
> included.  vger would get upset if I CCed everyone individually.

Oh I missed it. I looped in a few maintainers and arch lists anyway.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Thanks!
Linus Walleij

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-04-16  7:21 ` Linus Walleij
@ 2012-04-16  8:15   ` Mark Brown
  2012-04-16  8:26     ` Linus Walleij
  2012-05-12  0:08     ` Grant Likely
  0 siblings, 2 replies; 17+ messages in thread
From: Mark Brown @ 2012-04-16  8:15 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Grant Likely, Linus Walleij, linux-kernel, linux-arch,
	linux-alpha, linux-ia64, microblaze-uclinux, linux,
	linuxppc-dev@lists.ozlabs.org list, sparclinux, Chris Zankel

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

On Mon, Apr 16, 2012 at 09:21:58AM +0200, Linus Walleij wrote:

> This looks good but I think we need to page the alpha, ia64, m68k, microblaze,
> openrisc etc subarch maintainers on this patch so they have their say.

That's why I CCed linux-arch, to get all the architecture maintainers
included.  vger would get upset if I CCed everyone individually.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2012-04-15  9:52 Mark Brown
@ 2012-04-16  7:21 ` Linus Walleij
  2012-04-16  8:15   ` Mark Brown
  2012-04-17 18:49 ` Tony Luck
  1 sibling, 1 reply; 17+ messages in thread
From: Linus Walleij @ 2012-04-16  7:21 UTC (permalink / raw)
  To: Mark Brown
  Cc: Grant Likely, Linus Walleij, linux-kernel, linux-arch,
	linux-alpha, linux-ia64, microblaze-uclinux, linux,
	linuxppc-dev@lists.ozlabs.org list, sparclinux, Chris Zankel

On Sun, Apr 15, 2012 at 11:52 AM, Mark Brown
<broonie@opensource.wolfsonmicro.com> wrote:

> Rather than requiring architectures that use gpiolib but don't have any
> need to define anything custom to copy an asm/gpio.h provide a Kconfig
> symbol which architectures must select in order to include gpio.h and
> for other architectures just provide the trivial implementation directly.
>
> This makes it much easier to do gpiolib updates and is also a step towards
> making gpiolib APIs available on every architecture.
>
> For architectures with existing boilerplate code leave a stub header in
> place which warns on direct inclusion of asm/gpio.h and includes
> linux/gpio.h to catch code that's doing this.  Direct inclusion of
> asm/gpio.h has long been deprecated.
>
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>  arch/alpha/include/asm/gpio.h      |   59 ++----------------------------
>  arch/arm/Kconfig                   |    1 +
>  arch/avr32/Kconfig                 |    1 +
>  arch/blackfin/Kconfig              |    1 +
>  arch/ia64/include/asm/gpio.h       |   59 ++----------------------------
>  arch/m68k/Kconfig.cpu              |    1 +
>  arch/microblaze/include/asm/gpio.h |   57 ++---------------------------
>  arch/mips/Kconfig                  |    1 +
>  arch/openrisc/include/asm/gpio.h   |   69 ++---------------------------------
>  arch/powerpc/include/asm/gpio.h    |   57 ++---------------------------
>  arch/sh/Kconfig                    |    1 +
>  arch/sparc/include/asm/gpio.h      |   40 ++-------------------
>  arch/unicore32/Kconfig             |    1 +
>  arch/x86/include/asm/gpio.h        |   57 ++---------------------------
>  arch/xtensa/include/asm/gpio.h     |   60 ++-----------------------------
>  drivers/gpio/Kconfig               |    8 ++++
>  include/linux/gpio.h               |   34 +++++++++++++++++
>  17 files changed, 81 insertions(+), 426 deletions(-)

This looks good but I think we need to page the alpha, ia64, m68k, microblaze,
openrisc etc subarch maintainers on this patch so they have their say.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
@ 2012-04-15  9:52 Mark Brown
  2012-04-16  7:21 ` Linus Walleij
  2012-04-17 18:49 ` Tony Luck
  0 siblings, 2 replies; 17+ messages in thread
From: Mark Brown @ 2012-04-15  9:52 UTC (permalink / raw)
  To: Grant Likely, Linus Walleij; +Cc: linux-kernel, linux-arch, Mark Brown

Rather than requiring architectures that use gpiolib but don't have any
need to define anything custom to copy an asm/gpio.h provide a Kconfig
symbol which architectures must select in order to include gpio.h and
for other architectures just provide the trivial implementation directly.

This makes it much easier to do gpiolib updates and is also a step towards
making gpiolib APIs available on every architecture.

For architectures with existing boilerplate code leave a stub header in
place which warns on direct inclusion of asm/gpio.h and includes
linux/gpio.h to catch code that's doing this.  Direct inclusion of
asm/gpio.h has long been deprecated.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 arch/alpha/include/asm/gpio.h      |   59 ++----------------------------
 arch/arm/Kconfig                   |    1 +
 arch/avr32/Kconfig                 |    1 +
 arch/blackfin/Kconfig              |    1 +
 arch/ia64/include/asm/gpio.h       |   59 ++----------------------------
 arch/m68k/Kconfig.cpu              |    1 +
 arch/microblaze/include/asm/gpio.h |   57 ++---------------------------
 arch/mips/Kconfig                  |    1 +
 arch/openrisc/include/asm/gpio.h   |   69 ++---------------------------------
 arch/powerpc/include/asm/gpio.h    |   57 ++---------------------------
 arch/sh/Kconfig                    |    1 +
 arch/sparc/include/asm/gpio.h      |   40 ++-------------------
 arch/unicore32/Kconfig             |    1 +
 arch/x86/include/asm/gpio.h        |   57 ++---------------------------
 arch/xtensa/include/asm/gpio.h     |   60 ++-----------------------------
 drivers/gpio/Kconfig               |    8 ++++
 include/linux/gpio.h               |   34 +++++++++++++++++
 17 files changed, 81 insertions(+), 426 deletions(-)

diff --git a/arch/alpha/include/asm/gpio.h b/arch/alpha/include/asm/gpio.h
index 7dc6a63..b3799d8 100644
--- a/arch/alpha/include/asm/gpio.h
+++ b/arch/alpha/include/asm/gpio.h
@@ -1,55 +1,4 @@
-/*
- * Generic GPIO API implementation for Alpha.
- *
- * A stright copy of that for PowerPC which was:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_ALPHA_GPIO_H
-#define _ASM_ALPHA_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_ALPHA_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a5dd93e..9101c61 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1,6 +1,7 @@
 config ARM
 	bool
 	default y
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_AOUT
 	select HAVE_DMA_API_DEBUG
 	select HAVE_IDE if PCI || ISA || PCMCIA
diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
index 3dea7231..859b2de 100644
--- a/arch/avr32/Kconfig
+++ b/arch/avr32/Kconfig
@@ -11,6 +11,7 @@ config AVR32
 	select GENERIC_ATOMIC64
 	select HARDIRQS_SW_RESEND
 	select GENERIC_IRQ_SHOW
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	help
 	  AVR32 is a high-performance 32-bit RISC microprocessor core,
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 373a690..bf3d80f 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -31,6 +31,7 @@ config BLACKFIN
 	select HAVE_KERNEL_LZO if RAMKERNEL
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_GENERIC_HARDIRQS
 	select GENERIC_ATOMIC64
diff --git a/arch/ia64/include/asm/gpio.h b/arch/ia64/include/asm/gpio.h
index 590a20d..b3799d8 100644
--- a/arch/ia64/include/asm/gpio.h
+++ b/arch/ia64/include/asm/gpio.h
@@ -1,55 +1,4 @@
-/*
- * Generic GPIO API implementation for IA-64.
- *
- * A stright copy of that for PowerPC which was:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_IA64_GPIO_H
-#define _ASM_IA64_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_IA64_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu
index 8a9c767..8941af1 100644
--- a/arch/m68k/Kconfig.cpu
+++ b/arch/m68k/Kconfig.cpu
@@ -24,6 +24,7 @@ config COLDFIRE
 	bool "Coldfire CPU family support"
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select CPU_HAS_NO_BITFIELDS
 	select CPU_HAS_NO_MULDIV64
 	select GENERIC_CSUM
diff --git a/arch/microblaze/include/asm/gpio.h b/arch/microblaze/include/asm/gpio.h
index 2b2c18b..b3799d8 100644
--- a/arch/microblaze/include/asm/gpio.h
+++ b/arch/microblaze/include/asm/gpio.h
@@ -1,53 +1,4 @@
-/*
- * Generic GPIO API implementation for PowerPC.
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_MICROBLAZE_GPIO_H
-#define _ASM_MICROBLAZE_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_MICROBLAZE_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index ce30e2f..63321b2 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -8,6 +8,7 @@ config MIPS
 	select HAVE_PERF_EVENTS
 	select PERF_USE_VMALLOC
 	select HAVE_ARCH_KGDB
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_DYNAMIC_FTRACE
diff --git a/arch/openrisc/include/asm/gpio.h b/arch/openrisc/include/asm/gpio.h
index 0b0d174..b3799d8 100644
--- a/arch/openrisc/include/asm/gpio.h
+++ b/arch/openrisc/include/asm/gpio.h
@@ -1,65 +1,4 @@
-/*
- * OpenRISC Linux
- *
- * Linux architectural port borrowing liberally from similar works of
- * others.  All original copyrights apply as per the original source
- * declaration.
- *
- * OpenRISC implementation:
- * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
- * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
- * et al.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __ASM_OPENRISC_GPIO_H
-#define __ASM_OPENRISC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * OpenRISC (or1k) does not have on-chip GPIO's so there is not really
- * any standardized implementation that makes sense here.  If passing
- * through gpiolib becomes a bottleneck then it may make sense, on a
- * case-by-case basis, to implement these inlined/rapid versions.
- *
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-/*
- * Not implemented, yet.
- */
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return -ENOSYS;
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_OPENRISC_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h
index 38762ed..b3799d8 100644
--- a/arch/powerpc/include/asm/gpio.h
+++ b/arch/powerpc/include/asm/gpio.h
@@ -1,53 +1,4 @@
-/*
- * Generic GPIO API implementation for PowerPC.
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __ASM_POWERPC_GPIO_H
-#define __ASM_POWERPC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_POWERPC_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index ff9e033..c40b29a 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -13,6 +13,7 @@ config SUPERH
 	select HAVE_DMA_ATTRS
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select PERF_USE_VMALLOC
 	select HAVE_KERNEL_GZIP
diff --git a/arch/sparc/include/asm/gpio.h b/arch/sparc/include/asm/gpio.h
index a0e3ac0..b3799d8 100644
--- a/arch/sparc/include/asm/gpio.h
+++ b/arch/sparc/include/asm/gpio.h
@@ -1,36 +1,4 @@
-#ifndef __ASM_SPARC_GPIO_H
-#define __ASM_SPARC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return -ENOSYS;
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_SPARC_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
index eeb8054..7ff6d10 100644
--- a/arch/unicore32/Kconfig
+++ b/arch/unicore32/Kconfig
@@ -8,6 +8,7 @@ config UNICORE32
 	select HAVE_KERNEL_BZIP2
 	select HAVE_KERNEL_LZO
 	select HAVE_KERNEL_LZMA
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_IRQ_PROBE
 	select GENERIC_IRQ_SHOW
diff --git a/arch/x86/include/asm/gpio.h b/arch/x86/include/asm/gpio.h
index 91d915a..b3799d8 100644
--- a/arch/x86/include/asm/gpio.h
+++ b/arch/x86/include/asm/gpio.h
@@ -1,53 +1,4 @@
-/*
- * Generic GPIO API implementation for x86.
- *
- * Derived from the generic GPIO API for powerpc:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_X86_GPIO_H
-#define _ASM_X86_GPIO_H
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_X86_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/arch/xtensa/include/asm/gpio.h b/arch/xtensa/include/asm/gpio.h
index a8c9fc4..b3799d8 100644
--- a/arch/xtensa/include/asm/gpio.h
+++ b/arch/xtensa/include/asm/gpio.h
@@ -1,56 +1,4 @@
-/*
- * Generic GPIO API implementation for xtensa.
- *
- * Stolen from x86, which is derived from the generic GPIO API for powerpc:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_XTENSA_GPIO_H
-#define _ASM_XTENSA_GPIO_H
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-/*
- * Not implemented, yet.
- */
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_XTENSA_GPIO_H */
+#ifndef __LINUX_GPIO_H
+#warning Include linux/gpio.h instead of asm/gpio.h
+#include <linux/gpio.h>
+#endif
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7875c3f..4faec0a 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -2,6 +2,14 @@
 # GPIO infrastructure and drivers
 #
 
+config ARCH_HAVE_CUSTOM_GPIO_H
+	bool
+	help
+	  Selecting this config option from the architecture Kconfig allows
+	  the architecture to provide a custom asm/gpio.h implementation
+	  overriding the default implementations.  New uses of this are
+	  strongly discouraged.
+
 config ARCH_WANT_OPTIONAL_GPIOLIB
 	bool
 	help
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index a68024e..1df711f 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -1,6 +1,8 @@
 #ifndef __LINUX_GPIO_H
 #define __LINUX_GPIO_H
 
+#include <linux/errno.h>
+
 /* see Documentation/gpio.txt */
 
 /* make these flag values available regardless of GPIO kconfig options */
@@ -38,7 +40,39 @@ struct gpio {
 };
 
 #ifdef CONFIG_GENERIC_GPIO
+
+#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
 #include <asm/gpio.h>
+#else
+
+#include <asm-generic/gpio.h>
+
+static inline int gpio_get_value(unsigned int gpio)
+{
+	return __gpio_get_value(gpio);
+}
+
+static inline void gpio_set_value(unsigned int gpio, int value)
+{
+	__gpio_set_value(gpio, value);
+}
+
+static inline int gpio_cansleep(unsigned int gpio)
+{
+	return __gpio_cansleep(gpio);
+}
+
+static inline int gpio_to_irq(unsigned int gpio)
+{
+	return __gpio_to_irq(gpio);
+}
+
+static inline int irq_to_gpio(unsigned int irq)
+{
+	return -EINVAL;
+}
+
+#endif
 
 #else
 
-- 
1.7.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2011-10-26  7:33   ` Mark Brown
@ 2012-02-03 23:16     ` Grant Likely
  0 siblings, 0 replies; 17+ messages in thread
From: Grant Likely @ 2012-02-03 23:16 UTC (permalink / raw)
  To: Mark Brown
  Cc: Mike Frysinger, Russell King, Haavard Skinnemoen,
	Hans-Christian Egtvedt, Geert Uytterhoeven, Ralf Baechle,
	Paul Mundt, Guan Xuetao, linux-arm-kernel, linux-kernel,
	uclinux-dist-devel, linux-m68k, linux-mips, linux-sh, linux-arch

On Wed, Oct 26, 2011 at 1:33 AM, Mark Brown
<broonie@opensource.wolfsonmicro.com> wrote:
> On Tue, Oct 25, 2011 at 07:44:14PM -0400, Mike Frysinger wrote:
>
>> i don't think this is generally how asm-generic is handled.  instead, how about:
>>  - move the duplicate code to asm-generic/gpio.h
>>  - have the arches which merely need asm-generic/gpio.h add "generic-y
>> += gpio.h" to their include/asm/Kbuild
>>  - for arches which need to override these common funcs in some way,
>> add #ifdef protection to the asm-generic/gpio.h
>
>> and it seems like with slightly more work, this path allow you to
>> merge most of arch/sh/include/asm/gpio.h.  and it has the advantage of
>> not needing new Kconfig symbols.
>
> That's really not how gpiolib is currently handled, unfortunately -
> trying to transition over to that model in one patch would be way too
> much.
>
> The goal here from that point of view is to make transitioning to
> something more sensible easier by getting rid of the boilerplate code,
> it makes doing the more invasive changes like you're suggesting much
> easier as we're only dealing with the architectures that are actually
> doing something.  It also means that we're able to immediately work on
> turning on gpiolib on random architectures which is a definite win.

I had picked up this patch, but I've dropped again from gpio/next
since there are still a lot of drivers including asm/gpio.h.  It
caused build breakage on linux-next with allmodconfig.

g.


-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2011-10-25 23:44 ` Mike Frysinger
@ 2011-10-26  7:33   ` Mark Brown
  2012-02-03 23:16     ` Grant Likely
  0 siblings, 1 reply; 17+ messages in thread
From: Mark Brown @ 2011-10-26  7:33 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: Russell King, Haavard Skinnemoen, Hans-Christian Egtvedt,
	Geert Uytterhoeven, Ralf Baechle, Paul Mundt, Guan Xuetao,
	Grant Likely, linux-arm-kernel, linux-kernel, uclinux-dist-devel,
	linux-m68k, linux-mips, linux-sh, linux-arch

On Tue, Oct 25, 2011 at 07:44:14PM -0400, Mike Frysinger wrote:

> i don't think this is generally how asm-generic is handled.  instead, how about:
>  - move the duplicate code to asm-generic/gpio.h
>  - have the arches which merely need asm-generic/gpio.h add "generic-y
> += gpio.h" to their include/asm/Kbuild
>  - for arches which need to override these common funcs in some way,
> add #ifdef protection to the asm-generic/gpio.h

> and it seems like with slightly more work, this path allow you to
> merge most of arch/sh/include/asm/gpio.h.  and it has the advantage of
> not needing new Kconfig symbols.

That's really not how gpiolib is currently handled, unfortunately -
trying to transition over to that model in one patch would be way too
much.  

The goal here from that point of view is to make transitioning to
something more sensible easier by getting rid of the boilerplate code,
it makes doing the more invasive changes like you're suggesting much
easier as we're only dealing with the architectures that are actually
doing something.  It also means that we're able to immediately work on
turning on gpiolib on random architectures which is a definite win.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2011-10-25  7:33 Mark Brown
  2011-10-25  8:33 ` Grant Likely
@ 2011-10-25 23:44 ` Mike Frysinger
  2011-10-26  7:33   ` Mark Brown
  1 sibling, 1 reply; 17+ messages in thread
From: Mike Frysinger @ 2011-10-25 23:44 UTC (permalink / raw)
  To: Mark Brown
  Cc: Russell King, Haavard Skinnemoen, Hans-Christian Egtvedt,
	Geert Uytterhoeven, Ralf Baechle, Paul Mundt, Guan Xuetao,
	Grant Likely, linux-arm-kernel, linux-kernel, uclinux-dist-devel,
	linux-m68k, linux-mips, linux-sh, linux-arch

On Tue, Oct 25, 2011 at 03:33, Mark Brown wrote:
> Rather than requiring architectures that use gpiolib but don't have any
> need to define anything custom to copy an asm/gpio.h provide a Kconfig
> symbol which architectures must select in order to include gpio.h and
> for other architectures just provide the trivial implementation directly.

i don't think this is generally how asm-generic is handled.  instead, how about:
 - move the duplicate code to asm-generic/gpio.h
 - have the arches which merely need asm-generic/gpio.h add "generic-y
+= gpio.h" to their include/asm/Kbuild
 - for arches which need to override these common funcs in some way,
add #ifdef protection to the asm-generic/gpio.h

and it seems like with slightly more work, this path allow you to
merge most of arch/sh/include/asm/gpio.h.  and it has the advantage of
not needing new Kconfig symbols.

for example, with asm-generic/atomic.h, it does:
#ifndef atomic_sub_return
static inline int atomic_sub_return(int i, atomic_t *v)
{ ... common implementation ... }
#endif

and then any arch that wants to override it does:
#define atomic_sub_return atomic_sub_return
static inline int atomic_sub_return(int i, atomic_t *v) { weirdness }
#include <asm-generic/atomic.h>
-mike

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2011-10-25  8:33 ` Grant Likely
@ 2011-10-25  8:39   ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2011-10-25  8:39 UTC (permalink / raw)
  To: Grant Likely
  Cc: Russell King, Haavard Skinnemoen, Hans-Christian Egtvedt,
	Mike Frysinger, Geert Uytterhoeven, Ralf Baechle, Paul Mundt,
	Guan Xuetao, linux-arm-kernel, linux-kernel, uclinux-dist-devel,
	linux-m68k, linux-mips, linux-sh, linux-arch

On Tue, Oct 25, 2011 at 10:33:01AM +0200, Grant Likely wrote:

> (not that I've actually tested this much yet; it should probably go
> into a separate branch to marinate in linux-next for a bit without
> impacting the other GPIO patches I've got queued.

Yes, it should.  I've test built a few configurations covering both
asm/gpio.h and default implementations and it seems to be doing the
right thing but I might well have missed something.  I'm hoping to also
have a further patch to go on top of this which makes _OPTIONAL_GPOILIB
on by default.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
  2011-10-25  7:33 Mark Brown
@ 2011-10-25  8:33 ` Grant Likely
  2011-10-25  8:39   ` Mark Brown
  2011-10-25 23:44 ` Mike Frysinger
  1 sibling, 1 reply; 17+ messages in thread
From: Grant Likely @ 2011-10-25  8:33 UTC (permalink / raw)
  To: Mark Brown
  Cc: Russell King, Haavard Skinnemoen, Hans-Christian Egtvedt,
	Mike Frysinger, Geert Uytterhoeven, Ralf Baechle, Paul Mundt,
	Guan Xuetao, linux-arm-kernel, linux-kernel, uclinux-dist-devel,
	linux-m68k, linux-mips, linux-sh, linux-arch

On Tue, Oct 25, 2011 at 09:33:32AM +0200, Mark Brown wrote:
> Rather than requiring architectures that use gpiolib but don't have any
> need to define anything custom to copy an asm/gpio.h provide a Kconfig
> symbol which architectures must select in order to include gpio.h and
> for other architectures just provide the trivial implementation directly.
> 
> This makes it much easier to do gpiolib updates and is also a step towards
> making gpiolib APIs available on every architecture.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

Acked-by: Grant Likely <grant.likely@secretlab.ca>

(not that I've actually tested this much yet; it should probably go
into a separate branch to marinate in linux-next for a bit without
impacting the other GPIO patches I've got queued.

g.

> ---
>  arch/alpha/include/asm/gpio.h      |   55 ------------------------------
>  arch/arm/Kconfig                   |    1 +
>  arch/avr32/Kconfig                 |    1 +
>  arch/blackfin/Kconfig              |    1 +
>  arch/ia64/include/asm/gpio.h       |   55 ------------------------------
>  arch/m68k/Kconfig.cpu              |    1 +
>  arch/microblaze/include/asm/gpio.h |   53 -----------------------------
>  arch/mips/Kconfig                  |    1 +
>  arch/openrisc/include/asm/gpio.h   |   65 ------------------------------------
>  arch/powerpc/include/asm/gpio.h    |   53 -----------------------------
>  arch/sh/Kconfig                    |    1 +
>  arch/sparc/include/asm/gpio.h      |   36 --------------------
>  arch/unicore32/Kconfig             |    1 +
>  arch/x86/include/asm/gpio.h        |   53 -----------------------------
>  arch/xtensa/include/asm/gpio.h     |   56 -------------------------------
>  drivers/gpio/Kconfig               |    8 ++++
>  include/linux/gpio.h               |   34 +++++++++++++++++++
>  17 files changed, 49 insertions(+), 426 deletions(-)
>  delete mode 100644 arch/alpha/include/asm/gpio.h
>  delete mode 100644 arch/ia64/include/asm/gpio.h
>  delete mode 100644 arch/microblaze/include/asm/gpio.h
>  delete mode 100644 arch/openrisc/include/asm/gpio.h
>  delete mode 100644 arch/powerpc/include/asm/gpio.h
>  delete mode 100644 arch/sparc/include/asm/gpio.h
>  delete mode 100644 arch/x86/include/asm/gpio.h
>  delete mode 100644 arch/xtensa/include/asm/gpio.h
> 
> diff --git a/arch/alpha/include/asm/gpio.h b/arch/alpha/include/asm/gpio.h
> deleted file mode 100644
> index 7dc6a63..0000000
> --- a/arch/alpha/include/asm/gpio.h
> +++ /dev/null
> @@ -1,55 +0,0 @@
> -/*
> - * Generic GPIO API implementation for Alpha.
> - *
> - * A stright copy of that for PowerPC which was:
> - *
> - * Copyright (c) 2007-2008  MontaVista Software, Inc.
> - *
> - * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef _ASM_ALPHA_GPIO_H
> -#define _ASM_ALPHA_GPIO_H
> -
> -#include <linux/errno.h>
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * We don't (yet) implement inlined/rapid versions for on-chip gpios.
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return __gpio_to_irq(gpio);
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* _ASM_ALPHA_GPIO_H */
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 7e8ffe7..5e0446c 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1,6 +1,7 @@
>  config ARM
>  	bool
>  	default y
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select HAVE_AOUT
>  	select HAVE_DMA_API_DEBUG
>  	select HAVE_IDE if PCI || ISA || PCMCIA
> diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
> index 197e96f..b2e3e58 100644
> --- a/arch/avr32/Kconfig
> +++ b/arch/avr32/Kconfig
> @@ -10,6 +10,7 @@ config AVR32
>  	select GENERIC_IRQ_PROBE
>  	select HARDIRQS_SW_RESEND
>  	select GENERIC_IRQ_SHOW
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select ARCH_HAVE_NMI_SAFE_CMPXCHG
>  	help
>  	  AVR32 is a high-performance 32-bit RISC microprocessor core,
> diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
> index c747629..2c13eef 100644
> --- a/arch/blackfin/Kconfig
> +++ b/arch/blackfin/Kconfig
> @@ -31,6 +31,7 @@ config BLACKFIN
>  	select HAVE_KERNEL_LZO if RAMKERNEL
>  	select HAVE_OPROFILE
>  	select HAVE_PERF_EVENTS
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select ARCH_WANT_OPTIONAL_GPIOLIB
>  	select HAVE_GENERIC_HARDIRQS
>  	select GENERIC_ATOMIC64
> diff --git a/arch/ia64/include/asm/gpio.h b/arch/ia64/include/asm/gpio.h
> deleted file mode 100644
> index 590a20d..0000000
> --- a/arch/ia64/include/asm/gpio.h
> +++ /dev/null
> @@ -1,55 +0,0 @@
> -/*
> - * Generic GPIO API implementation for IA-64.
> - *
> - * A stright copy of that for PowerPC which was:
> - *
> - * Copyright (c) 2007-2008  MontaVista Software, Inc.
> - *
> - * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef _ASM_IA64_GPIO_H
> -#define _ASM_IA64_GPIO_H
> -
> -#include <linux/errno.h>
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * We don't (yet) implement inlined/rapid versions for on-chip gpios.
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return __gpio_to_irq(gpio);
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* _ASM_IA64_GPIO_H */
> diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu
> index e632b2d..d4a818b 100644
> --- a/arch/m68k/Kconfig.cpu
> +++ b/arch/m68k/Kconfig.cpu
> @@ -21,6 +21,7 @@ config MCPU32
>  config COLDFIRE
>  	bool
>  	select GENERIC_GPIO
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select ARCH_REQUIRE_GPIOLIB
>  	select CPU_HAS_NO_BITFIELDS
>  	help
> diff --git a/arch/microblaze/include/asm/gpio.h b/arch/microblaze/include/asm/gpio.h
> deleted file mode 100644
> index 2b2c18b..0000000
> --- a/arch/microblaze/include/asm/gpio.h
> +++ /dev/null
> @@ -1,53 +0,0 @@
> -/*
> - * Generic GPIO API implementation for PowerPC.
> - *
> - * Copyright (c) 2007-2008  MontaVista Software, Inc.
> - *
> - * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef _ASM_MICROBLAZE_GPIO_H
> -#define _ASM_MICROBLAZE_GPIO_H
> -
> -#include <linux/errno.h>
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * We don't (yet) implement inlined/rapid versions for on-chip gpios.
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return __gpio_to_irq(gpio);
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* _ASM_MICROBLAZE_GPIO_H */
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index 62b9677..567290c 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -8,6 +8,7 @@ config MIPS
>  	select HAVE_PERF_EVENTS
>  	select PERF_USE_VMALLOC
>  	select HAVE_ARCH_KGDB
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select HAVE_FUNCTION_TRACER
>  	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
>  	select HAVE_DYNAMIC_FTRACE
> diff --git a/arch/openrisc/include/asm/gpio.h b/arch/openrisc/include/asm/gpio.h
> deleted file mode 100644
> index 0b0d174..0000000
> --- a/arch/openrisc/include/asm/gpio.h
> +++ /dev/null
> @@ -1,65 +0,0 @@
> -/*
> - * OpenRISC Linux
> - *
> - * Linux architectural port borrowing liberally from similar works of
> - * others.  All original copyrights apply as per the original source
> - * declaration.
> - *
> - * OpenRISC implementation:
> - * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
> - * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
> - * et al.
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef __ASM_OPENRISC_GPIO_H
> -#define __ASM_OPENRISC_GPIO_H
> -
> -#include <linux/errno.h>
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * OpenRISC (or1k) does not have on-chip GPIO's so there is not really
> - * any standardized implementation that makes sense here.  If passing
> - * through gpiolib becomes a bottleneck then it may make sense, on a
> - * case-by-case basis, to implement these inlined/rapid versions.
> - *
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -/*
> - * Not implemented, yet.
> - */
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return -ENOSYS;
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* __ASM_OPENRISC_GPIO_H */
> diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h
> deleted file mode 100644
> index 38762ed..0000000
> --- a/arch/powerpc/include/asm/gpio.h
> +++ /dev/null
> @@ -1,53 +0,0 @@
> -/*
> - * Generic GPIO API implementation for PowerPC.
> - *
> - * Copyright (c) 2007-2008  MontaVista Software, Inc.
> - *
> - * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef __ASM_POWERPC_GPIO_H
> -#define __ASM_POWERPC_GPIO_H
> -
> -#include <linux/errno.h>
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * We don't (yet) implement inlined/rapid versions for on-chip gpios.
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return __gpio_to_irq(gpio);
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* __ASM_POWERPC_GPIO_H */
> diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
> index ff9177c..d00e11a 100644
> --- a/arch/sh/Kconfig
> +++ b/arch/sh/Kconfig
> @@ -11,6 +11,7 @@ config SUPERH
>  	select HAVE_DMA_ATTRS
>  	select HAVE_IRQ_WORK
>  	select HAVE_PERF_EVENTS
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
>  	select PERF_USE_VMALLOC
>  	select HAVE_KERNEL_GZIP
> diff --git a/arch/sparc/include/asm/gpio.h b/arch/sparc/include/asm/gpio.h
> deleted file mode 100644
> index a0e3ac0..0000000
> --- a/arch/sparc/include/asm/gpio.h
> +++ /dev/null
> @@ -1,36 +0,0 @@
> -#ifndef __ASM_SPARC_GPIO_H
> -#define __ASM_SPARC_GPIO_H
> -
> -#include <linux/errno.h>
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return -ENOSYS;
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* __ASM_SPARC_GPIO_H */
> diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
> index e57dcce..7bdc7c6 100644
> --- a/arch/unicore32/Kconfig
> +++ b/arch/unicore32/Kconfig
> @@ -8,6 +8,7 @@ config UNICORE32
>  	select HAVE_KERNEL_BZIP2
>  	select HAVE_KERNEL_LZO
>  	select HAVE_KERNEL_LZMA
> +	select ARCH_HAVE_CUSTOM_GPIO_H
>  	select GENERIC_FIND_FIRST_BIT
>  	select GENERIC_IRQ_PROBE
>  	select GENERIC_IRQ_SHOW
> diff --git a/arch/x86/include/asm/gpio.h b/arch/x86/include/asm/gpio.h
> deleted file mode 100644
> index 91d915a..0000000
> --- a/arch/x86/include/asm/gpio.h
> +++ /dev/null
> @@ -1,53 +0,0 @@
> -/*
> - * Generic GPIO API implementation for x86.
> - *
> - * Derived from the generic GPIO API for powerpc:
> - *
> - * Copyright (c) 2007-2008  MontaVista Software, Inc.
> - *
> - * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef _ASM_X86_GPIO_H
> -#define _ASM_X86_GPIO_H
> -
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return __gpio_to_irq(gpio);
> -}
> -
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* _ASM_X86_GPIO_H */
> diff --git a/arch/xtensa/include/asm/gpio.h b/arch/xtensa/include/asm/gpio.h
> deleted file mode 100644
> index a8c9fc4..0000000
> --- a/arch/xtensa/include/asm/gpio.h
> +++ /dev/null
> @@ -1,56 +0,0 @@
> -/*
> - * Generic GPIO API implementation for xtensa.
> - *
> - * Stolen from x86, which is derived from the generic GPIO API for powerpc:
> - *
> - * Copyright (c) 2007-2008  MontaVista Software, Inc.
> - *
> - * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - */
> -
> -#ifndef _ASM_XTENSA_GPIO_H
> -#define _ASM_XTENSA_GPIO_H
> -
> -#include <asm-generic/gpio.h>
> -
> -#ifdef CONFIG_GPIOLIB
> -
> -/*
> - * Just call gpiolib.
> - */
> -static inline int gpio_get_value(unsigned int gpio)
> -{
> -	return __gpio_get_value(gpio);
> -}
> -
> -static inline void gpio_set_value(unsigned int gpio, int value)
> -{
> -	__gpio_set_value(gpio, value);
> -}
> -
> -static inline int gpio_cansleep(unsigned int gpio)
> -{
> -	return __gpio_cansleep(gpio);
> -}
> -
> -static inline int gpio_to_irq(unsigned int gpio)
> -{
> -	return __gpio_to_irq(gpio);
> -}
> -
> -/*
> - * Not implemented, yet.
> - */
> -static inline int irq_to_gpio(unsigned int irq)
> -{
> -	return -EINVAL;
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> -#endif /* _ASM_XTENSA_GPIO_H */
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index a107d44..ef920a2 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -2,6 +2,14 @@
>  # GPIO infrastructure and drivers
>  #
>  
> +config ARCH_HAVE_CUSTOM_GPIO_H
> +	bool
> +	help
> +	  Selecting this config option from the architecture Kconfig allows
> +	  the architecture to provide a custom asm/gpio.h implementation
> +	  overriding the default implementations.  New uses of this are
> +	  strongly discouraged.
> +
>  config ARCH_WANT_OPTIONAL_GPIOLIB
>  	bool
>  	help
> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
> index 38ac48b..3149f68 100644
> --- a/include/linux/gpio.h
> +++ b/include/linux/gpio.h
> @@ -1,6 +1,8 @@
>  #ifndef __LINUX_GPIO_H
>  #define __LINUX_GPIO_H
>  
> +#include <linux/errno.h>
> +
>  /* see Documentation/gpio.txt */
>  
>  /* make these flag values available regardless of GPIO kconfig options */
> @@ -27,7 +29,39 @@ struct gpio {
>  };
>  
>  #ifdef CONFIG_GENERIC_GPIO
> +
> +#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
>  #include <asm/gpio.h>
> +#else
> +
> +#include <asm-generic/gpio.h>
> +
> +static inline int gpio_get_value(unsigned int gpio)
> +{
> +	return __gpio_get_value(gpio);
> +}
> +
> +static inline void gpio_set_value(unsigned int gpio, int value)
> +{
> +	__gpio_set_value(gpio, value);
> +}
> +
> +static inline int gpio_cansleep(unsigned int gpio)
> +{
> +	return __gpio_cansleep(gpio);
> +}
> +
> +static inline int gpio_to_irq(unsigned int gpio)
> +{
> +	return __gpio_to_irq(gpio);
> +}
> +
> +static inline int irq_to_gpio(unsigned int irq)
> +{
> +	return -EINVAL;
> +}
> +
> +#endif
>  
>  #else
>  
> -- 
> 1.7.6.3
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h
@ 2011-10-25  7:33 Mark Brown
  2011-10-25  8:33 ` Grant Likely
  2011-10-25 23:44 ` Mike Frysinger
  0 siblings, 2 replies; 17+ messages in thread
From: Mark Brown @ 2011-10-25  7:33 UTC (permalink / raw)
  To: Russell King, Haavard Skinnemoen, Hans-Christian Egtvedt,
	Mike Frysinger, Geert Uytterhoeven, Ralf Baechle, Paul Mundt,
	Guan Xuetao, Grant Likely
  Cc: linux-arm-kernel, linux-kernel, uclinux-dist-devel, linux-m68k,
	linux-mips, linux-sh, linux-arch, Mark Brown

Rather than requiring architectures that use gpiolib but don't have any
need to define anything custom to copy an asm/gpio.h provide a Kconfig
symbol which architectures must select in order to include gpio.h and
for other architectures just provide the trivial implementation directly.

This makes it much easier to do gpiolib updates and is also a step towards
making gpiolib APIs available on every architecture.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 arch/alpha/include/asm/gpio.h      |   55 ------------------------------
 arch/arm/Kconfig                   |    1 +
 arch/avr32/Kconfig                 |    1 +
 arch/blackfin/Kconfig              |    1 +
 arch/ia64/include/asm/gpio.h       |   55 ------------------------------
 arch/m68k/Kconfig.cpu              |    1 +
 arch/microblaze/include/asm/gpio.h |   53 -----------------------------
 arch/mips/Kconfig                  |    1 +
 arch/openrisc/include/asm/gpio.h   |   65 ------------------------------------
 arch/powerpc/include/asm/gpio.h    |   53 -----------------------------
 arch/sh/Kconfig                    |    1 +
 arch/sparc/include/asm/gpio.h      |   36 --------------------
 arch/unicore32/Kconfig             |    1 +
 arch/x86/include/asm/gpio.h        |   53 -----------------------------
 arch/xtensa/include/asm/gpio.h     |   56 -------------------------------
 drivers/gpio/Kconfig               |    8 ++++
 include/linux/gpio.h               |   34 +++++++++++++++++++
 17 files changed, 49 insertions(+), 426 deletions(-)
 delete mode 100644 arch/alpha/include/asm/gpio.h
 delete mode 100644 arch/ia64/include/asm/gpio.h
 delete mode 100644 arch/microblaze/include/asm/gpio.h
 delete mode 100644 arch/openrisc/include/asm/gpio.h
 delete mode 100644 arch/powerpc/include/asm/gpio.h
 delete mode 100644 arch/sparc/include/asm/gpio.h
 delete mode 100644 arch/x86/include/asm/gpio.h
 delete mode 100644 arch/xtensa/include/asm/gpio.h

diff --git a/arch/alpha/include/asm/gpio.h b/arch/alpha/include/asm/gpio.h
deleted file mode 100644
index 7dc6a63..0000000
--- a/arch/alpha/include/asm/gpio.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Generic GPIO API implementation for Alpha.
- *
- * A stright copy of that for PowerPC which was:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_ALPHA_GPIO_H
-#define _ASM_ALPHA_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_ALPHA_GPIO_H */
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 7e8ffe7..5e0446c 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1,6 +1,7 @@
 config ARM
 	bool
 	default y
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_AOUT
 	select HAVE_DMA_API_DEBUG
 	select HAVE_IDE if PCI || ISA || PCMCIA
diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
index 197e96f..b2e3e58 100644
--- a/arch/avr32/Kconfig
+++ b/arch/avr32/Kconfig
@@ -10,6 +10,7 @@ config AVR32
 	select GENERIC_IRQ_PROBE
 	select HARDIRQS_SW_RESEND
 	select GENERIC_IRQ_SHOW
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	help
 	  AVR32 is a high-performance 32-bit RISC microprocessor core,
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index c747629..2c13eef 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -31,6 +31,7 @@ config BLACKFIN
 	select HAVE_KERNEL_LZO if RAMKERNEL
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_GENERIC_HARDIRQS
 	select GENERIC_ATOMIC64
diff --git a/arch/ia64/include/asm/gpio.h b/arch/ia64/include/asm/gpio.h
deleted file mode 100644
index 590a20d..0000000
--- a/arch/ia64/include/asm/gpio.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Generic GPIO API implementation for IA-64.
- *
- * A stright copy of that for PowerPC which was:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_IA64_GPIO_H
-#define _ASM_IA64_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_IA64_GPIO_H */
diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu
index e632b2d..d4a818b 100644
--- a/arch/m68k/Kconfig.cpu
+++ b/arch/m68k/Kconfig.cpu
@@ -21,6 +21,7 @@ config MCPU32
 config COLDFIRE
 	bool
 	select GENERIC_GPIO
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_REQUIRE_GPIOLIB
 	select CPU_HAS_NO_BITFIELDS
 	help
diff --git a/arch/microblaze/include/asm/gpio.h b/arch/microblaze/include/asm/gpio.h
deleted file mode 100644
index 2b2c18b..0000000
--- a/arch/microblaze/include/asm/gpio.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Generic GPIO API implementation for PowerPC.
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_MICROBLAZE_GPIO_H
-#define _ASM_MICROBLAZE_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_MICROBLAZE_GPIO_H */
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 62b9677..567290c 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -8,6 +8,7 @@ config MIPS
 	select HAVE_PERF_EVENTS
 	select PERF_USE_VMALLOC
 	select HAVE_ARCH_KGDB
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_DYNAMIC_FTRACE
diff --git a/arch/openrisc/include/asm/gpio.h b/arch/openrisc/include/asm/gpio.h
deleted file mode 100644
index 0b0d174..0000000
--- a/arch/openrisc/include/asm/gpio.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * OpenRISC Linux
- *
- * Linux architectural port borrowing liberally from similar works of
- * others.  All original copyrights apply as per the original source
- * declaration.
- *
- * OpenRISC implementation:
- * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
- * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
- * et al.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __ASM_OPENRISC_GPIO_H
-#define __ASM_OPENRISC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * OpenRISC (or1k) does not have on-chip GPIO's so there is not really
- * any standardized implementation that makes sense here.  If passing
- * through gpiolib becomes a bottleneck then it may make sense, on a
- * case-by-case basis, to implement these inlined/rapid versions.
- *
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-/*
- * Not implemented, yet.
- */
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return -ENOSYS;
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_OPENRISC_GPIO_H */
diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h
deleted file mode 100644
index 38762ed..0000000
--- a/arch/powerpc/include/asm/gpio.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Generic GPIO API implementation for PowerPC.
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __ASM_POWERPC_GPIO_H
-#define __ASM_POWERPC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * We don't (yet) implement inlined/rapid versions for on-chip gpios.
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_POWERPC_GPIO_H */
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index ff9177c..d00e11a 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -11,6 +11,7 @@ config SUPERH
 	select HAVE_DMA_ATTRS
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select PERF_USE_VMALLOC
 	select HAVE_KERNEL_GZIP
diff --git a/arch/sparc/include/asm/gpio.h b/arch/sparc/include/asm/gpio.h
deleted file mode 100644
index a0e3ac0..0000000
--- a/arch/sparc/include/asm/gpio.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef __ASM_SPARC_GPIO_H
-#define __ASM_SPARC_GPIO_H
-
-#include <linux/errno.h>
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return -ENOSYS;
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_SPARC_GPIO_H */
diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
index e57dcce..7bdc7c6 100644
--- a/arch/unicore32/Kconfig
+++ b/arch/unicore32/Kconfig
@@ -8,6 +8,7 @@ config UNICORE32
 	select HAVE_KERNEL_BZIP2
 	select HAVE_KERNEL_LZO
 	select HAVE_KERNEL_LZMA
+	select ARCH_HAVE_CUSTOM_GPIO_H
 	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_IRQ_PROBE
 	select GENERIC_IRQ_SHOW
diff --git a/arch/x86/include/asm/gpio.h b/arch/x86/include/asm/gpio.h
deleted file mode 100644
index 91d915a..0000000
--- a/arch/x86/include/asm/gpio.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Generic GPIO API implementation for x86.
- *
- * Derived from the generic GPIO API for powerpc:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_X86_GPIO_H
-#define _ASM_X86_GPIO_H
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_X86_GPIO_H */
diff --git a/arch/xtensa/include/asm/gpio.h b/arch/xtensa/include/asm/gpio.h
deleted file mode 100644
index a8c9fc4..0000000
--- a/arch/xtensa/include/asm/gpio.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Generic GPIO API implementation for xtensa.
- *
- * Stolen from x86, which is derived from the generic GPIO API for powerpc:
- *
- * Copyright (c) 2007-2008  MontaVista Software, Inc.
- *
- * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _ASM_XTENSA_GPIO_H
-#define _ASM_XTENSA_GPIO_H
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-/*
- * Just call gpiolib.
- */
-static inline int gpio_get_value(unsigned int gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned int gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned int gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned int gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-/*
- * Not implemented, yet.
- */
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -EINVAL;
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* _ASM_XTENSA_GPIO_H */
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a107d44..ef920a2 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -2,6 +2,14 @@
 # GPIO infrastructure and drivers
 #
 
+config ARCH_HAVE_CUSTOM_GPIO_H
+	bool
+	help
+	  Selecting this config option from the architecture Kconfig allows
+	  the architecture to provide a custom asm/gpio.h implementation
+	  overriding the default implementations.  New uses of this are
+	  strongly discouraged.
+
 config ARCH_WANT_OPTIONAL_GPIOLIB
 	bool
 	help
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 38ac48b..3149f68 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -1,6 +1,8 @@
 #ifndef __LINUX_GPIO_H
 #define __LINUX_GPIO_H
 
+#include <linux/errno.h>
+
 /* see Documentation/gpio.txt */
 
 /* make these flag values available regardless of GPIO kconfig options */
@@ -27,7 +29,39 @@ struct gpio {
 };
 
 #ifdef CONFIG_GENERIC_GPIO
+
+#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
 #include <asm/gpio.h>
+#else
+
+#include <asm-generic/gpio.h>
+
+static inline int gpio_get_value(unsigned int gpio)
+{
+	return __gpio_get_value(gpio);
+}
+
+static inline void gpio_set_value(unsigned int gpio, int value)
+{
+	__gpio_set_value(gpio, value);
+}
+
+static inline int gpio_cansleep(unsigned int gpio)
+{
+	return __gpio_cansleep(gpio);
+}
+
+static inline int gpio_to_irq(unsigned int gpio)
+{
+	return __gpio_to_irq(gpio);
+}
+
+static inline int irq_to_gpio(unsigned int irq)
+{
+	return -EINVAL;
+}
+
+#endif
 
 #else
 
-- 
1.7.6.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-05-12  0:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-04 15:54 [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h Mark Brown
2012-02-04 17:06 ` Sam Ravnborg
2012-02-04 17:21   ` Mark Brown
2012-02-04 17:41   ` Russell King - ARM Linux
2012-02-06 11:37     ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2012-04-15  9:52 Mark Brown
2012-04-16  7:21 ` Linus Walleij
2012-04-16  8:15   ` Mark Brown
2012-04-16  8:26     ` Linus Walleij
2012-05-12  0:08     ` Grant Likely
2012-04-17 18:49 ` Tony Luck
2011-10-25  7:33 Mark Brown
2011-10-25  8:33 ` Grant Likely
2011-10-25  8:39   ` Mark Brown
2011-10-25 23:44 ` Mike Frysinger
2011-10-26  7:33   ` Mark Brown
2012-02-03 23:16     ` Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).