linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] gpio/omap: use gpiolib API to mark a GPIO used as an IRQ
@ 2013-10-16  0:47 Javier Martinez Canillas
  2013-10-16  8:06 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Javier Martinez Canillas @ 2013-10-16  0:47 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Santosh Shilimkar, Kevin Hilman, Stephen Warren, Lars Poeschel,
	Enric Balletbo i Serra, Tony Lindgren, linux-gpio, linux-omap,
	Javier Martinez Canillas

The OMAP GPIO driver keeps track about GPIO pins that are
used as IRQ lines for two reasons:

1) To prevent GPIO banks to be disabled while one of their
   GPIO pins are only used as an interrupt line.

2) To not allow another caller to set the GPIO pin as output.

Now gpiolib has an API to mark GPIO pins as used as IRQ lines
so the GPIO core only allows to set as output GPIO pins not
tied to an IRQ. So there is no need to have custom code for 2).

The IRQ usage still has to be maintained locally for 1) though.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
---
 drivers/gpio/gpio-omap.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 89675f8..f319c9f 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -514,6 +514,14 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
 		return -EINVAL;
 	}
 
+	retval = gpio_lock_as_irq(&bank->chip, offset);
+	if (retval) {
+		dev_err(bank->dev, "unable to lock offset %d for IRQ\n",
+			offset);
+		spin_unlock_irqrestore(&bank->lock, flags);
+		return retval;
+	}
+
 	bank->irq_usage |= 1 << GPIO_INDEX(bank, gpio);
 	spin_unlock_irqrestore(&bank->lock, flags);
 
@@ -797,6 +805,7 @@ static void gpio_irq_shutdown(struct irq_data *d)
 	unsigned offset = GPIO_INDEX(bank, gpio);
 
 	spin_lock_irqsave(&bank->lock, flags);
+	gpio_unlock_as_irq(&bank->chip, offset);
 	bank->irq_usage &= ~(1 << offset);
 	_disable_gpio_module(bank, offset);
 	_reset_gpio(bank, gpio);
@@ -957,22 +966,13 @@ static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
 {
 	struct gpio_bank *bank;
 	unsigned long flags;
-	int retval = 0;
 
 	bank = container_of(chip, struct gpio_bank, chip);
 	spin_lock_irqsave(&bank->lock, flags);
-
-	if (LINE_USED(bank->irq_usage, offset)) {
-			retval = -EINVAL;
-			goto exit;
-	}
-
 	bank->set_dataout(bank, offset, value);
 	_set_gpio_direction(bank, offset, 0);
-
-exit:
 	spin_unlock_irqrestore(&bank->lock, flags);
-	return retval;
+	return 0;
 }
 
 static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
-- 
1.8.4.rc3


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

* Re: [PATCH 1/1] gpio/omap: use gpiolib API to mark a GPIO used as an IRQ
  2013-10-16  0:47 [PATCH 1/1] gpio/omap: use gpiolib API to mark a GPIO used as an IRQ Javier Martinez Canillas
@ 2013-10-16  8:06 ` Linus Walleij
  2013-10-16  8:25   ` Javier Martinez Canillas
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2013-10-16  8:06 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: Santosh Shilimkar, Kevin Hilman, Stephen Warren, Lars Poeschel,
	Enric Balletbo i Serra, Tony Lindgren, linux-gpio@vger.kernel.org,
	Linux-OMAP

On Wed, Oct 16, 2013 at 2:47 AM, Javier Martinez Canillas
<javier.martinez@collabora.co.uk> wrote:

> The OMAP GPIO driver keeps track about GPIO pins that are
> used as IRQ lines for two reasons:
>
> 1) To prevent GPIO banks to be disabled while one of their
>    GPIO pins are only used as an interrupt line.
>
> 2) To not allow another caller to set the GPIO pin as output.
>
> Now gpiolib has an API to mark GPIO pins as used as IRQ lines
> so the GPIO core only allows to set as output GPIO pins not
> tied to an IRQ. So there is no need to have custom code for 2).
>
> The IRQ usage still has to be maintained locally for 1) though.
>
> Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>

Patch applied. I had to merge in v3.12-rc4 to get the dependency
fixes, so I guess you did something similar when developing
this...

Yours,
Linus Walleij

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

* Re: [PATCH 1/1] gpio/omap: use gpiolib API to mark a GPIO used as an IRQ
  2013-10-16  8:06 ` Linus Walleij
@ 2013-10-16  8:25   ` Javier Martinez Canillas
  0 siblings, 0 replies; 3+ messages in thread
From: Javier Martinez Canillas @ 2013-10-16  8:25 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Santosh Shilimkar, Kevin Hilman, Stephen Warren, Lars Poeschel,
	Enric Balletbo i Serra, Tony Lindgren, linux-gpio@vger.kernel.org,
	Linux-OMAP

On 10/16/2013 10:06 AM, Linus Walleij wrote:
> On Wed, Oct 16, 2013 at 2:47 AM, Javier Martinez Canillas
> <javier.martinez@collabora.co.uk> wrote:
> 
>> The OMAP GPIO driver keeps track about GPIO pins that are
>> used as IRQ lines for two reasons:
>>
>> 1) To prevent GPIO banks to be disabled while one of their
>>    GPIO pins are only used as an interrupt line.
>>
>> 2) To not allow another caller to set the GPIO pin as output.
>>
>> Now gpiolib has an API to mark GPIO pins as used as IRQ lines
>> so the GPIO core only allows to set as output GPIO pins not
>> tied to an IRQ. So there is no need to have custom code for 2).
>>
>> The IRQ usage still has to be maintained locally for 1) though.
>>
>> Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
> 
> Patch applied. I had to merge in v3.12-rc4 to get the dependency
> fixes, so I guess you did something similar when developing
> this...
>

Thanks and yes since this is not a critical bug it was meant to be for v3.13 on
top of fac7fa162 ("gpio/omap: auto-setup a GPIO when used as an IRQ") and after
you have merged your flag-irqs branch.

Sorry for not explicitly mentioning this dependency.

> Yours,
> Linus Walleij
> 

Best regards,
Javier

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

end of thread, other threads:[~2013-10-16  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-16  0:47 [PATCH 1/1] gpio/omap: use gpiolib API to mark a GPIO used as an IRQ Javier Martinez Canillas
2013-10-16  8:06 ` Linus Walleij
2013-10-16  8:25   ` Javier Martinez Canillas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).