dt: add helper function to read u32 arrays
Rework of_property_read_u32 to read an array of values. Then of_property_read_u32 becomes an inline with array size of 1. Also make struct device_node ptr const. Signed-off-by: Rob Herring <rob.herring@calxeda.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
This commit is contained in:
committed by
Grant Likely
parent
b84e773119
commit
0e373639ad
@@ -596,32 +596,39 @@ struct device_node *of_find_node_by_phandle(phandle handle)
|
|||||||
EXPORT_SYMBOL(of_find_node_by_phandle);
|
EXPORT_SYMBOL(of_find_node_by_phandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_property_read_u32 - Find and read a 32 bit integer from a property
|
* of_property_read_u32_array - Find and read an array of 32 bit integers
|
||||||
|
* from a property.
|
||||||
|
*
|
||||||
* @np: device node from which the property value is to be read.
|
* @np: device node from which the property value is to be read.
|
||||||
* @propname: name of the property to be searched.
|
* @propname: name of the property to be searched.
|
||||||
* @out_value: pointer to return value, modified only if return value is 0.
|
* @out_value: pointer to return value, modified only if return value is 0.
|
||||||
*
|
*
|
||||||
* Search for a property in a device node and read a 32-bit value from
|
* Search for a property in a device node and read 32-bit value(s) from
|
||||||
* it. Returns 0 on success, -EINVAL if the property does not exist,
|
* it. Returns 0 on success, -EINVAL if the property does not exist,
|
||||||
* -ENODATA if property does not have a value, and -EOVERFLOW if the
|
* -ENODATA if property does not have a value, and -EOVERFLOW if the
|
||||||
* property data isn't large enough.
|
* property data isn't large enough.
|
||||||
*
|
*
|
||||||
* The out_value is modified only if a valid u32 value can be decoded.
|
* The out_value is modified only if a valid u32 value can be decoded.
|
||||||
*/
|
*/
|
||||||
int of_property_read_u32(struct device_node *np, char *propname, u32 *out_value)
|
int of_property_read_u32_array(const struct device_node *np, char *propname,
|
||||||
|
u32 *out_values, size_t sz)
|
||||||
{
|
{
|
||||||
struct property *prop = of_find_property(np, propname, NULL);
|
struct property *prop = of_find_property(np, propname, NULL);
|
||||||
|
const __be32 *val;
|
||||||
|
|
||||||
if (!prop)
|
if (!prop)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!prop->value)
|
if (!prop->value)
|
||||||
return -ENODATA;
|
return -ENODATA;
|
||||||
if (sizeof(*out_value) > prop->length)
|
if ((sz * sizeof(*out_values)) > prop->length)
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
*out_value = be32_to_cpup(prop->value);
|
|
||||||
|
val = prop->value;
|
||||||
|
while (sz--)
|
||||||
|
*out_values++ = be32_to_cpup(val++);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(of_property_read_u32);
|
EXPORT_SYMBOL_GPL(of_property_read_u32_array);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_property_read_string - Find and read a string from a property
|
* of_property_read_string - Find and read a string from a property
|
||||||
|
@@ -195,8 +195,18 @@ extern struct device_node *of_find_node_with_property(
|
|||||||
extern struct property *of_find_property(const struct device_node *np,
|
extern struct property *of_find_property(const struct device_node *np,
|
||||||
const char *name,
|
const char *name,
|
||||||
int *lenp);
|
int *lenp);
|
||||||
extern int of_property_read_u32(struct device_node *np, char *propname,
|
extern int of_property_read_u32_array(const struct device_node *np,
|
||||||
u32 *out_value);
|
char *propname,
|
||||||
|
u32 *out_values,
|
||||||
|
size_t sz);
|
||||||
|
|
||||||
|
static inline int of_property_read_u32(const struct device_node *np,
|
||||||
|
char *propname,
|
||||||
|
u32 *out_value)
|
||||||
|
{
|
||||||
|
return of_property_read_u32_array(np, propname, out_value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
extern int of_property_read_string(struct device_node *np, char *propname,
|
extern int of_property_read_string(struct device_node *np, char *propname,
|
||||||
const char **out_string);
|
const char **out_string);
|
||||||
extern int of_device_is_compatible(const struct device_node *device,
|
extern int of_device_is_compatible(const struct device_node *device,
|
||||||
|
Reference in New Issue
Block a user