Skip to content

Commit e7a3a1b

Browse files
author
Bartosz Golaszewski
committed
gpio: ath79: use the generic GPIO chip lock for IRQ handling
This driver uses its own raw 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 raw 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-5-f3d1a4c57124@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 551a097 commit e7a3a1b

1 file changed

Lines changed: 19 additions & 32 deletions

File tree

drivers/gpio/gpio-ath79.c

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
struct ath79_gpio_ctrl {
3232
struct gpio_generic_chip chip;
3333
void __iomem *base;
34-
raw_spinlock_t lock;
3534
unsigned long both_edges;
3635
};
3736

@@ -72,48 +71,43 @@ static void ath79_gpio_irq_unmask(struct irq_data *data)
7271
{
7372
struct ath79_gpio_ctrl *ctrl = irq_data_to_ath79_gpio(data);
7473
u32 mask = BIT(irqd_to_hwirq(data));
75-
unsigned long flags;
7674

7775
gpiochip_enable_irq(&ctrl->chip.gc, irqd_to_hwirq(data));
78-
raw_spin_lock_irqsave(&ctrl->lock, flags);
76+
77+
guard(gpio_generic_lock_irqsave)(&ctrl->chip);
78+
7979
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, mask);
80-
raw_spin_unlock_irqrestore(&ctrl->lock, flags);
8180
}
8281

8382
static void ath79_gpio_irq_mask(struct irq_data *data)
8483
{
8584
struct ath79_gpio_ctrl *ctrl = irq_data_to_ath79_gpio(data);
8685
u32 mask = BIT(irqd_to_hwirq(data));
87-
unsigned long flags;
8886

89-
raw_spin_lock_irqsave(&ctrl->lock, flags);
90-
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, 0);
91-
raw_spin_unlock_irqrestore(&ctrl->lock, flags);
87+
scoped_guard(gpio_generic_lock_irqsave, &ctrl->chip)
88+
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, 0);
89+
9290
gpiochip_disable_irq(&ctrl->chip.gc, irqd_to_hwirq(data));
9391
}
9492

9593
static void ath79_gpio_irq_enable(struct irq_data *data)
9694
{
9795
struct ath79_gpio_ctrl *ctrl = irq_data_to_ath79_gpio(data);
9896
u32 mask = BIT(irqd_to_hwirq(data));
99-
unsigned long flags;
10097

101-
raw_spin_lock_irqsave(&ctrl->lock, flags);
98+
guard(gpio_generic_lock_irqsave)(&ctrl->chip);
10299
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_ENABLE, mask, mask);
103100
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, mask);
104-
raw_spin_unlock_irqrestore(&ctrl->lock, flags);
105101
}
106102

107103
static void ath79_gpio_irq_disable(struct irq_data *data)
108104
{
109105
struct ath79_gpio_ctrl *ctrl = irq_data_to_ath79_gpio(data);
110106
u32 mask = BIT(irqd_to_hwirq(data));
111-
unsigned long flags;
112107

113-
raw_spin_lock_irqsave(&ctrl->lock, flags);
108+
guard(gpio_generic_lock_irqsave)(&ctrl->chip);
114109
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, 0);
115110
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_ENABLE, mask, 0);
116-
raw_spin_unlock_irqrestore(&ctrl->lock, flags);
117111
}
118112

119113
static int ath79_gpio_irq_set_type(struct irq_data *data,
@@ -122,7 +116,6 @@ static int ath79_gpio_irq_set_type(struct irq_data *data,
122116
struct ath79_gpio_ctrl *ctrl = irq_data_to_ath79_gpio(data);
123117
u32 mask = BIT(irqd_to_hwirq(data));
124118
u32 type = 0, polarity = 0;
125-
unsigned long flags;
126119
bool disabled;
127120

128121
switch (flow_type) {
@@ -144,7 +137,7 @@ static int ath79_gpio_irq_set_type(struct irq_data *data,
144137
return -EINVAL;
145138
}
146139

147-
raw_spin_lock_irqsave(&ctrl->lock, flags);
140+
guard(gpio_generic_lock_irqsave)(&ctrl->chip);
148141

149142
if (flow_type == IRQ_TYPE_EDGE_BOTH) {
150143
ctrl->both_edges |= mask;
@@ -169,8 +162,6 @@ static int ath79_gpio_irq_set_type(struct irq_data *data,
169162
ath79_gpio_update_bits(
170163
ctrl, AR71XX_GPIO_REG_INT_ENABLE, mask, mask);
171164

172-
raw_spin_unlock_irqrestore(&ctrl->lock, flags);
173-
174165
return 0;
175166
}
176167

@@ -192,26 +183,24 @@ static void ath79_gpio_irq_handler(struct irq_desc *desc)
192183
struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
193184
struct ath79_gpio_ctrl *ctrl =
194185
container_of(gen_gc, struct ath79_gpio_ctrl, chip);
195-
unsigned long flags, pending;
186+
unsigned long pending;
196187
u32 both_edges, state;
197188
int irq;
198189

199190
chained_irq_enter(irqchip, desc);
200191

201-
raw_spin_lock_irqsave(&ctrl->lock, flags);
202-
203-
pending = ath79_gpio_read(ctrl, AR71XX_GPIO_REG_INT_PENDING);
192+
scoped_guard(gpio_generic_lock_irqsave, &ctrl->chip) {
193+
pending = ath79_gpio_read(ctrl, AR71XX_GPIO_REG_INT_PENDING);
204194

205-
/* Update the polarity of the both edges irqs */
206-
both_edges = ctrl->both_edges & pending;
207-
if (both_edges) {
208-
state = ath79_gpio_read(ctrl, AR71XX_GPIO_REG_IN);
209-
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_POLARITY,
210-
both_edges, ~state);
195+
/* Update the polarity of the both edges irqs */
196+
both_edges = ctrl->both_edges & pending;
197+
if (both_edges) {
198+
state = ath79_gpio_read(ctrl, AR71XX_GPIO_REG_IN);
199+
ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_POLARITY,
200+
both_edges, ~state);
201+
}
211202
}
212203

213-
raw_spin_unlock_irqrestore(&ctrl->lock, flags);
214-
215204
for_each_set_bit(irq, &pending, gc->ngpio)
216205
generic_handle_domain_irq(gc->irq.domain, irq);
217206

@@ -256,8 +245,6 @@ static int ath79_gpio_probe(struct platform_device *pdev)
256245
if (IS_ERR(ctrl->base))
257246
return PTR_ERR(ctrl->base);
258247

259-
raw_spin_lock_init(&ctrl->lock);
260-
261248
config = (struct gpio_generic_chip_config) {
262249
.dev = dev,
263250
.sz = 4,

0 commit comments

Comments
 (0)