Skip to contentSkip to conversation

regmap: regmap-irq: Make irq-type callbak optional

PATCH In review Matti Vaittinen 2 participants 4 messages Jan 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: regmap-irq: Make irq-type callbak optional

Do not register type setting callback if HW does not support setting the irq type. IRQ core can then handle cases where type setting is not supported and no regmap-irq specific handling is required.

---
 drivers/base/regmap/regmap-irq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/regmap/regmap-irq.c +3 -1
index d2d0014b0d23..a387ee499b5c 100644
@@ -322,7 +322,6 @@ static const struct irq_chip regmap_irq_chip = {
 	.irq_bus_sync_unlock	= regmap_irq_sync_unlock,
 	.irq_disable		= regmap_irq_disable,
 	.irq_enable		= regmap_irq_enable,
-	.irq_set_type		= regmap_irq_set_type,
 	.irq_set_wake		= regmap_irq_set_wake,
 };
 
@@ -560,6 +559,9 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 	d->chip = chip;
 	d->irq_base = irq_base;
 
+	if (num_type_reg)
+		d->irq_chip.irq_set_type = regmap_irq_set_type;
+
 	if (chip->irq_reg_stride)
 		d->irq_reg_stride = chip->irq_reg_stride;
 	else
Signature · 8 lines
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~
#1 lore raw
Quoted 23 lines · Matti Vaittinen

Do not register type setting callback if HW does not support setting the irq type. IRQ core can then handle cases where type setting is not supported and no regmap-irq specific handling is required.

---
 drivers/base/regmap/regmap-irq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/regmap/regmap-irq.c +0 -1
index d2d0014b0d23..a387ee499b5c 100644
@@ -322,7 +322,6 @@ static const struct irq_chip regmap_irq_chip = {
 	.irq_bus_sync_unlock	= regmap_irq_sync_unlock,
 	.irq_disable		= regmap_irq_disable,
 	.irq_enable		= regmap_irq_enable,
-	.irq_set_type		= regmap_irq_set_type,
 	.irq_set_wake		= regmap_irq_set_wake,
 };
 

drivers/base/regmap/regmap-irq.c int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, · line 567

Quoted 9 lines
drivers/base/regmap/regmap-irq.c +3 -0
@@ -560,6 +559,9 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 	d->chip = chip;
 	d->irq_base = irq_base;
 
+	if (num_type_reg)
+		d->irq_chip.irq_set_type = regmap_irq_set_type;
+
 	if (chip->irq_reg_stride)
 		d->irq_reg_stride = chip->irq_reg_stride;
 	else

Afraid this also causes regressions at my end, still having a bit of a look but it looks like some how this prevents properties of the IRQ getting passed along which causes my system to not probe properly with:

genirq: Flags mismatch irq 58. 00002088 (cs35l35) vs. 00002088 (cs35l35) cs35l35 0-0041: Failed to request IRQ: -16

Thanks,
Charles

Quoted 9 lines
Signature · 8 lines
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~
#2 lore raw
Quoted 10 lines · Charles Keepax

drivers/base/regmap/regmap-irq.c int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, · line 564

Quoted 3 lines · Matti Vaittinen
drivers/base/regmap/regmap-irq.c +3 -0
+	if (num_type_reg)
+		d->irq_chip.irq_set_type = regmap_irq_set_type;
+

Afraid this also causes regressions at my end, still having a bit of a look but it looks like some how this prevents properties of the IRQ getting passed along which causes my system to not probe properly with:

Quoted 3 lines

genirq: Flags mismatch irq 58. 00002088 (cs35l35) vs. 00002088 (cs35l35) cs35l35 0-0041: Failed to request IRQ: -16

My case is a shared IRQ with 2 amps (cs35l35) connected to a CODEC (wm8280).

So looks like the issue is if you don't have a set_type callback then the IRQ ends up as IRQF_TRIGGER_NONE, which causes the second IRQ to fail the middle check here in __setup_irq:

		if (!((old->flags & new->flags) & IRQF_SHARED) ||
		    (oldtype != (new->flags & IRQF_TRIGGER_MASK)) ||
		    ((old->flags ^ new->flags) & IRQF_ONESHOT)) {

Kinda inclined to just leave the fix as currently submitted and just drop this patch? But I can do more testing etc. if we want to push further down this road.

Thanks,
Charles

#3 lore raw

Big thanks for testing this so early Charles =) It's nice to get this report before I broke things more widely!

Quoted 18 lines · Charles Keepax
Quoted 10 lines · Charles Keepax

drivers/base/regmap/regmap-irq.c int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, · line 564

Quoted 3 lines · Matti Vaittinen
drivers/base/regmap/regmap-irq.c +3 -0
+	if (num_type_reg)
+		d->irq_chip.irq_set_type = regmap_irq_set_type;
+

Afraid this also causes regressions at my end, still having a bit of a look but it looks like some how this prevents properties of the IRQ getting passed along which causes my system to not probe properly with:

Quoted 3 lines

genirq: Flags mismatch irq 58. 00002088 (cs35l35) vs. 00002088 (cs35l35) cs35l35 0-0041: Failed to request IRQ: -16

My case is a shared IRQ with 2 amps (cs35l35) connected to a CODEC (wm8280).

Quoted 7 lines

So looks like the issue is if you don't have a set_type callback then the IRQ ends up as IRQF_TRIGGER_NONE, which causes the second IRQ to fail the middle check here in __setup_irq:

		if (!((old->flags & new->flags) & IRQF_SHARED) ||
		    (oldtype != (new->flags & IRQF_TRIGGER_MASK)) ||
		    ((old->flags ^ new->flags) & IRQF_ONESHOT)) {

Right. Thanks for pinpointing the issue. This thing is a bit fishy. There should not be a need for a 'fake type setting callback' when we have shared IRQ with two or more devices who actually agree on IRQ type
- assuming the HW default irq type is correct.

For me the correct thing would that the HW default type should be stored in desc and returned by irqd_get_trigger_type instead of IRQF_TRIGGER_NONE. But I have no idea how that would be nicely implemented w/o going trough all the irqchips.

The other option would be being more permissive when IRQF_TRIGGER_NONE is set as oldtype. But I am not feeling like an expert on this area.

Quoted 3 lines

Kinda inclined to just leave the fix as currently submitted and just drop this patch? But I can do more testing etc. if we want to push further down this road.

Huge thanks for the offer Charles - I do really appreciate the testing. Touching the IRQ core sounds quite scary to me. Changing it feels risky and would probably involve bunch of other people too. 10-years ago I would have taken the challenge and tried to get this "correct" - but nowadays I have learned to accept some small shortcuts :p

I will gladly follow things and participate the discussions/development if someone wants to see how this should be done - but I don't think I have the energy and time to drive this change further... So Mark, please just drop this patch and keep the original fix unless you want to drive this further yourself =)

Br,
Matti Vaittinen

Quoted 3 lines

Thanks,
Charles

Signature · 4 lines
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~