diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-09-20 07:36:44 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-23 21:15:13 +0200 |
commit | 72b0a6503f8519980a4734bcdbb35a9ec6cd6347 (patch) | |
tree | 12513db7ebad9cbe7ad92b0de96922e8bef7b763 | |
parent | 33a8fa16c68139c50e839f647cc0b34250c75193 (diff) | |
download | barebox-72b0a6503f8519980a4734bcdbb35a9ec6cd6347.tar.gz barebox-72b0a6503f8519980a4734bcdbb35a9ec6cd6347.tar.xz |
driver: register bus
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/base/Makefile | 1 | ||||
-rw-r--r-- | drivers/base/bus.c | 34 | ||||
-rw-r--r-- | drivers/base/platform.c | 14 | ||||
-rw-r--r-- | drivers/i2c/i2c.c | 7 | ||||
-rw-r--r-- | drivers/spi/spi.c | 6 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 5 | ||||
-rw-r--r-- | fs/fs.c | 6 | ||||
-rw-r--r-- | include/driver.h | 8 |
8 files changed, 71 insertions, 10 deletions
diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 957ca5ac2a..e1f1c7a0ad 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -1,3 +1,4 @@ +obj-y += bus.o obj-y += driver.o obj-y += platform.o obj-y += resource.o diff --git a/drivers/base/bus.c b/drivers/base/bus.c new file mode 100644 index 0000000000..f80363d5a7 --- /dev/null +++ b/drivers/base/bus.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> + * + * Under GPLv2 + */ + +#include <common.h> +#include <driver.h> +#include <errno.h> + +LIST_HEAD(bus_list); +EXPORT_SYMBOL(bus_list); + +struct bus_type *get_bus_by_name(const char *name) +{ + struct bus_type *bus; + + for_each_bus(bus) { + if(!strcmp(bus->name, name)) + return bus; + } + + return NULL; +} + +int bus_register(struct bus_type *bus) +{ + if (get_bus_by_name(bus->name)) + return -EEXIST; + + list_add_tail(&bus->list, &bus_list); + + return 0; +} diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9b0b1cc673..8c80e8e26d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -22,6 +22,7 @@ #include <common.h> #include <driver.h> #include <errno.h> +#include <init.h> static int platform_match(struct device_d *dev, struct driver_d *drv) { @@ -64,15 +65,8 @@ struct bus_type platform_bus = { .remove = platform_remove, }; -#if 0 -LIST_HEAD(bus_list); -EXPORT_SYMBOL(bus_list); - -int bus_register(struct bus_type *bus) +static int plarform_init(void) { - list_add_tail(&bus->list, &bus_list); - - return 0; + return bus_register(&platform_bus); } -#endif - +pure_initcall(plarform_init); diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index 555722b67f..27fd256cf7 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -21,6 +21,7 @@ #include <errno.h> #include <malloc.h> #include <xfuncs.h> +#include <init.h> #include <i2c/i2c.h> @@ -395,3 +396,9 @@ struct bus_type i2c_bus = { .probe = i2c_probe, .remove = i2c_remove, }; + +static int i2c_bus_init(void) +{ + return bus_register(&i2c_bus); +} +pure_initcall(i2c_bus_init); diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 215cc4e00d..61be38aca7 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -295,3 +295,9 @@ struct bus_type spi_bus = { .probe = spi_probe, .remove = spi_remove, }; + +static int spi_bus_init(void) +{ + return bus_register(&spi_bus); +} +pure_initcall(spi_bus_init); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 48bc121160..3ab06589d4 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -1422,3 +1422,8 @@ struct bus_type usb_bus_type = { .remove = usb_remove, }; +static int usb_bus_init(void) +{ + return bus_register(&usb_bus_type); +} +pure_initcall(usb_bus_init); @@ -1141,6 +1141,12 @@ struct bus_type fs_bus = { .remove = fs_remove, }; +static int fs_bus_init(void) +{ + return bus_register(&fs_bus); +} +pure_initcall(fs_bus_init); + int register_fs_driver(struct fs_driver_d *fsdrv) { fsdrv->drv.bus = &fs_bus; diff --git a/include/driver.h b/include/driver.h index 705e7d99f2..05670046f8 100644 --- a/include/driver.h +++ b/include/driver.h @@ -383,6 +383,14 @@ struct bus_type { struct list_head list; }; +int bus_register(struct bus_type *bus); + +extern struct list_head bus_list; + +/* Iterate over all buses + */ +#define for_each_bus(bus) list_for_each_entry(bus, &bus_list, list) + extern struct bus_type platform_bus; struct file_operations { |