mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 11/11] regulator: print regulator tree
Date: Wed, 20 Sep 2023 12:33:16 +0200	[thread overview]
Message-ID: <20230920103316.2758383-12-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230920103316.2758383-1-s.hauer@pengutronix.de>

Regulators have a tree structure, so print them as a tree to show the
users their dependencies.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/regulator/core.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 7fe264a133..a861d14cd2 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -15,6 +15,7 @@ static LIST_HEAD(regulator_list);
 
 struct regulator {
 	struct regulator_dev *rdev;
+	struct regulator_dev *rdev_consumer;
 	struct list_head list;
 	struct device *dev;
 };
@@ -183,7 +184,11 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 		return 0;
 	}
 
+	if (supply)
+		supply->rdev_consumer = rdev;
+
 	rdev->supply = supply;
+
 	return 0;
 }
 
@@ -716,17 +721,22 @@ int regulator_get_voltage(struct regulator *regulator)
 }
 EXPORT_SYMBOL_GPL(regulator_get_voltage);
 
-static void regulator_print_one(struct regulator_dev *rdev)
+static void regulator_print_one(struct regulator_dev *rdev, int level)
 {
 	struct regulator *r;
 
-	printf("%-20s %6d %10d %10d\n", rdev->name, rdev->enable_count, rdev->min_uv, rdev->max_uv);
+	if (!rdev)
+		return;
 
-	if (!list_empty(&rdev->consumer_list)) {
-		printf(" consumers:\n");
+	printf("%*s%-*s %6d %10d %10d\n", level * 3, "",
+	       30 - level * 3,
+	       rdev->name, rdev->enable_count, rdev->min_uv, rdev->max_uv);
 
-		list_for_each_entry(r, &rdev->consumer_list, list)
-			printf("   %s\n", r->dev ? dev_name(r->dev) : "none");
+	list_for_each_entry(r, &rdev->consumer_list, list) {
+		if (r->rdev_consumer)
+			regulator_print_one(r->rdev_consumer, level + 1);
+		else
+			printf("%*s%s\n", (level + 1) * 3, "", r->dev ? dev_name(r->dev) : "none");
 	}
 }
 
@@ -737,7 +747,9 @@ void regulators_print(void)
 {
 	struct regulator_dev *rdev;
 
-	printf("%-20s %6s %10s %10s\n", "name", "enable", "min_uv", "max_uv");
-	list_for_each_entry(rdev, &regulator_list, list)
-		regulator_print_one(rdev);
+	printf("%-30s %6s %10s %10s\n", "name", "enable", "min_uv", "max_uv");
+	list_for_each_entry(rdev, &regulator_list, list) {
+		if (!rdev->supply)
+			regulator_print_one(rdev, 0);
+	}
 }
-- 
2.39.2




      parent reply	other threads:[~2023-09-20 10:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 10:33 [PATCH 00/11] regulator updates Sascha Hauer
2023-09-20 10:33 ` [PATCH 01/11] regulator: rename variable rd to rdev Sascha Hauer
2023-09-20 11:15   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 02/11] regulator: merge struct regulator_internal fields into struct regulator_dev Sascha Hauer
2023-09-20 10:52   ` Marco Felsch
2023-09-20 11:07     ` Sascha Hauer
2023-09-20 11:13       ` Marco Felsch
2023-09-20 11:20   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 03/11] regulator: introduce regulator logging functions Sascha Hauer
2023-09-20 11:22   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 04/11] regulator: add regulator_get_voltage_internal() Sascha Hauer
2023-09-20 11:25   ` Marco Felsch
2023-09-20 11:45     ` Sascha Hauer
2023-09-20 10:33 ` [PATCH 05/11] regulator: Add missing cases in regulator_map_voltage() Sascha Hauer
2023-09-20 11:28   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 06/11] regulator: stpmic1: add .get_voltage_sel Sascha Hauer
2023-09-20 11:29   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 07/11] regulator: stpmic1: add .supply_name Sascha Hauer
2023-09-20 11:36   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 08/11] regulator: register regulator as last step in of_regulator_register() Sascha Hauer
2023-09-20 11:39   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 09/11] regulator: Set initial voltage Sascha Hauer
2023-09-20 11:51   ` Marco Felsch
2023-09-20 10:33 ` [PATCH 10/11] regulator: drop struct regulator_dev::supply_name Sascha Hauer
2023-09-20 11:51   ` Marco Felsch
2023-09-20 10:33 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230920103316.2758383-12-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox