aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-04-04 11:27:46 -0400
committerLinus Walleij <linus.walleij@linaro.org>2012-04-18 07:53:11 -0400
commitc541adc637066407d4cda9db14dcb0e618966a4c (patch)
tree0fda4e8f97c9e9a2a61524f3bb390a0a6b04ccbe /drivers/of/base.c
parentc05127c4e2c6e7d9949347a76fd05c337bcd5e84 (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 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 580644986945..d9bfd49b1935 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)
1260 return id; 1260 return id;
1261} 1261}
1262EXPORT_SYMBOL_GPL(of_alias_get_id); 1262EXPORT_SYMBOL_GPL(of_alias_get_id);
1263
1264const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
1265 u32 *pu)
1266{
1267 const void *curv = cur;
1268
1269 if (!prop)
1270 return NULL;
1271
1272 if (!cur) {
1273 curv = prop->value;
1274 goto out_val;
1275 }
1276
1277 curv += sizeof(*cur);
1278 if (curv >= prop->value + prop->length)
1279 return NULL;
1280
1281out_val:
1282 *pu = be32_to_cpup(curv);
1283 return curv;
1284}
1285EXPORT_SYMBOL_GPL(of_prop_next_u32);
1286
1287const char *of_prop_next_string(struct property *prop, const char *cur)
1288{
1289 const void *curv = cur;
1290
1291 if (!prop)
1292 return NULL;
1293
1294 if (!cur)
1295 return prop->value;
1296
1297 curv += strlen(cur) + 1;
1298 if (curv >= prop->value + prop->length)
1299 return NULL;
1300
1301 return curv;
1302}
1303EXPORT_SYMBOL_GPL(of_prop_next_string);