linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: Introduce "linux,gpiochip-name" property for device tree of GPIO controller.
@ 2024-05-19 14:49 egyszeregy
  2024-05-19 17:27 ` Bartosz Golaszewski
  0 siblings, 1 reply; 4+ messages in thread
From: egyszeregy @ 2024-05-19 14:49 UTC (permalink / raw)
  To: linus.walleij, brgl, linux-gpio, linux-kernel; +Cc: Benjamin Szőke

From: Benjamin Szőke <egyszeregy@freemail.hu>

Optionally, a GPIO controller may have a "linux,gpiochip-name" property.
This is a string which is defining a custom suffix name for gpiochip in
/dev/gpiochip-<name> format. It helps to improve software portability
between various SoCs and reduce complexities of hardware related codes
in SWs.

Signed-off-by: Benjamin Szőke <egyszeregy@freemail.hu>
---
 drivers/gpio/gpiolib.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index ce94e37bcbee..e24d8db1d054 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -860,6 +860,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 			       struct lock_class_key *lock_key,
 			       struct lock_class_key *request_key)
 {
+	const char *name;
 	struct gpio_device *gdev;
 	unsigned int desc_index;
 	int base = 0;
@@ -896,7 +897,16 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 		goto err_free_gdev;
 	}
 
-	ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);
+	/*
+	 * If "linux,gpiochip-name" is specified in device tree, use /dev/gpiochip-<name>
+	 * in Linux userspace, otherwise use /dev/gpiochip<id>.
+	 */
+	ret = device_property_read_string(gc->parent, "linux,gpiochip-name", &name);
+	if (ret < 0)
+		ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);
+	else
+		ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "-%s", name);
+
 	if (ret)
 		goto err_free_ida;
 
-- 
2.39.3


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

end of thread, other threads:[~2024-05-21 11:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-19 14:49 [PATCH] gpiolib: Introduce "linux,gpiochip-name" property for device tree of GPIO controller egyszeregy
2024-05-19 17:27 ` Bartosz Golaszewski
2024-05-20 16:41   ` Szőke Benjamin
2024-05-21 11:36     ` Bartosz Golaszewski

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).