mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Miguel Gazquez (Schneider Electric)" <miguel.gazquez@bootlin.com>
To: stable@vger.kernel.org, Hoan Tran <hoan@os.amperecomputing.com>,
	 Serge Semin <fancer.lancer@gmail.com>,
	 Linus Walleij <linus.walleij@linaro.org>,
	 Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	 Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	 Alan Tull <atull@altera.com>, Jamie Iles <jamie@jamieiles.com>
Cc: Benjamin Robin <benjamin.robin@bootlin.com>,
	 Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	linux-gpio@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Ralph Siemsen <ralph.siemsen@linaro.org>,
	 xiongxin <xiongxin@kylinos.cn>,
	stable@kernel.org,  Riwen Lu <luriwen@kylinos.cn>,
	Andy Shevchenko <andy@kernel.org>,
	 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 "Miguel Gazquez (Schneider Electric)"
	<miguel.gazquez@bootlin.com>
Subject: [PATCH 5.10.y v2] gpio: dwapb: mask/unmask IRQ when disable/enale it
Date: Tue, 03 Nov 2026 12:10:57 +0100	[thread overview]
Message-ID: <20261103-dwapb-fix-v2-1-9bd3785d1365@bootlin.com> (raw)

From: xiongxin <xiongxin@kylinos.cn>

commit 1cc3542c76acb5f59001e3e562eba672f1983355 upstream.

In the hardware implementation of the I2C HID driver based on DesignWare
GPIO IRQ chip, when the user continues to use the I2C HID device in the
suspend process, the I2C HID interrupt will be masked after the resume
process is finished.

This is because the disable_irq()/enable_irq() of the DesignWare GPIO
driver does not synchronize the IRQ mask register state. In normal use
of the I2C HID procedure, the GPIO IRQ irq_mask()/irq_unmask() functions
are called in pairs. In case of an exception, i2c_hid_core_suspend()
calls disable_irq() to disable the GPIO IRQ. With low probability, this
causes irq_unmask() to not be called, which causes the GPIO IRQ to be
masked and not unmasked in enable_irq(), raising an exception.

Add synchronization to the masked register state in the
dwapb_irq_enable()/dwapb_irq_disable() function. mask the GPIO IRQ
before disabling it. After enabling the GPIO IRQ, unmask the IRQ.

Fixes: 7779b3455697 ("gpio: add a driver for the Synopsys DesignWare APB GPIO block")
Cc: stable@kernel.org
Co-developed-by: Riwen Lu <luriwen@kylinos.cn>
Signed-off-by: Riwen Lu <luriwen@kylinos.cn>
Signed-off-by: xiongxin <xiongxin@kylinos.cn>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Miguel Gazquez (Schneider Electric) <miguel.gazquez@bootlin.com>
---
Changes in v2:
- Fix typo
- Link to v1: https://patch.msgid.link/20261103-dwapb-fix-v1-1-c93ef2f20695@bootlin.com
---
 drivers/gpio/gpio-dwapb.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index d6240ae0f87ca..51bed3adafc1f 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -282,13 +282,15 @@ static void dwapb_irq_enable(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 	unsigned long flags;
 	u32 val;
 
 	spin_lock_irqsave(&gc->bgpio_lock, flags);
-	val = dwapb_read(gpio, GPIO_INTEN);
-	val |= BIT(irqd_to_hwirq(d));
+	val = dwapb_read(gpio, GPIO_INTEN) | BIT(hwirq);
 	dwapb_write(gpio, GPIO_INTEN, val);
+	val = dwapb_read(gpio, GPIO_INTMASK) & ~BIT(hwirq);
+	dwapb_write(gpio, GPIO_INTMASK, val);
 	spin_unlock_irqrestore(&gc->bgpio_lock, flags);
 }
 
@@ -296,12 +298,14 @@ static void dwapb_irq_disable(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 	unsigned long flags;
 	u32 val;
 
 	spin_lock_irqsave(&gc->bgpio_lock, flags);
-	val = dwapb_read(gpio, GPIO_INTEN);
-	val &= ~BIT(irqd_to_hwirq(d));
+	val = dwapb_read(gpio, GPIO_INTMASK) | BIT(hwirq);
+	dwapb_write(gpio, GPIO_INTMASK, val);
+	val = dwapb_read(gpio, GPIO_INTEN) & ~BIT(hwirq);
 	dwapb_write(gpio, GPIO_INTEN, val);
 	spin_unlock_irqrestore(&gc->bgpio_lock, flags);
 }

---
base-commit: f23b568f7597f98a241454018a34361ce2523c05
change-id: 20261103-dwapb-fix-ab5776557f6c

Best regards,
--  
Miguel Gazquez (Schneider Electric) <miguel.gazquez@bootlin.com>


             reply	other threads:[~2026-11-03 11:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 11:10 Miguel Gazquez (Schneider Electric) [this message]
2026-11-03 14:52 ` Sasha Levin

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=20261103-dwapb-fix-v2-1-9bd3785d1365@bootlin.com \
    --to=miguel.gazquez@bootlin.com \
    --cc=andy@kernel.org \
    --cc=atull@altera.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=benjamin.robin@bootlin.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=fancer.lancer@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hoan@os.amperecomputing.com \
    --cc=jamie@jamieiles.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luriwen@kylinos.cn \
    --cc=ralph.siemsen@linaro.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=stable@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=xiongxin@kylinos.cn \
    /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

all inboxes | Powered by JetHome®