All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@nxp.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 3/4] clk: support clk tree dump
Date: Fri, 16 Aug 2019 09:55:13 +0000	[thread overview]
Message-ID: <20190816100740.22725-3-peng.fan@nxp.com> (raw)
In-Reply-To: <20190816100740.22725-1-peng.fan@nxp.com>

The previous code only dump the clk list. This patch is
to support clk tree dump, and also dump the enable_cnt.

The code used in patch is similar to dm_dump_all, but
the code here only filter out the UCLASS_CLK devices.

On i.MX8MM, Partial output:
u-boot=> clk dump
 Rate               Usecnt      Name
------------------------------------------
 24000000             0        |-- clock-osc-24m
 24000000             0        |   |-- dram_pll_ref_sel
 750000000            0        |   |   `-- dram_pll
 750000000            0        |   |       `-- dram_pll_bypass
 750000000            0        |   |           `-- dram_pll_out
 24000000             0        |   |-- arm_pll_ref_sel
 1200000000           0        |   |   `-- arm_pll
 1200000000           0        |   |       `-- arm_pll_bypass
 1200000000           0        |   |           `-- arm_pll_out
 1200000000           0        |   |               `-- arm_a53_src
 1200000000           0        |   |                   `-- arm_a53_cg
 1200000000           0        |   |                       `-- arm_a53_div
 24000000             4        |   |-- sys_pll1_ref_sel
 800000000            4        |   |   `-- sys_pll1
 800000000            4        |   |       `-- sys_pll1_bypass
 800000000            4        |   |           `-- sys_pll1_out
 40000000             0        |   |               |-- sys_pll1_40m

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---

V2:
 Improve commit log

 cmd/clk.c | 77 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 44 insertions(+), 33 deletions(-)

diff --git a/cmd/clk.c b/cmd/clk.c
index 5402c87de7..c0a64ff770 100644
--- a/cmd/clk.c
+++ b/cmd/clk.c
@@ -7,50 +7,61 @@
 #include <clk.h>
 #if defined(CONFIG_DM) && defined(CONFIG_CLK)
 #include <dm.h>
+#include <dm/device.h>
+#include <dm/root.h>
 #include <dm/device-internal.h>
+#include <linux/clk-provider.h>
 #endif
 
-int __weak soc_clk_dump(void)
+static void show_clks(struct udevice *dev, int depth, int last_flag)
 {
-#if defined(CONFIG_DM) && defined(CONFIG_CLK)
-	struct udevice *dev;
-	struct uclass *uc;
-	struct clk clk;
-	int ret;
-	ulong rate;
-
-	/* Device addresses start at 1 */
-	ret = uclass_get(UCLASS_CLK, &uc);
-	if (ret)
-		return ret;
-
-	uclass_foreach_dev(dev, uc) {
-		memset(&clk, 0, sizeof(clk));
-		ret = device_probe(dev);
-		if (ret)
-			goto noclk;
+	int i, is_last;
+	struct udevice *child;
+	struct clk *clkp;
+	u32 rate;
+
+	clkp = dev_get_clk_ptr(dev);
+	if (device_get_uclass_id(dev) == UCLASS_CLK && clkp) {
+		rate = clk_get_rate(clkp);
+
+	printf(" %-12u  %8d        ", rate, clkp->enable_count);
+
+	for (i = depth; i >= 0; i--) {
+		is_last = (last_flag >> i) & 1;
+		if (i) {
+			if (is_last)
+				printf("    ");
+			else
+				printf("|   ");
+		} else {
+			if (is_last)
+				printf("`-- ");
+			else
+				printf("|-- ");
+		}
+	}
 
-		ret = clk_request(dev, &clk);
-		if (ret)
-			goto noclk;
+	printf("%s\n", dev->name);
+	}
 
-		rate = clk_get_rate(&clk);
-		clk_free(&clk);
+	list_for_each_entry(child, &dev->child_head, sibling_node) {
+		is_last = list_is_last(&child->sibling_node, &dev->child_head);
+		show_clks(child, depth + 1, (last_flag << 1) | is_last);
+	}
+}
 
-		if (rate == -ENODEV)
-			goto noclk;
+int __weak soc_clk_dump(void)
+{
+	struct udevice *root;
 
-		printf("%-30.30s : %lu Hz\n", dev->name, rate);
-		continue;
-	noclk:
-		printf("%-30.30s : ? Hz\n", dev->name);
+	root = dm_root();
+	if (root) {
+		printf(" Rate               Usecnt      Name\n");
+		printf("------------------------------------------\n");
+		show_clks(root, -1, 0);
 	}
 
 	return 0;
-#else
-	puts("Not implemented\n");
-	return 1;
-#endif
 }
 
 static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
-- 
2.16.4

  parent reply	other threads:[~2019-08-16  9:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16  9:51 [U-Boot] [PATCH V2 1/4] clk: introduce enable_count Peng Fan
2019-08-16  9:55 ` [U-Boot] [PATCH V2 2/4] clk: prograte clk enable/disable to parent Peng Fan
2019-08-16  9:55 ` Peng Fan [this message]
2019-08-16  9:55 ` [U-Boot] [PATCH V2 4/4] sandbox: clk: add clk enable/disable test code Peng Fan

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=20190816100740.22725-3-peng.fan@nxp.com \
    --to=peng.fan@nxp.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.