[1/9] gpio: Support GPIO controllers without pin-ranges
diff mbox series

Message ID 20200319122737.3063291-2-thierry.reding@gmail.com
State New
Headers show
Series
  • pinctrl: tegra: Support SFIO/GPIO programming
Related show

Commit Message

Thierry Reding March 19, 2020, 12:27 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

Wake gpiochip_generic_request() call into the pinctrl helpers only if a
GPIO controller had any pin-ranges assigned to it. This allows a driver
to unconditionally use this helper if it supports multiple devices of
which only a subset have pin-ranges assigned to them.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/gpio/gpiolib.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Vidya Sagar March 19, 2020, 5:05 p.m. UTC | #1
On 3/19/2020 5:57 PM, Thierry Reding wrote:
> External email: Use caution opening links or attachments
> 
> 
> From: Thierry Reding <treding@nvidia.com>
> 
> Wake gpiochip_generic_request() call into the pinctrl helpers only if a
> GPIO controller had any pin-ranges assigned to it. This allows a driver
> to unconditionally use this helper if it supports multiple devices of
> which only a subset have pin-ranges assigned to them.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>   drivers/gpio/gpiolib.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index f31b1d46599e..12f3c339da78 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2792,7 +2792,10 @@ static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip)
>    */
>   int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset)
>   {
> -       return pinctrl_gpio_request(chip->gpiodev->base + offset);
> +       if (!list_empty(&chip->gpiodev->pin_ranges))
> +               return pinctrl_gpio_request(chip->gpiodev->base + offset);
> +
> +       return 0;
>   }
>   EXPORT_SYMBOL_GPL(gpiochip_generic_request);
> 
> --
> 2.24.1
> 
Tested-by: Vidya Sagar <vidyas@nvidia.com>
Linus Walleij March 27, 2020, 10:37 a.m. UTC | #2
On Thu, Mar 19, 2020 at 1:27 PM Thierry Reding <thierry.reding@gmail.com> wrote:

> From: Thierry Reding <treding@nvidia.com>
>
> Wake gpiochip_generic_request() call into the pinctrl helpers only if a
> GPIO controller had any pin-ranges assigned to it. This allows a driver
> to unconditionally use this helper if it supports multiple devices of
> which only a subset have pin-ranges assigned to them.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Patch applied.

We have some drivers like this:
drivers/gpio/gpio-pl061.c:

        if (of_property_read_bool(dev->of_node, "gpio-ranges")) {
                pl061->gc.request = gpiochip_generic_request;
                pl061->gc.free = gpiochip_generic_free;
        }

Should we just make a patch assigning these callbacks
unconditionally as a follow-up?

Yours,
Linus Walleij
Thierry Reding March 27, 2020, 12:13 p.m. UTC | #3
On Fri, Mar 27, 2020 at 11:37:07AM +0100, Linus Walleij wrote:
> On Thu, Mar 19, 2020 at 1:27 PM Thierry Reding <thierry.reding@gmail.com> wrote:
> 
> > From: Thierry Reding <treding@nvidia.com>
> >
> > Wake gpiochip_generic_request() call into the pinctrl helpers only if a
> > GPIO controller had any pin-ranges assigned to it. This allows a driver
> > to unconditionally use this helper if it supports multiple devices of
> > which only a subset have pin-ranges assigned to them.
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> Patch applied.
> 
> We have some drivers like this:
> drivers/gpio/gpio-pl061.c:
> 
>         if (of_property_read_bool(dev->of_node, "gpio-ranges")) {
>                 pl061->gc.request = gpiochip_generic_request;
>                 pl061->gc.free = gpiochip_generic_free;
>         }
> 
> Should we just make a patch assigning these callbacks
> unconditionally as a follow-up?

Yeah, that's a good idea. I'll look into it.

Thierry

Patch
diff mbox series

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f31b1d46599e..12f3c339da78 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2792,7 +2792,10 @@  static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip)
  */
 int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset)
 {
-	return pinctrl_gpio_request(chip->gpiodev->base + offset);
+	if (!list_empty(&chip->gpiodev->pin_ranges))
+		return pinctrl_gpio_request(chip->gpiodev->base + offset);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(gpiochip_generic_request);