* [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
@ 2012-09-13 11:10 Srinivas KANDAGATLA
[not found] ` <1347534640-787-1-git-send-email-srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Srinivas KANDAGATLA @ 2012-09-13 11:10 UTC (permalink / raw)
To: bergner-r/Jw6+rmf7HQT0dZR+AlfA
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q
From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
This patch introduces of_get_child 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 libary function would
avoid code duplication, errors and is more convenient.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
---
drivers/of/base.c | 27 +++++++++++++++++++++++++++
include/linux/of.h | 2 ++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4a1c9a..d4b6840 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -391,6 +391,33 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
EXPORT_SYMBOL(of_get_next_available_child);
/**
+ * of_get_child - Find the child node by name for given parent
+ * @node: parent node
+ * @name: child name to look for.
+ *
+ * This function looks for child node for given matching name
+ *
+ * Returns a node pointer if found, with refcount incremented, use
+ * of_node_put() on it when done.
+ * else returns NULL.
+ */
+
+struct device_node *of_get_child(const struct device_node *node,
+ const char *name)
+{
+ struct device_node *child;
+
+ read_lock(&devtree_lock);
+ for_each_child_of_node(node, child)
+ if (child->name && (of_node_cmp(child->name, name) == 0)
+ && of_node_get(child))
+ break;
+ read_unlock(&devtree_lock);
+ return child;
+}
+EXPORT_SYMBOL(of_get_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 1b11632..510e1fe 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -192,6 +192,8 @@ 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);
+extern struct device_node *of_get_child(const struct device_node *node,
+ const char *name);
#define for_each_child_of_node(parent, child) \
for (child = of_get_next_child(parent, NULL); child != NULL; \
--
1.7.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <1347534640-787-1-git-send-email-srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
@ 2012-09-13 15:14 ` Stephen Warren
[not found] ` <5051F838.5080002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-09-13 20:32 ` Rob Herring
1 sibling, 1 reply; 8+ messages in thread
From: Stephen Warren @ 2012-09-13 15:14 UTC (permalink / raw)
To: Srinivas KANDAGATLA
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q, Rob Herring
On 09/13/2012 05:10 AM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>
> This patch introduces of_get_child 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 libary function would
> avoid code duplication, errors and is more convenient.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
You forgot to Cc the drivers/of maintainers, Grant and Rob. I have here.
I can certainly see a use for this in many places; the "runtime
interpreted power sequences" patch, and the regulator DT parsing code at
least both could benefit from this.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <5051F838.5080002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-09-13 15:25 ` Srinivas KANDAGATLA
[not found] ` <5051FAFA.4040507-qxv4g6HH51o@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Srinivas KANDAGATLA @ 2012-09-13 15:25 UTC (permalink / raw)
To: Stephen Warren
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q, Rob Herring
On 13/09/12 16:14, Stephen Warren wrote:
> On 09/13/2012 05:10 AM, Srinivas KANDAGATLA wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>
>> This patch introduces of_get_child 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 libary function would
>> avoid code duplication, errors and is more convenient.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
> You forgot to Cc the drivers/of maintainers, Grant and Rob. I have here.
Oops...
>
> I can certainly see a use for this in many places; the "runtime
> interpreted power sequences" patch, and the regulator DT parsing code at
> least both could benefit from this.
There are at-least 7-8 places in the current kernel which could use this
function directly.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <5051FAFA.4040507-qxv4g6HH51o@public.gmane.org>
@ 2012-09-13 15:43 ` Rob Herring
[not found] ` <5051FF1A.7060507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2012-09-13 15:43 UTC (permalink / raw)
To: srinivas.kandagatla-qxv4g6HH51o
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q
On 09/13/2012 10:25 AM, Srinivas KANDAGATLA wrote:
>
> On 13/09/12 16:14, Stephen Warren wrote:
>> On 09/13/2012 05:10 AM, Srinivas KANDAGATLA wrote:
>>> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>>
>>> This patch introduces of_get_child 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 libary function would
>>> avoid code duplication, errors and is more convenient.
>>>
>>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>> You forgot to Cc the drivers/of maintainers, Grant and Rob. I have here.
>
> Oops...
>
>>
>> I can certainly see a use for this in many places; the "runtime
>> interpreted power sequences" patch, and the regulator DT parsing code at
>> least both could benefit from this.
I would think the power sequences code would always iterate over the nodes.
>
> There are at-least 7-8 places in the current kernel which could use this
> function directly.
Care to point them out and preferably fix them then. That would be more
convincing that this is needed.
Rob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <5051FF1A.7060507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2012-09-13 15:48 ` Stephen Warren
2012-09-13 15:51 ` Srinivas KANDAGATLA
1 sibling, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2012-09-13 15:48 UTC (permalink / raw)
To: Rob Herring
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q
On 09/13/2012 09:43 AM, Rob Herring wrote:
> On 09/13/2012 10:25 AM, Srinivas KANDAGATLA wrote:
>>
>> On 13/09/12 16:14, Stephen Warren wrote:
>>> On 09/13/2012 05:10 AM, Srinivas KANDAGATLA wrote:
>>>> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>>>
>>>> This patch introduces of_get_child 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 libary function would
>>>> avoid code duplication, errors and is more convenient.
>>>>
>>>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>> You forgot to Cc the drivers/of maintainers, Grant and Rob. I have here.
>>
>> Oops...
>>
>>>
>>> I can certainly see a use for this in many places; the "runtime
>>> interpreted power sequences" patch, and the regulator DT parsing code at
>>> least both could benefit from this.
>
> I would think the power sequences code would always iterate over the nodes.
There are two stages to the power sequences code; the first finds the
"power-sequences" child node in the device itself (and should use this
new API), and the next iterates over all children in that node, and then
all children in those nodes.
>> There are at-least 7-8 places in the current kernel which could use this
>> function directly.
>
> Care to point them out and preferably fix them then. That would be more
> convincing that this is needed.
drivers/mfd/tps6586x:tps6586x_parse_dt()'s call to
of_find_node_by_name() should be replaced by this function.
drivers/regulator/max8907-regulator.c:max8907_regulator_parse_dt() has
the same issue.
drivers/regulator/tps65910-regulator.c:tps65910_parse_dt_reg_data() has
the same issue.
Perhaps other regulators too; those are just the ones used on my platforms.
At least some of those three will be added during the 3.7 merge window,
so it'd be hard to fix in this patch without merging in a bunch of
dependencies first.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <5051FF1A.7060507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-09-13 15:48 ` Stephen Warren
@ 2012-09-13 15:51 ` Srinivas KANDAGATLA
1 sibling, 0 replies; 8+ messages in thread
From: Srinivas KANDAGATLA @ 2012-09-13 15:51 UTC (permalink / raw)
To: Rob Herring
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q
On 13/09/12 16:43, Rob Herring wrote:
> On 09/13/2012 10:25 AM, Srinivas KANDAGATLA wrote:
>> On 13/09/12 16:14, Stephen Warren wrote:
>>> On 09/13/2012 05:10 AM, Srinivas KANDAGATLA wrote:
>>>> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>>>
>>>> This patch introduces of_get_child 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 libary function would
>>>> avoid code duplication, errors and is more convenient.
>>>>
>>>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>> You forgot to Cc the drivers/of maintainers, Grant and Rob. I have here.
>> Oops...
>>
>>> I can certainly see a use for this in many places; the "runtime
>>> interpreted power sequences" patch, and the regulator DT parsing code at
>>> least both could benefit from this.
> I would think the power sequences code would always iterate over the nodes.
>
>> There are at-least 7-8 places in the current kernel which could use this
>> function directly.
> Care to point them out and preferably fix them then. That would be more
> convincing that this is needed.
I did plan on sending all the 7 patches with this one, But I wanted to
know overall opinion on introduction of this new function.
Here are the instances of the drivers... which can benefit from this
function..
drivers/tty/hvc/hvc_opal.c
drivers/spi/spi-s3c64xx.c
drivers/net/ethernet/freescale/fsl_pq_mdio.c
arch/powerpc/sysdev/qe_lib/qe.c
arch/powerpc/platforms/powernv/opal.c
arch/powerpc/kernel/prom.c
>
> Rob
>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <1347534640-787-1-git-send-email-srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
2012-09-13 15:14 ` Stephen Warren
@ 2012-09-13 20:32 ` Rob Herring
[not found] ` <505242C3.7090006-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Rob Herring @ 2012-09-13 20:32 UTC (permalink / raw)
To: Srinivas KANDAGATLA
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q
On 09/13/2012 06:10 AM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>
> This patch introduces of_get_child 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 libary function would
> avoid code duplication, errors and is more convenient.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
> ---
> drivers/of/base.c | 27 +++++++++++++++++++++++++++
> include/linux/of.h | 2 ++
> 2 files changed, 29 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index d4a1c9a..d4b6840 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -391,6 +391,33 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
> EXPORT_SYMBOL(of_get_next_available_child);
>
> /**
> + * of_get_child - Find the child node by name for given parent
> + * @node: parent node
> + * @name: child name to look for.
> + *
> + * This function looks for child node for given matching name
> + *
> + * Returns a node pointer if found, with refcount incremented, use
> + * of_node_put() on it when done.
> + * else returns NULL.
> + */
> +
> +struct device_node *of_get_child(const struct device_node *node,
of_get_child_by_name would be more consistent naming with other apis.
> + const char *name)
> +{
> + struct device_node *child;
> +
> + read_lock(&devtree_lock);
I don't think you need the lock here. The for_each takes the lock while
finding the node.
> + for_each_child_of_node(node, child)
> + if (child->name && (of_node_cmp(child->name, name) == 0)
> + && of_node_get(child))
> + break;
> + read_unlock(&devtree_lock);
> + return child;
> +}
> +EXPORT_SYMBOL(of_get_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 1b11632..510e1fe 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -192,6 +192,8 @@ 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);
> +extern struct device_node *of_get_child(const struct device_node *node,
> + const char *name);
>
> #define for_each_child_of_node(parent, child) \
> for (child = of_get_next_child(parent, NULL); child != NULL; \
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name.
[not found] ` <505242C3.7090006-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2012-09-14 6:55 ` Srinivas KANDAGATLA
0 siblings, 0 replies; 8+ messages in thread
From: Srinivas KANDAGATLA @ 2012-09-14 6:55 UTC (permalink / raw)
To: Rob Herring
Cc: bergner-r/Jw6+rmf7HQT0dZR+AlfA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
davem-fT/PcQaiUtIeIZ0/mPfg9Q
On 13/09/12 21:32, Rob Herring wrote:
> On 09/13/2012 06:10 AM, Srinivas KANDAGATLA wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>>
>> This patch introduces of_get_child 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 libary function would
>> avoid code duplication, errors and is more convenient.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
>> ---
>> drivers/of/base.c | 27 +++++++++++++++++++++++++++
>> include/linux/of.h | 2 ++
>> 2 files changed, 29 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>> index d4a1c9a..d4b6840 100644
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -391,6 +391,33 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
>> EXPORT_SYMBOL(of_get_next_available_child);
>>
>> /**
>> + * of_get_child - Find the child node by name for given parent
>> + * @node: parent node
>> + * @name: child name to look for.
>> + *
>> + * This function looks for child node for given matching name
>> + *
>> + * Returns a node pointer if found, with refcount incremented, use
>> + * of_node_put() on it when done.
>> + * else returns NULL.
>> + */
>> +
>> +struct device_node *of_get_child(const struct device_node *node,
> of_get_child_by_name would be more consistent naming with other apis.
I agree.
>> + const char *name)
>> +{
>> + struct device_node *child;
>> +
>> + read_lock(&devtree_lock);
> I don't think you need the lock here. The for_each takes the lock while
> finding the node.
yes, you are correct. We don't need a readlock here.
>> + for_each_child_of_node(node, child)
>> + if (child->name && (of_node_cmp(child->name, name) == 0)
>> + && of_node_get(child))
>> + break;
>> + read_unlock(&devtree_lock);
>> + return child;
>> +}
>> +EXPORT_SYMBOL(of_get_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 1b11632..510e1fe 100644
>> --- a/include/linux/of.h
>> +++ b/include/linux/of.h
>> @@ -192,6 +192,8 @@ 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);
>> +extern struct device_node *of_get_child(const struct device_node *node,
>> + const char *name);
>>
>> #define for_each_child_of_node(parent, child) \
>> for (child = of_get_next_child(parent, NULL); child != NULL; \
>>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-09-14 6:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-13 11:10 [PATCH 3.6.0-rc5] dt: introduce of_get_child to get child node by name Srinivas KANDAGATLA
[not found] ` <1347534640-787-1-git-send-email-srinivas.kandagatla-qxv4g6HH51o@public.gmane.org>
2012-09-13 15:14 ` Stephen Warren
[not found] ` <5051F838.5080002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-09-13 15:25 ` Srinivas KANDAGATLA
[not found] ` <5051FAFA.4040507-qxv4g6HH51o@public.gmane.org>
2012-09-13 15:43 ` Rob Herring
[not found] ` <5051FF1A.7060507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-09-13 15:48 ` Stephen Warren
2012-09-13 15:51 ` Srinivas KANDAGATLA
2012-09-13 20:32 ` Rob Herring
[not found] ` <505242C3.7090006-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-09-14 6:55 ` Srinivas KANDAGATLA
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).