1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Xilinx, Inc.
8 #if defined(CONFIG_DM) && defined(CONFIG_CLK)
10 #include <dm/device.h>
12 #include <dm/device-internal.h>
13 #include <linux/clk-provider.h>
16 #if defined(CONFIG_DM) && defined(CONFIG_CLK)
17 static void show_clks(struct udevice *dev, int depth, int last_flag)
20 struct udevice *child;
24 clkp = dev_get_clk_ptr(dev);
25 if (device_get_uclass_id(dev) == UCLASS_CLK && clkp) {
26 rate = clk_get_rate(clkp);
28 printf(" %-12u %8d ", rate, clkp->enable_count);
30 for (i = depth; i >= 0; i--) {
31 is_last = (last_flag >> i) & 1;
45 printf("%s\n", dev->name);
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);
54 int __weak soc_clk_dump(void)
60 printf(" Rate Usecnt Name\n");
61 printf("------------------------------------------\n");
62 show_clks(root, -1, 0);
68 int __weak soc_clk_dump(void)
70 puts("Not implemented\n");
75 static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int argc,
82 printf("Clock dump error %d\n", ret);
83 ret = CMD_RET_FAILURE;
89 static struct cmd_tbl cmd_clk_sub[] = {
90 U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
93 static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc,
101 /* Strip off leading 'clk' command argument */
105 c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
108 return c->cmd(cmdtp, flag, argc, argv);
110 return CMD_RET_USAGE;
113 #ifdef CONFIG_SYS_LONGHELP
114 static char clk_help_text[] =
115 "dump - Print clock frequencies";
118 U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);