Skip to contentSkip to conversation

gpio: tegra186: Simplify GPIO line name prefix handling

PATCH Applied Prathamesh Shete 5 participants 10 messages Feb 17 – Feb 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 gpio: tegra186: Simplify GPIO line name prefix handling

Introduce TEGRA_GPIO_PREFIX() to define the Tegra SoC GPIO name prefix in one place. Use it for the Tegra410 COMPUTE and SYSTEM controllers so the prefix is "COMPUTE-" and "SYSTEM-" respectively.

---
Changes in v2:
* Split the v1 patch into two; this one to simplify prefix handling.

---
 drivers/gpio/gpio-tegra186.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpio/gpio-tegra186.c +7 -8
index 9c874f07be75..f04cc240b5ec 100644
@@ -942,12 +942,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 		char *name;
 
 		for (j = 0; j < port->pins; j++) {
-			if (gpio->soc->prefix)
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%s-P%s.%02x",
-						      gpio->soc->prefix, port->name, j);
-			else
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "P%s.%02x",
-						      port->name, j);
+			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%sP%s.%02x",
+					      gpio->soc->prefix ?: "", port->name, j);
 			if (!name)
 				return -ENOMEM;
 
@@ -1373,6 +1369,9 @@ static const struct tegra_gpio_soc tegra256_main_soc = {
 	.has_vm_support = true,
 };
 
+/* Macro to define GPIO name prefix with separator */
+#define TEGRA_GPIO_PREFIX(_x)	_x "-"
+
 #define TEGRA410_COMPUTE_GPIO_PORT(_name, _bank, _port, _pins)	\
 	TEGRA_GPIO_PORT(TEGRA410_COMPUTE, _name, _bank, _port, _pins)
 
@@ -1388,7 +1387,7 @@ static const struct tegra_gpio_soc tegra410_compute_soc = {
 	.num_ports = ARRAY_SIZE(tegra410_compute_ports),
 	.ports = tegra410_compute_ports,
 	.name = "tegra410-gpio-compute",
-	.prefix = "COMPUTE",
+	.prefix = TEGRA_GPIO_PREFIX("COMPUTE"),
 	.num_irqs_per_bank = 8,
 	.instance = 0,
 };
@@ -1418,7 +1417,7 @@ static const struct tegra_gpio_soc tegra410_system_soc = {
 	.num_ports = ARRAY_SIZE(tegra410_system_ports),
 	.ports = tegra410_system_ports,
 	.name = "tegra410-gpio-system",
-	.prefix = "SYSTEM",
+	.prefix = TEGRA_GPIO_PREFIX("SYSTEM"),
 	.num_irqs_per_bank = 8,
 	.instance = 0,
 };
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/2 gpio: tegra186: Support multi-socket devices

On Tegra platforms, multiple SoC instances may be present with each defining the same GPIO name. For such devices, this results in duplicate GPIO names.

When the device has a valid NUMA node, prepend the NUMA node ID to the GPIO name prefix. The node ID identifies each socket, ensuring GPIO line names remain distinct across multiple sockets.

---
Changes in v2:
* Split the v1 patch into two; this one to support multi-socket devices.

---
 drivers/gpio/gpio-tegra186.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpio/gpio-tegra186.c +13 -3
index f04cc240b5ec..fb26402b6c47 100644
@@ -857,7 +857,7 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	struct device_node *np;
 	struct resource *res;
 	char **names;
-	int err;
+	int node, err;
 
 	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
 	if (!gpio)
@@ -937,13 +937,23 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!names)
 		return -ENOMEM;
 
+	node = dev_to_node(&pdev->dev);
+
 	for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
 		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
 		char *name;
 
 		for (j = 0; j < port->pins; j++) {
-			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%sP%s.%02x",
-					      gpio->soc->prefix ?: "", port->name, j);
+			if (node >= 0)
+				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
+						      "%d-%sP%s.%02x", node,
+						      gpio->soc->prefix ?: "",
+						      port->name, j);
+			else
+				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
+						      "%sP%s.%02x",
+						      gpio->soc->prefix ?: "",
+						      port->name, j);
 			if (!name)
 				return -ENOMEM;
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] gpio: tegra186: Support multi-socket devices

Quoted 45 lines · Prathamesh Shete

On Tegra platforms, multiple SoC instances may be present with each defining the same GPIO name. For such devices, this results in duplicate GPIO names.

When the device has a valid NUMA node, prepend the NUMA node ID to the GPIO name prefix. The node ID identifies each socket, ensuring GPIO line names remain distinct across multiple sockets.

---
Changes in v2:
* Split the v1 patch into two; this one to support multi-socket devices.

---
  drivers/gpio/gpio-tegra186.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpio/gpio-tegra186.c +6 -3
index f04cc240b5ec..fb26402b6c47 100644
@@ -857,7 +857,7 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
  	struct device_node *np;
  	struct resource *res;
  	char **names;
-	int err;
+	int node, err;
 
  	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
  	if (!gpio)
@@ -937,13 +937,23 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
  	if (!names)
  		return -ENOMEM;
 
+	node = dev_to_node(&pdev->dev);
+
  	for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
  		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  		char *name;
 
  		for (j = 0; j < port->pins; j++) {
-			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%sP%s.%02x",
-					      gpio->soc->prefix ?: "", port->name, j);
+			if (node >= 0)
+				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
+						      "%d-%sP%s.%02x", node,

drivers/gpio/gpio-tegra186.c static int tegra186_gpio_probe(struct platform_device *pdev) · line 959

Quoted 10 lines
drivers/gpio/gpio-tegra186.c +7 -0
+						      gpio->soc->prefix ?: "",
+						      port->name, j);
+			else
+				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
+						      "%sP%s.%02x",
+						      gpio->soc->prefix ?: "",
+						      port->name, j);
  			if (!name)
  				return -ENOMEM;
 

Thanks!
Jon

Signature · 1 line
nvpublic
maintainer Acked-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] gpio: tegra186: Support multi-socket devices

In reply to Prathamesh Shete
Quoted 8 lines · Prathamesh Shete

On Tegra platforms, multiple SoC instances may be present with each defining the same GPIO name. For such devices, this results in duplicate GPIO names.

When the device has a valid NUMA node, prepend the NUMA node ID to the GPIO name prefix. The node ID identifies each socket, ensuring GPIO line names remain distinct across multiple sockets.

Quoted 7 lines

---
Changes in v2:
* Split the v1 patch into two; this one to support multi-socket devices.

---
 drivers/gpio/gpio-tegra186.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
maintainer Reviewed-by on v2 1/2
#4 lore raw
In reply to Prathamesh Shete
Quoted 51 lines · Prathamesh Shete

Introduce TEGRA_GPIO_PREFIX() to define the Tegra SoC GPIO name prefix in one place. Use it for the Tegra410 COMPUTE and SYSTEM controllers so the prefix is "COMPUTE-" and "SYSTEM-" respectively.

---
Changes in v2:
* Split the v1 patch into two; this one to simplify prefix handling.

---
  drivers/gpio/gpio-tegra186.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpio/gpio-tegra186.c +6 -7
index 9c874f07be75..f04cc240b5ec 100644
@@ -942,12 +942,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
  		char *name;
 
  		for (j = 0; j < port->pins; j++) {
-			if (gpio->soc->prefix)
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%s-P%s.%02x",
-						      gpio->soc->prefix, port->name, j);
-			else
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "P%s.%02x",
-						      port->name, j);
+			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%sP%s.%02x",
+					      gpio->soc->prefix ?: "", port->name, j);
  			if (!name)
  				return -ENOMEM;
 
@@ -1373,6 +1369,9 @@ static const struct tegra_gpio_soc tegra256_main_soc = {
  	.has_vm_support = true,
  };
 
+/* Macro to define GPIO name prefix with separator */
+#define TEGRA_GPIO_PREFIX(_x)	_x "-"
+
  #define TEGRA410_COMPUTE_GPIO_PORT(_name, _bank, _port, _pins)	\
  	TEGRA_GPIO_PORT(TEGRA410_COMPUTE, _name, _bank, _port, _pins)
 
@@ -1388,7 +1387,7 @@ static const struct tegra_gpio_soc tegra410_compute_soc = {
  	.num_ports = ARRAY_SIZE(tegra410_compute_ports),
  	.ports = tegra410_compute_ports,
  	.name = "tegra410-gpio-compute",
-	.prefix = "COMPUTE",
+	.prefix = TEGRA_GPIO_PREFIX("COMPUTE"),
  	.num_irqs_per_bank = 8,
  	.instance = 0,
  };

drivers/gpio/gpio-tegra186.c static const struct tegra_gpio_soc tegra410_system_soc = { · line 1423

Quoted 8 lines
drivers/gpio/gpio-tegra186.c +1 -1
@@ -1418,7 +1417,7 @@ static const struct tegra_gpio_soc tegra410_system_soc = {
  	.num_ports = ARRAY_SIZE(tegra410_system_ports),
  	.ports = tegra410_system_ports,
  	.name = "tegra410-gpio-system",
-	.prefix = "SYSTEM",
+	.prefix = TEGRA_GPIO_PREFIX("SYSTEM"),
  	.num_irqs_per_bank = 8,
  	.instance = 0,
  };

Thanks!
Jon

Signature · 1 line
nvpublic
maintainer Acked-by on v2 1/2
#5 lore raw
In reply to Prathamesh Shete
Quoted 11 lines · Prathamesh Shete

Introduce TEGRA_GPIO_PREFIX() to define the Tegra SoC GPIO name prefix in one place. Use it for the Tegra410 COMPUTE and SYSTEM controllers so the prefix is "COMPUTE-" and "SYSTEM-" respectively.

---
Changes in v2:
* Split the v1 patch into two; this one to simplify prefix handling.

---
 drivers/gpio/gpio-tegra186.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
#6 lore raw
In reply to Prathamesh Shete
Quoted 60 lines · Prathamesh Shete

Introduce TEGRA_GPIO_PREFIX() to define the Tegra SoC GPIO name prefix in one place. Use it for the Tegra410 COMPUTE and SYSTEM controllers so the prefix is "COMPUTE-" and "SYSTEM-" respectively.

---
Changes in v2:
* Split the v1 patch into two; this one to simplify prefix handling.

---
 drivers/gpio/gpio-tegra186.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpio/gpio-tegra186.c +7 -9
index 9c874f07be75..f04cc240b5ec 100644
@@ -942,12 +942,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 		char *name;
 
 		for (j = 0; j < port->pins; j++) {
-			if (gpio->soc->prefix)
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%s-P%s.%02x",
-						      gpio->soc->prefix, port->name, j);
-			else
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "P%s.%02x",
-						      port->name, j);
+			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%sP%s.%02x",
+					      gpio->soc->prefix ?: "", port->name, j);
 			if (!name)
 				return -ENOMEM;
 
@@ -1373,6 +1369,9 @@ static const struct tegra_gpio_soc tegra256_main_soc = {
 	.has_vm_support = true,
 };
 
+/* Macro to define GPIO name prefix with separator */
+#define TEGRA_GPIO_PREFIX(_x)	_x "-"
+
 #define TEGRA410_COMPUTE_GPIO_PORT(_name, _bank, _port, _pins)	\
 	TEGRA_GPIO_PORT(TEGRA410_COMPUTE, _name, _bank, _port, _pins)
 
@@ -1388,7 +1387,7 @@ static const struct tegra_gpio_soc tegra410_compute_soc = {
 	.num_ports = ARRAY_SIZE(tegra410_compute_ports),
 	.ports = tegra410_compute_ports,
 	.name = "tegra410-gpio-compute",
-	.prefix = "COMPUTE",
+	.prefix = TEGRA_GPIO_PREFIX("COMPUTE"),
 	.num_irqs_per_bank = 8,
 	.instance = 0,
 };
@@ -1418,7 +1417,7 @@ static const struct tegra_gpio_soc tegra410_system_soc = {
 	.num_ports = ARRAY_SIZE(tegra410_system_ports),
 	.ports = tegra410_system_ports,
 	.name = "tegra410-gpio-system",
-	.prefix = "SYSTEM",
+	.prefix = TEGRA_GPIO_PREFIX("SYSTEM"),
 	.num_irqs_per_bank = 8,
 	.instance = 0,
 };
--
Quoted 3 lines

2.43.0

I'm perfectly fine with patch 2/2 but this one is giving me a hard time. What are we really gaining other than some questionable obfuscation? Keeping the dash in the format string makes more sense to me and if we ever reuse the prefix, we'll need to remember about it trimming it. I would drop this patch and keep just 2/2.

Bartosz

maintainer
#7 lore raw
Quoted 62 lines · Bartosz Golaszewski
Quoted 61 lines · Prathamesh Shete

Introduce TEGRA_GPIO_PREFIX() to define the Tegra SoC GPIO name prefix in one place. Use it for the Tegra410 COMPUTE and SYSTEM controllers so the prefix is "COMPUTE-" and "SYSTEM-" respectively.

---
Changes in v2:
* Split the v1 patch into two; this one to simplify prefix handling.

---
  drivers/gpio/gpio-tegra186.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpio/gpio-tegra186.c +7 -9
index 9c874f07be75..f04cc240b5ec 100644
@@ -942,12 +942,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
  		char *name;
 
  		for (j = 0; j < port->pins; j++) {
-			if (gpio->soc->prefix)
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%s-P%s.%02x",
-						      gpio->soc->prefix, port->name, j);
-			else
-				name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "P%s.%02x",
-						      port->name, j);
+			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%sP%s.%02x",
+					      gpio->soc->prefix ?: "", port->name, j);
  			if (!name)
  				return -ENOMEM;
 
@@ -1373,6 +1369,9 @@ static const struct tegra_gpio_soc tegra256_main_soc = {
  	.has_vm_support = true,
  };
 
+/* Macro to define GPIO name prefix with separator */
+#define TEGRA_GPIO_PREFIX(_x)	_x "-"
+
  #define TEGRA410_COMPUTE_GPIO_PORT(_name, _bank, _port, _pins)	\
  	TEGRA_GPIO_PORT(TEGRA410_COMPUTE, _name, _bank, _port, _pins)
 
@@ -1388,7 +1387,7 @@ static const struct tegra_gpio_soc tegra410_compute_soc = {
  	.num_ports = ARRAY_SIZE(tegra410_compute_ports),
  	.ports = tegra410_compute_ports,
  	.name = "tegra410-gpio-compute",
-	.prefix = "COMPUTE",
+	.prefix = TEGRA_GPIO_PREFIX("COMPUTE"),
  	.num_irqs_per_bank = 8,
  	.instance = 0,
  };
@@ -1418,7 +1417,7 @@ static const struct tegra_gpio_soc tegra410_system_soc = {
  	.num_ports = ARRAY_SIZE(tegra410_system_ports),
  	.ports = tegra410_system_ports,
  	.name = "tegra410-gpio-system",
-	.prefix = "SYSTEM",
+	.prefix = TEGRA_GPIO_PREFIX("SYSTEM"),
  	.num_irqs_per_bank = 8,
  	.instance = 0,
  };
--

2.43.0

Quoted 8 lines
Quoted 2 lines

I'm perfectly fine with patch 2/2 but this one is giving me a hard time. What are we really gaining other than some questionable obfuscation? Keeping the dash in the format string makes more sense to me and if we ever reuse the prefix, we'll need to remember about it trimming it. I would drop this patch and keep just 2/2.

What we are gaining is by adding the '-' to the prefix directly in the tegra_gpio_soc structure, is that we no longer need the if-else clause in the code to add the dash if the prefix is valid. And this allows us to use the ternary operator instead.

If we drop this patch, then after patch 2/2, we will end up with nested if-else clauses to handle the prefix and multi-socket cases.

Jon

Signature · 1 line
nvpublic
#8 lore raw
Quoted 8 lines · Jon Hunter
Quoted 7 lines

I'm perfectly fine with patch 2/2 but this one is giving me a hard time. What are we really gaining other than some questionable obfuscation? Keeping the dash in the format string makes more sense to me and if we ever reuse the prefix, we'll need to remember about it trimming it. I would drop this patch and keep just 2/2.

Quoted 8 lines

What we are gaining is by adding the '-' to the prefix directly in the tegra_gpio_soc structure, is that we no longer need the if-else clause in the code to add the dash if the prefix is valid. And this allows us to use the ternary operator instead.

If we drop this patch, then after patch 2/2, we will end up with nested if-else clauses to handle the prefix and multi-socket cases.

I see. Ok, will pick this up after v7.0-rc1.

Bart

#9 lore raw
In reply to Prathamesh Shete
Quoted 5 lines · Prathamesh Shete

Introduce TEGRA_GPIO_PREFIX() to define the Tegra SoC GPIO name prefix in one place. Use it for the Tegra410 COMPUTE and SYSTEM controllers so the prefix is "COMPUTE-" and "SYSTEM-" respectively.

Applied, thanks!

[1/2] gpio: tegra186: Simplify GPIO line name prefix handling

      https://git.kernel.org/brgl/c/2423e336d94868f0d2fcd81a87b90c5ea59736e0
[2/2] gpio: tegra186: Support multi-socket devices
      https://git.kernel.org/brgl/c/2c299030c6813eaa9ef95773c64d65c50fa706ac

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>