diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2015-10-25 22:03:28 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-11-27 08:26:40 +0100 |
commit | 75b682795eafb2385556a9642f09e0af96a1264a (patch) | |
tree | 6fa0dd37f809770b94ef0cb185de5d111017867a /drivers/of/of_path.c | |
parent | 770c1ef83c2628cea4e9070810609b102037339a (diff) | |
download | barebox-75b682795eafb2385556a9642f09e0af96a1264a.tar.gz barebox-75b682795eafb2385556a9642f09e0af96a1264a.tar.xz |
of_path: of_find_path() factor out device detection logic into separate function
This patch factors out the device detection logic into separate function, so
that it can be used from another function.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of/of_path.c')
-rw-r--r-- | drivers/of/of_path.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c index 992972c9b5..ad64bee08a 100644 --- a/drivers/of/of_path.c +++ b/drivers/of/of_path.c @@ -106,6 +106,48 @@ out: return ret; } +static int __of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags) +{ + struct of_path op = {}; + const char *str; + bool add_bb = false; + int i, ret; + + op.dev = of_find_device_by_node_path(node->full_name); + if (!op.dev) { + op.dev = of_find_device_by_node_path(node->parent->full_name); + if (!op.dev) + return -ENODEV; + } + + device_detect(op.dev); + + op.cdev = cdev_by_device_node(node); + + i = 1; + + while (1) { + ret = of_property_read_string_index(node, propname, i++, &str); + if (ret) + break; + + ret = of_path_parse_one(&op, str); + if (ret) + return ret; + } + + if (!op.cdev) + return -ENOENT; + + if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd && + mtd_can_have_bb(op.cdev->mtd)) + add_bb = true; + + *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : ""); + + return 0; +} + /** * of_find_path - translate a path description in the devicetree to a barebox * path @@ -134,11 +176,8 @@ out: */ int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags) { - struct of_path op = {}; struct device_node *rnode; - const char *path, *str; - bool add_bb = false; - int i, ret; + const char *path; path = of_get_property(node, propname, NULL); if (!path) @@ -148,37 +187,5 @@ int of_find_path(struct device_node *node, const char *propname, char **outpath, if (!rnode) return -ENODEV; - op.dev = of_find_device_by_node_path(rnode->full_name); - if (!op.dev) { - op.dev = of_find_device_by_node_path(rnode->parent->full_name); - if (!op.dev) - return -ENODEV; - } - - device_detect(op.dev); - - op.cdev = cdev_by_device_node(rnode); - - i = 1; - - while (1) { - ret = of_property_read_string_index(node, propname, i++, &str); - if (ret) - break; - - ret = of_path_parse_one(&op, str); - if (ret) - return ret; - } - - if (!op.cdev) - return -ENOENT; - - if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd && - mtd_can_have_bb(op.cdev->mtd)) - add_bb = true; - - *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : ""); - - return 0; + return __of_find_path(rnode, propname, outpath, flags); } |