Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dt: add helper to read 64-bit integers

Add a helper similar to of_property_read_u32() that handles 64-bit
integers.

v2/v3: constify device node and property name parameters.

Cc: Grant Likely <grant.likely@secretlab.ca>
Reviewed-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Jamie Iles <jamie@jamieiles.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Jamie Iles and committed by
Grant Likely
4cd7f7a3 85888069

+37
+29
drivers/of/base.c
··· 657 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 689 * of_property_read_string - Find and read a string from a property 661 690 * @np: device node from which the property value is to be read. 662 691 * @propname: name of the property to be searched.
+8
include/linux/of.h
··· 200 200 const char *propname, 201 201 u32 *out_values, 202 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 206 extern int of_property_read_string(struct device_node *np, 205 207 const char *propname, ··· 281 279 int *lenp) 282 280 { 283 281 return NULL; 282 + } 283 + 284 + static inline int of_property_read_u64(const struct device_node *np, 285 + const char *propname, u64 *out_value) 286 + { 287 + return -ENOSYS; 284 288 } 285 289 286 290 #define of_match_ptr(_ptr) NULL