diff mbox series

gpio: Get rid of gpio_to_chip()

Message ID 20230120093800.653126-1-linus.walleij@linaro.org
State Accepted
Commit e3863fa123c8fd9647782bc560216c6b910711e8
Headers show
Series gpio: Get rid of gpio_to_chip() | expand

Commit Message

Linus Walleij Jan. 20, 2023, 9:38 a.m. UTC
The gpio_to_chip() function refers to the global GPIO numberspace
which is a problem we want to get rid of. Get this function out
of the header and open code it into gpiolib with appropriate FIXME
notices so no new users appear in the kernel.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/pinctrl/core.c     | 14 ++++++++++++--
 include/asm-generic/gpio.h |  6 ------
 2 files changed, 12 insertions(+), 8 deletions(-)

Comments

Bartosz Golaszewski Jan. 20, 2023, 1:04 p.m. UTC | #1
On Fri, Jan 20, 2023 at 10:38 AM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> The gpio_to_chip() function refers to the global GPIO numberspace
> which is a problem we want to get rid of. Get this function out
> of the header and open code it into gpiolib with appropriate FIXME
> notices so no new users appear in the kernel.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/pinctrl/core.c     | 14 ++++++++++++--
>  include/asm-generic/gpio.h |  6 ------
>  2 files changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index 41fd84738707..d6e6c751255f 100644
> --- a/drivers/pinctrl/core.c
> +++ b/drivers/pinctrl/core.c
> @@ -325,7 +325,12 @@ 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);
> +       /*
> +        * FIXME: "gpio" here is a number in the global GPIO numberspace.
> +        * get rid of this from the ranges eventually and get the GPIO
> +        * descriptor from the gpio_chip.
> +        */
> +       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 +1662,12 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
>                         }
>                 }
>                 if (gpio_num >= 0)
> -                       chip = gpio_to_chip(gpio_num);
> +                       /*
> +                        * FIXME: gpio_num comes from the global GPIO numberspace.
> +                        * we need to get rid of the range->base eventually and
> +                        * get the descriptor directly from the gpio_chip.
> +                        */
> +                       chip = gpiod_to_chip(gpio_to_desc(gpio_num));
>                 else
>                         chip = NULL;
>                 if (chip)
> diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
> index a7752cf152ce..21437fc96835 100644
> --- a/include/asm-generic/gpio.h
> +++ b/include/asm-generic/gpio.h
> @@ -31,12 +31,6 @@ 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.
>   */
> --
> 2.34.1
>

Yes please! Applied, thanks!

Bart
diff mbox series

Patch

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 41fd84738707..d6e6c751255f 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -325,7 +325,12 @@  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);
+	/*
+	 * FIXME: "gpio" here is a number in the global GPIO numberspace.
+	 * get rid of this from the ranges eventually and get the GPIO
+	 * descriptor from the gpio_chip.
+	 */
+	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 +1662,12 @@  static int pinctrl_pins_show(struct seq_file *s, void *what)
 			}
 		}
 		if (gpio_num >= 0)
-			chip = gpio_to_chip(gpio_num);
+			/*
+			 * FIXME: gpio_num comes from the global GPIO numberspace.
+			 * we need to get rid of the range->base eventually and
+			 * get the descriptor directly from the gpio_chip.
+			 */
+			chip = gpiod_to_chip(gpio_to_desc(gpio_num));
 		else
 			chip = NULL;
 		if (chip)
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index a7752cf152ce..21437fc96835 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -31,12 +31,6 @@  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.
  */