[PATCH v2 4/4] pinctrl: renesas: rzt2h: reuse helpers
From: Cosmin Tanislav
Date: Thu Sep 10 2026 - 12:12:26 EST
The PMCm peripheral-mode test, the PFCm function read, the PINm input
read, the PMm write, and the PMm read are open-coded in several places.
Reuse the already existing helpers.
Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@xxxxxxxxxxx>
---
V2:
* pick up Geert's Reviewed-by
drivers/pinctrl/renesas/pinctrl-rzt2h.c | 39 +++++++++----------------
1 file changed, 13 insertions(+), 26 deletions(-)
diff --git a/drivers/pinctrl/renesas/pinctrl-rzt2h.c b/drivers/pinctrl/renesas/pinctrl-rzt2h.c
index 8cf4b7f48e7e..4872a208e0c3 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzt2h.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzt2h.c
@@ -230,7 +230,7 @@ static void rzt2h_pinctrl_set_pfc_mode(struct rzt2h_pinctrl *pctrl,
reg64 = rzt2h_pinctrl_readq(pctrl, port, PFC(port));
/* Check if pin is already configured to the desired function */
- if ((rzt2h_pinctrl_readb(pctrl, port, PMC(port)) & BIT(pin)) &&
+ if (rzt2h_pin_mode_is_peripheral(pctrl, port, pin) &&
field_get(PFC_PIN_MASK(pin), reg64) == func)
return;
@@ -784,15 +784,7 @@ static int rzt2h_gpio_request(struct gpio_chip *chip, unsigned int offset)
static void rzt2h_gpio_set_direction(struct rzt2h_pinctrl *pctrl, u32 port,
u8 bit, bool output)
{
- u16 reg;
-
- guard(raw_spinlock_irqsave)(&pctrl->lock);
-
- reg = rzt2h_pinctrl_readw(pctrl, port, PM(port));
- reg &= ~PM_PIN_MASK(bit);
-
- reg |= (output ? PM_OUTPUT : PM_INPUT) << (bit * 2);
- rzt2h_pinctrl_writew(pctrl, port, reg, PM(port));
+ rzt2h_pin_write_pm(pctrl, port, bit, output ? PM_OUTPUT : PM_INPUT);
}
static int rzt2h_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
@@ -800,9 +792,8 @@ static int rzt2h_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
struct rzt2h_pinctrl *pctrl = gpiochip_get_data(chip);
u8 port = RZT2H_PIN_ID_TO_PORT(offset);
u8 bit = RZT2H_PIN_ID_TO_PIN(offset);
- u64 reg64;
- u16 reg;
int ret;
+ u8 pm;
ret = rzt2h_validate_pin(pctrl, offset);
if (ret)
@@ -810,7 +801,7 @@ static int rzt2h_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
guard(raw_spinlock_irqsave)(&pctrl->lock);
- if (rzt2h_pinctrl_readb(pctrl, port, PMC(port)) & BIT(bit)) {
+ if (rzt2h_pin_mode_is_peripheral(pctrl, port, bit)) {
/*
* When a GPIO is being requested as an IRQ, the pinctrl
* framework expects to be able to read the GPIO's direction.
@@ -820,19 +811,16 @@ static int rzt2h_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
* called to enable the IRQ function.
* Default to input direction for IRQ function.
*/
- reg64 = rzt2h_pinctrl_readq(pctrl, port, PFC(port));
- reg64 = (reg64 >> (bit * 8)) & PFC_MASK;
- if (reg64 == PFC_FUNC_INTERRUPT)
+ if (rzt2h_pin_read_pfc(pctrl, port, bit) == PFC_FUNC_INTERRUPT)
return GPIO_LINE_DIRECTION_IN;
return -EINVAL;
}
- reg = rzt2h_pinctrl_readw(pctrl, port, PM(port));
- reg = (reg >> (bit * 2)) & PM_MASK;
- if (reg & PM_OUTPUT)
+ pm = rzt2h_pin_read_pm(pctrl, port, bit);
+ if (pm & PM_OUTPUT)
return GPIO_LINE_DIRECTION_OUT;
- if (reg & PM_INPUT)
+ if (pm & PM_INPUT)
return GPIO_LINE_DIRECTION_IN;
return -EINVAL;
@@ -862,16 +850,15 @@ static int rzt2h_gpio_get(struct gpio_chip *chip, unsigned int offset)
struct rzt2h_pinctrl *pctrl = gpiochip_get_data(chip);
u8 port = RZT2H_PIN_ID_TO_PORT(offset);
u8 bit = RZT2H_PIN_ID_TO_PIN(offset);
- u16 reg;
+ u8 pm;
if (rzt2h_pin_mode_is_peripheral(pctrl, port, bit))
return rzt2h_pin_read_input(pctrl, port, bit);
- reg = rzt2h_pinctrl_readw(pctrl, port, PM(port));
- reg = (reg >> (bit * 2)) & PM_MASK;
- if (reg & PM_INPUT)
- return !!(rzt2h_pinctrl_readb(pctrl, port, PIN(port)) & BIT(bit));
- if (reg & PM_OUTPUT)
+ pm = rzt2h_pin_read_pm(pctrl, port, bit);
+ if (pm & PM_INPUT)
+ return rzt2h_pin_read_input(pctrl, port, bit);
+ if (pm & PM_OUTPUT)
return !!(rzt2h_pinctrl_readb(pctrl, port, P(port)) & BIT(bit));
return -EINVAL;
--
2.55.0