summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2019-01-31 16:30:58 +0100
committerHeiko Schocher <hs@denx.de>2019-02-08 06:25:15 +0100
commit003c9dc89176cacc9996f737d08490805e29582e (patch)
tree2aad94199a819a45930c372e5fe1cd28e692be1e /lib
parent5ebc7c7e27780ce9a16289eeb87290eebd248ea9 (diff)
fdt: Introduce fdtdec_get_alias_highest_id()
Find out the highest alias ID used for certain subsystem. This call will be used for alocating IDs for i2c buses which are not described in DT. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Heiko Schocher <hs@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/fdtdec.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 18663ce6bd..55811975ef 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -549,6 +549,39 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
return -ENOENT;
}
+int fdtdec_get_alias_highest_id(const void *blob, const char *base)
+{
+ int base_len = strlen(base);
+ int prop_offset;
+ int aliases;
+ int max = -1;
+
+ debug("Looking for highest alias id for '%s'\n", base);
+
+ aliases = fdt_path_offset(blob, "/aliases");
+ for (prop_offset = fdt_first_property_offset(blob, aliases);
+ prop_offset > 0;
+ prop_offset = fdt_next_property_offset(blob, prop_offset)) {
+ const char *prop;
+ const char *name;
+ int len, val;
+
+ prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
+ debug(" - %s, %s\n", name, prop);
+ if (*prop != '/' || prop[len - 1] ||
+ strncmp(name, base, base_len))
+ continue;
+
+ val = trailing_strtol(name);
+ if (val > max) {
+ debug("Found seq %d\n", val);
+ max = val;
+ }
+ }
+
+ return max;
+}
+
const char *fdtdec_get_chosen_prop(const void *blob, const char *name)
{
int chosen_node;