summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-08-14 10:06:00 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-09-14 11:47:24 +0200
commit617bfbcbeb3a278c76ab53e76b4fb7a086255a1e (patch)
tree6d586f6ec3b3b99d4059a776222516c30848908b /drivers/spi/spi.c
parent4def29f141c99d3d77bb7f5813cbd630d571e970 (diff)
downloadbarebox-617bfbcbeb3a278c76ab53e76b4fb7a086255a1e.tar.gz
barebox-617bfbcbeb3a278c76ab53e76b4fb7a086255a1e.tar.xz
SPI: Put SPI devices on their own bus
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> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a7fe10cba0..441678320c 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,
+};