pinctrl: renesas: trivial fixes and enhancements
Subsystems (2)
v4 cover pinctrl: renesas: trivial fixes and enhancements
Hi All,
This patch series includes trivial fixes and enhancements to renesas pfc driver.
Cheers,
Prabhakar
v3->v4
* Avoided pin to be re-muxed for the same device.
v2->v3
* Patch 1/2 print a warning message if the current pin is being overwritten before abort as suggested by Marek.
* Patch 2/2 unchanged
v1->v2
* Patch 1/2 updated commit message
* Patch 2/2 unchanged
Lad Prabhakar (2):
pinctrl: renesas: Make sure the pin type is updated after setting the
MUX
pinctrl: renesas: Implement get_pin_muxing() callback
drivers/pinctrl/renesas/pfc.c | 77 ++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/2 pinctrl: renesas: Make sure the pin type is updated after setting the MUX
By default on startup all the pin types are configured to PINMUX_TYPE_NONE (in sh_pfc_map_pins()), when pin is set as GPIO the pin type is updated to PINMUX_TYPE_GPIO. But the type is not updated when the pin is set as a function in sh_pfc_pinctrl_pin_set() or sh_pfc_pinctrl_group_set() calls (these calls only set the MUX if the pin type is PINMUX_TYPE_NONE ie unused).
So with the current implementation pin functionality could be overwritten silently, for example if the same pin is added for SPI and serial.
This patch makes sure of updating pin type after every successful call to sh_pfc_config_mux() and thus fixing from pin functionality to be overwritten. Also a warning message is printed if the current pin is being overwritten before abort.
This also avoids pin re-muxing to same type that is for example from command line device is asked to re-probe/select (mmc dev x) we return early with success in this case as the pin is already muxed.
--- drivers/pinctrl/renesas/pfc.c | 52 +++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-)
drivers/pinctrl/renesas/pfc.c +47 -5
@@ -45,6 +45,7 @@ enum sh_pfc_model {struct sh_pfc_pin_config {u32 type; +const char *name; };struct sh_pfc_pinctrl {
@@ -488,14 +489,21 @@ static int sh_pfc_gpio_request_enable(struct udevice *dev, idx =sh_pfc_get_pin_index (pfc, pin->pin); cfg = &pmx->configs[idx]; -if (cfg->type !=PINMUX_TYPE_NONE ) +if (cfg->type !=PINMUX_TYPE_NONE ) { +if (!strcmp (cfg->name, pin->name)) +return 0 ; + +dev_err (pfc->dev,"Pin already used as %s\n" , + cfg->name);return -EBUSY ; + } ret =sh_pfc_config_mux (pfc, pin->enum_id,PINMUX_TYPE_GPIO );if (ret)return ret; cfg->type =PINMUX_TYPE_GPIO ; + cfg->name ="gpio" ;return 0 ; }
@@ -525,6 +533,7 @@ static int sh_pfc_gpio_disable_free(struct udevice *dev, cfg = &pmx->configs[idx]; cfg->type =PINMUX_TYPE_NONE ; + cfg->name ="none" ;return 0 ; }
@@ -538,11 +547,25 @@ static int sh_pfc_pinctrl_pin_set(struct udevice *dev, unsigned pin_selector,const struct sh_pfc_pin *pin = &priv->pfc.info->pins[pin_selector];int idx =sh_pfc_get_pin_index (pfc, pin->pin);struct sh_pfc_pin_config *cfg = &pmx->configs[idx]; +int ret; -if (cfg->type !=PINMUX_TYPE_NONE ) +if (cfg->type !=PINMUX_TYPE_NONE ) { +if (!strcmp (cfg->name, pin->name)) +return 0 ; + +dev_err (pfc->dev,"Pin already used as %s\n" , + cfg->name);return -EBUSY ; + } + + ret =sh_pfc_config_mux (pfc, pin->enum_id,PINMUX_TYPE_FUNCTION ); +if (ret) +return ret; -return sh_pfc_config_mux (pfc, pin->enum_id,PINMUX_TYPE_FUNCTION ); + cfg->type =PINMUX_TYPE_FUNCTION ; + cfg->name ="function" ; + +return 0 ; } static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selector,
@@ -552,23 +575,41 @@ static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selectorstruct sh_pfc_pinctrl *pmx = &priv->pmx;struct sh_pfc *pfc = &priv->pfc;const struct sh_pfc_pin_group *grp = &priv->pfc.info->groups[group_selector]; +bool grp_pins_configured = true; +struct sh_pfc_pin_config *cfg;unsigned int i;int ret =0 ; +int idx;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]; + idx =sh_pfc_get_pin_index (pfc, grp->pins[i]); + cfg = &pmx->configs[idx];if (cfg->type !=PINMUX_TYPE_NONE ) { +if (!strcmp (cfg->name, grp->name)) +continue ; + +dev_err (pfc->dev,"Pin already used as %s\n" , + cfg->name); ret = -EBUSY ; goto done; + }else { + grp_pins_configured = false; } } +if (grp_pins_configured) +return 0 ; +for (i =0 ; i < grp->nr_pins; ++i) { ret =sh_pfc_config_mux (pfc, grp->mux[i],PINMUX_TYPE_FUNCTION );if (ret <0 )break ; + + idx =sh_pfc_get_pin_index (pfc, grp->pins[i]); + cfg = &pmx->configs[idx]; + cfg->type =PINMUX_TYPE_FUNCTION ; + cfg->name = priv->pfc.info->groups[group_selector].name; } done:
@@ -805,6 +846,7 @@ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)for (i =0 ; i < pfc->info->nr_pins; ++i) {struct sh_pfc_pin_config *cfg = &pmx->configs[i]; cfg->type =PINMUX_TYPE_NONE ; + cfg->name ="none" ; }return 0 ;
Signature · 1 line
2.17.1
Marek Vasut
AppliedPATCH v4 1/2 pinctrl: renesas: Make sure the pin type is updated after setting the MUX
Quoted 10 lines · Lad Prabhakar
By default on startup all the pin types are configured to
PINMUX_TYPE_NONE(insh_pfc_map_pins()), when pin is set as GPIO the pin type is updated toPINMUX_TYPE_GPIO. But the type is not updated when the pin is set as a function insh_pfc_pinctrl_pin_set()orsh_pfc_pinctrl_group_set()calls (these calls only set the MUX if the pin type isPINMUX_TYPE_NONEie unused).So with the current implementation pin functionality could be overwritten silently, for example if the same pin is added for SPI and serial.
Quoted 8 lines
This patch makes sure of updating pin type after every successful call to
sh_pfc_config_mux()and thus fixing from pin functionality to be overwritten. Also a warning message is printed if the current pin is being overwritten before abort.This also avoids pin re-muxing to same type that is for example from command line device is asked to re-probe/select (mmc dev x) we return early with success in this case as the pin is already muxed.
Applied, thanks
PATCH v4 2/2 pinctrl: renesas: Implement get_pin_muxing() callback
In reply to Lad PrabhakarImplement get_pin_muxing() callback so that pinmux status command can be used on Renesas platforms.
--- drivers/pinctrl/renesas/pfc.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/pinctrl/renesas/pfc.c +25 -0
@@ -450,6 +450,30 @@ static const char *sh_pfc_pinctrl_get_group_name(struct udevice *dev,return priv->pfc.info->groups[selector].name; } +static int sh_pfc_pinctrl_get_pin_muxing (struct udevice *dev, +unsigned int selector, +char *buf,int size) +{ +struct sh_pfc_pinctrl_priv *priv =dev_get_priv (dev); +struct sh_pfc_pinctrl *pmx = &priv->pmx; +struct sh_pfc *pfc = &priv->pfc; +struct sh_pfc_pin_config *cfg; +const struct sh_pfc_pin *pin; +int idx; + + pin = &priv->pfc.info->pins[selector]; +if (!pin) { +snprintf (buf, size,"Unknown" ); +return -EINVAL ; + } + + idx =sh_pfc_get_pin_index (pfc, pin->pin); + cfg = &pmx->configs[idx]; +snprintf (buf, size,"%s" , cfg->name); + +return 0 ; +} +static int sh_pfc_pinctrl_get_functions_count (struct udevice *dev) {struct sh_pfc_pinctrl_priv *priv =dev_get_priv (dev);
@@ -816,6 +840,7 @@ static struct pinctrl_ops sh_pfc_pinctrl_ops = { .get_pin_name = sh_pfc_pinctrl_get_pin_name, .get_groups_count = sh_pfc_pinctrl_get_groups_count, .get_group_name = sh_pfc_pinctrl_get_group_name, + .get_pin_muxing = sh_pfc_pinctrl_get_pin_muxing, .get_functions_count = sh_pfc_pinctrl_get_functions_count, .get_function_name = sh_pfc_pinctrl_get_function_name,
Signature · 1 line
2.17.1
Marek Vasut
AppliedPATCH v4 2/2 pinctrl: renesas: Implement get_pin_muxing() callback
Quoted 2 lines · Lad Prabhakar
Implement
get_pin_muxing()callback so that pinmux status command can be used on Renesas platforms.
Applied, thanks