diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2012-11-19 23:45:19 -0500 |
---|---|---|
committer | Rob Herring <rob.herring@calxeda.com> | 2012-11-20 23:58:55 -0500 |
commit | be193249b4178158c0f697cb452b2bbf0cb16361 (patch) | |
tree | 4278eba967e625f0cdb6de865a83038243c51e80 /drivers/of | |
parent | 9846210b1ec9bbaa30022d6d8af7e55ef67ccb45 (diff) |
dt: add helper function to read u8 & u16 variables & arrays
This adds following helper routines:
- of_property_read_u8_array()
- of_property_read_u16_array()
- of_property_read_u8()
- of_property_read_u16()
This expects arrays from DT to be passed as:
- u8 array:
property = /bits/ 8 <0x50 0x60 0x70>;
- u16 array:
property = /bits/ 16 <0x5000 0x6000 0x7000>;
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index af3b22ac7627..f564e3107b3e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -671,12 +671,89 @@ struct device_node *of_find_node_by_phandle(phandle handle) | |||
671 | EXPORT_SYMBOL(of_find_node_by_phandle); | 671 | EXPORT_SYMBOL(of_find_node_by_phandle); |
672 | 672 | ||
673 | /** | 673 | /** |
674 | * of_property_read_u8_array - Find and read an array of u8 from a property. | ||
675 | * | ||
676 | * @np: device node from which the property value is to be read. | ||
677 | * @propname: name of the property to be searched. | ||
678 | * @out_value: pointer to return value, modified only if return value is 0. | ||
679 | * @sz: number of array elements to read | ||
680 | * | ||
681 | * Search for a property in a device node and read 8-bit value(s) from | ||
682 | * it. Returns 0 on success, -EINVAL if the property does not exist, | ||
683 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | ||
684 | * property data isn't large enough. | ||
685 | * | ||
686 | * dts entry of array should be like: | ||
687 | * property = /bits/ 8 <0x50 0x60 0x70>; | ||
688 | * | ||
689 | * The out_value is modified only if a valid u8 value can be decoded. | ||
690 | */ | ||
691 | int of_property_read_u8_array(const struct device_node *np, | ||
692 | const char *propname, u8 *out_values, size_t sz) | ||
693 | { | ||
694 | struct property *prop = of_find_property(np, propname, NULL); | ||
695 | const u8 *val; | ||
696 | |||
697 | if (!prop) | ||
698 | return -EINVAL; | ||
699 | if (!prop->value) | ||
700 | return -ENODATA; | ||
701 | if ((sz * sizeof(*out_values)) > prop->length) | ||
702 | return -EOVERFLOW; | ||
703 | |||
704 | val = prop->value; | ||
705 | while (sz--) | ||
706 | *out_values++ = *val++; | ||
707 | return 0; | ||
708 | } | ||
709 | EXPORT_SYMBOL_GPL(of_property_read_u8_array); | ||
710 | |||
711 | /** | ||
712 | * of_property_read_u16_array - Find and read an array of u16 from a property. | ||
713 | * | ||
714 | * @np: device node from which the property value is to be read. | ||
715 | * @propname: name of the property to be searched. | ||
716 | * @out_value: pointer to return value, modified only if return value is 0. | ||
717 | * @sz: number of array elements to read | ||
718 | * | ||
719 | * Search for a property in a device node and read 16-bit value(s) from | ||
720 | * it. Returns 0 on success, -EINVAL if the property does not exist, | ||
721 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | ||
722 | * property data isn't large enough. | ||
723 | * | ||
724 | * dts entry of array should be like: | ||
725 | * property = /bits/ 16 <0x5000 0x6000 0x7000>; | ||
726 | * | ||
727 | * The out_value is modified only if a valid u16 value can be decoded. | ||
728 | */ | ||
729 | int of_property_read_u16_array(const struct device_node *np, | ||
730 | const char *propname, u16 *out_values, size_t sz) | ||
731 | { | ||
732 | struct property *prop = of_find_property(np, propname, NULL); | ||
733 | const __be16 *val; | ||
734 | |||
735 | if (!prop) | ||
736 | return -EINVAL; | ||
737 | if (!prop->value) | ||
738 | return -ENODATA; | ||
739 | if ((sz * sizeof(*out_values)) > prop->length) | ||
740 | return -EOVERFLOW; | ||
741 | |||
742 | val = prop->value; | ||
743 | while (sz--) | ||
744 | *out_values++ = be16_to_cpup(val++); | ||
745 | return 0; | ||
746 | } | ||
747 | EXPORT_SYMBOL_GPL(of_property_read_u16_array); | ||
748 | |||
749 | /** | ||
674 | * of_property_read_u32_array - Find and read an array of 32 bit integers | 750 | * of_property_read_u32_array - Find and read an array of 32 bit integers |
675 | * from a property. | 751 | * from a property. |
676 | * | 752 | * |
677 | * @np: device node from which the property value is to be read. | 753 | * @np: device node from which the property value is to be read. |
678 | * @propname: name of the property to be searched. | 754 | * @propname: name of the property to be searched. |
679 | * @out_value: pointer to return value, modified only if return value is 0. | 755 | * @out_value: pointer to return value, modified only if return value is 0. |
756 | * @sz: number of array elements to read | ||
680 | * | 757 | * |
681 | * Search for a property in a device node and read 32-bit value(s) from | 758 | * Search for a property in a device node and read 32-bit value(s) from |
682 | * it. Returns 0 on success, -EINVAL if the property does not exist, | 759 | * it. Returns 0 on success, -EINVAL if the property does not exist, |