From 0cd4a7b3a4883970df3ae8814d9aabdecf65a81e Mon Sep 17 00:00:00 2001 From: Cosmin Tanislav Date: Sun, 13 Sep 2026 22:56:54 +0300 Subject: [PATCH] pinctrl: renesas: rzt2h: Add a helper for reading PFC Introduce a rzt2h_pin_read_pfc() helper and replace the open-coded implementation inside rzt2h_gpio_get_direction() to simplify the code. While at it, use field_get() with PFC_PIN_MASK to avoid the manual shift and mask. Signed-off-by: Cosmin Tanislav Reviewed-by: Geert Uytterhoeven Link: https://patch.msgid.link/20260913195654.3371385-6-cosmin-gabriel.tanislav.xa@renesas.com Signed-off-by: Geert Uytterhoeven --- drivers/pinctrl/renesas/pinctrl-rzt2h.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/renesas/pinctrl-rzt2h.c b/drivers/pinctrl/renesas/pinctrl-rzt2h.c index 80a581fdef37..4872a208e0c3 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzt2h.c +++ b/drivers/pinctrl/renesas/pinctrl-rzt2h.c @@ -175,6 +175,13 @@ static bool rzt2h_pin_mode_is_peripheral(struct rzt2h_pinctrl *pctrl, u8 port, u return rzt2h_pinctrl_readb(pctrl, port, PMC(port)) & BIT(bit); } +static u8 rzt2h_pin_read_pfc(struct rzt2h_pinctrl *pctrl, u8 port, u8 pin) +{ + u64 reg64 = rzt2h_pinctrl_readq(pctrl, port, PFC(port)); + + return field_get(PFC_PIN_MASK(pin), reg64); +} + static bool rzt2h_pin_read_input(struct rzt2h_pinctrl *pctrl, u8 port, u8 bit) { return rzt2h_pinctrl_readb(pctrl, port, PIN(port)) & BIT(bit); @@ -785,7 +792,6 @@ 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; int ret; u8 pm; @@ -805,9 +811,7 @@ 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;