1 From dcb717bc899cd55a969fb4f1f8526f313efe148c Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Fri, 5 May 2023 11:25:48 +0100
4 Subject: [PATCH] pinctrl: bcm2835: Workaround for edge IRQ loss
6 It has been observed that edge events can be lost when GPIO edges occur
7 close to each other. Investigation suggests this is due to a hardware
8 bug, although no mechanism has been identified.
10 Work around the event loss by moving the IRQ acknowledgement into the
11 main ISR, adding missing events by explicit level-change detection.
13 See: https://forums.raspberrypi.com/viewtopic.php?t=350295
15 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
17 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 23 ++++++++++++++++++-----
18 1 file changed, 18 insertions(+), 5 deletions(-)
20 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
21 +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
22 @@ -422,15 +422,32 @@ static void bcm2835_gpio_irq_handle_bank
28 events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4);
29 + levs = bcm2835_gpio_rd(pc, GPLEV0 + bank * 4);
31 events &= pc->enabled_irq_map[bank];
32 + bcm2835_gpio_wr(pc, GPEDS0 + bank * 4, events);
35 for_each_set_bit(offset, &events, 32) {
36 gpio = (32 * bank) + offset;
37 generic_handle_domain_irq(pc->gpio_chip.irq.domain,
40 + events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4);
41 + levs2 = bcm2835_gpio_rd(pc, GPLEV0 + bank * 4);
43 + events |= levs2 & ~levs & bcm2835_gpio_rd(pc, GPREN0 + bank * 4);
44 + events |= ~levs2 & levs & bcm2835_gpio_rd(pc, GPFEN0 + bank * 4);
46 + events &= pc->enabled_irq_map[bank];
48 + bcm2835_gpio_wr(pc, GPEDS0 + bank * 4, events);
54 static void bcm2835_gpio_irq_handler(struct irq_desc *desc)
55 @@ -670,11 +687,7 @@ static int bcm2835_gpio_irq_set_type(str
57 static void bcm2835_gpio_irq_ack(struct irq_data *data)
59 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
60 - struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
61 - unsigned gpio = irqd_to_hwirq(data);
63 - bcm2835_gpio_set_bit(pc, GPEDS0, gpio);
64 + /* Nothing to do - the main interrupt handler includes the ACK */
67 static int bcm2835_gpio_irq_set_wake(struct irq_data *data, unsigned int on)