Skip to contentSkip to conversation

gpiolib: remove irq_to_gpio() definition

RFC Superseded Arnd Bergmann 5 participants 13 messages Nov 5, 2021 – Nov 9, 2021

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC 1/3 gpiolib: remove irq_to_gpio() definition

From: Arnd Bergmann <[email protected]>

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

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

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

RFC 2/3 gpiolib: remove empty asm/gpio.h files

From: Arnd Bergmann <[email protected]>

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

The drivers that actually use the sh3 specific version also include cpu/gpio.h directly. This leaves coldfire as the only gpio driver that needs something custom for gpiolib.

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

45 lines not on this page · raw message

Signature · 1 line
2.29.2
maintainer Reviewed-by on v1 2/3
#2 lore raw

Re: [RFC 2/3] gpiolib: remove empty asm/gpio.h files

Hi Arnd,

Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

The drivers that actually use the sh3 specific version also include cpu/gpio.h directly. This leaves coldfire as the only gpio driver

All but arch/sh/boards/board-magicpanelr2.c do. So that one needs a direct inclusion of <cpu/gpio.h>.

Quoted 3 lines

that needs something custom for gpiolib.

With the above fixed:

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Reviewed-by on v1 2/3
#3 lore raw

Re: [RFC 2/3] gpiolib: remove empty asm/gpio.h files

In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

The drivers that actually use the sh3 specific version also include cpu/gpio.h directly. This leaves coldfire as the only gpio driver that needs something custom for gpiolib.

Excellent!

I suggest Bartosz can queue this in the GPIO tree.

Yours,
Linus Walleij

#4 lore raw

Re: [RFC 2/3] gpiolib: remove empty asm/gpio.h files

Quoted 12 lines · Linus Walleij
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

The drivers that actually use the sh3 specific version also include cpu/gpio.h directly. This leaves coldfire as the only gpio driver that needs something custom for gpiolib.

Quoted 6 lines
Quoted 1 line

Excellent!

I suggest Bartosz can queue this in the GPIO tree.

I just sent v2 with slightly updated changelog texts and additional patches but without your Reviewed-by:. I suppose I'll have a v3 after the merge window, let's use that.

Arnd

#5 lore raw

RFC 3/3 gpiolib: coldfire: remove custom asm/gpio.h

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

For the gpio_get_value()/gpio_set_value()/gpio_to_irq(), gpio_cansleep() functions, the custom version is only a micro-optimization to inline the function for constant GPIO numbers. However, in the coldfire defconfigs, I was unable to find a single instance where this micro-optimization was even used, so to my best knowledge removing this has no downsides.

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

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

95 lines not on this page · raw message

drivers/gpio/Kconfig +0 -8
index 9ef5d3fdd405..5b233e69a98f 100644
@@ -3,14 +3,6 @@
 # GPIO infrastructure and drivers
 #
 
-config ARCH_HAVE_CUSTOM_GPIO_H
-	bool
-	help
-	  Selecting this config option from the architecture Kconfig allows
-	  the architecture to provide a custom asm/gpio.h implementation
-	  overriding the default implementations.  New uses of this are
-	  strongly discouraged.
-
 menuconfig GPIOLIB
 	bool "GPIO Support"
 	help
include/linux/gpio.h +0 -7
index d8d7daa7eb94..7e6b1b8277ca 100644
@@ -54,11 +54,6 @@ struct gpio {
 };
 
 #ifdef CONFIG_GPIOLIB
-
-#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
-#include <asm/gpio.h>
-#else
-
 #include <asm-generic/gpio.h>
 
 static inline int gpio_get_value(unsigned int gpio)
@@ -81,8 +76,6 @@ static inline int gpio_to_irq(unsigned int gpio)
 	return __gpio_to_irq(gpio);
 }
 
-#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
-
 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
 
 struct device;
Signature · 1 line
2.29.2
maintainer Reviewed-by on v1 3/3
#6 lore raw

Re: [RFC 3/3] gpiolib: coldfire: remove custom asm/gpio.h

Hi Arnd,

Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

For the gpio_get_value()/gpio_set_value()/gpio_to_irq(), gpio_cansleep() functions, the custom version is only a micro-optimization to inline the function for constant GPIO numbers. However, in the coldfire defconfigs, I was unable to find a single instance where this micro-optimization was even used, so to my best knowledge removing this has no downsides.

The only user seems to be QSPI chip select handling (not bit-banged data transfer) in arch/m68k/coldfire/device.c, but that indeed depends on CONFIG_SPI_COLDFIRE_QSPI, which is not set in any of the defconfigs. That doesn't mean there were/are no real users, though ;-)

Quoted 4 lines

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

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Reviewed-by
#7 lore raw

Re: [RFC 3/3] gpiolib: coldfire: remove custom asm/gpio.h

Hi arnd, Geert,

Quoted 14 lines · Geert Uytterhoeven

Hi Arnd,

Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

For the gpio_get_value()/gpio_set_value()/gpio_to_irq(), gpio_cansleep() functions, the custom version is only a micro-optimization to inline the function for constant GPIO numbers. However, in the coldfire defconfigs, I was unable to find a single instance where this micro-optimization was even used, so to my best knowledge removing this has no downsides.

Quoted 4 lines

The only user seems to be QSPI chip select handling (not bit-banged data transfer) in arch/m68k/coldfire/device.c, but that indeed depends on CONFIG_SPI_COLDFIRE_QSPI, which is not set in any of the defconfigs. That doesn't mean there were/are no real users, though ;-)

That is definitely used by some.
But the generalization and removal of the special casing seems like a win to me.

Quoted 6 lines
Quoted 4 lines

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

Regards
Greg

Quoted 11 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Reviewed-by on v1 3/3
#8 lore raw

Re: [RFC 3/3] gpiolib: coldfire: remove custom asm/gpio.h

In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

For the gpio_get_value()/gpio_set_value()/gpio_to_irq(), gpio_cansleep() functions, the custom version is only a micro-optimization to inline the function for constant GPIO numbers. However, in the coldfire defconfigs, I was unable to find a single instance where this micro-optimization was even used, so to my best knowledge removing this has no downsides.

Quoted 4 lines

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

Yours,
Linus Walleij

Reviewed-by on v1 1/3
#9 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

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

FWIW,

Thanks, Arnd, for cleaning this up!

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

From: Arnd Bergmann <[email protected]>

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

Quoted 5 lines
Quoted 2 lines

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

FWIW,

This is for the entire series.

Quoted 1 line

Thanks, Arnd, for cleaning this up!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Reviewed-by on v1 1/3
#11 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

Quoted 8 lines

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

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Reviewed-by on v1 1/3
#12 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

Quoted 8 lines

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

Thanks for doing this Arnd. I had it on my mind some years ago but I think Coldfire or something was still using it and didn't think about it as the last user disappeared.

Yours,
Linus Walleij