diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-10-12 08:26:09 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-10-13 08:45:12 +0200 |
commit | 05f622f7bc5baa414e78d9ee1928f08b321f53f8 (patch) | |
tree | b5f6eed98a3aea94fc7fec3462a1c255068846d3 /drivers | |
parent | 35f0f5f3c0bf14aaf1d3cbfe9735282bd7ee9262 (diff) | |
download | barebox-05f622f7bc5baa414e78d9ee1928f08b321f53f8.tar.gz barebox-05f622f7bc5baa414e78d9ee1928f08b321f53f8.tar.xz |
of: implement of_property_read_u64_array
For reading reg with #address-cells and #size-cells of 2,
an of_property_read_u64_array can be quite convenient.
Add one.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/base.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 4e88af7b22..7da4ff62f0 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -893,6 +893,43 @@ int of_property_read_u64(const struct device_node *np, const char *propname, EXPORT_SYMBOL_GPL(of_property_read_u64); /** + * of_property_read_u64_array - Find and read an array of 64 bit integers + * from a property. + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_value: pointer to return value, modified only if return value is 0. + * @sz: number of array elements to read + * + * Search for a property in a device node and read 64-bit value(s) from + * it. Returns 0 on success, -EINVAL if the property does not exist, + * -ENODATA if property does not have a value, and -EOVERFLOW if the + * property data isn't large enough. + * + * The out_value is modified only if a valid u64 value can be decoded. + */ +int of_property_read_variable_u64_array(const struct device_node *np, + const char *propname, u64 *out_values, + size_t sz) +{ + size_t count; + const __be32 *val = of_find_property_value_of_size(np, propname, + (sz * sizeof(*out_values))); + + if (IS_ERR(val)) + return PTR_ERR(val); + + count = sz; + while (count--) { + *out_values++ = of_read_number(val, 2); + val += 2; + } + + return sz; +} +EXPORT_SYMBOL_GPL(of_property_read_variable_u64_array); + +/** * of_property_read_string - Find and read a string from a property * @np: device node from which the property value is to be read. * @propname: name of the property to be searched. |