diff options
author | Tony Prisk <linux@prisktech.co.nz> | 2013-03-23 00:02:15 -0400 |
---|---|---|
committer | Tony Prisk <linux@prisktech.co.nz> | 2013-04-04 00:58:59 -0400 |
commit | 3daf37260e965aa4bb060db99c2ed10b28109e04 (patch) | |
tree | ea9a0908cf24622b29d21d16e30f995afe17a58a /drivers/of | |
parent | 8bb9660418e05bb1845ac1a2428444d78e322cc7 (diff) |
of: Add support for reading a u32 from a multi-value property.
This patch adds an of_property_read_u32_index() function to allow
reading a single indexed u32 value from a property containing multiple
u32 values.
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Rob Herring <robherring2@gmail.com>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 321d3ef05006..f6c89ed38db9 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -746,6 +746,39 @@ struct device_node *of_find_node_by_phandle(phandle handle) | |||
746 | EXPORT_SYMBOL(of_find_node_by_phandle); | 746 | EXPORT_SYMBOL(of_find_node_by_phandle); |
747 | 747 | ||
748 | /** | 748 | /** |
749 | * of_property_read_u32_index - Find and read a u32 from a multi-value property. | ||
750 | * | ||
751 | * @np: device node from which the property value is to be read. | ||
752 | * @propname: name of the property to be searched. | ||
753 | * @index: index of the u32 in the list of values | ||
754 | * @out_value: pointer to return value, modified only if no error. | ||
755 | * | ||
756 | * Search for a property in a device node and read nth 32-bit value from | ||
757 | * it. Returns 0 on success, -EINVAL if the property does not exist, | ||
758 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | ||
759 | * property data isn't large enough. | ||
760 | * | ||
761 | * The out_value is modified only if a valid u32 value can be decoded. | ||
762 | */ | ||
763 | int of_property_read_u32_index(const struct device_node *np, | ||
764 | const char *propname, | ||
765 | u32 index, u32 *out_value) | ||
766 | { | ||
767 | struct property *prop = of_find_property(np, propname, NULL); | ||
768 | |||
769 | if (!prop) | ||
770 | return -EINVAL; | ||
771 | if (!prop->value) | ||
772 | return -ENODATA; | ||
773 | if (((index + 1) * sizeof(*out_value)) > prop->length) | ||
774 | return -EOVERFLOW; | ||
775 | |||
776 | *out_value = be32_to_cpup(((__be32 *)prop->value) + index); | ||
777 | return 0; | ||
778 | } | ||
779 | EXPORT_SYMBOL_GPL(of_property_read_u32_index); | ||
780 | |||
781 | /** | ||
749 | * of_property_read_u8_array - Find and read an array of u8 from a property. | 782 | * of_property_read_u8_array - Find and read an array of u8 from a property. |
750 | * | 783 | * |
751 | * @np: device node from which the property value is to be read. | 784 | * @np: device node from which the property value is to be read. |