return (pincfg & BIT(pin)) ? 0 : -EINVAL;
}
+static void rzt2h_pinctrl_set_gpio_en(struct rzt2h_pinctrl *pctrl,
+ u8 port, u8 pin, bool en)
+{
+ u8 reg = rzt2h_pinctrl_readb(pctrl, port, PMC(port));
+
+ if (en)
+ reg &= ~BIT(pin);
+ else
+ reg |= BIT(pin);
+
+ rzt2h_pinctrl_writeb(pctrl, port, reg, PMC(port));
+}
+
static void rzt2h_pinctrl_set_pfc_mode(struct rzt2h_pinctrl *pctrl,
u8 port, u8 pin, u8 func)
{
rzt2h_pinctrl_writew(pctrl, port, reg16, PM(port));
/* Temporarily switch to GPIO mode with PMC register */
- reg16 = rzt2h_pinctrl_readb(pctrl, port, PMC(port));
- rzt2h_pinctrl_writeb(pctrl, port, reg16 & ~BIT(pin), PMC(port));
+ rzt2h_pinctrl_set_gpio_en(pctrl, port, pin, true);
/* Select Pin function mode with PFC register */
reg64 = rzt2h_pinctrl_readq(pctrl, port, PFC(port));
rzt2h_pinctrl_writeq(pctrl, port, reg64 | ((u64)func << (pin * 8)), PFC(port));
/* Switch to Peripheral pin function with PMC register */
- reg16 = rzt2h_pinctrl_readb(pctrl, port, PMC(port));
- rzt2h_pinctrl_writeb(pctrl, port, reg16 | BIT(pin), PMC(port));
+ rzt2h_pinctrl_set_gpio_en(pctrl, port, pin, false);
}
static int rzt2h_pinctrl_set_mux(struct pinctrl_dev *pctldev,
u8 port = RZT2H_PIN_ID_TO_PORT(offset);
u8 bit = RZT2H_PIN_ID_TO_PIN(offset);
int ret;
- u8 reg;
ret = rzt2h_validate_pin(pctrl, offset);
if (ret)
guard(spinlock_irqsave)(&pctrl->lock);
/* Select GPIO mode in PMC Register */
- reg = rzt2h_pinctrl_readb(pctrl, port, PMC(port));
- reg &= ~BIT(bit);
- rzt2h_pinctrl_writeb(pctrl, port, reg, PMC(port));
+ rzt2h_pinctrl_set_gpio_en(pctrl, port, bit, true);
return 0;
}