gpiolib/arches: Centralise bolierplate asm/gpio.h
Subsystems (13)
PATCH 1/1 gpiolib/arches: Centralise bolierplate asm/gpio.h
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.
---
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(-)
arch/alpha/include/asm/gpio.h +4 -55
@@ -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 <[email protected]> -* -* 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
arch/arm/Kconfig +1 -0
@@ -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
arch/avr32/Kconfig +1 -0
@@ -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,
arch/blackfin/Kconfig +1 -0
@@ -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
arch/ia64/include/asm/gpio.h +4 -55
59 lines not on this page · raw message
arch/m68k/Kconfig.cpu +1 -0
@@ -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
arch/microblaze/include/asm/gpio.h +4 -53
57 lines not on this page · raw message
arch/mips/Kconfig +1 -0
@@ -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
arch/openrisc/include/asm/gpio.h +4 -65
69 lines not on this page · raw message
arch/powerpc/include/asm/gpio.h +4 -53
57 lines not on this page · raw message
arch/sh/Kconfig +1 -0
@@ -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
arch/sparc/include/asm/gpio.h +4 -36
@@ -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
arch/unicore32/Kconfig +1 -0
@@ -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
arch/x86/include/asm/gpio.h +4 -53
57 lines not on this page · raw message
arch/xtensa/include/asm/gpio.h +4 -56
60 lines not on this page · raw message
drivers/gpio/Kconfig +8 -0
@@ -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
include/linux/gpio.h +34 -0
@@ -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
Signature · 1 line
1.7.9.rc1
Quoted 4 lines · Mark Brown
Rather than requiring architectures that use gpiolib but don't have any need to define anything custom to copy an
asm/gpio.hprovide aKconfigsymbol which architectures must select in order to includegpio.hand 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
Quoted 11 lines · Sam Ravnborg
There is an even simpler solution.
For each arch that uses
asm-generic/gpio.hadd a line toarch/$ARCH/include/asm/Kbuildlike this:generic-y += gpio.hThis 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.
Quoted 10 lines · Sam Ravnborg
Quoted 4 lines · Mark Brown
Rather than requiring architectures that use gpiolib but don't have any need to define anything custom to copy an
asm/gpio.hprovide aKconfigsymbol which architectures must select in order to includegpio.hand for other architectures just provide the trivial implementation directly.Hi Mark.
There is an even simpler solution.
Quoted 8 lines
For each arch that uses
asm-generic/gpio.hadd a line toarch/$ARCH/include/asm/Kbuildlike this:generic-y += gpio.hThis 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.)
Quoted 10 lines · Sam Ravnborg
Quoted 4 lines · Mark Brown
Rather than requiring architectures that use gpiolib but don't have any need to define anything custom to copy an
asm/gpio.hprovide aKconfigsymbol which architectures must select in order to includegpio.hand for other architectures just provide the trivial implementation directly.Hi Mark.
There is an even simpler solution.
Quoted 8 lines
For each arch that uses
asm-generic/gpio.hadd a line toarch/$ARCH/include/asm/Kbuildlike this:generic-y += gpio.hThis 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.)
Quoted 3 lines · Russell King - ARM Linux
What's platform specific about
asm/gpio.his the number of GPIOs in the system, and whether it wants to intercept thegpio_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.
Quoted 9 lines
What I'd suggest is moving
asm-generic/gpio.htolinux/gpiolib.h, and makingasm-generic/gpio.hinclude that as a patch until stuff is fixed for its new location. That should result in a properasm-generic/gpio.hbeing:Alternatively, instead of
linux/gpiolib.h, put it inlinux/gpio.hinstead, but that gets more icky because of the mess ofasm/gpio.hincludes (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.
Quoted 3 lines · Russell King - ARM Linux
What's platform specific about
asm/gpio.his the number of GPIOs in the system, and whether it wants to intercept thegpio_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.
Quoted 9 lines
What I'd suggest is moving
asm-generic/gpio.htolinux/gpiolib.h, and makingasm-generic/gpio.hinclude that as a patch until stuff is fixed for its new location. That should result in a properasm-generic/gpio.hbeing:Alternatively, instead of
linux/gpiolib.h, put it inlinux/gpio.hinstead, but that gets more icky because of the mess ofasm/gpio.hincludes (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.