From: Simon Glass Date: Tue, 17 Jan 2017 22:51:49 -0700 Subject: [U-Boot] [PATCH 13/22] dm: core: Scan the live tree when setting up driver model In-Reply-To: <20170118055200.6825-6-sjg@chromium.org> References: <20170118055200.6825-6-sjg@chromium.org> Message-ID: <20170118055200.6825-14-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de When starting up driver model with a live tree we need to scan the tree for devices. Add code to handle this. Signed-off-by: Simon Glass --- drivers/core/root.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/core/root.c b/drivers/core/root.c index cd09c55d9d2..b15376a9859 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -12,9 +12,13 @@ #include #include #include +#include #include #include #include +#include +#include +#include #include #include #include @@ -165,7 +169,11 @@ int dm_init(void) if (ret) return ret; #if CONFIG_IS_ENABLED(OF_CONTROL) +# if defined(CONFIG_OF_LIVE) + DM_ROOT_NON_CONST->node_ref = of_node_to_ref(gd->of_root); +# else DM_ROOT_NON_CONST->of_offset = 0; +# endif #endif ret = device_probe(DM_ROOT_NON_CONST); if (ret) @@ -195,6 +203,36 @@ int dm_scan_platdata(bool pre_reloc_only) return ret; } +#ifdef CONFIG_OF_LIVE +static int dm_scan_fdt_live(struct udevice *parent, + 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 (pre_reloc_only && + !of_find_property(np, "u-boot,dm-pre-reloc", NULL)) + continue; + if (!of_device_is_available(np)) { + dm_dbg(" - ignoring disabled device\n"); + continue; + } + err = lists_bind_node(parent, np, NULL); + 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; +} +#endif /* CONFIG_OF_LIVE */ + #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) /** * dm_scan_fdt_node() - Scan the device tree and bind drivers for a node @@ -249,6 +287,12 @@ int dm_scan_fdt_dev(struct udevice *dev) int dm_scan_fdt(const void *blob, bool pre_reloc_only) { +#ifdef CONFIG_OF_LIVE + if (of_use_livetree()) + return dm_scan_fdt_live(gd->dm_root, gd->of_root, + pre_reloc_only); + else +#endif return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only); } #endif -- 2.11.0.483.g087da7b7c-goog