Skip to contentSkip to conversation

gpiolib header cleanup

PATCH In review Arnd Bergmann 3 participants 23 messages Nov 9, 2021 – Nov 10, 2021

Subsystems (30)
lore
Share & tools
lore
#0 lore raw

v2 cover gpiolib header cleanup

From: Arnd Bergmann <[email protected]>

I got a bit carried away after posting the first three patches, so here is a somewhat larger rework towards simplifying the remainder of the traditional linux/gpio.h interface, removing some of the rarely used functions, and dropping the inclusion of linux/gpio/driver.h from linux/gpio.h. This makes linux/gpio.h mainly a wrapper for the consumer interface.

There is one more possible follow-up that I did not include here:
As there are only around 350 files[1] remaining that actually use the legacy interfaces, we could rename linux/gpio.h to e.g. linux/gpio/legacy.h, and leave linux/gpio.h as an alias for linux/gpio/consumer.h until we remove it entirely.

Arnd

Changes since v1:
- incorporate feedback from Geert Uytterhoeven
- remove asm-generic/gpio.h
- drop legacy export interface and a few other functions
- stop including linux/gpio/driver.h

Arnd Bergmann (8):
gpiolib: remove irq_to_gpio() definition
gpiolib: remove empty asm/gpio.h files
gpiolib: coldfire: remove custom asm/gpio.h
gpiolib: remove asm-generic/gpio.h
gpiolib: shrink further
gpiolib: remove legacy gpio_export
gpiolib: remove gpio_to_chip
gpiolib: split linux/gpio/driver.h out of linux/gpio.h

 Documentation/admin-guide/gpio/sysfs.rst      |   2 +-
 .../driver-api/driver-model/devres.rst        |   1 -
 Documentation/driver-api/gpio/legacy.rst      |  52 +-----
 Documentation/translations/zh_CN/gpio.txt     |  26 ---
 Documentation/translations/zh_TW/gpio.txt     |  27 ---
 arch/arm/Kconfig                              |   1 -
 arch/arm/include/asm/gpio.h                   |  22 ---
 arch/arm/mach-davinci/board-dm646x-evm.c      |  28 +--
 arch/arm/mach-omap1/irq.c                     |   1 +
 arch/arm/mach-omap2/pdata-quirks.c            |   9 +-
 arch/arm/mach-orion5x/board-rd88f5182.c       |   1 +
 arch/arm/mach-pxa/lubbock.c                   |   2 +-
 arch/arm/mach-s3c/mach-h1940.c                |   1 +
 arch/arm/mach-s3c/s3c64xx.c                   |   1 +
 arch/arm/mach-sa1100/assabet.c                |   1 +
 arch/arm/plat-orion/gpio.c                    |   1 +
 arch/m68k/Kconfig.cpu                         |   1 -
 arch/m68k/include/asm/gpio.h                  | 102 -----------
 arch/m68k/include/asm/mcfgpio.h               |   2 +-
 arch/sh/Kconfig                               |   1 -
 arch/sh/boards/board-magicpanelr2.c           |   1 +
 arch/sh/boards/mach-ap325rxa/setup.c          |   7 +-
 arch/sh/include/asm/gpio.h                    |  50 -----
 drivers/gpio/Kconfig                          |   8 -
 drivers/gpio/gpio-davinci.c                   |   3 +-
 drivers/gpio/gpio-ucb1400.c                   |   1 +
 drivers/gpio/gpiolib-devres.c                 |  25 ---
 drivers/gpio/gpiolib-sysfs.c                  |   4 +-
 drivers/input/touchscreen/ads7846.c           |   3 +-
 drivers/media/i2c/noon010pc30.c               |   5 +-
 drivers/media/i2c/ov9650.c                    |   4 +-
 drivers/media/i2c/s5k4ecgx.c                  |   3 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c       |  10 +-
 drivers/mfd/dm355evm_msp.c                    |   3 +-
 drivers/mfd/htc-i2cpld.c                      |   1 +
 drivers/mfd/ucb1400_core.c                    |   1 +
 drivers/net/ieee802154/ca8210.c               |   3 +-
 .../broadcom/brcm80211/brcmsmac/led.c         |   1 +
 drivers/pinctrl/core.c                        |   5 +-
 drivers/soc/fsl/qe/gpio.c                     |   4 +-
 include/asm-generic/gpio.h                    | 172 ------------------
 include/linux/bcma/bcma_driver_chipcommon.h   |   2 +-
 include/linux/gpio.h                          | 123 +++++++------
 include/linux/mfd/ucb1x00.h                   |   1 +
 include/linux/ucb1400.h                       |   1 +
 45 files changed, 133 insertions(+), 590 deletions(-)
 delete mode 100644 arch/arm/include/asm/gpio.h
 delete mode 100644 arch/m68k/include/asm/gpio.h
 delete mode 100644 arch/sh/include/asm/gpio.h
 delete mode 100644 include/asm-generic/gpio.h
Signature · 11 lines
2.29.2

Cc: [email protected]
Cc: Linus Walleij <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: [email protected]
Cc: [email protected]

[1] git grep -wl  '\<\(gpio_direction_input\|gpio_direction_output\|gpio_get_value_cansleep\|gpio_set_value_cansleep\|gpio_get_value\|gpio_set_value\|gpio_to_irq\|gpio_request\|gpio_request_one\|gpio_request_array\)\>\|\<\(ARCH_NR_GPIOS\|GPIOF_DIR_\|GPIOF_INIT\|GPIOF_EXPORT\|GPIOF_OPEN\|GPIOF_IN\|GPIOF_OUT\|gpio_is_valid\\|gpio_free\|devm_gpio_\)' | wc -l
#1 lore raw

PATCH v2 1/8 gpiolib: remove irq_to_gpio() definition

From: Arnd Bergmann <[email protected]>

All implementations other than coldfire have returned an error since the avr32 and blackfin architectures got removed, and the last user in driver code was removed in 2016, so just remove this old interface.

The only reference is now in the Chinese documentation, which should be changed to remove this reference as well.

---
 Documentation/driver-api/gpio/legacy.rst | 20 +++++---------------
 arch/m68k/include/asm/gpio.h             |  7 -------
 arch/sh/include/asm/gpio.h               |  5 -----
 include/linux/gpio.h                     | 12 ------------
 4 files changed, 5 insertions(+), 39 deletions(-)
Documentation/driver-api/gpio/legacy.rst +5 -15
index 9b12eeb89170..06c05e2d62c1 100644
@@ -382,22 +382,18 @@ GPIOs mapped to IRQs
 --------------------
 GPIO numbers are unsigned integers; so are IRQ numbers.  These make up
 two logically distinct namespaces (GPIO 0 need not use IRQ 0).  You can
-map between them using calls like::
+map between them using::
 
 	/* map GPIO numbers to IRQ numbers */
 	int gpio_to_irq(unsigned gpio);
 
-	/* map IRQ numbers to GPIO numbers (avoid using this) */
-	int irq_to_gpio(unsigned irq);
-
-Those return either the corresponding number in the other namespace, or
+This returns an irq number corresponding to the gpio number, or
 else a negative errno code if the mapping can't be done.  (For example,
 some GPIOs can't be used as IRQs.)  It is an unchecked error to use a GPIO
-number that wasn't set up as an input using gpio_direction_input(), or
-to use an IRQ number that didn't originally come from gpio_to_irq().
+number that wasn't set up as an input using gpio_direction_input().
 
-These two mapping calls are expected to cost on the order of a single
-addition or subtraction.  They're not allowed to sleep.
+The mapping call is expected to cost on the order of a single
+addition or subtraction.  It is not allowed to sleep.
 
 Non-error values returned from gpio_to_irq() can be passed to request_irq()
 or free_irq().  They will often be stored into IRQ resources for platform
@@ -405,12 +401,6 @@ devices, by the board-specific initialization code.  Note that IRQ trigger
 options are part of the IRQ interface, e.g. IRQF_TRIGGER_FALLING, as are
 system wakeup capabilities.
 
-Non-error values returned from irq_to_gpio() would most commonly be used
-with gpio_get_value(), for example to initialize or update driver state
-when the IRQ is edge-triggered.  Note that some platforms don't support
-this reverse mapping, so you should avoid using it.
-
-
 Emulating Open Drain Signals
 ----------------------------
 Sometimes shared signals need to use "open drain" signaling, where only the
arch/m68k/include/asm/gpio.h +0 -7
index a50b27719a58..5cfc0996ba94 100644
@@ -66,13 +66,6 @@ static inline int gpio_to_irq(unsigned gpio)
 		return __gpio_to_irq(gpio);
 }
 
-static inline int irq_to_gpio(unsigned irq)
-{
-	return (irq >= MCFGPIO_IRQ_VECBASE &&
-		irq < (MCFGPIO_IRQ_VECBASE + MCFGPIO_IRQ_MAX)) ?
-		irq - MCFGPIO_IRQ_VECBASE : -ENXIO;
-}
-
 static inline int gpio_cansleep(unsigned gpio)
 {
 	return gpio < MCFGPIO_PIN_MAX ? 0 : __gpio_cansleep(gpio);
arch/sh/include/asm/gpio.h +0 -5
index d643250f0a0f..588c1380e4cb 100644
@@ -40,11 +40,6 @@ static inline int gpio_to_irq(unsigned gpio)
 	return __gpio_to_irq(gpio);
 }
 
-static inline int irq_to_gpio(unsigned int irq)
-{
-	return -ENOSYS;
-}
-
 #endif /* CONFIG_GPIOLIB */
 
 #endif /* __ASM_SH_GPIO_H */
include/linux/gpio.h +0 -12
index 008ad3ee56b7..d8d7daa7eb94 100644
@@ -81,11 +81,6 @@ 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_ARCH_HAVE_CUSTOM_GPIO_H */
 
 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
@@ -219,13 +214,6 @@ static inline int gpio_to_irq(unsigned gpio)
 	return -EINVAL;
 }
 
-static inline int irq_to_gpio(unsigned irq)
-{
-	/* irq can never have been returned from gpio_to_irq() */
-	WARN_ON(1);
-	return -EINVAL;
-}
-
 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
 				    const char *label)
 {
Signature · 1 line
2.29.2
#2 lore raw

PATCH v2 2/8 gpiolib: remove empty asm/gpio.h files

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The arm and sh versions of this file are identical to the generic versions and can just be removed.

The drivers that actually use the sh3 specific version also include cpu/gpio.h directly, with the exception of magicpanelr2, which is easily fixed. This leaves coldfire as the only gpio driver that needs something custom for gpiolib.

---
 arch/arm/Kconfig                    |  1 -
 arch/arm/include/asm/gpio.h         | 22 --------------
 arch/sh/Kconfig                     |  1 -
 arch/sh/boards/board-magicpanelr2.c |  1 +
 arch/sh/include/asm/gpio.h          | 45 -----------------------------
 5 files changed, 1 insertion(+), 69 deletions(-)
 delete mode 100644 arch/arm/include/asm/gpio.h
 delete mode 100644 arch/sh/include/asm/gpio.h
arch/arm/Kconfig +0 -1
index 526ae94b1c9a..80378eeee760 100644
@@ -23,7 +23,6 @@ config ARM
 	select ARCH_HAS_SYNC_DMA_FOR_CPU if SWIOTLB || !MMU
 	select ARCH_HAS_TEARDOWN_DMA_OPS if MMU
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
-	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if CPU_V7 || CPU_V7M || CPU_V6K
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_KEEP_MEMBLOCK
arch/arm/include/asm/gpio.h deleted +0 -22
deleted file mode 100644
index f3bb8a2bf788..000000000000
@@ -1,22 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ARCH_ARM_GPIO_H
-#define _ARCH_ARM_GPIO_H
-
-/* Note: this may rely upon the value of ARCH_NR_GPIOS set in mach/gpio.h */
-#include <asm-generic/gpio.h>
-
-/* The trivial gpiolib dispatchers */
-#define gpio_get_value  __gpio_get_value
-#define gpio_set_value  __gpio_set_value
-#define gpio_cansleep   __gpio_cansleep
-
-/*
- * Provide a default gpio_to_irq() which should satisfy every case.
- * However, some platforms want to do this differently, so allow them
- * to override it.
- */
-#ifndef gpio_to_irq
-#define gpio_to_irq	__gpio_to_irq
-#endif
-
-#endif /* _ARCH_ARM_GPIO_H */
arch/sh/Kconfig +0 -1
index 2474a04ceac4..cebd04314d76 100644
@@ -4,7 +4,6 @@ config SUPERH
 	select ARCH_32BIT_OFF_T
 	select ARCH_ENABLE_MEMORY_HOTPLUG if SPARSEMEM && MMU
 	select ARCH_ENABLE_MEMORY_HOTREMOVE if SPARSEMEM && MMU
-	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select ARCH_HAS_BINFMT_FLAT if !MMU
 	select ARCH_HAS_GIGANTIC_PAGE
arch/sh/boards/board-magicpanelr2.c +1 -0
index 56bd386ff3b0..75de893152af 100644
@@ -21,6 +21,7 @@
 #include <linux/sh_intc.h>
 #include <mach/magicpanelr2.h>
 #include <asm/heartbeat.h>
+#include <cpu/gpio.h>
 #include <cpu/sh7720.h>
 
 /* Dummy supplies, where voltage doesn't matter */
arch/sh/include/asm/gpio.h deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
2.29.2
#3 lore raw

PATCH v2 3/8 gpiolib: coldfire: remove custom asm/gpio.h

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Now that coldfire is the only user of a custom asm/gpio.h, it seems better to remove this as well, and have the same interface everywhere.

For the gpio_get_value()/gpio_set_value()/gpio_to_irq(), gpio_cansleep() functions, the custom version is only a micro-optimization to inline the function for constant GPIO numbers. However, in the coldfire defconfigs, I was unable to find a single instance where this micro-optimization was even used, and according to Geert the only user appears to be the QSPI chip that is disabled everywhere.

The custom gpio_request_one() function is even less useful, as it is guarded by an #ifdef that is never true.

---
 arch/m68k/Kconfig.cpu        |  1 -
 arch/m68k/include/asm/gpio.h | 95 ------------------------------------
 drivers/gpio/Kconfig         |  8 ---
 include/linux/gpio.h         |  7 ---
 4 files changed, 111 deletions(-)
 delete mode 100644 arch/m68k/include/asm/gpio.h
arch/m68k/Kconfig.cpu +0 -1
index 0d00ef5117dc..8256ff6b5b87 100644
@@ -24,7 +24,6 @@ config M68KCLASSIC
 
 config COLDFIRE
 	bool "Coldfire CPU family support"
-	select ARCH_HAVE_CUSTOM_GPIO_H
 	select CPU_HAS_NO_BITFIELDS
 	select CPU_HAS_NO_CAS
 	select CPU_HAS_NO_MULDIV64
arch/m68k/include/asm/gpio.h deleted +0 -95

95 lines not on this page · raw message

drivers/gpio/Kconfig +0 -8
index 5c3b29bddc5b..e2a3e9b66151 100644
@@ -3,14 +3,6 @@
 # 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.
-
 menuconfig GPIOLIB
 	bool "GPIO Support"
 	help
include/linux/gpio.h +0 -7
index d8d7daa7eb94..7e6b1b8277ca 100644
@@ -54,11 +54,6 @@ struct gpio {
 };
 
 #ifdef CONFIG_GPIOLIB
-
-#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)
@@ -81,8 +76,6 @@ static inline int gpio_to_irq(unsigned int gpio)
 	return __gpio_to_irq(gpio);
 }
 
-#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
-
 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
 
 struct device;
Signature · 1 line
2.29.2
#4 lore raw

PATCH v2 4/8 gpiolib: remove asm-generic/gpio.h

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The asm-generic/gpio.h file is now always included when using gpiolib, so just move its contents into linux/gpio.h with a few minor simplifications.

---
 arch/m68k/include/asm/mcfgpio.h |   2 +-
 drivers/gpio/gpio-davinci.c     |   3 +-
 drivers/pinctrl/core.c          |   2 +-
 include/asm-generic/gpio.h      | 172 --------------------------------
 include/linux/gpio.h            | 116 +++++++++++++++++++--
 5 files changed, 110 insertions(+), 185 deletions(-)
 delete mode 100644 include/asm-generic/gpio.h
arch/m68k/include/asm/mcfgpio.h +1 -1
index 27f32cc81da6..2cefe8445980 100644
@@ -9,7 +9,7 @@
 #define mcfgpio_h
 
 #ifdef CONFIG_GPIOLIB
-#include <asm-generic/gpio.h>
+#include <linux/gpio.h>
 #else
 
 int __mcfgpio_get_value(unsigned gpio);
drivers/gpio/gpio-davinci.c +1 -2
index cb5afaa7ed48..8122c3a8d659 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/gpio/driver.h>
+#include <linux/gpio.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/clk.h>
@@ -23,8 +24,6 @@
 #include <linux/irqchip/chained_irq.h>
 #include <linux/spinlock.h>
 
-#include <asm-generic/gpio.h>
-
 #define MAX_REGS_BANKS 5
 #define MAX_INT_PER_BANK 32
 
drivers/pinctrl/core.c +1 -1
index ffe39336fcac..976607758e98 100644
@@ -28,7 +28,7 @@
 
 #ifdef CONFIG_GPIOLIB
 #include "../gpio/gpiolib.h"
-#include <asm-generic/gpio.h>
+#include <linux/gpio.h>
 #endif
 
 #include "core.h"
include/asm-generic/gpio.h deleted +0 -172

172 lines not on this page · raw message

include/linux/gpio.h +107 -9

133 lines not on this page · raw message

Signature · 1 line
2.29.2
Reviewed-by on v2 4/8
#5 lore raw

Re: [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h

Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The asm-generic/gpio.h file is now always included when using gpiolib, so just move its contents into linux/gpio.h with a few minor simplifications.

Quoted 8 lines
---
 arch/m68k/include/asm/mcfgpio.h |   2 +-
 drivers/gpio/gpio-davinci.c     |   3 +-
 drivers/pinctrl/core.c          |   2 +-
 include/asm-generic/gpio.h      | 172 --------------------------------
 include/linux/gpio.h            | 116 +++++++++++++++++++--

For these three

Quoted 369 lines
 5 files changed, 110 insertions(+), 185 deletions(-)
 delete mode 100644 include/asm-generic/gpio.h
arch/m68k/include/asm/mcfgpio.h +1 -1
index 27f32cc81da6..2cefe8445980 100644
@@ -9,7 +9,7 @@
 #define mcfgpio_h
 
 #ifdef CONFIG_GPIOLIB
-#include <asm-generic/gpio.h>
+#include <linux/gpio.h>
 #else
 
 int __mcfgpio_get_value(unsigned gpio);
drivers/gpio/gpio-davinci.c +1 -2
index cb5afaa7ed48..8122c3a8d659 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/gpio/driver.h>
+#include <linux/gpio.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/clk.h>
@@ -23,8 +24,6 @@
 #include <linux/irqchip/chained_irq.h>
 #include <linux/spinlock.h>
 
-#include <asm-generic/gpio.h>
-
 #define MAX_REGS_BANKS 5
 #define MAX_INT_PER_BANK 32
 
drivers/pinctrl/core.c +1 -1
index ffe39336fcac..976607758e98 100644
@@ -28,7 +28,7 @@
 
 #ifdef CONFIG_GPIOLIB
 #include "../gpio/gpiolib.h"
-#include <asm-generic/gpio.h>
+#include <linux/gpio.h>
 #endif
 
 #include "core.h"
include/asm-generic/gpio.h deleted +0 -172
deleted file mode 100644
index aea9aee1f3e9..000000000000
@@ -1,172 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_GENERIC_GPIO_H
-#define _ASM_GENERIC_GPIO_H
-
-#include <linux/types.h>
-#include <linux/errno.h>
-
-#ifdef CONFIG_GPIOLIB
-
-#include <linux/compiler.h>
-#include <linux/gpio/driver.h>
-#include <linux/gpio/consumer.h>
-
-/* Platforms may implement their GPIO interface with library code,
- * at a small performance cost for non-inlined operations and some
- * extra memory (for code and for per-GPIO table entries).
- *
- * While the GPIO programming interface defines valid GPIO numbers
- * to be in the range 0..MAX_INT, this library restricts them to the
- * smaller range 0..ARCH_NR_GPIOS-1.
- *
- * ARCH_NR_GPIOS is somewhat arbitrary; it usually reflects the sum of
- * builtin/SoC GPIOs plus a number of GPIOs on expanders; the latter is
- * actually an estimate of a board-specific value.
- */
-
-#ifndef ARCH_NR_GPIOS
-#if defined(CONFIG_ARCH_NR_GPIO) && CONFIG_ARCH_NR_GPIO > 0
-#define ARCH_NR_GPIOS CONFIG_ARCH_NR_GPIO
-#else
-#define ARCH_NR_GPIOS		512
-#endif
-#endif
-
-/*
- * "valid" GPIO numbers are nonnegative and may be passed to
- * setup routines like gpio_request().  only some valid numbers
- * can successfully be requested and used.
- *
- * Invalid GPIO numbers are useful for indicating no-such-GPIO in
- * platform data and other tables.
- */
-
-static inline bool gpio_is_valid(int number)
-{
-	return number >= 0 && number < ARCH_NR_GPIOS;
-}
-
-struct device;
-struct gpio;
-struct seq_file;
-struct module;
-struct device_node;
-struct gpio_desc;
-
-/* caller holds gpio_lock *OR* gpio is marked as requested */
-static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
-{
-	return gpiod_to_chip(gpio_to_desc(gpio));
-}
-
-/* Always use the library code for GPIO management calls,
- * or when sleeping may be involved.
- */
-extern int gpio_request(unsigned gpio, const char *label);
-extern void gpio_free(unsigned gpio);
-
-static inline int gpio_direction_input(unsigned gpio)
-{
-	return gpiod_direction_input(gpio_to_desc(gpio));
-}
-static inline int gpio_direction_output(unsigned gpio, int value)
-{
-	return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
-}
-
-static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
-{
-	return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
-}
-
-static inline int gpio_get_value_cansleep(unsigned gpio)
-{
-	return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio));
-}
-static inline void gpio_set_value_cansleep(unsigned gpio, int value)
-{
-	return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
-}
-
-
-/* A platform's <asm/gpio.h> code may want to inline the I/O calls when
- * the GPIO is constant and refers to some always-present controller,
- * giving direct access to chip registers and tight bitbanging loops.
- */
-static inline int __gpio_get_value(unsigned gpio)
-{
-	return gpiod_get_raw_value(gpio_to_desc(gpio));
-}
-static inline void __gpio_set_value(unsigned gpio, int value)
-{
-	return gpiod_set_raw_value(gpio_to_desc(gpio), value);
-}
-
-static inline int __gpio_cansleep(unsigned gpio)
-{
-	return gpiod_cansleep(gpio_to_desc(gpio));
-}
-
-static inline int __gpio_to_irq(unsigned gpio)
-{
-	return gpiod_to_irq(gpio_to_desc(gpio));
-}
-
-extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
-extern int gpio_request_array(const struct gpio *array, size_t num);
-extern void gpio_free_array(const struct gpio *array, size_t num);
-
-/*
- * A sysfs interface can be exported by individual drivers if they want,
- * but more typically is configured entirely from userspace.
- */
-static inline int gpio_export(unsigned gpio, bool direction_may_change)
-{
-	return gpiod_export(gpio_to_desc(gpio), direction_may_change);
-}
-
-static inline int gpio_export_link(struct device *dev, const char *name,
-				   unsigned gpio)
-{
-	return gpiod_export_link(dev, name, gpio_to_desc(gpio));
-}
-
-static inline void gpio_unexport(unsigned gpio)
-{
-	gpiod_unexport(gpio_to_desc(gpio));
-}
-
-#else	/* !CONFIG_GPIOLIB */
-
-#include <linux/kernel.h>
-
-static inline bool gpio_is_valid(int number)
-{
-	/* only non-negative numbers are valid */
-	return number >= 0;
-}
-
-/* platforms that don't directly support access to GPIOs through I2C, SPI,
- * or other blocking infrastructure can use these wrappers.
- */
-
-static inline int gpio_cansleep(unsigned gpio)
-{
-	return 0;
-}
-
-static inline int gpio_get_value_cansleep(unsigned gpio)
-{
-	might_sleep();
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value_cansleep(unsigned gpio, int value)
-{
-	might_sleep();
-	__gpio_set_value(gpio, value);
-}
-
-#endif /* !CONFIG_GPIOLIB */
-
-#endif /* _ASM_GENERIC_GPIO_H */
include/linux/gpio.h +107 -9
index 7e6b1b8277ca..c19256f67e02 100644
@@ -54,26 +54,124 @@ struct gpio {
 };
 
 #ifdef CONFIG_GPIOLIB
-#include <asm-generic/gpio.h>
 
-static inline int gpio_get_value(unsigned int gpio)
+#include <linux/compiler.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio/consumer.h>
+
+/* Platforms may implement their GPIO interface with library code,
+ * at a small performance cost for non-inlined operations and some
+ * extra memory (for code and for per-GPIO table entries).
+ *
+ * While the GPIO programming interface defines valid GPIO numbers
+ * to be in the range 0..MAX_INT, this library restricts them to the
+ * smaller range 0..ARCH_NR_GPIOS-1.
+ *
+ * ARCH_NR_GPIOS is somewhat arbitrary; it usually reflects the sum of
+ * builtin/SoC GPIOs plus a number of GPIOs on expanders; the latter is
+ * actually an estimate of a board-specific value.
+ */
+
+#ifndef ARCH_NR_GPIOS
+#if defined(CONFIG_ARCH_NR_GPIO) && CONFIG_ARCH_NR_GPIO > 0
+#define ARCH_NR_GPIOS CONFIG_ARCH_NR_GPIO
+#else
+#define ARCH_NR_GPIOS		512
+#endif
+#endif
+
+/*
+ * "valid" GPIO numbers are nonnegative and may be passed to
+ * setup routines like gpio_request().  only some valid numbers
+ * can successfully be requested and used.
+ *
+ * Invalid GPIO numbers are useful for indicating no-such-GPIO in
+ * platform data and other tables.
+ */
+
+static inline bool gpio_is_valid(int number)
 {
-	return __gpio_get_value(gpio);
+	return number >= 0 && number < ARCH_NR_GPIOS;
 }
 
-static inline void gpio_set_value(unsigned int gpio, int value)
+struct device;
+
+/* caller holds gpio_lock *OR* gpio is marked as requested */
+static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
 {
-	__gpio_set_value(gpio, value);
+	return gpiod_to_chip(gpio_to_desc(gpio));
 }
 
-static inline int gpio_cansleep(unsigned int gpio)
+/* Always use the library code for GPIO management calls,
+ * or when sleeping may be involved.
+ */
+extern int gpio_request(unsigned gpio, const char *label);
+extern void gpio_free(unsigned gpio);
+
+static inline int gpio_direction_input(unsigned gpio)
+{
+	return gpiod_direction_input(gpio_to_desc(gpio));
+}
+static inline int gpio_direction_output(unsigned gpio, int value)
+{
+	return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
+}
+
+static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
 {
-	return __gpio_cansleep(gpio);
+	return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
 }
 
-static inline int gpio_to_irq(unsigned int gpio)
+static inline int gpio_get_value_cansleep(unsigned gpio)
+{
+	return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio));
+}
+static inline void gpio_set_value_cansleep(unsigned gpio, int value)
+{
+	return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
+}
+
+static inline int gpio_get_value(unsigned gpio)
+{
+	return gpiod_get_raw_value(gpio_to_desc(gpio));
+}
+static inline void gpio_set_value(unsigned gpio, int value)
+{
+	return gpiod_set_raw_value(gpio_to_desc(gpio), value);
+}
+
+static inline int gpio_cansleep(unsigned gpio)
+{
+	return gpiod_cansleep(gpio_to_desc(gpio));
+}
+
+static inline int gpio_to_irq(unsigned gpio)
+{
+	return gpiod_to_irq(gpio_to_desc(gpio));
+}
+
+extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
+extern int gpio_request_array(const struct gpio *array, size_t num);
+extern void gpio_free_array(const struct gpio *array, size_t num);
+
+/*
+ * A sysfs interface can be exported by individual drivers if they want,
+ * but more typically is configured entirely from userspace.
+ */
+static inline int gpio_export(unsigned gpio, bool direction_may_change)
+{
+	return gpiod_export(gpio_to_desc(gpio), direction_may_change);
+}
+
+static inline int gpio_export_link(struct device *dev, const char *name,
+				   unsigned gpio)
+{
+	return gpiod_export_link(dev, name, gpio_to_desc(gpio));
+}
+
+static inline void gpio_unexport(unsigned gpio)
 {
-	return __gpio_to_irq(gpio);
+	gpiod_unexport(gpio_to_desc(gpio));
 }
 
 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
Signature · 1 line
2.29.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

PATCH v2 5/8 gpiolib: shrink further

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

gpio_set_debounce() only has a single user, which is trivially converted to gpiod_set_debounce(), while gpio_cansleep() and devm_gpio_free() have no users at all.

Remove them all to shrink the old gpio interface.

---
 .../driver-api/driver-model/devres.rst        |  1 -
 Documentation/driver-api/gpio/legacy.rst      |  2 --
 drivers/gpio/gpiolib-devres.c                 | 25 ----------------
 drivers/input/touchscreen/ads7846.c           |  3 +-
 include/linux/gpio.h                          | 29 -------------------
 5 files changed, 2 insertions(+), 58 deletions(-)
Documentation/driver-api/driver-model/devres.rst +0 -1
index 148e19381b79..52821478decd 100644
@@ -277,7 +277,6 @@ GPIO
   devm_gpiochip_add_data()
   devm_gpio_request()
   devm_gpio_request_one()
-  devm_gpio_free()
 
 I2C
   devm_i2c_new_dummy_device()
Documentation/driver-api/gpio/legacy.rst +0 -2
index 06c05e2d62c1..eae185f771d7 100644
@@ -238,8 +238,6 @@ setup or driver probe/teardown code, so this is an easy constraint.)::
         ## 	gpio_free_array()
 
                 gpio_free()
-                gpio_set_debounce()
-
 
 
 Claiming and Releasing GPIOs
drivers/gpio/gpiolib-devres.c +0 -25
index 79da85d17b71..55465ead492f 100644
@@ -385,13 +385,6 @@ static void devm_gpio_release(struct device *dev, void *res)
 	gpio_free(*gpio);
 }
 
-static int devm_gpio_match(struct device *dev, void *res, void *data)
-{
-	unsigned *this = res, *gpio = data;
-
-	return *this == *gpio;
-}
-
 /**
  *      devm_gpio_request - request a GPIO for a managed device
  *      @dev: device to request the GPIO for
@@ -459,24 +452,6 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
 }
 EXPORT_SYMBOL_GPL(devm_gpio_request_one);
 
-/**
- *      devm_gpio_free - free a GPIO
- *      @dev: device to free GPIO for
- *      @gpio: GPIO to free
- *
- *      Except for the extra @dev argument, this function takes the
- *      same arguments and performs the same function as gpio_free().
- *      This function instead of gpio_free() should be used to manually
- *      free GPIOs allocated with devm_gpio_request().
- */
-void devm_gpio_free(struct device *dev, unsigned int gpio)
-{
-
-	WARN_ON(devres_release(dev, devm_gpio_release, devm_gpio_match,
-		&gpio));
-}
-EXPORT_SYMBOL_GPL(devm_gpio_free);
-
 static void devm_gpio_chip_release(void *data)
 {
 	struct gpio_chip *gc = data;
drivers/input/touchscreen/ads7846.c +2 -1
index a25a77dd9a32..d0664e3b89bb 100644
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/of_device.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/ads7846.h>
@@ -1018,7 +1019,7 @@ static int ads7846_setup_pendown(struct spi_device *spi,
 		ts->gpio_pendown = pdata->gpio_pendown;
 
 		if (pdata->gpio_pendown_debounce)
-			gpio_set_debounce(pdata->gpio_pendown,
+			gpiod_set_debounce(gpio_to_desc(pdata->gpio_pendown),
 					  pdata->gpio_pendown_debounce);
 	} else {
 		dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n");
include/linux/gpio.h +0 -29
index c19256f67e02..64cc8f09eba8 100644
@@ -117,11 +117,6 @@ static inline int gpio_direction_output(unsigned gpio, int value)
 	return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
 }
 
-static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
-{
-	return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
-}
-
 static inline int gpio_get_value_cansleep(unsigned gpio)
 {
 	return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio));
@@ -140,11 +135,6 @@ static inline void gpio_set_value(unsigned gpio, int value)
 	return gpiod_set_raw_value(gpio_to_desc(gpio), value);
 }
 
-static inline int gpio_cansleep(unsigned gpio)
-{
-	return gpiod_cansleep(gpio_to_desc(gpio));
-}
-
 static inline int gpio_to_irq(unsigned gpio)
 {
 	return gpiod_to_irq(gpio_to_desc(gpio));
@@ -181,8 +171,6 @@ struct device;
 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
 int devm_gpio_request_one(struct device *dev, unsigned gpio,
 			  unsigned long flags, const char *label);
-void devm_gpio_free(struct device *dev, unsigned int gpio);
-
 #else /* ! CONFIG_GPIOLIB */
 
 #include <linux/kernel.h>
@@ -239,11 +227,6 @@ static inline int gpio_direction_output(unsigned gpio, int value)
 	return -ENOSYS;
 }
 
-static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
-{
-	return -ENOSYS;
-}
-
 static inline int gpio_get_value(unsigned gpio)
 {
 	/* GPIO can never have been requested or set as {in,out}put */
@@ -257,13 +240,6 @@ static inline void gpio_set_value(unsigned gpio, int value)
 	WARN_ON(1);
 }
 
-static inline int gpio_cansleep(unsigned gpio)
-{
-	/* GPIO can never have been requested or set as {in,out}put */
-	WARN_ON(1);
-	return 0;
-}
-
 static inline int gpio_get_value_cansleep(unsigned gpio)
 {
 	/* GPIO can never have been requested or set as {in,out}put */
@@ -319,11 +295,6 @@ static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
 	return -EINVAL;
 }
 
-static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
-{
-	WARN_ON(1);
-}
-
 #endif /* ! CONFIG_GPIOLIB */
 
 #endif /* __LINUX_GPIO_H */
Signature · 1 line
2.29.2
Reviewed-by on v2 5/8
#7 lore raw

Re: [PATCH v2 5/8] gpiolib: shrink further

Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

gpio_set_debounce() only has a single user, which is trivially converted to gpiod_set_debounce(), while gpio_cansleep() and devm_gpio_free() have no users at all.

Remove them all to shrink the old gpio interface.

A couple of nit-picks below.
In either case,

Quoted 26 lines
---
 .../driver-api/driver-model/devres.rst        |  1 -
 Documentation/driver-api/gpio/legacy.rst      |  2 --
 drivers/gpio/gpiolib-devres.c                 | 25 ----------------
 drivers/input/touchscreen/ads7846.c           |  3 +-
 include/linux/gpio.h                          | 29 -------------------
 5 files changed, 2 insertions(+), 58 deletions(-)
Documentation/driver-api/driver-model/devres.rst +0 -1
index 148e19381b79..52821478decd 100644
@@ -277,7 +277,6 @@ GPIO
   devm_gpiochip_add_data()
   devm_gpio_request()
   devm_gpio_request_one()
-  devm_gpio_free()
 
 I2C
   devm_i2c_new_dummy_device()
Documentation/driver-api/gpio/legacy.rst +0 -0
index 06c05e2d62c1..eae185f771d7 100644

Documentation/driver-api/gpio/legacy.rst setup or driver probe/teardown code, so this is an easy constraint.):: · line 241

Quoted 6 lines
Documentation/driver-api/gpio/legacy.rst +0 -2
@@ -238,8 +238,6 @@ setup or driver probe/teardown code, so this is an easy constraint.)::
         ## 	gpio_free_array()
 
                 gpio_free()
-                gpio_set_debounce()
-
 

One more blank line removal?

Quoted 50 lines
Documentation/driver-api/gpio/legacy.rst +0 -0
 Claiming and Releasing GPIOs
drivers/gpio/gpiolib-devres.c +0 -25
index 79da85d17b71..55465ead492f 100644
@@ -385,13 +385,6 @@ static void devm_gpio_release(struct device *dev, void *res)
 	gpio_free(*gpio);
 }
 
-static int devm_gpio_match(struct device *dev, void *res, void *data)
-{
-	unsigned *this = res, *gpio = data;
-
-	return *this == *gpio;
-}
-
 /**
  *      devm_gpio_request - request a GPIO for a managed device
  *      @dev: device to request the GPIO for
@@ -459,24 +452,6 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
 }
 EXPORT_SYMBOL_GPL(devm_gpio_request_one);
 
-/**
- *      devm_gpio_free - free a GPIO
- *      @dev: device to free GPIO for
- *      @gpio: GPIO to free
- *
- *      Except for the extra @dev argument, this function takes the
- *      same arguments and performs the same function as gpio_free().
- *      This function instead of gpio_free() should be used to manually
- *      free GPIOs allocated with devm_gpio_request().
- */
-void devm_gpio_free(struct device *dev, unsigned int gpio)
-{
-
-	WARN_ON(devres_release(dev, devm_gpio_release, devm_gpio_match,
-		&gpio));
-}
-EXPORT_SYMBOL_GPL(devm_gpio_free);
-
 static void devm_gpio_chip_release(void *data)
 {
 	struct gpio_chip *gc = data;
drivers/input/touchscreen/ads7846.c +0 -0
index a25a77dd9a32..d0664e3b89bb 100644

drivers/input/touchscreen/ads7846.c line 29

Quoted 3 lines
drivers/input/touchscreen/ads7846.c +0 -0
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 
 #include <linux/of_gpio.h>

(1)

drivers/input/touchscreen/ads7846.c line 30

Quoted 3 lines
drivers/input/touchscreen/ads7846.c +1 -0
 #include <linux/of_device.h>
 
+#include <linux/gpio/consumer.h>

(2)

drivers/input/touchscreen/ads7846.c line 31

Quoted 1 line
drivers/input/touchscreen/ads7846.c +0 -0
 #include <linux/gpio.h>

(3)

Seems too many...

Are you planning to clean up this driver to get rid of (1) and (3) altogether?

(I understand that for current purposes above is a good quick cleanup)

Quoted 89 lines

#include <linux/spi/spi.h>
#include <linux/spi/ads7846.h>

drivers/input/touchscreen/ads7846.c +1 -1
@@ -1018,7 +1019,7 @@ static int ads7846_setup_pendown(struct spi_device *spi,
 		ts->gpio_pendown = pdata->gpio_pendown;
 
 		if (pdata->gpio_pendown_debounce)
-			gpio_set_debounce(pdata->gpio_pendown,
+			gpiod_set_debounce(gpio_to_desc(pdata->gpio_pendown),
 					  pdata->gpio_pendown_debounce);
 	} else {
 		dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n");
include/linux/gpio.h +0 -29
index c19256f67e02..64cc8f09eba8 100644
@@ -117,11 +117,6 @@ static inline int gpio_direction_output(unsigned gpio, int value)
 	return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
 }
 
-static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
-{
-	return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
-}
-
 static inline int gpio_get_value_cansleep(unsigned gpio)
 {
 	return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio));
@@ -140,11 +135,6 @@ static inline void gpio_set_value(unsigned gpio, int value)
 	return gpiod_set_raw_value(gpio_to_desc(gpio), value);
 }
 
-static inline int gpio_cansleep(unsigned gpio)
-{
-	return gpiod_cansleep(gpio_to_desc(gpio));
-}
-
 static inline int gpio_to_irq(unsigned gpio)
 {
 	return gpiod_to_irq(gpio_to_desc(gpio));
@@ -181,8 +171,6 @@ struct device;
 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
 int devm_gpio_request_one(struct device *dev, unsigned gpio,
 			  unsigned long flags, const char *label);
-void devm_gpio_free(struct device *dev, unsigned int gpio);
-
 #else /* ! CONFIG_GPIOLIB */
 
 #include <linux/kernel.h>
@@ -239,11 +227,6 @@ static inline int gpio_direction_output(unsigned gpio, int value)
 	return -ENOSYS;
 }
 
-static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
-{
-	return -ENOSYS;
-}
-
 static inline int gpio_get_value(unsigned gpio)
 {
 	/* GPIO can never have been requested or set as {in,out}put */
@@ -257,13 +240,6 @@ static inline void gpio_set_value(unsigned gpio, int value)
 	WARN_ON(1);
 }
 
-static inline int gpio_cansleep(unsigned gpio)
-{
-	/* GPIO can never have been requested or set as {in,out}put */
-	WARN_ON(1);
-	return 0;
-}
-
 static inline int gpio_get_value_cansleep(unsigned gpio)
 {
 	/* GPIO can never have been requested or set as {in,out}put */
@@ -319,11 +295,6 @@ static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
 	return -EINVAL;
 }
 
-static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
-{
-	WARN_ON(1);
-}
-
 #endif /* ! CONFIG_GPIOLIB */
 
 #endif /* __LINUX_GPIO_H */
Signature · 1 line
2.29.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v2 5/8] gpiolib: shrink further

Quoted 9 lines · Andy Shevchenko

Review setup or driver probe/teardown code, so this is an easy constraint.):: · line 241

Quoted 7 lines
(quoted diff) +0 -2
@@ -238,8 +238,6 @@ setup or driver probe/teardown code, so this is an easy constraint.)::
         ##   gpio_free_array()
 
                 gpio_free()
-                gpio_set_debounce()
-
 

One more blank line removal?

I think two blank lines at the end of a section is the normal style for this file.
Do you mean I should remove another line, or not remove the third blank line here?

Quoted 19 lines

drivers/input/touchscreen/ads7846.c line 29

Quoted 8 lines
drivers/input/touchscreen/ads7846.c +0 -0
index a25a77dd9a32..d0664e3b89bb 100644
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 
 #include <linux/of_gpio.h>

(1)

drivers/input/touchscreen/ads7846.c line 32

Quoted 3 lines
drivers/input/touchscreen/ads7846.c +1 -0
 #include <linux/of_device.h>
 
+#include <linux/gpio/consumer.h>

(2)

drivers/input/touchscreen/ads7846.c line 33

Quoted 1 line
drivers/input/touchscreen/ads7846.c +0 -0
 #include <linux/gpio.h>
Quoted 7 lines

(3)

Seems too many...

Are you planning to clean up this driver to get rid of (1) and (3) altogether?

(I understand that for current purposes above is a good quick cleanup)

Ideally we should only use linux/gpio/consumer.h, which is required for gpiod_set_debounce(). of_gpio.h is still needed for of_get_named_gpio() and should be taken out once we change this to gpiod_get(), while linux/gpio.h is still needed for gpio_is_valid()/gpio_get_value() and should be removed when those are changed to the gpiod_ versions.

We could do an intermediate patch that converts one half of the interface, something like

(quoted diff) +0 -0

b/drivers/input/touchscreen/ads7846.c
index d0664e3b89bb..60e6b292ccdf 100644

drivers/input/touchscreen/ads7846.c +10 -5
@@ -140,7 +140,7 @@ struct ads7846 {
        int                     (*filter)(void *data, int data_idx, int *val);
        void                    *filter_data;
        int                     (*get_pendown_state)(void);
-       int                     gpio_pendown;
+       struct gpio_desc        *gpio_pendown;
 
        void                    (*wait_for_sync)(void);
 };
@@ -223,7 +223,7 @@ static int get_pendown_state(struct ads7846 *ts)
        if (ts->get_pendown_state)
                return ts->get_pendown_state();
 
-       return !gpio_get_value(ts->gpio_pendown);
+       return !gpiod_get_value(ts->gpio_pendown);
 }
 
 static void ads7846_report_pen_up(struct ads7846 *ts)
@@ -1005,6 +1005,11 @@ static int ads7846_setup_pendown(struct spi_device *spi,
 
        if (pdata->get_pendown_state) {
                ts->get_pendown_state = pdata->get_pendown_state;
+       } else if (ts->gpio_pendown) {
+               if (IS_ERR(ts->gpio_pendown)) {
+                       dev_err(&spi->dev, "missing pendown gpio\n");
+                       return PTR_ERR(ts->gpio_pendown);
+               }
        } else if (gpio_is_valid(pdata->gpio_pendown)) {
 
                err = devm_gpio_request_one(&spi->dev, pdata->gpio_pendown,
@@ -1016,10 +1016,10 @@ static int ads7846_setup_pendown(struct spi_device *spi,
                        return err;
                }
 
-               ts->gpio_pendown = pdata->gpio_pendown;
+               ts->gpio_pendown = gpio_to_desc(pdata->gpio_pendown);
 
                if (pdata->gpio_pendown_debounce)
-                       gpiod_set_debounce(gpio_to_desc(pdata->gpio_pendown),
+                       gpiod_set_debounce(ts->gpio_pendown,
                                          pdata->gpio_pendown_debounce);
        } else {
                dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n");
@@ -1128,7 +1128,7 @@ static const struct of_device_id ads7846_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, ads7846_dt_ids);
 
-static const struct ads7846_platform_data *ads7846_probe_dt(struct device *dev)
+static const struct ads7846_platform_data *ads7846_probe_dt(struct

ads7846 *ts, struct device *dev)

 {
        struct ads7846_platform_data *pdata;
        struct device_node *node = dev->of_node;
@@ -1193,7 +1193,7 @@ static const struct ads7846_platform_data
*ads7846_probe_dt(struct device *dev)
        pdata->wakeup = of_property_read_bool(node, "wakeup-source") ||
                        of_property_read_bool(node, "linux,wakeup");

- pdata->gpio_pendown = of_get_named_gpio(dev->of_node,
"pendown-gpio", 0);
+ ts->gpio_pendown = gpiod_get(dev, "pendown-gpio", GPIOD_IN);

        return pdata;

}
@@ -1267,7 +1267,7 @@ static int ads7846_probe(struct spi_device *spi)

        pdata = dev_get_platdata(dev);
        if (!pdata) {
-               pdata = ads7846_probe_dt(dev);
+               pdata = ads7846_probe_dt(ts, dev);
                if (IS_ERR(pdata))
                        return PTR_ERR(pdata);
        }

while leaving the platform side untouched, but I think Linus' plan was to remove the gpio settings from all platform data and instead use the gpio lookup in the board files.

Arnd

#9 lore raw

Re: [PATCH v2 5/8] gpiolib: shrink further

Quoted 8 lines · Arnd Bergmann

Ideally we should only use linux/gpio/consumer.h, which is required for gpiod_set_debounce(). of_gpio.h is still needed for of_get_named_gpio() and should be taken out once we change this to gpiod_get(), while linux/gpio.h is still needed for gpio_is_valid()/gpio_get_value() and should be removed when those are changed to the gpiod_ versions.

We could do an intermediate patch that converts one half of the interface, something like

When I convert stuff I try to go all the way when I can. It can be a bit daring if no one is there to test changes.

The patch looks good though apart from:

drivers/input/touchscreen/ads7846.c static int ads7846_setup_pendown(struct spi_device *spi, · line 1019

Quoted 2 lines
drivers/input/touchscreen/ads7846.c +1 -1
-               ts->gpio_pendown = pdata->gpio_pendown;
+               ts->gpio_pendown = gpio_to_desc(pdata->gpio_pendown);

I usually even go into the defined platform data and try to convert the boardfile to use a descriptor table so this is never needed. (But, more work.)

Examples:
git log -p --author=Walleij arch/arm/mach-pxa/

Quoted 3 lines

- pdata->gpio_pendown = of_get_named_gpio(dev->of_node,
"pendown-gpio", 0);
+ ts->gpio_pendown = gpiod_get(dev, "pendown-gpio", GPIOD_IN);

Needs to be just gpiod_get(dev, "pendown", GPIOD_IN); the new API tries the "-gpio[s]" suffixes when going into the device tree.

Yours,
Linus Walleij

#10 lore raw

Re: [PATCH v2 5/8] gpiolib: shrink further

Quoted 15 lines · Linus Walleij
Quoted 8 lines · Arnd Bergmann

Ideally we should only use linux/gpio/consumer.h, which is required for gpiod_set_debounce(). of_gpio.h is still needed for of_get_named_gpio() and should be taken out once we change this to gpiod_get(), while linux/gpio.h is still needed for gpio_is_valid()/gpio_get_value() and should be removed when those are changed to the gpiod_ versions.

We could do an intermediate patch that converts one half of the interface, something like

When I convert stuff I try to go all the way when I can. It can be a bit daring if no one is there to test changes.

Quoted 8 lines

The patch looks good though apart from:

drivers/input/touchscreen/ads7846.c static int ads7846_setup_pendown(struct spi_device *spi, · line 1019

Quoted 2 lines
drivers/input/touchscreen/ads7846.c +1 -1
-               ts->gpio_pendown = pdata->gpio_pendown;
+               ts->gpio_pendown = gpio_to_desc(pdata->gpio_pendown);

I usually even go into the defined platform data and try to convert the boardfile to use a descriptor table so this is never needed. (But, more work.)

Yes, I noticed. I had done some conversions for pxa this way, I should look in my tree if I should resend those.

My hope would be that by making the steps smaller, it's easier to find people that are willing and able to help out. From looking at it so far, I would partition the problem something like:

a) Remove the (now) trivial wrappers around gpiod_*() functions by using open-coded gpio_to_desc() calls everywhere. This doesn't improve the code, but it can be trivially scripted and it should help by making it less practical to put new users in.

b) one driver/subsystem at a time, replace all calls to {devm_,}gpio_{free,request{,_one}} with a new
struct gpio_desc *gpiod_get_legacy(struct device *dev, int gpio, enum gpiod_flags flags);
This takes the conversion only half-way, but is much more manageable for a random contributor or reviewer, and it undoes the ugly bits added in step a), making it a clear improvement.

c) convert the boardfile/platform_data/of_get_named_gpio side along with the corresponding s/gpiod_get_legacy/gpiod_get/, which is now a fairly simple change on the driver side, while the platform side can be reviewed by the platform
maintainers.

Quoted 9 lines

Examples:
git log -p --author=Walleij arch/arm/mach-pxa/

Quoted 3 lines

- pdata->gpio_pendown = of_get_named_gpio(dev->of_node,
"pendown-gpio", 0);
+ ts->gpio_pendown = gpiod_get(dev, "pendown-gpio", GPIOD_IN);

Needs to be just gpiod_get(dev, "pendown", GPIOD_IN); the new API tries the "-gpio[s]" suffixes when going into the device tree.

Ok, got it.

Arnd

#11 lore raw

PATCH v2 6/8 gpiolib: remove legacy gpio_export

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

There are only a handful of users of gpio_export() and related functions.

As these are just wrappers around the modern gpiod_export() helper, remove the wrappers and open-code the gpio_to_desc in all callers to shrink the legacy API.

---
 Documentation/admin-guide/gpio/sysfs.rst  |  2 +-
 Documentation/driver-api/gpio/legacy.rst  | 30 -----------------
 Documentation/translations/zh_CN/gpio.txt | 26 --------------
 Documentation/translations/zh_TW/gpio.txt | 27 ---------------
 arch/arm/mach-davinci/board-dm646x-evm.c  | 28 +++++++++-------
 arch/arm/mach-omap2/pdata-quirks.c        |  9 ++---
 arch/sh/boards/mach-ap325rxa/setup.c      |  7 ++--
 drivers/gpio/gpiolib-sysfs.c              |  4 +--
 drivers/media/i2c/noon010pc30.c           |  5 +--
 drivers/media/i2c/ov9650.c                |  4 +--
 drivers/media/i2c/s5k4ecgx.c              |  3 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c   | 10 ++++--
 drivers/mfd/dm355evm_msp.c                |  3 +-
 drivers/net/ieee802154/ca8210.c           |  3 +-
 include/linux/gpio.h                      | 41 -----------------------
 15 files changed, 45 insertions(+), 157 deletions(-)
Documentation/admin-guide/gpio/sysfs.rst +1 -1
index ec09ffd983e7..35171d15f78d 100644
@@ -145,7 +145,7 @@ requested using gpio_request()::
 	/* export the GPIO to userspace */
 	int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
 
-	/* reverse gpio_export() */
+	/* reverse gpiod_export() */
 	void gpiod_unexport(struct gpio_desc *desc);
 
 	/* create a sysfs link to an exported GPIO node */
Documentation/driver-api/gpio/legacy.rst +0 -30
index eae185f771d7..34fcb14814db 100644
@@ -717,36 +717,6 @@ gpiochip nodes (possibly in conjunction with schematics) to determine
 the correct GPIO number to use for a given signal.
 
 
-Exporting from Kernel code
---------------------------
-Kernel code can explicitly manage exports of GPIOs which have already been
-requested using gpio_request()::
-
-	/* export the GPIO to userspace */
-	int gpio_export(unsigned gpio, bool direction_may_change);
-
-	/* reverse gpio_export() */
-	void gpio_unexport();
-
-	/* create a sysfs link to an exported GPIO node */
-	int gpio_export_link(struct device *dev, const char *name,
-		unsigned gpio)
-
-After a kernel driver requests a GPIO, it may only be made available in
-the sysfs interface by gpio_export().  The driver can control whether the
-signal direction may change.  This helps drivers prevent userspace code
-from accidentally clobbering important system state.
-
-This explicit exporting can help with debugging (by making some kinds
-of experiments easier), or can provide an always-there interface that's
-suitable for documenting as part of a board support package.
-
-After the GPIO has been exported, gpio_export_link() allows creating
-symlinks from elsewhere in sysfs to the GPIO sysfs node.  Drivers can
-use this to provide the interface under their own device in sysfs with
-a descriptive name.
-
-
 API Reference
 =============
 
Documentation/translations/zh_CN/gpio.txt +0 -26
index a23ee14fc927..e49fa88a2804 100644
@@ -622,29 +622,3 @@ GPIO 控制器的路径类似 /sys/class/gpio/gpiochip42/ (对于从#42 GPIO
 固定的,例如在扩展卡上的 GPIO会根据所使用的主板或所在堆叠架构中其他的板子而
 有所不同。在这种情况下,你可能需要使用 gpiochip 节点(尽可能地结合电路图)来
 确定给定信号所用的 GPIO 编号。
-
-
-从内核代码中导出
--------------
-内核代码可以明确地管理那些已通过 gpio_request()申请的 GPIO 的导出:
-
-	/* 导出 GPIO 到用户空间 */
-	int gpio_export(unsigned gpio, bool direction_may_change);
-
-	/* gpio_export()的逆操作 */
-	void gpio_unexport();
-
-	/* 创建一个 sysfs 连接到已导出的 GPIO 节点 */
-	int gpio_export_link(struct device *dev, const char *name,
-		unsigned gpio)
-
-在一个内核驱动申请一个 GPIO 之后,它可以通过 gpio_export()使其在 sysfs
-接口中可见。该驱动可以控制信号方向是否可修改。这有助于防止用户空间代码无意间
-破坏重要的系统状态。
-
-这个明确的导出有助于(通过使某些实验更容易来)调试,也可以提供一个始终存在的接口,
-与文档配合作为板级支持包的一部分。
-
-在 GPIO 被导出之后,gpio_export_link()允许在 sysfs 文件系统的任何地方
-创建一个到这个 GPIO sysfs 节点的符号链接。这样驱动就可以通过一个描述性的
-名字,在 sysfs 中他们所拥有的设备下提供一个(到这个 GPIO sysfs 节点的)接口。
Documentation/translations/zh_TW/gpio.txt +0 -27
index e3c076dd75a5..c9bf3ddd08b3 100644
@@ -622,30 +622,3 @@ GPIO 控制器的路徑類似 /sys/class/gpio/gpiochip42/ (對於從#42 GPIO
 固定的,例如在擴展卡上的 GPIO會根據所使用的主板或所在堆疊架構中其他的板子而
 有所不同。在這種情況下,你可能需要使用 gpiochip 節點(儘可能地結合電路圖)來
 確定給定信號所用的 GPIO 編號。
-
-
-從內核代碼中導出
--------------
-內核代碼可以明確地管理那些已通過 gpio_request()申請的 GPIO 的導出:
-
-	/* 導出 GPIO 到用戶空間 */
-	int gpio_export(unsigned gpio, bool direction_may_change);
-
-	/* gpio_export()的逆操作 */
-	void gpio_unexport();
-
-	/* 創建一個 sysfs 連接到已導出的 GPIO 節點 */
-	int gpio_export_link(struct device *dev, const char *name,
-		unsigned gpio)
-
-在一個內核驅動申請一個 GPIO 之後,它可以通過 gpio_export()使其在 sysfs
-接口中可見。該驅動可以控制信號方向是否可修改。這有助於防止用戶空間代碼無意間
-破壞重要的系統狀態。
-
-這個明確的導出有助於(通過使某些實驗更容易來)調試,也可以提供一個始終存在的接口,
-與文檔配合作爲板級支持包的一部分。
-
-在 GPIO 被導出之後,gpio_export_link()允許在 sysfs 文件系統的任何地方
-創建一個到這個 GPIO sysfs 節點的符號連結。這樣驅動就可以通過一個描述性的
-名字,在 sysfs 中他們所擁有的設備下提供一個(到這個 GPIO sysfs 節點的)接口。
-
arch/arm/mach-davinci/board-dm646x-evm.c +15 -13
index ee91d81ebbfd..4a258e33021d 100644
@@ -19,7 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/leds.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
 #include <linux/property.h>
@@ -249,7 +249,7 @@ static int evm_led_teardown(struct i2c_client *client, int gpio,
 	return 0;
 }
 
-static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
+static struct gpio_desc *evm_sw_gpio[4];
 
 static int evm_sw_setup(struct i2c_client *client, int gpio,
 			unsigned ngpio, void *c)
@@ -259,17 +259,19 @@ static int evm_sw_setup(struct i2c_client *client, int gpio,
 	char label[10];
 
 	for (i = 0; i < 4; ++i) {
+		struct gpio_desc *desc = gpio_to_desc(gpio + i);
+
 		snprintf(label, 10, "user_sw%d", i);
-		status = gpio_request(gpio, label);
+		status = gpio_request(gpio + i, label);
 		if (status)
 			goto out_free;
-		evm_sw_gpio[i] = gpio++;
+		evm_sw_gpio[i] = desc;
 
-		status = gpio_direction_input(evm_sw_gpio[i]);
+		status = gpiod_direction_input(desc);
 		if (status)
 			goto out_free;
 
-		status = gpio_export(evm_sw_gpio[i], 0);
+		status = gpiod_export(desc, 0);
 		if (status)
 			goto out_free;
 	}
@@ -277,9 +279,9 @@ static int evm_sw_setup(struct i2c_client *client, int gpio,
 
 out_free:
 	for (i = 0; i < 4; ++i) {
-		if (evm_sw_gpio[i] != -EINVAL) {
-			gpio_free(evm_sw_gpio[i]);
-			evm_sw_gpio[i] = -EINVAL;
+		if (evm_sw_gpio[i]) {
+			gpio_free(pin + i);
+			evm_sw_gpio[i] = NULL;
 		}
 	}
 	return status;
@@ -291,10 +293,10 @@ static int evm_sw_teardown(struct i2c_client *client, int gpio,
 	int i;
 
 	for (i = 0; i < 4; ++i) {
-		if (evm_sw_gpio[i] != -EINVAL) {
-			gpio_unexport(evm_sw_gpio[i]);
-			gpio_free(evm_sw_gpio[i]);
-			evm_sw_gpio[i] = -EINVAL;
+		if (evm_sw_gpio[i]) {
+			gpiod_unexport(evm_sw_gpio[i]);
+			gpio_free(gpio + i);
+			evm_sw_gpio[i] = NULL;
 		}
 	}
 	return 0;
arch/arm/mach-omap2/pdata-quirks.c +5 -4
index e7fd29a502a0..1fdf7fcf091e 100644
@@ -6,6 +6,7 @@
  */
 #include <linux/clk.h>
 #include <linux/davinci_emac.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -120,7 +121,7 @@ static int omap3_sbc_t3730_twl_callback(struct device *dev,
 	if (res)
 		return res;
 
-	gpio_export(gpio, 0);
+	gpiod_export(gpio_to_desc(gpio), 0);
 
 	return 0;
 }
@@ -135,7 +136,7 @@ static void __init omap3_sbc_t3x_usb_hub_init(int gpio, char *hub_name)
 		return;
 	}
 
-	gpio_export(gpio, 0);
+	gpiod_export(gpio_to_desc(gpio), 0);
 
 	udelay(10);
 	gpio_set_value(gpio, 1);
@@ -212,8 +213,8 @@ static void __init omap3_sbc_t3517_wifi_init(void)
 		return;
 	}
 
-	gpio_export(cm_t3517_wlan_gpios[0].gpio, 0);
-	gpio_export(cm_t3517_wlan_gpios[1].gpio, 0);
+	gpiod_export(gpio_to_desc(cm_t3517_wlan_gpios[0].gpio), 0);
+	gpiod_export(gpio_to_desc(cm_t3517_wlan_gpios[1].gpio), 0);
 
 	msleep(100);
 	gpio_set_value(cm_t3517_wlan_gpios[1].gpio, 0);
arch/sh/boards/mach-ap325rxa/setup.c +4 -3
index c77b5f00a66a..151792162152 100644
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -411,16 +412,16 @@ static int __init ap325rxa_devices_setup(void)
 	/* LD3 and LD4 LEDs */
 	gpio_request(GPIO_PTX5, NULL); /* RUN */
 	gpio_direction_output(GPIO_PTX5, 1);
-	gpio_export(GPIO_PTX5, 0);
+	gpiod_export(gpio_to_desc(GPIO_PTX5), 0);
 
 	gpio_request(GPIO_PTX4, NULL); /* INDICATOR */
 	gpio_direction_output(GPIO_PTX4, 0);
-	gpio_export(GPIO_PTX4, 0);
+	gpiod_export(gpio_to_desc(GPIO_PTX4), 0);
 
 	/* SW1 input */
 	gpio_request(GPIO_PTF7, NULL); /* MODE */
 	gpio_direction_input(GPIO_PTF7);
-	gpio_export(GPIO_PTF7, 0);
+	gpiod_export(gpio_to_desc(GPIO_PTF7), 0);
 
 	/* LCDC */
 	gpio_request(GPIO_FN_LCDD15, NULL);
drivers/gpio/gpiolib-sysfs.c +2 -2
index 4098bc7f88b7..a83fba3649c4 100644
@@ -511,7 +511,7 @@ static ssize_t unexport_store(struct class *class,
 		goto done;
 
 	desc = gpio_to_desc(gpio);
-	/* reject bogus commands (gpio_unexport ignores them) */
+	/* reject bogus commands (gpiod_unexport ignores them) */
 	if (!desc) {
 		pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
 		return -EINVAL;
@@ -814,7 +814,7 @@ static int __init gpiolib_sysfs_init(void)
 	 * early (e.g. before the class_register above was called).
 	 *
 	 * We run before arch_initcall() so chip->dev nodes can have
-	 * registered, and so arch_initcall() can always gpio_export().
+	 * registered, and so arch_initcall() can always gpiod_export().
 	 */
 	spin_lock_irqsave(&gpio_lock, flags);
 	list_for_each_entry(gdev, &gpio_devices, list) {
drivers/media/i2c/noon010pc30.c +3 -2
index f3ac379ef34a..6faa44eb5354 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/slab.h>
@@ -755,7 +756,7 @@ static int noon010_probe(struct i2c_client *client,
 			goto np_err;
 		}
 		info->gpio_nreset = pdata->gpio_nreset;
-		gpio_export(info->gpio_nreset, 0);
+		gpiod_export(gpio_to_desc(info->gpio_nreset), 0);
 	}
 
 	if (gpio_is_valid(pdata->gpio_nstby)) {
@@ -767,7 +768,7 @@ static int noon010_probe(struct i2c_client *client,
 			goto np_err;
 		}
 		info->gpio_nstby = pdata->gpio_nstby;
-		gpio_export(info->gpio_nstby, 0);
+		gpiod_export(gpio_to_desc(info->gpio_nstby), 0);
 	}
 
 	for (i = 0; i < NOON010_NUM_SUPPLIES; i++)
drivers/media/i2c/ov9650.c +2 -2
index c313e11a9754..021acd20ede2 100644
@@ -1426,9 +1426,9 @@ static int ov965x_configure_gpios_pdata(struct ov965x *ov965x,
 			return ret;
 		v4l2_dbg(1, debug, &ov965x->sd, "set gpio %d to 1\n", gpio);
 
-		gpio_set_value_cansleep(gpio, 1);
-		gpio_export(gpio, 0);
 		ov965x->gpios[i] = gpio_to_desc(gpio);
+		gpiod_set_value_cansleep(ov965x->gpios[i], 1);
+		gpiod_export(ov965x->gpios[i], 0);
 	}
 
 	return 0;
drivers/media/i2c/s5k4ecgx.c +2 -1
index af9a305242cd..419d03fcc978 100644
@@ -15,6 +15,7 @@
 #include <linux/ctype.h>
 #include <linux/delay.h>
 #include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
@@ -852,7 +853,7 @@ static int s5k4ecgx_config_gpio(int nr, int val, const char *name)
 		return 0;
 	ret = gpio_request_one(nr, flags, name);
 	if (!ret)
-		gpio_export(nr, 0);
+		gpiod_export(gpio_to_desc(nr), 0);
 
 	return ret;
 }
drivers/media/pci/sta2x11/sta2x11_vip.c +7 -3
index 524912f20d9f..f7cef598f21d 100644
@@ -18,6 +18,7 @@
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/delay.h>
@@ -893,6 +894,7 @@ static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
 static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 			    const char *name)
 {
+	struct gpio_desc *desc = gpio_to_desc(pin);
 	int ret = -ENODEV;
 
 	if (!gpio_is_valid(pin))
@@ -904,7 +906,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 		return ret;
 	}
 
-	ret = gpio_direction_output(pin, dir);
+	ret = gpiod_direction_output(desc, dir);
 	if (ret) {
 		dev_err(dev, "Failed to set direction for pin %d (%s)\n",
 			pin, name);
@@ -912,7 +914,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 		return ret;
 	}
 
-	ret = gpio_export(pin, false);
+	ret = gpiod_export(desc, false);
 	if (ret) {
 		dev_err(dev, "Failed to export pin %d (%s)\n", pin, name);
 		gpio_free(pin);
@@ -932,8 +934,10 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 static void vip_gpio_release(struct device *dev, int pin, const char *name)
 {
 	if (gpio_is_valid(pin)) {
+		struct gpio_desc *desc = gpio_to_desc(pin);
+
 		dev_dbg(dev, "releasing pin %d (%s)\n",	pin, name);
-		gpio_unexport(pin);
+		gpiod_unexport(desc);
 		gpio_free(pin);
 	}
 }
drivers/mfd/dm355evm_msp.c +2 -1
index 54fb6cbd2aa0..2388fb4d0121 100644
@@ -11,6 +11,7 @@
 #include <linux/clk.h>
 #include <linux/module.h>
 #include <linux/err.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/gpio/machine.h>
 #include <linux/leds.h>
@@ -329,7 +330,7 @@ static int add_children(struct i2c_client *client)
 		gpio_request_one(gpio, GPIOF_IN, config_inputs[i].label);
 
 		/* make it easy for userspace to see these */
-		gpio_export(gpio, false);
+		gpiod_export(gpio_to_desc(gpio), false);
 	}
 
 	/* MMC/SD inputs -- right after the last config input */
drivers/net/ieee802154/ca8210.c +2 -1
index ece6ff6049f6..6252907b2c92 100644
@@ -51,6 +51,7 @@
 #include <linux/clk-provider.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/ieee802154.h>
 #include <linux/io.h>
@@ -2895,7 +2896,7 @@ static int ca8210_interrupt_init(struct spi_device *spi)
 	);
 	if (ret) {
 		dev_crit(&spi->dev, "request_irq %d failed\n", pdata->irq_id);
-		gpio_unexport(pdata->gpio_irq);
+		gpiod_unexport(gpio_to_desc(pdata->gpio_irq));
 		gpio_free(pdata->gpio_irq);
 	}
 
include/linux/gpio.h +0 -41

53 lines not on this page · raw message

Signature · 1 line
2.29.2
Reviewed-by on v2 6/8
#12 lore raw

Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export

Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

There are only a handful of users of gpio_export() and related functions.

As these are just wrappers around the modern gpiod_export() helper, remove the wrappers and open-code the gpio_to_desc in all callers to shrink the legacy API.

What I wish to see meanwhile is a section in the TODO list somewhere to clean up those modules that have gpio.h. Linus, do we have one in the kernel or is it your personal TODO?

In case we have one in the kernel, please add there modules you modified in a way that they still need further attention.

Quoted 165 lines
---
 Documentation/admin-guide/gpio/sysfs.rst  |  2 +-
 Documentation/driver-api/gpio/legacy.rst  | 30 -----------------
 Documentation/translations/zh_CN/gpio.txt | 26 --------------
 Documentation/translations/zh_TW/gpio.txt | 27 ---------------
 arch/arm/mach-davinci/board-dm646x-evm.c  | 28 +++++++++-------
 arch/arm/mach-omap2/pdata-quirks.c        |  9 ++---
 arch/sh/boards/mach-ap325rxa/setup.c      |  7 ++--
 drivers/gpio/gpiolib-sysfs.c              |  4 +--
 drivers/media/i2c/noon010pc30.c           |  5 +--
 drivers/media/i2c/ov9650.c                |  4 +--
 drivers/media/i2c/s5k4ecgx.c              |  3 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c   | 10 ++++--
 drivers/mfd/dm355evm_msp.c                |  3 +-
 drivers/net/ieee802154/ca8210.c           |  3 +-
 include/linux/gpio.h                      | 41 -----------------------
 15 files changed, 45 insertions(+), 157 deletions(-)
Documentation/admin-guide/gpio/sysfs.rst +1 -1
index ec09ffd983e7..35171d15f78d 100644
@@ -145,7 +145,7 @@ requested using gpio_request()::
 	/* export the GPIO to userspace */
 	int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
 
-	/* reverse gpio_export() */
+	/* reverse gpiod_export() */
 	void gpiod_unexport(struct gpio_desc *desc);
 
 	/* create a sysfs link to an exported GPIO node */
Documentation/driver-api/gpio/legacy.rst +0 -30
index eae185f771d7..34fcb14814db 100644
@@ -717,36 +717,6 @@ gpiochip nodes (possibly in conjunction with schematics) to determine
 the correct GPIO number to use for a given signal.
 
 
-Exporting from Kernel code
---------------------------
-Kernel code can explicitly manage exports of GPIOs which have already been
-requested using gpio_request()::
-
-	/* export the GPIO to userspace */
-	int gpio_export(unsigned gpio, bool direction_may_change);
-
-	/* reverse gpio_export() */
-	void gpio_unexport();
-
-	/* create a sysfs link to an exported GPIO node */
-	int gpio_export_link(struct device *dev, const char *name,
-		unsigned gpio)
-
-After a kernel driver requests a GPIO, it may only be made available in
-the sysfs interface by gpio_export().  The driver can control whether the
-signal direction may change.  This helps drivers prevent userspace code
-from accidentally clobbering important system state.
-
-This explicit exporting can help with debugging (by making some kinds
-of experiments easier), or can provide an always-there interface that's
-suitable for documenting as part of a board support package.
-
-After the GPIO has been exported, gpio_export_link() allows creating
-symlinks from elsewhere in sysfs to the GPIO sysfs node.  Drivers can
-use this to provide the interface under their own device in sysfs with
-a descriptive name.
-
-
 API Reference
 =============
 
Documentation/translations/zh_CN/gpio.txt +0 -26
index a23ee14fc927..e49fa88a2804 100644
@@ -622,29 +622,3 @@ GPIO 控制器的路径类似 /sys/class/gpio/gpiochip42/ (对于从#42 GPIO
 固定的,例如在扩展卡上的 GPIO会根据所使用的主板或所在堆叠架构中其他的板子而
 有所不同。在这种情况下,你可能需要使用 gpiochip 节点(尽可能地结合电路图)来
 确定给定信号所用的 GPIO 编号。
-
-
-从内核代码中导出
--------------
-内核代码可以明确地管理那些已通过 gpio_request()申请的 GPIO 的导出:
-
-	/* 导出 GPIO 到用户空间 */
-	int gpio_export(unsigned gpio, bool direction_may_change);
-
-	/* gpio_export()的逆操作 */
-	void gpio_unexport();
-
-	/* 创建一个 sysfs 连接到已导出的 GPIO 节点 */
-	int gpio_export_link(struct device *dev, const char *name,
-		unsigned gpio)
-
-在一个内核驱动申请一个 GPIO 之后,它可以通过 gpio_export()使其在 sysfs
-接口中可见。该驱动可以控制信号方向是否可修改。这有助于防止用户空间代码无意间
-破坏重要的系统状态。
-
-这个明确的导出有助于(通过使某些实验更容易来)调试,也可以提供一个始终存在的接口,
-与文档配合作为板级支持包的一部分。
-
-在 GPIO 被导出之后,gpio_export_link()允许在 sysfs 文件系统的任何地方
-创建一个到这个 GPIO sysfs 节点的符号链接。这样驱动就可以通过一个描述性的
-名字,在 sysfs 中他们所拥有的设备下提供一个(到这个 GPIO sysfs 节点的)接口。
Documentation/translations/zh_TW/gpio.txt +0 -27
index e3c076dd75a5..c9bf3ddd08b3 100644
@@ -622,30 +622,3 @@ GPIO 控制器的路徑類似 /sys/class/gpio/gpiochip42/ (對於從#42 GPIO
 固定的,例如在擴展卡上的 GPIO會根據所使用的主板或所在堆疊架構中其他的板子而
 有所不同。在這種情況下,你可能需要使用 gpiochip 節點(儘可能地結合電路圖)來
 確定給定信號所用的 GPIO 編號。
-
-
-從內核代碼中導出
--------------
-內核代碼可以明確地管理那些已通過 gpio_request()申請的 GPIO 的導出:
-
-	/* 導出 GPIO 到用戶空間 */
-	int gpio_export(unsigned gpio, bool direction_may_change);
-
-	/* gpio_export()的逆操作 */
-	void gpio_unexport();
-
-	/* 創建一個 sysfs 連接到已導出的 GPIO 節點 */
-	int gpio_export_link(struct device *dev, const char *name,
-		unsigned gpio)
-
-在一個內核驅動申請一個 GPIO 之後,它可以通過 gpio_export()使其在 sysfs
-接口中可見。該驅動可以控制信號方向是否可修改。這有助於防止用戶空間代碼無意間
-破壞重要的系統狀態。
-
-這個明確的導出有助於(通過使某些實驗更容易來)調試,也可以提供一個始終存在的接口,
-與文檔配合作爲板級支持包的一部分。
-
-在 GPIO 被導出之後,gpio_export_link()允許在 sysfs 文件系統的任何地方
-創建一個到這個 GPIO sysfs 節點的符號連結。這樣驅動就可以通過一個描述性的
-名字,在 sysfs 中他們所擁有的設備下提供一個(到這個 GPIO sysfs 節點的)接口。
-
arch/arm/mach-davinci/board-dm646x-evm.c +2 -2
index ee91d81ebbfd..4a258e33021d 100644
@@ -19,7 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/leds.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
 #include <linux/property.h>
@@ -249,7 +249,7 @@ static int evm_led_teardown(struct i2c_client *client, int gpio,
 	return 0;
 }
 
-static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
+static struct gpio_desc *evm_sw_gpio[4];
 
 static int evm_sw_setup(struct i2c_client *client, int gpio,
 			unsigned ngpio, void *c)

arch/arm/mach-davinci/board-dm646x-evm.c static int evm_sw_setup(struct i2c_client *client, int gpio, · line 265

Quoted 8 lines
arch/arm/mach-davinci/board-dm646x-evm.c +3 -1
@@ -259,17 +259,19 @@ static int evm_sw_setup(struct i2c_client *client, int gpio,
 	char label[10];
 
 	for (i = 0; i < 4; ++i) {
+		struct gpio_desc *desc = gpio_to_desc(gpio + i);
+
 		snprintf(label, 10, "user_sw%d", i);
-		status = gpio_request(gpio, label);
+		status = gpio_request(gpio + i, label);

Shouldn't be gpiod_get() or so at the end?

Quoted 359 lines
arch/arm/mach-davinci/board-dm646x-evm.c +10 -10
 		if (status)
 			goto out_free;
-		evm_sw_gpio[i] = gpio++;
+		evm_sw_gpio[i] = desc;
 
-		status = gpio_direction_input(evm_sw_gpio[i]);
+		status = gpiod_direction_input(desc);
 		if (status)
 			goto out_free;
 
-		status = gpio_export(evm_sw_gpio[i], 0);
+		status = gpiod_export(desc, 0);
 		if (status)
 			goto out_free;
 	}
@@ -277,9 +279,9 @@ static int evm_sw_setup(struct i2c_client *client, int gpio,
 
 out_free:
 	for (i = 0; i < 4; ++i) {
-		if (evm_sw_gpio[i] != -EINVAL) {
-			gpio_free(evm_sw_gpio[i]);
-			evm_sw_gpio[i] = -EINVAL;
+		if (evm_sw_gpio[i]) {
+			gpio_free(pin + i);
+			evm_sw_gpio[i] = NULL;
 		}
 	}
 	return status;
@@ -291,10 +293,10 @@ static int evm_sw_teardown(struct i2c_client *client, int gpio,
 	int i;
 
 	for (i = 0; i < 4; ++i) {
-		if (evm_sw_gpio[i] != -EINVAL) {
-			gpio_unexport(evm_sw_gpio[i]);
-			gpio_free(evm_sw_gpio[i]);
-			evm_sw_gpio[i] = -EINVAL;
+		if (evm_sw_gpio[i]) {
+			gpiod_unexport(evm_sw_gpio[i]);
+			gpio_free(gpio + i);
+			evm_sw_gpio[i] = NULL;
 		}
 	}
 	return 0;
arch/arm/mach-omap2/pdata-quirks.c +5 -4
index e7fd29a502a0..1fdf7fcf091e 100644
@@ -6,6 +6,7 @@
  */
 #include <linux/clk.h>
 #include <linux/davinci_emac.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -120,7 +121,7 @@ static int omap3_sbc_t3730_twl_callback(struct device *dev,
 	if (res)
 		return res;
 
-	gpio_export(gpio, 0);
+	gpiod_export(gpio_to_desc(gpio), 0);
 
 	return 0;
 }
@@ -135,7 +136,7 @@ static void __init omap3_sbc_t3x_usb_hub_init(int gpio, char *hub_name)
 		return;
 	}
 
-	gpio_export(gpio, 0);
+	gpiod_export(gpio_to_desc(gpio), 0);
 
 	udelay(10);
 	gpio_set_value(gpio, 1);
@@ -212,8 +213,8 @@ static void __init omap3_sbc_t3517_wifi_init(void)
 		return;
 	}
 
-	gpio_export(cm_t3517_wlan_gpios[0].gpio, 0);
-	gpio_export(cm_t3517_wlan_gpios[1].gpio, 0);
+	gpiod_export(gpio_to_desc(cm_t3517_wlan_gpios[0].gpio), 0);
+	gpiod_export(gpio_to_desc(cm_t3517_wlan_gpios[1].gpio), 0);
 
 	msleep(100);
 	gpio_set_value(cm_t3517_wlan_gpios[1].gpio, 0);
arch/sh/boards/mach-ap325rxa/setup.c +4 -3
index c77b5f00a66a..151792162152 100644
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -411,16 +412,16 @@ static int __init ap325rxa_devices_setup(void)
 	/* LD3 and LD4 LEDs */
 	gpio_request(GPIO_PTX5, NULL); /* RUN */
 	gpio_direction_output(GPIO_PTX5, 1);
-	gpio_export(GPIO_PTX5, 0);
+	gpiod_export(gpio_to_desc(GPIO_PTX5), 0);
 
 	gpio_request(GPIO_PTX4, NULL); /* INDICATOR */
 	gpio_direction_output(GPIO_PTX4, 0);
-	gpio_export(GPIO_PTX4, 0);
+	gpiod_export(gpio_to_desc(GPIO_PTX4), 0);
 
 	/* SW1 input */
 	gpio_request(GPIO_PTF7, NULL); /* MODE */
 	gpio_direction_input(GPIO_PTF7);
-	gpio_export(GPIO_PTF7, 0);
+	gpiod_export(gpio_to_desc(GPIO_PTF7), 0);
 
 	/* LCDC */
 	gpio_request(GPIO_FN_LCDD15, NULL);
drivers/gpio/gpiolib-sysfs.c +2 -2
index 4098bc7f88b7..a83fba3649c4 100644
@@ -511,7 +511,7 @@ static ssize_t unexport_store(struct class *class,
 		goto done;
 
 	desc = gpio_to_desc(gpio);
-	/* reject bogus commands (gpio_unexport ignores them) */
+	/* reject bogus commands (gpiod_unexport ignores them) */
 	if (!desc) {
 		pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
 		return -EINVAL;
@@ -814,7 +814,7 @@ static int __init gpiolib_sysfs_init(void)
 	 * early (e.g. before the class_register above was called).
 	 *
 	 * We run before arch_initcall() so chip->dev nodes can have
-	 * registered, and so arch_initcall() can always gpio_export().
+	 * registered, and so arch_initcall() can always gpiod_export().
 	 */
 	spin_lock_irqsave(&gpio_lock, flags);
 	list_for_each_entry(gdev, &gpio_devices, list) {
drivers/media/i2c/noon010pc30.c +3 -2
index f3ac379ef34a..6faa44eb5354 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/slab.h>
@@ -755,7 +756,7 @@ static int noon010_probe(struct i2c_client *client,
 			goto np_err;
 		}
 		info->gpio_nreset = pdata->gpio_nreset;
-		gpio_export(info->gpio_nreset, 0);
+		gpiod_export(gpio_to_desc(info->gpio_nreset), 0);
 	}
 
 	if (gpio_is_valid(pdata->gpio_nstby)) {
@@ -767,7 +768,7 @@ static int noon010_probe(struct i2c_client *client,
 			goto np_err;
 		}
 		info->gpio_nstby = pdata->gpio_nstby;
-		gpio_export(info->gpio_nstby, 0);
+		gpiod_export(gpio_to_desc(info->gpio_nstby), 0);
 	}
 
 	for (i = 0; i < NOON010_NUM_SUPPLIES; i++)
drivers/media/i2c/ov9650.c +2 -2
index c313e11a9754..021acd20ede2 100644
@@ -1426,9 +1426,9 @@ static int ov965x_configure_gpios_pdata(struct ov965x *ov965x,
 			return ret;
 		v4l2_dbg(1, debug, &ov965x->sd, "set gpio %d to 1\n", gpio);
 
-		gpio_set_value_cansleep(gpio, 1);
-		gpio_export(gpio, 0);
 		ov965x->gpios[i] = gpio_to_desc(gpio);
+		gpiod_set_value_cansleep(ov965x->gpios[i], 1);
+		gpiod_export(ov965x->gpios[i], 0);
 	}
 
 	return 0;
drivers/media/i2c/s5k4ecgx.c +2 -1
index af9a305242cd..419d03fcc978 100644
@@ -15,6 +15,7 @@
 #include <linux/ctype.h>
 #include <linux/delay.h>
 #include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
@@ -852,7 +853,7 @@ static int s5k4ecgx_config_gpio(int nr, int val, const char *name)
 		return 0;
 	ret = gpio_request_one(nr, flags, name);
 	if (!ret)
-		gpio_export(nr, 0);
+		gpiod_export(gpio_to_desc(nr), 0);
 
 	return ret;
 }
drivers/media/pci/sta2x11/sta2x11_vip.c +7 -3
index 524912f20d9f..f7cef598f21d 100644
@@ -18,6 +18,7 @@
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/delay.h>
@@ -893,6 +894,7 @@ static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
 static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 			    const char *name)
 {
+	struct gpio_desc *desc = gpio_to_desc(pin);
 	int ret = -ENODEV;
 
 	if (!gpio_is_valid(pin))
@@ -904,7 +906,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 		return ret;
 	}
 
-	ret = gpio_direction_output(pin, dir);
+	ret = gpiod_direction_output(desc, dir);
 	if (ret) {
 		dev_err(dev, "Failed to set direction for pin %d (%s)\n",
 			pin, name);
@@ -912,7 +914,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 		return ret;
 	}
 
-	ret = gpio_export(pin, false);
+	ret = gpiod_export(desc, false);
 	if (ret) {
 		dev_err(dev, "Failed to export pin %d (%s)\n", pin, name);
 		gpio_free(pin);
@@ -932,8 +934,10 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 static void vip_gpio_release(struct device *dev, int pin, const char *name)
 {
 	if (gpio_is_valid(pin)) {
+		struct gpio_desc *desc = gpio_to_desc(pin);
+
 		dev_dbg(dev, "releasing pin %d (%s)\n",	pin, name);
-		gpio_unexport(pin);
+		gpiod_unexport(desc);
 		gpio_free(pin);
 	}
 }
drivers/mfd/dm355evm_msp.c +2 -1
index 54fb6cbd2aa0..2388fb4d0121 100644
@@ -11,6 +11,7 @@
 #include <linux/clk.h>
 #include <linux/module.h>
 #include <linux/err.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/gpio/machine.h>
 #include <linux/leds.h>
@@ -329,7 +330,7 @@ static int add_children(struct i2c_client *client)
 		gpio_request_one(gpio, GPIOF_IN, config_inputs[i].label);
 
 		/* make it easy for userspace to see these */
-		gpio_export(gpio, false);
+		gpiod_export(gpio_to_desc(gpio), false);
 	}
 
 	/* MMC/SD inputs -- right after the last config input */
drivers/net/ieee802154/ca8210.c +2 -1
index ece6ff6049f6..6252907b2c92 100644
@@ -51,6 +51,7 @@
 #include <linux/clk-provider.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
 #include <linux/ieee802154.h>
 #include <linux/io.h>
@@ -2895,7 +2896,7 @@ static int ca8210_interrupt_init(struct spi_device *spi)
 	);
 	if (ret) {
 		dev_crit(&spi->dev, "request_irq %d failed\n", pdata->irq_id);
-		gpio_unexport(pdata->gpio_irq);
+		gpiod_unexport(gpio_to_desc(pdata->gpio_irq));
 		gpio_free(pdata->gpio_irq);
 	}
 
include/linux/gpio.h +0 -41
index 64cc8f09eba8..7ceb93678689 100644
@@ -144,26 +144,6 @@ extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *labe
 extern int gpio_request_array(const struct gpio *array, size_t num);
 extern void gpio_free_array(const struct gpio *array, size_t num);
 
-/*
- * A sysfs interface can be exported by individual drivers if they want,
- * but more typically is configured entirely from userspace.
- */
-static inline int gpio_export(unsigned gpio, bool direction_may_change)
-{
-	return gpiod_export(gpio_to_desc(gpio), direction_may_change);
-}
-
-static inline int gpio_export_link(struct device *dev, const char *name,
-				   unsigned gpio)
-{
-	return gpiod_export_link(dev, name, gpio_to_desc(gpio));
-}
-
-static inline void gpio_unexport(unsigned gpio)
-{
-	gpiod_unexport(gpio_to_desc(gpio));
-}
-
 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
 
 struct device;
@@ -253,27 +233,6 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
 	WARN_ON(1);
 }
 
-static inline int gpio_export(unsigned gpio, bool direction_may_change)
-{
-	/* GPIO can never have been requested or set as {in,out}put */
-	WARN_ON(1);
-	return -EINVAL;
-}
-
-static inline int gpio_export_link(struct device *dev, const char *name,
-				unsigned gpio)
-{
-	/* GPIO can never have been exported */
-	WARN_ON(1);
-	return -EINVAL;
-}
-
-static inline void gpio_unexport(unsigned gpio)
-{
-	/* GPIO can never have been exported */
-	WARN_ON(1);
-}
-
 static inline int gpio_to_irq(unsigned gpio)
 {
 	/* GPIO can never have been requested or set as input */
Signature · 1 line
2.29.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export

Quoted 11 lines · Andy Shevchenko
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

There are only a handful of users of gpio_export() and related functions.

As these are just wrappers around the modern gpiod_export() helper, remove the wrappers and open-code the gpio_to_desc in all callers to shrink the legacy API.

Quoted 8 lines

What I wish to see meanwhile is a section in the TODO list somewhere to clean up those modules that have gpio.h. Linus, do we have one in the kernel or is it your personal TODO?

In case we have one in the kernel, please add there modules you modified in a way that they still need further attention.

I think the TODO list is in Linus' head, but it would include all the files that use one of the interfaces in linux/gpio.h. I found about 350 of them, so there is little point in listing them one at a time. IIRC Linus is going through those one subsystem at a time.

It might help to make it harder to get new users if we add some pattern matching to scripts/checkpatch.pl, and/or something for scripts/coccinelle/. I don't think it's possible to convert a gpio_request() user to gpio_get() in a scripted way because you usually have to change the platform side at the same time as the driver side.

I also found that we have a ton of users of linux/of_gpio.h, which is somewhere inbetween the linux/gpio.h interface and the linux/gpio/consumer.h version.

Quoted 11 lines

arch/arm/mach-davinci/board-dm646x-evm.c static int evm_sw_setup(struct i2c_client *client, int gpio, · line 265

Quoted 9 lines
arch/arm/mach-davinci/board-dm646x-evm.c +3 -1
@@ -259,17 +259,19 @@ static int evm_sw_setup(struct i2c_client *client, int gpio,
      char label[10];
 
      for (i = 0; i < 4; ++i) {
+             struct gpio_desc *desc = gpio_to_desc(gpio + i);
+
              snprintf(label, 10, "user_sw%d", i);
-             status = gpio_request(gpio, label);
+             status = gpio_request(gpio + i, label);

Shouldn't be gpiod_get() or so at the end?

Yes, but that would be a more invasive change that I think should be done separately.

Arnd

#14 lore raw

Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export

Quoted 1 line · Arnd Bergmann

I think the TODO list is in Linus' head,

Oh no, drivers/gpio/TODO

Quoted 4 lines

but it would include all the files
that use one of the interfaces in linux/gpio.h. I found about 350 of them, so there is little point in listing them one at a time. IIRC Linus is going through those one subsystem at a time.

Yeah but if it's just me I doubt that I will manage to do it by the time I retire in 2037 or so... So the TODO is there to inspire others to step in and help out.

Quoted 3 lines

I also found that we have a ton of users of linux/of_gpio.h, which is somewhere inbetween the linux/gpio.h interface and the linux/gpio/consumer.h version.

This is also mentioned in the TODO.

Yours,
Linus Walleij

#15 lore raw

Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export

Quoted 6 lines · Linus Walleij
Quoted 1 line · Arnd Bergmann

I think the TODO list is in Linus' head,

Oh no, drivers/gpio/TODO

Quoted 8 lines
Quoted 4 lines

but it would include all the files
that use one of the interfaces in linux/gpio.h. I found about 350 of them, so there is little point in listing them one at a time. IIRC Linus is going through those one subsystem at a time.

Yeah but if it's just me I doubt that I will manage to do it by the time I retire in 2037 or so... So the TODO is there to inspire others to step in and help out.

I think at the current rate, it should only take about another ten years: ;-)

$ for i in v3.18 v4.1 v4.4 v4.9 v4.14 v4.19 v5.4 v5.10 v5.15 ; do echo
-n $i\  ;  git grep -wl
'\<\(gpio_direction_input\|gpio_direction_output\|gpio_get_value_cansleep\|gpio_set_value_cansleep\|gpio_get_value\|gpio_set_value\|gpio_to_irq\|gpio_request\|gpio_request_one\|gpio_request_array\)\>\|\<\(ARCH_NR_GPIOS\|GPIOF_DIR_\|GPIOF_INIT\|GPIOF_EXPORT\|GPIOF_OPEN\|GPIOF_IN\|GPIOF_OUT\|gpio_is_valid\\|gpio_free\|devm_gpio_\)'
$i | wc -l ; done
v3.18 676
v4.1 669
v4.4 646
v4.9 639
v4.14 614
v4.19 553
v5.4 465
v5.10 381
v5.15 354

I'm a fan of deconstruction interfaces one function call at a time, which is different from your one-subsystem at a time approach, but these can obviously be done at the same time. This 8-patch series is hopefully a good step in that direction, removing some of the more obscure interfaces and making the rest a little more obvious.

I've also started a patch series to remove some of the less common of_gpio portions, which gets rid of of_get_gpio(), of_get_gpio_flags() and of_get_named_gpio_flags() but leaves of_get_named_gpio() in place for now. I'm much less confident about that work though, so I haven't posted that. I think killing off the of_gpio consumer-side interfaces entirely would likely make the biggest impact, as those appear to still be used a lot in relatively modern drivers, while the traditional gpio_request() interfaces are mainly used in drivers for legacy boards that don't have a long future ahead of them unless they get converted to DT.

Arnd

#16 lore raw

Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export

Quoted 9 lines · Arnd Bergmann

v3.18 676
v4.1 669
v4.4 646
v4.9 639
v4.14 614
v4.19 553
v5.4 465
v5.10 381
v5.15 354

Hey :D I didn't know it was working out that well. OK this give me hope!

Quoted 10 lines

I've also started a patch series to remove some of the less common of_gpio portions, which gets rid of of_get_gpio(), of_get_gpio_flags() and of_get_named_gpio_flags() but leaves of_get_named_gpio() in place for now. I'm much less confident about that work though, so I haven't posted that. I think killing off the of_gpio consumer-side interfaces entirely would likely make the biggest impact, as those appear to still be used a lot in relatively modern drivers, while the traditional gpio_request() interfaces are mainly used in drivers for legacy boards that don't have a long future ahead of them unless they get converted to DT.

OK you got a point. I am running around in SA1100 systems and stuff like that :/ getting rid of of_gpio.h would be a real nice feat.

Yours,
Linus Walleij

#17 lore raw

Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export

In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

What I wish to see meanwhile is a section in the TODO list somewhere to clean up those modules that have gpio.h. Linus, do we have one in the kernel or is it your personal TODO?

It's hidden in plain sight :D
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpio/TODO

Quoted 2 lines

In case we have one in the kernel, please add there modules you modified in a way that they still need further attention.

The TODO is maybe a bit generic, I would simply add comments directly in these modules/files with some fat TODO stamps over them.

Yours,
Linus Walleij

#18 lore raw

PATCH v2 7/8 gpiolib: remove gpio_to_chip

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

There are only two callers of this helper, remove them by open-coding the call to the gpiod version.

---
 drivers/pinctrl/core.c    | 5 ++---
 drivers/soc/fsl/qe/gpio.c | 4 +---
 include/linux/gpio.h      | 7 -------
 3 files changed, 3 insertions(+), 13 deletions(-)
drivers/pinctrl/core.c +2 -3
index 976607758e98..8d3c00782178 100644
@@ -28,7 +28,6 @@
 
 #ifdef CONFIG_GPIOLIB
 #include "../gpio/gpiolib.h"
-#include <linux/gpio.h>
 #endif
 
 #include "core.h"
@@ -324,7 +323,7 @@ static bool pinctrl_ready_for_gpio_range(unsigned gpio)
 {
 	struct pinctrl_dev *pctldev;
 	struct pinctrl_gpio_range *range = NULL;
-	struct gpio_chip *chip = gpio_to_chip(gpio);
+	struct gpio_chip *chip = gpiod_to_chip(gpio_to_desc(gpio));
 
 	if (WARN(!chip, "no gpio_chip for gpio%i?", gpio))
 		return false;
@@ -1657,7 +1656,7 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 			}
 		}
 		if (gpio_num >= 0)
-			chip = gpio_to_chip(gpio_num);
+			chip = gpiod_to_chip(gpio_to_desc(gpio_num));
 		else
 			chip = NULL;
 		if (chip)
drivers/soc/fsl/qe/gpio.c +1 -3
index 99f7de43c3c6..a6aa55055e9a 100644
@@ -15,8 +15,6 @@
 #include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/gpio/driver.h>
-/* FIXME: needed for gpio_to_chip() get rid of this */
-#include <linux/gpio.h>
 #include <linux/slab.h>
 #include <linux/export.h>
 #include <soc/fsl/qe/qe.h>
@@ -173,7 +171,7 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
 	err = of_get_gpio(np, index);
 	if (err < 0)
 		goto err0;
-	gc = gpio_to_chip(err);
+	gc = gpiod_to_chip(gpio_to_desc(err));
 	if (WARN_ON(!gc)) {
 		err = -ENODEV;
 		goto err0;
include/linux/gpio.h +0 -7
index 7ceb93678689..61fb427b4e70 100644
@@ -96,12 +96,6 @@ static inline bool gpio_is_valid(int number)
 
 struct device;
 
-/* caller holds gpio_lock *OR* gpio is marked as requested */
-static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
-{
-	return gpiod_to_chip(gpio_to_desc(gpio));
-}
-
 /* Always use the library code for GPIO management calls,
  * or when sleeping may be involved.
  */
@@ -158,7 +152,6 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
 #include <linux/bug.h>
 
 struct device;
-struct gpio_chip;
 
 static inline bool gpio_is_valid(int number)
 {
Signature · 1 line
2.29.2
Reviewed-by on v2 7/8
#19 lore raw

Re: [PATCH v2 7/8] gpiolib: remove gpio_to_chip

Quoted 4 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

There are only two callers of this helper, remove them by open-coding the call to the gpiod version.

Quoted 12 lines
---
 drivers/pinctrl/core.c    | 5 ++---
 drivers/soc/fsl/qe/gpio.c | 4 +---
 include/linux/gpio.h      | 7 -------
 3 files changed, 3 insertions(+), 13 deletions(-)
drivers/pinctrl/core.c +0 -0
index 976607758e98..8d3c00782178 100644

drivers/pinctrl/core.c line 29

Quoted 2 lines
drivers/pinctrl/core.c +0 -0
@@ -28,7 +28,6 @@
 
 #ifdef CONFIG_GPIOLIB

I'm wondering if we need this ifdeffery at all.

Quoted 73 lines
drivers/pinctrl/core.c +2 -3
 #include "../gpio/gpiolib.h"
-#include <linux/gpio.h>
 #endif
 
 #include "core.h"
@@ -324,7 +323,7 @@ static bool pinctrl_ready_for_gpio_range(unsigned gpio)
 {
 	struct pinctrl_dev *pctldev;
 	struct pinctrl_gpio_range *range = NULL;
-	struct gpio_chip *chip = gpio_to_chip(gpio);
+	struct gpio_chip *chip = gpiod_to_chip(gpio_to_desc(gpio));
 
 	if (WARN(!chip, "no gpio_chip for gpio%i?", gpio))
 		return false;
@@ -1657,7 +1656,7 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 			}
 		}
 		if (gpio_num >= 0)
-			chip = gpio_to_chip(gpio_num);
+			chip = gpiod_to_chip(gpio_to_desc(gpio_num));
 		else
 			chip = NULL;
 		if (chip)
drivers/soc/fsl/qe/gpio.c +1 -3
index 99f7de43c3c6..a6aa55055e9a 100644
@@ -15,8 +15,6 @@
 #include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/gpio/driver.h>
-/* FIXME: needed for gpio_to_chip() get rid of this */
-#include <linux/gpio.h>
 #include <linux/slab.h>
 #include <linux/export.h>
 #include <soc/fsl/qe/qe.h>
@@ -173,7 +171,7 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
 	err = of_get_gpio(np, index);
 	if (err < 0)
 		goto err0;
-	gc = gpio_to_chip(err);
+	gc = gpiod_to_chip(gpio_to_desc(err));
 	if (WARN_ON(!gc)) {
 		err = -ENODEV;
 		goto err0;
include/linux/gpio.h +0 -7
index 7ceb93678689..61fb427b4e70 100644
@@ -96,12 +96,6 @@ static inline bool gpio_is_valid(int number)
 
 struct device;
 
-/* caller holds gpio_lock *OR* gpio is marked as requested */
-static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
-{
-	return gpiod_to_chip(gpio_to_desc(gpio));
-}
-
 /* Always use the library code for GPIO management calls,
  * or when sleeping may be involved.
  */
@@ -158,7 +152,6 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
 #include <linux/bug.h>
 
 struct device;
-struct gpio_chip;
 
 static inline bool gpio_is_valid(int number)
 {
Signature · 1 line
2.29.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw

Re: [PATCH v2 7/8] gpiolib: remove gpio_to_chip

Quoted 4 lines · Andy Shevchenko
Quoted 2 lines

#ifdef CONFIG_GPIOLIB

I'm wondering if we need this ifdeffery at all.

We don't need it for the first half (gpio_set_value, gpio_direction_input, ...), which could just be unconditional wrappers around the gpiod versions. Removing that #ifdef would require always including linux/gpio/consumer.h here, so we'd no longer get a build failure when a driver uses gpiod_* without including that directly (when GPIOLIB is disabled).

I actually had a patch in my series to do this, but dropped that because the second half (gpio_request/gpio_free/...) does need the #ifdef

Arnd

#21 lore raw

PATCH v2 8/8 gpiolib: split linux/gpio/driver.h out of linux/gpio.h

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Almost all gpio drivers include linux/gpio/driver.h, and other files should not rely on includes from this header.

Remove the indirect include from here and include the correct headers directly from where they are used.

---
 arch/arm/mach-omap1/irq.c                              | 1 +
 arch/arm/mach-orion5x/board-rd88f5182.c                | 1 +
 arch/arm/mach-pxa/lubbock.c                            | 2 +-
 arch/arm/mach-s3c/mach-h1940.c                         | 1 +
 arch/arm/mach-s3c/s3c64xx.c                            | 1 +
 arch/arm/mach-sa1100/assabet.c                         | 1 +
 arch/arm/plat-orion/gpio.c                             | 1 +
 drivers/gpio/gpio-ucb1400.c                            | 1 +
 drivers/mfd/dm355evm_msp.c                             | 1 +
 drivers/mfd/htc-i2cpld.c                               | 1 +
 drivers/mfd/ucb1400_core.c                             | 1 +
 drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c | 1 +
 include/linux/bcma/bcma_driver_chipcommon.h            | 2 +-
 include/linux/gpio.h                                   | 3 ---
 include/linux/mfd/ucb1x00.h                            | 1 +
 include/linux/ucb1400.h                                | 1 +
 16 files changed, 15 insertions(+), 5 deletions(-)
arch/arm/mach-omap1/irq.c +1 -0
index ee6a93083154..d8c38270867f 100644
@@ -41,6 +41,7 @@
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/irqdomain.h>
 
 #include <asm/irq.h>
 #include <asm/exception.h>
arch/arm/mach-orion5x/board-rd88f5182.c +1 -0
index b7b0f52f4c0a..99abf6daca77 100644
@@ -12,6 +12,7 @@
 #include <linux/gpio.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pci.h>
 #include <linux/irq.h>
arch/arm/mach-pxa/lubbock.c +1 -1
index 742d18a1f7dc..875b405d9fce 100644
@@ -9,7 +9,7 @@
  *  Copyright:	MontaVista Software Inc.
  */
 #include <linux/clkdev.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio/gpio-reg.h>
 #include <linux/gpio/machine.h>
 #include <linux/module.h>
arch/arm/mach-s3c/mach-h1940.c +1 -0
index 8a43ed1c4c4d..0cc9f9d08c38 100644
@@ -18,6 +18,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
arch/arm/mach-s3c/s3c64xx.c +1 -0
index 4dfb648142f2..d098e28bd5dd 100644
@@ -24,6 +24,7 @@
 #include <linux/platform_device.h>
 #include <linux/reboot.h>
 #include <linux/io.h>
+#include <linux/of.h>
 #include <linux/clk/samsung.h>
 #include <linux/dma-mapping.h>
 #include <linux/irq.h>
arch/arm/mach-sa1100/assabet.c +1 -0
index 9919e0f32c4b..4ba2d28c1fd3 100644
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/gpio/gpio-reg.h>
 #include <linux/gpio/machine.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio_keys.h>
 #include <linux/ioport.h>
 #include <linux/platform_data/sa11x0-serial.h>
arch/arm/plat-orion/gpio.c +1 -0
index 734f0be4f14a..e21d589ec78a 100644
@@ -19,6 +19,7 @@
 #include <linux/bitops.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/leds.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
drivers/gpio/gpio-ucb1400.c +1 -0
index d2a8644864c3..aceac8bb12ff 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/gpio/driver.h>
 #include <linux/ucb1400.h>
 
 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
drivers/mfd/dm355evm_msp.c +1 -0
index 2388fb4d0121..2c82907600f0 100644
@@ -13,6 +13,7 @@
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
 #include <linux/leds.h>
 #include <linux/i2c.h>
drivers/mfd/htc-i2cpld.c +1 -0
index 417b0355d904..d7d0a2e50746 100644
@@ -20,6 +20,7 @@
 #include <linux/irq.h>
 #include <linux/spinlock.h>
 #include <linux/htcpld.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio.h>
 #include <linux/slab.h>
 
drivers/mfd/ucb1400_core.c +1 -0
index 8c3832a58ef6..f71ef41ac9dc 100644
@@ -20,6 +20,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/gpio/driver.h>
 #include <linux/ucb1400.h>
 
 unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel,
drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c +1 -0
index c1b9ac692d26..2349fcce37dd 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <net/mac80211.h>
 #include <linux/bcma/bcma_driver_chipcommon.h>
+#include <linux/gpio.h>
 #include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
 #include <linux/gpio/consumer.h>
include/linux/bcma/bcma_driver_chipcommon.h +1 -1
index d35b9206096d..9ba1b6311681 100644
@@ -3,7 +3,7 @@
 #define LINUX_BCMA_DRIVER_CC_H_
 
 #include <linux/platform_device.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 
 /** ChipCommon core registers. **/
 #define BCMA_CC_ID			0x0000
include/linux/gpio.h +0 -3
index 61fb427b4e70..f25546e060e9 100644
@@ -54,9 +54,6 @@ struct gpio {
 };
 
 #ifdef CONFIG_GPIOLIB
-
-#include <linux/compiler.h>
-#include <linux/gpio/driver.h>
 #include <linux/gpio/consumer.h>
 
 /* Platforms may implement their GPIO interface with library code,
include/linux/mfd/ucb1x00.h +1 -0
index 43bcf35afe27..7c0d40ddc674 100644
@@ -9,6 +9,7 @@
 
 #include <linux/device.h>
 #include <linux/mfd/mcp.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio.h>
 #include <linux/mutex.h>
 
include/linux/ucb1400.h +1 -0
index 0968ef458447..199b1280fa26 100644
@@ -23,6 +23,7 @@
 #include <sound/ac97_codec.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio.h>
 
 /*
Signature · 1 line
2.29.2
Reviewed-by on v2 8/8
#22 lore raw

Re: [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h

Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Almost all gpio drivers include linux/gpio/driver.h, and other files should not rely on includes from this header.

Remove the indirect include from here and include the correct headers directly from where they are used.

for gpio.h changes with one comment below.

Quoted 183 lines
---
 arch/arm/mach-omap1/irq.c                              | 1 +
 arch/arm/mach-orion5x/board-rd88f5182.c                | 1 +
 arch/arm/mach-pxa/lubbock.c                            | 2 +-
 arch/arm/mach-s3c/mach-h1940.c                         | 1 +
 arch/arm/mach-s3c/s3c64xx.c                            | 1 +
 arch/arm/mach-sa1100/assabet.c                         | 1 +
 arch/arm/plat-orion/gpio.c                             | 1 +
 drivers/gpio/gpio-ucb1400.c                            | 1 +
 drivers/mfd/dm355evm_msp.c                             | 1 +
 drivers/mfd/htc-i2cpld.c                               | 1 +
 drivers/mfd/ucb1400_core.c                             | 1 +
 drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c | 1 +
 include/linux/bcma/bcma_driver_chipcommon.h            | 2 +-
 include/linux/gpio.h                                   | 3 ---
 include/linux/mfd/ucb1x00.h                            | 1 +
 include/linux/ucb1400.h                                | 1 +
 16 files changed, 15 insertions(+), 5 deletions(-)
arch/arm/mach-omap1/irq.c +1 -0
index ee6a93083154..d8c38270867f 100644
@@ -41,6 +41,7 @@
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/irqdomain.h>
 
 #include <asm/irq.h>
 #include <asm/exception.h>
arch/arm/mach-orion5x/board-rd88f5182.c +1 -0
index b7b0f52f4c0a..99abf6daca77 100644
@@ -12,6 +12,7 @@
 #include <linux/gpio.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pci.h>
 #include <linux/irq.h>
arch/arm/mach-pxa/lubbock.c +1 -1
index 742d18a1f7dc..875b405d9fce 100644
@@ -9,7 +9,7 @@
  *  Copyright:	MontaVista Software Inc.
  */
 #include <linux/clkdev.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio/gpio-reg.h>
 #include <linux/gpio/machine.h>
 #include <linux/module.h>
arch/arm/mach-s3c/mach-h1940.c +1 -0
index 8a43ed1c4c4d..0cc9f9d08c38 100644
@@ -18,6 +18,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
arch/arm/mach-s3c/s3c64xx.c +1 -0
index 4dfb648142f2..d098e28bd5dd 100644
@@ -24,6 +24,7 @@
 #include <linux/platform_device.h>
 #include <linux/reboot.h>
 #include <linux/io.h>
+#include <linux/of.h>
 #include <linux/clk/samsung.h>
 #include <linux/dma-mapping.h>
 #include <linux/irq.h>
arch/arm/mach-sa1100/assabet.c +1 -0
index 9919e0f32c4b..4ba2d28c1fd3 100644
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/gpio/gpio-reg.h>
 #include <linux/gpio/machine.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio_keys.h>
 #include <linux/ioport.h>
 #include <linux/platform_data/sa11x0-serial.h>
arch/arm/plat-orion/gpio.c +1 -0
index 734f0be4f14a..e21d589ec78a 100644
@@ -19,6 +19,7 @@
 #include <linux/bitops.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/leds.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
drivers/gpio/gpio-ucb1400.c +1 -0
index d2a8644864c3..aceac8bb12ff 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/gpio/driver.h>
 #include <linux/ucb1400.h>
 
 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
drivers/mfd/dm355evm_msp.c +1 -0
index 2388fb4d0121..2c82907600f0 100644
@@ -13,6 +13,7 @@
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
 #include <linux/leds.h>
 #include <linux/i2c.h>
drivers/mfd/htc-i2cpld.c +1 -0
index 417b0355d904..d7d0a2e50746 100644
@@ -20,6 +20,7 @@
 #include <linux/irq.h>
 #include <linux/spinlock.h>
 #include <linux/htcpld.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio.h>
 #include <linux/slab.h>
 
drivers/mfd/ucb1400_core.c +1 -0
index 8c3832a58ef6..f71ef41ac9dc 100644
@@ -20,6 +20,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/gpio/driver.h>
 #include <linux/ucb1400.h>
 
 unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel,
drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c +1 -0
index c1b9ac692d26..2349fcce37dd 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <net/mac80211.h>
 #include <linux/bcma/bcma_driver_chipcommon.h>
+#include <linux/gpio.h>
 #include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
 #include <linux/gpio/consumer.h>
include/linux/bcma/bcma_driver_chipcommon.h +1 -1
index d35b9206096d..9ba1b6311681 100644
@@ -3,7 +3,7 @@
 #define LINUX_BCMA_DRIVER_CC_H_
 
 #include <linux/platform_device.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
 
 /** ChipCommon core registers. **/
 #define BCMA_CC_ID			0x0000
include/linux/gpio.h +0 -0
index 61fb427b4e70..f25546e060e9 100644

include/linux/gpio.h struct gpio { · line 58

Quoted 8 lines
include/linux/gpio.h +0 -3
@@ -54,9 +54,6 @@ struct gpio {
 };
 
 #ifdef CONFIG_GPIOLIB
-
-#include <linux/compiler.h>
-#include <linux/gpio/driver.h>
 
 #include <linux/gpio/consumer.h>

Hmm... It's in some of the previous patches I suppose. Do we really need this to be under ifdeffery?

Quoted 29 lines
include/linux/gpio.h +0 -0
 /* Platforms may implement their GPIO interface with library code,
include/linux/mfd/ucb1x00.h +1 -0
index 43bcf35afe27..7c0d40ddc674 100644
@@ -9,6 +9,7 @@
 
 #include <linux/device.h>
 #include <linux/mfd/mcp.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio.h>
 #include <linux/mutex.h>
 
include/linux/ucb1400.h +1 -0
index 0968ef458447..199b1280fa26 100644
@@ -23,6 +23,7 @@
 #include <sound/ac97_codec.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/driver.h>
 #include <linux/gpio.h>
 
 /*
Signature · 1 line
2.29.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko