public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] regmap: irq: fix ack-invert
@ 2018-03-05 20:57 Tim Harvey
  2018-03-06 14:57 ` Tony Lindgren
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Harvey @ 2018-03-05 20:57 UTC (permalink / raw)
  To: linux-kernel, Mark Brown, Benjamin Gaignard, Lee Jones,
	Tony Lindgren
  Cc: Guo Zeng

When acking irqs we need to take into account the ack-invert case.
Without this chips that require 0's to ACK interrupts will never clear
the interrupt.

By using regmap_irq_update_bits to ACK the interrupts we use the masked
status bits so we take care not to affect any other bits then use
ack_invert to determine if we clear or set those bits.

The only user of ack_invert currently appears to be the motorola-cpcap
driver which we find is incorrectly setting ack_invert and thus we
fix that at the same time as otherwise it would break.

Cc: Guo Zeng <Guo.Zeng@csr.com>
Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
v2:
 - use regmap_irq_update_bits for readability as well as taking into account
   only affecting bits we are acking
 - add fix for affected motorola-cpcap driver
---
 drivers/base/regmap/regmap-irq.c | 5 ++++-
 drivers/mfd/motorola-cpcap.c     | 3 ---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 429ca8e..840cadee 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -360,7 +360,10 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 		if (data->status_buf[i] && (chip->ack_base || chip->use_ack)) {
 			reg = chip->ack_base +
 				(i * map->reg_stride * data->irq_reg_stride);
-			ret = regmap_write(map, reg, data->status_buf[i]);
+			ret = regmap_irq_update_bits(d, reg,
+						     data->status_buf[i],
+						     chip->ack_invert ?
+						     0x00 : 0xFF);
 			if (ret != 0)
 				dev_err(map->dev, "Failed to ack 0x%x: %d\n",
 					reg, ret);
diff --git a/drivers/mfd/motorola-cpcap.c b/drivers/mfd/motorola-cpcap.c
index d2cc1ea..59082cf 100644
--- a/drivers/mfd/motorola-cpcap.c
+++ b/drivers/mfd/motorola-cpcap.c
@@ -99,7 +99,6 @@ static struct regmap_irq_chip cpcap_irq_chip[CPCAP_NR_IRQ_CHIPS] = {
 		.ack_base = CPCAP_REG_MI1,
 		.mask_base = CPCAP_REG_MIM1,
 		.use_ack = true,
-		.ack_invert = true,
 	},
 	{
 		.name = "cpcap-m2",
@@ -108,7 +107,6 @@ static struct regmap_irq_chip cpcap_irq_chip[CPCAP_NR_IRQ_CHIPS] = {
 		.ack_base = CPCAP_REG_MI2,
 		.mask_base = CPCAP_REG_MIM2,
 		.use_ack = true,
-		.ack_invert = true,
 	},
 	{
 		.name = "cpcap1-4",
@@ -117,7 +115,6 @@ static struct regmap_irq_chip cpcap_irq_chip[CPCAP_NR_IRQ_CHIPS] = {
 		.ack_base = CPCAP_REG_INT1,
 		.mask_base = CPCAP_REG_INTM1,
 		.use_ack = true,
-		.ack_invert = true,
 	},
 };
 
-- 
2.7.4

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

* Re: [PATCH v2] regmap: irq: fix ack-invert
  2018-03-05 20:57 [PATCH v2] regmap: irq: fix ack-invert Tim Harvey
@ 2018-03-06 14:57 ` Tony Lindgren
  2018-03-07 14:36   ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Tony Lindgren @ 2018-03-06 14:57 UTC (permalink / raw)
  To: Tim Harvey
  Cc: linux-kernel, Mark Brown, Benjamin Gaignard, Lee Jones, Guo Zeng

Hi,

* Tim Harvey <tharvey@gateworks.com> [180305 20:59]:
> When acking irqs we need to take into account the ack-invert case.
> Without this chips that require 0's to ACK interrupts will never clear
> the interrupt.
> 
> By using regmap_irq_update_bits to ACK the interrupts we use the masked
> status bits so we take care not to affect any other bits then use
> ack_invert to determine if we clear or set those bits.

This change to use regmap_irq_update_bits() now breaks things for
me with cpcap interrupts. So it seems to cause a non-inverted mode
regression. There should be no need to read the ack register, I
gues that's the whole idea of having a separate ack register :)

> The only user of ack_invert currently appears to be the motorola-cpcap
> driver which we find is incorrectly setting ack_invert and thus we
> fix that at the same time as otherwise it would break.

Regards,

Tony

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

* Re: [PATCH v2] regmap: irq: fix ack-invert
  2018-03-06 14:57 ` Tony Lindgren
@ 2018-03-07 14:36   ` Mark Brown
  2018-03-09 18:51     ` Tim Harvey
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2018-03-07 14:36 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Tim Harvey, linux-kernel, Benjamin Gaignard, Lee Jones, Guo Zeng

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

On Tue, Mar 06, 2018 at 06:57:49AM -0800, Tony Lindgren wrote:

> > By using regmap_irq_update_bits to ACK the interrupts we use the masked
> > status bits so we take care not to affect any other bits then use
> > ack_invert to determine if we clear or set those bits.

> This change to use regmap_irq_update_bits() now breaks things for
> me with cpcap interrupts. So it seems to cause a non-inverted mode
> regression. There should be no need to read the ack register, I
> gues that's the whole idea of having a separate ack register :)

Yes, that'd be my expectation as well - the register should be just
write only.  regmap_update_bits() definitely isn't the right thing here
since it will suppress the write part of the read/modify/write cycle if
it detects that it didn't actually modify anything as an optimization.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2] regmap: irq: fix ack-invert
  2018-03-07 14:36   ` Mark Brown
@ 2018-03-09 18:51     ` Tim Harvey
  0 siblings, 0 replies; 4+ messages in thread
From: Tim Harvey @ 2018-03-09 18:51 UTC (permalink / raw)
  To: Mark Brown
  Cc: Tony Lindgren, linux-kernel, Benjamin Gaignard, Lee Jones,
	Guo Zeng

On Wed, Mar 7, 2018 at 6:36 AM, Mark Brown <broonie@kernel.org> wrote:
> On Tue, Mar 06, 2018 at 06:57:49AM -0800, Tony Lindgren wrote:
>
>> > By using regmap_irq_update_bits to ACK the interrupts we use the masked
>> > status bits so we take care not to affect any other bits then use
>> > ack_invert to determine if we clear or set those bits.
>
>> This change to use regmap_irq_update_bits() now breaks things for
>> me with cpcap interrupts. So it seems to cause a non-inverted mode
>> regression. There should be no need to read the ack register, I
>> gues that's the whole idea of having a separate ack register :)
>
> Yes, that'd be my expectation as well - the register should be just
> write only.  regmap_update_bits() definitely isn't the right thing here
> since it will suppress the write part of the read/modify/write cycle if
> it detects that it didn't actually modify anything as an optimization.

understood. I will put together a v3 soon.

Thanks,

Tim

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

end of thread, other threads:[~2018-03-09 18:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-05 20:57 [PATCH v2] regmap: irq: fix ack-invert Tim Harvey
2018-03-06 14:57 ` Tony Lindgren
2018-03-07 14:36   ` Mark Brown
2018-03-09 18:51     ` Tim Harvey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox