From 04539b46d521a675e53806a7cc0164ad191203b0 Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Mon, 3 Jun 2019 12:55:59 +0800 Subject: [PATCH] dm: core: add function dev_write_u32_array() to write u32 array values Change-Id: I6633395c7704eefff59c2145562fe239e21f3b35 Signed-off-by: Joseph Chen --- drivers/core/of_access.c | 19 +++++++++++++++++++ drivers/core/ofnode.c | 15 +++++++++++++++ drivers/core/read.c | 8 ++++++++ include/dm/of_access.h | 16 ++++++++++++++++ include/dm/ofnode.h | 13 +++++++++++++ include/dm/read.h | 19 +++++++++++++++++++ 6 files changed, 90 insertions(+) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 863f6ecc47..cfaee4e4d6 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -485,6 +485,25 @@ int of_read_u32_array(const struct device_node *np, const char *propname, return 0; } +int of_write_u32_array(const struct device_node *np, const char *propname, + u32 *values, size_t sz) +{ + __be32 *val; + + debug("%s: %s: ", __func__, propname); + val = of_find_property_value_of_size(np, propname, + sz * sizeof(*values)); + + if (IS_ERR(val)) + return PTR_ERR(val); + + debug("size %zd\n", sz); + while (sz--) + *val++ = cpu_to_be32p(values++); + + return 0; +} + int of_property_match_string(const struct device_node *np, const char *propname, const char *string) { diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 3f51b6d74b..992dd573a2 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -160,6 +160,21 @@ int ofnode_read_u32_array(ofnode node, const char *propname, } } +int ofnode_write_u32_array(ofnode node, const char *propname, + u32 *values, size_t sz) +{ + assert(ofnode_valid(node)); + debug("%s: %s: ", __func__, propname); + + if (ofnode_is_np(node)) { + return of_write_u32_array(ofnode_to_np(node), propname, + values, sz); + } else { + return fdt_setprop((void *)gd->fdt_blob, ofnode_to_offset(node), + propname, values, sz); + } +} + ofnode ofnode_first_subnode(ofnode node) { assert(ofnode_valid(node)); diff --git a/drivers/core/read.c b/drivers/core/read.c index 9f4d8c72c4..9b216726ac 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -175,6 +175,14 @@ int dev_read_u32_array(struct udevice *dev, const char *propname, return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); } +int dev_write_u32_array(struct udevice *dev, const char *propname, + u32 *values, size_t sz) +{ + if (!dev_of_valid(dev)) + return -EINVAL; + return ofnode_write_u32_array(dev_ofnode(dev), propname, values, sz); +} + const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, size_t sz) { diff --git a/include/dm/of_access.h b/include/dm/of_access.h index 035f0c8d65..48baad5ef9 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -251,6 +251,22 @@ int of_property_read_u64(const struct device_node *np, const char *propname, int of_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz); +/** + * of_write_u32_array() - Find and write an array of 32 bit integers + * + * Search for a property in a device node and write 32-bit value(s) to + * it. + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @values: pointer to update value, modified only if return value is 0. + * @sz: number of array elements to read + * @return 0 on success, -EINVAL if the property does not exist, -ENODATA + * if property does not have a value, and -EOVERFLOW is longer than sz. + */ +int of_write_u32_array(const struct device_node *np, const char *propname, + u32 *values, size_t sz); + /** * of_property_match_string() - Find string in a list and return index * diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index f90ce33ea9..8a4291a6ad 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -274,6 +274,19 @@ const char *ofnode_read_string(ofnode node, const char *propname); int ofnode_read_u32_array(ofnode node, const char *propname, u32 *out_values, size_t sz); +/** + * ofnode_write_u32_array() - Find and write an array of 32 bit integers + * + * @node: valid node reference to read property from + * @propname: name of the property to read + * @values: pointer to update value, modified only if return value is 0 + * @sz: number of array elements to read + * @return 0 on success, -EINVAL if the property does not exist, -ENODATA + * if property does not have a value, and -EOVERFLOW is longer than sz. + */ +int ofnode_write_u32_array(ofnode node, const char *propname, + u32 *values, size_t sz); + /** * ofnode_read_bool() - read a boolean value from a property * diff --git a/include/dm/read.h b/include/dm/read.h index 77c9ae6fcd..71b128ff10 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -341,6 +341,25 @@ int dev_read_alias_seq(struct udevice *dev, int *devnump); int dev_read_u32_array(struct udevice *dev, const char *propname, u32 *out_values, size_t sz); +/** + * dev_write_u32_array() - Find and write an array of 32 bit integers + * + * Search for a property in a device node and write 32-bit value(s) to + * it. + * + * The out_values is modified only if a valid u32 value can be decoded. + * + * @dev: device to look up + * @propname: name of the property to read + * @values: pointer to update value, modified only if return value is 0 + * @sz: number of array elements to read + * @return 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. + */ +int dev_write_u32_array(struct udevice *dev, const char *propname, + u32 *values, size_t sz); + /** * dev_read_first_subnode() - find the first subnode of a device's node *