blob: fd4231589c5cb4d70cc69a9d613a26d504777d8d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simeka0d28022013-11-21 13:39:02 -08002/*
3 * Copyright (C) 2013 Xilinx, Inc.
Michal Simeka0d28022013-11-21 13:39:02 -08004 */
5#include <common.h>
6#include <command.h>
7#include <clk.h>
Marek Vasut9254f992018-08-08 22:10:44 +02008#if defined(CONFIG_DM) && defined(CONFIG_CLK)
9#include <dm.h>
10#include <dm/device-internal.h>
11#endif
Michal Simeka0d28022013-11-21 13:39:02 -080012
13int __weak soc_clk_dump(void)
14{
Marek Vasut9254f992018-08-08 22:10:44 +020015#if defined(CONFIG_DM) && defined(CONFIG_CLK)
16 struct udevice *dev;
17 struct uclass *uc;
18 struct clk clk;
19 int ret;
20
21 /* Device addresses start at 1 */
22 ret = uclass_get(UCLASS_CLK, &uc);
23 if (ret)
24 return ret;
25
26 uclass_foreach_dev(dev, uc) {
27 memset(&clk, 0, sizeof(clk));
28 ret = device_probe(dev);
29 if (ret) {
30 printf("%-30.30s : ? Hz\n", dev->name);
31 continue;
32 }
33
34 ret = clk_request(dev, &clk);
35 if (ret) {
36 printf("%-30.30s : ? Hz\n", dev->name);
37 continue;
38 }
39
40 printf("%-30.30s : %lu Hz\n", dev->name, clk_get_rate(&clk));
41
42 clk_free(&clk);
43 }
44
45 return 0;
46#else
Michal Simeka0d28022013-11-21 13:39:02 -080047 puts("Not implemented\n");
48 return 1;
Marek Vasut9254f992018-08-08 22:10:44 +020049#endif
Michal Simeka0d28022013-11-21 13:39:02 -080050}
51
52static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
53 char *const argv[])
54{
Michal Simek7f6992b2018-04-19 15:15:25 +020055 int ret;
56
57 ret = soc_clk_dump();
58 if (ret < 0) {
59 printf("Clock dump error %d\n", ret);
60 ret = CMD_RET_FAILURE;
61 }
62
63 return ret;
Michal Simeka0d28022013-11-21 13:39:02 -080064}
65
66static cmd_tbl_t cmd_clk_sub[] = {
67 U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
68};
69
70static int do_clk(cmd_tbl_t *cmdtp, int flag, int argc,
71 char *const argv[])
72{
73 cmd_tbl_t *c;
74
75 if (argc < 2)
76 return CMD_RET_USAGE;
77
78 /* Strip off leading 'clk' command argument */
79 argc--;
80 argv++;
81
82 c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
83
84 if (c)
85 return c->cmd(cmdtp, flag, argc, argv);
86 else
87 return CMD_RET_USAGE;
88}
89
90#ifdef CONFIG_SYS_LONGHELP
91static char clk_help_text[] =
92 "dump - Print clock frequencies";
93#endif
94
95U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);