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 device_bind_driver(struct udevice *parent, const char *drv_name, const char *dev_name, struct udevice **devp) { struct driver *drv; int ret; drv = lists_driver_lookup_name(drv_name); if (!drv) { printf("Cannot find driver '%s'\n", drv_name); return -ENOENT; } ret = device_bind(parent, drv, dev_name, NULL, -1, devp); if (ret) { printf("Cannot create device named '%s' (err=%d)\n", dev_name, ret); return ret; } return 0; }