Skip to content

Commit 44bf661

Browse files
claudiubezneageertu
authored andcommitted
pinctrl: renesas: rzg2l: Fix ISEL restore on resume
Commit 1d2da79 ("pinctrl: renesas: rzg2l: Avoid configuring ISEL in gpio_irq_{en,dis}able*()") dropped the configuration of ISEL from struct irq_chip::{irq_enable, irq_disable} APIs and moved it to struct gpio_chip::irq::{child_to_parent_hwirq, child_irq_domain_ops::free} APIs to fix spurious IRQs. After commit 1d2da79 ("pinctrl: renesas: rzg2l: Avoid configuring ISEL in gpio_irq_{en,dis}able*()"), ISEL was no longer configured properly on resume. This is because the pinctrl resume code used struct irq_chip::irq_enable (called from rzg2l_gpio_irq_restore()) to reconfigure the wakeup interrupts. Some drivers (e.g. Ethernet) may also reconfigure non-wakeup interrupts on resume through their own code, eventually calling struct irq_chip::irq_enable. Fix this by adding ISEL configuration back into the struct irq_chip::irq_enable API and on resume path for wakeup interrupts. As struct irq_chip::irq_enable needs now to lock to update the ISEL, convert the struct rzg2l_pinctrl::lock to a raw spinlock and replace the locking API calls with the raw variants. Otherwise the lockdep reports invalid wait context when probing the adv7511 module on RZ/G2L: [ BUG: Invalid wait context ] 6.17.0-rc5-next-20250911-00001-gfcfac22533c9 #18 Not tainted ----------------------------- (udev-worker)/165 is trying to lock: ffff00000e3664a8 (&pctrl->lock){....}-{3:3}, at: rzg2l_gpio_irq_enable+0x38/0x78 other info that might help us debug this: context-{5:5} 3 locks held by (udev-worker)/165: #0: ffff00000e890108 (&dev->mutex){....}-{4:4}, at: __driver_attach+0x90/0x1ac #1: ffff000011c07240 (request_class){+.+.}-{4:4}, at: __setup_irq+0xb4/0x6dc #2: ffff000011c070c8 (lock_class){....}-{2:2}, at: __setup_irq+0xdc/0x6dc stack backtrace: CPU: 1 UID: 0 PID: 165 Comm: (udev-worker) Not tainted 6.17.0-rc5-next-20250911-00001-gfcfac22533c9 #18 PREEMPT Hardware name: Renesas SMARC EVK based on r9a07g044l2 (DT) Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0x90/0xd0 dump_stack+0x18/0x24 __lock_acquire+0xa14/0x20b4 lock_acquire+0x1c8/0x354 _raw_spin_lock_irqsave+0x60/0x88 rzg2l_gpio_irq_enable+0x38/0x78 irq_enable+0x40/0x8c __irq_startup+0x78/0xa4 irq_startup+0x108/0x16c __setup_irq+0x3c0/0x6dc request_threaded_irq+0xec/0x1ac devm_request_threaded_irq+0x80/0x134 adv7511_probe+0x928/0x9a4 [adv7511] i2c_device_probe+0x22c/0x3dc really_probe+0xbc/0x2a0 __driver_probe_device+0x78/0x12c driver_probe_device+0x40/0x164 __driver_attach+0x9c/0x1ac bus_for_each_dev+0x74/0xd0 driver_attach+0x24/0x30 bus_add_driver+0xe4/0x208 driver_register+0x60/0x128 i2c_register_driver+0x48/0xd0 adv7511_init+0x5c/0x1000 [adv7511] do_one_initcall+0x64/0x30c do_init_module+0x58/0x23c load_module+0x1bcc/0x1d40 init_module_from_file+0x88/0xc4 idempotent_init_module+0x188/0x27c __arm64_sys_finit_module+0x68/0xac invoke_syscall+0x48/0x110 el0_svc_common.constprop.0+0xc0/0xe0 do_el0_svc+0x1c/0x28 el0_svc+0x4c/0x160 el0t_64_sync_handler+0xa0/0xe4 el0t_64_sync+0x198/0x19c Having ISEL configuration back into the struct irq_chip::irq_enable API should be safe with respect to spurious IRQs, as in the probe case IRQs are enabled anyway in struct gpio_chip::irq::child_to_parent_hwirq. No spurious IRQs were detected on suspend/resume, boot, ethernet link insert/remove tests (executed on RZ/G3S). Boot, ethernet link insert/remove tests were also executed successfully on RZ/G2L. Fixes: 1d2da79 ("pinctrl: renesas: rzg2l: Avoid configuring ISEL in gpio_irq_{en,dis}able*(") Cc: [email protected] Signed-off-by: Claudiu Beznea <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 3a86608 commit 44bf661

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ struct rzg2l_pinctrl {
359359
spinlock_t bitmap_lock; /* protect tint_slot bitmap */
360360
unsigned int hwirq[RZG2L_TINT_MAX_INTERRUPT];
361361

362-
spinlock_t lock; /* lock read/write registers */
362+
raw_spinlock_t lock; /* lock read/write registers */
363363
struct mutex mutex; /* serialize adding groups and functions */
364364

365365
struct rzg2l_pinctrl_pin_settings *settings;
@@ -543,7 +543,7 @@ static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
543543
unsigned long flags;
544544
u32 reg;
545545

546-
spin_lock_irqsave(&pctrl->lock, flags);
546+
raw_spin_lock_irqsave(&pctrl->lock, flags);
547547

548548
/* Set pin to 'Non-use (Hi-Z input protection)' */
549549
reg = readw(pctrl->base + PM(off));
@@ -567,7 +567,7 @@ static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
567567

568568
pctrl->data->pwpr_pfc_lock_unlock(pctrl, true);
569569

570-
spin_unlock_irqrestore(&pctrl->lock, flags);
570+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
571571
};
572572

573573
static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
@@ -882,10 +882,10 @@ static void rzg2l_rmw_pin_config(struct rzg2l_pinctrl *pctrl, u32 offset,
882882
addr += 4;
883883
}
884884

885-
spin_lock_irqsave(&pctrl->lock, flags);
885+
raw_spin_lock_irqsave(&pctrl->lock, flags);
886886
reg = readl(addr) & ~(mask << (bit * 8));
887887
writel(reg | (val << (bit * 8)), addr);
888-
spin_unlock_irqrestore(&pctrl->lock, flags);
888+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
889889
}
890890

891891
static int rzg2l_caps_to_pwr_reg(const struct rzg2l_register_offsets *regs, u32 caps)
@@ -1121,7 +1121,7 @@ static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oe
11211121
if (bit < 0)
11221122
return -EINVAL;
11231123

1124-
spin_lock_irqsave(&pctrl->lock, flags);
1124+
raw_spin_lock_irqsave(&pctrl->lock, flags);
11251125
val = readb(pctrl->base + oen_offset);
11261126
if (oen)
11271127
val &= ~BIT(bit);
@@ -1134,7 +1134,7 @@ static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oe
11341134
writeb(val, pctrl->base + oen_offset);
11351135
if (pctrl->data->hwcfg->oen_pwpr_lock)
11361136
writeb(pwpr & ~PWPR_REGWE_B, pctrl->base + regs->pwpr);
1137-
spin_unlock_irqrestore(&pctrl->lock, flags);
1137+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
11381138

11391139
return 0;
11401140
}
@@ -1687,14 +1687,14 @@ static int rzg2l_gpio_request(struct gpio_chip *chip, unsigned int offset)
16871687
if (ret)
16881688
return ret;
16891689

1690-
spin_lock_irqsave(&pctrl->lock, flags);
1690+
raw_spin_lock_irqsave(&pctrl->lock, flags);
16911691

16921692
/* Select GPIO mode in PMC Register */
16931693
reg8 = readb(pctrl->base + PMC(off));
16941694
reg8 &= ~BIT(bit);
16951695
pctrl->data->pmc_writeb(pctrl, reg8, PMC(off));
16961696

1697-
spin_unlock_irqrestore(&pctrl->lock, flags);
1697+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
16981698

16991699
return 0;
17001700
}
@@ -1709,15 +1709,15 @@ static void rzg2l_gpio_set_direction(struct rzg2l_pinctrl *pctrl, u32 offset,
17091709
unsigned long flags;
17101710
u16 reg16;
17111711

1712-
spin_lock_irqsave(&pctrl->lock, flags);
1712+
raw_spin_lock_irqsave(&pctrl->lock, flags);
17131713

17141714
reg16 = readw(pctrl->base + PM(off));
17151715
reg16 &= ~(PM_MASK << (bit * 2));
17161716

17171717
reg16 |= (output ? PM_OUTPUT : PM_INPUT) << (bit * 2);
17181718
writew(reg16, pctrl->base + PM(off));
17191719

1720-
spin_unlock_irqrestore(&pctrl->lock, flags);
1720+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
17211721
}
17221722

17231723
static int rzg2l_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
@@ -1761,7 +1761,7 @@ static int rzg2l_gpio_set(struct gpio_chip *chip, unsigned int offset,
17611761
unsigned long flags;
17621762
u8 reg8;
17631763

1764-
spin_lock_irqsave(&pctrl->lock, flags);
1764+
raw_spin_lock_irqsave(&pctrl->lock, flags);
17651765

17661766
reg8 = readb(pctrl->base + P(off));
17671767

@@ -1770,7 +1770,7 @@ static int rzg2l_gpio_set(struct gpio_chip *chip, unsigned int offset,
17701770
else
17711771
writeb(reg8 & ~BIT(bit), pctrl->base + P(off));
17721772

1773-
spin_unlock_irqrestore(&pctrl->lock, flags);
1773+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
17741774

17751775
return 0;
17761776
}
@@ -2429,14 +2429,13 @@ static int rzg2l_gpio_get_gpioint(unsigned int virq, struct rzg2l_pinctrl *pctrl
24292429
return gpioint;
24302430
}
24312431

2432-
static void rzg2l_gpio_irq_endisable(struct rzg2l_pinctrl *pctrl,
2433-
unsigned int hwirq, bool enable)
2432+
static void __rzg2l_gpio_irq_endisable(struct rzg2l_pinctrl *pctrl,
2433+
unsigned int hwirq, bool enable)
24342434
{
24352435
const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[hwirq];
24362436
u64 *pin_data = pin_desc->drv_data;
24372437
u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data);
24382438
u8 bit = RZG2L_PIN_ID_TO_PIN(hwirq);
2439-
unsigned long flags;
24402439
void __iomem *addr;
24412440

24422441
addr = pctrl->base + ISEL(off);
@@ -2445,12 +2444,20 @@ static void rzg2l_gpio_irq_endisable(struct rzg2l_pinctrl *pctrl,
24452444
addr += 4;
24462445
}
24472446

2448-
spin_lock_irqsave(&pctrl->lock, flags);
24492447
if (enable)
24502448
writel(readl(addr) | BIT(bit * 8), addr);
24512449
else
24522450
writel(readl(addr) & ~BIT(bit * 8), addr);
2453-
spin_unlock_irqrestore(&pctrl->lock, flags);
2451+
}
2452+
2453+
static void rzg2l_gpio_irq_endisable(struct rzg2l_pinctrl *pctrl,
2454+
unsigned int hwirq, bool enable)
2455+
{
2456+
unsigned long flags;
2457+
2458+
raw_spin_lock_irqsave(&pctrl->lock, flags);
2459+
__rzg2l_gpio_irq_endisable(pctrl, hwirq, enable);
2460+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
24542461
}
24552462

24562463
static void rzg2l_gpio_irq_disable(struct irq_data *d)
@@ -2462,15 +2469,25 @@ static void rzg2l_gpio_irq_disable(struct irq_data *d)
24622469
gpiochip_disable_irq(gc, hwirq);
24632470
}
24642471

2465-
static void rzg2l_gpio_irq_enable(struct irq_data *d)
2472+
static void __rzg2l_gpio_irq_enable(struct irq_data *d, bool lock)
24662473
{
24672474
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
2475+
struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip);
24682476
unsigned int hwirq = irqd_to_hwirq(d);
24692477

24702478
gpiochip_enable_irq(gc, hwirq);
2479+
if (lock)
2480+
rzg2l_gpio_irq_endisable(pctrl, hwirq, true);
2481+
else
2482+
__rzg2l_gpio_irq_endisable(pctrl, hwirq, true);
24712483
irq_chip_enable_parent(d);
24722484
}
24732485

2486+
static void rzg2l_gpio_irq_enable(struct irq_data *d)
2487+
{
2488+
__rzg2l_gpio_irq_enable(d, true);
2489+
}
2490+
24742491
static int rzg2l_gpio_irq_set_type(struct irq_data *d, unsigned int type)
24752492
{
24762493
return irq_chip_set_type_parent(d, type);
@@ -2616,11 +2633,11 @@ static void rzg2l_gpio_irq_restore(struct rzg2l_pinctrl *pctrl)
26162633
* This has to be atomically executed to protect against a concurrent
26172634
* interrupt.
26182635
*/
2619-
spin_lock_irqsave(&pctrl->lock, flags);
2636+
raw_spin_lock_irqsave(&pctrl->lock, flags);
26202637
ret = rzg2l_gpio_irq_set_type(data, irqd_get_trigger_type(data));
26212638
if (!ret && !irqd_irq_disabled(data))
2622-
rzg2l_gpio_irq_enable(data);
2623-
spin_unlock_irqrestore(&pctrl->lock, flags);
2639+
__rzg2l_gpio_irq_enable(data, false);
2640+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
26242641

26252642
if (ret)
26262643
dev_crit(pctrl->dev, "Failed to set IRQ type for virq=%u\n", virq);
@@ -2950,7 +2967,7 @@ static int rzg2l_pinctrl_probe(struct platform_device *pdev)
29502967
"failed to enable GPIO clk\n");
29512968
}
29522969

2953-
spin_lock_init(&pctrl->lock);
2970+
raw_spin_lock_init(&pctrl->lock);
29542971
spin_lock_init(&pctrl->bitmap_lock);
29552972
mutex_init(&pctrl->mutex);
29562973
atomic_set(&pctrl->wakeup_path, 0);
@@ -3093,7 +3110,7 @@ static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl)
30933110
u32 nports = pctrl->data->n_port_pins / RZG2L_PINS_PER_PORT;
30943111
unsigned long flags;
30953112

3096-
spin_lock_irqsave(&pctrl->lock, flags);
3113+
raw_spin_lock_irqsave(&pctrl->lock, flags);
30973114
pctrl->data->pwpr_pfc_lock_unlock(pctrl, false);
30983115

30993116
/* Restore port registers. */
@@ -3138,7 +3155,7 @@ static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl)
31383155
}
31393156

31403157
pctrl->data->pwpr_pfc_lock_unlock(pctrl, true);
3141-
spin_unlock_irqrestore(&pctrl->lock, flags);
3158+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
31423159
}
31433160

31443161
static int rzg2l_pinctrl_suspend_noirq(struct device *dev)
@@ -3187,14 +3204,14 @@ static int rzg2l_pinctrl_resume_noirq(struct device *dev)
31873204

31883205
writeb(cache->qspi, pctrl->base + QSPI);
31893206
if (pctrl->data->hwcfg->oen_pwpr_lock) {
3190-
spin_lock_irqsave(&pctrl->lock, flags);
3207+
raw_spin_lock_irqsave(&pctrl->lock, flags);
31913208
pwpr = readb(pctrl->base + regs->pwpr);
31923209
writeb(pwpr | PWPR_REGWE_B, pctrl->base + regs->pwpr);
31933210
}
31943211
writeb(cache->oen, pctrl->base + pctrl->data->hwcfg->regs.oen);
31953212
if (pctrl->data->hwcfg->oen_pwpr_lock) {
31963213
writeb(pwpr & ~PWPR_REGWE_B, pctrl->base + regs->pwpr);
3197-
spin_unlock_irqrestore(&pctrl->lock, flags);
3214+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
31983215
}
31993216
for (u8 i = 0; i < 2; i++) {
32003217
if (regs->sd_ch)

0 commit comments

Comments
 (0)