Skip to content

Commit fb8a790

Browse files
bijudasgeertu
authored andcommitted
pinctrl: renesas: rzg2l: Drop unnecessary pin configurations
There is no need to reconfigure a pin if the pin's configuration values are the same as the reset values. E.g. the PS0 pin configuration for the NMI function is PMC = 1 and PFC = 0, which is the same as the reset values. Currently the code is first setting it to GPIO HI-Z state and then again reconfiguring to the NMI function, leading to spurious IRQs. Fix this by dropping unnecessary pin configuration from the driver. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://patch.msgid.link/20250909104247.3309-1-biju.das.jz@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent 44bf661 commit fb8a790

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,16 @@ static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
541541
u8 pin, u8 off, u8 func)
542542
{
543543
unsigned long flags;
544-
u32 reg;
544+
u32 reg, pfc;
545545

546+
/* Switching to GPIO is not required if reset value is same as func */
546547
raw_spin_lock_irqsave(&pctrl->lock, flags);
548+
reg = readb(pctrl->base + PMC(off));
549+
pfc = readl(pctrl->base + PFC(off));
550+
if ((reg & BIT(pin)) && (((pfc >> (pin * 4)) & PFC_MASK) == func)) {
551+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
552+
return;
553+
}
547554

548555
/* Set pin to 'Non-use (Hi-Z input protection)' */
549556
reg = readw(pctrl->base + PM(off));
@@ -557,9 +564,8 @@ static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
557564
writeb(reg & ~BIT(pin), pctrl->base + PMC(off));
558565

559566
/* Select Pin function mode with PFC register */
560-
reg = readl(pctrl->base + PFC(off));
561-
reg &= ~(PFC_MASK << (pin * 4));
562-
writel(reg | (func << (pin * 4)), pctrl->base + PFC(off));
567+
pfc &= ~(PFC_MASK << (pin * 4));
568+
writel(pfc | (func << (pin * 4)), pctrl->base + PFC(off));
563569

564570
/* Switch to Peripheral pin function with PMC register */
565571
reg = readb(pctrl->base + PMC(off));
@@ -3130,11 +3136,18 @@ static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl)
31303136
pm = readw(pctrl->base + PM(off));
31313137
for_each_set_bit(pin, &pinmap, max_pin) {
31323138
struct rzg2l_pinctrl_reg_cache *cache = pctrl->cache;
3139+
u32 pfc_val, pfc_mask;
31333140

31343141
/* Nothing to do if PFC was not configured before. */
31353142
if (!(cache->pmc[port] & BIT(pin)))
31363143
continue;
31373144

3145+
pfc_val = readl(pctrl->base + PFC(off));
3146+
pfc_mask = PFC_MASK << (pin * 4);
3147+
/* Nothing to do if reset value of the pin is same as cached value */
3148+
if ((cache->pfc[port] & pfc_mask) == (pfc_val & pfc_mask))
3149+
continue;
3150+
31383151
/* Set pin to 'Non-use (Hi-Z input protection)' */
31393152
pm &= ~(PM_MASK << (pin * 2));
31403153
writew(pm, pctrl->base + PM(off));
@@ -3144,8 +3157,8 @@ static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl)
31443157
writeb(pmc, pctrl->base + PMC(off));
31453158

31463159
/* Select Pin function mode. */
3147-
pfc &= ~(PFC_MASK << (pin * 4));
3148-
pfc |= (cache->pfc[port] & (PFC_MASK << (pin * 4)));
3160+
pfc &= ~pfc_mask;
3161+
pfc |= (cache->pfc[port] & pfc_mask);
31493162
writel(pfc, pctrl->base + PFC(off));
31503163

31513164
/* Switch to Peripheral pin function. */

0 commit comments

Comments
 (0)