Skip to contentSkip to conversation

gpiolib: Allow user-selection

PATCH Superseded Michael Buesch 2 participants 5 messages Jul 3, 2008 – Jul 6, 2008

Subsystems (10)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---

This patch should be scheduled for the next kernel feature merge window. This is diffed against current linux-next. Compiletested on x86 and powerpc. Runtime tested on x86.

arch/x86/Kconfig +1 -0
Index: linux-next/arch/x86/Kconfig
===================================================================
@@ -27,6 +27,7 @@
 	select HAVE_FTRACE
 	select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
 	select HAVE_ARCH_KGDB if !X86_VOYAGER
+	select ARCH_WANT_OPTIONAL_GPIOLIB if !X86_RDC321X
 
 config ARCH_DEFCONFIG
 	string
include/asm-x86/gpio.h +56 -0

62 lines not on this page · raw message

arch/powerpc/Kconfig +1 -0
Index: linux-next/arch/powerpc/Kconfig
===================================================================
@@ -113,6 +113,7 @@
 	select HAVE_LMB
 	select USE_GENERIC_SMP_HELPERS if SMP
 	select HAVE_OPROFILE
+	select ARCH_WANT_OPTIONAL_GPIOLIB
 
 config EARLY_PRINTK
 	bool
drivers/gpio/Kconfig +29 -4
Index: linux-next/drivers/gpio/Kconfig
===================================================================
@@ -2,15 +2,40 @@
 # GPIO infrastructure and expanders
 #
 
-config HAVE_GPIO_LIB
+config ARCH_WANT_OPTIONAL_GPIOLIB
 	bool
 	help
+	  Select this config option from the architecture Kconfig, if
+	  it is possible to use gpiolib on the architecture, but let the
+	  user decide whether to actually build it or not.
+	  Select this instead of ARCH_REQUIRE_GPIOLIB, if your architecture does
+	  not depend on GPIOs being available, but rather let the user
+	  decide whether he needs it or not.
+
+config ARCH_REQUIRE_GPIOLIB
+	bool
+	select GPIOLIB
+	help
 	  Platforms select gpiolib if they use this infrastructure
 	  for all their GPIOs, usually starting with ones integrated
 	  into SOC processors.
+	  Selecting this from the architecture code will cause the gpiolib
+	  code to always get built in.
+
+
+
+menuconfig GPIOLIB
+	bool "GPIO Support"
+	depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB
+	select GENERIC_GPIO
+	help
+	  This enables GPIO support through the generic GPIO library.
+	  You only need to enable this, if you also want to enable
+	  one or more of the GPIO expansion card drivers below.
+
+	  If unsure, say N.
 
-menu "GPIO Support"
-	depends on HAVE_GPIO_LIB
+if GPIOLIB
 
 config DEBUG_GPIO
 	bool "Debug GPIO calls"
@@ -70,4 +95,4 @@
 	  SPI driver for Microchip MCP23S08 I/O expander.  This provides
 	  a GPIO interface supporting inputs and outputs.
 
-endmenu
+endif
drivers/gpio/Makefile +1 -1
Index: linux-next/drivers/gpio/Makefile
===================================================================
@@ -2,7 +2,7 @@
 
 ccflags-$(CONFIG_DEBUG_GPIO)	+= -DDEBUG
 
-obj-$(CONFIG_HAVE_GPIO_LIB)	+= gpiolib.o
+obj-$(CONFIG_GPIOLIB)		+= gpiolib.o
 
 obj-$(CONFIG_GPIO_MCP23S08)	+= mcp23s08.o
 obj-$(CONFIG_GPIO_PCA953X)	+= pca953x.o
Documentation/gpio.txt +11 -1
Index: linux-next/Documentation/gpio.txt
===================================================================
@@ -392,11 +392,21 @@
 
 Platform Support
 ----------------
-To support this framework, a platform's Kconfig will "select HAVE_GPIO_LIB"
+To support this framework, a platform's Kconfig will "select" either
+ARCH_REQUIRE_GPIOLIB or ARCH_WANT_OPTIONAL_GPIOLIB
 and arrange that its <asm/gpio.h> includes <asm-generic/gpio.h> and defines
 three functions: gpio_get_value(), gpio_set_value(), and gpio_cansleep().
 They may also want to provide a custom value for ARCH_NR_GPIOS.
 
+ARCH_REQUIRE_GPIOLIB means that the gpio-lib code will always get compiled
+into the kernel on that architecture.
+
+ARCH_WANT_OPTIONAL_GPIOLIB means the gpio-lib code defaults to off and the user
+can enable it and build it into the kernel optionally.
+
+If neither of these options are selected, the platform does not support
+GPIOs through GPIO-lib and the code cannot be enabled by the user.
+
 Trivial implementations of those functions can directly use framework
 code, which always dispatches through the gpio_chip:
 
arch/arm/Kconfig +4 -4
Index: linux-next/arch/arm/Kconfig
===================================================================
@@ -262,7 +262,7 @@
 	select ARM_AMBA
 	select ARM_VIC
 	select GENERIC_GPIO
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	help
 	  This enables support for the Cirrus EP93xx series of CPUs.
 
@@ -430,7 +430,7 @@
 	depends on MMU
 	select ARCH_MTD_XIP
 	select GENERIC_GPIO
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
@@ -460,7 +460,7 @@
 	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	help
 	  Support for StrongARM 11x0 based boards.
 
@@ -500,7 +500,7 @@
 config ARCH_OMAP
 	bool "TI OMAP"
 	select GENERIC_GPIO
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
arch/arm/configs/am200epdkit_defconfig +1 -1
Index: linux-next/arch/arm/configs/am200epdkit_defconfig
===================================================================
@@ -668,7 +668,7 @@
 #
 # CONFIG_SPI is not set
 # CONFIG_SPI_MASTER is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/avr32/Kconfig +1 -1
Index: linux-next/arch/avr32/Kconfig
===================================================================
@@ -87,7 +87,7 @@
 	select SUBARCH_AVR32B
 	select MMU
 	select PERFORMANCE_COUNTERS
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	select GENERIC_ALLOCATOR
 
 #
arch/avr32/configs/atngw100_defconfig +1 -1
Index: linux-next/arch/avr32/configs/atngw100_defconfig
===================================================================
@@ -646,7 +646,7 @@
 # CONFIG_SPI_AT25 is not set
 CONFIG_SPI_SPIDEV=m
 # CONFIG_SPI_TLE62X0 is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/avr32/configs/atstk1002_defconfig +1 -1
Index: linux-next/arch/avr32/configs/atstk1002_defconfig
===================================================================
@@ -664,7 +664,7 @@
 # CONFIG_SPI_AT25 is not set
 CONFIG_SPI_SPIDEV=m
 # CONFIG_SPI_TLE62X0 is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/avr32/configs/atstk1003_defconfig +1 -1
Index: linux-next/arch/avr32/configs/atstk1003_defconfig
===================================================================
@@ -614,7 +614,7 @@
 # CONFIG_SPI_AT25 is not set
 CONFIG_SPI_SPIDEV=m
 # CONFIG_SPI_TLE62X0 is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/avr32/configs/atstk1004_defconfig +1 -1
Index: linux-next/arch/avr32/configs/atstk1004_defconfig
===================================================================
@@ -390,7 +390,7 @@
 # CONFIG_SPI_AT25 is not set
 # CONFIG_SPI_SPIDEV is not set
 # CONFIG_SPI_TLE62X0 is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/mips/Kconfig +1 -1
Index: linux-next/arch/mips/Kconfig
===================================================================
@@ -800,7 +800,7 @@
 
 config GPIO_TXX9
 	select GENERIC_GPIO
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	bool
 
 config CFE
arch/powerpc/platforms/52xx/Kconfig +1 -1
Index: linux-next/arch/powerpc/platforms/52xx/Kconfig
===================================================================
@@ -47,6 +47,6 @@
 config PPC_MPC5200_GPIO
 	bool "MPC5200 GPIO support"
 	depends on PPC_MPC52xx
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	help
 	  Enable gpiolib support for mpc5200 based boards
drivers/Makefile +1 -1
Index: linux-next/drivers/Makefile
===================================================================
@@ -5,7 +5,7 @@
 # Rewritten to use lists instead of if-statements.
 #
 
-obj-$(CONFIG_HAVE_GPIO_LIB)	+= gpio/
+obj-y				+= gpio/
 obj-$(CONFIG_PCI)		+= pci/
 obj-$(CONFIG_PARISC)		+= parisc/
 obj-$(CONFIG_RAPIDIO)		+= rapidio/
drivers/i2c/chips/Kconfig +1 -1
Index: linux-next/drivers/i2c/chips/Kconfig
===================================================================
@@ -126,7 +126,7 @@
 
 config TPS65010
 	tristate "TPS6501x Power Management chips"
-	depends on HAVE_GPIO_LIB
+	depends on GPIOLIB
 	default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
 	help
 	  If you say yes here you get support for the TPS6501x series of
drivers/mfd/Kconfig +2 -2
Index: linux-next/drivers/mfd/Kconfig
===================================================================
@@ -28,7 +28,7 @@
 
 config HTC_EGPIO
 	bool "HTC EGPIO support"
-	depends on GENERIC_HARDIRQS && HAVE_GPIO_LIB && ARM
+	depends on GENERIC_HARDIRQS && GPIOLIB && ARM
 	help
 	    This driver supports the CPLD egpio chip present on
 	    several HTC phones.  It provides basic support for input
@@ -44,7 +44,7 @@
 
 config MFD_TC6393XB
 	bool "Support Toshiba TC6393XB"
-	depends on HAVE_GPIO_LIB
+	depends on GPIOLIB
 	select MFD_CORE
 	help
 	  Support for Toshiba Mobile IO Controller TC6393XB
drivers/of/Kconfig +1 -1
Index: linux-next/drivers/of/Kconfig
===================================================================
@@ -4,7 +4,7 @@
 
 config OF_GPIO
 	def_bool y
-	depends on OF && PPC_OF && HAVE_GPIO_LIB
+	depends on OF && PPC_OF && GPIOLIB
 	help
 	  OpenFirmware GPIO accessors
 
include/asm-generic/gpio.h +1 -1
Index: linux-next/include/asm-generic/gpio.h
===================================================================
@@ -3,7 +3,7 @@
 
 #include <linux/types.h>
 
-#ifdef CONFIG_HAVE_GPIO_LIB
+#ifdef CONFIG_GPIOLIB
 
 #include <linux/compiler.h>
 
include/asm-mips/mach-generic/gpio.h +1 -1
Index: linux-next/include/asm-mips/mach-generic/gpio.h
===================================================================
@@ -1,7 +1,7 @@
 #ifndef __ASM_MACH_GENERIC_GPIO_H
 #define __ASM_MACH_GENERIC_GPIO_H
 
-#ifdef CONFIG_HAVE_GPIO_LIB
+#ifdef CONFIG_GPIOLIB
 #define gpio_get_value	__gpio_get_value
 #define gpio_set_value	__gpio_set_value
 #define gpio_cansleep	__gpio_cansleep
include/asm-powerpc/gpio.h +2 -2
Index: linux-next/include/asm-powerpc/gpio.h
===================================================================
@@ -17,7 +17,7 @@
 #include <linux/errno.h>
 #include <asm-generic/gpio.h>
 
-#ifdef CONFIG_HAVE_GPIO_LIB
+#ifdef CONFIG_GPIOLIB
 
 /*
  * We don't (yet) implement inlined/rapid versions for on-chip gpios.
@@ -51,6 +51,6 @@
 	return -EINVAL;
 }
 
-#endif /* CONFIG_HAVE_GPIO_LIB */
+#endif /* CONFIG_GPIOLIB */
 
 #endif /* __ASM_POWERPC_GPIO_H */
arch/arm/configs/xm_x270_defconfig +1 -1
Index: linux-next/arch/arm/configs/xm_x270_defconfig
===================================================================
@@ -970,7 +970,7 @@
 # CONFIG_I2C_DEBUG_BUS is not set
 # CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/powerpc/configs/83xx/mpc836x_rdk_defconfig +1 -1
Index: linux-next/arch/powerpc/configs/83xx/mpc836x_rdk_defconfig
===================================================================
@@ -703,7 +703,7 @@
 # CONFIG_SPI_AT25 is not set
 CONFIG_SPI_SPIDEV=y
 # CONFIG_SPI_TLE62X0 is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
 
 #
 # GPIO Support
arch/powerpc/sysdev/qe_lib/Kconfig +1 -1
Index: linux-next/arch/powerpc/sysdev/qe_lib/Kconfig
===================================================================
@@ -29,7 +29,7 @@
 	bool "QE GPIO support"
 	depends on QUICC_ENGINE
 	select GENERIC_GPIO
-	select HAVE_GPIO_LIB
+	select ARCH_REQUIRE_GPIOLIB
 	help
 	  Say Y here if you're going to use hardware that connects to the
 	  QE GPIOs.
Signature · 1 line
Greetings Michael.
#1 lore raw
Quoted 31 lines · Michael Buesch

...

drivers/gpio/Kconfig +18 -1
@@ -2,15 +2,40 @@
 # GPIO infrastructure and expanders
 #
 
-config HAVE_GPIO_LIB
+config ARCH_WANT_OPTIONAL_GPIOLIB
 	bool
 	help
+	  Select this config option from the architecture Kconfig, if
+	  it is possible to use gpiolib on the architecture, but let the
+	  user decide whether to actually build it or not.
+	  Select this instead of ARCH_REQUIRE_GPIOLIB, if your architecture does
+	  not depend on GPIOs being available, but rather let the user
+	  decide whether he needs it or not.
+
+config ARCH_REQUIRE_GPIOLIB
+	bool
+	select GPIOLIB
+	help
 	  Platforms select gpiolib if they use this infrastructure
 	  for all their GPIOs, usually starting with ones integrated
 	  into SOC processors.
+	  Selecting this from the architecture code will cause the gpiolib
+	  code to always get built in.
+
+
+
+menuconfig GPIOLIB

drivers/gpio/Kconfig line 36

Quoted 10 lines
drivers/gpio/Kconfig +9 -0
+	bool "GPIO Support"
+	depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB
+	select GENERIC_GPIO
+	help
+	  This enables GPIO support through the generic GPIO library.
+	  You only need to enable this, if you also want to enable
+	  one or more of the GPIO expansion card drivers below.
+
+	  If unsure, say N.
...

The implementation of ARCH_REQUIRE_GPIOLIB does not match the description.

Matching the description would be:

menuconfig GPIOLIB

        bool "GPIO Support" if !ARCH_REQUIRE_GPIOLIB
        depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB
        default ARCH_REQUIRE_GPIOLIB
        select GENERIC_GPIO
        help
          ...

arch/arm/configs/am200epdkit_defconfig line 671

Quoted 9 lines
arch/arm/configs/am200epdkit_defconfig +1 -1
@@ -668,7 +668,7 @@
 #
 # CONFIG_SPI is not set
 # CONFIG_SPI_MASTER is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
...

Please don't do this kind of defconfig updates - it doesn't bring any advantage but can create tons of patch conflicts.

The next time a defconfig gets updated it will anyway automatically be fixed, and for defconfigs that aren't updated it doesn't create any problems to keep them as they are today until they might one day get updated.

Quoted 1 line

Greetings Michael.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#2 lore raw
Quoted 16 lines · On Sunday 06 July 2008 21:52:12 Adrian Bunk wrote:

drivers/gpio/Kconfig line 36

Quoted 11 lines
drivers/gpio/Kconfig +10 -0
+menuconfig GPIOLIB
+	bool "GPIO Support"
+	depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB
+	select GENERIC_GPIO
+	help
+	  This enables GPIO support through the generic GPIO library.
+	  You only need to enable this, if you also want to enable
+	  one or more of the GPIO expansion card drivers below.
+
+	  If unsure, say N.
...

The implementation of ARCH_REQUIRE_GPIOLIB does not match the description.

Matching the description would be:

Quoted 7 lines

menuconfig GPIOLIB

        bool "GPIO Support" if !ARCH_REQUIRE_GPIOLIB
        depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB
        default ARCH_REQUIRE_GPIOLIB
        select GENERIC_GPIO
        help
          ...

So well. I'm not sure what you're talking about. Care to make a better helptext?

Quoted 13 lines

arch/arm/configs/am200epdkit_defconfig line 671

Quoted 9 lines
arch/arm/configs/am200epdkit_defconfig +1 -1
@@ -668,7 +668,7 @@
 #
 # CONFIG_SPI is not set
 # CONFIG_SPI_MASTER is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
...

Please don't do this kind of defconfig updates - it doesn't bring any advantage but can create tons of patch conflicts.

Quoted 4 lines

The next time a defconfig gets updated it will anyway automatically be fixed, and for defconfigs that aren't updated it doesn't create any problems to keep them as they are today until they might one day get updated.

So will the auto-regenerated defconfig result in CONFIG_ARCH_REQUIRE_GPIOLIB=y or CONFIG_ARCH_REQUIRE_GPIOLIB=n? I thought it would result in =n, as the option defaults to n. So I changed all defconfigs.

(I think these (sub)archs should "select" the option in their Kconfig, but I didn't want to go down that way).

Signature · 1 line
Greetings Michael.
#3 lore raw
Quoted 4 lines · Michael Buesch

On Sunday 06 July 2008 21:52:12 Adrian Bunk wrote:
...
So well. I'm not sure what you're talking about. Care to make a better helptext?

Sorry, the problem wasn't the help text but me being blind.

Please ignore my comment.

Quoted 18 lines
Quoted 13 lines

arch/arm/configs/am200epdkit_defconfig line 671

Quoted 9 lines
arch/arm/configs/am200epdkit_defconfig +1 -1
@@ -668,7 +668,7 @@
 #
 # CONFIG_SPI is not set
 # CONFIG_SPI_MASTER is not set
-CONFIG_HAVE_GPIO_LIB=y
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
...

Please don't do this kind of defconfig updates - it doesn't bring any advantage but can create tons of patch conflicts.

Quoted 4 lines

The next time a defconfig gets updated it will anyway automatically be fixed, and for defconfigs that aren't updated it doesn't create any problems to keep them as they are today until they might one day get updated.

Quoted 6 lines

So will the auto-regenerated defconfig result in CONFIG_ARCH_REQUIRE_GPIOLIB=y or CONFIG_ARCH_REQUIRE_GPIOLIB=n? I thought it would result in =n, as the option defaults to n. So I changed all defconfigs.

(I think these (sub)archs should "select" the option in their Kconfig, but I didn't want to go down that way).

A defconfig is just a normal .config and cannot override any dependencies.

CONFIG_ARCH_REQUIRE_GPIOLIB is not user visible and defaults to n, so if no option select's it then even using a defconfig that has it enabled will result in a .config that has it disabled.

Quoted 1 line

Greetings Michael.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#4 lore raw
Quoted 5 lines · On Sunday 06 July 2008 22:13:46 Adrian Bunk wrote:

A defconfig is just a normal .config and cannot override any dependencies.

CONFIG_ARCH_REQUIRE_GPIOLIB is not user visible and defaults to n, so if no option select's it then even using a defconfig that has it enabled will result in a .config that has it disabled.

Ok, thanks a lot for explaining this to me. :)

Signature · 1 line
Greetings Michael.