Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1314337 > unrolled thread

[TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects

Started byMans Rullgard <mans@mansr.com>
First post2016-01-21 17:40 +0100
Last post2016-01-21 18:30 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects Mans Rullgard <mans@mansr.com> - 2016-01-21 17:40 +0100
    Re: [TROLL PATCH] spi: add option to create spidev nodes for  unclaimed chip selects Geert Uytterhoeven <geert@linux-m68k.org> - 2016-01-21 18:20 +0100
      Re: [TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects Måns Rullgård <mans@mansr.com> - 2016-01-21 18:30 +0100

#1314337 — [TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects

FromMans Rullgard <mans@mansr.com>
Date2016-01-21 17:40 +0100
Subject[TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects
Message-ID<qTqr8-7RN-13@gated-at.bofh.it>
This adds an option to create spidev nodes for any chip selects not
bound to a driver via DT/ACPI.  It probably doesn't play nicely with
modules.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 drivers/spi/Kconfig |  4 ++++
 drivers/spi/spi.c   | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 8b9c2a38d1cc..4977fc2fbb30 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -689,6 +689,10 @@ config SPI_SPIDEV
 	  Note that this application programming interface is EXPERIMENTAL
 	  and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes.
 
+config SPI_SPIDEV_AUTO
+	bool "Create spidev nodes for unclaimed chip selects"
+	depends on SPI_SPIDEV
+
 config SPI_TLE62X0
 	tristate "Infineon TLE62X0 (for power switching)"
 	depends on SYSFS
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index dee1cb87d24f..8c0294387e6d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1654,6 +1654,34 @@ static void acpi_register_spi_devices(struct spi_master *master)
 static inline void acpi_register_spi_devices(struct spi_master *master) {}
 #endif /* CONFIG_ACPI */
 
+#ifdef CONFIG_SPI_SPIDEV_AUTO
+static void spidev_register_spi_devices(struct spi_master *master)
+{
+	struct spi_device *spi;
+	int err;
+	int i;
+
+	for (i = 0; i < master->num_chipselect; i++) {
+		spi = spi_alloc_device(master);
+		if (!spi)
+			return;
+
+		strlcpy(spi->modalias, "spidev", sizeof(spi->modalias));
+		spi->chip_select = i;
+
+		err = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);
+
+		if (!err)
+			err = spi_add_device(spi);
+
+		if (err)
+			spi_dev_put(spi);
+	}
+}
+#else
+static void spidev_register_spi_devices(struct spi_master *master) { }
+#endif
+
 static void spi_master_release(struct device *dev)
 {
 	struct spi_master *master;
@@ -1849,6 +1877,7 @@ int spi_register_master(struct spi_master *master)
 	/* Register devices from the device tree and ACPI */
 	of_register_spi_devices(master);
 	acpi_register_spi_devices(master);
+	spidev_register_spi_devices(master);
 done:
 	return status;
 }
-- 
2.7.0

[toc] | [next] | [standalone]


#1314363 — Re: [TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects

FromGeert Uytterhoeven <geert@linux-m68k.org>
Date2016-01-21 18:20 +0100
SubjectRe: [TROLL PATCH] spi: add option to create spidev nodes for unclaimed chip selects
Message-ID<qTr3Q-8oL-25@gated-at.bofh.it>
In reply to#1314337
On Thu, Jan 21, 2016 at 5:36 PM, Mans Rullgard <mans@mansr.com> wrote:
> This adds an option to create spidev nodes for any chip selects not
> bound to a driver via DT/ACPI.  It probably doesn't play nicely with
> modules.

And with pinmux, FWIW ;-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

[toc] | [prev] | [next] | [standalone]


#1314370

FromMåns Rullgård <mans@mansr.com>
Date2016-01-21 18:30 +0100
Message-ID<qTrdy-8tf-29@gated-at.bofh.it>
In reply to#1314363
Geert Uytterhoeven <geert@linux-m68k.org> writes:

> On Thu, Jan 21, 2016 at 5:36 PM, Mans Rullgard <mans@mansr.com> wrote:
>> This adds an option to create spidev nodes for any chip selects not
>> bound to a driver via DT/ACPI.  It probably doesn't play nicely with
>> modules.
>
> And with pinmux, FWIW ;-)

In my particular case, I can put whatever pinmux I want in the DT and
bring out the SPI signals, but I simply don't know what device will be
connected.

-- 
Måns Rullgård

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web