Skip to content

Commit 3b0cf6a

Browse files
John Madieugeertu
authored andcommitted
pinctrl: renesas: rzg2l: Refactor OEN register PWPR handling
Extract the OEN register write with PWPR protection logic into a helper function to eliminate code duplication between rzg2l_write_oen() and rzg2l_pinctrl_resume_noirq(). Introduce rzg2l_oen_write_with_pwpr() helper that encapsulates the PWPR unlock, OEN register write, and PWPR lock sequence. This helper must be called with pctrl->lock already held by the caller. Reported-by: Pavel Machek <pavel@denx.de> Closes: https://lore.kernel.org/cip-dev/OS9PR01MB16368C765305362F5F4132759FFC4A@OS9PR01MB16368.jpnprd01.prod.outlook.com/T/#u Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://patch.msgid.link/20251106080758.36645-1-john.madieu.xa@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent 8903597 commit 3b0cf6a

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,13 +1112,37 @@ static int rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin)
11121112
return !(readb(pctrl->base + pctrl->data->hwcfg->regs.oen) & BIT(bit));
11131113
}
11141114

1115-
static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oen)
1115+
/**
1116+
* rzg2l_oen_write_with_pwpr - Write to OEN register with PWPR protection
1117+
* @pctrl: pinctrl driver data
1118+
* @val: value to write to OEN register
1119+
*
1120+
* Writes to the OEN register, handling PWPR write protection if required
1121+
* by the hardware configuration. Must be called with pctrl->lock held.
1122+
*/
1123+
static void rzg2l_oen_write_with_pwpr(struct rzg2l_pinctrl *pctrl, u8 val)
11161124
{
11171125
const struct rzg2l_register_offsets *regs = &pctrl->data->hwcfg->regs;
1126+
u16 oen_offset = pctrl->data->hwcfg->regs.oen;
1127+
u8 pwpr;
1128+
1129+
if (pctrl->data->hwcfg->oen_pwpr_lock) {
1130+
pwpr = readb(pctrl->base + regs->pwpr);
1131+
writeb(pwpr | PWPR_REGWE_B, pctrl->base + regs->pwpr);
1132+
}
1133+
1134+
writeb(val, pctrl->base + oen_offset);
1135+
1136+
if (pctrl->data->hwcfg->oen_pwpr_lock)
1137+
writeb(pwpr & ~PWPR_REGWE_B, pctrl->base + regs->pwpr);
1138+
}
1139+
1140+
static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oen)
1141+
{
11181142
u16 oen_offset = pctrl->data->hwcfg->regs.oen;
11191143
unsigned long flags;
1120-
u8 val, pwpr;
11211144
int bit;
1145+
u8 val;
11221146

11231147
if (!pctrl->data->pin_to_oen_bit)
11241148
return -EOPNOTSUPP;
@@ -1133,13 +1157,8 @@ static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oe
11331157
val &= ~BIT(bit);
11341158
else
11351159
val |= BIT(bit);
1136-
if (pctrl->data->hwcfg->oen_pwpr_lock) {
1137-
pwpr = readb(pctrl->base + regs->pwpr);
1138-
writeb(pwpr | PWPR_REGWE_B, pctrl->base + regs->pwpr);
1139-
}
1140-
writeb(val, pctrl->base + oen_offset);
1141-
if (pctrl->data->hwcfg->oen_pwpr_lock)
1142-
writeb(pwpr & ~PWPR_REGWE_B, pctrl->base + regs->pwpr);
1160+
1161+
rzg2l_oen_write_with_pwpr(pctrl, val);
11431162
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
11441163

11451164
return 0;
@@ -3200,7 +3219,6 @@ static int rzg2l_pinctrl_resume_noirq(struct device *dev)
32003219
const struct rzg2l_register_offsets *regs = &hwcfg->regs;
32013220
struct rzg2l_pinctrl_reg_cache *cache = pctrl->cache;
32023221
unsigned long flags;
3203-
u8 pwpr;
32043222
int ret;
32053223

32063224
if (!atomic_read(&pctrl->wakeup_path)) {
@@ -3210,16 +3228,11 @@ static int rzg2l_pinctrl_resume_noirq(struct device *dev)
32103228
}
32113229

32123230
writeb(cache->qspi, pctrl->base + QSPI);
3213-
if (pctrl->data->hwcfg->oen_pwpr_lock) {
3214-
raw_spin_lock_irqsave(&pctrl->lock, flags);
3215-
pwpr = readb(pctrl->base + regs->pwpr);
3216-
writeb(pwpr | PWPR_REGWE_B, pctrl->base + regs->pwpr);
3217-
}
3218-
writeb(cache->oen, pctrl->base + pctrl->data->hwcfg->regs.oen);
3219-
if (pctrl->data->hwcfg->oen_pwpr_lock) {
3220-
writeb(pwpr & ~PWPR_REGWE_B, pctrl->base + regs->pwpr);
3221-
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
3222-
}
3231+
3232+
raw_spin_lock_irqsave(&pctrl->lock, flags);
3233+
rzg2l_oen_write_with_pwpr(pctrl, cache->oen);
3234+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
3235+
32233236
for (u8 i = 0; i < 2; i++) {
32243237
if (regs->sd_ch)
32253238
writeb(cache->sd_ch[i], pctrl->base + SD_CH(regs->sd_ch, i));

0 commit comments

Comments
 (0)