Skip to content

Commit 14c32dc

Browse files
prabhakarladgeertu
authored andcommitted
pinctrl: renesas: rzg2l: Add function pointer for PFC register locking
On the RZ/G2L SoC, the PFCWE bit controls writing to PFC registers. However, on the RZ/V2H(P) SoC, the PFCWE (REGWE_A on RZ/V2H) bit controls writing to both PFC and PMC registers. Additionally, BIT(7) B0WI is undocumented for the PWPR register on RZ/V2H(P) SoC. To accommodate these differences across SoC variants, introduce the pwpr_pfc_lock_unlock() function pointer. Note, in rzg2l_pinctrl_set_pfc_mode() the pwpr_pfc_lock_unlock(.., false) is now called before PMC read/write and pwpr_pfc_lock_unlock(.., true) is now called after PMC read/write this is to keep changes minimal for RZ/V2H(P) SoC. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> # on RZ/G3S Link: https://lore.kernel.org/r/20240530173857.164073-8-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent a3a632e commit 14c32dc

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ struct rzg2l_dedicated_configs {
241241
u64 config;
242242
};
243243

244+
struct rzg2l_pinctrl;
245+
244246
struct rzg2l_pinctrl_data {
245247
const char * const *port_pins;
246248
const u64 *port_pin_configs;
@@ -251,6 +253,7 @@ struct rzg2l_pinctrl_data {
251253
const struct rzg2l_hwcfg *hwcfg;
252254
const u64 *variable_pin_cfg;
253255
unsigned int n_variable_pin_cfg;
256+
void (*pwpr_pfc_lock_unlock)(struct rzg2l_pinctrl *pctrl, bool lock);
254257
};
255258

256259
/**
@@ -383,7 +386,6 @@ static const u64 r9a07g043f_variable_pin_cfg[] = {
383386
static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
384387
u8 pin, u8 off, u8 func)
385388
{
386-
const struct rzg2l_register_offsets *regs = &pctrl->data->hwcfg->regs;
387389
unsigned long flags;
388390
u32 reg;
389391

@@ -394,27 +396,23 @@ static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
394396
reg &= ~(PM_MASK << (pin * 2));
395397
writew(reg, pctrl->base + PM(off));
396398

399+
pctrl->data->pwpr_pfc_lock_unlock(pctrl, false);
400+
397401
/* Temporarily switch to GPIO mode with PMC register */
398402
reg = readb(pctrl->base + PMC(off));
399403
writeb(reg & ~BIT(pin), pctrl->base + PMC(off));
400404

401-
/* Set the PWPR register to allow PFC register to write */
402-
writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */
403-
writel(PWPR_PFCWE, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=1 */
404-
405405
/* Select Pin function mode with PFC register */
406406
reg = readl(pctrl->base + PFC(off));
407407
reg &= ~(PFC_MASK << (pin * 4));
408408
writel(reg | (func << (pin * 4)), pctrl->base + PFC(off));
409409

410-
/* Set the PWPR register to be write-protected */
411-
writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */
412-
writel(PWPR_B0WI, pctrl->base + regs->pwpr); /* B0WI=1, PFCWE=0 */
413-
414410
/* Switch to Peripheral pin function with PMC register */
415411
reg = readb(pctrl->base + PMC(off));
416412
writeb(reg | BIT(pin), pctrl->base + PMC(off));
417413

414+
pctrl->data->pwpr_pfc_lock_unlock(pctrl, true);
415+
418416
spin_unlock_irqrestore(&pctrl->lock, flags);
419417
};
420418

@@ -2439,12 +2437,8 @@ static void rzg2l_pinctrl_pm_setup_dedicated_regs(struct rzg2l_pinctrl *pctrl, b
24392437
static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl)
24402438
{
24412439
u32 nports = pctrl->data->n_port_pins / RZG2L_PINS_PER_PORT;
2442-
const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg;
2443-
const struct rzg2l_register_offsets *regs = &hwcfg->regs;
24442440

2445-
/* Set the PWPR register to allow PFC register to write. */
2446-
writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */
2447-
writel(PWPR_PFCWE, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=1 */
2441+
pctrl->data->pwpr_pfc_lock_unlock(pctrl, false);
24482442

24492443
/* Restore port registers. */
24502444
for (u32 port = 0; port < nports; port++) {
@@ -2487,9 +2481,7 @@ static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl)
24872481
}
24882482
}
24892483

2490-
/* Set the PWPR register to be write-protected. */
2491-
writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */
2492-
writel(PWPR_B0WI, pctrl->base + regs->pwpr); /* B0WI=1, PFCWE=0 */
2484+
pctrl->data->pwpr_pfc_lock_unlock(pctrl, true);
24932485
}
24942486

24952487
static int rzg2l_pinctrl_suspend_noirq(struct device *dev)
@@ -2551,6 +2543,21 @@ static int rzg2l_pinctrl_resume_noirq(struct device *dev)
25512543
return 0;
25522544
}
25532545

2546+
static void rzg2l_pwpr_pfc_lock_unlock(struct rzg2l_pinctrl *pctrl, bool lock)
2547+
{
2548+
const struct rzg2l_register_offsets *regs = &pctrl->data->hwcfg->regs;
2549+
2550+
if (lock) {
2551+
/* Set the PWPR register to be write-protected */
2552+
writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */
2553+
writel(PWPR_B0WI, pctrl->base + regs->pwpr); /* B0WI=1, PFCWE=0 */
2554+
} else {
2555+
/* Set the PWPR register to allow PFC register to write */
2556+
writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */
2557+
writel(PWPR_PFCWE, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=1 */
2558+
}
2559+
}
2560+
25542561
static const struct rzg2l_hwcfg rzg2l_hwcfg = {
25552562
.regs = {
25562563
.pwpr = 0x3014,
@@ -2608,6 +2615,7 @@ static struct rzg2l_pinctrl_data r9a07g043_data = {
26082615
.variable_pin_cfg = r9a07g043f_variable_pin_cfg,
26092616
.n_variable_pin_cfg = ARRAY_SIZE(r9a07g043f_variable_pin_cfg),
26102617
#endif
2618+
.pwpr_pfc_lock_unlock = &rzg2l_pwpr_pfc_lock_unlock,
26112619
};
26122620

26132621
static struct rzg2l_pinctrl_data r9a07g044_data = {
@@ -2619,6 +2627,7 @@ static struct rzg2l_pinctrl_data r9a07g044_data = {
26192627
.n_dedicated_pins = ARRAY_SIZE(rzg2l_dedicated_pins.common) +
26202628
ARRAY_SIZE(rzg2l_dedicated_pins.rzg2l_pins),
26212629
.hwcfg = &rzg2l_hwcfg,
2630+
.pwpr_pfc_lock_unlock = &rzg2l_pwpr_pfc_lock_unlock,
26222631
};
26232632

26242633
static struct rzg2l_pinctrl_data r9a08g045_data = {
@@ -2629,6 +2638,7 @@ static struct rzg2l_pinctrl_data r9a08g045_data = {
26292638
.n_port_pins = ARRAY_SIZE(r9a08g045_gpio_configs) * RZG2L_PINS_PER_PORT,
26302639
.n_dedicated_pins = ARRAY_SIZE(rzg3s_dedicated_pins),
26312640
.hwcfg = &rzg3s_hwcfg,
2641+
.pwpr_pfc_lock_unlock = &rzg2l_pwpr_pfc_lock_unlock,
26322642
};
26332643

26342644
static const struct of_device_id rzg2l_pinctrl_of_table[] = {

0 commit comments

Comments
 (0)