diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-08-09 19:12:34 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-14 11:47:42 +0200 |
commit | 58f3457f4f03313a7bab58f36382d57048fbe1c1 (patch) | |
tree | 9662cc78ea52a8a2efb9c3dc4b8d8a0e011f47b2 /drivers/base | |
parent | b2a13798a6c68c03ef87fbfdf66f2a942edebabd (diff) | |
download | barebox-58f3457f4f03313a7bab58f36382d57048fbe1c1.tar.gz barebox-58f3457f4f03313a7bab58f36382d57048fbe1c1.tar.xz |
of: add devicetree probing support
This adds code to probe devices from a devicetree. Most helper
functions are directly imported from Linux.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/driver.c | 25 | ||||
-rw-r--r-- | drivers/base/platform.c | 5 |
2 files changed, 28 insertions, 2 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 4d6b2505c2..e3a7bf291c 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -116,9 +116,19 @@ 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; + + for_each_device(dev) { + if (!dev->resource) + continue; + if (dev->resource->start == new_device->resource->start) { + return -EBUSY; + } + } } list_add_tail(&new_device->list, &device_list); @@ -378,6 +388,11 @@ static int do_devinfo_subtree(struct device_d *dev, int depth) 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; @@ -435,6 +450,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 82d2521a2e..9b0b1cc673 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -21,9 +21,14 @@ */ #include <common.h> #include <driver.h> +#include <errno.h> static int platform_match(struct device_d *dev, struct driver_d *drv) { + if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node && + drv->of_compatible) + return of_match(dev, drv); + if (!strcmp(dev->name, drv->name)) return 0; |