diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-12-08 08:29:02 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-12-08 08:29:02 +0100 |
commit | 2ae9bbba0742d79376eb26252b212913d9181bd8 (patch) | |
tree | d4905ffccf62b563d9d67bbae66648421cd3745c /drivers | |
parent | fab8198323d88ec061032b406b0dc4a874096d60 (diff) | |
parent | 34cda8c23115b3ae3aeeeba7618d5d5654536494 (diff) | |
download | barebox-2ae9bbba0742d79376eb26252b212913d9181bd8.tar.gz barebox-2ae9bbba0742d79376eb26252b212913d9181bd8.tar.xz |
Merge branch 'for-next/state'
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/misc/state.c | 34 | ||||
-rw-r--r-- | drivers/of/of_path.c | 96 |
2 files changed, 69 insertions, 61 deletions
diff --git a/drivers/misc/state.c b/drivers/misc/state.c index f3e366480f..73356b45a0 100644 --- a/drivers/misc/state.c +++ b/drivers/misc/state.c @@ -37,7 +37,7 @@ static int state_probe(struct device_d *dev) alias = of_alias_get(np); if (!alias) - alias = "state"; + alias = np->name; state = state_new_from_node(alias, np); if (IS_ERR(state)) @@ -52,34 +52,21 @@ static int state_probe(struct device_d *dev) /* guess if of_path is a path, not a phandle */ if (of_path[0] == '/' && len > 1) { ret = of_find_path(np, "backend", &path, 0); - if (ret) - goto out_release; } else { - struct device_d *dev; - struct cdev *cdev; partition_node = of_parse_phandle(np, "backend", 0); - if (!partition_node) { - ret = -ENODEV; - goto out_release; - } - - dev = of_find_device_by_node(partition_node); - if (!list_is_singular(&dev->cdevs)) { - ret = -ENODEV; - goto out_release; - } - - cdev = list_first_entry(&dev->cdevs, struct cdev, devices_list); - if (!cdev) { - ret = -ENODEV; - goto out_release; - } - - path = asprintf("/dev/%s", cdev->name); + if (!partition_node) + return -EINVAL; + of_path = partition_node->full_name; + ret = of_find_path_by_node(partition_node, &path, 0); } + if (ret == -ENODEV) + ret = -EPROBE_DEFER; + if (ret) + goto out_release; + ret = of_property_read_string(np, "backend-type", &backend_type); if (ret) { goto out_free; @@ -99,7 +86,6 @@ static int state_probe(struct device_d *dev) dev_info(dev, "backend: %s, path: %s, of_path: %s\n", backend_type, path, of_path); free(path); - state_load(state); return 0; out_free: diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c index 992972c9b5..6903905259 100644 --- a/drivers/of/of_path.c +++ b/drivers/of/of_path.c @@ -106,6 +106,63 @@ 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 (propname) { + 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_by_node - translate a node in the devicetree to a + * barebox device path + * + * @node: the node we're interested in + * @outpath: if this function returns 0 outpath will contain the path belonging + * to the input path description. Must be freed with free(). + * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available + * + */ +int of_find_path_by_node(struct device_node *node, char **outpath, unsigned flags) +{ + return __of_find_path(node, NULL, outpath, flags); +} + /** * of_find_path - translate a path description in the devicetree to a barebox * path @@ -134,11 +191,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 +202,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); } |