aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2011-10-04 16:54:30 -0400
committerTony Lindgren <tony@atomide.com>2011-10-04 16:54:30 -0400
commit3ae3e253db7385238dd9d6c67c085afa3e770a56 (patch)
treec3f93d9742c4654c9d10af829db1122bac0b6f6f /drivers
parentc541c15fb5ab48c47bc9b90121538fd30d152f23 (diff)
parent476b679a5d785d1244f6b43ad26877acf278cd18 (diff)
Merge branch 'for_3.2/3_omap_devicetree' of git://gitorious.org/omap-pm/linux into dt
Diffstat (limited to 'drivers')
-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