All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] regmap-irq: Introduce inverted status registers support
@ 2021-05-18  9:44 Maxim Kochetkov
  2021-05-18 12:06 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Kochetkov @ 2021-05-18  9:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: broonie, gregkh, rafael, Maxim Kochetkov

Some interrupt controllers have inverted status register:
cleared bits is active interrupts and set bits is inactive interrupts,
so add inverted status support to the framework.

Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
---
 drivers/base/regmap/regmap-irq.c | 4 ++++
 include/linux/regmap.h           | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 760296a4b606..fbab3ff7b877 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -531,6 +531,10 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 		}
 	}
 
+	if (chip->status_invert)
+		for (i = 0; i < data->chip->num_regs; i++)
+			data->status_buf[i] = ~data->status_buf[i];
+
 	/*
 	 * Ignore masked IRQs and ack if we need to; we ack early so
 	 * there is no race between handling and acknowleding the
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 8c16e6fa0f66..c5b7c9c600a5 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1413,6 +1413,7 @@ struct regmap_irq_sub_irq_map {
  * @not_fixed_stride: Used when chip peripherals are not laid out with fixed
  * 		      stride. Must be used with sub_reg_offsets containing the
  * 		      offsets to each peripheral.
+ * @status_invert: Inverted status register: cleared bits are active interrupts.
  * @runtime_pm:  Hold a runtime PM lock on the device when accessing it.
  *
  * @num_regs:    Number of registers in each control bank.
@@ -1465,6 +1466,7 @@ struct regmap_irq_chip {
 	bool type_in_mask:1;
 	bool clear_on_unmask:1;
 	bool not_fixed_stride:1;
+	bool status_invert:1;
 
 	int num_regs;
 
-- 
2.31.1


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

* Re: [PATCH 1/1] regmap-irq: Introduce inverted status registers support
  2021-05-18  9:44 [PATCH 1/1] regmap-irq: Introduce inverted status registers support Maxim Kochetkov
@ 2021-05-18 12:06 ` Mark Brown
  2021-05-24  4:53   ` Maxim Kochetkov
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2021-05-18 12:06 UTC (permalink / raw)
  To: Maxim Kochetkov; +Cc: linux-kernel, gregkh, rafael

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

On Tue, May 18, 2021 at 12:44:41PM +0300, Maxim Kochetkov wrote:

> +	if (chip->status_invert)
> +		for (i = 0; i < data->chip->num_regs; i++)
> +			data->status_buf[i] = ~data->status_buf[i];
> +

This is the only active change so this only affects readback meaning
that if both read and write are inverted this won't do what's expected,
breaking acks.  I'm guessing your device either mixes things or is clear
on read?

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

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

* Re: [PATCH 1/1] regmap-irq: Introduce inverted status registers support
  2021-05-18 12:06 ` Mark Brown
@ 2021-05-24  4:53   ` Maxim Kochetkov
  0 siblings, 0 replies; 3+ messages in thread
From: Maxim Kochetkov @ 2021-05-24  4:53 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, gregkh, rafael

18.05.2021 15:06, Mark Brown wrote:
> On Tue, May 18, 2021 at 12:44:41PM +0300, Maxim Kochetkov wrote:
> 
>> +	if (chip->status_invert)
>> +		for (i = 0; i < data->chip->num_regs; i++)
>> +			data->status_buf[i] = ~data->status_buf[i];
>> +
> 
> This is the only active change so this only affects readback meaning
> that if both read and write are inverted this won't do what's expected,
> breaking acks.

I mean 'status_invert' as just status register has inverted bits. So to 
keep all other logic we just need to invert status register after read. 
It will not break acks because we can use ack_invert option to invert 
status back if needed. Anyway it will not affect existing devices just 
new ones with inverted status.

> I'm guessing your device either mixes things or is clear on read?

Yes my device is clear on read. It don`t use ack registers. It has only 
mask and status.


I missed read status register at regmap_add_irq_chip_fwnode(). I will 
send v2.


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

end of thread, other threads:[~2021-05-24  5:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18  9:44 [PATCH 1/1] regmap-irq: Introduce inverted status registers support Maxim Kochetkov
2021-05-18 12:06 ` Mark Brown
2021-05-24  4:53   ` Maxim Kochetkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.