mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/5] SPI: Put SPI devices on their own bus bus
Date: Tue, 11 Sep 2012 15:31:50 +0200	[thread overview]
Message-ID: <1347370313-15184-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1347370313-15184-1-git-send-email-s.hauer@pengutronix.de>

This patch adds a SPI bus on which the SPI devices and drivers register.
This makes it cleaner as SPI devices won't accidently end up probed by
a platform_device driver.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/eeprom/at25.c |    2 +-
 drivers/mfd/mc13xxx.c |    2 +-
 drivers/mfd/mc34708.c |    2 +-
 drivers/nor/m25p80.c  |    2 +-
 drivers/spi/spi.c     |   24 ++++++++++++++++++++++++
 include/spi/spi.h     |    7 +++++++
 6 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
index 03d191e..5578c78 100644
--- a/drivers/eeprom/at25.c
+++ b/drivers/eeprom/at25.c
@@ -312,7 +312,7 @@ static struct driver_d at25_driver = {
 
 static int at25_init(void)
 {
-	register_driver(&at25_driver);
+	spi_register_driver(&at25_driver);
 	return 0;
 }
 
diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 58394a7..42ed960 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -367,7 +367,7 @@ static struct driver_d mc_spi_driver = {
 
 static int mc_spi_init(void)
 {
-	return register_driver(&mc_spi_driver);
+	return spi_register_driver(&mc_spi_driver);
 }
 
 device_initcall(mc_spi_init);
diff --git a/drivers/mfd/mc34708.c b/drivers/mfd/mc34708.c
index 02c58a9..75fff7b 100644
--- a/drivers/mfd/mc34708.c
+++ b/drivers/mfd/mc34708.c
@@ -289,7 +289,7 @@ static struct driver_d mc_spi_driver = {
 static int mc_init(void)
 {
         register_driver(&mc_i2c_driver);
-        register_driver(&mc_spi_driver);
+        spi_register_driver(&mc_spi_driver);
         return 0;
 }
 
diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index 5713ad5..f718483 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -838,7 +838,7 @@ static struct driver_d epcs_flash_driver = {
 
 static int epcs_init(void)
 {
-	register_driver(&epcs_flash_driver);
+	spi_register_driver(&epcs_flash_driver);
 	return 0;
 }
 
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a7fe10c..4416783 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -27,6 +27,7 @@
 #include <xfuncs.h>
 #include <malloc.h>
 #include <errno.h>
+#include <init.h>
 
 /* SPI devices should normally not be created by SPI device drivers; that
  * would make them board-specific.  Similarly with SPI master drivers.
@@ -77,6 +78,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
 	proxy->mode = chip->mode;
 	proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
 	proxy->dev.platform_data = chip->platform_data;
+	proxy->dev.bus = &spi_bus;
 	strcpy(proxy->dev.name, chip->name);
 	/* allocate a free id for this chip */
 	proxy->dev.id = DEVICE_ID_DYNAMIC;
@@ -240,3 +242,25 @@ int spi_write_then_read(struct spi_device *spi,
 	return status;
 }
 EXPORT_SYMBOL(spi_write_then_read);
+
+static int spi_match(struct device_d *dev, struct driver_d *drv)
+{
+	return strcmp(dev->name, drv->name) ? -1 : 0;
+}
+
+static int spi_probe(struct device_d *dev)
+{
+	return dev->driver->probe(dev);
+}
+
+static void spi_remove(struct device_d *dev)
+{
+	dev->driver->remove(dev);
+}
+
+struct bus_type spi_bus = {
+	.name = "spi",
+	.match = spi_match,
+	.probe = spi_probe,
+	.remove = spi_remove,
+};
diff --git a/include/spi/spi.h b/include/spi/spi.h
index 9d01d06..569cdcd 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -427,4 +427,11 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
 
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
+extern struct bus_type spi_bus;
+
+static inline int spi_register_driver(struct driver_d *drv)
+{
+	drv->bus = &spi_bus;
+	return register_driver(drv);
+}
 #endif /* __INCLUDE_SPI_H */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-09-11 13:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11 13:31 [PATCH] device/driver work Sascha Hauer
2012-09-11 13:31 ` [PATCH 1/5] mfd mc13xxx: Separate I2C and SPI probe Sascha Hauer
2012-09-11 13:31 ` Sascha Hauer [this message]
2012-09-11 14:03   ` [PATCH 2/5] SPI: Put SPI devices on their own bus bus Jean-Christophe PLAGNIOL-VILLARD
2012-09-11 14:26     ` Sascha Hauer
2012-09-11 13:31 ` [PATCH 3/5] I2C: Put I2C devices on their own bus Sascha Hauer
2012-09-11 14:04   ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11 14:27     ` Sascha Hauer
2012-09-11 15:56       ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11 16:10         ` Sascha Hauer
2012-09-11 17:24           ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-12  6:47             ` Sascha Hauer
2012-09-11 13:31 ` [PATCH 4/5] driver: rewrite dev_printf as a function Sascha Hauer
2012-09-11 13:31 ` [PATCH 5/5] driver: Add platform_device_id mechanism Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347370313-15184-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox