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>
This commit is contained in:
Dario Binacchi
2020-03-29 18:04:41 +02:00
committed by Simon Glass
parent 70573c6c46
commit 4bb7075c83
8 changed files with 189 additions and 0 deletions

View File

@@ -66,6 +66,32 @@ int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
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
*
@@ -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)
{