summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStefan Herbrechtsmeier <[email protected]>2022-06-14 15:21:30 +0200
committerTom Rini <[email protected]>2022-09-14 15:23:03 -0400
commitb471bdc47b2acabe0b5fcb0fb40a0b1c0602d3b3 (patch)
tree63a7b1e3e0d0db6be0aaeea90c57a7a0a8a3d7f9 /include
parent7a0d88076b9cd8ccc88d41383f92ac2494d4168e (diff)
dm: core: Add functions to read 8/16-bit integers
Add functions to read 8/16-bit integers like the existing functions for 32/64-bit to simplify read of 8/16-bit integers from device tree properties. Signed-off-by: Stefan Herbrechtsmeier <[email protected]> Reviewed-by: Marek Vasut <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Simon Glass <[email protected]>
Diffstat (limited to 'include')
-rw-r--r--include/dm/of_access.h32
-rw-r--r--include/dm/ofnode.h40
-rw-r--r--include/dm/read.h65
3 files changed, 137 insertions, 0 deletions
diff --git a/include/dm/of_access.h b/include/dm/of_access.h
index 5b7821d0a1b..83f34f0d2ad 100644
--- a/include/dm/of_access.h
+++ b/include/dm/of_access.h
@@ -265,6 +265,38 @@ struct device_node *of_find_node_by_prop_value(struct device_node *from,
struct device_node *of_find_node_by_phandle(phandle handle);
/**
+ * of_read_u8() - Find and read a 8-bit integer from a property
+ *
+ * Search for a property in a device node and read a 8-bit value from
+ * it.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @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_u8(const struct device_node *np, const char *propname, u8 *outp);
+
+/**
+ * of_read_u16() - Find and read a 16-bit integer from a property
+ *
+ * Search for a property in a device node and read a 16-bit value from
+ * it.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @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_u16(const struct device_node *np, const char *propname, u16 *outp);
+
+/**
* of_read_u32() - Find and read a 32-bit integer from a property
*
* Search for a property in a device node and read a 32-bit value from
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 7ce1e4c6d91..f6085231bbd 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -222,6 +222,46 @@ static inline oftree oftree_default(void)
bool ofnode_name_eq(ofnode node, const char *name);
/**
+ * ofnode_read_u8() - Read a 8-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int ofnode_read_u8(ofnode node, const char *propname, u8 *outp);
+
+/**
+ * ofnode_read_u8_default() - Read a 8-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u8 ofnode_read_u8_default(ofnode node, const char *propname, u8 def);
+
+/**
+ * ofnode_read_u16() - Read a 16-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int ofnode_read_u16(ofnode node, const char *propname, u16 *outp);
+
+/**
+ * ofnode_read_u16_default() - Read a 16-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u16 ofnode_read_u16_default(ofnode node, const char *propname, u16 def);
+
+/**
* ofnode_read_u32() - Read a 32-bit integer from a property
*
* @node: valid node reference to read property from
diff --git a/include/dm/read.h b/include/dm/read.h
index 1b54b69acf0..122b9cd15b8 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -32,6 +32,47 @@ static inline const struct device_node *dev_np(const struct udevice *dev)
#if !defined(CONFIG_DM_DEV_READ_INLINE) || CONFIG_IS_ENABLED(OF_PLATDATA)
/**
+ * dev_read_u8() - read a 8-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int dev_read_u8(const struct udevice *dev, const char *propname, u8 *outp);
+
+/**
+ * dev_read_u8_default() - read a 8-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u8 dev_read_u8_default(const struct udevice *dev, const char *propname, u8 def);
+
+/**
+ * dev_read_u16() - read a 16-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int dev_read_u16(const struct udevice *dev, const char *propname, u16 *outp);
+
+/**
+ * dev_read_u16_default() - read a 16-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u16 dev_read_u16_default(const struct udevice *dev, const char *propname,
+ u16 def);
+
+/**
* dev_read_u32() - read a 32-bit integer from a device's DT property
*
* @dev: device to read DT property from
@@ -772,6 +813,30 @@ phy_interface_t dev_read_phy_mode(const struct udevice *dev);
#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
#include <asm/global_data.h>
+static inline int dev_read_u8(const struct udevice *dev,
+ const char *propname, u8 *outp)
+{
+ return ofnode_read_u8(dev_ofnode(dev), propname, outp);
+}
+
+static inline int dev_read_u8_default(const struct udevice *dev,
+ const char *propname, u8 def)
+{
+ return ofnode_read_u8_default(dev_ofnode(dev), propname, def);
+}
+
+static inline int dev_read_u16(const struct udevice *dev,
+ const char *propname, u16 *outp)
+{
+ return ofnode_read_u16(dev_ofnode(dev), propname, outp);
+}
+
+static inline int dev_read_u16_default(const struct udevice *dev,
+ const char *propname, u16 def)
+{
+ return ofnode_read_u16_default(dev_ofnode(dev), propname, def);
+}
+
static inline int dev_read_u32(const struct udevice *dev,
const char *propname, u32 *outp)
{