diff --git a/core/drivers/regulator/regulator.c b/core/drivers/regulator/regulator.c index 3df613f17f5..ed5794a7e51 100644 --- a/core/drivers/regulator/regulator.c +++ b/core/drivers/regulator/regulator.c @@ -328,6 +328,43 @@ static __printf(3, 4) char *add_msg(char *cur, char *end, const char *fmt, ...) return cur + ret; } +/* Regulator is the last supplied one by its supply in the registered list */ +static bool regulator_is_supply_last_supplied(struct regulator *node_regulator) +{ + struct regulator *regulator = NULL; + + /* Find if there is still another node with the same parent */ + regulator = SLIST_NEXT(node_regulator, link); + while (regulator && regulator->supply != node_regulator->supply) + regulator = SLIST_NEXT(regulator, link); + + return !regulator; +} + +/* Supply last node may already be printed for indentation level @cur_indent */ +static bool indent_with_empty_string(struct regulator *node_regulator, + int node_indent, int cur_indent) +{ + struct regulator *indent_plus_one_regulator = NULL; + struct regulator *indent_regulator = NULL; + struct regulator *regulator = NULL; + int indent = 0; + + /* Find the supplied and supply of @cur_indent indentation level */ + indent_regulator = node_regulator; + for (indent = 0; indent < node_indent - cur_indent; indent++) { + indent_plus_one_regulator = indent_regulator; + indent_regulator = indent_regulator->supply; + } + + /* Find if there remains a supplied regulator for the found supply */ + regulator = SLIST_NEXT(indent_plus_one_regulator, link); + while (regulator && regulator->supply != indent_regulator) + regulator = SLIST_NEXT(regulator, link); + + return !regulator; +} + static void __maybe_unused print_regulator(struct regulator *regulator, int indent) { @@ -345,15 +382,32 @@ static void __maybe_unused print_regulator(struct regulator *regulator, int n = 0; if (indent) { + /* Indent for root clock level */ + msg = add_msg(msg, msg_end, " "); + if (!msg) + goto out; + + /* Indent for root supply to regulator supply levels */ for (n = 0; n < indent - 1; n++) { - msg = add_msg(msg, msg_end, "| "); + if (indent_with_empty_string(regulator, indent, n)) + msg = add_msg(msg, msg_end, " "); + else + msg = add_msg(msg, msg_end, "| "); if (!msg) goto out; } - msg = add_msg(msg, msg_end, "+-- "); + /* Regulator indentation */ + if (regulator_is_supply_last_supplied(regulator)) + msg = add_msg(msg, msg_end, "`-- "); + else + msg = add_msg(msg, msg_end, "|-- "); + if (!msg) goto out; + } else { + /* Root supply indentation */ + msg = add_msg(msg, msg_end, "o- "); } regulator_get_range(regulator, &level_min, &level_max);