gpio: rcar: Request GPIO while enabling interrupt

Message ID 1541185843-32732-1-git-send-email-fabrizio.castro@bp.renesas.com
State New
Headers show
Series
  • gpio: rcar: Request GPIO while enabling interrupt
Related show

Commit Message

Fabrizio Castro Nov. 2, 2018, 7:10 p.m.
There are cases when the bootloader configures a pin to work
as a function rather than GPIO, and other cases when the pin
is configured as a function at POR.
This commit makes sure the pin is configured as a GPIO the
moment we need it to work as an interrupt.

Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
---
RFC->PATCH:
* Moved gc->request to the bottom of gpio_rcar_irq_set_type

 drivers/gpio/gpio-rcar.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Geert Uytterhoeven Nov. 5, 2018, 10:10 a.m. | #1
Hi Fabrizio,

On Fri, Nov 2, 2018 at 8:10 PM Fabrizio Castro
<fabrizio.castro@bp.renesas.com> wrote:
> There are cases when the bootloader configures a pin to work
> as a function rather than GPIO, and other cases when the pin
> is configured as a function at POR.
> This commit makes sure the pin is configured as a GPIO the
> moment we need it to work as an interrupt.
>
> Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
> ---
> RFC->PATCH:
> * Moved gc->request to the bottom of gpio_rcar_irq_set_type

Thanks for the update!

> --- a/drivers/gpio/gpio-rcar.c
> +++ b/drivers/gpio/gpio-rcar.c
> @@ -147,6 +147,7 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
>         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
>         struct gpio_rcar_priv *p = gpiochip_get_data(gc);
>         unsigned int hwirq = irqd_to_hwirq(d);
> +       int err;
>
>         dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type);
>
> @@ -176,6 +177,13 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
>         default:
>                 return -EINVAL;
>         }
> +
> +       err = gc->request(gc, hwirq);

Call gpio_rcar_request() directly?

Where should the matching gpio_rcar_free() be called?

> +       if (err) {
> +               dev_err(&p->pdev->dev, "Can't request GPIO %d from %s\n", hwirq,

%u for unsigned int

> +                       gc->label);
> +               return err;
> +       }
>         return 0;
>  }

Gr{oetje,eeting}s,

                        Geert
Fabrizio Castro Nov. 6, 2018, 7:12 p.m. | #2
Hello Geert,

Thank you for your feedback!

> Subject: Re: [PATCH] gpio: rcar: Request GPIO while enabling interrupt
>
> Hi Fabrizio,
>
> On Fri, Nov 2, 2018 at 8:10 PM Fabrizio Castro
> <fabrizio.castro@bp.renesas.com> wrote:
> > There are cases when the bootloader configures a pin to work
> > as a function rather than GPIO, and other cases when the pin
> > is configured as a function at POR.
> > This commit makes sure the pin is configured as a GPIO the
> > moment we need it to work as an interrupt.
> >
> > Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
> > ---
> > RFC->PATCH:
> > * Moved gc->request to the bottom of gpio_rcar_irq_set_type
>
> Thanks for the update!
>
> > --- a/drivers/gpio/gpio-rcar.c
> > +++ b/drivers/gpio/gpio-rcar.c
> > @@ -147,6 +147,7 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
> >         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> >         struct gpio_rcar_priv *p = gpiochip_get_data(gc);
> >         unsigned int hwirq = irqd_to_hwirq(d);
> > +       int err;
> >
> >         dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type);
> >
> > @@ -176,6 +177,13 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
> >         default:
> >                 return -EINVAL;
> >         }
> > +
> > +       err = gc->request(gc, hwirq);
>
> Call gpio_rcar_request() directly?

Will change

>
> Where should the matching gpio_rcar_free() be called?

That is the question, isn't it?! I have looked around and I couldn't find anywhere sensible where to
call gpio_rcar_free from in such a way that would be somehow balance gpio_rcar_request  from
gpio_rcar_irq_set_type.
Thank you for suggesting irq_request_resources and irq_release_resources on IRC, it seems appropriate
to me, and after testing it  everything seems to be working fine, I'll send a new version exploring this
option, and I'll wait for valuable comments.

>
> > +       if (err) {
> > +               dev_err(&p->pdev->dev, "Can't request GPIO %d from %s\n", hwirq,
>
> %u for unsigned int

Well spotted, will fix


Thanks,
Fab

>
> > +                       gc->label);
> > +               return err;
> > +       }
> >         return 0;
> >  }
>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> 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



Renesas Electronics Europe Ltd, Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, UK. Registered in England & Wales under Registered No. 04586709.

Patch

diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 3c82bb3..5b96ee3 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -147,6 +147,7 @@  static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct gpio_rcar_priv *p = gpiochip_get_data(gc);
 	unsigned int hwirq = irqd_to_hwirq(d);
+	int err;
 
 	dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type);
 
@@ -176,6 +177,13 @@  static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
 	default:
 		return -EINVAL;
 	}
+
+	err = gc->request(gc, hwirq);
+	if (err) {
+		dev_err(&p->pdev->dev, "Can't request GPIO %d from %s\n", hwirq,
+			gc->label);
+		return err;
+	}
 	return 0;
 }