summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-04-16 18:40:42 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-04-16 18:40:42 +0200
commit32a48332753ac141998197f9f0e9c99d0d855102 (patch)
tree458d76d9917dc6640f0d0f53e718c4b12cd95242 /drivers/of
parentddc3394069ab2e43e64b3f0c2465a3fb3069a970 (diff)
parentb2cd220105a6bd03ff819a99ce0c3c853a6d00f3 (diff)
downloadbarebox-32a48332753ac141998197f9f0e9c99d0d855102.tar.gz
barebox-32a48332753ac141998197f9f0e9c99d0d855102.tar.xz
Merge branch 'for-next/pwm'
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 72a3df4e6f..1223e0ab55 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -739,6 +739,38 @@ int of_property_read_u32_index(const struct device_node *np,
EXPORT_SYMBOL_GPL(of_property_read_u32_index);
/**
+ * of_property_count_elems_of_size - Count the number of elements in a property
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @elem_size: size of the individual element
+ *
+ * Search for a property in a device node and count the number of elements of
+ * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
+ * property does not exist or its length does not match a multiple of elem_size
+ * and -ENODATA if the property does not have a value.
+ */
+int of_property_count_elems_of_size(const struct device_node *np,
+ const char *propname, int elem_size)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ if (prop->length % elem_size != 0) {
+ pr_err("size of %s in node %pOF is not a multiple of %d\n",
+ propname, np, elem_size);
+ return -EINVAL;
+ }
+
+ return prop->length / elem_size;
+}
+EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
+
+/**
* of_property_read_u8_array - Find and read an array of u8 from a property.
*
* @np: device node from which the property value is to be read.