summaryrefslogtreecommitdiff
path: root/include/dm/read.h
diff options
context:
space:
mode:
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>2022-06-14 16:21:30 +0300
committerTom Rini <trini@konsulko.com>2022-09-14 22:23:03 +0300
commitb471bdc47b2acabe0b5fcb0fb40a0b1c0602d3b3 (patch)
tree63a7b1e3e0d0db6be0aaeea90c57a7a0a8a3d7f9 /include/dm/read.h
parent7a0d88076b9cd8ccc88d41383f92ac2494d4168e (diff)
downloadu-boot-b471bdc47b2acabe0b5fcb0fb40a0b1c0602d3b3.tar.xz
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 <stefan.herbrechtsmeier@weidmueller.com> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm/read.h')
-rw-r--r--include/dm/read.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/include/dm/read.h b/include/dm/read.h
index 1b54b69acf..122b9cd15b 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)
{