mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: Mark Brown <broonie@kernel.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	Laxminath Kasam <lkasam@codeaurora.org>,
	Tony Lindgren <tony@atomide.com>,
	Lee Jones <lee.jones@linaro.org>
Cc: Tim Harvey <tharvey@gateworks.com>, Robert Jones <rjones@gateworks.com>
Subject: [PATCH] regmap: irq: do not allow setting irq bits during ack
Date: Mon, 28 Dec 2020 13:45:51 -0800	[thread overview]
Message-ID: <1609191951-15590-1-git-send-email-tharvey@gateworks.com> (raw)

Some interrupt controllers may not de-assert their interrupt if
bits are set when acknowledging the bits that caused the interrupt.

Take care to not apply the mask to the status until we are done
acknowledging the interrupt and take care to mask the bits according
for the ack_invert state.

This is needed to avoid a stuck interrupt case for the Gateworks
System Controller which uses ack_invert. If the status has the mask
applied before clearing the bits it will end up setting bits that
are enabled but were not the cause the interrupt which will keep
the GSC from ever de-asserting its interrupt.

Cc: Tony Lindgren <tony@atomide.com>
Cc: Laxminath Kasam <lkasam@codeaurora.org>
Cc: Robert Jones <rjones@gateworks.com>
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 drivers/base/regmap/regmap-irq.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index ad5c2de..560c641 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -496,29 +496,29 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 	 * doing a write per register.
 	 */
 	for (i = 0; i < data->chip->num_regs; i++) {
-		data->status_buf[i] &= ~data->mask_buf[i];
-
-		if (data->status_buf[i] && (chip->ack_base || chip->use_ack)) {
+		if ((data->status_buf[i] && ~data->mask_buf[i]) &&
+		    (chip->ack_base || chip->use_ack)) {
 			reg = chip->ack_base +
 				(i * map->reg_stride * data->irq_reg_stride);
 			if (chip->ack_invert)
 				ret = regmap_write(map, reg,
-						~data->status_buf[i]);
+						~data->status_buf[i] & data->mask_buf[i]);
 			else
 				ret = regmap_write(map, reg,
-						data->status_buf[i]);
+						data->status_buf[i] & ~data->mask_buf[i]);
 			if (chip->clear_ack) {
 				if (chip->ack_invert && !ret)
 					ret = regmap_write(map, reg,
-							data->status_buf[i]);
+							data->status_buf[i] & ~data->mask_buf[i]);
 				else if (!ret)
 					ret = regmap_write(map, reg,
-							~data->status_buf[i]);
+							~data->status_buf[i] & data->mask_buf[i]);
 			}
 			if (ret != 0)
 				dev_err(map->dev, "Failed to ack 0x%x: %d\n",
 					reg, ret);
 		}
+		data->status_buf[i] &= ~data->mask_buf[i];
 	}
 
 	for (i = 0; i < chip->num_irqs; i++) {
-- 
2.7.4


             reply	other threads:[~2020-12-28 23:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28 21:45 Tim Harvey [this message]
2020-12-29 13:06 ` Mark Brown
2020-12-29 16:23   ` Tim Harvey
2020-12-30 13:14     ` Mark Brown
2020-12-30 16:37       ` Tim Harvey
2020-12-31 13:30         ` Mark Brown

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=1609191951-15590-1-git-send-email-tharvey@gateworks.com \
    --to=tharvey@gateworks.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkasam@codeaurora.org \
    --cc=rafael@kernel.org \
    --cc=rjones@gateworks.com \
    --cc=tony@atomide.com \
    /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®