diff options
author | Rob Herring <rob.herring@calxeda.com> | 2011-07-06 16:42:58 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2011-07-06 16:58:09 -0400 |
commit | 0e373639ad7c7ef2b0c9cf907574b266791b9778 (patch) | |
tree | 2600fab3cee4360311a3e0784aa2498dc9cceb6a /drivers/of | |
parent | b84e773119e1401e6ebd8906fb0b2a43bbe64871 (diff) |
dt: add helper function to read u32 arrays
Rework of_property_read_u32 to read an array of values. Then
of_property_read_u32 becomes an inline with array size of 1.
Also make struct device_node ptr const.
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 57ec27bed44f..02ed36719def 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -596,32 +596,39 @@ struct device_node *of_find_node_by_phandle(phandle handle) | |||
596 | EXPORT_SYMBOL(of_find_node_by_phandle); | 596 | EXPORT_SYMBOL(of_find_node_by_phandle); |
597 | 597 | ||
598 | /** | 598 | /** |
599 | * of_property_read_u32 - Find and read a 32 bit integer from a property | 599 | * of_property_read_u32_array - Find and read an array of 32 bit integers |
600 | * from a property. | ||
601 | * | ||
600 | * @np: device node from which the property value is to be read. | 602 | * @np: device node from which the property value is to be read. |
601 | * @propname: name of the property to be searched. | 603 | * @propname: name of the property to be searched. |
602 | * @out_value: pointer to return value, modified only if return value is 0. | 604 | * @out_value: pointer to return value, modified only if return value is 0. |
603 | * | 605 | * |
604 | * Search for a property in a device node and read a 32-bit value from | 606 | * Search for a property in a device node and read 32-bit value(s) from |
605 | * it. Returns 0 on success, -EINVAL if the property does not exist, | 607 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
606 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | 608 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
607 | * property data isn't large enough. | 609 | * property data isn't large enough. |
608 | * | 610 | * |
609 | * The out_value is modified only if a valid u32 value can be decoded. | 611 | * The out_value is modified only if a valid u32 value can be decoded. |
610 | */ | 612 | */ |
611 | int of_property_read_u32(struct device_node *np, char *propname, u32 *out_value) | 613 | int of_property_read_u32_array(const struct device_node *np, char *propname, |
614 | u32 *out_values, size_t sz) | ||
612 | { | 615 | { |
613 | struct property *prop = of_find_property(np, propname, NULL); | 616 | struct property *prop = of_find_property(np, propname, NULL); |
617 | const __be32 *val; | ||
614 | 618 | ||
615 | if (!prop) | 619 | if (!prop) |
616 | return -EINVAL; | 620 | return -EINVAL; |
617 | if (!prop->value) | 621 | if (!prop->value) |
618 | return -ENODATA; | 622 | return -ENODATA; |
619 | if (sizeof(*out_value) > prop->length) | 623 | if ((sz * sizeof(*out_values)) > prop->length) |
620 | return -EOVERFLOW; | 624 | return -EOVERFLOW; |
621 | *out_value = be32_to_cpup(prop->value); | 625 | |
626 | val = prop->value; | ||
627 | while (sz--) | ||
628 | *out_values++ = be32_to_cpup(val++); | ||
622 | return 0; | 629 | return 0; |
623 | } | 630 | } |
624 | EXPORT_SYMBOL_GPL(of_property_read_u32); | 631 | EXPORT_SYMBOL_GPL(of_property_read_u32_array); |
625 | 632 | ||
626 | /** | 633 | /** |
627 | * of_property_read_string - Find and read a string from a property | 634 | * of_property_read_string - Find and read a string from a property |