Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Jonas Bonn <jonas@southpole.se>
Acked-by: Tony Luck <tony.luck@intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Mark Brown and committed by
Grant Likely
7563bbf8 25cf2507

+81 -426
+4 -55
arch/alpha/include/asm/gpio.h
··· 1 - /* 2 - * Generic GPIO API implementation for Alpha. 3 - * 4 - * A stright copy of that for PowerPC which was: 5 - * 6 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 7 - * 8 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 9 - * 10 - * This program is free software; you can redistribute it and/or modify 11 - * it under the terms of the GNU General Public License as published by 12 - * the Free Software Foundation; either version 2 of the License, or 13 - * (at your option) any later version. 14 - */ 15 - 16 - #ifndef _ASM_ALPHA_GPIO_H 17 - #define _ASM_ALPHA_GPIO_H 18 - 19 - #include <linux/errno.h> 20 - #include <asm-generic/gpio.h> 21 - 22 - #ifdef CONFIG_GPIOLIB 23 - 24 - /* 25 - * We don't (yet) implement inlined/rapid versions for on-chip gpios. 26 - * Just call gpiolib. 27 - */ 28 - static inline int gpio_get_value(unsigned int gpio) 29 - { 30 - return __gpio_get_value(gpio); 31 - } 32 - 33 - static inline void gpio_set_value(unsigned int gpio, int value) 34 - { 35 - __gpio_set_value(gpio, value); 36 - } 37 - 38 - static inline int gpio_cansleep(unsigned int gpio) 39 - { 40 - return __gpio_cansleep(gpio); 41 - } 42 - 43 - static inline int gpio_to_irq(unsigned int gpio) 44 - { 45 - return __gpio_to_irq(gpio); 46 - } 47 - 48 - static inline int irq_to_gpio(unsigned int irq) 49 - { 50 - return -EINVAL; 51 - } 52 - 53 - #endif /* CONFIG_GPIOLIB */ 54 - 55 - #endif /* _ASM_ALPHA_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+1
arch/arm/Kconfig
··· 1 1 config ARM 2 2 bool 3 3 default y 4 + select ARCH_HAVE_CUSTOM_GPIO_H 4 5 select HAVE_AOUT 5 6 select HAVE_DMA_API_DEBUG 6 7 select HAVE_IDE if PCI || ISA || PCMCIA
+1
arch/avr32/Kconfig
··· 11 11 select GENERIC_ATOMIC64 12 12 select HARDIRQS_SW_RESEND 13 13 select GENERIC_IRQ_SHOW 14 + select ARCH_HAVE_CUSTOM_GPIO_H 14 15 select ARCH_HAVE_NMI_SAFE_CMPXCHG 15 16 help 16 17 AVR32 is a high-performance 32-bit RISC microprocessor core,
+1
arch/blackfin/Kconfig
··· 31 31 select HAVE_KERNEL_LZO if RAMKERNEL 32 32 select HAVE_OPROFILE 33 33 select HAVE_PERF_EVENTS 34 + select ARCH_HAVE_CUSTOM_GPIO_H 34 35 select ARCH_WANT_OPTIONAL_GPIOLIB 35 36 select HAVE_GENERIC_HARDIRQS 36 37 select GENERIC_ATOMIC64
+4 -55
arch/ia64/include/asm/gpio.h
··· 1 - /* 2 - * Generic GPIO API implementation for IA-64. 3 - * 4 - * A stright copy of that for PowerPC which was: 5 - * 6 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 7 - * 8 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 9 - * 10 - * This program is free software; you can redistribute it and/or modify 11 - * it under the terms of the GNU General Public License as published by 12 - * the Free Software Foundation; either version 2 of the License, or 13 - * (at your option) any later version. 14 - */ 15 - 16 - #ifndef _ASM_IA64_GPIO_H 17 - #define _ASM_IA64_GPIO_H 18 - 19 - #include <linux/errno.h> 20 - #include <asm-generic/gpio.h> 21 - 22 - #ifdef CONFIG_GPIOLIB 23 - 24 - /* 25 - * We don't (yet) implement inlined/rapid versions for on-chip gpios. 26 - * Just call gpiolib. 27 - */ 28 - static inline int gpio_get_value(unsigned int gpio) 29 - { 30 - return __gpio_get_value(gpio); 31 - } 32 - 33 - static inline void gpio_set_value(unsigned int gpio, int value) 34 - { 35 - __gpio_set_value(gpio, value); 36 - } 37 - 38 - static inline int gpio_cansleep(unsigned int gpio) 39 - { 40 - return __gpio_cansleep(gpio); 41 - } 42 - 43 - static inline int gpio_to_irq(unsigned int gpio) 44 - { 45 - return __gpio_to_irq(gpio); 46 - } 47 - 48 - static inline int irq_to_gpio(unsigned int irq) 49 - { 50 - return -EINVAL; 51 - } 52 - 53 - #endif /* CONFIG_GPIOLIB */ 54 - 55 - #endif /* _ASM_IA64_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+1
arch/m68k/Kconfig.cpu
··· 24 24 bool "Coldfire CPU family support" 25 25 select GENERIC_GPIO 26 26 select ARCH_REQUIRE_GPIOLIB 27 + select ARCH_HAVE_CUSTOM_GPIO_H 27 28 select CPU_HAS_NO_BITFIELDS 28 29 select CPU_HAS_NO_MULDIV64 29 30 select GENERIC_CSUM
+4 -53
arch/microblaze/include/asm/gpio.h
··· 1 - /* 2 - * Generic GPIO API implementation for PowerPC. 3 - * 4 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 5 - * 6 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; either version 2 of the License, or 11 - * (at your option) any later version. 12 - */ 13 - 14 - #ifndef _ASM_MICROBLAZE_GPIO_H 15 - #define _ASM_MICROBLAZE_GPIO_H 16 - 17 - #include <linux/errno.h> 18 - #include <asm-generic/gpio.h> 19 - 20 - #ifdef CONFIG_GPIOLIB 21 - 22 - /* 23 - * We don't (yet) implement inlined/rapid versions for on-chip gpios. 24 - * Just call gpiolib. 25 - */ 26 - static inline int gpio_get_value(unsigned int gpio) 27 - { 28 - return __gpio_get_value(gpio); 29 - } 30 - 31 - static inline void gpio_set_value(unsigned int gpio, int value) 32 - { 33 - __gpio_set_value(gpio, value); 34 - } 35 - 36 - static inline int gpio_cansleep(unsigned int gpio) 37 - { 38 - return __gpio_cansleep(gpio); 39 - } 40 - 41 - static inline int gpio_to_irq(unsigned int gpio) 42 - { 43 - return __gpio_to_irq(gpio); 44 - } 45 - 46 - static inline int irq_to_gpio(unsigned int irq) 47 - { 48 - return -EINVAL; 49 - } 50 - 51 - #endif /* CONFIG_GPIOLIB */ 52 - 53 - #endif /* _ASM_MICROBLAZE_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+1
arch/mips/Kconfig
··· 8 8 select HAVE_PERF_EVENTS 9 9 select PERF_USE_VMALLOC 10 10 select HAVE_ARCH_KGDB 11 + select ARCH_HAVE_CUSTOM_GPIO_H 11 12 select HAVE_FUNCTION_TRACER 12 13 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 13 14 select HAVE_DYNAMIC_FTRACE
+4 -65
arch/openrisc/include/asm/gpio.h
··· 1 - /* 2 - * OpenRISC Linux 3 - * 4 - * Linux architectural port borrowing liberally from similar works of 5 - * others. All original copyrights apply as per the original source 6 - * declaration. 7 - * 8 - * OpenRISC implementation: 9 - * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> 10 - * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> 11 - * et al. 12 - * 13 - * This program is free software; you can redistribute it and/or modify 14 - * it under the terms of the GNU General Public License as published by 15 - * the Free Software Foundation; either version 2 of the License, or 16 - * (at your option) any later version. 17 - */ 18 - 19 - #ifndef __ASM_OPENRISC_GPIO_H 20 - #define __ASM_OPENRISC_GPIO_H 21 - 22 - #include <linux/errno.h> 23 - #include <asm-generic/gpio.h> 24 - 25 - #ifdef CONFIG_GPIOLIB 26 - 27 - /* 28 - * OpenRISC (or1k) does not have on-chip GPIO's so there is not really 29 - * any standardized implementation that makes sense here. If passing 30 - * through gpiolib becomes a bottleneck then it may make sense, on a 31 - * case-by-case basis, to implement these inlined/rapid versions. 32 - * 33 - * Just call gpiolib. 34 - */ 35 - static inline int gpio_get_value(unsigned int gpio) 36 - { 37 - return __gpio_get_value(gpio); 38 - } 39 - 40 - static inline void gpio_set_value(unsigned int gpio, int value) 41 - { 42 - __gpio_set_value(gpio, value); 43 - } 44 - 45 - static inline int gpio_cansleep(unsigned int gpio) 46 - { 47 - return __gpio_cansleep(gpio); 48 - } 49 - 50 - /* 51 - * Not implemented, yet. 52 - */ 53 - static inline int gpio_to_irq(unsigned int gpio) 54 - { 55 - return -ENOSYS; 56 - } 57 - 58 - static inline int irq_to_gpio(unsigned int irq) 59 - { 60 - return -EINVAL; 61 - } 62 - 63 - #endif /* CONFIG_GPIOLIB */ 64 - 65 - #endif /* __ASM_OPENRISC_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+4 -53
arch/powerpc/include/asm/gpio.h
··· 1 - /* 2 - * Generic GPIO API implementation for PowerPC. 3 - * 4 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 5 - * 6 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; either version 2 of the License, or 11 - * (at your option) any later version. 12 - */ 13 - 14 - #ifndef __ASM_POWERPC_GPIO_H 15 - #define __ASM_POWERPC_GPIO_H 16 - 17 - #include <linux/errno.h> 18 - #include <asm-generic/gpio.h> 19 - 20 - #ifdef CONFIG_GPIOLIB 21 - 22 - /* 23 - * We don't (yet) implement inlined/rapid versions for on-chip gpios. 24 - * Just call gpiolib. 25 - */ 26 - static inline int gpio_get_value(unsigned int gpio) 27 - { 28 - return __gpio_get_value(gpio); 29 - } 30 - 31 - static inline void gpio_set_value(unsigned int gpio, int value) 32 - { 33 - __gpio_set_value(gpio, value); 34 - } 35 - 36 - static inline int gpio_cansleep(unsigned int gpio) 37 - { 38 - return __gpio_cansleep(gpio); 39 - } 40 - 41 - static inline int gpio_to_irq(unsigned int gpio) 42 - { 43 - return __gpio_to_irq(gpio); 44 - } 45 - 46 - static inline int irq_to_gpio(unsigned int irq) 47 - { 48 - return -EINVAL; 49 - } 50 - 51 - #endif /* CONFIG_GPIOLIB */ 52 - 53 - #endif /* __ASM_POWERPC_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+1
arch/sh/Kconfig
··· 13 13 select HAVE_DMA_ATTRS 14 14 select HAVE_IRQ_WORK 15 15 select HAVE_PERF_EVENTS 16 + select ARCH_HAVE_CUSTOM_GPIO_H 16 17 select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A) 17 18 select PERF_USE_VMALLOC 18 19 select HAVE_KERNEL_GZIP
+4 -36
arch/sparc/include/asm/gpio.h
··· 1 - #ifndef __ASM_SPARC_GPIO_H 2 - #define __ASM_SPARC_GPIO_H 3 - 4 - #include <linux/errno.h> 5 - #include <asm-generic/gpio.h> 6 - 7 - #ifdef CONFIG_GPIOLIB 8 - 9 - static inline int gpio_get_value(unsigned int gpio) 10 - { 11 - return __gpio_get_value(gpio); 12 - } 13 - 14 - static inline void gpio_set_value(unsigned int gpio, int value) 15 - { 16 - __gpio_set_value(gpio, value); 17 - } 18 - 19 - static inline int gpio_cansleep(unsigned int gpio) 20 - { 21 - return __gpio_cansleep(gpio); 22 - } 23 - 24 - static inline int gpio_to_irq(unsigned int gpio) 25 - { 26 - return -ENOSYS; 27 - } 28 - 29 - static inline int irq_to_gpio(unsigned int irq) 30 - { 31 - return -EINVAL; 32 - } 33 - 34 - #endif /* CONFIG_GPIOLIB */ 35 - 36 - #endif /* __ASM_SPARC_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+1
arch/unicore32/Kconfig
··· 8 8 select HAVE_KERNEL_BZIP2 9 9 select HAVE_KERNEL_LZO 10 10 select HAVE_KERNEL_LZMA 11 + select ARCH_HAVE_CUSTOM_GPIO_H 11 12 select GENERIC_FIND_FIRST_BIT 12 13 select GENERIC_IRQ_PROBE 13 14 select GENERIC_IRQ_SHOW
+4 -53
arch/x86/include/asm/gpio.h
··· 1 - /* 2 - * Generic GPIO API implementation for x86. 3 - * 4 - * Derived from the generic GPIO API for powerpc: 5 - * 6 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 7 - * 8 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 9 - * 10 - * This program is free software; you can redistribute it and/or modify 11 - * it under the terms of the GNU General Public License as published by 12 - * the Free Software Foundation; either version 2 of the License, or 13 - * (at your option) any later version. 14 - */ 15 - 16 - #ifndef _ASM_X86_GPIO_H 17 - #define _ASM_X86_GPIO_H 18 - 19 - #include <asm-generic/gpio.h> 20 - 21 - #ifdef CONFIG_GPIOLIB 22 - 23 - /* 24 - * Just call gpiolib. 25 - */ 26 - static inline int gpio_get_value(unsigned int gpio) 27 - { 28 - return __gpio_get_value(gpio); 29 - } 30 - 31 - static inline void gpio_set_value(unsigned int gpio, int value) 32 - { 33 - __gpio_set_value(gpio, value); 34 - } 35 - 36 - static inline int gpio_cansleep(unsigned int gpio) 37 - { 38 - return __gpio_cansleep(gpio); 39 - } 40 - 41 - static inline int gpio_to_irq(unsigned int gpio) 42 - { 43 - return __gpio_to_irq(gpio); 44 - } 45 - 46 - static inline int irq_to_gpio(unsigned int irq) 47 - { 48 - return -EINVAL; 49 - } 50 - 51 - #endif /* CONFIG_GPIOLIB */ 52 - 53 - #endif /* _ASM_X86_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+4 -56
arch/xtensa/include/asm/gpio.h
··· 1 - /* 2 - * Generic GPIO API implementation for xtensa. 3 - * 4 - * Stolen from x86, which is derived from the generic GPIO API for powerpc: 5 - * 6 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 7 - * 8 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 9 - * 10 - * This program is free software; you can redistribute it and/or modify 11 - * it under the terms of the GNU General Public License as published by 12 - * the Free Software Foundation; either version 2 of the License, or 13 - * (at your option) any later version. 14 - */ 15 - 16 - #ifndef _ASM_XTENSA_GPIO_H 17 - #define _ASM_XTENSA_GPIO_H 18 - 19 - #include <asm-generic/gpio.h> 20 - 21 - #ifdef CONFIG_GPIOLIB 22 - 23 - /* 24 - * Just call gpiolib. 25 - */ 26 - static inline int gpio_get_value(unsigned int gpio) 27 - { 28 - return __gpio_get_value(gpio); 29 - } 30 - 31 - static inline void gpio_set_value(unsigned int gpio, int value) 32 - { 33 - __gpio_set_value(gpio, value); 34 - } 35 - 36 - static inline int gpio_cansleep(unsigned int gpio) 37 - { 38 - return __gpio_cansleep(gpio); 39 - } 40 - 41 - static inline int gpio_to_irq(unsigned int gpio) 42 - { 43 - return __gpio_to_irq(gpio); 44 - } 45 - 46 - /* 47 - * Not implemented, yet. 48 - */ 49 - static inline int irq_to_gpio(unsigned int irq) 50 - { 51 - return -EINVAL; 52 - } 53 - 54 - #endif /* CONFIG_GPIOLIB */ 55 - 56 - #endif /* _ASM_XTENSA_GPIO_H */ 1 + #ifndef __LINUX_GPIO_H 2 + #warning Include linux/gpio.h instead of asm/gpio.h 3 + #include <linux/gpio.h> 4 + #endif
+8
drivers/gpio/Kconfig
··· 2 2 # GPIO infrastructure and drivers 3 3 # 4 4 5 + config ARCH_HAVE_CUSTOM_GPIO_H 6 + bool 7 + help 8 + Selecting this config option from the architecture Kconfig allows 9 + the architecture to provide a custom asm/gpio.h implementation 10 + overriding the default implementations. New uses of this are 11 + strongly discouraged. 12 + 5 13 config ARCH_WANT_OPTIONAL_GPIOLIB 6 14 bool 7 15 help
+34
include/linux/gpio.h
··· 1 1 #ifndef __LINUX_GPIO_H 2 2 #define __LINUX_GPIO_H 3 3 4 + #include <linux/errno.h> 5 + 4 6 /* see Documentation/gpio.txt */ 5 7 6 8 /* make these flag values available regardless of GPIO kconfig options */ ··· 40 38 }; 41 39 42 40 #ifdef CONFIG_GENERIC_GPIO 41 + 42 + #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H 43 43 #include <asm/gpio.h> 44 + #else 45 + 46 + #include <asm-generic/gpio.h> 47 + 48 + static inline int gpio_get_value(unsigned int gpio) 49 + { 50 + return __gpio_get_value(gpio); 51 + } 52 + 53 + static inline void gpio_set_value(unsigned int gpio, int value) 54 + { 55 + __gpio_set_value(gpio, value); 56 + } 57 + 58 + static inline int gpio_cansleep(unsigned int gpio) 59 + { 60 + return __gpio_cansleep(gpio); 61 + } 62 + 63 + static inline int gpio_to_irq(unsigned int gpio) 64 + { 65 + return __gpio_to_irq(gpio); 66 + } 67 + 68 + static inline int irq_to_gpio(unsigned int irq) 69 + { 70 + return -EINVAL; 71 + } 72 + 73 + #endif 44 74 45 75 #else 46 76