ARM: uniphier: fix build error for CONFIG_DEBUG_LL=y
[project/bcm63xx/u-boot.git] / cmd / clk.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2013 Xilinx, Inc.
4 */
5 #include <common.h>
6 #include <command.h>
7 #include <clk.h>
8 #if defined(CONFIG_DM) && defined(CONFIG_CLK)
9 #include <dm.h>
10 #include <dm/device-internal.h>
11 #endif
12
13 int __weak soc_clk_dump(void)
14 {
15 #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;
21
22 /* Device addresses start at 1 */
23 ret = uclass_get(UCLASS_CLK, &uc);
24 if (ret)
25 return ret;
26
27 uclass_foreach_dev(dev, uc) {
28 memset(&clk, 0, sizeof(clk));
29 ret = device_probe(dev);
30 if (ret)
31 goto noclk;
32
33 ret = clk_request(dev, &clk);
34 if (ret)
35 goto noclk;
36
37 rate = clk_get_rate(&clk);
38 clk_free(&clk);
39
40 if (rate == -ENODEV)
41 goto noclk;
42
43 printf("%-30.30s : %lu Hz\n", dev->name, rate);
44 continue;
45 noclk:
46 printf("%-30.30s : ? Hz\n", dev->name);
47 }
48
49 return 0;
50 #else
51 puts("Not implemented\n");
52 return 1;
53 #endif
54 }
55
56 static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
57 char *const argv[])
58 {
59 int ret;
60
61 ret = soc_clk_dump();
62 if (ret < 0) {
63 printf("Clock dump error %d\n", ret);
64 ret = CMD_RET_FAILURE;
65 }
66
67 return ret;
68 }
69
70 static cmd_tbl_t cmd_clk_sub[] = {
71 U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
72 };
73
74 static int do_clk(cmd_tbl_t *cmdtp, int flag, int argc,
75 char *const argv[])
76 {
77 cmd_tbl_t *c;
78
79 if (argc < 2)
80 return CMD_RET_USAGE;
81
82 /* Strip off leading 'clk' command argument */
83 argc--;
84 argv++;
85
86 c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
87
88 if (c)
89 return c->cmd(cmdtp, flag, argc, argv);
90 else
91 return CMD_RET_USAGE;
92 }
93
94 #ifdef CONFIG_SYS_LONGHELP
95 static char clk_help_text[] =
96 "dump - Print clock frequencies";
97 #endif
98
99 U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);