X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fcore%2Flists.c;h=6fa5d1090ab0e0796bd3a1c820e8ebb7088dcccc;hb=24bf59d0243f0ee496b20aee985968729b8d0386;hp=afb59d1d8dd277f62601c225679064f341dbdfa5;hpb=b5b8d85e9a50c2294b6043830cd045de1002dc5d;p=u-boot diff --git a/drivers/core/lists.c b/drivers/core/lists.c index afb59d1d8d..6fa5d1090a 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -23,19 +24,9 @@ struct driver *lists_driver_lookup_name(const char *name) ll_entry_start(struct driver, driver); const int n_ents = ll_entry_count(struct driver, driver); struct driver *entry; - int len; - - if (!drv || !n_ents) - return NULL; - - len = strlen(name); for (entry = drv; entry != drv + n_ents; entry++) { - if (strncmp(name, entry->name, len)) - continue; - - /* Full match */ - if (len == strlen(entry->name)) + if (!strcmp(name, entry->name)) return entry; } @@ -50,9 +41,6 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id) const int n_ents = ll_entry_count(struct uclass_driver, uclass); struct uclass_driver *entry; - if ((id == UCLASS_INVALID) || !uclass) - return NULL; - for (entry = uclass; entry != uclass + n_ents; entry++) { if (entry->id == id) return entry; @@ -61,7 +49,7 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id) return NULL; } -int lists_bind_drivers(struct udevice *parent) +int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only) { struct driver_info *info = ll_entry_start(struct driver_info, driver_info); @@ -72,8 +60,8 @@ int lists_bind_drivers(struct udevice *parent) int ret; for (entry = info; entry != info + n_ents; entry++) { - ret = device_bind_by_name(parent, entry, &dev); - if (ret) { + ret = device_bind_by_name(parent, pre_reloc_only, entry, &dev); + if (ret && ret != -EPERM) { dm_warn("No match for driver '%s'\n", entry->name); if (!result || ret != -ENOENT) result = ret; @@ -83,74 +71,129 @@ int lists_bind_drivers(struct udevice *parent) return result; } -#ifdef CONFIG_OF_CONTROL +int device_bind_driver(struct udevice *parent, const char *drv_name, + const char *dev_name, struct udevice **devp) +{ + return device_bind_driver_to_node(parent, drv_name, dev_name, + ofnode_null(), devp); +} + +int device_bind_driver_to_node(struct udevice *parent, const char *drv_name, + const char *dev_name, ofnode node, + struct udevice **devp) +{ + struct driver *drv; + int ret; + + drv = lists_driver_lookup_name(drv_name); + if (!drv) { + debug("Cannot find driver '%s'\n", drv_name); + return -ENOENT; + } + ret = device_bind_with_driver_data(parent, drv, dev_name, 0 /* data */, + node, devp); + + return ret; +} + +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) /** - * driver_check_compatible() - Check if a driver is compatible with this node + * driver_check_compatible() - Check if a driver matches a compatible string * - * @param blob: Device tree pointer - * @param offset: Offset of node in device tree - * @param of_matchL List of compatible strings to match - * @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node - * does not have a compatible string, other error <0 if there is a device - * tree error + * @param of_match: List of compatible strings to match + * @param of_idp: Returns the match that was found + * @param compat: The compatible string to search for + * @return 0 if there is a match, -ENOENT if no match */ -static int driver_check_compatible(const void *blob, int offset, - const struct udevice_id *of_match) +static int driver_check_compatible(const struct udevice_id *of_match, + const struct udevice_id **of_idp, + const char *compat) { - int ret; - if (!of_match) return -ENOENT; while (of_match->compatible) { - ret = fdt_node_check_compatible(blob, offset, - of_match->compatible); - if (!ret) + if (!strcmp(of_match->compatible, compat)) { + *of_idp = of_match; return 0; - else if (ret == -FDT_ERR_NOTFOUND) - return -ENODEV; - else if (ret < 0) - return -EINVAL; + } of_match++; } return -ENOENT; } -int lists_bind_fdt(struct udevice *parent, const void *blob, int offset) +int lists_bind_fdt(struct udevice *parent, ofnode node, struct udevice **devp) { struct driver *driver = ll_entry_start(struct driver, driver); const int n_ents = ll_entry_count(struct driver, driver); + const struct udevice_id *id; struct driver *entry; struct udevice *dev; - const char *name; + bool found = false; + const char *name, *compat_list, *compat; + int compat_length, i; int result = 0; - int ret; + int ret = 0; + + if (devp) + *devp = NULL; + name = ofnode_get_name(node); + pr_debug("bind node %s\n", name); + + compat_list = ofnode_get_property(node, "compatible", &compat_length); + if (!compat_list) { + if (compat_length == -FDT_ERR_NOTFOUND) { + pr_debug("Device '%s' has no compatible string\n", + name); + return 0; + } - dm_dbg("bind node %s\n", fdt_get_name(blob, offset, NULL)); - for (entry = driver; entry != driver + n_ents; entry++) { - ret = driver_check_compatible(blob, offset, entry->of_match); - if (ret == -ENOENT) { - continue; - } else if (ret == -ENODEV) { - break; - } else if (ret) { - dm_warn("Device tree error at offset %d\n", offset); - if (!result || ret != -ENOENT) - result = ret; - break; + dm_warn("Device tree error at node '%s'\n", name); + return compat_length; + } + + /* + * Walk through the compatible string list, attempting to match each + * compatible string in order such that we match in order of priority + * from the first string to the last. + */ + for (i = 0; i < compat_length; i += strlen(compat) + 1) { + compat = compat_list + i; + pr_debug(" - attempt to match compatible string '%s'\n", + compat); + + for (entry = driver; entry != driver + n_ents; entry++) { + ret = driver_check_compatible(entry->of_match, &id, + compat); + if (!ret) + break; } + if (entry == driver + n_ents) + continue; - name = fdt_get_name(blob, offset, NULL); - dm_dbg(" - found match at '%s'\n", entry->name); - ret = device_bind(parent, entry, name, NULL, offset, &dev); + pr_debug(" - found match at '%s'\n", entry->name); + ret = device_bind_with_driver_data(parent, entry, name, + id->data, node, &dev); + if (ret == -ENODEV) { + pr_debug("Driver '%s' refuses to bind\n", entry->name); + continue; + } if (ret) { - dm_warn("No match for driver '%s'\n", entry->name); - if (!result || ret != -ENOENT) - result = ret; + dm_warn("Error binding driver '%s': %d\n", entry->name, + ret); + return ret; + } else { + found = true; + if (devp) + *devp = dev; } + break; } + if (!found && !result && ret != -ENODEV) + pr_debug("No match for node '%s'\n", name); + return result; } #endif