Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 336560
b: refs/heads/master
c: be19324
h: refs/heads/master
v: v3
  • Loading branch information
Viresh Kumar authored and Rob Herring committed Nov 21, 2012
1 parent fcfbdfa commit 3ace1d7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9846210b1ec9bbaa30022d6d8af7e55ef67ccb45
refs/heads/master: be193249b4178158c0f697cb452b2bbf0cb16361
77 changes: 77 additions & 0 deletions trunk/drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,90 @@ struct device_node *of_find_node_by_phandle(phandle handle)
}
EXPORT_SYMBOL(of_find_node_by_phandle);

/**
* of_property_read_u8_array - Find and read an array of u8 from a property.
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_value: pointer to return value, modified only if return value is 0.
* @sz: number of array elements to read
*
* Search for a property in a device node and read 8-bit value(s) from
* it. Returns 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.
*
* dts entry of array should be like:
* property = /bits/ 8 <0x50 0x60 0x70>;
*
* The out_value is modified only if a valid u8 value can be decoded.
*/
int of_property_read_u8_array(const struct device_node *np,
const char *propname, u8 *out_values, size_t sz)
{
struct property *prop = of_find_property(np, propname, NULL);
const u8 *val;

if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
if ((sz * sizeof(*out_values)) > prop->length)
return -EOVERFLOW;

val = prop->value;
while (sz--)
*out_values++ = *val++;
return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_u8_array);

/**
* of_property_read_u16_array - Find and read an array of u16 from a property.
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_value: pointer to return value, modified only if return value is 0.
* @sz: number of array elements to read
*
* Search for a property in a device node and read 16-bit value(s) from
* it. Returns 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.
*
* dts entry of array should be like:
* property = /bits/ 16 <0x5000 0x6000 0x7000>;
*
* The out_value is modified only if a valid u16 value can be decoded.
*/
int of_property_read_u16_array(const struct device_node *np,
const char *propname, u16 *out_values, size_t sz)
{
struct property *prop = of_find_property(np, propname, NULL);
const __be16 *val;

if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
if ((sz * sizeof(*out_values)) > prop->length)
return -EOVERFLOW;

val = prop->value;
while (sz--)
*out_values++ = be16_to_cpup(val++);
return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_u16_array);

/**
* 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.
* @propname: name of the property to be searched.
* @out_value: pointer to return value, modified only if return value is 0.
* @sz: number of array elements to read
*
* 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,
Expand Down
30 changes: 30 additions & 0 deletions trunk/include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ extern struct device_node *of_find_node_with_property(
extern struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp);
extern int of_property_read_u8_array(const struct device_node *np,
const char *propname, u8 *out_values, size_t sz);
extern int of_property_read_u16_array(const struct device_node *np,
const char *propname, u16 *out_values, size_t sz);
extern int of_property_read_u32_array(const struct device_node *np,
const char *propname,
u32 *out_values,
Expand Down Expand Up @@ -364,6 +368,18 @@ static inline struct device_node *of_find_compatible_node(
return NULL;
}

static inline int of_property_read_u8_array(const struct device_node *np,
const char *propname, u8 *out_values, size_t sz)
{
return -ENOSYS;
}

static inline int of_property_read_u16_array(const struct device_node *np,
const char *propname, u16 *out_values, size_t sz)
{
return -ENOSYS;
}

static inline int of_property_read_u32_array(const struct device_node *np,
const char *propname,
u32 *out_values, size_t sz)
Expand Down Expand Up @@ -470,6 +486,20 @@ static inline bool of_property_read_bool(const struct device_node *np,
return prop ? true : false;
}

static inline int of_property_read_u8(const struct device_node *np,
const char *propname,
u8 *out_value)
{
return of_property_read_u8_array(np, propname, out_value, 1);
}

static inline int of_property_read_u16(const struct device_node *np,
const char *propname,
u16 *out_value)
{
return of_property_read_u16_array(np, propname, out_value, 1);
}

static inline int of_property_read_u32(const struct device_node *np,
const char *propname,
u32 *out_value)
Expand Down

0 comments on commit 3ace1d7

Please sign in to comment.