linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: pcf857x: Fix missing first interrupt
@ 2021-02-16 20:16 Maksim Kiselev
  2021-02-17 13:11 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Maksim Kiselev @ 2021-02-16 20:16 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Maxim Kochetkov

From: Maxim Kiselev <bigunclemax@gmail.com>
Date: Tue, 16 Feb 2021 17:00:58 +0300
Subject: [PATCH] gpio: pcf857x: Fix missing first interrupt

If no n_latch value will be provided at driver probe then all pins will
be used as an input:
gpio->out = ~n_latch;

In that case initial state for all pins is "one":
gpio->status = gpio->out;

So if pcf857x IRQ happens with change pin value from "zero" to "one"
then we miss it, because of "one" from IRQ and "one" from initial state
leaves corresponding pin unchanged:
change = (gpio->status ^ status) & gpio->irq_enabled;

The right solution will be to read actual state at driver probe.

Fixies: commit 6e20a0a429bd ("gpio: pcf857x: enable gpio_to_irq() support")
Signed-off-by: Maxim Kiselev <bigunclemax@gmail.com>
---
drivers/gpio/gpio-pcf857x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index a2a8d155c75e3..b7568ee33696d 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -332,7 +332,7 @@ static int pcf857x_probe(struct i2c_client *client,
* reset state. Otherwise it flags pins to be driven low.
*/
gpio->out = ~n_latch;
- gpio->status = gpio->out;
+ gpio->status = gpio->read(gpio->client);
/* Enable irqchip if we have an interrupt */
if (client->irq) {
--
2.27.0

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

* Re: [PATCH] gpio: pcf857x: Fix missing first interrupt
  2021-02-16 20:16 [PATCH] gpio: pcf857x: Fix missing first interrupt Maksim Kiselev
@ 2021-02-17 13:11 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2021-02-17 13:11 UTC (permalink / raw)
  To: Maksim Kiselev; +Cc: Linus Walleij, linux-gpio, Maxim Kochetkov

On Tue, Feb 16, 2021 at 9:16 PM Maksim Kiselev <bigunclemax@gmail.com> wrote:
>
> From: Maxim Kiselev <bigunclemax@gmail.com>
> Date: Tue, 16 Feb 2021 17:00:58 +0300
> Subject: [PATCH] gpio: pcf857x: Fix missing first interrupt
>
> If no n_latch value will be provided at driver probe then all pins will
> be used as an input:
> gpio->out = ~n_latch;
>
> In that case initial state for all pins is "one":
> gpio->status = gpio->out;
>
> So if pcf857x IRQ happens with change pin value from "zero" to "one"
> then we miss it, because of "one" from IRQ and "one" from initial state
> leaves corresponding pin unchanged:
> change = (gpio->status ^ status) & gpio->irq_enabled;
>
> The right solution will be to read actual state at driver probe.
>
> Fixies: commit 6e20a0a429bd ("gpio: pcf857x: enable gpio_to_irq() support")
> Signed-off-by: Maxim Kiselev <bigunclemax@gmail.com>
> ---
> drivers/gpio/gpio-pcf857x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
> index a2a8d155c75e3..b7568ee33696d 100644
> --- a/drivers/gpio/gpio-pcf857x.c
> +++ b/drivers/gpio/gpio-pcf857x.c
> @@ -332,7 +332,7 @@ static int pcf857x_probe(struct i2c_client *client,
> * reset state. Otherwise it flags pins to be driven low.
> */
> gpio->out = ~n_latch;
> - gpio->status = gpio->out;
> + gpio->status = gpio->read(gpio->client);
> /* Enable irqchip if we have an interrupt */
> if (client->irq) {
> --
> 2.27.0

Applied with the Fixes tag fixed.

Bartosz

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

end of thread, other threads:[~2021-02-17 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 20:16 [PATCH] gpio: pcf857x: Fix missing first interrupt Maksim Kiselev
2021-02-17 13:11 ` Bartosz Golaszewski

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