diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-10-07 11:37:37 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-10-09 20:57:10 +0200 |
commit | efed4960013ed2636ed79b863e872a66f1ccd25d (patch) | |
tree | c3572c98acf9a3015d3b86d29acbbcb76ca25184 | |
parent | f59f5e86256f82daf4af3bf1922805592b780613 (diff) | |
download | barebox-efed4960013ed2636ed79b863e872a66f1ccd25d.tar.gz barebox-efed4960013ed2636ed79b863e872a66f1ccd25d.tar.xz |
of: Add function to get the model name
This is useful for printing it during startup.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/of/base.c | 39 | ||||
-rw-r--r-- | include/of.h | 9 |
2 files changed, 48 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 09785fb34b..a2f34e33d1 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -490,6 +490,36 @@ struct device_node *of_find_node_by_path(const char *path) } EXPORT_SYMBOL(of_find_node_by_path); +/** + * 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, const char *propname, + const char **out_string) +{ + struct property *prop = of_find_property(np, propname); + 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); + struct device_node *of_get_root_node(void) { return root_node; @@ -758,11 +788,20 @@ static void __of_probe(struct device_node *node) __of_probe(n); } +const char *of_model; + +const char *of_get_model(void) +{ + return of_model; +} + int of_probe(void) { if(!root_node) return -ENODEV; + of_property_read_string(root_node, "model", &of_model); + __of_probe(root_node); return 0; diff --git a/include/of.h b/include/of.h index 7b6a23ad71..ff01c937d0 100644 --- a/include/of.h +++ b/include/of.h @@ -108,12 +108,16 @@ void of_print_nodes(struct device_node *node, int indent); int of_probe(void); int of_parse_dtb(struct fdt_header *fdt); +int of_property_read_string(struct device_node *np, const char *propname, + const char **out_string); + #ifdef CONFIG_OFDEVICE int of_parse_partitions(const char *cdevname, struct device_node *node); struct device_node *of_get_root_node(void); int of_alias_get_id(struct device_node *np, const char *stem); +const char *of_get_model(void); #else static inline int of_parse_partitions(const char *cdevname, struct device_node *node) @@ -130,6 +134,11 @@ static inline int of_alias_get_id(struct device_node *np, const char *stem) { return -ENOENT; } + +static inline const char *of_get_model(void) +{ + return NULL; +} #endif #endif /* __OF_H */ |