dm: core: Combine the flattree and livetree binding code

At present there are two copies of this code. With ofnode we can combine
them to reduce duplication. Update the dm_scan_fdt_node() function and
adjust its callers.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-11-28 17:50:08 -07:00
parent d0c20ce6bc
commit 2ebea5eaeb

View file

@ -199,33 +199,6 @@ int dm_scan_platdata(bool pre_reloc_only)
} }
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int dm_scan_fdt_live(struct udevice *parent,
const struct device_node *node_parent,
bool pre_reloc_only)
{
struct device_node *np;
int ret = 0, err;
for (np = node_parent->child; np; np = np->sibling) {
if (!of_device_is_available(np)) {
pr_debug(" - ignoring disabled device\n");
continue;
}
err = lists_bind_fdt(parent, np_to_ofnode(np), NULL,
pre_reloc_only);
if (err && !ret) {
ret = err;
debug("%s: ret=%d\n", np->name, ret);
}
}
if (ret)
dm_warn("Some drivers failed to bind\n");
return ret;
}
/** /**
* dm_scan_fdt_node() - Scan the device tree and bind drivers for a node * dm_scan_fdt_node() - Scan the device tree and bind drivers for a node
* *
@ -233,28 +206,30 @@ static int dm_scan_fdt_live(struct udevice *parent,
* for each one. * for each one.
* *
* @parent: Parent device for the devices that will be created * @parent: Parent device for the devices that will be created
* @blob: Pointer to device tree blob * @node: Node to scan
* @offset: Offset of node to scan
* @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
* flag. If false bind all drivers. * flag. If false bind all drivers.
* @return 0 if OK, -ve on error * @return 0 if OK, -ve on error
*/ */
static int dm_scan_fdt_node(struct udevice *parent, const void *blob, static int dm_scan_fdt_node(struct udevice *parent, ofnode parent_node,
int offset, bool pre_reloc_only) bool pre_reloc_only)
{ {
int ret = 0, err; int ret = 0, err;
ofnode node;
for (offset = fdt_first_subnode(blob, offset); if (!ofnode_valid(parent_node))
offset > 0; return 0;
offset = fdt_next_subnode(blob, offset)) {
const char *node_name = fdt_get_name(blob, offset, NULL);
if (!fdtdec_get_is_enabled(blob, offset)) { for (node = ofnode_first_subnode(parent_node);
ofnode_valid(node);
node = ofnode_next_subnode(node)) {
const char *node_name = ofnode_get_name(node);
if (!ofnode_is_enabled(node)) {
pr_debug(" - ignoring disabled device\n"); pr_debug(" - ignoring disabled device\n");
continue; continue;
} }
err = lists_bind_fdt(parent, offset_to_ofnode(offset), NULL, err = lists_bind_fdt(parent, node, NULL, pre_reloc_only);
pre_reloc_only);
if (err && !ret) { if (err && !ret) {
ret = err; ret = err;
debug("%s: ret=%d\n", node_name, ret); debug("%s: ret=%d\n", node_name, ret);
@ -269,24 +244,13 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob,
int dm_scan_fdt_dev(struct udevice *dev) int dm_scan_fdt_dev(struct udevice *dev)
{ {
if (!dev_of_valid(dev)) return dm_scan_fdt_node(dev, dev_ofnode(dev),
return 0;
if (of_live_active())
return dm_scan_fdt_live(dev, dev_np(dev),
gd->flags & GD_FLG_RELOC ? false : true);
return dm_scan_fdt_node(dev, gd->fdt_blob, dev_of_offset(dev),
gd->flags & GD_FLG_RELOC ? false : true); gd->flags & GD_FLG_RELOC ? false : true);
} }
int dm_scan_fdt(const void *blob, bool pre_reloc_only) int dm_scan_fdt(const void *blob, bool pre_reloc_only)
{ {
if (of_live_active()) return dm_scan_fdt_node(gd->dm_root, ofnode_root(), pre_reloc_only);
return dm_scan_fdt_live(gd->dm_root, gd_of_root(),
pre_reloc_only);
return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
} }
static int dm_scan_fdt_ofnode_path(const void *blob, const char *path, static int dm_scan_fdt_ofnode_path(const void *blob, const char *path,
@ -295,14 +259,8 @@ static int dm_scan_fdt_ofnode_path(const void *blob, const char *path,
ofnode node; ofnode node;
node = ofnode_path(path); node = ofnode_path(path);
if (!ofnode_valid(node))
return 0;
if (of_live_active()) return dm_scan_fdt_node(gd->dm_root, node, pre_reloc_only);
return dm_scan_fdt_live(gd->dm_root, node.np, pre_reloc_only);
return dm_scan_fdt_node(gd->dm_root, blob, node.of_offset,
pre_reloc_only);
} }
int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only)