pinctrl: at91: don't use the same irqchip with multiple gpiochips
authorLudovic Desroches <ludovic.desroches@microchip.com>
Thu, 13 Sep 2018 12:42:13 +0000 (14:42 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Nov 2019 08:52:20 +0000 (09:52 +0100)
[ Upstream commit 0c3dfa176912b5f87732545598200fb55e9c1978 ]

Sharing the same irqchip with multiple gpiochips is not a good
practice. For instance, when installing hooks, we change the state
of the irqchip. The initial state of the irqchip for the second
gpiochip to register is then disrupted.

Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pinctrl/pinctrl-at91.c

index 9f09041..9401a06 100644 (file)
@@ -1545,16 +1545,6 @@ void at91_pinctrl_gpio_resume(void)
 #define gpio_irq_set_wake      NULL
 #endif /* CONFIG_PM */
 
-static struct irq_chip gpio_irqchip = {
-       .name           = "GPIO",
-       .irq_ack        = gpio_irq_ack,
-       .irq_disable    = gpio_irq_mask,
-       .irq_mask       = gpio_irq_mask,
-       .irq_unmask     = gpio_irq_unmask,
-       /* .irq_set_type is set dynamically */
-       .irq_set_wake   = gpio_irq_set_wake,
-};
-
 static void gpio_irq_handler(struct irq_desc *desc)
 {
        struct irq_chip *chip = irq_desc_get_chip(desc);
@@ -1595,12 +1585,22 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev,
        struct gpio_chip        *gpiochip_prev = NULL;
        struct at91_gpio_chip   *prev = NULL;
        struct irq_data         *d = irq_get_irq_data(at91_gpio->pioc_virq);
+       struct irq_chip         *gpio_irqchip;
        int ret, i;
 
+       gpio_irqchip = devm_kzalloc(&pdev->dev, sizeof(*gpio_irqchip), GFP_KERNEL);
+       if (!gpio_irqchip)
+               return -ENOMEM;
+
        at91_gpio->pioc_hwirq = irqd_to_hwirq(d);
 
-       /* Setup proper .irq_set_type function */
-       gpio_irqchip.irq_set_type = at91_gpio->ops->irq_type;
+       gpio_irqchip->name = "GPIO";
+       gpio_irqchip->irq_ack = gpio_irq_ack;
+       gpio_irqchip->irq_disable = gpio_irq_mask;
+       gpio_irqchip->irq_mask = gpio_irq_mask;
+       gpio_irqchip->irq_unmask = gpio_irq_unmask;
+       gpio_irqchip->irq_set_wake = gpio_irq_set_wake,
+       gpio_irqchip->irq_set_type = at91_gpio->ops->irq_type;
 
        /* Disable irqs of this PIO controller */
        writel_relaxed(~0, at91_gpio->regbase + PIO_IDR);
@@ -1611,7 +1611,7 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev,
         * interrupt.
         */
        ret = gpiochip_irqchip_add(&at91_gpio->chip,
-                                  &gpio_irqchip,
+                                  gpio_irqchip,
                                   0,
                                   handle_edge_irq,
                                   IRQ_TYPE_NONE);
@@ -1629,7 +1629,7 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev,
        if (!gpiochip_prev) {
                /* Then register the chain on the parent IRQ */
                gpiochip_set_chained_irqchip(&at91_gpio->chip,
-                                            &gpio_irqchip,
+                                            gpio_irqchip,
                                             at91_gpio->pioc_virq,
                                             gpio_irq_handler);
                return 0;