diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2023-02-21 08:07:34 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-02-21 08:50:21 +0100 |
commit | 90f70dbe29586b5fc98a9b96a41772cdd5ae251f (patch) | |
tree | 4e93d9abf1cd6719c25f25346ce1d1723f9a8b58 /drivers/of | |
parent | 4e8713dd6e89f68cb649be94b7796bdd8e7b0be4 (diff) | |
download | barebox-90f70dbe29586b5fc98a9b96a41772cdd5ae251f.tar.gz |
of: split part of of_get_stdoutpath into of_find_node_by_chosen
Follow-up commit will also lookup the value of a chosen property by full
path or alias, so factor this out into a helper function.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Link: https://lore.barebox.org/20230221070735.1130600-1-ahmad@a3f.at
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 1d8b207b15..34854d9b0d 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2668,30 +2668,52 @@ void of_delete_node(struct device_node *node) free(node); } -struct device_node *of_get_stdoutpath(unsigned int *baudrate) +/* + * of_find_node_by_chosen - Find a node given a chosen property pointing at it + * @propname: the name of the property containing a path or alias + * The function will lookup the first string in the property + * value up to the first : character or till \0. + * @options The Remainder (without : or \0 at the end) will be written + * to *options if not NULL. + */ +struct device_node *of_find_node_by_chosen(const char *propname, + const char **options) { + const char *value, *p; + char *buf = NULL; struct device_node *dn; - const char *name; - const char *p; - char *q; - name = of_get_property(of_chosen, "stdout-path", NULL); - if (!name) - name = of_get_property(of_chosen, "linux,stdout-path", NULL); + value = of_get_property(of_chosen, propname, NULL); + if (!value) + return NULL; - if (!name) - return 0; + p = strchrnul(value, ':'); + if (*p) + buf = xstrndup(value, p - value); - p = strchrnul(name, ':'); + dn = of_find_node_by_path_or_alias(NULL, buf); - q = xstrndup(name, p - name); + free(buf); - dn = of_find_node_by_path_or_alias(NULL, q); + if (options && *p) + *options = p + 1; - free(q); + return dn; +} + +struct device_node *of_get_stdoutpath(unsigned int *baudrate) +{ + const char *opts = NULL; + struct device_node *dn; + + dn = of_find_node_by_chosen("stdout-path", &opts); + if (!dn) + dn = of_find_node_by_chosen("linux,stdout-path", &opts); + if (!dn) + return NULL; - if (baudrate && *p) { - unsigned rate = simple_strtoul(p + 1, NULL, 10); + if (baudrate && opts) { + unsigned rate = simple_strtoul(opts, NULL, 10); if (rate) *baudrate = rate; } |