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

gpiolib: allow user-selection

This patch adds functionality to the gpio-lib subsystem to make it
possible to enable the gpio-lib code even if the architecture code didn't
request to get it built in.

The archtitecture code does still need to implement the gpiolib accessor
functions in its asm/gpio.h file. This patch adds the implementations for
x86 and PPC.

With these changes it is possible to run generic GPIO expansion cards on
every architecture that implements the trivial wrapper functions. Support
for more architectures can easily be added.

Signed-off-by: Michael Buesch <mb@bu3sch.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: David Brownell <david-b@pacbell.net>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Haavard Skinnemoen <hskinnemoen@atmel.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Samuel Ortiz <sameo@openedhand.com>
Cc: Kumar Gala <galak@gate.crashing.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Michael Buesch and committed by
Linus Torvalds
7444a72e ff1d5c2f

+116 -23
+11 -1
Documentation/gpio.txt
··· 389 389 390 390 Platform Support 391 391 ---------------- 392 - To support this framework, a platform's Kconfig will "select HAVE_GPIO_LIB" 392 + To support this framework, a platform's Kconfig will "select" either 393 + ARCH_REQUIRE_GPIOLIB or ARCH_WANT_OPTIONAL_GPIOLIB 393 394 and arrange that its <asm/gpio.h> includes <asm-generic/gpio.h> and defines 394 395 three functions: gpio_get_value(), gpio_set_value(), and gpio_cansleep(). 395 396 They may also want to provide a custom value for ARCH_NR_GPIOS. 397 + 398 + ARCH_REQUIRE_GPIOLIB means that the gpio-lib code will always get compiled 399 + into the kernel on that architecture. 400 + 401 + ARCH_WANT_OPTIONAL_GPIOLIB means the gpio-lib code defaults to off and the user 402 + can enable it and build it into the kernel optionally. 403 + 404 + If neither of these options are selected, the platform does not support 405 + GPIOs through GPIO-lib and the code cannot be enabled by the user. 396 406 397 407 Trivial implementations of those functions can directly use framework 398 408 code, which always dispatches through the gpio_chip:
+4 -4
arch/arm/Kconfig
··· 268 268 select GENERIC_GPIO 269 269 select HAVE_CLK 270 270 select HAVE_CLK 271 - select HAVE_GPIO_LIB 271 + select ARCH_REQUIRE_GPIOLIB 272 272 help 273 273 This enables support for the Cirrus EP93xx series of CPUs. 274 274 ··· 447 447 select ARCH_MTD_XIP 448 448 select GENERIC_GPIO 449 449 select HAVE_CLK 450 - select HAVE_GPIO_LIB 450 + select ARCH_REQUIRE_GPIOLIB 451 451 select GENERIC_TIME 452 452 select GENERIC_CLOCKEVENTS 453 453 select TICK_ONESHOT ··· 479 479 select GENERIC_CLOCKEVENTS 480 480 select HAVE_CLK 481 481 select TICK_ONESHOT 482 - select HAVE_GPIO_LIB 482 + select ARCH_REQUIRE_GPIOLIB 483 483 help 484 484 Support for StrongARM 11x0 based boards. 485 485 ··· 522 522 bool "TI OMAP" 523 523 select GENERIC_GPIO 524 524 select HAVE_CLK 525 - select HAVE_GPIO_LIB 525 + select ARCH_REQUIRE_GPIOLIB 526 526 select GENERIC_TIME 527 527 select GENERIC_CLOCKEVENTS 528 528 help
+1 -1
arch/avr32/Kconfig
··· 88 88 select SUBARCH_AVR32B 89 89 select MMU 90 90 select PERFORMANCE_COUNTERS 91 - select HAVE_GPIO_LIB 91 + select ARCH_REQUIRE_GPIOLIB 92 92 select GENERIC_ALLOCATOR 93 93 94 94 #
+1 -1
arch/mips/Kconfig
··· 713 713 714 714 config GPIO_TXX9 715 715 select GENERIC_GPIO 716 - select HAVE_GPIO_LIB 716 + select ARCH_REQUIRE_GPIOLIB 717 717 bool 718 718 719 719 config CFE
+1
arch/powerpc/Kconfig
··· 110 110 default y 111 111 select HAVE_DYNAMIC_FTRACE 112 112 select HAVE_FTRACE 113 + select ARCH_WANT_OPTIONAL_GPIOLIB 113 114 select HAVE_IDE 114 115 select HAVE_IOREMAP_PROT 115 116 select HAVE_EFFICIENT_UNALIGNED_ACCESS
+1 -1
arch/powerpc/platforms/52xx/Kconfig
··· 48 48 config PPC_MPC5200_GPIO 49 49 bool "MPC5200 GPIO support" 50 50 depends on PPC_MPC52xx 51 - select HAVE_GPIO_LIB 51 + select ARCH_REQUIRE_GPIOLIB 52 52 help 53 53 Enable gpiolib support for mpc5200 based boards
+1 -1
arch/powerpc/sysdev/qe_lib/Kconfig
··· 29 29 bool "QE GPIO support" 30 30 depends on QUICC_ENGINE 31 31 select GENERIC_GPIO 32 - select HAVE_GPIO_LIB 32 + select ARCH_REQUIRE_GPIOLIB 33 33 help 34 34 Say Y here if you're going to use hardware that connects to the 35 35 QE GPIOs.
+1
arch/x86/Kconfig
··· 23 23 select HAVE_OPROFILE 24 24 select HAVE_IOREMAP_PROT 25 25 select HAVE_KPROBES 26 + select ARCH_WANT_OPTIONAL_GPIOLIB if !X86_RDC321X 26 27 select HAVE_KRETPROBES 27 28 select HAVE_DYNAMIC_FTRACE 28 29 select HAVE_FTRACE
+1 -1
drivers/Makefile
··· 5 5 # Rewritten to use lists instead of if-statements. 6 6 # 7 7 8 - obj-$(CONFIG_HAVE_GPIO_LIB) += gpio/ 8 + obj-y += gpio/ 9 9 obj-$(CONFIG_PCI) += pci/ 10 10 obj-$(CONFIG_PARISC) += parisc/ 11 11 obj-$(CONFIG_RAPIDIO) += rapidio/
+29 -4
drivers/gpio/Kconfig
··· 2 2 # GPIO infrastructure and expanders 3 3 # 4 4 5 - config HAVE_GPIO_LIB 5 + config ARCH_WANT_OPTIONAL_GPIOLIB 6 6 bool 7 + help 8 + Select this config option from the architecture Kconfig, if 9 + it is possible to use gpiolib on the architecture, but let the 10 + user decide whether to actually build it or not. 11 + Select this instead of ARCH_REQUIRE_GPIOLIB, if your architecture does 12 + not depend on GPIOs being available, but rather let the user 13 + decide whether he needs it or not. 14 + 15 + config ARCH_REQUIRE_GPIOLIB 16 + bool 17 + select GPIOLIB 7 18 help 8 19 Platforms select gpiolib if they use this infrastructure 9 20 for all their GPIOs, usually starting with ones integrated 10 21 into SOC processors. 22 + Selecting this from the architecture code will cause the gpiolib 23 + code to always get built in. 11 24 12 - menu "GPIO Support" 13 - depends on HAVE_GPIO_LIB 25 + 26 + 27 + menuconfig GPIOLIB 28 + bool "GPIO Support" 29 + depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB 30 + select GENERIC_GPIO 31 + help 32 + This enables GPIO support through the generic GPIO library. 33 + You only need to enable this, if you also want to enable 34 + one or more of the GPIO expansion card drivers below. 35 + 36 + If unsure, say N. 37 + 38 + if GPIOLIB 14 39 15 40 config DEBUG_GPIO 16 41 bool "Debug GPIO calls" ··· 141 116 SPI driver for Microchip MCP23S08 I/O expander. This provides 142 117 a GPIO interface supporting inputs and outputs. 143 118 144 - endmenu 119 + endif
+1 -1
drivers/gpio/Makefile
··· 2 2 3 3 ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG 4 4 5 - obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o 5 + obj-$(CONFIG_GPIOLIB) += gpiolib.o 6 6 7 7 obj-$(CONFIG_GPIO_MAX7301) += max7301.o 8 8 obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
+1 -1
drivers/i2c/chips/Kconfig
··· 126 126 127 127 config TPS65010 128 128 tristate "TPS6501x Power Management chips" 129 - depends on HAVE_GPIO_LIB 129 + depends on GPIOLIB 130 130 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 131 131 help 132 132 If you say yes here you get support for the TPS6501x series of
+2 -2
drivers/mfd/Kconfig
··· 36 36 37 37 config HTC_EGPIO 38 38 bool "HTC EGPIO support" 39 - depends on GENERIC_HARDIRQS && HAVE_GPIO_LIB && ARM 39 + depends on GENERIC_HARDIRQS && GPIOLIB && ARM 40 40 help 41 41 This driver supports the CPLD egpio chip present on 42 42 several HTC phones. It provides basic support for input ··· 52 52 53 53 config MFD_TC6393XB 54 54 bool "Support Toshiba TC6393XB" 55 - depends on HAVE_GPIO_LIB 55 + depends on GPIOLIB 56 56 select MFD_CORE 57 57 help 58 58 Support for Toshiba Mobile IO Controller TC6393XB
+1 -1
drivers/of/Kconfig
··· 4 4 5 5 config OF_GPIO 6 6 def_bool y 7 - depends on OF && PPC_OF && HAVE_GPIO_LIB 7 + depends on OF && PPC_OF && GPIOLIB 8 8 help 9 9 OpenFirmware GPIO accessors 10 10
+1 -1
include/asm-generic/gpio.h
··· 3 3 4 4 #include <linux/types.h> 5 5 6 - #ifdef CONFIG_HAVE_GPIO_LIB 6 + #ifdef CONFIG_GPIOLIB 7 7 8 8 #include <linux/compiler.h> 9 9
+1 -1
include/asm-mips/mach-generic/gpio.h
··· 1 1 #ifndef __ASM_MACH_GENERIC_GPIO_H 2 2 #define __ASM_MACH_GENERIC_GPIO_H 3 3 4 - #ifdef CONFIG_HAVE_GPIO_LIB 4 + #ifdef CONFIG_GPIOLIB 5 5 #define gpio_get_value __gpio_get_value 6 6 #define gpio_set_value __gpio_set_value 7 7 #define gpio_cansleep __gpio_cansleep
+2 -2
include/asm-powerpc/gpio.h
··· 17 17 #include <linux/errno.h> 18 18 #include <asm-generic/gpio.h> 19 19 20 - #ifdef CONFIG_HAVE_GPIO_LIB 20 + #ifdef CONFIG_GPIOLIB 21 21 22 22 /* 23 23 * We don't (yet) implement inlined/rapid versions for on-chip gpios. ··· 51 51 return -EINVAL; 52 52 } 53 53 54 - #endif /* CONFIG_HAVE_GPIO_LIB */ 54 + #endif /* CONFIG_GPIOLIB */ 55 55 56 56 #endif /* __ASM_POWERPC_GPIO_H */
+56
include/asm-x86/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 + 1 16 #ifndef _ASM_I386_GPIO_H 2 17 #define _ASM_I386_GPIO_H 3 18 19 + #ifdef CONFIG_X86_RDC321X 4 20 #include <gpio.h> 21 + #else /* CONFIG_X86_RDC321X */ 22 + 23 + #include <asm-generic/gpio.h> 24 + 25 + #ifdef CONFIG_GPIOLIB 26 + 27 + /* 28 + * Just call gpiolib. 29 + */ 30 + static inline int gpio_get_value(unsigned int gpio) 31 + { 32 + return __gpio_get_value(gpio); 33 + } 34 + 35 + static inline void gpio_set_value(unsigned int gpio, int value) 36 + { 37 + __gpio_set_value(gpio, value); 38 + } 39 + 40 + static inline int gpio_cansleep(unsigned int gpio) 41 + { 42 + return __gpio_cansleep(gpio); 43 + } 44 + 45 + /* 46 + * Not implemented, yet. 47 + */ 48 + static inline int gpio_to_irq(unsigned int gpio) 49 + { 50 + return -ENOSYS; 51 + } 52 + 53 + static inline int irq_to_gpio(unsigned int irq) 54 + { 55 + return -EINVAL; 56 + } 57 + 58 + #endif /* CONFIG_GPIOLIB */ 59 + 60 + #endif /* CONFIG_X86_RDC321X */ 5 61 6 62 #endif /* _ASM_I386_GPIO_H */