diff options
author | Stephen Warren <swarren@nvidia.com> | 2012-04-04 11:27:46 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2012-04-18 07:53:11 -0400 |
commit | c541adc637066407d4cda9db14dcb0e618966a4c (patch) | |
tree | 0fda4e8f97c9e9a2a61524f3bb390a0a6b04ccbe /include | |
parent | c05127c4e2c6e7d9949347a76fd05c337bcd5e84 (diff) |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/of.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/linux/of.h b/include/linux/of.h index fa7fb1d97458..e3f942d9da89 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -259,6 +259,37 @@ extern void of_detach_node(struct device_node *); | |||
259 | #endif | 259 | #endif |
260 | 260 | ||
261 | #define of_match_ptr(_ptr) (_ptr) | 261 | #define of_match_ptr(_ptr) (_ptr) |
262 | |||
263 | /* | ||
264 | * struct property *prop; | ||
265 | * const __be32 *p; | ||
266 | * u32 u; | ||
267 | * | ||
268 | * of_property_for_each_u32(np, "propname", prop, p, u) | ||
269 | * printk("U32 value: %x\n", u); | ||
270 | */ | ||
271 | const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, | ||
272 | u32 *pu); | ||
273 | #define of_property_for_each_u32(np, propname, prop, p, u) \ | ||
274 | for (prop = of_find_property(np, propname, NULL), \ | ||
275 | p = of_prop_next_u32(prop, NULL, &u); \ | ||
276 | p; \ | ||
277 | p = of_prop_next_u32(prop, p, &u)) | ||
278 | |||
279 | /* | ||
280 | * struct property *prop; | ||
281 | * const char *s; | ||
282 | * | ||
283 | * of_property_for_each_string(np, "propname", prop, s) | ||
284 | * printk("String value: %s\n", s); | ||
285 | */ | ||
286 | const char *of_prop_next_string(struct property *prop, const char *cur); | ||
287 | #define of_property_for_each_string(np, propname, prop, s) \ | ||
288 | for (prop = of_find_property(np, propname, NULL), \ | ||
289 | s = of_prop_next_string(prop, NULL); \ | ||
290 | s; \ | ||
291 | s = of_prop_next_string(prop, s)) | ||
292 | |||
262 | #else /* CONFIG_OF */ | 293 | #else /* CONFIG_OF */ |
263 | 294 | ||
264 | static inline bool of_have_populated_dt(void) | 295 | static inline bool of_have_populated_dt(void) |
@@ -349,6 +380,10 @@ static inline int of_machine_is_compatible(const char *compat) | |||
349 | 380 | ||
350 | #define of_match_ptr(_ptr) NULL | 381 | #define of_match_ptr(_ptr) NULL |
351 | #define of_match_node(_matches, _node) NULL | 382 | #define of_match_node(_matches, _node) NULL |
383 | #define of_property_for_each_u32(np, propname, prop, p, u) \ | ||
384 | while (0) | ||
385 | #define of_property_for_each_string(np, propname, prop, s) \ | ||
386 | while (0) | ||
352 | #endif /* CONFIG_OF */ | 387 | #endif /* CONFIG_OF */ |
353 | 388 | ||
354 | /** | 389 | /** |