Skip to content

Commit

Permalink
[review] drivers: regulator: print regulator tree summary
Browse files Browse the repository at this point in the history
Beautify (IMHO) the regulator tree:
- remove empty lines between root supplies. They are now prefixed
  with indentation string "o- ";
- prevent bars '|' when last node of a supply was already printed
- use `-- for last supplied of a supply and |-- otherwise.

For example, the below tree:

I/TC: Regulator tree summary
I/TC:
I/TC: vin       (...)
I/TC: +-- vdd_sd        (...)
I/TC: +-- vdd_usb       (...)
I/TC: |   +-- usb33     (...)
I/TC: |   |   +-- usb33_io     (...)
I/TC: +-- vdd_adc       (...)
I/TC: +-- vddcore       (...)
I/TC: +-- vdd   (...)
I/TC: |   +-- reg11     (...)
I/TC: |   +-- reg18     (...)
I/TC:
I/TC: v3v3_ao   (...)
I/TC: +-- v3v3_sw       (...)
I/TC:

is now printed as:
I/TC: Regulator tree summary
I/TC:
I/TC: o- vin       (...)
I/TC:    |-- vdd_sd        (...)
I/TC:    |-- vdd_usb       (...)
I/TC:    |   `-- usb33     (...)
I/TC:    |       `-- usb33_io     (...)
I/TC:    |-- vdd_adc       (...)
I/TC:    |-- vddcore       (...)
I/TC:    `-- vdd   (...)
I/TC:        |-- reg11     (...)
I/TC:        `-- reg18     (...)
I/TC:
I/TC: o- v3v3_ao   (...)
I/TC:    `-- v3v3_sw       (...)
I/TC:

Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
  • Loading branch information
etienne-lms committed Nov 26, 2023
1 parent 42c5671 commit 39293fb
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions core/drivers/regulator/regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down

0 comments on commit 39293fb

Please sign in to comment.