From 5ebc7c7e27780ce9a16289eeb87290eebd248ea9 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 31 Jan 2019 16:30:57 +0100 Subject: dm: core: Add of_alias_get_highest_id() The same functionality was added to Linux for i2c bus registration with this commit message: " of: base: add function to get highest id of an alias stem I2C supports adding adapters using either a dynamic or fixed id. The latter is provided by aliases in the DT case. To prevent id collisions of those two types, install this function which gives us the highest fixed id, so we can then let the dynamically created ones come after this highest number. Signed-off-by: Wolfram Sang Acked-by: Rob Herring Signed-off-by: Wolfram Sang " Add it also to U-Boot for DM I2C support. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- drivers/core/of_access.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'drivers/core') diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 14c020a687..945b81448c 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -812,6 +812,24 @@ int of_alias_get_id(const struct device_node *np, const char *stem) return id; } +int of_alias_get_highest_id(const char *stem) +{ + struct alias_prop *app; + int id = -1; + + mutex_lock(&of_mutex); + list_for_each_entry(app, &aliases_lookup, link) { + if (strcmp(app->stem, stem) != 0) + continue; + + if (app->id > id) + id = app->id; + } + mutex_unlock(&of_mutex); + + return id; +} + struct device_node *of_get_stdout(void) { return of_stdout; -- cgit v1.2.1 From 83e4c7e9ffa57fe4116967999c223c952a46a78a Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 31 Jan 2019 16:30:59 +0100 Subject: dm: core: Introduce dev_read_alias_highest_id() It is wrapper for calling of_alias_get_highest_id() when live tree is enabled and fdtdec_get_alias_highest_id() if not. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- drivers/core/read.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/core') diff --git a/drivers/core/read.c b/drivers/core/read.c index 3c46b3674e..6bda077a34 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -264,3 +264,11 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) { return ofnode_translate_address(dev_ofnode(dev), in_addr); } + +int dev_read_alias_highest_id(const char *stem) +{ + if (of_live_active()) + return of_alias_get_highest_id(stem); + + return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); +} -- cgit v1.2.1