From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/5] of: Add of_find_node_by_name() with Linux semantics
Date: Tue, 8 Mar 2022 12:51:01 +0100 [thread overview]
Message-ID: <20220308115103.3664883-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20220308115103.3664883-1-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 38 ++++++++++++++++++++++++++++++++++++++
include/of.h | 20 ++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d5cbb12a29..83291c4785 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -23,6 +23,21 @@
static struct device_node *root_node;
+bool of_node_name_eq(const struct device_node *np, const char *name)
+{
+ const char *node_name;
+ size_t len;
+
+ if (!np)
+ return false;
+
+ node_name = kbasename(np->full_name);
+ len = strchrnul(node_name, '@') - node_name;
+
+ return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
+}
+EXPORT_SYMBOL(of_node_name_eq);
+
/*
* Iterate over all nodes of a tree. As a devicetree does not
* have a dedicated list head, the start node (usually the root
@@ -560,6 +575,29 @@ struct device_node *of_find_node_by_name_address(struct device_node *from,
}
EXPORT_SYMBOL(of_find_node_by_name_address);
+/**
+ * of_find_node_by_name - Find a node by its "name" property
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @name: The name string to match against
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name)
+{
+ struct device_node *np;
+
+ of_tree_for_each_node_from(np, from)
+ if (np->name && of_node_name_eq(np, name))
+ return np;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
/**
* of_find_node_by_type - Find a node by its "device_type" property
* @from: The node to start searching from, or NULL to start searching
diff --git a/include/of.h b/include/of.h
index 2c1a3f5510..9089409f9f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -120,6 +120,7 @@ extern int of_bus_n_addr_cells(struct device_node *np);
extern int of_n_addr_cells(struct device_node *np);
extern int of_bus_n_size_cells(struct device_node *np);
extern int of_n_size_cells(struct device_node *np);
+extern bool of_node_name_eq(const struct device_node *np, const char *name);
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
@@ -136,6 +137,8 @@ extern struct property *of_new_property_const(struct device_node *node,
const void *data, int len);
extern void of_delete_property(struct property *pp);
+extern struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name);
extern struct device_node *of_find_node_by_name_address(struct device_node *from,
const char *name);
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
@@ -313,6 +316,11 @@ struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
int of_autoenable_device_by_path(char *path);
int of_autoenable_i2c_by_component(char *path);
#else
+static inline bool of_node_name_eq(const struct device_node *np, const char *name)
+{
+ return false;
+}
+
static inline int of_parse_partitions(struct cdev *cdev,
struct device_node *node)
{
@@ -653,6 +661,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
return NULL;
}
+static inline struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_node_by_name_address(struct device_node *from,
const char *name)
{
@@ -824,12 +838,18 @@ static inline int of_autoenable_i2c_by_component(char *path)
#define for_each_property_of_node(dn, pp) \
list_for_each_entry(pp, &dn->properties, list)
+#define for_each_node_by_name(dn, name) \
+ for (dn = of_find_node_by_name(NULL, name); dn; \
+ dn = of_find_node_by_name(dn, name))
#define for_each_node_by_name_address(dn, name) \
for (dn = of_find_node_by_name_address(NULL, name); dn; \
dn = of_find_node_by_name_address(dn, name))
#define for_each_node_by_type(dn, type) \
for (dn = of_find_node_by_type(NULL, type); dn; \
dn = of_find_node_by_type(dn, type))
+#define for_each_node_by_name_from(dn, root, name) \
+ for (dn = of_find_node_by_name(root, name); dn; \
+ dn = of_find_node_by_name(dn, name))
#define for_each_node_by_name_address_from(dn, root, name) \
for (dn = of_find_node_by_name_address(root, name); dn; \
dn = of_find_node_by_name_address(dn, name))
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2022-03-08 11:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
2022-03-08 11:50 ` [PATCH 1/5] of: platform: return early when deep probe is not supported Sascha Hauer
2022-03-08 11:51 ` [PATCH 2/5] of: rename of_find_node_by_name() to of_find_node_by_name_address() Sascha Hauer
2022-03-08 11:51 ` Sascha Hauer [this message]
2022-03-08 11:51 ` [PATCH 4/5] of: platform: Change of_devices_ensure_probed_by_property() return value Sascha Hauer
2022-03-08 11:51 ` [PATCH 5/5] of: platform: Ensure timers are probed early Sascha Hauer
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=20220308115103.3664883-4-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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