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>
This commit is contained in:
parent
4def29f141
commit
617bfbcbeb
|
@ -312,7 +312,7 @@ static struct driver_d at25_driver = {
|
||||||
|
|
||||||
static int at25_init(void)
|
static int at25_init(void)
|
||||||
{
|
{
|
||||||
register_driver(&at25_driver);
|
spi_register_driver(&at25_driver);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -423,7 +423,7 @@ static struct driver_d spi_mci_driver = {
|
||||||
|
|
||||||
static int spi_mci_init_driver(void)
|
static int spi_mci_init_driver(void)
|
||||||
{
|
{
|
||||||
register_driver(&spi_mci_driver);
|
spi_register_driver(&spi_mci_driver);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ static struct driver_d mc_spi_driver = {
|
||||||
|
|
||||||
static int mc_spi_init(void)
|
static int mc_spi_init(void)
|
||||||
{
|
{
|
||||||
return register_driver(&mc_spi_driver);
|
return spi_register_driver(&mc_spi_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
device_initcall(mc_spi_init);
|
device_initcall(mc_spi_init);
|
||||||
|
|
|
@ -298,7 +298,7 @@ static struct driver_d mc_spi_driver = {
|
||||||
|
|
||||||
static int mc_spi_init(void)
|
static int mc_spi_init(void)
|
||||||
{
|
{
|
||||||
return register_driver(&mc_spi_driver);
|
return spi_register_driver(&mc_spi_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
device_initcall(mc_spi_init);
|
device_initcall(mc_spi_init);
|
||||||
|
|
|
@ -838,7 +838,7 @@ static struct driver_d epcs_flash_driver = {
|
||||||
|
|
||||||
static int epcs_init(void)
|
static int epcs_init(void)
|
||||||
{
|
{
|
||||||
register_driver(&epcs_flash_driver);
|
spi_register_driver(&epcs_flash_driver);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <xfuncs.h>
|
#include <xfuncs.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <init.h>
|
||||||
|
|
||||||
/* SPI devices should normally not be created by SPI device drivers; that
|
/* SPI devices should normally not be created by SPI device drivers; that
|
||||||
* would make them board-specific. Similarly with SPI master drivers.
|
* 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->mode = chip->mode;
|
||||||
proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
|
proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
|
||||||
proxy->dev.platform_data = chip->platform_data;
|
proxy->dev.platform_data = chip->platform_data;
|
||||||
|
proxy->dev.bus = &spi_bus;
|
||||||
strcpy(proxy->dev.name, chip->name);
|
strcpy(proxy->dev.name, chip->name);
|
||||||
/* allocate a free id for this chip */
|
/* allocate a free id for this chip */
|
||||||
proxy->dev.id = DEVICE_ID_DYNAMIC;
|
proxy->dev.id = DEVICE_ID_DYNAMIC;
|
||||||
|
@ -240,3 +242,25 @@ int spi_write_then_read(struct spi_device *spi,
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(spi_write_then_read);
|
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,
|
||||||
|
};
|
||||||
|
|
|
@ -427,4 +427,11 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
|
||||||
|
|
||||||
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
|
#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 */
|
#endif /* __INCLUDE_SPI_H */
|
||||||
|
|
Loading…
Reference in New Issue