linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] add small improvements to the S32G pinctrl driver
@ 2024-07-23 13:18 Andrei Stefanescu
  2024-07-23 13:18 ` [PATCH 1/3] pinctrl: s32cc: enable the input buffer for a GPIO Andrei Stefanescu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andrei Stefanescu @ 2024-07-23 13:18 UTC (permalink / raw)
  To: Linus Walleij, Dong Aisheng, Fabio Estevam, Shawn Guo, Jacky Bai,
	Pengutronix Kernel Team, Chester Lin, Matthias Brugger,
	Ghennadi Procopciuc
  Cc: linux-arm-kernel, linux-gpio, linux-kernel, NXP S32 Linux Team,
	Andrei Stefanescu

This patch series adds various small improvements to the pinctrl
driver used by S32G SoCs. These can also be found in the
downstream kernel version [1].

[1] - https://github.com/nxp-auto-linux/linux

Andrei Stefanescu (3):
  pinctrl: s32cc: enable the input buffer for a GPIO
  pinctrl: s32cc: configure PIN_CONFIG_DRIVE_PUSH_PULL
  pinctrl: s32cc: add update and overwrite options when setting pinconf

 drivers/pinctrl/nxp/pinctrl-s32cc.c | 51 ++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 16 deletions(-)

-- 
2.45.2


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

* [PATCH 1/3] pinctrl: s32cc: enable the input buffer for a GPIO
  2024-07-23 13:18 [PATCH 0/3] add small improvements to the S32G pinctrl driver Andrei Stefanescu
@ 2024-07-23 13:18 ` Andrei Stefanescu
  2024-07-23 13:18 ` [PATCH 2/3] pinctrl: s32cc: configure PIN_CONFIG_DRIVE_PUSH_PULL Andrei Stefanescu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrei Stefanescu @ 2024-07-23 13:18 UTC (permalink / raw)
  To: Linus Walleij, Dong Aisheng, Fabio Estevam, Shawn Guo, Jacky Bai,
	Pengutronix Kernel Team, Chester Lin, Matthias Brugger,
	Ghennadi Procopciuc
  Cc: linux-arm-kernel, linux-gpio, linux-kernel, NXP S32 Linux Team,
	Andrei Stefanescu, Florin Buica

The IBE (input buffer enable) should be enabled for a GPIO. Reading the
value will return the one from the input register, writing the value
will return the one from the output register.

This offers the flexibility to check if the value intended to be set
matches the actual physical one.

Signed-off-by: Florin Buica <florin.buica@nxp.com>
Signed-off-by: Andrei Stefanescu <andrei.stefanescu@oss.nxp.com>
---
 drivers/pinctrl/nxp/pinctrl-s32cc.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index f0cad2c501f7..1f58772c472e 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -2,7 +2,7 @@
 /*
  * Core driver for the S32 CC (Common Chassis) pin controller
  *
- * Copyright 2017-2022 NXP
+ * Copyright 2017-2022,2024 NXP
  * Copyright (C) 2022 SUSE LLC
  * Copyright 2015-2016 Freescale Semiconductor, Inc.
  */
@@ -436,16 +436,15 @@ static int s32_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
 				      unsigned int offset,
 				      bool input)
 {
-	unsigned int config;
+	/* Always enable IBE for GPIOs. This allows us to read the
+	 * actual line value and compare it with the one set.
+	 */
+	unsigned int config = S32_MSCR_IBE;
 	unsigned int mask = S32_MSCR_IBE | S32_MSCR_OBE;
 
-	if (input) {
-		/* Disable output buffer and enable input buffer */
-		config = S32_MSCR_IBE;
-	} else {
-		/* Disable input buffer and enable output buffer */
-		config = S32_MSCR_OBE;
-	}
+	/* Enable output buffer */
+	if (!input)
+		config |= S32_MSCR_OBE;
 
 	return s32_regmap_update(pctldev, offset, mask, config);
 }
-- 
2.45.2


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

* [PATCH 2/3] pinctrl: s32cc: configure PIN_CONFIG_DRIVE_PUSH_PULL
  2024-07-23 13:18 [PATCH 0/3] add small improvements to the S32G pinctrl driver Andrei Stefanescu
  2024-07-23 13:18 ` [PATCH 1/3] pinctrl: s32cc: enable the input buffer for a GPIO Andrei Stefanescu
@ 2024-07-23 13:18 ` Andrei Stefanescu
  2024-07-23 13:18 ` [PATCH 3/3] pinctrl: s32cc: add update and overwrite options when setting pinconf Andrei Stefanescu
  2024-08-05  8:18 ` [PATCH 0/3] add small improvements to the S32G pinctrl driver Linus Walleij
  3 siblings, 0 replies; 5+ messages in thread
From: Andrei Stefanescu @ 2024-07-23 13:18 UTC (permalink / raw)
  To: Linus Walleij, Dong Aisheng, Fabio Estevam, Shawn Guo, Jacky Bai,
	Pengutronix Kernel Team, Chester Lin, Matthias Brugger,
	Ghennadi Procopciuc
  Cc: linux-arm-kernel, linux-gpio, linux-kernel, NXP S32 Linux Team,
	Andrei Stefanescu, Florin Buica

Previously, it was possible to only configure the open-drain for a pin.
However, after a pin got configured with open-drain, there wasn't any
way to disable it. Add the push-pull configuration in order to reverse
the open-drain configuration.

Signed-off-by: Florin Buica <florin.buica@nxp.com>
Signed-off-by: Andrei Stefanescu <andrei.stefanescu@oss.nxp.com>
---
 drivers/pinctrl/nxp/pinctrl-s32cc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index 1f58772c472e..48d9d6df953f 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -515,6 +515,10 @@ static int s32_parse_pincfg(unsigned long pincfg, unsigned int *mask,
 		*config |= S32_MSCR_ODE;
 		*mask |= S32_MSCR_ODE;
 		break;
+	case PIN_CONFIG_DRIVE_PUSH_PULL:
+		*config &= ~S32_MSCR_ODE;
+		*mask |= S32_MSCR_ODE;
+		break;
 	case PIN_CONFIG_OUTPUT_ENABLE:
 		if (arg)
 			*config |= S32_MSCR_OBE;
-- 
2.45.2


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

* [PATCH 3/3] pinctrl: s32cc: add update and overwrite options when setting pinconf
  2024-07-23 13:18 [PATCH 0/3] add small improvements to the S32G pinctrl driver Andrei Stefanescu
  2024-07-23 13:18 ` [PATCH 1/3] pinctrl: s32cc: enable the input buffer for a GPIO Andrei Stefanescu
  2024-07-23 13:18 ` [PATCH 2/3] pinctrl: s32cc: configure PIN_CONFIG_DRIVE_PUSH_PULL Andrei Stefanescu
@ 2024-07-23 13:18 ` Andrei Stefanescu
  2024-08-05  8:18 ` [PATCH 0/3] add small improvements to the S32G pinctrl driver Linus Walleij
  3 siblings, 0 replies; 5+ messages in thread
From: Andrei Stefanescu @ 2024-07-23 13:18 UTC (permalink / raw)
  To: Linus Walleij, Dong Aisheng, Fabio Estevam, Shawn Guo, Jacky Bai,
	Pengutronix Kernel Team, Chester Lin, Matthias Brugger,
	Ghennadi Procopciuc
  Cc: linux-arm-kernel, linux-gpio, linux-kernel, NXP S32 Linux Team,
	Andrei Stefanescu, Radu Pirea, Florin Buica

The previous pinconf settings(made by the bootloader) need to be
overwritten when configuring the pinctrl of a driver during the boot
process.

Configuring the bias of a GPIO at runtime (e.g. pull-up) needs to
preserve the other settings unaltered.

This patch introduces changes to differentiate between the two cases.

Signed-off-by: Radu Pirea <radu-nicolae.pirea@nxp.com>
Signed-off-by: Florin Buica <florin.buica@nxp.com>
Signed-off-by: Andrei Stefanescu <andrei.stefanescu@oss.nxp.com>
---
 drivers/pinctrl/nxp/pinctrl-s32cc.c | 30 ++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index 48d9d6df953f..9c730f2ca172 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -39,6 +39,11 @@
 #define S32_MSCR_ODE		BIT(20)
 #define S32_MSCR_OBE		BIT(21)
 
+enum s32_write_type {
+	S32_PINCONF_UPDATE_ONLY,
+	S32_PINCONF_OVERWRITE,
+};
+
 static struct regmap_config s32_regmap_config = {
 	.reg_bits = 32,
 	.val_bits = 32,
@@ -557,10 +562,11 @@ static int s32_parse_pincfg(unsigned long pincfg, unsigned int *mask,
 	return 0;
 }
 
-static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev,
+static int s32_pinconf_mscr_write(struct pinctrl_dev *pctldev,
 				   unsigned int pin_id,
 				   unsigned long *configs,
-				   unsigned int num_configs)
+				   unsigned int num_configs,
+				   enum s32_write_type write_type)
 {
 	struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
 	unsigned int config = 0, mask = 0;
@@ -579,10 +585,20 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev,
 			return ret;
 	}
 
+	/* If the MSCR configuration has to be written,
+	 * the SSS field should not be touched.
+	 */
+	if (write_type == S32_PINCONF_OVERWRITE)
+		mask = (unsigned int)~S32_MSCR_SSS_MASK;
+
 	if (!config && !mask)
 		return 0;
 
-	dev_dbg(ipctl->dev, "update: pin %u cfg 0x%x\n", pin_id, config);
+	if (write_type == S32_PINCONF_OVERWRITE)
+		dev_dbg(ipctl->dev, "set: pin %u cfg 0x%x\n", pin_id, config);
+	else
+		dev_dbg(ipctl->dev, "update: pin %u cfg 0x%x\n", pin_id,
+			config);
 
 	return s32_regmap_update(pctldev, pin_id, mask, config);
 }
@@ -598,8 +614,8 @@ static int s32_pinconf_set(struct pinctrl_dev *pctldev,
 			   unsigned int pin_id, unsigned long *configs,
 			   unsigned int num_configs)
 {
-	return s32_pinconf_mscr_update(pctldev, pin_id, configs,
-				       num_configs);
+	return s32_pinconf_mscr_write(pctldev, pin_id, configs,
+				       num_configs, S32_PINCONF_UPDATE_ONLY);
 }
 
 static int s32_pconf_group_set(struct pinctrl_dev *pctldev, unsigned int selector,
@@ -612,8 +628,8 @@ static int s32_pconf_group_set(struct pinctrl_dev *pctldev, unsigned int selecto
 
 	grp = &info->groups[selector];
 	for (i = 0; i < grp->data.npins; i++) {
-		ret = s32_pinconf_mscr_update(pctldev, grp->data.pins[i],
-					      configs, num_configs);
+		ret = s32_pinconf_mscr_write(pctldev, grp->data.pins[i],
+					      configs, num_configs, S32_PINCONF_OVERWRITE);
 		if (ret)
 			return ret;
 	}
-- 
2.45.2


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

* Re: [PATCH 0/3] add small improvements to the S32G pinctrl driver
  2024-07-23 13:18 [PATCH 0/3] add small improvements to the S32G pinctrl driver Andrei Stefanescu
                   ` (2 preceding siblings ...)
  2024-07-23 13:18 ` [PATCH 3/3] pinctrl: s32cc: add update and overwrite options when setting pinconf Andrei Stefanescu
@ 2024-08-05  8:18 ` Linus Walleij
  3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2024-08-05  8:18 UTC (permalink / raw)
  To: Andrei Stefanescu
  Cc: Dong Aisheng, Fabio Estevam, Shawn Guo, Jacky Bai,
	Pengutronix Kernel Team, Chester Lin, Matthias Brugger,
	Ghennadi Procopciuc, linux-arm-kernel, linux-gpio, linux-kernel,
	NXP S32 Linux Team

On Tue, Jul 23, 2024 at 3:20 PM Andrei Stefanescu
<andrei.stefanescu@oss.nxp.com> wrote:

> This patch series adds various small improvements to the pinctrl
> driver used by S32G SoCs. These can also be found in the
> downstream kernel version [1].
>
> [1] - https://github.com/nxp-auto-linux/linux

Patches applied!

Yours,
Linus Walleij

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

end of thread, other threads:[~2024-08-05  8:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 13:18 [PATCH 0/3] add small improvements to the S32G pinctrl driver Andrei Stefanescu
2024-07-23 13:18 ` [PATCH 1/3] pinctrl: s32cc: enable the input buffer for a GPIO Andrei Stefanescu
2024-07-23 13:18 ` [PATCH 2/3] pinctrl: s32cc: configure PIN_CONFIG_DRIVE_PUSH_PULL Andrei Stefanescu
2024-07-23 13:18 ` [PATCH 3/3] pinctrl: s32cc: add update and overwrite options when setting pinconf Andrei Stefanescu
2024-08-05  8:18 ` [PATCH 0/3] add small improvements to the S32G pinctrl driver Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).