public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	Sughosh Ganu <sughosh.ganu@linaro.org>,
	Sean Anderson <seanga2@gmail.com>,
	Julien Masson <jmasson@baylibre.com>,
	Patrick Rudolph <patrick.rudolph@9elements.com>,
	Yang Xiwen <forbidden405@outlook.com>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Caleb Connolly <caleb.connolly@linaro.org>,
	Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Marek Vasut <marex@denx.de>,
	Michael Polyntsov <michael.polyntsov@iopsys.eu>,
	u-boot@lists.denx.de
Subject: [PATCH 3/8] dm: core: implement ofnode/tree_parse_phandle() helper
Date: Sat,  9 Nov 2024 19:00:28 +0100	[thread overview]
Message-ID: <20241109180038.10344-4-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20241109180038.10344-1-ansuelsmth@gmail.com>

Implement ofnode/tree_parse_phandle() helper as an equivalent of
of_parse_phandle to handle simple single value phandle.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/core/ofnode.c | 58 +++++++++++++++++++++++++++++++++++++++++++
 include/dm/ofnode.h   | 26 +++++++++++++++++++
 2 files changed, 84 insertions(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index a2136f61b7d..774b428c43f 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -879,6 +879,64 @@ int ofnode_read_string_list(ofnode node, const char *property,
 	return count;
 }
 
+ofnode ofnode_parse_phandle(ofnode node, const char *phandle_name,
+			    int index)
+{
+	ofnode phandle;
+
+	if (ofnode_is_np(node)) {
+		struct device_node *np;
+
+		np = of_parse_phandle(ofnode_to_np(node), phandle_name,
+				      index);
+		if (!np)
+			return ofnode_null();
+
+		phandle = np_to_ofnode(np);
+	} else {
+		struct fdtdec_phandle_args args;
+
+		if (fdtdec_parse_phandle_with_args(ofnode_to_fdt(node),
+						   ofnode_to_offset(node),
+						   phandle_name, NULL,
+						   0, index, &args))
+			return ofnode_null();
+
+		phandle = offset_to_ofnode(args.node);
+	}
+
+	return phandle;
+}
+
+ofnode oftree_parse_phandle(oftree tree, ofnode node, const char *phandle_name,
+			    int index)
+{
+	ofnode phandle;
+
+	if (ofnode_is_np(node)) {
+		struct device_node *np;
+
+		np = of_root_parse_phandle(tree.np, ofnode_to_np(node),
+					   phandle_name, index);
+		if (!np)
+			return ofnode_null();
+
+		phandle = np_to_ofnode(np);
+	} else {
+		struct fdtdec_phandle_args args;
+
+		if (fdtdec_parse_phandle_with_args(tree.fdt,
+						   ofnode_to_offset(node),
+						   phandle_name, NULL,
+						   0, index, &args))
+			return ofnode_null();
+
+		phandle = offset_to_ofnode(args.node);
+	}
+
+	return phandle;
+}
+
 static void ofnode_from_fdtdec_phandle_args(struct fdtdec_phandle_args *in,
 					    struct ofnode_phandle_args *out)
 {
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 7ece68874ae..eea6b13217c 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -847,6 +847,18 @@ int ofnode_read_string_count(ofnode node, const char *property);
 int ofnode_read_string_list(ofnode node, const char *property,
 			    const char ***listp);
 
+/**
+ * ofnode_parse_phandle() - Resolve a phandle property to an ofnode
+ *
+ * @node: node to check
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ *         the table
+ * Return: ofnode that the phandle points to or ofnode_null() on error.
+ */
+ofnode ofnode_parse_phandle(ofnode node, const char *phandle_name,
+			    int index);
+
 /**
  * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
  *
@@ -909,6 +921,20 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
 				   const char *cells_name, int cell_count);
 
+/**
+ * oftree_parse_phandle() - Resolve a phandle property to an ofnode
+ *			    from a root node
+ *
+ * @tree: device tree to use
+ * @node: node to check
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ *         the table
+ * Return: ofnode that the phandle points to or ofnode_null() on error.
+ */
+ofnode oftree_parse_phandle(oftree tree, ofnode node, const char *phandle_name,
+			    int index);
+
 /**
  * oftree_parse_phandle_with_args() - Find a node pointed by phandle in a list
  *				      from a root node
-- 
2.45.2


  parent reply	other threads:[~2024-11-09 18:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-09 18:00 [PATCH 0/8] led: update LED boot/activity to new property implementation Christian Marangi
2024-11-09 18:00 ` [PATCH 1/8] dm: core: implement oftree variant of parse_phandle OPs Christian Marangi
2024-11-09 18:00 ` [PATCH 2/8] test: dm: fix broken dm_test_ofnode_phandle_ot Christian Marangi
2024-11-09 18:00 ` Christian Marangi [this message]
2024-11-09 18:00 ` [PATCH 4/8] test: dm: Expand dm_test_ofnode_phandle(_ot) with new ofnode/tree_parse_phandle Christian Marangi
2024-11-09 18:00 ` [PATCH 5/8] dm: core: implement phandle ofnode_options helper Christian Marangi
2024-11-09 18:00 ` [PATCH 6/8] test: dm: Add test for ofnode options phandle helper Christian Marangi
2024-11-09 18:00 ` [PATCH 7/8] led: update LED boot/activity to new property implementation Christian Marangi
2024-11-09 18:00 ` [PATCH 8/8] test: dm: Update test for LED activity and boot Christian Marangi
2024-11-09 20:29 ` [PATCH 0/8] led: update LED boot/activity to new property implementation Christian Marangi
2024-11-20 13:46 ` 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=20241109180038.10344-4-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=caleb.connolly@linaro.org \
    --cc=forbidden405@outlook.com \
    --cc=jmasson@baylibre.com \
    --cc=marex@denx.de \
    --cc=michael.polyntsov@iopsys.eu \
    --cc=mikhail.kshevetskiy@iopsys.eu \
    --cc=mkorpershoek@baylibre.com \
    --cc=patrick.rudolph@9elements.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=sughosh.ganu@linaro.org \
    --cc=trini@konsulko.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox