diff mbox series

[v2,01/17] regmap-irq: Use sub_irq_reg() to calculate unmask register address

Message ID 20220607155324.118102-2-aidanmacdonald.0x0@gmail.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series Add support for AXP192 PMIC | expand

Commit Message

Aidan MacDonald June 7, 2022, 3:53 p.m. UTC
Call sub_irq_reg() instead of calculating the offset of the register
to avoid relying on the fact that sub_irq_reg() is a linear function.
This prepares for allowing drivers to override the default sub_irq_reg
implementation if the default behavior is unsuitable.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
 drivers/base/regmap/regmap-irq.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Guru Das Srinagesh June 9, 2022, 4:39 p.m. UTC | #1
On Tue, Jun 07, 2022 at 04:53:08PM +0100, Aidan MacDonald wrote:
> Call sub_irq_reg() instead of calculating the offset of the register
> to avoid relying on the fact that sub_irq_reg() is a linear function.

Seems like unmask_reg is the only register whose address is not calculated
using sub_irq_reg(). Switching to using sub_irq_reg() will bring it in line
with the other calculations.

Could you please incorporate this info in your commit message as well? This
should be the rationale for this change; that it allows for the get_irq_reg()
patch should be secondary.

The change seems okay to me, but I'd ideally like someone to pick this up and
test it out just to make sure it doesn't break existing behaviour for them.

Thank you.

Guru Das.
Aidan MacDonald June 11, 2022, 2:32 p.m. UTC | #2
Guru Das Srinagesh <quic_gurus@quicinc.com> writes:

> On Tue, Jun 07, 2022 at 04:53:08PM +0100, Aidan MacDonald wrote:
>> Call sub_irq_reg() instead of calculating the offset of the register
>> to avoid relying on the fact that sub_irq_reg() is a linear function.
>
> Seems like unmask_reg is the only register whose address is not calculated
> using sub_irq_reg(). Switching to using sub_irq_reg() will bring it in line
> with the other calculations.
>
> Could you please incorporate this info in your commit message as well? This
> should be the rationale for this change; that it allows for the get_irq_reg()
> patch should be secondary.

I'll note that in v3, thanks.

>
> The change seems okay to me, but I'd ideally like someone to pick this up and
> test it out just to make sure it doesn't break existing behaviour for them.
>
> Thank you.
>
> Guru Das.
diff mbox series

Patch

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 400c7412a7dc..4a2e1f6aa94d 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -97,7 +97,6 @@  static void regmap_irq_sync_unlock(struct irq_data *data)
 	struct regmap *map = d->map;
 	int i, j, ret;
 	u32 reg;
-	u32 unmask_offset;
 	u32 val;
 
 	if (d->chip->runtime_pm) {
@@ -141,11 +140,11 @@  static void regmap_irq_sync_unlock(struct irq_data *data)
 				dev_err(d->map->dev,
 					"Failed to sync unmasks in %x\n",
 					reg);
-			unmask_offset = d->chip->unmask_base -
-							d->chip->mask_base;
+
 			/* clear mask with unmask_base register */
+			reg = sub_irq_reg(d, d->chip->unmask_base, i);
 			ret = regmap_irq_update_bits(d,
-					reg + unmask_offset,
+					reg,
 					d->mask_buf_def[i],
 					d->mask_buf[i]);
 		} else {
@@ -632,7 +631,6 @@  int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
 	int ret = -ENOMEM;
 	int num_type_reg;
 	u32 reg;
-	u32 unmask_offset;
 
 	if (chip->num_regs <= 0)
 		return -EINVAL;
@@ -773,10 +771,9 @@  int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
 			ret = regmap_irq_update_bits(d, reg,
 					 d->mask_buf[i], ~d->mask_buf[i]);
 		else if (d->chip->unmask_base) {
-			unmask_offset = d->chip->unmask_base -
-					d->chip->mask_base;
+			reg = sub_irq_reg(d, d->chip->unmask_base, i);
 			ret = regmap_irq_update_bits(d,
-					reg + unmask_offset,
+					reg,
 					d->mask_buf[i],
 					d->mask_buf[i]);
 		} else