linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: tegra: use new gpio_lock_as_irq() API
@ 2013-10-16 19:25 Stephen Warren
  2013-10-17  3:25 ` Javier Martinez Canillas
       [not found] ` <1381951533-18179-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Warren @ 2013-10-16 19:25 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-tegra, Stephen Warren

From: Stephen Warren <swarren@nvidia.com>

Whenever an IRQ is claimed or freed, call gpio_lock_as_irq() or
gpio_unlock_as_irq() on the associated GPIO, to prevent that GPIO from
being configured in a manner incompatible with an interrupt.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/gpio/gpio-tegra.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 9a62672..cfd3b90 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -75,6 +75,7 @@ struct tegra_gpio_bank {
 #endif
 };
 
+static struct device *dev;
 static struct irq_domain *irq_domain;
 static void __iomem *regs;
 static u32 tegra_gpio_bank_count;
@@ -205,6 +206,7 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	int lvl_type;
 	int val;
 	unsigned long flags;
+	int ret;
 
 	switch (type & IRQ_TYPE_SENSE_MASK) {
 	case IRQ_TYPE_EDGE_RISING:
@@ -231,6 +233,12 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 		return -EINVAL;
 	}
 
+	ret = gpio_lock_as_irq(&tegra_gpio_chip, gpio);
+	if (ret) {
+		dev_err(dev, "unable to lock Tegra GPIO %d as IRQ\n", gpio);
+		return ret;
+	}
+
 	spin_lock_irqsave(&bank->lvl_lock[port], flags);
 
 	val = tegra_gpio_readl(GPIO_INT_LVL(gpio));
@@ -251,6 +259,13 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	return 0;
 }
 
+static void tegra_gpio_irq_shutdown(struct irq_data *d)
+{
+	int gpio = d->hwirq;
+
+	gpio_unlock_as_irq(&tegra_gpio_chip, gpio);
+}
+
 static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
 {
 	struct tegra_gpio_bank *bank;
@@ -368,6 +383,7 @@ static struct irq_chip tegra_gpio_irq_chip = {
 	.irq_mask	= tegra_gpio_irq_mask,
 	.irq_unmask	= tegra_gpio_irq_unmask,
 	.irq_set_type	= tegra_gpio_irq_set_type,
+	.irq_shutdown	= tegra_gpio_irq_shutdown,
 #ifdef CONFIG_PM_SLEEP
 	.irq_set_wake	= tegra_gpio_irq_set_wake,
 #endif
@@ -413,6 +429,8 @@ static int tegra_gpio_probe(struct platform_device *pdev)
 	int i;
 	int j;
 
+	dev = &pdev->dev;
+
 	match = of_match_device(tegra_gpio_of_match, &pdev->dev);
 	if (!match) {
 		dev_err(&pdev->dev, "Error: No device match found\n");
-- 
1.8.1.5


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

* Re: [PATCH] gpio: tegra: use new gpio_lock_as_irq() API
  2013-10-16 19:25 [PATCH] gpio: tegra: use new gpio_lock_as_irq() API Stephen Warren
@ 2013-10-17  3:25 ` Javier Martinez Canillas
       [not found] ` <1381951533-18179-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Javier Martinez Canillas @ 2013-10-17  3:25 UTC (permalink / raw)
  To: Stephen Warren; +Cc: Linus Walleij, linux-gpio, linux-tegra, Stephen Warren

On Wed, Oct 16, 2013 at 9:25 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Whenever an IRQ is claimed or freed, call gpio_lock_as_irq() or
> gpio_unlock_as_irq() on the associated GPIO, to prevent that GPIO from
> being configured in a manner incompatible with an interrupt.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  drivers/gpio/gpio-tegra.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 9a62672..cfd3b90 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -75,6 +75,7 @@ struct tegra_gpio_bank {
>  #endif
>  };
>
> +static struct device *dev;
>  static struct irq_domain *irq_domain;
>  static void __iomem *regs;
>  static u32 tegra_gpio_bank_count;
> @@ -205,6 +206,7 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>         int lvl_type;
>         int val;
>         unsigned long flags;
> +       int ret;
>
>         switch (type & IRQ_TYPE_SENSE_MASK) {
>         case IRQ_TYPE_EDGE_RISING:
> @@ -231,6 +233,12 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>                 return -EINVAL;
>         }
>
> +       ret = gpio_lock_as_irq(&tegra_gpio_chip, gpio);
> +       if (ret) {
> +               dev_err(dev, "unable to lock Tegra GPIO %d as IRQ\n", gpio);
> +               return ret;
> +       }
> +
>         spin_lock_irqsave(&bank->lvl_lock[port], flags);
>
>         val = tegra_gpio_readl(GPIO_INT_LVL(gpio));
> @@ -251,6 +259,13 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>         return 0;
>  }
>
> +static void tegra_gpio_irq_shutdown(struct irq_data *d)
> +{
> +       int gpio = d->hwirq;
> +
> +       gpio_unlock_as_irq(&tegra_gpio_chip, gpio);
> +}
> +
>  static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
>  {
>         struct tegra_gpio_bank *bank;
> @@ -368,6 +383,7 @@ static struct irq_chip tegra_gpio_irq_chip = {
>         .irq_mask       = tegra_gpio_irq_mask,
>         .irq_unmask     = tegra_gpio_irq_unmask,
>         .irq_set_type   = tegra_gpio_irq_set_type,
> +       .irq_shutdown   = tegra_gpio_irq_shutdown,
>  #ifdef CONFIG_PM_SLEEP
>         .irq_set_wake   = tegra_gpio_irq_set_wake,
>  #endif
> @@ -413,6 +429,8 @@ static int tegra_gpio_probe(struct platform_device *pdev)
>         int i;
>         int j;
>
> +       dev = &pdev->dev;
> +
>         match = of_match_device(tegra_gpio_of_match, &pdev->dev);
>         if (!match) {
>                 dev_err(&pdev->dev, "Error: No device match found\n");
> --

Reviewed-by: Javier Martinez Canillas <javier@dowhile0.org>

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

* Re: [PATCH] gpio: tegra: use new gpio_lock_as_irq() API
       [not found] ` <1381951533-18179-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2013-10-17  3:45   ` David Cohen
  2013-10-17  4:25     ` Stephen Warren
  2013-10-17  8:52   ` Linus Walleij
  1 sibling, 1 reply; 6+ messages in thread
From: David Cohen @ 2013-10-17  3:45 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Linus Walleij, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren

Hi Stephen,

On 10/16/2013 12:25 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> Whenever an IRQ is claimed or freed, call gpio_lock_as_irq() or
> gpio_unlock_as_irq() on the associated GPIO, to prevent that GPIO from
> being configured in a manner incompatible with an interrupt.
>
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>   drivers/gpio/gpio-tegra.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
>
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 9a62672..cfd3b90 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -75,6 +75,7 @@ struct tegra_gpio_bank {
>   #endif
>   };
>
> +static struct device *dev;
>   static struct irq_domain *irq_domain;
>   static void __iomem *regs;
>   static u32 tegra_gpio_bank_count;
> @@ -205,6 +206,7 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>   	int lvl_type;
>   	int val;
>   	unsigned long flags;
> +	int ret;
>
>   	switch (type & IRQ_TYPE_SENSE_MASK) {
>   	case IRQ_TYPE_EDGE_RISING:
> @@ -231,6 +233,12 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>   		return -EINVAL;
>   	}
>
> +	ret = gpio_lock_as_irq(&tegra_gpio_chip, gpio);
> +	if (ret) {
> +		dev_err(dev, "unable to lock Tegra GPIO %d as IRQ\n", gpio);

As a suggestion, you could add a pointer to dev on tegra gpio priv data
and recover it using ira_data_get_irq_chip_data(), instead of using
static file-scope variable.

Br, David Cohen

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

* Re: [PATCH] gpio: tegra: use new gpio_lock_as_irq() API
  2013-10-17  3:45   ` David Cohen
@ 2013-10-17  4:25     ` Stephen Warren
       [not found]       ` <525F66B1.9020903-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Warren @ 2013-10-17  4:25 UTC (permalink / raw)
  To: David Cohen; +Cc: Linus Walleij, linux-gpio, linux-tegra, Stephen Warren

On 10/16/2013 09:45 PM, David Cohen wrote:
> Hi Stephen,
> 
> On 10/16/2013 12:25 PM, Stephen Warren wrote:
>> From: Stephen Warren <swarren@nvidia.com>
>>
>> Whenever an IRQ is claimed or freed, call gpio_lock_as_irq() or
>> gpio_unlock_as_irq() on the associated GPIO, to prevent that GPIO from
>> being configured in a manner incompatible with an interrupt.

> As a suggestion, you could add a pointer to dev on tegra gpio priv data
> and recover it using ira_data_get_irq_chip_data(), instead of using
> static file-scope variable.

That's true, but I figured it wasn't worth doing that without getting
rid of all the other global data, which is a subject for another patch.


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

* Re: [PATCH] gpio: tegra: use new gpio_lock_as_irq() API
       [not found] ` <1381951533-18179-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  2013-10-17  3:45   ` David Cohen
@ 2013-10-17  8:52   ` Linus Walleij
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2013-10-17  8:52 UTC (permalink / raw)
  To: Stephen Warren
  Cc: linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Stephen Warren

On Wed, Oct 16, 2013 at 9:25 PM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:

> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> Whenever an IRQ is claimed or freed, call gpio_lock_as_irq() or
> gpio_unlock_as_irq() on the associated GPIO, to prevent that GPIO from
> being configured in a manner incompatible with an interrupt.
>
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

Patch applied with Javiers review-tag.

Yours,
Linus Walleij

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

* Re: [PATCH] gpio: tegra: use new gpio_lock_as_irq() API
       [not found]       ` <525F66B1.9020903-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2013-10-17  8:53         ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2013-10-17  8:53 UTC (permalink / raw)
  To: Stephen Warren
  Cc: David Cohen, linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Stephen Warren

On Thu, Oct 17, 2013 at 6:25 AM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:
> On 10/16/2013 09:45 PM, David Cohen wrote:
>> Hi Stephen,
>>
>> On 10/16/2013 12:25 PM, Stephen Warren wrote:
>>> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>>>
>>> Whenever an IRQ is claimed or freed, call gpio_lock_as_irq() or
>>> gpio_unlock_as_irq() on the associated GPIO, to prevent that GPIO from
>>> being configured in a manner incompatible with an interrupt.
>
>> As a suggestion, you could add a pointer to dev on tegra gpio priv data
>> and recover it using ira_data_get_irq_chip_data(), instead of using
>> static file-scope variable.
>
> That's true, but I figured it wasn't worth doing that without getting
> rid of all the other global data, which is a subject for another patch.

Yeah that would be nice, singletons are a bit unorthodox these
days but it's certain a separate refactoring.

Yours,
Linus Walleij

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

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-16 19:25 [PATCH] gpio: tegra: use new gpio_lock_as_irq() API Stephen Warren
2013-10-17  3:25 ` Javier Martinez Canillas
     [not found] ` <1381951533-18179-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-10-17  3:45   ` David Cohen
2013-10-17  4:25     ` Stephen Warren
     [not found]       ` <525F66B1.9020903-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-10-17  8:53         ` Linus Walleij
2013-10-17  8:52   ` Linus Walleij

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).