aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-11-01 23:58:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-01 23:58:25 -0400
commit81a3c10ce8a7fd5bf9a06bfc38bd417512911831 (patch)
tree12ceac10fae8c4b2dc17b362672a5db305a8d960 /drivers/of/base.c
parent6585dea1f99cc2265582ff2e4cc1727062136e92 (diff)
parentdf80442d1ee2902c2e39f90f18160f2e08d14c06 (diff)
Merge branch 'next/cleanup2' of git://git.linaro.org/people/arnd/arm-soc
* 'next/cleanup2' of git://git.linaro.org/people/arnd/arm-soc: (31 commits) ARM: OMAP: Warn if omap_ioremap is called before SoC detection ARM: OMAP: Move set_globals initialization to happen in init_early ARM: OMAP: Map SRAM later on with ioremap_exec() ARM: OMAP: Remove calls to SRAM allocations for framebuffer ARM: OMAP: Avoid cpu_is_omapxxxx usage until map_io is done ARM: OMAP1: Use generic map_io, init_early and init_irq arm/dts: OMAP3+: Add mpu, dsp and iva nodes arm/dts: OMAP4: Add a main ocp entry bound to l3-noc driver ARM: OMAP2+: l3-noc: Add support for device-tree ARM: OMAP2+: board-generic: Add i2c static init ARM: OMAP2+: board-generic: Add DT support to generic board arm/dts: Add support for OMAP3 Beagle board arm/dts: Add initial device tree support for OMAP3 SoC arm/dts: Add support for OMAP4 SDP board arm/dts: Add support for OMAP4 PandaBoard arm/dts: Add initial device tree support for OMAP4 SoC ARM: OMAP: omap_device: Add a method to build an omap_device from a DT node ARM: OMAP: omap_device: Add omap_device_[alloc|delete] for DT integration of: Add helpers to get one string in multiple strings property ARM: OMAP2+: devices: Remove all omap_device_pm_latency structures ... Fix up trivial header file conflicts in arch/arm/mach-omap2/board-generic.c
Diffstat (limited to 'drivers/of/base.c')
-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 b970562e0111..9b6588ef0673 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -716,6 +716,90 @@ int of_property_read_string(struct device_node *np, const char *propname,
716EXPORT_SYMBOL_GPL(of_property_read_string); 716EXPORT_SYMBOL_GPL(of_property_read_string);
717 717
718/** 718/**
719 * of_property_read_string_index - Find and read a string from a multiple
720 * strings property.
721 * @np: device node from which the property value is to be read.
722 * @propname: name of the property to be searched.
723 * @index: index of the string in the list of strings
724 * @out_string: pointer to null terminated return string, modified only if
725 * return value is 0.
726 *
727 * Search for a property in a device tree node and retrieve a null
728 * terminated string value (pointer to data, not a copy) in the list of strings
729 * contained in that property.
730 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
731 * property does not have a value, and -EILSEQ if the string is not
732 * null-terminated within the length of the property data.
733 *
734 * The out_string pointer is modified only if a valid string can be decoded.
735 */
736int of_property_read_string_index(struct device_node *np, const char *propname,
737 int index, const char **output)
738{
739 struct property *prop = of_find_property(np, propname, NULL);
740 int i = 0;
741 size_t l = 0, total = 0;
742 const char *p;
743
744 if (!prop)
745 return -EINVAL;
746 if (!prop->value)
747 return -ENODATA;
748 if (strnlen(prop->value, prop->length) >= prop->length)
749 return -EILSEQ;
750
751 p = prop->value;
752
753 for (i = 0; total < prop->length; total += l, p += l) {
754 l = strlen(p) + 1;
755 if ((*p != 0) && (i++ == index)) {
756 *output = p;
757 return 0;
758 }
759 }
760 return -ENODATA;
761}
762EXPORT_SYMBOL_GPL(of_property_read_string_index);
763
764
765/**
766 * of_property_count_strings - Find and return the number of strings from a
767 * multiple strings property.
768 * @np: device node from which the property value is to be read.
769 * @propname: name of the property to be searched.
770 *
771 * Search for a property in a device tree node and retrieve the number of null
772 * terminated string contain in it. Returns the number of strings on
773 * success, -EINVAL if the property does not exist, -ENODATA if property
774 * does not have a value, and -EILSEQ if the string is not null-terminated
775 * within the length of the property data.
776 */
777int of_property_count_strings(struct device_node *np, const char *propname)
778{
779 struct property *prop = of_find_property(np, propname, NULL);
780 int i = 0;
781 size_t l = 0, total = 0;
782 const char *p;
783
784 if (!prop)
785 return -EINVAL;
786 if (!prop->value)
787 return -ENODATA;
788 if (strnlen(prop->value, prop->length) >= prop->length)
789 return -EILSEQ;
790
791 p = prop->value;
792
793 for (i = 0; total < prop->length; total += l, p += l) {
794 l = strlen(p) + 1;
795 if (*p != 0)
796 i++;
797 }
798 return i;
799}
800EXPORT_SYMBOL_GPL(of_property_count_strings);
801
802/**
719 * of_parse_phandle - Resolve a phandle property to a device_node pointer 803 * of_parse_phandle - Resolve a phandle property to a device_node pointer
720 * @np: Pointer to device node holding phandle property 804 * @np: Pointer to device node holding phandle property
721 * @phandle_name: Name of property holding a phandle value 805 * @phandle_name: Name of property holding a phandle value