All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] pinctrl: renesas: trivial fixes and enhancements
@ 2020-11-15 17:46 Lad Prabhakar
  2020-11-15 17:46 ` [PATCH v3 1/2] pinctrl: renesas: Make sure the pin type is updated after setting the MUX Lad Prabhakar
  2020-11-15 17:47 ` [PATCH v3 2/2] pinctrl: renesas: Implement get_pin_muxing() callback Lad Prabhakar
  0 siblings, 2 replies; 3+ messages in thread
From: Lad Prabhakar @ 2020-11-15 17:46 UTC (permalink / raw)
  To: u-boot

Hi All,

This patch series includes trivial fixes and enhancements to
renesas pfc driver.

Oops sorry to miss the u-boot ML earlier resent a V3 again.

Cheers,
Prabhakar

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 | 59 ++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 5 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 1/2] pinctrl: renesas: Make sure the pin type is updated after setting the MUX
  2020-11-15 17:46 [PATCH v3 0/2] pinctrl: renesas: trivial fixes and enhancements Lad Prabhakar
@ 2020-11-15 17:46 ` Lad Prabhakar
  2020-11-15 17:47 ` [PATCH v3 2/2] pinctrl: renesas: Implement get_pin_muxing() callback Lad Prabhakar
  1 sibling, 0 replies; 3+ messages in thread
From: Lad Prabhakar @ 2020-11-15 17:46 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/pinctrl/renesas/pfc.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/pinctrl/renesas/pfc.c b/drivers/pinctrl/renesas/pfc.c
index fb811a95bc..174e91923a 100644
--- a/drivers/pinctrl/renesas/pfc.c
+++ b/drivers/pinctrl/renesas/pfc.c
@@ -487,8 +487,10 @@ 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) {
+		dev_err(pfc->dev, "Pin already used\n");
 		return -EBUSY;
+	}
 
 	ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
 	if (ret)
@@ -537,11 +539,20 @@ 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) {
+		dev_err(pfc->dev, "Pin already used\n");
 		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;
+
+	return 0;
 }
 
 static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selector,
@@ -551,14 +562,17 @@ static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selector
 	struct 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];
+	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) {
+			dev_err(pfc->dev, "Pin already used\n");
 			ret = -EBUSY;
 			goto done;
 		}
@@ -568,6 +582,10 @@ static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selector
 		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;
 	}
 
 done:
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v3 2/2] pinctrl: renesas: Implement get_pin_muxing() callback
  2020-11-15 17:46 [PATCH v3 0/2] pinctrl: renesas: trivial fixes and enhancements Lad Prabhakar
  2020-11-15 17:46 ` [PATCH v3 1/2] pinctrl: renesas: Make sure the pin type is updated after setting the MUX Lad Prabhakar
@ 2020-11-15 17:47 ` Lad Prabhakar
  1 sibling, 0 replies; 3+ messages in thread
From: Lad Prabhakar @ 2020-11-15 17:47 UTC (permalink / raw)
  To: u-boot

Implement get_pin_muxing() callback so that pinmux status
command can be used on Renesas platforms.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/pinctrl/renesas/pfc.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/pinctrl/renesas/pfc.c b/drivers/pinctrl/renesas/pfc.c
index 174e91923a..4c1e770422 100644
--- a/drivers/pinctrl/renesas/pfc.c
+++ b/drivers/pinctrl/renesas/pfc.c
@@ -44,6 +44,7 @@ enum sh_pfc_model {
 
 struct sh_pfc_pin_config {
 	u32 type;
+	const char *function_name;
 };
 
 struct sh_pfc_pinctrl {
@@ -448,6 +449,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->function_name);
+
+	return 0;
+}
+
 static int sh_pfc_pinctrl_get_functions_count(struct udevice *dev)
 {
 	struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
@@ -497,6 +522,7 @@ static int sh_pfc_gpio_request_enable(struct udevice *dev,
 		return ret;
 
 	cfg->type = PINMUX_TYPE_GPIO;
+	cfg->function_name = "gpio";
 
 	return 0;
 }
@@ -526,6 +552,7 @@ static int sh_pfc_gpio_disable_free(struct udevice *dev,
 	cfg = &pmx->configs[idx];
 
 	cfg->type = PINMUX_TYPE_NONE;
+	cfg->function_name = "none";
 
 	return 0;
 }
@@ -551,6 +578,7 @@ static int sh_pfc_pinctrl_pin_set(struct udevice *dev, unsigned pin_selector,
 		return ret;
 
 	cfg->type = PINMUX_TYPE_FUNCTION;
+	cfg->function_name = "function";
 
 	return 0;
 }
@@ -586,6 +614,7 @@ static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selector
 		idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
 		cfg = &pmx->configs[idx];
 		cfg->type = PINMUX_TYPE_FUNCTION;
+		cfg->function_name = priv->pfc.info->groups[group_selector].name;
 	}
 
 done:
@@ -792,6 +821,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,
 
@@ -822,6 +852,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->function_name = "none";
 	}
 
 	return 0;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-15 17:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15 17:46 [PATCH v3 0/2] pinctrl: renesas: trivial fixes and enhancements Lad Prabhakar
2020-11-15 17:46 ` [PATCH v3 1/2] pinctrl: renesas: Make sure the pin type is updated after setting the MUX Lad Prabhakar
2020-11-15 17:47 ` [PATCH v3 2/2] pinctrl: renesas: Implement get_pin_muxing() callback Lad Prabhakar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.