Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 256779
b: refs/heads/master
c: a3b8536
h: refs/heads/master
i:
  256777: 1e5af4a
  256775: cf138eb
v: v3
  • Loading branch information
Thomas Abraham authored and Grant Likely committed Jun 30, 2011
1 parent f7f8298 commit 469dfbb
Show file tree
Hide file tree
Showing 3 changed files with 63 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: 7423734e19e7e0a90e3379152eacca2647f4377e
refs/heads/master: a3b853633d78c3930b513ee219df48637ac82eed
58 changes: 58 additions & 0 deletions trunk/drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,64 @@ struct device_node *of_find_node_by_phandle(phandle handle)
}
EXPORT_SYMBOL(of_find_node_by_phandle);

/**
* of_property_read_u32 - Find and read a 32 bit integer 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.
*
* Search for a property in a device node and read a 32-bit value 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.
*
* 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)
{
struct property *prop = of_find_property(np, propname, NULL);

if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
if (sizeof(*out_value) > prop->length)
return -EOVERFLOW;
*out_value = be32_to_cpup(prop->value);
return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_u32);

/**
* of_property_read_string - Find and read a string from a property
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_string: pointer to null terminated return string, modified only if
* return value is 0.
*
* Search for a property in a device tree node and retrieve a null
* terminated string value (pointer to data, not a copy). Returns 0 on
* success, -EINVAL if the property does not exist, -ENODATA if property
* does not have a value, and -EILSEQ if the string is not null-terminated
* within the length of the property data.
*
* The out_string pointer is modified only if a valid string can be decoded.
*/
int of_property_read_string(struct device_node *np, char *propname,
char **out_string)
{
struct property *prop = of_find_property(np, propname, NULL);
if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
if (strnlen(prop->value, prop->length) >= prop->length)
return -EILSEQ;
*out_string = prop->value;
return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_string);

/**
* of_parse_phandle - Resolve a phandle property to a device_node pointer
* @np: Pointer to device node holding phandle property
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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_u32(struct device_node *np, char *propname,
u32 *out_value);
extern int of_property_read_string(struct device_node *np, char *propname,
char **out_string);
extern int of_device_is_compatible(const struct device_node *device,
const char *);
extern int of_device_is_available(const struct device_node *device);
Expand Down

0 comments on commit 469dfbb

Please sign in to comment.