diff options
-rw-r--r-- | drivers/of/base.c | 29 | ||||
-rw-r--r-- | include/linux/of.h | 8 |
2 files changed, 37 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 8abde58cbe82..b970562e0111 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -657,6 +657,35 @@ int of_property_read_u32_array(const struct device_node *np, | |||
657 | EXPORT_SYMBOL_GPL(of_property_read_u32_array); | 657 | EXPORT_SYMBOL_GPL(of_property_read_u32_array); |
658 | 658 | ||
659 | /** | 659 | /** |
660 | * of_property_read_u64 - Find and read a 64 bit integer from a property | ||
661 | * @np: device node from which the property value is to be read. | ||
662 | * @propname: name of the property to be searched. | ||
663 | * @out_value: pointer to return value, modified only if return value is 0. | ||
664 | * | ||
665 | * Search for a property in a device node and read a 64-bit value from | ||
666 | * it. Returns 0 on success, -EINVAL if the property does not exist, | ||
667 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | ||
668 | * property data isn't large enough. | ||
669 | * | ||
670 | * The out_value is modified only if a valid u64 value can be decoded. | ||
671 | */ | ||
672 | int of_property_read_u64(const struct device_node *np, const char *propname, | ||
673 | u64 *out_value) | ||
674 | { | ||
675 | struct property *prop = of_find_property(np, propname, NULL); | ||
676 | |||
677 | if (!prop) | ||
678 | return -EINVAL; | ||
679 | if (!prop->value) | ||
680 | return -ENODATA; | ||
681 | if (sizeof(*out_value) > prop->length) | ||
682 | return -EOVERFLOW; | ||
683 | *out_value = of_read_number(prop->value, 2); | ||
684 | return 0; | ||
685 | } | ||
686 | EXPORT_SYMBOL_GPL(of_property_read_u64); | ||
687 | |||
688 | /** | ||
660 | * of_property_read_string - Find and read a string from a property | 689 | * of_property_read_string - Find and read a string from a property |
661 | * @np: device node from which the property value is to be read. | 690 | * @np: device node from which the property value is to be read. |
662 | * @propname: name of the property to be searched. | 691 | * @propname: name of the property to be searched. |
diff --git a/include/linux/of.h b/include/linux/of.h index 53107b09cbdf..1cc9930ba06a 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -200,6 +200,8 @@ extern int of_property_read_u32_array(const struct device_node *np, | |||
200 | const char *propname, | 200 | const char *propname, |
201 | u32 *out_values, | 201 | u32 *out_values, |
202 | size_t sz); | 202 | size_t sz); |
203 | extern int of_property_read_u64(const struct device_node *np, | ||
204 | const char *propname, u64 *out_value); | ||
203 | 205 | ||
204 | extern int of_property_read_string(struct device_node *np, | 206 | extern int of_property_read_string(struct device_node *np, |
205 | const char *propname, | 207 | const char *propname, |
@@ -281,6 +283,12 @@ static inline const void *of_get_property(const struct device_node *node, | |||
281 | return NULL; | 283 | return NULL; |
282 | } | 284 | } |
283 | 285 | ||
286 | static inline int of_property_read_u64(const struct device_node *np, | ||
287 | const char *propname, u64 *out_value) | ||
288 | { | ||
289 | return -ENOSYS; | ||
290 | } | ||
291 | |||
284 | #define of_match_ptr(_ptr) NULL | 292 | #define of_match_ptr(_ptr) NULL |
285 | #endif /* CONFIG_OF */ | 293 | #endif /* CONFIG_OF */ |
286 | 294 | ||