Skip to contentSkip to conversation

dt: introduce for_each_available_child_of_node, of_get_next_available_child

PATCH Applied Timur Tabi 2 participants 4 messages Aug 14, 2012 – Aug 20, 2012 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH 1/2 dt: introduce for_each_available_child_of_node, of_get_next_available_child

Macro for_each_child_of_node() makes it easy to iterate over all of the children for a given device tree node, including those nodes that are marked as unavailable (i.e. status = "disabled").

Introduce for_each_available_child_of_node(), which is like for_each_child_of_node(), but it automatically skips unavailable nodes. This also requires the introduction of helper function of_get_next_available_child(), which returns the next available child node.

---
 drivers/of/base.c  |   27 +++++++++++++++++++++++++++
 include/linux/of.h |    7 +++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
drivers/of/base.c +27 -0
index c181b94..d4a1c9a 100644
@@ -364,6 +364,33 @@ struct device_node *of_get_next_child(const struct device_node *node,
 EXPORT_SYMBOL(of_get_next_child);
 
 /**
+ *	of_get_next_available_child - Find the next available child node
+ *	@node:	parent node
+ *	@prev:	previous child of the parent node, or NULL to get first
+ *
+ *      This function is like of_get_next_child(), except that it
+ *      automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+	struct device_node *prev)
+{
+	struct device_node *next;
+
+	read_lock(&devtree_lock);
+	next = prev ? prev->sibling : node->child;
+	for (; next; next = next->sibling) {
+		if (!of_device_is_available(next))
+			continue;
+		if (of_node_get(next))
+			break;
+	}
+	of_node_put(prev);
+	read_unlock(&devtree_lock);
+	return next;
+}
+EXPORT_SYMBOL(of_get_next_available_child);
+
+/**
  *	of_find_node_by_path - Find a node matching a full OF path
  *	@path:	The full path to match
  *
include/linux/of.h +7 -0
index 5919ee3..1b11632 100644
@@ -190,10 +190,17 @@ extern struct device_node *of_get_parent(const struct device_node *node);
 extern struct device_node *of_get_next_parent(struct device_node *node);
 extern struct device_node *of_get_next_child(const struct device_node *node,
 					     struct device_node *prev);
+extern struct device_node *of_get_next_available_child(
+	const struct device_node *node, struct device_node *prev);
+
 #define for_each_child_of_node(parent, child) \
 	for (child = of_get_next_child(parent, NULL); child != NULL; \
 	     child = of_get_next_child(parent, child))
 
+#define for_each_available_child_of_node(parent, child) \
+	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
+	     child = of_get_next_available_child(parent, child))
+
 static inline int of_get_child_count(const struct device_node *np)
 {
 	struct device_node *child;
Signature · 1 line
1.7.3.4

A message that is not in the archive (sent off-list or not yet received): 1344986424-14360-1-git-send-email-timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org

author
#2 lore raw

PATCH v2 2/2 netdev/phy: skip disabled mdio-mux nodes

The mdio-mux driver scans all child mdio nodes, without regard to whether the node is actually used. Some device trees include all possible mdio-mux nodes and rely on the boot loader to disable those that are not present, based on some run-time configuration. Those nodes need to be skipped.

---
 drivers/net/phy/mdio-mux.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/phy/mdio-mux.c +1 -1
index 5c12018..4d4d25e 100644
@@ -132,7 +132,7 @@ int mdio_mux_init(struct device *dev,
 	pb->mii_bus = parent_bus;
 
 	ret_val = -ENODEV;
-	for_each_child_of_node(dev->of_node, child_bus_node) {
+	for_each_available_child_of_node(dev->of_node, child_bus_node) {
 		u32 v;
 
 		r = of_property_read_u32(child_bus_node, "reg", &v);
Signature · 1 line
1.7.3.4
maintainer Applied
#3 lore raw

Re: [PATCH 2/2] [v2] netdev/phy: skip disabled mdio-mux nodes

From: Timur Tabi <[email protected]>
Date: Tue, 14 Aug 2012 18:20:24 -0500

Quoted 7 lines

The mdio-mux driver scans all child mdio nodes, without regard to whether the node is actually used. Some device trees include all possible mdio-mux nodes and rely on the boot loader to disable those that are not present, based on some run-time configuration. Those nodes need to be skipped.

Applied.

maintainer Applied
#4 lore raw
In reply to Timur Tabi

From: Timur Tabi <[email protected]>
Date: Tue, 14 Aug 2012 18:20:23 -0500

Quoted 11 lines

Macro for_each_child_of_node() makes it easy to iterate over all of the children for a given device tree node, including those nodes that are marked as unavailable (i.e. status = "disabled").

Introduce for_each_available_child_of_node(), which is like for_each_child_of_node(), but it automatically skips unavailable nodes. This also requires the introduction of helper function of_get_next_available_child(), which returns the next available child node.

Applied.