linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spidev: Introduce "linux,spidev-name" property for device tree of spidev.
@ 2024-05-19 18:10 egyszeregy
  2024-05-19 20:35 ` kernel test robot
  2024-05-19 21:18 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: egyszeregy @ 2024-05-19 18:10 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel; +Cc: Benjamin Szőke

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

Optionally, spidev may have a "linux,spidev-name" property.
This is a string which is defining a custom suffix name for spi device in
/dev/spidev-<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/spi/spidev.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 95fb5f1c91c1..e0071522fc6d 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -767,6 +767,8 @@ MODULE_DEVICE_TABLE(acpi, spidev_acpi_ids);
 
 static int spidev_probe(struct spi_device *spi)
 {
+	int ret;
+	const char *name;
 	int (*match)(struct device *dev);
 	struct spidev_data	*spidev;
 	int			status;
@@ -800,9 +802,20 @@ static int spidev_probe(struct spi_device *spi)
 		struct device *dev;
 
 		spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
-		dev = device_create(&spidev_class, &spi->dev, spidev->devt,
-				    spidev, "spidev%d.%d",
-				    spi->controller->bus_num, spi_get_chipselect(spi, 0));
+
+		/*
+		 * If "linux,spidev-name" is specified in device tree, use /dev/spidev-<name>
+		 * in Linux userspace, otherwise use /dev/spidev<bus_num>.<cs_num>.
+		 */
+		ret = device_property_read_string(&spi->dev, "linux,spidev-name", &name);
+		if (ret < 0)
+			dev = device_create(spidev_class, &spi->dev, spidev->devt,
+					    spidev, "spidev%d.%d",
+					    spi->controller->bus_num, spi_get_chipselect(spi, 0));
+		else
+			dev = device_create(spidev_class, &spi->dev, spidev->devt,
+					    spidev, "spidev-%s", name);
+
 		status = PTR_ERR_OR_ZERO(dev);
 	} else {
 		dev_dbg(&spi->dev, "no minor number available!\n");
-- 
2.39.3


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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-19 18:10 [PATCH] spidev: Introduce "linux,spidev-name" property for device tree of spidev egyszeregy
2024-05-19 20:35 ` kernel test robot
2024-05-19 21:18 ` kernel test robot

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