diff options
author | Mark Brown <broonie@linaro.org> | 2014-02-12 10:49:36 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-12 10:49:36 -0500 |
commit | 13cf4ea01abcc7868c64ce0f26dd5cb3abafda4c (patch) | |
tree | 6b997f4f2ffd6c4e6f943610f49c72f1dc984eef | |
parent | 6127daa85094e20b42d306dde800e0d745847990 (diff) | |
parent | ad54a0cfbeb4bd4033d09017557ccbc423f9d5ff (diff) |
Merge branch 'topic/of-core' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator into regulator-ti-abb
-rw-r--r-- | drivers/of/base.c | 32 | ||||
-rw-r--r-- | include/linux/of.h | 76 |
2 files changed, 108 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index ff85450d5683..8a2a55c65e5d 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -886,6 +886,38 @@ struct device_node *of_find_node_by_phandle(phandle handle) | |||
886 | EXPORT_SYMBOL(of_find_node_by_phandle); | 886 | EXPORT_SYMBOL(of_find_node_by_phandle); |
887 | 887 | ||
888 | /** | 888 | /** |
889 | * of_property_count_elems_of_size - Count the number of elements in a property | ||
890 | * | ||
891 | * @np: device node from which the property value is to be read. | ||
892 | * @propname: name of the property to be searched. | ||
893 | * @elem_size: size of the individual element | ||
894 | * | ||
895 | * Search for a property in a device node and count the number of elements of | ||
896 | * size elem_size in it. Returns number of elements on sucess, -EINVAL if the | ||
897 | * property does not exist or its length does not match a multiple of elem_size | ||
898 | * and -ENODATA if the property does not have a value. | ||
899 | */ | ||
900 | int of_property_count_elems_of_size(const struct device_node *np, | ||
901 | const char *propname, int elem_size) | ||
902 | { | ||
903 | struct property *prop = of_find_property(np, propname, NULL); | ||
904 | |||
905 | if (!prop) | ||
906 | return -EINVAL; | ||
907 | if (!prop->value) | ||
908 | return -ENODATA; | ||
909 | |||
910 | if (prop->length % elem_size != 0) { | ||
911 | pr_err("size of %s in node %s is not a multiple of %d\n", | ||
912 | propname, np->full_name, elem_size); | ||
913 | return -EINVAL; | ||
914 | } | ||
915 | |||
916 | return prop->length / elem_size; | ||
917 | } | ||
918 | EXPORT_SYMBOL_GPL(of_property_count_elems_of_size); | ||
919 | |||
920 | /** | ||
889 | * of_find_property_value_of_size | 921 | * of_find_property_value_of_size |
890 | * | 922 | * |
891 | * @np: device node from which the property value is to be read. | 923 | * @np: device node from which the property value is to be read. |
diff --git a/include/linux/of.h b/include/linux/of.h index 70c64ba17fa5..b59f2e41c7ce 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -250,6 +250,8 @@ extern struct device_node *of_find_node_with_property( | |||
250 | extern struct property *of_find_property(const struct device_node *np, | 250 | extern struct property *of_find_property(const struct device_node *np, |
251 | const char *name, | 251 | const char *name, |
252 | int *lenp); | 252 | int *lenp); |
253 | extern int of_property_count_elems_of_size(const struct device_node *np, | ||
254 | const char *propname, int elem_size); | ||
253 | extern int of_property_read_u32_index(const struct device_node *np, | 255 | extern int of_property_read_u32_index(const struct device_node *np, |
254 | const char *propname, | 256 | const char *propname, |
255 | u32 index, u32 *out_value); | 257 | u32 index, u32 *out_value); |
@@ -431,6 +433,12 @@ static inline struct device_node *of_find_compatible_node( | |||
431 | return NULL; | 433 | return NULL; |
432 | } | 434 | } |
433 | 435 | ||
436 | static inline int of_property_count_elems_of_size(const struct device_node *np, | ||
437 | const char *propname, int elem_size) | ||
438 | { | ||
439 | return -ENOSYS; | ||
440 | } | ||
441 | |||
434 | static inline int of_property_read_u32_index(const struct device_node *np, | 442 | static inline int of_property_read_u32_index(const struct device_node *np, |
435 | const char *propname, u32 index, u32 *out_value) | 443 | const char *propname, u32 index, u32 *out_value) |
436 | { | 444 | { |
@@ -570,6 +578,74 @@ static inline int of_node_to_nid(struct device_node *device) { return 0; } | |||
570 | #endif | 578 | #endif |
571 | 579 | ||
572 | /** | 580 | /** |
581 | * of_property_count_u8_elems - Count the number of u8 elements in a property | ||
582 | * | ||
583 | * @np: device node from which the property value is to be read. | ||
584 | * @propname: name of the property to be searched. | ||
585 | * | ||
586 | * Search for a property in a device node and count the number of u8 elements | ||
587 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
588 | * not exist or its length does not match a multiple of u8 and -ENODATA if the | ||
589 | * property does not have a value. | ||
590 | */ | ||
591 | static inline int of_property_count_u8_elems(const struct device_node *np, | ||
592 | const char *propname) | ||
593 | { | ||
594 | return of_property_count_elems_of_size(np, propname, sizeof(u8)); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * of_property_count_u16_elems - Count the number of u16 elements in a property | ||
599 | * | ||
600 | * @np: device node from which the property value is to be read. | ||
601 | * @propname: name of the property to be searched. | ||
602 | * | ||
603 | * Search for a property in a device node and count the number of u16 elements | ||
604 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
605 | * not exist or its length does not match a multiple of u16 and -ENODATA if the | ||
606 | * property does not have a value. | ||
607 | */ | ||
608 | static inline int of_property_count_u16_elems(const struct device_node *np, | ||
609 | const char *propname) | ||
610 | { | ||
611 | return of_property_count_elems_of_size(np, propname, sizeof(u16)); | ||
612 | } | ||
613 | |||
614 | /** | ||
615 | * of_property_count_u32_elems - Count the number of u32 elements in a property | ||
616 | * | ||
617 | * @np: device node from which the property value is to be read. | ||
618 | * @propname: name of the property to be searched. | ||
619 | * | ||
620 | * Search for a property in a device node and count the number of u32 elements | ||
621 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
622 | * not exist or its length does not match a multiple of u32 and -ENODATA if the | ||
623 | * property does not have a value. | ||
624 | */ | ||
625 | static inline int of_property_count_u32_elems(const struct device_node *np, | ||
626 | const char *propname) | ||
627 | { | ||
628 | return of_property_count_elems_of_size(np, propname, sizeof(u32)); | ||
629 | } | ||
630 | |||
631 | /** | ||
632 | * of_property_count_u64_elems - Count the number of u64 elements in a property | ||
633 | * | ||
634 | * @np: device node from which the property value is to be read. | ||
635 | * @propname: name of the property to be searched. | ||
636 | * | ||
637 | * Search for a property in a device node and count the number of u64 elements | ||
638 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
639 | * not exist or its length does not match a multiple of u64 and -ENODATA if the | ||
640 | * property does not have a value. | ||
641 | */ | ||
642 | static inline int of_property_count_u64_elems(const struct device_node *np, | ||
643 | const char *propname) | ||
644 | { | ||
645 | return of_property_count_elems_of_size(np, propname, sizeof(u64)); | ||
646 | } | ||
647 | |||
648 | /** | ||
573 | * of_property_read_bool - Findfrom a property | 649 | * of_property_read_bool - Findfrom a property |
574 | * @np: device node from which the property value is to be read. | 650 | * @np: device node from which the property value is to be read. |
575 | * @propname: name of the property to be searched. | 651 | * @propname: name of the property to be searched. |