diff mbox

[PATCHv2,3/3] spi: Use stable dev_name for ACPI enumerated SPI slaves

Message ID 1383309356-25430-4-git-send-email-jarkko.nikula@linux.intel.com
State Superseded
Headers show

Commit Message

Jarkko Nikula Nov. 1, 2013, 12:35 p.m. UTC
Current spi bus_num.chip_select "spix.y" based device naming scheme may not
be stable enough to be used in name based matching, for instance within
ALSA SoC subsystem.

This can be problem in PC kind of platforms if there are changes in SPI bus
configuration, amount of busses or probe order.

This patch addresses the problem by using the ACPI device name with
"spi-" prefix for ACPI enumerated SPI slave. For them device name
"spix.y" becomes "spi-INTABCD:ij".

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/spi/spi.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Comments

Mark Brown Nov. 1, 2013, 6:03 p.m. UTC | #1
On Fri, Nov 01, 2013 at 02:35:56PM +0200, Jarkko Nikula wrote:
> Current spi bus_num.chip_select "spix.y" based device naming scheme may not
> be stable enough to be used in name based matching, for instance within
> ALSA SoC subsystem.

Acked-by: Mark Brown <broonie@linaro.org>
diff mbox

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 740f9dd..4c0c801 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -38,6 +38,7 @@ 
 #include <linux/kthread.h>
 #include <linux/ioport.h>
 #include <linux/acpi.h>
+#include <acpi/acpi_bus.h>
 
 static void spidev_release(struct device *dev)
 {
@@ -352,6 +353,21 @@  struct spi_device *spi_alloc_device(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_alloc_device);
 
+void spi_dev_set_name(struct spi_device *spi)
+{
+	if (ACPI_HANDLE(&spi->dev)) {
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&spi->dev), &adev)) {
+			dev_set_name(&spi->dev, "spi-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+
+	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
+		     spi->chip_select);
+}
+
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -378,9 +394,7 @@  int spi_add_device(struct spi_device *spi)
 	}
 
 	/* Set the bus ID string */
-	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
-			spi->chip_select);
-
+	spi_dev_set_name(spi);
 
 	/* We need to make sure there's no other device with this
 	 * chipselect **BEFORE** we call setup(), else we'll trash