diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/Makefile | 1 | ||||
-rw-r--r-- | drivers/base/bus.c | 37 | ||||
-rw-r--r-- | drivers/base/driver.c | 63 | ||||
-rw-r--r-- | drivers/base/platform.c | 36 |
4 files changed, 120 insertions, 17 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..1dd139f7a3 --- /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/driver.c b/drivers/base/driver.c index 6cd428681f..c55fd23d76 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -85,8 +85,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)) @@ -116,18 +114,29 @@ int register_device(struct device_d *new_device) debug ("register_device: %s\n", dev_name(new_device)); - if (!new_device->bus) { -// dev_err(new_device, "no bus type associated. Needs fixup\n"); + if (!new_device->bus) new_device->bus = &platform_bus; + + if (new_device->bus == &platform_bus && new_device->resource) { + struct device_d *dev; + + bus_for_each_device(new_device->bus, dev) { + if (!dev->resource) + continue; + if (dev->resource->start == new_device->resource->start) { + return -EBUSY; + } + } } 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) { + bus_for_each_driver(new_device->bus, drv) { if (!match(drv, new_device)) break; } @@ -159,6 +168,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 */ @@ -212,13 +222,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) + bus_for_each_device(drv->bus, dev) match(drv, dev); return 0; @@ -313,6 +324,25 @@ const char *dev_id(const struct device_d *dev) return buf; } +int dev_printf(const struct device_d *dev, const char *format, ...) +{ + va_list args; + int ret = 0; + + if (dev->driver && dev->driver->name) + ret += printf("%s ", dev->driver->name); + + ret += printf("%s: ", dev_name(dev)); + + va_start(args, format); + + ret += vprintf(format, args); + + va_end(args); + + return ret; +} + void devices_shutdown(void) { struct device_d *dev; @@ -357,6 +387,21 @@ static int do_devinfo_subtree(struct device_d *dev, int depth) return 0; } +int dev_get_drvdata(struct device_d *dev, unsigned long *data) +{ + if (dev->of_id_entry) { + *data = dev->of_id_entry->data; + return 0; + } + + if (dev->id_entry) { + *data = dev->id_entry->driver_data; + return 0; + } + + return -ENODEV; +} + static int do_devinfo(int argc, char *argv[]) { struct device_d *dev; @@ -406,6 +451,12 @@ static int do_devinfo(int argc, char *argv[]) list_for_each_entry(param, &dev->parameters, list) printf("%16s = %s\n", param->name, dev_get_param(dev, param->name)); +#ifdef CONFIG_OFDEVICE + if (dev->device_node) { + printf("\ndevice node: %s\n", dev->device_node->full_name); + of_print_nodes(dev->device_node, 0); + } +#endif } return 0; diff --git a/drivers/base/platform.c b/drivers/base/platform.c index e0dd9ea58e..8c80e8e26d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -21,10 +21,31 @@ */ #include <common.h> #include <driver.h> +#include <errno.h> +#include <init.h> static int platform_match(struct device_d *dev, struct driver_d *drv) { - return strcmp(dev->name, drv->name) ? -1 : 0; + if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node && + drv->of_compatible) + return of_match(dev, drv); + + if (!strcmp(dev->name, drv->name)) + return 0; + + if (drv->id_table) { + struct platform_device_id *id = drv->id_table; + + while (id->name) { + if (!strcmp(id->name, dev->name)) { + dev->id_entry = id; + return 0; + } + id++; + } + } + + return -1; } static int platform_probe(struct device_d *dev) @@ -44,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); |