All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH 09/11] dm: core: Combine the flattree and livetree binding code
Date: Sat, 28 Nov 2020 17:50:08 -0700	[thread overview]
Message-ID: <20201128174958.9.Ia1e9e05434447b46189fa7d729820c68dde511e0@changeid> (raw)
In-Reply-To: <20201129005011.2104545-1-sjg@chromium.org>

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>
---

 drivers/core/root.c | 74 ++++++++++-----------------------------------
 1 file changed, 16 insertions(+), 58 deletions(-)

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)
-- 
2.29.2.454.gaff20da3a2-goog

  parent reply	other threads:[~2020-11-29  0:50 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-29  0:49 [PATCH 00/11] dm: Simplify livetree handling Simon Glass
2020-11-29  0:50 ` [PATCH 01/11] dm: core: Rename device_bind() to device_bind_offset() Simon Glass
2020-11-29  0:50 ` [PATCH 02/11] dm: core: Rename device_bind_ofnode() to device_bind() Simon Glass
2020-11-29  0:50 ` [PATCH 03/11] dm: core: Add a livetree function to check node status Simon Glass
2020-11-29  0:50 ` [PATCH 04/11] dm: Remove uses of device_bind_offset() Simon Glass
2020-11-29  0:50 ` [PATCH 05/11] dm: Drop uses of dev_set_of_offset() Simon Glass
2020-11-29  0:50 ` [PATCH 06/11] dm: core: Drop dev_set_of_offset() Simon Glass
2020-11-29  0:50 ` [PATCH 07/11] dm: core: Drop device_bind_offset() Simon Glass
2020-11-29  0:50 ` [PATCH 08/11] dm: core: Add an ofnode function to get the devicetree root Simon Glass
2020-11-29  0:50 ` Simon Glass [this message]
2020-11-29  0:50 ` [PATCH 10/11] dm: core: Drop unused parameter from dm_scan_fdt() Simon Glass
2020-11-29  0:50 ` [PATCH 11/11] dm: core: Drop unused parameter from dm_extended_scan_fdt() Simon Glass
2020-12-10  0:26 ` Simon Glass
2020-12-10  0:26 ` [PATCH 10/11] dm: core: Drop unused parameter from dm_scan_fdt() Simon Glass
2020-12-10  0:26 ` [PATCH 09/11] dm: core: Combine the flattree and livetree binding code Simon Glass
2020-12-10  0:26 ` [PATCH 08/11] dm: core: Add an ofnode function to get the devicetree root Simon Glass
2020-12-10  0:26 ` [PATCH 07/11] dm: core: Drop device_bind_offset() Simon Glass
2020-12-10  0:26 ` [PATCH 06/11] dm: core: Drop dev_set_of_offset() Simon Glass
2020-12-10  0:26 ` [PATCH 05/11] dm: Drop uses of dev_set_of_offset() Simon Glass
2020-12-10  0:26   ` Simon Glass
2020-12-10  0:26 ` [PATCH 04/11] dm: Remove uses of device_bind_offset() Simon Glass
2020-12-10  0:26   ` Simon Glass
2021-01-31  9:18   ` Eugen.Hristev at microchip.com
2021-01-31  9:18     ` Eugen.Hristev
2021-01-31 15:37     ` Simon Glass
2021-01-31 15:37       ` Simon Glass
2021-02-01  8:13       ` Eugen.Hristev at microchip.com
2021-02-01  8:13         ` Eugen.Hristev
2021-02-01 12:02         ` Simon Glass
2021-02-01 12:02           ` Simon Glass
2021-02-01 12:14           ` Eugen.Hristev at microchip.com
2020-12-10  0:26 ` [PATCH 03/11] dm: core: Add a livetree function to check node status Simon Glass
2020-12-10  0:26 ` [PATCH 02/11] dm: core: Rename device_bind_ofnode() to device_bind() Simon Glass
2020-12-10  0:26 ` [PATCH 01/11] dm: core: Rename device_bind() to device_bind_offset() Simon Glass
2020-12-10  0:26   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201128174958.9.Ia1e9e05434447b46189fa7d729820c68dde511e0@changeid \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.