Skip to contentSkip to conversation

gpiolib: make legacy interfaces optional

PATCH Applied Arnd Bergmann 5 participants 9 messages Jul 22, 2025 – Jul 24, 2025 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: make legacy interfaces optional

From: Arnd Bergmann <[email protected]>

The traditional interfaces are only used on a small number of ancient boards. Make these optional now so they can be disabled by default.

---
This is the first patch of a series to turn off the legacy interfaces by default. If we can still have this one in linux-6.17, we can more easily merge the other patches for 6.18.

See for the longer series:
https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=config-gpio-legacy

I'm sure there are still problems in the other patches, but it does pass my randconfig build tests on the three architectures I'm testing on. I plan to post them after some more testing once -rc1 is out.

 drivers/gpio/Kconfig  |  3 +++
 drivers/gpio/Makefile |  2 +-
 include/linux/gpio.h  | 10 ++++++----
 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpio/Kconfig +3 -0
index 12bdf6e965f1..8bda3c9d47b4 100644
@@ -14,6 +14,9 @@ menuconfig GPIOLIB
 
 if GPIOLIB
 
+config GPIOLIB_LEGACY
+	def_bool y
+
 config GPIOLIB_FASTPATH_LIMIT
 	int "Maximum number of GPIOs for fast path"
 	range 32 512
drivers/gpio/Makefile +1 -1
index 88dedd298256..b01ff2b68bf6 100644
@@ -5,7 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO)	+= -DDEBUG
 
 obj-$(CONFIG_GPIOLIB)		+= gpiolib.o
 obj-$(CONFIG_GPIOLIB)		+= gpiolib-devres.o
-obj-$(CONFIG_GPIOLIB)		+= gpiolib-legacy.o
+obj-$(CONFIG_GPIOLIB_LEGACY)	+= gpiolib-legacy.o
 obj-$(CONFIG_OF_GPIO)		+= gpiolib-of.o
 obj-$(CONFIG_GPIO_CDEV)		+= gpiolib-cdev.o
 obj-$(CONFIG_GPIO_SYSFS)	+= gpiolib-sysfs.o
include/linux/gpio.h +6 -4
index ff99ed76fdc3..8f85ddb26429 100644
@@ -13,6 +13,11 @@
 #define __LINUX_GPIO_H
 
 #include <linux/types.h>
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>
+#endif
+
+#ifdef CONFIG_GPIOLIB_LEGACY
 
 struct device;
 
@@ -22,9 +27,6 @@ struct device;
 #define GPIOF_OUT_INIT_HIGH	((0 << 0) | (1 << 1))
 
 #ifdef CONFIG_GPIOLIB
-
-#include <linux/gpio/consumer.h>
-
 /*
  * "valid" GPIO numbers are nonnegative and may be passed to
  * setup routines like gpio_request().  Only some valid numbers
@@ -170,5 +172,5 @@ static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
 }
 
 #endif /* ! CONFIG_GPIOLIB */
-
+#endif /* CONFIG_GPIOLIB_LEGACY */
 #endif /* __LINUX_GPIO_H */
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The traditional interfaces are only used on a small number of ancient boards. Make these optional now so they can be disabled by default.

Quoted 78 lines

---
This is the first patch of a series to turn off the legacy interfaces by default. If we can still have this one in linux-6.17, we can more easily merge the other patches for 6.18.

See for the longer series:
https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=config-gpio-legacy

I'm sure there are still problems in the other patches, but it does pass my randconfig build tests on the three architectures I'm testing on. I plan to post them after some more testing once -rc1 is out.

 drivers/gpio/Kconfig  |  3 +++
 drivers/gpio/Makefile |  2 +-
 include/linux/gpio.h  | 10 ++++++----

 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpio/Kconfig +0 -0
index 12bdf6e965f1..8bda3c9d47b4 100644
@@ -14,6 +14,9 @@ menuconfig GPIOLIB


 if GPIOLIB

drivers/gpio/Kconfig +3 -0
+config GPIOLIB_LEGACY
+	def_bool y
+

 config GPIOLIB_FASTPATH_LIMIT
  int "Maximum number of GPIOs for fast path" range 32 512

drivers/gpio/Makefile +0 -0
index 88dedd298256..b01ff2b68bf6 100644
@@ -5,7 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO)	+= -DDEBUG


 obj-$(CONFIG_GPIOLIB) += gpiolib.o
 obj-$(CONFIG_GPIOLIB) += gpiolib-devres.o

drivers/gpio/Makefile +1 -1
-obj-$(CONFIG_GPIOLIB)		+= gpiolib-legacy.o
+obj-$(CONFIG_GPIOLIB_LEGACY)	+= gpiolib-legacy.o

 obj-$(CONFIG_OF_GPIO) += gpiolib-of.o
 obj-$(CONFIG_GPIO_CDEV) += gpiolib-cdev.o
 obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o

include/linux/gpio.h +0 -0
index ff99ed76fdc3..8f85ddb26429 100644
@@ -13,6 +13,11 @@
  #define __LINUX_GPIO_H


 #include <linux/types.h>

include/linux/gpio.h +5 -0
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>
+#endif
+
+#ifdef CONFIG_GPIOLIB_LEGACY


 struct device;

include/linux/gpio.h +0 -0
@@ -22,9 +27,6 @@ struct device;
  #define GPIOF_OUT_INIT_HIGH	((0 << 0) | (1 << 1))


 #ifdef CONFIG_GPIOLIB

include/linux/gpio.h +0 -3
-
-#include <linux/gpio/consumer.h>
-

 /*
  * "valid" GPIO numbers are nonnegative and may be passed to
  * setup routines like gpio_request().  Only some valid numbers

include/linux/gpio.h +0 -0
@@ -170,5 +172,5 @@ static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
  }


 #endif /* ! CONFIG_GPIOLIB */

include/linux/gpio.h +1 -1
-
+#endif /* CONFIG_GPIOLIB_LEGACY */

 #endif /* __LINUX_GPIO_H */

Signature · 1 line
Alexander Sverdlin.
#2 lore raw
In reply to Arnd Bergmann
Quoted 57 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The traditional interfaces are only used on a small number of ancient boards. Make these optional now so they can be disabled by default.

---
This is the first patch of a series to turn off the legacy interfaces by default. If we can still have this one in linux-6.17, we can more easily merge the other patches for 6.18.

See for the longer series:
https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=config-gpio-legacy

I'm sure there are still problems in the other patches, but it does pass my randconfig build tests on the three architectures I'm testing on. I plan to post them after some more testing once -rc1 is out.

 drivers/gpio/Kconfig  |  3 +++
 drivers/gpio/Makefile |  2 +-
 include/linux/gpio.h  | 10 ++++++----
 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpio/Kconfig +3 -0
index 12bdf6e965f1..8bda3c9d47b4 100644
@@ -14,6 +14,9 @@ menuconfig GPIOLIB
 
 if GPIOLIB
 
+config GPIOLIB_LEGACY
+       def_bool y
+
 config GPIOLIB_FASTPATH_LIMIT
        int "Maximum number of GPIOs for fast path"
        range 32 512
drivers/gpio/Makefile +1 -1
index 88dedd298256..b01ff2b68bf6 100644
@@ -5,7 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO)    += -DDEBUG
 
 obj-$(CONFIG_GPIOLIB)          += gpiolib.o
 obj-$(CONFIG_GPIOLIB)          += gpiolib-devres.o
-obj-$(CONFIG_GPIOLIB)          += gpiolib-legacy.o
+obj-$(CONFIG_GPIOLIB_LEGACY)   += gpiolib-legacy.o
 obj-$(CONFIG_OF_GPIO)          += gpiolib-of.o
 obj-$(CONFIG_GPIO_CDEV)                += gpiolib-cdev.o
 obj-$(CONFIG_GPIO_SYSFS)       += gpiolib-sysfs.o
include/linux/gpio.h +0 -0
index ff99ed76fdc3..8f85ddb26429 100644

include/linux/gpio.h line 17

Quoted 5 lines
include/linux/gpio.h +2 -0
@@ -13,6 +13,11 @@
 #define __LINUX_GPIO_H
 
 #include <linux/types.h>
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>

I want to queue this ASAP but do we really need this guard here? consumer.h already guards against !CONFIG_GPIOLIB internally, right?

Bart

Quoted 26 lines
include/linux/gpio.h +4 -5
+#endif
+
+#ifdef CONFIG_GPIOLIB_LEGACY
 
 struct device;
 
@@ -22,9 +27,6 @@ struct device;
 #define GPIOF_OUT_INIT_HIGH    ((0 << 0) | (1 << 1))
 
 #ifdef CONFIG_GPIOLIB
-
-#include <linux/gpio/consumer.h>
-
 /*
  * "valid" GPIO numbers are nonnegative and may be passed to
  * setup routines like gpio_request().  Only some valid numbers
@@ -170,5 +172,5 @@ static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
 }
 
 #endif /* ! CONFIG_GPIOLIB */
-
+#endif /* CONFIG_GPIOLIB_LEGACY */
 #endif /* __LINUX_GPIO_H */
--

2.39.5

#3 lore raw
Quoted 1 line · Bartosz Golaszewski

On Tue, Jul 22, 2025 at 5:36 PM Arnd Bergmann <[email protected]> wrote:

...

Quoted 5 lines

include/linux/gpio.h line 17

Quoted 2 lines
include/linux/gpio.h +2 -0
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>

I want to queue this ASAP but do we really need this guard here? consumer.h already guards against !CONFIG_GPIOLIB internally, right?

I probably missed something, but I do not understand why we need this include at all in the gpio.h.

Quoted 1 line
Quoted 1 line

+#endif

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski

On Tue, Jul 22, 2025 at 5:36 PM Arnd Bergmann <[email protected]> wrote:

...

Quoted 8 lines
Quoted 5 lines

include/linux/gpio.h line 17

Quoted 2 lines
include/linux/gpio.h +2 -0
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>

I want to queue this ASAP but do we really need this guard here? consumer.h already guards against !CONFIG_GPIOLIB internally, right?

I probably missed something, but I do not understand why we need this include at all in the gpio.h.

We've been thinning out linux/gpio.h over the years on both the contents and the inclusions, but I'm fairly sure that out of the 173 files that still include it, the majority actually need the consumer interfaces.

One thing I've considered doing here was to make this file only contain two lines

#include <linux/gpio/consumer.h>
#include <linux/gpio/legacy.h>

then then replace all of the remaining users with one or the other in order to remove linux/gpio.h completely.

I think both approaches are useful and can be combined, but the CONFIG_GPIOLIB_LEGACY patch seems sufficient for now.

If you want to experiment with the other one, you could try my whole series and drop the #include <linux/gpio/consumer.h> line to find all the instances in allmodconfig builds that should use that in place of linux/gpio.h.

Arnd

#5 lore raw
In reply to Bartosz Golaszewski
Quoted 8 lines · Bartosz Golaszewski

include/linux/gpio.h line 17

Quoted 3 lines · Arnd Bergmann

#include <linux/types.h>

include/linux/gpio.h +2 -0
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>

I want to queue this ASAP but do we really need this guard here? consumer.h already guards against !CONFIG_GPIOLIB internally, right?

I was trying to not change the behavior here. linux/gpio/consumer.h has an #ifdef check but has the #else portion with empty stubs that can be used by any driver that includes it, while drivers that include linux/gpio.h never saw the stub version.

Arnd

#6 lore raw
Quoted 11 lines · Arnd Bergmann
Quoted 8 lines · Bartosz Golaszewski

include/linux/gpio.h line 17

Quoted 3 lines · Arnd Bergmann

#include <linux/types.h>

include/linux/gpio.h +2 -0
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>

I want to queue this ASAP but do we really need this guard here? consumer.h already guards against !CONFIG_GPIOLIB internally, right?

Quoted 6 lines

I was trying to not change the behavior here. linux/gpio/consumer.h has an #ifdef check but has the #else portion with empty stubs that can be used by any driver that includes it, while drivers that include linux/gpio.h never saw the stub version.

Arnd

Ok, fair enough, let me queue this and we can change it later if needed.

Bart

#7 lore raw
In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann

The traditional interfaces are only used on a small number of ancient boards. Make these optional now so they can be disabled by default.

...

include/linux/gpio.h struct device; · line 27

Quoted 8 lines
include/linux/gpio.h +3 -3
+#ifdef CONFIG_GPIOLIB
+#include <linux/gpio/consumer.h>
+#endif
 
 #ifdef CONFIG_GPIOLIB
-
-#include <linux/gpio/consumer.h>
-

Why is the above needed to be changed?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: (subset) [PATCH] gpiolib: make legacy interfaces optional

In reply to Arnd Bergmann

From: Bartosz Golaszewski <[email protected]>

Quoted 4 lines · Arnd Bergmann

The traditional interfaces are only used on a small number of ancient boards. Make these optional now so they can be disabled by default.

Applied, thanks!

[1/1] gpiolib: make legacy interfaces optional

      https://git.kernel.org/brgl/linux/c/678bae2eaa812662929a83b3de399645e9de93ad

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>