dm: core: Add a way to obtain a string list

At present we support reading a string list a string at a time. Apart
from being inefficient, this makes it impossible to separate reading of
the devicetree into the of_to_plat() method where it belongs, since any
code which needs access to the string must read it from the devicetree.

Add a function which returns the string property as an array of pointers
to the strings, which is easily used by clients.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-10-23 17:26:07 -06:00
parent 32c6a8e1f8
commit 075bfc9575
5 changed files with 100 additions and 0 deletions

View File

@@ -456,6 +456,32 @@ int ofnode_read_string_count(ofnode node, const char *property)
}
}
int ofnode_read_string_list(ofnode node, const char *property,
const char ***listp)
{
const char **prop;
int count;
int i;
*listp = NULL;
count = ofnode_read_string_count(node, property);
if (count < 0)
return count;
if (!count)
return 0;
prop = calloc(count + 1, sizeof(char *));
if (!prop)
return -ENOMEM;
for (i = 0; i < count; i++)
ofnode_read_string_index(node, property, i, &prop[i]);
prop[count] = NULL;
*listp = prop;
return count;
}
static void ofnode_from_fdtdec_phandle_args(struct fdtdec_phandle_args *in,
struct ofnode_phandle_args *out)
{

View File

@@ -205,6 +205,12 @@ int dev_read_string_count(const struct udevice *dev, const char *propname)
return ofnode_read_string_count(dev_ofnode(dev), propname);
}
int dev_read_string_list(const struct udevice *dev, const char *propname,
const char ***listp)
{
return ofnode_read_string_list(dev_ofnode(dev), propname, listp);
}
int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
const char *cells_name, int cell_count,
int index, struct ofnode_phandle_args *out_args)