1 From 6f92d02f7af5a9b5ed5ded7dbeb18bf2bbb2ad85 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Tue, 24 Feb 2015 13:40:50 +0000
4 Subject: [PATCH] pinctrl-bcm2835: Fix interrupt handling for GPIOs 28-31 and
7 Contrary to the documentation, the BCM2835 GPIO controller actually has
8 four interrupt lines - one each for the three IRQ groups and one common. Rather
9 confusingly, the GPIO interrupt groups don't correspond directly with the GPIO
10 control banks. Instead, GPIOs 0-27 generate IRQ GPIO0, 28-45 GPIO1 and
13 Awkwardly, the GPIOS for IRQ GPIO1 straddle two 32-entry GPIO banks, so it is
14 cleaner to split out a function to process the interrupts for a single GPIO
17 This bug has only just been observed because GPIOs above 27 can only be
18 accessed on an old Raspberry Pi with the optional P5 header fitted, where
19 the pins are often used for I2S instead.
21 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 51 ++++++++++++++++++++++++++---------
22 1 file changed, 39 insertions(+), 12 deletions(-)
24 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
25 +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
27 #define MODULE_NAME "pinctrl-bcm2835"
28 #define BCM2835_NUM_GPIOS 54
29 #define BCM2835_NUM_BANKS 2
30 +#define BCM2835_NUM_IRQS 3
32 #define BCM2835_PIN_BITMAP_SZ \
33 DIV_ROUND_UP(BCM2835_NUM_GPIOS, sizeof(unsigned long) * 8)
34 @@ -88,13 +89,13 @@ enum bcm2835_pinconf_pull {
36 struct bcm2835_gpio_irqdata {
37 struct bcm2835_pinctrl *pc;
42 struct bcm2835_pinctrl {
45 - int irq[BCM2835_NUM_BANKS];
46 + int irq[BCM2835_NUM_IRQS];
48 /* note: locking assumes each bank will have its own unsigned long */
49 unsigned long enabled_irq_map[BCM2835_NUM_BANKS];
50 @@ -105,7 +106,7 @@ struct bcm2835_pinctrl {
51 struct gpio_chip gpio_chip;
52 struct pinctrl_gpio_range gpio_range;
54 - struct bcm2835_gpio_irqdata irq_data[BCM2835_NUM_BANKS];
55 + struct bcm2835_gpio_irqdata irq_data[BCM2835_NUM_IRQS];
56 spinlock_t irq_lock[BCM2835_NUM_BANKS];
59 @@ -391,17 +392,16 @@ static struct gpio_chip bcm2835_gpio_chi
63 -static irqreturn_t bcm2835_gpio_irq_handler(int irq, void *dev_id)
64 +static int bcm2835_gpio_irq_handle_bank(struct bcm2835_pinctrl *pc,
65 + unsigned int bank, u32 mask)
67 - struct bcm2835_gpio_irqdata *irqdata = dev_id;
68 - struct bcm2835_pinctrl *pc = irqdata->pc;
69 - int bank = irqdata->bank;
75 events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4);
77 events &= pc->enabled_irq_map[bank];
78 for_each_set_bit(offset, &events, 32) {
79 gpio = (32 * bank) + offset;
80 @@ -409,7 +409,30 @@ static irqreturn_t bcm2835_gpio_irq_hand
82 generic_handle_irq(irq_linear_revmap(pc->irq_domain, gpio));
84 - return events ? IRQ_HANDLED : IRQ_NONE;
86 + return (events != 0);
89 +static irqreturn_t bcm2835_gpio_irq_handler(int irq, void *dev_id)
91 + struct bcm2835_gpio_irqdata *irqdata = dev_id;
92 + struct bcm2835_pinctrl *pc = irqdata->pc;
95 + switch (irqdata->irqgroup) {
96 + case 0: /* IRQ0 covers GPIOs 0-27 */
97 + handled = bcm2835_gpio_irq_handle_bank(pc, 0, 0x0fffffff);
99 + case 1: /* IRQ1 covers GPIOs 28-45 */
100 + handled = bcm2835_gpio_irq_handle_bank(pc, 0, 0xf0000000) |
101 + bcm2835_gpio_irq_handle_bank(pc, 1, 0x00003fff);
103 + case 2: /* IRQ2 covers GPIOs 46-53 */
104 + handled = bcm2835_gpio_irq_handle_bank(pc, 1, 0x003fc000);
108 + return handled ? IRQ_HANDLED : IRQ_NONE;
111 static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc,
112 @@ -998,8 +1021,6 @@ static int bcm2835_pinctrl_probe(struct
113 for (i = 0; i < BCM2835_NUM_BANKS; i++) {
114 unsigned long events;
119 /* clear event detection flags */
120 bcm2835_gpio_wr(pc, GPREN0 + i * 4, 0);
121 @@ -1014,10 +1035,15 @@ static int bcm2835_pinctrl_probe(struct
122 for_each_set_bit(offset, &events, 32)
123 bcm2835_gpio_wr(pc, GPEDS0 + i * 4, BIT(offset));
125 + spin_lock_init(&pc->irq_lock[i]);
128 + for (i = 0; i < BCM2835_NUM_IRQS; i++) {
131 pc->irq[i] = irq_of_parse_and_map(np, i);
132 pc->irq_data[i].pc = pc;
133 - pc->irq_data[i].bank = i;
134 - spin_lock_init(&pc->irq_lock[i]);
135 + pc->irq_data[i].irqgroup = i;
137 len = strlen(dev_name(pc->dev)) + 16;
138 name = devm_kzalloc(pc->dev, len, GFP_KERNEL);
139 @@ -1074,6 +1100,7 @@ static struct platform_driver bcm2835_pi
140 .remove = bcm2835_pinctrl_remove,
143 + .owner = THIS_MODULE,
144 .of_match_table = bcm2835_pinctrl_match,