Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: mxs: fix duplicate level interrupts

According to the reference manual level interrupts can't be acked
using the IRQSTAT registers. The effect is that when a level interrupt
triggers the following ack is a no-op and the same interrupt triggers
again right after it has been unmasked after running the interrupt
handler.

The reference manual says:

Status bits for pins configured as level sensitive interrupts cannot be
cleared unless either the actual pin is in the non-interrupting state, or
the pin has been disabled as an interrupt source by clearing its bit in
HW_PINCTRL_PIN2IRQ.

To work around the duplicated interrupts we can use the PIN2IRQ
rather than the IRQEN registers to mask the interrupts. This
probably does not work for the edge interrupts, so we have to split up
the irq chip into two chip types, one for the level interrupts and
one for the edge interrupts. We now make use of two different enable
registers, so we have to take care to always enable the right one,
especially during switching of the interrupt type. An easy way
to accomplish this is to use the IRQCHIP_SET_TYPE_MASKED which
makes sure that set_irq_type is called with masked interrupts. With this
the flow to change the irq type is like:

- core masks interrupt (using the current chip type)
- mxs_gpio_set_irq_type() changes chip type if necessary
- mxs_gpio_set_irq_type() unconditionally sets the enable bit in the
now unused enable register
- core eventually unmasks the interrupt (using the new chip type)

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Marek Vasut <marex@denx.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Sascha Hauer and committed by
Linus Walleij
f08ea3cc 66a37c3b

+29 -9
+29 -9
drivers/gpio/gpio-mxs.c
··· 87 87 u32 val; 88 88 u32 pin_mask = 1 << d->hwirq; 89 89 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 90 + struct irq_chip_type *ct = irq_data_get_chip_type(d); 90 91 struct mxs_gpio_port *port = gc->private; 91 92 void __iomem *pin_addr; 92 93 int edge; 94 + 95 + if (!(ct->type & type)) 96 + if (irq_setup_alt_chip(d, type)) 97 + return -EINVAL; 93 98 94 99 port->both_edges &= ~pin_mask; 95 100 switch (type) { ··· 124 119 125 120 /* set level or edge */ 126 121 pin_addr = port->base + PINCTRL_IRQLEV(port); 127 - if (edge & GPIO_INT_LEV_MASK) 122 + if (edge & GPIO_INT_LEV_MASK) { 128 123 writel(pin_mask, pin_addr + MXS_SET); 129 - else 124 + writel(pin_mask, port->base + PINCTRL_IRQEN(port) + MXS_SET); 125 + } else { 130 126 writel(pin_mask, pin_addr + MXS_CLR); 127 + writel(pin_mask, port->base + PINCTRL_PIN2IRQ(port) + MXS_SET); 128 + } 131 129 132 130 /* set polarity */ 133 131 pin_addr = port->base + PINCTRL_IRQPOL(port); ··· 210 202 struct irq_chip_generic *gc; 211 203 struct irq_chip_type *ct; 212 204 213 - gc = irq_alloc_generic_chip("gpio-mxs", 1, irq_base, 205 + gc = irq_alloc_generic_chip("gpio-mxs", 2, irq_base, 214 206 port->base, handle_level_irq); 215 207 if (!gc) 216 208 return -ENOMEM; 217 209 218 210 gc->private = port; 219 211 220 - ct = gc->chip_types; 212 + ct = &gc->chip_types[0]; 213 + ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW; 221 214 ct->chip.irq_ack = irq_gc_ack_set_bit; 222 215 ct->chip.irq_mask = irq_gc_mask_disable_reg; 223 216 ct->chip.irq_unmask = irq_gc_unmask_enable_reg; 224 217 ct->chip.irq_set_type = mxs_gpio_set_irq_type; 225 218 ct->chip.irq_set_wake = mxs_gpio_set_wake_irq; 219 + ct->chip.flags = IRQCHIP_SET_TYPE_MASKED; 220 + ct->regs.ack = PINCTRL_IRQSTAT(port) + MXS_CLR; 221 + ct->regs.enable = PINCTRL_PIN2IRQ(port) + MXS_SET; 222 + ct->regs.disable = PINCTRL_PIN2IRQ(port) + MXS_CLR; 223 + 224 + ct = &gc->chip_types[1]; 225 + ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; 226 + ct->chip.irq_ack = irq_gc_ack_set_bit; 227 + ct->chip.irq_mask = irq_gc_mask_disable_reg; 228 + ct->chip.irq_unmask = irq_gc_unmask_enable_reg; 229 + ct->chip.irq_set_type = mxs_gpio_set_irq_type; 230 + ct->chip.irq_set_wake = mxs_gpio_set_wake_irq; 231 + ct->chip.flags = IRQCHIP_SET_TYPE_MASKED; 226 232 ct->regs.ack = PINCTRL_IRQSTAT(port) + MXS_CLR; 227 233 ct->regs.enable = PINCTRL_IRQEN(port) + MXS_SET; 228 234 ct->regs.disable = PINCTRL_IRQEN(port) + MXS_CLR; 235 + ct->handler = handle_level_irq; 229 236 230 237 irq_setup_generic_chip(gc, IRQ_MSK(32), IRQ_GC_INIT_NESTED_LOCK, 231 238 IRQ_NOREQUEST, 0); ··· 321 298 } 322 299 port->base = base; 323 300 324 - /* 325 - * select the pin interrupt functionality but initially 326 - * disable the interrupts 327 - */ 328 - writel(~0U, port->base + PINCTRL_PIN2IRQ(port)); 301 + /* initially disable the interrupts */ 302 + writel(0, port->base + PINCTRL_PIN2IRQ(port)); 329 303 writel(0, port->base + PINCTRL_IRQEN(port)); 330 304 331 305 /* clear address has to be used to clear IRQSTAT bits */