From: Francesco Lavra <flavra@baylibre.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] gpio: pca953x: enable latch only on edge-triggered inputs
Date: Wed, 8 Oct 2025 12:43:09 +0200 [thread overview]
Message-ID: <20251008104309.794273-1-flavra@baylibre.com> (raw)
The latched input feature of the pca953x GPIO controller is useful
when an input is configured to trigger interrupts on rising or
falling edges, because it allows retrieving which edge type caused
a given interrupt even if the pin state changes again before the
interrupt handler has a chance to run. But for level-triggered
interrupts, reading the latched input state can cause an active
interrupt condition to be missed, e.g. if an active-low signal (for
which an IRQ_TYPE_LEVEL_LOW interrupt has been configured) triggers
an interrupt when switching to the inactive state, but then becomes
active again before the interrupt handler has a chance to run: in
this case, if the interrupt handler reads the latched input state,
it will wrongly assume that the interrupt is not pending.
Fix the above issue by enabling the latch only on edge-triggered
inputs, instead of all interrupt-enabled inputs.
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
---
drivers/gpio/gpio-pca953x.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index e80a96f39788..e87ef2c3ff82 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -761,10 +761,13 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
int level;
if (chip->driver_data & PCA_PCAL) {
+ DECLARE_BITMAP(latched_inputs, MAX_LINE);
guard(mutex)(&chip->i2c_lock);
- /* Enable latch on interrupt-enabled inputs */
- pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask);
+ /* Enable latch on edge-triggered interrupt-enabled inputs */
+ bitmap_or(latched_inputs, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio);
+ bitmap_and(latched_inputs, latched_inputs, chip->irq_mask, gc->ngpio);
+ pca953x_write_regs(chip, PCAL953X_IN_LATCH, latched_inputs);
bitmap_complement(irq_mask, chip->irq_mask, gc->ngpio);
--
2.39.5
next reply other threads:[~2025-10-08 10:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 10:43 Francesco Lavra [this message]
2025-10-09 6:03 ` [PATCH] gpio: pca953x: enable latch only on edge-triggered inputs Linus Walleij
2025-10-09 7:17 ` Martyn Welch
2025-10-09 7:44 ` Francesco Lavra
2025-10-09 10:24 ` Martyn Welch
2025-10-10 8:36 ` Ian Ray
2025-10-16 14:30 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251008104309.794273-1-flavra@baylibre.com \
--to=flavra@baylibre.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox