aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSrinivas Kandagatla <srinivas.kandagatla@st.com>2012-09-18 03:10:28 -0400
committerRob Herring <rob.herring@calxeda.com>2012-10-01 11:42:21 -0400
commit9c19761a7ecdc86abb2fba0feb81e8952eccc1f1 (patch)
tree7da34de41c8b77b9cccf446d53a3943be33b6c3c
parentee67016fcc58998c44a9c99b0721568b3d2edc6e (diff)
dt: introduce of_get_child_by_name to get child node by name
This patch introduces of_get_child_by_name function to get a child node by its name in a given parent node. Without this patch each driver code has to iterate the parent and do a string compare, However having of_get_child_by_name libary function would avoid code duplication, errors and is more convenient. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: Rob Herring <rob.herring@calxeda.com>
-rw-r--r--drivers/of/base.c23
-rw-r--r--include/linux/of.h2
2 files changed, 25 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c181b94abc36..e2e813624df5 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -364,6 +364,29 @@ struct device_node *of_get_next_child(const struct device_node *node,
364EXPORT_SYMBOL(of_get_next_child); 364EXPORT_SYMBOL(of_get_next_child);
365 365
366/** 366/**
367 * of_get_child_by_name - Find the child node by name for a given parent
368 * @node: parent node
369 * @name: child name to look for.
370 *
371 * This function looks for child node for given matching name
372 *
373 * Returns a node pointer if found, with refcount incremented, use
374 * of_node_put() on it when done.
375 * Returns NULL if node is not found.
376 */
377struct device_node *of_get_child_by_name(const struct device_node *node,
378 const char *name)
379{
380 struct device_node *child;
381
382 for_each_child_of_node(node, child)
383 if (child->name && (of_node_cmp(child->name, name) == 0))
384 break;
385 return child;
386}
387EXPORT_SYMBOL(of_get_child_by_name);
388
389/**
367 * of_find_node_by_path - Find a node matching a full OF path 390 * of_find_node_by_path - Find a node matching a full OF path
368 * @path: The full path to match 391 * @path: The full path to match
369 * 392 *
diff --git a/include/linux/of.h b/include/linux/of.h
index 5919ee33f2b7..fabb524d3d75 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -190,6 +190,8 @@ extern struct device_node *of_get_parent(const struct device_node *node);
190extern struct device_node *of_get_next_parent(struct device_node *node); 190extern struct device_node *of_get_next_parent(struct device_node *node);
191extern struct device_node *of_get_next_child(const struct device_node *node, 191extern struct device_node *of_get_next_child(const struct device_node *node,
192 struct device_node *prev); 192 struct device_node *prev);
193extern struct device_node *of_get_child_by_name(const struct device_node *node,
194 const char *name);
193#define for_each_child_of_node(parent, child) \ 195#define for_each_child_of_node(parent, child) \
194 for (child = of_get_next_child(parent, NULL); child != NULL; \ 196 for (child = of_get_next_child(parent, NULL); child != NULL; \
195 child = of_get_next_child(parent, child)) 197 child = of_get_next_child(parent, child))