int pmic_bind_children(struct udevice *pmic, ofnode parent, const struct pmic_child_info *child_info) { const struct pmic_child_info *info; struct driver *drv; struct udevice *child; const char *node_name; int bind_count = 0; ofnode node; int prefix_len; int ret; debug("%s for '%s' at node offset: %d\n", __func__, pmic->name, dev_of_offset(pmic)); ofnode_for_each_subnode(node, parent) { node_name = ofnode_get_name(node); debug("* Found child node: '%s'\n", node_name); child = NULL; for (info = child_info; info->prefix && info->driver; info++) { debug(" - compatible prefix: '%s'\n", info->prefix); prefix_len = strlen(info->prefix); if (strncmp(info->prefix, node_name, prefix_len)) continue; drv = lists_driver_lookup_name(info->driver); if (!drv) { debug(" - driver: '%s' not found!\n", info->driver); continue; } debug(" - found child driver: '%s'\n", drv->name); ret = device_bind_with_driver_data(pmic, drv, node_name, 0, node, &child); if (ret) { debug(" - child binding error: %d\n", ret); continue; } debug(" - bound child device: '%s'\n", child->name); child->driver_data = trailing_strtol(node_name); debug(" - set 'child->driver_data': %lu\n", child->driver_data); break; } if (child) bind_count++; else debug(" - compatible prefix not found\n"); }
int lists_bind_fdt(struct udevice *parent, const void *blob, int offset, 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; bool found = false; const char *name; int result = 0; int ret = 0; dm_dbg("bind node %s\n", fdt_get_name(blob, offset, NULL)); if (devp) *devp = NULL; for (entry = driver; entry != driver + n_ents; entry++) { ret = driver_check_compatible(blob, offset, entry->of_match, &id); name = fdt_get_name(blob, offset, NULL); if (ret == -ENOENT) { continue; } else if (ret == -ENODEV) { dm_dbg("Device '%s' has no compatible string\n", name); break; } else if (ret) { dm_warn("Device tree error at offset %d\n", offset); result = ret; break; } dm_dbg(" - found match at '%s'\n", entry->name); ret = device_bind_with_driver_data(parent, entry, name, id->data, offset, &dev); if (ret == -ENODEV) { dm_dbg("Driver '%s' refuses to bind\n", entry->name); continue; } if (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) { dm_dbg("No match for node '%s'\n", fdt_get_name(blob, offset, NULL)); } return result; }