diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2009-02-26 00:51:19 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2009-04-07 10:42:33 +0200 |
commit | 4511a8873b3758970b6a3f2e55c27ad59223a3e5 (patch) | |
tree | 50be7f78407c569ea39301dc0bdb25bd8fc7a935 /lib | |
parent | 03c2189aa83c8db00f34908e0c6daf5b92b8f51f (diff) | |
download | barebox-4511a8873b3758970b6a3f2e55c27ad59223a3e5.tar.gz barebox-4511a8873b3758970b6a3f2e55c27ad59223a3e5.tar.xz |
we need different bus types
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/bus.c | 58 | ||||
-rw-r--r-- | lib/driver.c | 27 |
3 files changed, 79 insertions, 7 deletions
diff --git a/lib/Makefile b/lib/Makefile index 2828fbe114..c52b06facb 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -6,6 +6,7 @@ obj-y += vsprintf.o obj-y += div64.o obj-y += misc.o obj-y += driver.o +obj-y += bus.o obj-y += parameter.o obj-y += xfuncs.o obj-y += getopt.o diff --git a/lib/bus.c b/lib/bus.c new file mode 100644 index 0000000000..39170fe380 --- /dev/null +++ b/lib/bus.c @@ -0,0 +1,58 @@ +/* + * bus.c - U-Boot driver model + * + * Copyright (c) 2009 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <common.h> +#include <driver.h> + +static int platform_match(struct device_d *dev, struct driver_d *drv) +{ + return strcmp(dev->name, drv->name) ? -1 : 0; +} + +static int platform_probe(struct device_d *dev) +{ + return dev->driver->probe(dev); +} + +static int platform_remove(struct device_d *dev) +{ + return dev->driver->remove(dev); +} + +struct bus_type platform_bus = { + .name = "platform", + .match = platform_match, + .probe = platform_probe, + .remove = platform_remove, +}; + +#if 0 +LIST_HEAD(bus_list); +EXPORT_SYMBOL(bus_list); + +int bus_register(struct bus_type *bus) +{ + list_add_tail(&bus->list, &bus_list); + + return 0; +} +#endif + diff --git a/lib/driver.c b/lib/driver.c index 9f0b14945a..6f49ca97d5 100644 --- a/lib/driver.c +++ b/lib/driver.c @@ -70,18 +70,21 @@ int get_free_deviceid(char *id, const char *id_template) static int match(struct driver_d *drv, struct device_d *dev) { - if (strcmp(dev->name, drv->name)) - return -1; - if (dev->type != drv->type) - return -1; - if(drv->probe(dev)) - return -1; - 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)) + goto err_out; + list_add(&dev->active, &active); return 0; +err_out: + dev->driver = NULL; + return -1; } int register_device(struct device_d *new_device) @@ -94,6 +97,11 @@ int register_device(struct device_d *new_device) } debug ("register_device: %s\n",new_device->name); + if (!new_device->bus) { +// dev_err(new_device, "no bus type associated. Needs fixup\n"); + new_device->bus = &platform_bus; + } + list_add_tail(&new_device->list, &device_list); INIT_LIST_HEAD(&new_device->children); @@ -165,6 +173,11 @@ int register_driver(struct driver_d *drv) debug("register_driver: %s\n", drv->name); + if (!drv->bus) { +// pr_err("driver %s has no bus type associated. Needs fixup\n", drv->name); + drv->bus = &platform_bus; + } + list_add_tail(&drv->list, &driver_list); if (!drv->info) |