aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorBenoit Cousson <b-cousson@ti.com>2011-09-27 11:45:43 -0400
committerKevin Hilman <khilman@ti.com>2011-10-04 12:52:23 -0400
commit4fcd15a032cec4b2684a32c86e895b50cdbee50c (patch)
tree21f86422ba269e5ddec5916fbd88bc294e9d7451 /drivers/of
parentf718e2c034bf6ff872106344935006230764cb12 (diff)
of: Add helpers to get one string in multiple strings property
Add of_property_read_string_index and of_property_count_strings to retrieve one string inside a property that will contains severals strings. Signed-off-by: Benoit Cousson <b-cousson@ti.com> Acked-by: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Kevin Hilman <khilman@ti.com>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3ff22e32b602..f7239b33d762 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -662,6 +662,90 @@ int of_property_read_string(struct device_node *np, const char *propname,
662EXPORT_SYMBOL_GPL(of_property_read_string); 662EXPORT_SYMBOL_GPL(of_property_read_string);
663 663
664/** 664/**
665 * of_property_read_string_index - Find and read a string from a multiple
666 * strings property.
667 * @np: device node from which the property value is to be read.
668 * @propname: name of the property to be searched.
669 * @index: index of the string in the list of strings
670 * @out_string: pointer to null terminated return string, modified only if
671 * return value is 0.
672 *
673 * Search for a property in a device tree node and retrieve a null
674 * terminated string value (pointer to data, not a copy) in the list of strings
675 * contained in that property.
676 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
677 * property does not have a value, and -EILSEQ if the string is not
678 * null-terminated within the length of the property data.
679 *
680 * The out_string pointer is modified only if a valid string can be decoded.
681 */
682int of_property_read_string_index(struct device_node *np, const char *propname,
683 int index, const char **output)
684{
685 struct property *prop = of_find_property(np, propname, NULL);
686 int i = 0;
687 size_t l = 0, total = 0;
688 const char *p;
689
690 if (!prop)
691 return -EINVAL;
692 if (!prop->value)
693 return -ENODATA;
694 if (strnlen(prop->value, prop->length) >= prop->length)
695 return -EILSEQ;
696
697 p = prop->value;
698
699 for (i = 0; total < prop->length; total += l, p += l) {
700 l = strlen(p) + 1;
701 if ((*p != 0) && (i++ == index)) {
702 *output = p;
703 return 0;
704 }
705 }
706 return -ENODATA;
707}
708EXPORT_SYMBOL_GPL(of_property_read_string_index);
709
710
711/**
712 * of_property_count_strings - Find and return the number of strings from a
713 * multiple strings property.
714 * @np: device node from which the property value is to be read.
715 * @propname: name of the property to be searched.
716 *
717 * Search for a property in a device tree node and retrieve the number of null
718 * terminated string contain in it. Returns the number of strings on
719 * success, -EINVAL if the property does not exist, -ENODATA if property
720 * does not have a value, and -EILSEQ if the string is not null-terminated
721 * within the length of the property data.
722 */
723int of_property_count_strings(struct device_node *np, const char *propname)
724{
725 struct property *prop = of_find_property(np, propname, NULL);
726 int i = 0;
727 size_t l = 0, total = 0;
728 const char *p;
729
730 if (!prop)
731 return -EINVAL;
732 if (!prop->value)
733 return -ENODATA;
734 if (strnlen(prop->value, prop->length) >= prop->length)
735 return -EILSEQ;
736
737 p = prop->value;
738
739 for (i = 0; total < prop->length; total += l, p += l) {
740 l = strlen(p) + 1;
741 if (*p != 0)
742 i++;
743 }
744 return i;
745}
746EXPORT_SYMBOL_GPL(of_property_count_strings);
747
748/**
665 * of_parse_phandle - Resolve a phandle property to a device_node pointer 749 * of_parse_phandle - Resolve a phandle property to a device_node pointer
666 * @np: Pointer to device node holding phandle property 750 * @np: Pointer to device node holding phandle property
667 * @phandle_name: Name of property holding a phandle value 751 * @phandle_name: Name of property holding a phandle value