* [PATCH 1/2] driver: register bus
@ 2012-09-19 13:39 Jean-Christophe PLAGNIOL-VILLARD
2012-09-19 13:39 ` [PATCH 2/2] driver: search device and driver based on the bus instead of all Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-19 13:39 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/base/Makefile | 1 +
drivers/base/bus.c | 37 +++++++++++++++++++++++++++++++++++++
drivers/base/platform.c | 14 ++++----------
drivers/i2c/i2c.c | 7 +++++++
drivers/net/phy/phy.c | 7 +++++++
drivers/spi/spi.c | 6 ++++++
drivers/usb/core/usb.c | 5 +++++
fs/fs.c | 6 ++++++
include/driver.h | 8 ++++++++
9 files changed, 81 insertions(+), 10 deletions(-)
create mode 100644 drivers/base/bus.c
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 957ca5a..e1f1c7a 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 0000000..1dd139f
--- /dev/null
+++ b/drivers/base/bus.c
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+ INIT_LIST_HEAD(&bus->device_list);
+ INIT_LIST_HEAD(&bus->driver_list);
+
+ list_add_tail(&bus->list, &bus_list);
+
+ return 0;
+}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index afeee05..d3021ab 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -19,6 +19,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)
{
@@ -61,15 +62,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 555722b..27fd256 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/net/phy/phy.c b/drivers/net/phy/phy.c
index bfebe3b..424de44 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -22,6 +22,7 @@
#include <net.h>
#include <malloc.h>
#include <miidev.h>
+#include <init.h>
#include <linux/phy.h>
#include <linux/err.h>
@@ -685,3 +686,9 @@ int phy_driver_register(struct phy_driver *phydrv)
return register_driver(&phydrv->drv);
}
+
+static int phy_bus_init(void)
+{
+ return bus_register(&phy_bustype);
+}
+pure_initcall(phy_bus_init);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 99a5069..17aae93 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -291,3 +291,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 662705e..9dc931b 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1418,3 +1418,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);
diff --git a/fs/fs.c b/fs/fs.c
index bbee124..b9a1f17 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1138,6 +1138,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 7c31c24..f89bfff 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -379,6 +379,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 {
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] driver: search device and driver based on the bus instead of all
2012-09-19 13:39 [PATCH 1/2] driver: register bus Jean-Christophe PLAGNIOL-VILLARD
@ 2012-09-19 13:39 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-19 17:25 ` Sascha Hauer
0 siblings, 1 reply; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-19 13:39 UTC (permalink / raw)
To: barebox
This will allow reduce the number of driver and device to search on.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/base/driver.c | 9 +++++----
include/driver.h | 12 ++++++++++++
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 18ac70c..8fade78 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -82,8 +82,6 @@ static int match(struct driver_d *drv, struct device_d *dev)
dev->driver = drv;
- if (dev->bus != drv->bus)
- goto err_out;
if (dev->bus->match(dev, drv))
goto err_out;
if (dev->bus->probe(dev))
@@ -129,12 +127,13 @@ int register_device(struct device_d *new_device)
}
list_add_tail(&new_device->list, &device_list);
+ list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
INIT_LIST_HEAD(&new_device->children);
INIT_LIST_HEAD(&new_device->cdevs);
INIT_LIST_HEAD(&new_device->parameters);
INIT_LIST_HEAD(&new_device->active);
- for_each_driver(drv) {
+ for_each_bus_driver(new_device->bus, drv) {
if (!match(drv, new_device))
break;
}
@@ -166,6 +165,7 @@ int unregister_device(struct device_d *old_dev)
}
list_del(&old_dev->list);
+ list_del(&old_dev->bus_list);
list_del(&old_dev->active);
/* remove device from parents child list */
@@ -219,13 +219,14 @@ int register_driver(struct driver_d *drv)
}
list_add_tail(&drv->list, &driver_list);
+ list_add_tail(&drv->bus_list, &drv->bus->driver_list);
if (!drv->info)
drv->info = noinfo;
if (!drv->shortinfo)
drv->shortinfo = noshortinfo;
- for_each_device(dev)
+ for_each_bus_device(drv->bus, dev)
match(drv, dev);
return 0;
diff --git a/include/driver.h b/include/driver.h
index f89bfff..10a2f10 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -88,6 +88,7 @@ struct device_d {
struct driver_d *driver; /*! The driver for this device */
struct list_head list; /* The list of all devices */
+ struct list_head bus_list; /* our bus */
struct list_head children; /* our children */
struct list_head sibling;
struct list_head active; /* The list of all devices which have a driver */
@@ -115,6 +116,7 @@ struct driver_d {
const char *name;
struct list_head list;
+ struct list_head bus_list; /* our bus */
/*! Called if an instance of a device is found */
int (*probe) (struct device_d *);
@@ -377,6 +379,8 @@ struct bus_type {
void (*remove)(struct device_d *dev);
struct list_head list;
+ struct list_head device_list;
+ struct list_head driver_list;
};
int bus_register(struct bus_type *bus);
@@ -387,6 +391,14 @@ extern struct list_head bus_list;
*/
#define for_each_bus(bus) list_for_each_entry(bus, &bus_list, list)
+/* Iterate over all devices of a bus
+ */
+#define for_each_bus_device(bus, dev) list_for_each_entry(dev, &bus->device_list, list)
+
+/* Iterate over all drivers of a bus
+ */
+#define for_each_bus_driver(bus, drv) list_for_each_entry(drv, &bus->driver_list, list)
+
extern struct bus_type platform_bus;
struct file_operations {
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] driver: search device and driver based on the bus instead of all
2012-09-19 13:39 ` [PATCH 2/2] driver: search device and driver based on the bus instead of all Jean-Christophe PLAGNIOL-VILLARD
@ 2012-09-19 17:25 ` Sascha Hauer
0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-09-19 17:25 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Wed, Sep 19, 2012 at 03:39:57PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> This will allow reduce the number of driver and device to search on.
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> drivers/base/driver.c | 9 +++++----
> include/driver.h | 12 ++++++++++++
> 2 files changed, 17 insertions(+), 4 deletions(-)
>
[...]
>
> +/* Iterate over all devices of a bus
> + */
> +#define for_each_bus_device(bus, dev) list_for_each_entry(dev, &bus->device_list, list)
> +
> +/* Iterate over all drivers of a bus
> + */
> +#define for_each_bus_driver(bus, drv) list_for_each_entry(drv, &bus->driver_list, list)
> +
bus_for_each_* please.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-19 17:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-19 13:39 [PATCH 1/2] driver: register bus Jean-Christophe PLAGNIOL-VILLARD
2012-09-19 13:39 ` [PATCH 2/2] driver: search device and driver based on the bus instead of all Jean-Christophe PLAGNIOL-VILLARD
2012-09-19 17:25 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox