Commit aeeb2e6d9c67273da5d91f7567657447878eb493
Committed by
Lukasz Majewski
1 parent
0520be0f67
Exists in
smarc_8mq_lf_v2020.04
and in
12 other branches
clk: support clk tree dump
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>
Showing 1 changed file with 49 additions and 30 deletions Side-by-side Diff
cmd/clk.c
| ... | ... | @@ -7,51 +7,70 @@ |
| 7 | 7 | #include <clk.h> |
| 8 | 8 | #if defined(CONFIG_DM) && defined(CONFIG_CLK) |
| 9 | 9 | #include <dm.h> |
| 10 | +#include <dm/device.h> | |
| 11 | +#include <dm/root.h> | |
| 10 | 12 | #include <dm/device-internal.h> |
| 13 | +#include <linux/clk-provider.h> | |
| 11 | 14 | #endif |
| 12 | 15 | |
| 13 | -int __weak soc_clk_dump(void) | |
| 14 | -{ | |
| 15 | 16 | #if defined(CONFIG_DM) && defined(CONFIG_CLK) |
| 16 | - struct udevice *dev; | |
| 17 | - struct uclass *uc; | |
| 18 | - struct clk clk; | |
| 19 | - int ret; | |
| 20 | - ulong rate; | |
| 17 | +static void show_clks(struct udevice *dev, int depth, int last_flag) | |
| 18 | +{ | |
| 19 | + int i, is_last; | |
| 20 | + struct udevice *child; | |
| 21 | + struct clk *clkp; | |
| 22 | + u32 rate; | |
| 21 | 23 | |
| 22 | - /* Device addresses start at 1 */ | |
| 23 | - ret = uclass_get(UCLASS_CLK, &uc); | |
| 24 | - if (ret) | |
| 25 | - return ret; | |
| 24 | + clkp = dev_get_clk_ptr(dev); | |
| 25 | + if (device_get_uclass_id(dev) == UCLASS_CLK && clkp) { | |
| 26 | + rate = clk_get_rate(clkp); | |
| 26 | 27 | |
| 27 | - uclass_foreach_dev(dev, uc) { | |
| 28 | - memset(&clk, 0, sizeof(clk)); | |
| 29 | - ret = device_probe(dev); | |
| 30 | - if (ret) | |
| 31 | - goto noclk; | |
| 28 | + printf(" %-12u %8d ", rate, clkp->enable_count); | |
| 32 | 29 | |
| 33 | - ret = clk_request(dev, &clk); | |
| 34 | - if (ret) | |
| 35 | - goto noclk; | |
| 30 | + for (i = depth; i >= 0; i--) { | |
| 31 | + is_last = (last_flag >> i) & 1; | |
| 32 | + if (i) { | |
| 33 | + if (is_last) | |
| 34 | + printf(" "); | |
| 35 | + else | |
| 36 | + printf("| "); | |
| 37 | + } else { | |
| 38 | + if (is_last) | |
| 39 | + printf("`-- "); | |
| 40 | + else | |
| 41 | + printf("|-- "); | |
| 42 | + } | |
| 43 | + } | |
| 36 | 44 | |
| 37 | - rate = clk_get_rate(&clk); | |
| 38 | - clk_free(&clk); | |
| 45 | + printf("%s\n", dev->name); | |
| 46 | + } | |
| 39 | 47 | |
| 40 | - if (rate == -ENODEV) | |
| 41 | - goto noclk; | |
| 48 | + list_for_each_entry(child, &dev->child_head, sibling_node) { | |
| 49 | + is_last = list_is_last(&child->sibling_node, &dev->child_head); | |
| 50 | + show_clks(child, depth + 1, (last_flag << 1) | is_last); | |
| 51 | + } | |
| 52 | +} | |
| 42 | 53 | |
| 43 | - printf("%-30.30s : %lu Hz\n", dev->name, rate); | |
| 44 | - continue; | |
| 45 | - noclk: | |
| 46 | - printf("%-30.30s : ? Hz\n", dev->name); | |
| 54 | +int __weak soc_clk_dump(void) | |
| 55 | +{ | |
| 56 | + struct udevice *root; | |
| 57 | + | |
| 58 | + root = dm_root(); | |
| 59 | + if (root) { | |
| 60 | + printf(" Rate Usecnt Name\n"); | |
| 61 | + printf("------------------------------------------\n"); | |
| 62 | + show_clks(root, -1, 0); | |
| 47 | 63 | } |
| 48 | 64 | |
| 49 | 65 | return 0; |
| 66 | +} | |
| 50 | 67 | #else |
| 68 | +int __weak soc_clk_dump(void) | |
| 69 | +{ | |
| 51 | 70 | puts("Not implemented\n"); |
| 52 | 71 | return 1; |
| 53 | -#endif | |
| 54 | 72 | } |
| 73 | +#endif | |
| 55 | 74 | |
| 56 | 75 | static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc, |
| 57 | 76 | char *const argv[]) |