linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] gpiolib header cleanup
@ 2021-11-09 10:01 Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 1/8] gpiolib: remove irq_to_gpio() definition Arnd Bergmann
                   ` (7 more replies)
  0 siblings, 8 replies; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:01 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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

-- 
2.29.2

Cc: linux-gpio@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org

[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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 1/8] gpiolib: remove irq_to_gpio() definition
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 2/8] gpiolib: remove empty asm/gpio.h files Arnd Bergmann
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel, Fu Wei, Alex Shi, Hu Haowen, linux-doc-tw-discuss

From: Arnd Bergmann <arnd@arndb.de>

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.

Cc: Fu Wei <tekkamanninja@gmail.com>
Cc: Alex Shi <alexs@kernel.org>
Cc: Hu Haowen <src.res@email.cn>
Cc: linux-doc-tw-discuss@lists.sourceforge.net
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/Documentation/driver-api/gpio/legacy.rst b/Documentation/driver-api/gpio/legacy.rst
index 9b12eeb89170..06c05e2d62c1 100644
--- a/Documentation/driver-api/gpio/legacy.rst
+++ b/Documentation/driver-api/gpio/legacy.rst
@@ -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
diff --git a/arch/m68k/include/asm/gpio.h b/arch/m68k/include/asm/gpio.h
index a50b27719a58..5cfc0996ba94 100644
--- a/arch/m68k/include/asm/gpio.h
+++ b/arch/m68k/include/asm/gpio.h
@@ -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);
diff --git a/arch/sh/include/asm/gpio.h b/arch/sh/include/asm/gpio.h
index d643250f0a0f..588c1380e4cb 100644
--- a/arch/sh/include/asm/gpio.h
+++ b/arch/sh/include/asm/gpio.h
@@ -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 */
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 008ad3ee56b7..d8d7daa7eb94 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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)
 {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 2/8] gpiolib: remove empty asm/gpio.h files
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 1/8] gpiolib: remove irq_to_gpio() definition Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 3/8] gpiolib: coldfire: remove custom asm/gpio.h Arnd Bergmann
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 526ae94b1c9a..80378eeee760 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -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
diff --git a/arch/arm/include/asm/gpio.h b/arch/arm/include/asm/gpio.h
deleted file mode 100644
index f3bb8a2bf788..000000000000
--- a/arch/arm/include/asm/gpio.h
+++ /dev/null
@@ -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 */
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 2474a04ceac4..cebd04314d76 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -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
diff --git a/arch/sh/boards/board-magicpanelr2.c b/arch/sh/boards/board-magicpanelr2.c
index 56bd386ff3b0..75de893152af 100644
--- a/arch/sh/boards/board-magicpanelr2.c
+++ b/arch/sh/boards/board-magicpanelr2.c
@@ -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 */
diff --git a/arch/sh/include/asm/gpio.h b/arch/sh/include/asm/gpio.h
deleted file mode 100644
index 588c1380e4cb..000000000000
--- a/arch/sh/include/asm/gpio.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0
- *
- *  include/asm-sh/gpio.h
- *
- * Generic GPIO API and pinmux table support for SuperH.
- *
- * Copyright (c) 2008 Magnus Damm
- */
-#ifndef __ASM_SH_GPIO_H
-#define __ASM_SH_GPIO_H
-
-#include <linux/kernel.h>
-#include <linux/errno.h>
-
-#if defined(CONFIG_CPU_SH3)
-#include <cpu/gpio.h>
-#endif
-
-#include <asm-generic/gpio.h>
-
-#ifdef CONFIG_GPIOLIB
-
-static inline int gpio_get_value(unsigned gpio)
-{
-	return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned gpio, int value)
-{
-	__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_cansleep(unsigned gpio)
-{
-	return __gpio_cansleep(gpio);
-}
-
-static inline int gpio_to_irq(unsigned gpio)
-{
-	return __gpio_to_irq(gpio);
-}
-
-#endif /* CONFIG_GPIOLIB */
-
-#endif /* __ASM_SH_GPIO_H */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 3/8] gpiolib: coldfire: remove custom asm/gpio.h
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 1/8] gpiolib: remove irq_to_gpio() definition Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 2/8] gpiolib: remove empty asm/gpio.h files Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h Arnd Bergmann
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel, Geert Uytterhoeven

From: Arnd Bergmann <arnd@arndb.de>

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.

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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

diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu
index 0d00ef5117dc..8256ff6b5b87 100644
--- a/arch/m68k/Kconfig.cpu
+++ b/arch/m68k/Kconfig.cpu
@@ -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
diff --git a/arch/m68k/include/asm/gpio.h b/arch/m68k/include/asm/gpio.h
deleted file mode 100644
index 5cfc0996ba94..000000000000
--- a/arch/m68k/include/asm/gpio.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Coldfire generic GPIO support
- *
- * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
-*/
-
-#ifndef coldfire_gpio_h
-#define coldfire_gpio_h
-
-#include <linux/io.h>
-#include <asm/coldfire.h>
-#include <asm/mcfsim.h>
-#include <asm/mcfgpio.h>
-/*
- * The Generic GPIO functions
- *
- * If the gpio is a compile time constant and is one of the Coldfire gpios,
- * use the inline version, otherwise dispatch thru gpiolib.
- */
-
-static inline int gpio_get_value(unsigned gpio)
-{
-	if (__builtin_constant_p(gpio) && gpio < MCFGPIO_PIN_MAX)
-		return mcfgpio_read(__mcfgpio_ppdr(gpio)) & mcfgpio_bit(gpio);
-	else
-		return __gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned gpio, int value)
-{
-	if (__builtin_constant_p(gpio) && gpio < MCFGPIO_PIN_MAX) {
-		if (gpio < MCFGPIO_SCR_START) {
-			unsigned long flags;
-			MCFGPIO_PORTTYPE data;
-
-			local_irq_save(flags);
-			data = mcfgpio_read(__mcfgpio_podr(gpio));
-			if (value)
-				data |= mcfgpio_bit(gpio);
-			else
-				data &= ~mcfgpio_bit(gpio);
-			mcfgpio_write(data, __mcfgpio_podr(gpio));
-			local_irq_restore(flags);
-		} else {
-			if (value)
-				mcfgpio_write(mcfgpio_bit(gpio),
-						MCFGPIO_SETR_PORT(gpio));
-			else
-				mcfgpio_write(~mcfgpio_bit(gpio),
-						MCFGPIO_CLRR_PORT(gpio));
-		}
-	} else
-		__gpio_set_value(gpio, value);
-}
-
-static inline int gpio_to_irq(unsigned gpio)
-{
-#if defined(MCFGPIO_IRQ_MIN)
-	if ((gpio >= MCFGPIO_IRQ_MIN) && (gpio < MCFGPIO_IRQ_MAX))
-#else
-	if (gpio < MCFGPIO_IRQ_MAX)
-#endif
-		return gpio + MCFGPIO_IRQ_VECBASE;
-	else
-		return __gpio_to_irq(gpio);
-}
-
-static inline int gpio_cansleep(unsigned gpio)
-{
-	return gpio < MCFGPIO_PIN_MAX ? 0 : __gpio_cansleep(gpio);
-}
-
-#ifndef CONFIG_GPIOLIB
-static inline int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
-{
-	int err;
-
-	err = gpio_request(gpio, label);
-	if (err)
-		return err;
-
-	if (flags & GPIOF_DIR_IN)
-		err = gpio_direction_input(gpio);
-	else
-		err = gpio_direction_output(gpio,
-			(flags & GPIOF_INIT_HIGH) ? 1 : 0);
-
-	if (err)
-		gpio_free(gpio);
-
-	return err;
-}
-#endif /* !CONFIG_GPIOLIB */
-#endif
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 5c3b29bddc5b..e2a3e9b66151 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -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
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index d8d7daa7eb94..7e6b1b8277ca 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
                   ` (2 preceding siblings ...)
  2021-11-09 10:02 ` [PATCH v2 3/8] gpiolib: coldfire: remove custom asm/gpio.h Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:19   ` Andy Shevchenko
  2021-11-09 10:02 ` [PATCH v2 5/8] gpiolib: shrink further Arnd Bergmann
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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

diff --git a/arch/m68k/include/asm/mcfgpio.h b/arch/m68k/include/asm/mcfgpio.h
index 27f32cc81da6..2cefe8445980 100644
--- a/arch/m68k/include/asm/mcfgpio.h
+++ b/arch/m68k/include/asm/mcfgpio.h
@@ -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);
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index cb5afaa7ed48..8122c3a8d659 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -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
 
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index ffe39336fcac..976607758e98 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -28,7 +28,7 @@
 
 #ifdef CONFIG_GPIOLIB
 #include "../gpio/gpiolib.h"
-#include <asm-generic/gpio.h>
+#include <linux/gpio.h>
 #endif
 
 #include "core.h"
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
deleted file mode 100644
index aea9aee1f3e9..000000000000
--- a/include/asm-generic/gpio.h
+++ /dev/null
@@ -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 */
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 7e6b1b8277ca..c19256f67e02 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 5/8] gpiolib: shrink further
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
                   ` (3 preceding siblings ...)
  2021-11-09 10:02 ` [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:24   ` Andy Shevchenko
  2021-11-09 10:02 ` [PATCH v2 6/8] gpiolib: remove legacy gpio_export Arnd Bergmann
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 .../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(-)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index 148e19381b79..52821478decd 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -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()
diff --git a/Documentation/driver-api/gpio/legacy.rst b/Documentation/driver-api/gpio/legacy.rst
index 06c05e2d62c1..eae185f771d7 100644
--- a/Documentation/driver-api/gpio/legacy.rst
+++ b/Documentation/driver-api/gpio/legacy.rst
@@ -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
diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 79da85d17b71..55465ead492f 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -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;
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index a25a77dd9a32..d0664e3b89bb 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -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");
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index c19256f67e02..64cc8f09eba8 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
                   ` (4 preceding siblings ...)
  2021-11-09 10:02 ` [PATCH v2 5/8] gpiolib: shrink further Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:30   ` Andy Shevchenko
  2021-11-09 10:02 ` [PATCH v2 7/8] gpiolib: remove gpio_to_chip Arnd Bergmann
  2021-11-09 10:02 ` [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h Arnd Bergmann
  7 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/Documentation/admin-guide/gpio/sysfs.rst b/Documentation/admin-guide/gpio/sysfs.rst
index ec09ffd983e7..35171d15f78d 100644
--- a/Documentation/admin-guide/gpio/sysfs.rst
+++ b/Documentation/admin-guide/gpio/sysfs.rst
@@ -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 */
diff --git a/Documentation/driver-api/gpio/legacy.rst b/Documentation/driver-api/gpio/legacy.rst
index eae185f771d7..34fcb14814db 100644
--- a/Documentation/driver-api/gpio/legacy.rst
+++ b/Documentation/driver-api/gpio/legacy.rst
@@ -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
 =============
 
diff --git a/Documentation/translations/zh_CN/gpio.txt b/Documentation/translations/zh_CN/gpio.txt
index a23ee14fc927..e49fa88a2804 100644
--- a/Documentation/translations/zh_CN/gpio.txt
+++ b/Documentation/translations/zh_CN/gpio.txt
@@ -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 节点的)接口。
diff --git a/Documentation/translations/zh_TW/gpio.txt b/Documentation/translations/zh_TW/gpio.txt
index e3c076dd75a5..c9bf3ddd08b3 100644
--- a/Documentation/translations/zh_TW/gpio.txt
+++ b/Documentation/translations/zh_TW/gpio.txt
@@ -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 節點的)接口。
-
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c b/arch/arm/mach-davinci/board-dm646x-evm.c
index ee91d81ebbfd..4a258e33021d 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -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;
diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c
index e7fd29a502a0..1fdf7fcf091e 100644
--- a/arch/arm/mach-omap2/pdata-quirks.c
+++ b/arch/arm/mach-omap2/pdata-quirks.c
@@ -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);
diff --git a/arch/sh/boards/mach-ap325rxa/setup.c b/arch/sh/boards/mach-ap325rxa/setup.c
index c77b5f00a66a..151792162152 100644
--- a/arch/sh/boards/mach-ap325rxa/setup.c
+++ b/arch/sh/boards/mach-ap325rxa/setup.c
@@ -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);
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 4098bc7f88b7..a83fba3649c4 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -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) {
diff --git a/drivers/media/i2c/noon010pc30.c b/drivers/media/i2c/noon010pc30.c
index f3ac379ef34a..6faa44eb5354 100644
--- a/drivers/media/i2c/noon010pc30.c
+++ b/drivers/media/i2c/noon010pc30.c
@@ -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++)
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index c313e11a9754..021acd20ede2 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -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;
diff --git a/drivers/media/i2c/s5k4ecgx.c b/drivers/media/i2c/s5k4ecgx.c
index af9a305242cd..419d03fcc978 100644
--- a/drivers/media/i2c/s5k4ecgx.c
+++ b/drivers/media/i2c/s5k4ecgx.c
@@ -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;
 }
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 524912f20d9f..f7cef598f21d 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -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);
 	}
 }
diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 54fb6cbd2aa0..2388fb4d0121 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -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 */
diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index ece6ff6049f6..6252907b2c92 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -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);
 	}
 
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 64cc8f09eba8..7ceb93678689 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 7/8] gpiolib: remove gpio_to_chip
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
                   ` (5 preceding siblings ...)
  2021-11-09 10:02 ` [PATCH v2 6/8] gpiolib: remove legacy gpio_export Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:32   ` Andy Shevchenko
  2021-11-09 10:02 ` [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h Arnd Bergmann
  7 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/pinctrl/core.c    | 5 ++---
 drivers/soc/fsl/qe/gpio.c | 4 +---
 include/linux/gpio.h      | 7 -------
 3 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 976607758e98..8d3c00782178 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -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)
diff --git a/drivers/soc/fsl/qe/gpio.c b/drivers/soc/fsl/qe/gpio.c
index 99f7de43c3c6..a6aa55055e9a 100644
--- a/drivers/soc/fsl/qe/gpio.c
+++ b/drivers/soc/fsl/qe/gpio.c
@@ -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;
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 7ceb93678689..61fb427b4e70 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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)
 {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h
  2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
                   ` (6 preceding siblings ...)
  2021-11-09 10:02 ` [PATCH v2 7/8] gpiolib: remove gpio_to_chip Arnd Bergmann
@ 2021-11-09 10:02 ` Arnd Bergmann
  2021-11-09 10:34   ` Andy Shevchenko
  7 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:02 UTC (permalink / raw)
  To: linux-gpio
  Cc: Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Geert Uytterhoeven, linux-arm-kernel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/arch/arm/mach-omap1/irq.c b/arch/arm/mach-omap1/irq.c
index ee6a93083154..d8c38270867f 100644
--- a/arch/arm/mach-omap1/irq.c
+++ b/arch/arm/mach-omap1/irq.c
@@ -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>
diff --git a/arch/arm/mach-orion5x/board-rd88f5182.c b/arch/arm/mach-orion5x/board-rd88f5182.c
index b7b0f52f4c0a..99abf6daca77 100644
--- a/arch/arm/mach-orion5x/board-rd88f5182.c
+++ b/arch/arm/mach-orion5x/board-rd88f5182.c
@@ -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>
diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
index 742d18a1f7dc..875b405d9fce 100644
--- a/arch/arm/mach-pxa/lubbock.c
+++ b/arch/arm/mach-pxa/lubbock.c
@@ -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>
diff --git a/arch/arm/mach-s3c/mach-h1940.c b/arch/arm/mach-s3c/mach-h1940.c
index 8a43ed1c4c4d..0cc9f9d08c38 100644
--- a/arch/arm/mach-s3c/mach-h1940.c
+++ b/arch/arm/mach-s3c/mach-h1940.c
@@ -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>
diff --git a/arch/arm/mach-s3c/s3c64xx.c b/arch/arm/mach-s3c/s3c64xx.c
index 4dfb648142f2..d098e28bd5dd 100644
--- a/arch/arm/mach-s3c/s3c64xx.c
+++ b/arch/arm/mach-s3c/s3c64xx.c
@@ -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>
diff --git a/arch/arm/mach-sa1100/assabet.c b/arch/arm/mach-sa1100/assabet.c
index 9919e0f32c4b..4ba2d28c1fd3 100644
--- a/arch/arm/mach-sa1100/assabet.c
+++ b/arch/arm/mach-sa1100/assabet.c
@@ -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>
diff --git a/arch/arm/plat-orion/gpio.c b/arch/arm/plat-orion/gpio.c
index 734f0be4f14a..e21d589ec78a 100644
--- a/arch/arm/plat-orion/gpio.c
+++ b/arch/arm/plat-orion/gpio.c
@@ -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>
diff --git a/drivers/gpio/gpio-ucb1400.c b/drivers/gpio/gpio-ucb1400.c
index d2a8644864c3..aceac8bb12ff 100644
--- a/drivers/gpio/gpio-ucb1400.c
+++ b/drivers/gpio/gpio-ucb1400.c
@@ -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)
diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 2388fb4d0121..2c82907600f0 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -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>
diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
index 417b0355d904..d7d0a2e50746 100644
--- a/drivers/mfd/htc-i2cpld.c
+++ b/drivers/mfd/htc-i2cpld.c
@@ -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>
 
diff --git a/drivers/mfd/ucb1400_core.c b/drivers/mfd/ucb1400_core.c
index 8c3832a58ef6..f71ef41ac9dc 100644
--- a/drivers/mfd/ucb1400_core.c
+++ b/drivers/mfd/ucb1400_core.c
@@ -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,
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c
index c1b9ac692d26..2349fcce37dd 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c
@@ -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>
diff --git a/include/linux/bcma/bcma_driver_chipcommon.h b/include/linux/bcma/bcma_driver_chipcommon.h
index d35b9206096d..9ba1b6311681 100644
--- a/include/linux/bcma/bcma_driver_chipcommon.h
+++ b/include/linux/bcma/bcma_driver_chipcommon.h
@@ -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
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 61fb427b4e70..f25546e060e9 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -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,
diff --git a/include/linux/mfd/ucb1x00.h b/include/linux/mfd/ucb1x00.h
index 43bcf35afe27..7c0d40ddc674 100644
--- a/include/linux/mfd/ucb1x00.h
+++ b/include/linux/mfd/ucb1x00.h
@@ -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>
 
diff --git a/include/linux/ucb1400.h b/include/linux/ucb1400.h
index 0968ef458447..199b1280fa26 100644
--- a/include/linux/ucb1400.h
+++ b/include/linux/ucb1400.h
@@ -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>
 
 /*
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h
  2021-11-09 10:02 ` [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h Arnd Bergmann
@ 2021-11-09 10:19   ` Andy Shevchenko
  0 siblings, 0 replies; 23+ messages in thread
From: Andy Shevchenko @ 2021-11-09 10:19 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-gpio, Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Geert Uytterhoeven, linux-arm-kernel, linux-kernel

On Tue, Nov 09, 2021 at 11:02:03AM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  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
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

>  5 files changed, 110 insertions(+), 185 deletions(-)
>  delete mode 100644 include/asm-generic/gpio.h
> 
> diff --git a/arch/m68k/include/asm/mcfgpio.h b/arch/m68k/include/asm/mcfgpio.h
> index 27f32cc81da6..2cefe8445980 100644
> --- a/arch/m68k/include/asm/mcfgpio.h
> +++ b/arch/m68k/include/asm/mcfgpio.h
> @@ -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);
> diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
> index cb5afaa7ed48..8122c3a8d659 100644
> --- a/drivers/gpio/gpio-davinci.c
> +++ b/drivers/gpio/gpio-davinci.c
> @@ -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
>  
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index ffe39336fcac..976607758e98 100644
> --- a/drivers/pinctrl/core.c
> +++ b/drivers/pinctrl/core.c
> @@ -28,7 +28,7 @@
>  
>  #ifdef CONFIG_GPIOLIB
>  #include "../gpio/gpiolib.h"
> -#include <asm-generic/gpio.h>
> +#include <linux/gpio.h>
>  #endif
>  
>  #include "core.h"
> diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
> deleted file mode 100644
> index aea9aee1f3e9..000000000000
> --- a/include/asm-generic/gpio.h
> +++ /dev/null
> @@ -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 */
> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
> index 7e6b1b8277ca..c19256f67e02 100644
> --- a/include/linux/gpio.h
> +++ b/include/linux/gpio.h
> @@ -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 */
> -- 
> 2.29.2
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/8] gpiolib: shrink further
  2021-11-09 10:02 ` [PATCH v2 5/8] gpiolib: shrink further Arnd Bergmann
@ 2021-11-09 10:24   ` Andy Shevchenko
  2021-11-09 11:18     ` Arnd Bergmann
  0 siblings, 1 reply; 23+ messages in thread
From: Andy Shevchenko @ 2021-11-09 10:24 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-gpio, Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Geert Uytterhoeven, linux-arm-kernel, linux-kernel

On Tue, Nov 09, 2021 at 11:02:04AM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  .../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(-)
> 
> diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
> index 148e19381b79..52821478decd 100644
> --- a/Documentation/driver-api/driver-model/devres.rst
> +++ b/Documentation/driver-api/driver-model/devres.rst
> @@ -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()
> diff --git a/Documentation/driver-api/gpio/legacy.rst b/Documentation/driver-api/gpio/legacy.rst
> index 06c05e2d62c1..eae185f771d7 100644
> --- a/Documentation/driver-api/gpio/legacy.rst
> +++ b/Documentation/driver-api/gpio/legacy.rst
> @@ -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?

>  
>  Claiming and Releasing GPIOs
> diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
> index 79da85d17b71..55465ead492f 100644
> --- a/drivers/gpio/gpiolib-devres.c
> +++ b/drivers/gpio/gpiolib-devres.c
> @@ -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;
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index a25a77dd9a32..d0664e3b89bb 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -27,6 +27,7 @@
>  #include <linux/of.h>

>  #include <linux/of_gpio.h>

(1)

>  #include <linux/of_device.h>

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

(2)

>  #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)

>  #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");
> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
> index c19256f67e02..64cc8f09eba8 100644
> --- a/include/linux/gpio.h
> +++ b/include/linux/gpio.h
> @@ -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 */
> -- 
> 2.29.2
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 10:02 ` [PATCH v2 6/8] gpiolib: remove legacy gpio_export Arnd Bergmann
@ 2021-11-09 10:30   ` Andy Shevchenko
  2021-11-09 10:50     ` Arnd Bergmann
  2021-11-09 20:33     ` Linus Walleij
  0 siblings, 2 replies; 23+ messages in thread
From: Andy Shevchenko @ 2021-11-09 10:30 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-gpio, Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Geert Uytterhoeven, linux-arm-kernel, linux-kernel

On Tue, Nov 09, 2021 at 11:02:05AM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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.

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  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(-)
> 
> diff --git a/Documentation/admin-guide/gpio/sysfs.rst b/Documentation/admin-guide/gpio/sysfs.rst
> index ec09ffd983e7..35171d15f78d 100644
> --- a/Documentation/admin-guide/gpio/sysfs.rst
> +++ b/Documentation/admin-guide/gpio/sysfs.rst
> @@ -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 */
> diff --git a/Documentation/driver-api/gpio/legacy.rst b/Documentation/driver-api/gpio/legacy.rst
> index eae185f771d7..34fcb14814db 100644
> --- a/Documentation/driver-api/gpio/legacy.rst
> +++ b/Documentation/driver-api/gpio/legacy.rst
> @@ -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
>  =============
>  
> diff --git a/Documentation/translations/zh_CN/gpio.txt b/Documentation/translations/zh_CN/gpio.txt
> index a23ee14fc927..e49fa88a2804 100644
> --- a/Documentation/translations/zh_CN/gpio.txt
> +++ b/Documentation/translations/zh_CN/gpio.txt
> @@ -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 节点的)接口。
> diff --git a/Documentation/translations/zh_TW/gpio.txt b/Documentation/translations/zh_TW/gpio.txt
> index e3c076dd75a5..c9bf3ddd08b3 100644
> --- a/Documentation/translations/zh_TW/gpio.txt
> +++ b/Documentation/translations/zh_TW/gpio.txt
> @@ -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 節點的)接口。
> -
> diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c b/arch/arm/mach-davinci/board-dm646x-evm.c
> index ee91d81ebbfd..4a258e33021d 100644
> --- a/arch/arm/mach-davinci/board-dm646x-evm.c
> +++ b/arch/arm/mach-davinci/board-dm646x-evm.c
> @@ -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);

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

>  		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;
> diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c
> index e7fd29a502a0..1fdf7fcf091e 100644
> --- a/arch/arm/mach-omap2/pdata-quirks.c
> +++ b/arch/arm/mach-omap2/pdata-quirks.c
> @@ -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);
> diff --git a/arch/sh/boards/mach-ap325rxa/setup.c b/arch/sh/boards/mach-ap325rxa/setup.c
> index c77b5f00a66a..151792162152 100644
> --- a/arch/sh/boards/mach-ap325rxa/setup.c
> +++ b/arch/sh/boards/mach-ap325rxa/setup.c
> @@ -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);
> diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
> index 4098bc7f88b7..a83fba3649c4 100644
> --- a/drivers/gpio/gpiolib-sysfs.c
> +++ b/drivers/gpio/gpiolib-sysfs.c
> @@ -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) {
> diff --git a/drivers/media/i2c/noon010pc30.c b/drivers/media/i2c/noon010pc30.c
> index f3ac379ef34a..6faa44eb5354 100644
> --- a/drivers/media/i2c/noon010pc30.c
> +++ b/drivers/media/i2c/noon010pc30.c
> @@ -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++)
> diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
> index c313e11a9754..021acd20ede2 100644
> --- a/drivers/media/i2c/ov9650.c
> +++ b/drivers/media/i2c/ov9650.c
> @@ -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;
> diff --git a/drivers/media/i2c/s5k4ecgx.c b/drivers/media/i2c/s5k4ecgx.c
> index af9a305242cd..419d03fcc978 100644
> --- a/drivers/media/i2c/s5k4ecgx.c
> +++ b/drivers/media/i2c/s5k4ecgx.c
> @@ -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;
>  }
> diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
> index 524912f20d9f..f7cef598f21d 100644
> --- a/drivers/media/pci/sta2x11/sta2x11_vip.c
> +++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
> @@ -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);
>  	}
>  }
> diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
> index 54fb6cbd2aa0..2388fb4d0121 100644
> --- a/drivers/mfd/dm355evm_msp.c
> +++ b/drivers/mfd/dm355evm_msp.c
> @@ -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 */
> diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> index ece6ff6049f6..6252907b2c92 100644
> --- a/drivers/net/ieee802154/ca8210.c
> +++ b/drivers/net/ieee802154/ca8210.c
> @@ -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);
>  	}
>  
> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
> index 64cc8f09eba8..7ceb93678689 100644
> --- a/include/linux/gpio.h
> +++ b/include/linux/gpio.h
> @@ -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 */
> -- 
> 2.29.2
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/8] gpiolib: remove gpio_to_chip
  2021-11-09 10:02 ` [PATCH v2 7/8] gpiolib: remove gpio_to_chip Arnd Bergmann
@ 2021-11-09 10:32   ` Andy Shevchenko
  2021-11-09 10:54     ` Arnd Bergmann
  0 siblings, 1 reply; 23+ messages in thread
From: Andy Shevchenko @ 2021-11-09 10:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-gpio, Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Geert Uytterhoeven, linux-arm-kernel, linux-kernel

On Tue, Nov 09, 2021 at 11:02:06AM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> There are only two callers of this helper, remove them by
> open-coding the call to the gpiod version.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/pinctrl/core.c    | 5 ++---
>  drivers/soc/fsl/qe/gpio.c | 4 +---
>  include/linux/gpio.h      | 7 -------
>  3 files changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index 976607758e98..8d3c00782178 100644
> --- a/drivers/pinctrl/core.c
> +++ b/drivers/pinctrl/core.c
> @@ -28,7 +28,6 @@

>  #ifdef CONFIG_GPIOLIB

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

>  #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)
> diff --git a/drivers/soc/fsl/qe/gpio.c b/drivers/soc/fsl/qe/gpio.c
> index 99f7de43c3c6..a6aa55055e9a 100644
> --- a/drivers/soc/fsl/qe/gpio.c
> +++ b/drivers/soc/fsl/qe/gpio.c
> @@ -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;
> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
> index 7ceb93678689..61fb427b4e70 100644
> --- a/include/linux/gpio.h
> +++ b/include/linux/gpio.h
> @@ -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)
>  {
> -- 
> 2.29.2
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h
  2021-11-09 10:02 ` [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h Arnd Bergmann
@ 2021-11-09 10:34   ` Andy Shevchenko
  0 siblings, 0 replies; 23+ messages in thread
From: Andy Shevchenko @ 2021-11-09 10:34 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-gpio, Arnd Bergmann, Linus Walleij, Bartosz Golaszewski,
	Geert Uytterhoeven, linux-arm-kernel, linux-kernel

On Tue, Nov 09, 2021 at 11:02:07AM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

for gpio.h changes with one comment below.

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  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(-)
> 
> diff --git a/arch/arm/mach-omap1/irq.c b/arch/arm/mach-omap1/irq.c
> index ee6a93083154..d8c38270867f 100644
> --- a/arch/arm/mach-omap1/irq.c
> +++ b/arch/arm/mach-omap1/irq.c
> @@ -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>
> diff --git a/arch/arm/mach-orion5x/board-rd88f5182.c b/arch/arm/mach-orion5x/board-rd88f5182.c
> index b7b0f52f4c0a..99abf6daca77 100644
> --- a/arch/arm/mach-orion5x/board-rd88f5182.c
> +++ b/arch/arm/mach-orion5x/board-rd88f5182.c
> @@ -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>
> diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
> index 742d18a1f7dc..875b405d9fce 100644
> --- a/arch/arm/mach-pxa/lubbock.c
> +++ b/arch/arm/mach-pxa/lubbock.c
> @@ -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>
> diff --git a/arch/arm/mach-s3c/mach-h1940.c b/arch/arm/mach-s3c/mach-h1940.c
> index 8a43ed1c4c4d..0cc9f9d08c38 100644
> --- a/arch/arm/mach-s3c/mach-h1940.c
> +++ b/arch/arm/mach-s3c/mach-h1940.c
> @@ -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>
> diff --git a/arch/arm/mach-s3c/s3c64xx.c b/arch/arm/mach-s3c/s3c64xx.c
> index 4dfb648142f2..d098e28bd5dd 100644
> --- a/arch/arm/mach-s3c/s3c64xx.c
> +++ b/arch/arm/mach-s3c/s3c64xx.c
> @@ -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>
> diff --git a/arch/arm/mach-sa1100/assabet.c b/arch/arm/mach-sa1100/assabet.c
> index 9919e0f32c4b..4ba2d28c1fd3 100644
> --- a/arch/arm/mach-sa1100/assabet.c
> +++ b/arch/arm/mach-sa1100/assabet.c
> @@ -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>
> diff --git a/arch/arm/plat-orion/gpio.c b/arch/arm/plat-orion/gpio.c
> index 734f0be4f14a..e21d589ec78a 100644
> --- a/arch/arm/plat-orion/gpio.c
> +++ b/arch/arm/plat-orion/gpio.c
> @@ -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>
> diff --git a/drivers/gpio/gpio-ucb1400.c b/drivers/gpio/gpio-ucb1400.c
> index d2a8644864c3..aceac8bb12ff 100644
> --- a/drivers/gpio/gpio-ucb1400.c
> +++ b/drivers/gpio/gpio-ucb1400.c
> @@ -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)
> diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
> index 2388fb4d0121..2c82907600f0 100644
> --- a/drivers/mfd/dm355evm_msp.c
> +++ b/drivers/mfd/dm355evm_msp.c
> @@ -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>
> diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
> index 417b0355d904..d7d0a2e50746 100644
> --- a/drivers/mfd/htc-i2cpld.c
> +++ b/drivers/mfd/htc-i2cpld.c
> @@ -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>
>  
> diff --git a/drivers/mfd/ucb1400_core.c b/drivers/mfd/ucb1400_core.c
> index 8c3832a58ef6..f71ef41ac9dc 100644
> --- a/drivers/mfd/ucb1400_core.c
> +++ b/drivers/mfd/ucb1400_core.c
> @@ -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,
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c
> index c1b9ac692d26..2349fcce37dd 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/led.c
> @@ -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>
> diff --git a/include/linux/bcma/bcma_driver_chipcommon.h b/include/linux/bcma/bcma_driver_chipcommon.h
> index d35b9206096d..9ba1b6311681 100644
> --- a/include/linux/bcma/bcma_driver_chipcommon.h
> +++ b/include/linux/bcma/bcma_driver_chipcommon.h
> @@ -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
> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
> index 61fb427b4e70..f25546e060e9 100644
> --- a/include/linux/gpio.h
> +++ b/include/linux/gpio.h
> @@ -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?

>  
>  /* Platforms may implement their GPIO interface with library code,
> diff --git a/include/linux/mfd/ucb1x00.h b/include/linux/mfd/ucb1x00.h
> index 43bcf35afe27..7c0d40ddc674 100644
> --- a/include/linux/mfd/ucb1x00.h
> +++ b/include/linux/mfd/ucb1x00.h
> @@ -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>
>  
> diff --git a/include/linux/ucb1400.h b/include/linux/ucb1400.h
> index 0968ef458447..199b1280fa26 100644
> --- a/include/linux/ucb1400.h
> +++ b/include/linux/ucb1400.h
> @@ -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>
>  
>  /*
> -- 
> 2.29.2
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 10:30   ` Andy Shevchenko
@ 2021-11-09 10:50     ` Arnd Bergmann
  2021-11-09 20:42       ` Linus Walleij
  2021-11-09 20:33     ` Linus Walleij
  1 sibling, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:50 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Arnd Bergmann, Linus Walleij,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 11:30 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Tue, Nov 09, 2021 at 11:02:05AM +0100, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > 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.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> 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.

> > @@ -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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/8] gpiolib: remove gpio_to_chip
  2021-11-09 10:32   ` Andy Shevchenko
@ 2021-11-09 10:54     ` Arnd Bergmann
  0 siblings, 0 replies; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 10:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Arnd Bergmann, Linus Walleij,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 11:32 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> >  #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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/8] gpiolib: shrink further
  2021-11-09 10:24   ` Andy Shevchenko
@ 2021-11-09 11:18     ` Arnd Bergmann
  2021-11-09 22:17       ` Linus Walleij
  0 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 11:18 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Arnd Bergmann, Linus Walleij,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 11:24 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> > @@ -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?

> > diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> > index a25a77dd9a32..d0664e3b89bb 100644
> > --- a/drivers/input/touchscreen/ads7846.c
> > +++ b/drivers/input/touchscreen/ads7846.c
> > @@ -27,6 +27,7 @@
> >  #include <linux/of.h>
>
> >  #include <linux/of_gpio.h>
>
> (1)
>
> >  #include <linux/of_device.h>
>
> > +#include <linux/gpio/consumer.h>
>
> (2)
>
> >  #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)

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

diff --git a/drivers/input/touchscreen/ads7846.c
b/drivers/input/touchscreen/ads7846.c
index d0664e3b89bb..60e6b292ccdf 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 10:30   ` Andy Shevchenko
  2021-11-09 10:50     ` Arnd Bergmann
@ 2021-11-09 20:33     ` Linus Walleij
  1 sibling, 0 replies; 23+ messages in thread
From: Linus Walleij @ 2021-11-09 20:33 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Arnd Bergmann, linux-gpio, Arnd Bergmann, Bartosz Golaszewski,
	Geert Uytterhoeven, linux-arm-kernel, linux-kernel

On Tue, Nov 9, 2021 at 11:31 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> 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

> 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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 10:50     ` Arnd Bergmann
@ 2021-11-09 20:42       ` Linus Walleij
  2021-11-09 22:46         ` Arnd Bergmann
  0 siblings, 1 reply; 23+ messages in thread
From: Linus Walleij @ 2021-11-09 20:42 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andy Shevchenko, open list:GPIO SUBSYSTEM, Arnd Bergmann,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 11:50 AM Arnd Bergmann <arnd@kernel.org> wrote:

> I think the TODO list is in Linus' head,

Oh no, drivers/gpio/TODO

> 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 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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/8] gpiolib: shrink further
  2021-11-09 11:18     ` Arnd Bergmann
@ 2021-11-09 22:17       ` Linus Walleij
  2021-11-10 12:39         ` Arnd Bergmann
  0 siblings, 1 reply; 23+ messages in thread
From: Linus Walleij @ 2021-11-09 22:17 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andy Shevchenko, open list:GPIO SUBSYSTEM, Arnd Bergmann,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 12:18 PM Arnd Bergmann <arnd@kernel.org> wrote:

> 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:

> -               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/

> -       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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 20:42       ` Linus Walleij
@ 2021-11-09 22:46         ` Arnd Bergmann
  2021-11-10  0:03           ` Linus Walleij
  0 siblings, 1 reply; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-09 22:46 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, open list:GPIO SUBSYSTEM, Arnd Bergmann,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 9:42 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> On Tue, Nov 9, 2021 at 11:50 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> > I think the TODO list is in Linus' head,
>
> Oh no, drivers/gpio/TODO
>
> > 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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/8] gpiolib: remove legacy gpio_export
  2021-11-09 22:46         ` Arnd Bergmann
@ 2021-11-10  0:03           ` Linus Walleij
  0 siblings, 0 replies; 23+ messages in thread
From: Linus Walleij @ 2021-11-10  0:03 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andy Shevchenko, open list:GPIO SUBSYSTEM, Arnd Bergmann,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 11:47 PM Arnd Bergmann <arnd@kernel.org> wrote:

> 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!

> 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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/8] gpiolib: shrink further
  2021-11-09 22:17       ` Linus Walleij
@ 2021-11-10 12:39         ` Arnd Bergmann
  0 siblings, 0 replies; 23+ messages in thread
From: Arnd Bergmann @ 2021-11-10 12:39 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, open list:GPIO SUBSYSTEM, Arnd Bergmann,
	Bartosz Golaszewski, Geert Uytterhoeven, Linux ARM,
	Linux Kernel Mailing List

On Tue, Nov 9, 2021 at 11:17 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Tue, Nov 9, 2021 at 12:18 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> > 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:
>
> > -               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.

> Examples:
> git log -p --author=Walleij arch/arm/mach-pxa/
>
> > -       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

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-11-10 12:39 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 10:01 [PATCH v2 0/8] gpiolib header cleanup Arnd Bergmann
2021-11-09 10:02 ` [PATCH v2 1/8] gpiolib: remove irq_to_gpio() definition Arnd Bergmann
2021-11-09 10:02 ` [PATCH v2 2/8] gpiolib: remove empty asm/gpio.h files Arnd Bergmann
2021-11-09 10:02 ` [PATCH v2 3/8] gpiolib: coldfire: remove custom asm/gpio.h Arnd Bergmann
2021-11-09 10:02 ` [PATCH v2 4/8] gpiolib: remove asm-generic/gpio.h Arnd Bergmann
2021-11-09 10:19   ` Andy Shevchenko
2021-11-09 10:02 ` [PATCH v2 5/8] gpiolib: shrink further Arnd Bergmann
2021-11-09 10:24   ` Andy Shevchenko
2021-11-09 11:18     ` Arnd Bergmann
2021-11-09 22:17       ` Linus Walleij
2021-11-10 12:39         ` Arnd Bergmann
2021-11-09 10:02 ` [PATCH v2 6/8] gpiolib: remove legacy gpio_export Arnd Bergmann
2021-11-09 10:30   ` Andy Shevchenko
2021-11-09 10:50     ` Arnd Bergmann
2021-11-09 20:42       ` Linus Walleij
2021-11-09 22:46         ` Arnd Bergmann
2021-11-10  0:03           ` Linus Walleij
2021-11-09 20:33     ` Linus Walleij
2021-11-09 10:02 ` [PATCH v2 7/8] gpiolib: remove gpio_to_chip Arnd Bergmann
2021-11-09 10:32   ` Andy Shevchenko
2021-11-09 10:54     ` Arnd Bergmann
2021-11-09 10:02 ` [PATCH v2 8/8] gpiolib: split linux/gpio/driver.h out of linux/gpio.h Arnd Bergmann
2021-11-09 10:34   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).