dt: add property iteration helpers
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@gmail.com> Cc: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Rob Herring <rob.herring@calxeda.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
c05127c4e2
commit
c541adc637
2 changed files with 76 additions and 0 deletions
|
@ -259,6 +259,37 @@ extern void of_detach_node(struct device_node *);
|
|||
#endif
|
||||
|
||||
#define of_match_ptr(_ptr) (_ptr)
|
||||
|
||||
/*
|
||||
* struct property *prop;
|
||||
* const __be32 *p;
|
||||
* u32 u;
|
||||
*
|
||||
* of_property_for_each_u32(np, "propname", prop, p, u)
|
||||
* printk("U32 value: %x\n", u);
|
||||
*/
|
||||
const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
|
||||
u32 *pu);
|
||||
#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);
|
||||
*/
|
||||
const char *of_prop_next_string(struct property *prop, const char *cur);
|
||||
#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,10 @@ static inline int of_machine_is_compatible(const char *compat)
|
|||
|
||||
#define of_match_ptr(_ptr) NULL
|
||||
#define of_match_node(_matches, _node) 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 */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue