All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: convince line to become input in irq helper
@ 2016-06-22 14:33 Linus Walleij
  2016-06-22 17:12 ` Bjorn Andersson
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2016-06-22 14:33 UTC (permalink / raw)
  To: linux-gpio, Alexandre Courbot; +Cc: Linus Walleij

The generic IRQ helper library just checks if the IRQ line is
set as input before activating it for interrupts. As we
recently started to check things better with .get_dir() it
turns out that it's good to try to convince the line to become
an input before attempting to lock it as IRQ.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpiolib.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 58d822d7e8da..b9a6a5c69fbb 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1010,6 +1010,23 @@ static int gpiochip_irq_reqres(struct irq_data *d)
 	if (!try_module_get(chip->gpiodev->owner))
 		return -ENODEV;
 
+	/*
+	 * If it is possible to switch this GPIO to an input
+	 * this is a good time to do it.
+	 */
+	if (chip->direction_input) {
+		struct gpio_desc *desc;
+		int ret;
+
+		desc = gpiochip_get_desc(chip, d->hwirq);
+		if (IS_ERR(desc))
+			return PTR_ERR(desc);
+
+	        ret = chip->direction_input(chip, d->hwirq);
+		if (!ret)
+			clear_bit(FLAG_IS_OUT, &desc->flags);
+	}
+
 	if (gpiochip_lock_as_irq(chip, d->hwirq)) {
 		chip_err(chip,
 			"unable to lock HW IRQ %lu for IRQ\n",
-- 
2.4.11


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

* Re: [PATCH] gpio: convince line to become input in irq helper
  2016-06-22 14:33 [PATCH] gpio: convince line to become input in irq helper Linus Walleij
@ 2016-06-22 17:12 ` Bjorn Andersson
  2016-06-22 21:23   ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Andersson @ 2016-06-22 17:12 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Alexandre Courbot

On Wed 22 Jun 07:33 PDT 2016, Linus Walleij wrote:

> The generic IRQ helper library just checks if the IRQ line is
> set as input before activating it for interrupts. As we
> recently started to check things better with .get_dir() it
> turns out that it's good to try to convince the line to become
> an input before attempting to lock it as IRQ.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

I really like this.

> ---
>  drivers/gpio/gpiolib.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 58d822d7e8da..b9a6a5c69fbb 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1010,6 +1010,23 @@ static int gpiochip_irq_reqres(struct irq_data *d)
>  	if (!try_module_get(chip->gpiodev->owner))
>  		return -ENODEV;
>  
> +	/*
> +	 * If it is possible to switch this GPIO to an input
> +	 * this is a good time to do it.
> +	 */
> +	if (chip->direction_input) {
> +		struct gpio_desc *desc;
> +		int ret;
> +
> +		desc = gpiochip_get_desc(chip, d->hwirq);
> +		if (IS_ERR(desc))
> +			return PTR_ERR(desc);
> +
> +	        ret = chip->direction_input(chip, d->hwirq);
> +		if (!ret)
> +			clear_bit(FLAG_IS_OUT, &desc->flags);

With this updated semantics I think it's a mistake to not propagate this
error. Clients will not be able to rely on it and have to continue
configuring their pins as input just to be sure.

> +	}
> +
>  	if (gpiochip_lock_as_irq(chip, d->hwirq)) {
>  		chip_err(chip,
>  			"unable to lock HW IRQ %lu for IRQ\n",

Regards,
Bjorn

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

* Re: [PATCH] gpio: convince line to become input in irq helper
  2016-06-22 17:12 ` Bjorn Andersson
@ 2016-06-22 21:23   ` Linus Walleij
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2016-06-22 21:23 UTC (permalink / raw)
  To: Bjorn Andersson; +Cc: linux-gpio, Alexandre Courbot

On Wed, Jun 22, 2016 at 7:12 PM, Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
> On Wed 22 Jun 07:33 PDT 2016, Linus Walleij wrote:
>
>> The generic IRQ helper library just checks if the IRQ line is
>> set as input before activating it for interrupts. As we
>> recently started to check things better with .get_dir() it
>> turns out that it's good to try to convince the line to become
>> an input before attempting to lock it as IRQ.
>>
>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
>
> I really like this.

Thanks :)

>> +     /*
>> +      * If it is possible to switch this GPIO to an input
>> +      * this is a good time to do it.
>> +      */
>> +     if (chip->direction_input) {
>> +             struct gpio_desc *desc;
>> +             int ret;
>> +
>> +             desc = gpiochip_get_desc(chip, d->hwirq);
>> +             if (IS_ERR(desc))
>> +                     return PTR_ERR(desc);
>> +
>> +             ret = chip->direction_input(chip, d->hwirq);
>> +             if (!ret)
>> +                     clear_bit(FLAG_IS_OUT, &desc->flags);
>
> With this updated semantics I think it's a mistake to not propagate this
> error. Clients will not be able to rely on it and have to continue
> configuring their pins as input just to be sure.

OK good point I'll propagate it. But it will only be used by those
driver utilizing the generic IRQchip helper.

It's especially for the usecase where you take an IRQ off a DT
resource without gpiod_to_irq() first.

Yours,
Linus Walleij

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

end of thread, other threads:[~2016-06-22 21:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-22 14:33 [PATCH] gpio: convince line to become input in irq helper Linus Walleij
2016-06-22 17:12 ` Bjorn Andersson
2016-06-22 21:23   ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.