Linux-GPIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] gpio: sprd: Clear interrupt when setting the type as edge
@ 2020-07-29  9:34 Chunyan Zhang
  2020-07-31 23:58 ` Baolin Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Chunyan Zhang @ 2020-07-29  9:34 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Chunyan Zhang, Taiping Lai

From: Taiping Lai <taiping.lai@unisoc.com>

The raw interrupt status of GPIO maybe set before the interrupt is enabled,
which would trigger the interrupt event once enabled it from user side.
This is the case for edge interrupts only. Adding a clear operation when
setting interrupt type can avoid that.

Fixes: 9a3821c2bb47 ("gpio: Add GPIO driver for Spreadtrum SC9860 platform")
Signed-off-by: Taiping Lai <taiping.lai@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
 drivers/gpio/gpio-sprd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c
index d7314d39ab65..36ea8a3bd451 100644
--- a/drivers/gpio/gpio-sprd.c
+++ b/drivers/gpio/gpio-sprd.c
@@ -149,17 +149,20 @@ static int sprd_gpio_irq_set_type(struct irq_data *data,
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0);
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 1);
+		sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
 		irq_set_handler_locked(data, handle_edge_irq);
 		break;
 	case IRQ_TYPE_EDGE_FALLING:
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0);
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 0);
+		sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
 		irq_set_handler_locked(data, handle_edge_irq);
 		break;
 	case IRQ_TYPE_EDGE_BOTH:
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
 		sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 1);
+		sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
 		irq_set_handler_locked(data, handle_edge_irq);
 		break;
 	case IRQ_TYPE_LEVEL_HIGH:
-- 
2.20.1


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

* Re: [PATCH] gpio: sprd: Clear interrupt when setting the type as edge
  2020-07-29  9:34 [PATCH] gpio: sprd: Clear interrupt when setting the type as edge Chunyan Zhang
@ 2020-07-31 23:58 ` Baolin Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Baolin Wang @ 2020-07-31 23:58 UTC (permalink / raw)
  To: Chunyan Zhang
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, LKML, Orson Zhai,
	Chunyan Zhang, Taiping Lai

On Wed, Jul 29, 2020 at 5:35 PM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> From: Taiping Lai <taiping.lai@unisoc.com>
>
> The raw interrupt status of GPIO maybe set before the interrupt is enabled,
> which would trigger the interrupt event once enabled it from user side.
> This is the case for edge interrupts only. Adding a clear operation when
> setting interrupt type can avoid that.
>
> Fixes: 9a3821c2bb47 ("gpio: Add GPIO driver for Spreadtrum SC9860 platform")
> Signed-off-by: Taiping Lai <taiping.lai@unisoc.com>
> Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
> ---
>  drivers/gpio/gpio-sprd.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c
> index d7314d39ab65..36ea8a3bd451 100644
> --- a/drivers/gpio/gpio-sprd.c
> +++ b/drivers/gpio/gpio-sprd.c
> @@ -149,17 +149,20 @@ static int sprd_gpio_irq_set_type(struct irq_data *data,
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0);
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 1);
> +               sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);

I think you should move this abonormal interrupt clearing operation to
sprd_gpio_request(), when users request a GPIO.

>                 irq_set_handler_locked(data, handle_edge_irq);
>                 break;
>         case IRQ_TYPE_EDGE_FALLING:
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0);
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 0);
> +               sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
>                 irq_set_handler_locked(data, handle_edge_irq);
>                 break;
>         case IRQ_TYPE_EDGE_BOTH:
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
>                 sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 1);
> +               sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
>                 irq_set_handler_locked(data, handle_edge_irq);
>                 break;
>         case IRQ_TYPE_LEVEL_HIGH:
> --
> 2.20.1
>


-- 
Baolin Wang

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29  9:34 [PATCH] gpio: sprd: Clear interrupt when setting the type as edge Chunyan Zhang
2020-07-31 23:58 ` Baolin Wang

Linux-GPIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \
		linux-gpio@vger.kernel.org
	public-inbox-index linux-gpio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-gpio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git