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

Configure Feed

Select the types of activity you want to include in your feed.

gpio: mt7621: use the generic GPIO chip lock for IRQ handling

This driver uses its own spinlock in interrupt routines while the
generic GPIO chip callbacks use a separate one. This is, of course, racy
so use the fact that the lock in generic GPIO chip is also a spinlock and
convert the interrupt handling functions in this module to using the
provided generic GPIO chip locking API.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250910-gpio-mmio-gpio-conv-part4-v2-9-f3d1a4c57124@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+12 -17
+12 -17
drivers/gpio/gpio-mt7621.c
··· 11 11 #include <linux/io.h> 12 12 #include <linux/module.h> 13 13 #include <linux/platform_device.h> 14 - #include <linux/spinlock.h> 15 14 16 15 #define MTK_BANK_CNT 3 17 16 #define MTK_BANK_WIDTH 32 ··· 31 32 struct mtk_gc { 32 33 struct irq_chip irq_chip; 33 34 struct gpio_generic_chip chip; 34 - spinlock_t lock; 35 35 int bank; 36 36 u32 rising; 37 37 u32 falling; ··· 109 111 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 110 112 struct mtk_gc *rg = to_mediatek_gpio(gc); 111 113 int pin = d->hwirq; 112 - unsigned long flags; 113 114 u32 rise, fall, high, low; 114 115 115 116 gpiochip_enable_irq(gc, d->hwirq); 116 117 117 - spin_lock_irqsave(&rg->lock, flags); 118 + guard(gpio_generic_lock_irqsave)(&rg->chip); 119 + 118 120 rise = mtk_gpio_r32(rg, GPIO_REG_REDGE); 119 121 fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE); 120 122 high = mtk_gpio_r32(rg, GPIO_REG_HLVL); ··· 123 125 mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall | (BIT(pin) & rg->falling)); 124 126 mtk_gpio_w32(rg, GPIO_REG_HLVL, high | (BIT(pin) & rg->hlevel)); 125 127 mtk_gpio_w32(rg, GPIO_REG_LLVL, low | (BIT(pin) & rg->llevel)); 126 - spin_unlock_irqrestore(&rg->lock, flags); 127 128 } 128 129 129 130 static void ··· 131 134 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 132 135 struct mtk_gc *rg = to_mediatek_gpio(gc); 133 136 int pin = d->hwirq; 134 - unsigned long flags; 135 137 u32 rise, fall, high, low; 136 138 137 - spin_lock_irqsave(&rg->lock, flags); 138 - rise = mtk_gpio_r32(rg, GPIO_REG_REDGE); 139 - fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE); 140 - high = mtk_gpio_r32(rg, GPIO_REG_HLVL); 141 - low = mtk_gpio_r32(rg, GPIO_REG_LLVL); 142 - mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall & ~BIT(pin)); 143 - mtk_gpio_w32(rg, GPIO_REG_REDGE, rise & ~BIT(pin)); 144 - mtk_gpio_w32(rg, GPIO_REG_HLVL, high & ~BIT(pin)); 145 - mtk_gpio_w32(rg, GPIO_REG_LLVL, low & ~BIT(pin)); 146 - spin_unlock_irqrestore(&rg->lock, flags); 139 + scoped_guard(gpio_generic_lock_irqsave, &rg->chip) { 140 + rise = mtk_gpio_r32(rg, GPIO_REG_REDGE); 141 + fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE); 142 + high = mtk_gpio_r32(rg, GPIO_REG_HLVL); 143 + low = mtk_gpio_r32(rg, GPIO_REG_LLVL); 144 + mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall & ~BIT(pin)); 145 + mtk_gpio_w32(rg, GPIO_REG_REDGE, rise & ~BIT(pin)); 146 + mtk_gpio_w32(rg, GPIO_REG_HLVL, high & ~BIT(pin)); 147 + mtk_gpio_w32(rg, GPIO_REG_LLVL, low & ~BIT(pin)); 148 + } 147 149 148 150 gpiochip_disable_irq(gc, d->hwirq); 149 151 } ··· 228 232 rg = &mtk->gc_map[bank]; 229 233 memset(rg, 0, sizeof(*rg)); 230 234 231 - spin_lock_init(&rg->lock); 232 235 rg->bank = bank; 233 236 234 237 dat = mtk->base + GPIO_REG_DATA + (rg->bank * GPIO_BANK_STRIDE);