linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: tegra: Fix tegra_gpio_irq_set_type()
@ 2018-07-17 16:10 Dmitry Osipenko
  2018-07-19 14:41 ` Jon Hunter
  2018-07-29 20:39 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Osipenko @ 2018-07-17 16:10 UTC (permalink / raw)
  To: Linus Walleij, Thierry Reding, Jonathan Hunter
  Cc: linux-tegra, linux-gpio, linux-kernel

Commit 36b312792b97 ("gpiolib: Respect error code of ->get_direction()")
broke tegra_gpio_irq_set_type() because requesting of GPIO direction must
be done after enabling GPIO function for a pin.

This patch fixes drivers probe failure like this:

 gpio gpiochip0: (tegra-gpio): gpiochip_lock_as_irq: cannot get GPIO direction
 tegra-gpio 6000d000.gpio: unable to lock Tegra GPIO 144 as IRQ

Fixes: 36b312792b97 ("gpiolib: Respect error code of ->get_direction()")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/gpio/gpio-tegra.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 94396caaca75..22e7c99ed69e 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -323,13 +323,6 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 		return -EINVAL;
 	}
 
-	ret = gpiochip_lock_as_irq(&tgi->gc, gpio);
-	if (ret) {
-		dev_err(tgi->dev,
-			"unable to lock Tegra GPIO %u as IRQ\n", gpio);
-		return ret;
-	}
-
 	spin_lock_irqsave(&bank->lvl_lock[port], flags);
 
 	val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio));
@@ -342,6 +335,14 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0);
 	tegra_gpio_enable(tgi, gpio);
 
+	ret = gpiochip_lock_as_irq(&tgi->gc, gpio);
+	if (ret) {
+		dev_err(tgi->dev,
+			"unable to lock Tegra GPIO %u as IRQ\n", gpio);
+		tegra_gpio_disable(tgi, gpio);
+		return ret;
+	}
+
 	if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
 		irq_set_handler_locked(d, handle_level_irq);
 	else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
-- 
2.18.0

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

* Re: [PATCH] gpio: tegra: Fix tegra_gpio_irq_set_type()
  2018-07-17 16:10 [PATCH] gpio: tegra: Fix tegra_gpio_irq_set_type() Dmitry Osipenko
@ 2018-07-19 14:41 ` Jon Hunter
  2018-07-29 20:39 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Jon Hunter @ 2018-07-19 14:41 UTC (permalink / raw)
  To: Dmitry Osipenko, Linus Walleij, Thierry Reding
  Cc: linux-tegra, linux-gpio, linux-kernel

Hi Dmitry

On 17/07/18 17:10, Dmitry Osipenko wrote:
> Commit 36b312792b97 ("gpiolib: Respect error code of ->get_direction()")
> broke tegra_gpio_irq_set_type() because requesting of GPIO direction must
> be done after enabling GPIO function for a pin.
> 
> This patch fixes drivers probe failure like this:
> 
>  gpio gpiochip0: (tegra-gpio): gpiochip_lock_as_irq: cannot get GPIO direction
>  tegra-gpio 6000d000.gpio: unable to lock Tegra GPIO 144 as IRQ
> 
> Fixes: 36b312792b97 ("gpiolib: Respect error code of ->get_direction()")
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/gpio/gpio-tegra.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 94396caaca75..22e7c99ed69e 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -323,13 +323,6 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>  		return -EINVAL;
>  	}
>  
> -	ret = gpiochip_lock_as_irq(&tgi->gc, gpio);
> -	if (ret) {
> -		dev_err(tgi->dev,
> -			"unable to lock Tegra GPIO %u as IRQ\n", gpio);
> -		return ret;
> -	}
> -
>  	spin_lock_irqsave(&bank->lvl_lock[port], flags);
>  
>  	val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio));
> @@ -342,6 +335,14 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
>  	tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0);
>  	tegra_gpio_enable(tgi, gpio);
>  
> +	ret = gpiochip_lock_as_irq(&tgi->gc, gpio);
> +	if (ret) {
> +		dev_err(tgi->dev,
> +			"unable to lock Tegra GPIO %u as IRQ\n", gpio);
> +		tegra_gpio_disable(tgi, gpio);
> +		return ret;
> +	}
> +
>  	if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
>  		irq_set_handler_locked(d, handle_level_irq);
>  	else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))

Thanks for reporting this. I am seeing this as well on Tegra20 Ventana
and Tegra30 Cardhu looking at the boot log. Given that gpiochip_lock_as_irq
is checking the direction, the above fix looks good to me. So ...

Acked-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>

Cheers
Jon

-- 
nvpublic

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

* Re: [PATCH] gpio: tegra: Fix tegra_gpio_irq_set_type()
  2018-07-17 16:10 [PATCH] gpio: tegra: Fix tegra_gpio_irq_set_type() Dmitry Osipenko
  2018-07-19 14:41 ` Jon Hunter
@ 2018-07-29 20:39 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2018-07-29 20:39 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: thierry.reding@gmail.com, Jon Hunter, linux-tegra,
	open list:GPIO SUBSYSTEM, linux-kernel@vger.kernel.org

On Tue, Jul 17, 2018 at 6:12 PM Dmitry Osipenko <digetx@gmail.com> wrote:

> Commit 36b312792b97 ("gpiolib: Respect error code of ->get_direction()")
> broke tegra_gpio_irq_set_type() because requesting of GPIO direction must
> be done after enabling GPIO function for a pin.
>
> This patch fixes drivers probe failure like this:
>
>  gpio gpiochip0: (tegra-gpio): gpiochip_lock_as_irq: cannot get GPIO direction
>  tegra-gpio 6000d000.gpio: unable to lock Tegra GPIO 144 as IRQ
>
> Fixes: 36b312792b97 ("gpiolib: Respect error code of ->get_direction()")
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

Patch applied with Jon's tags.

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-07-29 20:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-17 16:10 [PATCH] gpio: tegra: Fix tegra_gpio_irq_set_type() Dmitry Osipenko
2018-07-19 14:41 ` Jon Hunter
2018-07-29 20:39 ` 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).