]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pinctrl: ocelot: Fix incorrect trigger of the interrupt.
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Tue, 18 Oct 2022 07:09:59 +0000 (09:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Nov 2022 15:00:28 +0000 (00:00 +0900)
[ Upstream commit e9945b2633deccda74a769d94060df49c53ff181 ]

The interrupt controller can detect only link changes. So in case an
external device generated a level based interrupt, then the interrupt
controller detected correctly the first edge. But the problem was that
the interrupt controller was detecting also the edge when the interrupt
was cleared. So it would generate another interrupt.
The fix for this is to clear the second interrupt but still check the
interrupt line status.

Fixes: c297561bc98a ("pinctrl: ocelot: Fix interrupt controller")
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Tested-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20221018070959.1322606-1-horatiu.vultur@microchip.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pinctrl/pinctrl-ocelot.c

index c7df8c5fe5854462d1585782c3d0f72b7a02f5dd..105771ff82e6294f30dcaa3c76579ee13b927fc4 100644 (file)
@@ -1863,19 +1863,28 @@ static void ocelot_irq_unmask_level(struct irq_data *data)
        if (val & bit)
                ack = true;
 
+       /* Try to clear any rising edges */
+       if (!active && ack)
+               regmap_write_bits(info->map, REG(OCELOT_GPIO_INTR, info, gpio),
+                                 bit, bit);
+
        /* Enable the interrupt now */
        gpiochip_enable_irq(chip, gpio);
        regmap_update_bits(info->map, REG(OCELOT_GPIO_INTR_ENA, info, gpio),
                           bit, bit);
 
        /*
-        * In case the interrupt line is still active and the interrupt
-        * controller has not seen any changes in the interrupt line, then it
-        * means that there happen another interrupt while the line was active.
+        * In case the interrupt line is still active then it means that
+        * there happen another interrupt while the line was active.
         * So we missed that one, so we need to kick the interrupt again
         * handler.
         */
-       if (active && !ack) {
+       regmap_read(info->map, REG(OCELOT_GPIO_IN, info, gpio), &val);
+       if ((!(val & bit) && trigger_level == IRQ_TYPE_LEVEL_LOW) ||
+             (val & bit && trigger_level == IRQ_TYPE_LEVEL_HIGH))
+               active = true;
+
+       if (active) {
                struct ocelot_irq_work *work;
 
                work = kmalloc(sizeof(*work), GFP_ATOMIC);