From d0c20ce6bcb9af3d70ed6ada618607ca1099e811 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:07 -0700 Subject: dm: core: Add an ofnode function to get the devicetree root This is needed in at least one place. Avoid the conditional code in root.c by adding this inline function. Signed-off-by: Simon Glass --- drivers/core/root.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 5f10d7a39c7..9ee65504e6e 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -147,12 +147,8 @@ int dm_init(bool of_live) ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST); if (ret) return ret; -#if CONFIG_IS_ENABLED(OF_CONTROL) - if (CONFIG_IS_ENABLED(OF_LIVE) && of_live) - DM_ROOT_NON_CONST->node = np_to_ofnode(gd_of_root()); - else - DM_ROOT_NON_CONST->node = offset_to_ofnode(0); -#endif + if (CONFIG_IS_ENABLED(OF_CONTROL)) + DM_ROOT_NON_CONST->node = ofnode_root(); ret = device_probe(DM_ROOT_NON_CONST); if (ret) return ret; -- cgit v1.2.3 From 2ebea5eaebf2c11c3f18f553d1bceba22e220893 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:08 -0700 Subject: 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 --- drivers/core/root.c | 74 ++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 58 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 9ee65504e6e..62efa0fedcf 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -199,33 +199,6 @@ int dm_scan_platdata(bool pre_reloc_only) } #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 * @@ -233,28 +206,30 @@ static int dm_scan_fdt_live(struct udevice *parent, * for each one. * * @parent: Parent device for the devices that will be created - * @blob: Pointer to device tree blob - * @offset: Offset of node to scan + * @node: Node to scan * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC * flag. If false bind all drivers. * @return 0 if OK, -ve on error */ -static int dm_scan_fdt_node(struct udevice *parent, const void *blob, - int offset, bool pre_reloc_only) +static int dm_scan_fdt_node(struct udevice *parent, ofnode parent_node, + bool pre_reloc_only) { int ret = 0, err; + ofnode node; + + if (!ofnode_valid(parent_node)) + return 0; - for (offset = fdt_first_subnode(blob, offset); - offset > 0; - offset = fdt_next_subnode(blob, offset)) { - const char *node_name = fdt_get_name(blob, offset, NULL); + for (node = ofnode_first_subnode(parent_node); + ofnode_valid(node); + node = ofnode_next_subnode(node)) { + const char *node_name = ofnode_get_name(node); - if (!fdtdec_get_is_enabled(blob, offset)) { + if (!ofnode_is_enabled(node)) { pr_debug(" - ignoring disabled device\n"); continue; } - err = lists_bind_fdt(parent, offset_to_ofnode(offset), NULL, - pre_reloc_only); + err = lists_bind_fdt(parent, node, NULL, pre_reloc_only); if (err && !ret) { ret = err; 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) { - if (!dev_of_valid(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), + return dm_scan_fdt_node(dev, dev_ofnode(dev), gd->flags & GD_FLG_RELOC ? false : true); } int dm_scan_fdt(const void *blob, bool pre_reloc_only) { - if (of_live_active()) - 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); + return dm_scan_fdt_node(gd->dm_root, ofnode_root(), pre_reloc_only); } 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; node = ofnode_path(path); - if (!ofnode_valid(node)) - return 0; - - if (of_live_active()) - 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); + return dm_scan_fdt_node(gd->dm_root, node, pre_reloc_only); } int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) -- cgit v1.2.3 From 725e4fce61e5b8339fdc975b01ce7bb3dd9fa5f4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:09 -0700 Subject: dm: core: Drop unused parameter from dm_scan_fdt() This doesn't need to be passed the devicetree anymore. Drop it. Signed-off-by: Simon Glass --- drivers/core/root.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 62efa0fedcf..54498b2df71 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -248,13 +248,12 @@ int dm_scan_fdt_dev(struct udevice *dev) gd->flags & GD_FLG_RELOC ? false : true); } -int dm_scan_fdt(const void *blob, bool pre_reloc_only) +int dm_scan_fdt(bool pre_reloc_only) { return dm_scan_fdt_node(gd->dm_root, ofnode_root(), pre_reloc_only); } -static int dm_scan_fdt_ofnode_path(const void *blob, const char *path, - bool pre_reloc_only) +static int dm_scan_fdt_ofnode_path(const char *path, bool pre_reloc_only) { ofnode node; @@ -272,7 +271,7 @@ int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) "/firmware" }; - ret = dm_scan_fdt(blob, pre_reloc_only); + ret = dm_scan_fdt(pre_reloc_only); if (ret) { debug("dm_scan_fdt() failed: %d\n", ret); return ret; @@ -280,7 +279,7 @@ int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) /* Some nodes aren't devices themselves but may contain some */ for (i = 0; i < ARRAY_SIZE(nodes); i++) { - ret = dm_scan_fdt_ofnode_path(blob, nodes[i], pre_reloc_only); + ret = dm_scan_fdt_ofnode_path(nodes[i], pre_reloc_only); if (ret) { debug("dm_scan_fdt() scan for %s failed: %d\n", nodes[i], ret); -- cgit v1.2.3 From 8ee05b5f903bdfb0c4c2d578fd0172ecb900e3e2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:10 -0700 Subject: dm: core: Drop unused parameter from dm_extended_scan_fdt() This doesn't need to be passed the devicetree anymore. Drop it. Also rename the function to drop the _fdt suffix. Signed-off-by: Simon Glass --- drivers/core/root.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 54498b2df71..6f8168bb92d 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -262,7 +262,7 @@ static int dm_scan_fdt_ofnode_path(const char *path, bool pre_reloc_only) return dm_scan_fdt_node(gd->dm_root, node, pre_reloc_only); } -int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) +int dm_extended_scan(bool pre_reloc_only) { int ret, i; const char * const nodes[] = { @@ -315,9 +315,9 @@ int dm_init_and_scan(bool pre_reloc_only) } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { - ret = dm_extended_scan_fdt(gd->fdt_blob, pre_reloc_only); + ret = dm_extended_scan(pre_reloc_only); if (ret) { - debug("dm_extended_scan_dt() failed: %d\n", ret); + debug("dm_extended_scan() failed: %d\n", ret); return ret; } } -- cgit v1.2.3 From caa4daa2ae3dc0a3e516addea5772c9af76abcb0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 3 Dec 2020 16:55:18 -0700 Subject: dm: treewide: Rename 'platdata' variables to just 'plat' We use 'priv' for private data but often use 'platdata' for platform data. We can't really use 'pdata' since that is ambiguous (it could mean private or platform data). Rename some of the latter variables to end with 'plat' for consistency. Signed-off-by: Simon Glass --- drivers/core/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 6f8168bb92d..348dc9e1c1f 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -123,8 +123,8 @@ void fix_devices(void) struct driver_info *entry; for (entry = dev; entry != dev + n_ents; entry++) { - if (entry->platdata) - entry->platdata += gd->reloc_off; + if (entry->plat) + entry->plat += gd->reloc_off; } } -- cgit v1.2.3 From d1998a9fde0a917d6496299f6a97b6bccfdc6724 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 3 Dec 2020 16:55:21 -0700 Subject: dm: treewide: Rename ofdata_to_platdata() to of_to_plat() This name is far too long. Rename it to remove the 'data' bits. This makes it consistent with the platdata->plat rename. Signed-off-by: Simon Glass --- drivers/core/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 348dc9e1c1f..42f8f0cedd4 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -69,8 +69,8 @@ void fix_drivers(void) entry->remove += gd->reloc_off; if (entry->unbind) entry->unbind += gd->reloc_off; - if (entry->ofdata_to_platdata) - entry->ofdata_to_platdata += gd->reloc_off; + if (entry->of_to_plat) + entry->of_to_plat += gd->reloc_off; if (entry->child_post_bind) entry->child_post_bind += gd->reloc_off; if (entry->child_pre_probe) -- cgit v1.2.3 From 8a8d24bdf174851ebb8607f359d54b72e3283b97 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 3 Dec 2020 16:55:23 -0700 Subject: dm: treewide: Rename ..._platdata variables to just ..._plat Try to maintain some consistency between these variables by using _plat as a suffix for them. Signed-off-by: Simon Glass --- drivers/core/root.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 42f8f0cedd4..672aa7cea72 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -174,7 +174,7 @@ int dm_remove_devices_flags(uint flags) } #endif -int dm_scan_platdata(bool pre_reloc_only) +int dm_scan_plat(bool pre_reloc_only) { int ret; @@ -308,9 +308,9 @@ int dm_init_and_scan(bool pre_reloc_only) debug("dm_init() failed: %d\n", ret); return ret; } - ret = dm_scan_platdata(pre_reloc_only); + ret = dm_scan_plat(pre_reloc_only); if (ret) { - debug("dm_scan_platdata() failed: %d\n", ret); + debug("dm_scan_plat() failed: %d\n", ret); return ret; } -- cgit v1.2.3