* [PATCH 1/1 v3] dt: add property iteration helpers
@ 2012-04-09 10:46 Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <1333968374-28451-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-09 10:46 UTC (permalink / raw)
To: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A
From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
This patch adds macros of_property_for_each_u32() and
of_property_for_each_string(), which iterate over an array of values
within a device-tree property. Usage is for example:
struct property *prop;
const __be32 *p;
u32 u;
of_property_for_each_u32(np, "propname", prop, p, u)
printk("U32 value: %x\n", u);
struct property *prop;
const char *s;
of_property_for_each_string(np, "propname", prop, s)
printk("String value: %s\n", s);
Based on work by Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
---
I need it for at91 for the interrupt controller
and pinctrl
Best Regards,
J.
drivers/of/base.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5806449..d9bfd49 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1260,3 +1260,44 @@ int of_alias_get_id(struct device_node *np, const char *stem)
return id;
}
EXPORT_SYMBOL_GPL(of_alias_get_id);
+
+const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
+ u32 *pu)
+{
+ const void *curv = cur;
+
+ if (!prop)
+ return NULL;
+
+ if (!cur) {
+ curv = prop->value;
+ goto out_val;
+ }
+
+ curv += sizeof(*cur);
+ if (curv >= prop->value + prop->length)
+ return NULL;
+
+out_val:
+ *pu = be32_to_cpup(curv);
+ return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_u32);
+
+const char *of_prop_next_string(struct property *prop, const char *cur)
+{
+ const void *curv = cur;
+
+ if (!prop)
+ return NULL;
+
+ if (!cur)
+ return prop->value;
+
+ curv += strlen(cur) + 1;
+ if (curv >= prop->value + prop->length)
+ return NULL;
+
+ return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_string);
diff --git a/include/linux/of.h b/include/linux/of.h
index fa7fb1d..5d23f6d 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -259,6 +259,37 @@ extern void of_detach_node(struct device_node *);
#endif
#define of_match_ptr(_ptr) (_ptr)
+extern const __be32 *of_prop_next_u32(struct property *prop,
+ const __be32 *cur, u32 *pu);
+extern const char *of_prop_next_string(struct property *prop, const char *cur);
+
+/*
+ * struct property *prop;
+ * const __be32 *p;
+ * u32 u;
+ *
+ * of_property_for_each_u32(np, "propname", prop, p, u)
+ * printk("U32 value: %x\n", u);
+ */
+#define of_property_for_each_u32(np, propname, prop, p, u) \
+ for (prop = of_find_property(np, propname, NULL), \
+ p = of_prop_next_u32(prop, NULL, &u); \
+ p; \
+ p = of_prop_next_u32(prop, p, &u))
+
+/*
+ * struct property *prop;
+ * const char *s;
+ *
+ * of_property_for_each_string(np, "propname", prop, s)
+ * printk("String value: %s\n", s);
+ */
+#define of_property_for_each_string(np, propname, prop, s) \
+ for (prop = of_find_property(np, propname, NULL), \
+ s = of_prop_next_string(prop, NULL); \
+ s; \
+ s = of_prop_next_string(prop, s))
+
#else /* CONFIG_OF */
static inline bool of_have_populated_dt(void)
@@ -349,6 +380,24 @@ static inline int of_machine_is_compatible(const char *compat)
#define of_match_ptr(_ptr) NULL
#define of_match_node(_matches, _node) NULL
+
+static inline const __be32 *of_prop_next_u32(struct property *prop,
+ const __be32 *cur, u32 *pu)
+{
+ return NULL;
+}
+
+static inline const char *of_prop_next_string(struct property *prop,
+ const char *cur)
+{
+ return NULL;
+}
+
+#define of_property_for_each_u32(np, propname, prop, p, u) \
+ while (0)
+
+#define of_property_for_each_string(np, propname, prop, s) \
+ while (0)
#endif /* CONFIG_OF */
/**
--
1.7.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1 v3] dt: add property iteration helpers
[not found] ` <1333968374-28451-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
@ 2012-04-09 15:26 ` Stephen Warren
[not found] ` <4F82FF8E.8090407-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-11 8:07 ` Linus Walleij
1 sibling, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2012-04-09 15:26 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD, Linus Walleij, Grant Likely,
Rob Herring
Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A
On 04/09/2012 04:46 AM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
>
> This patch adds macros of_property_for_each_u32() and
> of_property_for_each_string(), which iterate over an array of values
> within a device-tree property. Usage is for example:
...
> ---
> I need it for at91 for the interrupt controller
> and pinctrl
OK. But just reposting the patch isn't a good idea; we don't want it to
get applied directly to multiple places.
I'd included this patch in my series to add DT support into the pinctrl
subsystem, and hence I believe it was planned to merge it into that
tree. If it's needed elsewhere, I guess it should be put in a branch
that can be merged into both the pinctrl tree and elsewhere.
Linus, Grant, Rob, can you co-ordinate this? If you want, I can create
the branch and send a pull request to LinusW. I'm not sure which branch
Jean-Christophe needs this in for his IRQ work.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1 v3] dt: add property iteration helpers
[not found] ` <4F82FF8E.8090407-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-04-10 2:27 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120410022728.GD29577-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-04-11 8:09 ` Linus Walleij
1 sibling, 1 reply; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-10 2:27 UTC (permalink / raw)
To: Stephen Warren; +Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A, Rob Herring
On 09:26 Mon 09 Apr , Stephen Warren wrote:
> On 04/09/2012 04:46 AM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
> >
> > This patch adds macros of_property_for_each_u32() and
> > of_property_for_each_string(), which iterate over an array of values
> > within a device-tree property. Usage is for example:
> ...
> > ---
> > I need it for at91 for the interrupt controller
> > and pinctrl
>
> OK. But just reposting the patch isn't a good idea; we don't want it to
> get applied directly to multiple places.
>
> I'd included this patch in my series to add DT support into the pinctrl
> subsystem, and hence I believe it was planned to merge it into that
> tree. If it's needed elsewhere, I guess it should be put in a branch
> that can be merged into both the pinctrl tree and elsewhere.
>
> Linus, Grant, Rob, can you co-ordinate this? If you want, I can create
> the branch and send a pull request to LinusW. I'm not sure which branch
> Jean-Christophe needs this in for his IRQ work.
today just this patch and the 3.4-rc2 for the irq
for pinctrl LinusW tree
Best Regards,
J.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1 v3] dt: add property iteration helpers
[not found] ` <20120410022728.GD29577-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
@ 2012-04-10 3:46 ` Stephen Warren
[not found] ` <4F83AD1E.20002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2012-04-10 3:46 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD
Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A, Rob Herring
On 04/09/2012 08:27 PM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 09:26 Mon 09 Apr , Stephen Warren wrote:
>> On 04/09/2012 04:46 AM, Jean-Christophe PLAGNIOL-VILLARD wrote:
>>> From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
>>>
>>> This patch adds macros of_property_for_each_u32() and
>>> of_property_for_each_string(), which iterate over an array of values
>>> within a device-tree property. Usage is for example:
>> ...
>>> ---
>>> I need it for at91 for the interrupt controller
>>> and pinctrl
>>
>> OK. But just reposting the patch isn't a good idea; we don't want it to
>> get applied directly to multiple places.
>>
>> I'd included this patch in my series to add DT support into the pinctrl
>> subsystem, and hence I believe it was planned to merge it into that
>> tree. If it's needed elsewhere, I guess it should be put in a branch
>> that can be merged into both the pinctrl tree and elsewhere.
>>
>> Linus, Grant, Rob, can you co-ordinate this? If you want, I can create
>> the branch and send a pull request to LinusW. I'm not sure which branch
>> Jean-Christophe needs this in for his IRQ work.
>
> today just this patch and the 3.4-rc2 for the irq
>
> for pinctrl LinusW tree
I'm not sure I understand your response. I think you're saying that you
need only code that's in 3.4-rc2 plus this patch on top. However, that
doesn't tell us which branch your IRQ changes are going into and hence
which branch needs this patch merged in.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1 v3] dt: add property iteration helpers
[not found] ` <4F83AD1E.20002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-04-10 7:57 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-10 7:57 UTC (permalink / raw)
To: Stephen Warren; +Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A, Rob Herring
On 21:46 Mon 09 Apr , Stephen Warren wrote:
> On 04/09/2012 08:27 PM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 09:26 Mon 09 Apr , Stephen Warren wrote:
> >> On 04/09/2012 04:46 AM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> >>> From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
> >>>
> >>> This patch adds macros of_property_for_each_u32() and
> >>> of_property_for_each_string(), which iterate over an array of values
> >>> within a device-tree property. Usage is for example:
> >> ...
> >>> ---
> >>> I need it for at91 for the interrupt controller
> >>> and pinctrl
> >>
> >> OK. But just reposting the patch isn't a good idea; we don't want it to
> >> get applied directly to multiple places.
> >>
> >> I'd included this patch in my series to add DT support into the pinctrl
> >> subsystem, and hence I believe it was planned to merge it into that
> >> tree. If it's needed elsewhere, I guess it should be put in a branch
> >> that can be merged into both the pinctrl tree and elsewhere.
> >>
> >> Linus, Grant, Rob, can you co-ordinate this? If you want, I can create
> >> the branch and send a pull request to LinusW. I'm not sure which branch
> >> Jean-Christophe needs this in for his IRQ work.
> >
> > today just this patch and the 3.4-rc2 for the irq
> >
> > for pinctrl LinusW tree
>
> I'm not sure I understand your response. I think you're saying that you
> need only code that's in 3.4-rc2 plus this patch on top. However, that
> doesn't tell us which branch your IRQ changes are going into and hence
> which branch needs this patch merged in.
move some code to DT for external IRQ and default propoerties
it's Interrupt controller specific
Best Regrds,
J.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1 v3] dt: add property iteration helpers
[not found] ` <1333968374-28451-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-04-09 15:26 ` Stephen Warren
@ 2012-04-11 8:07 ` Linus Walleij
1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2012-04-11 8:07 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD
Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A
On Mon, Apr 9, 2012 at 12:46 PM, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org> wrote:
> This patch adds macros of_property_for_each_u32() and
> of_property_for_each_string(), which iterate over an array of values
> within a device-tree property. Usage is for example:
>
> struct property *prop;
> const __be32 *p;
> u32 u;
> of_property_for_each_u32(np, "propname", prop, p, u)
> printk("U32 value: %x\n", u);
>
> struct property *prop;
> const char *s;
> of_property_for_each_string(np, "propname", prop, s)
> printk("String value: %s\n", s);
>
> Based on work by Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> Signed-off-by: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> ---
> I need it for at91 for the interrupt controller
> and pinctrl
This is merged into the pinctrl tree now anyway, can I add your
Acked-by:?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1 v3] dt: add property iteration helpers
[not found] ` <4F82FF8E.8090407-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-10 2:27 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-11 8:09 ` Linus Walleij
1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2012-04-11 8:09 UTC (permalink / raw)
To: Stephen Warren; +Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A, Rob Herring
On Mon, Apr 9, 2012 at 5:26 PM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:
> Linus, Grant, Rob, can you co-ordinate this? If you want, I can create
> the branch and send a pull request to LinusW. I'm not sure which branch
> Jean-Christophe needs this in for his IRQ work.
If we don't change the patch at all I think git will survive if it gets merged
into multiple trees...
Else whatever branch needs this patch will need to merge the pinctrl
baseline or something like that.
I will stabilize the pinctrl tree as soon as I've pushed pending fixes
for the -rc:s to Torvalds.
Thanks,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-04-11 8:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-09 10:46 [PATCH 1/1 v3] dt: add property iteration helpers Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <1333968374-28451-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-04-09 15:26 ` Stephen Warren
[not found] ` <4F82FF8E.8090407-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-10 2:27 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120410022728.GD29577-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-04-10 3:46 ` Stephen Warren
[not found] ` <4F83AD1E.20002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-10 7:57 ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-11 8:09 ` Linus Walleij
2012-04-11 8:07 ` Linus Walleij
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).