netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] dt: introduce for_each_available_child_of_node, of_get_next_available_child
@ 2012-08-14 23:20 Timur Tabi
       [not found] ` <1344986424-14360-1-git-send-email-timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2012-08-20  9:16 ` [PATCH 1/2] dt: introduce for_each_available_child_of_node, of_get_next_available_child David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Timur Tabi @ 2012-08-14 23:20 UTC (permalink / raw)
  To: Grant Likely, David Miller, david.daney-YGCgFSpz5w/QT0dZR+AlfA,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

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.

Signed-off-by: Timur Tabi <timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/of/base.c  |   27 +++++++++++++++++++++++++++
 include/linux/of.h |    7 +++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index c181b94..d4a1c9a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -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
  *
diff --git a/include/linux/of.h b/include/linux/of.h
index 5919ee3..1b11632 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -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;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] [v2] netdev/phy: skip disabled mdio-mux nodes
       [not found] ` <1344986424-14360-1-git-send-email-timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2012-08-14 23:20   ` Timur Tabi
  2012-08-20  9:16     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Timur Tabi @ 2012-08-14 23:20 UTC (permalink / raw)
  To: Grant Likely, David Miller, david.daney-YGCgFSpz5w/QT0dZR+AlfA,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

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.

Signed-off-by: Timur Tabi <timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/net/phy/mdio-mux.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/phy/mdio-mux.c b/drivers/net/phy/mdio-mux.c
index 5c12018..4d4d25e 100644
--- a/drivers/net/phy/mdio-mux.c
+++ b/drivers/net/phy/mdio-mux.c
@@ -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);
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dt: introduce for_each_available_child_of_node, of_get_next_available_child
  2012-08-14 23:20 [PATCH 1/2] dt: introduce for_each_available_child_of_node, of_get_next_available_child Timur Tabi
       [not found] ` <1344986424-14360-1-git-send-email-timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2012-08-20  9:16 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2012-08-20  9:16 UTC (permalink / raw)
  To: timur; +Cc: grant.likely, david.daney, netdev, devicetree-discuss

From: Timur Tabi <timur@freescale.com>
Date: Tue, 14 Aug 2012 18:20:23 -0500

> 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.
> 
> Signed-off-by: Timur Tabi <timur@freescale.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] [v2] netdev/phy: skip disabled mdio-mux nodes
  2012-08-14 23:20   ` [PATCH 2/2] [v2] netdev/phy: skip disabled mdio-mux nodes Timur Tabi
@ 2012-08-20  9:16     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2012-08-20  9:16 UTC (permalink / raw)
  To: timur; +Cc: grant.likely, david.daney, netdev, devicetree-discuss

From: Timur Tabi <timur@freescale.com>
Date: Tue, 14 Aug 2012 18:20:24 -0500

> 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.
> 
> Signed-off-by: Timur Tabi <timur@freescale.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-20  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-14 23:20 [PATCH 1/2] dt: introduce for_each_available_child_of_node, of_get_next_available_child Timur Tabi
     [not found] ` <1344986424-14360-1-git-send-email-timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-08-14 23:20   ` [PATCH 2/2] [v2] netdev/phy: skip disabled mdio-mux nodes Timur Tabi
2012-08-20  9:16     ` David Miller
2012-08-20  9:16 ` [PATCH 1/2] dt: introduce for_each_available_child_of_node, of_get_next_available_child David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).