Commit 8a0cc47c authored by Yoshihiro Shimoda's avatar Yoshihiro Shimoda Committed by Geert Uytterhoeven

pinctrl: sh-pfc: Rollback to mux if required when the gpio is freed

Some drivers require switching between function and gpio at run-time.
Allow to roll back from gpio to mux when the gpio is freed.
Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: default avatarSimon Horman <horms+renesas@verge.net.au>
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
parent b13431ed
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "../pinconf.h" #include "../pinconf.h"
struct sh_pfc_pin_config { struct sh_pfc_pin_config {
unsigned int mux_mark;
bool mux_set; bool mux_set;
bool gpio_enabled; bool gpio_enabled;
}; };
...@@ -353,6 +354,16 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector, ...@@ -353,6 +354,16 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
spin_lock_irqsave(&pfc->lock, flags); spin_lock_irqsave(&pfc->lock, flags);
for (i = 0; i < grp->nr_pins; ++i) { for (i = 0; i < grp->nr_pins; ++i) {
int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
/*
* This driver cannot manage both gpio and mux when the gpio
* pin is already enabled. So, this function fails.
*/
if (cfg->gpio_enabled)
return -EBUSY;
ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION); ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
if (ret < 0) if (ret < 0)
goto done; goto done;
...@@ -364,6 +375,7 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector, ...@@ -364,6 +375,7 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
struct sh_pfc_pin_config *cfg = &pmx->configs[idx]; struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
cfg->mux_set = true; cfg->mux_set = true;
cfg->mux_mark = grp->mux[i];
} }
done: done:
...@@ -417,6 +429,9 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev, ...@@ -417,6 +429,9 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
spin_lock_irqsave(&pfc->lock, flags); spin_lock_irqsave(&pfc->lock, flags);
cfg->gpio_enabled = false; cfg->gpio_enabled = false;
/* If mux is already set, this configures it here */
if (cfg->mux_set)
sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
spin_unlock_irqrestore(&pfc->lock, flags); spin_unlock_irqrestore(&pfc->lock, flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment