aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDario Binacchi <dariobin@libero.it>2020-03-29 18:04:41 +0200
committerSimon Glass <sjg@chromium.org>2020-04-16 08:07:58 -0600
commit4bb7075c830c6f4e4512fe0277ff1f08c5a9e084 (patch)
treea1d8d9d36db2c061edd17dadddfed57a4188470e /include
parent70573c6c46be96d2e60497d8484b9afb119da8c1 (diff)
downloadu-boot-4bb7075c830c6f4e4512fe0277ff1f08c5a9e084.zip
u-boot-4bb7075c830c6f4e4512fe0277ff1f08c5a9e084.tar.gz
u-boot-4bb7075c830c6f4e4512fe0277ff1f08c5a9e084.tar.bz2
dm: core: support reading a single indexed u32 value
The patch adds helper functions to allow reading a single indexed u32 value from a device-tree property containing multiple u32 values, that is an array of integers. Signed-off-by: Dario Binacchi <dariobin@libero.it> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/dm/of_access.h19
-rw-r--r--include/dm/ofnode.h25
-rw-r--r--include/dm/read.h40
3 files changed, 84 insertions, 0 deletions
diff --git a/include/dm/of_access.h b/include/dm/of_access.h
index 13fedb7..92876b3 100644
--- a/include/dm/of_access.h
+++ b/include/dm/of_access.h
@@ -235,6 +235,25 @@ struct device_node *of_find_node_by_phandle(phandle handle);
int of_read_u32(const struct device_node *np, const char *propname, u32 *outp);
/**
+ * of_read_u32_index() - Find and read a 32-bit value from a multi-value
+ * property
+ *
+ * Search for a property in a device node and read a 32-bit value from
+ * it.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the u32 in the list of values
+ * @outp: pointer to return value, modified only if return value is 0.
+ *
+ * @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 of_read_u32_index(const struct device_node *np, const char *propname,
+ int index, u32 *outp);
+
+/**
* of_read_u64() - Find and read a 64-bit integer from a property
*
* Search for a property in a device node and read a 64-bit value from
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index b5a50e8..ce5e366 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -203,6 +203,18 @@ static inline ofnode ofnode_null(void)
int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
/**
+ * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
+ *
+ * @ref: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @index: index of the integer to return
+ * @outp: place to put value (if found)
+ * @return 0 if OK, -ve on error
+ */
+int ofnode_read_u32_index(ofnode node, const char *propname, int index,
+ u32 *outp);
+
+/**
* ofnode_read_s32() - Read a 32-bit integer from a property
*
* @ref: valid node reference to read property from
@@ -227,6 +239,19 @@ static inline int ofnode_read_s32(ofnode node, const char *propname,
u32 ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
/**
+ * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
+ * property
+ *
+ * @ref: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @index: index of the integer to return
+ * @def: default value to return if the property has no value
+ * @return property value, or @def if not found
+ */
+u32 ofnode_read_u32_index_default(ofnode ref, const char *propname, int index,
+ u32 def);
+
+/**
* ofnode_read_s32_default() - Read a 32-bit integer from a property
*
* @ref: valid node reference to read property from
diff --git a/include/dm/read.h b/include/dm/read.h
index da8c7f2..77d3bc8 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -67,6 +67,32 @@ int dev_read_u32_default(const struct udevice *dev, const char *propname,
int def);
/**
+ * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
+ * property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @index: index of the integer to return
+ * @outp: place to put value (if found)
+ * @return 0 if OK, -ve on error
+ */
+int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
+ u32 *outp);
+
+/**
+ * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
+ * DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @index: index of the integer to return
+ * @def: default value to return if the property has no value
+ * @return property value, or @def if not found
+ */
+u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
+ int index, u32 def);
+
+/**
* dev_read_s32() - read a signed 32-bit integer from a device's DT property
*
* @dev: device to read DT property from
@@ -621,6 +647,20 @@ static inline int dev_read_u32_default(const struct udevice *dev,
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
+static inline int dev_read_u32_index(struct udevice *dev,
+ const char *propname, int index, u32 *outp)
+{
+ return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
+}
+
+static inline u32 dev_read_u32_index_default(struct udevice *dev,
+ const char *propname, int index,
+ u32 def)
+{
+ return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
+ def);
+}
+
static inline int dev_read_s32(const struct udevice *dev,
const char *propname, s32 *outp)
{