From 732f829f69406cd00c3759eef97e461b79ef53a8 Mon Sep 17 00:00:00 2001 From: Aymeric Aillet Date: Mon, 24 Jan 2022 15:24:02 +0100 Subject: [PATCH] drivers: pinctrl: rcar: Rework pin configuration Rework pin configuration to meet documented procedures. 3 procedures are covered here: - GPIO -> Peripheral (+select peripheral function) - Peripheral -> GPIO - Change from Peripheral function 1 -> Peripheral function 2 Signed-off-by: Aymeric Aillet --- drivers/pinctrl/pfc_rcar.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/pinctrl/pfc_rcar.c b/drivers/pinctrl/pfc_rcar.c index 0aabf669a33..c6bb47b7293 100644 --- a/drivers/pinctrl/pfc_rcar.c +++ b/drivers/pinctrl/pfc_rcar.c @@ -166,19 +166,27 @@ int pinctrl_configure_pin(const pinctrl_soc_pin_t *pin) { int ret = 0; - /* Some pins cannot be used as GPIO */ + /* Set pin as GPIO if capable */ if (RCAR_IS_GP_PIN(pin->pin)) { - pfc_rcar_set_gpsr(pin->pin, true); + pfc_rcar_set_gpsr(pin->pin, false); + } else if ((pin->flags & RCAR_PIN_FLAGS_FUNC_SET) == 0U) { + /* A function must be set for non GPIO capable pin */ + return -EINVAL; } + /* Select function for pin */ if ((pin->flags & RCAR_PIN_FLAGS_FUNC_SET) != 0U) { pfc_rcar_set_ipsr(&pin->func); - } - if ((pin->flags & RCAR_PIN_FLAGS_PULL_SET) != 0U) { - ret = pfc_rcar_set_bias(pin->pin, pin->flags); - if (ret < 0) { - return ret; + if (RCAR_IS_GP_PIN(pin->pin)) { + pfc_rcar_set_gpsr(pin->pin, true); + } + + if ((pin->flags & RCAR_PIN_FLAGS_PULL_SET) != 0U) { + ret = pfc_rcar_set_bias(pin->pin, pin->flags); + if (ret < 0) { + return ret; + } } }