blob: 5402c87de7295ca8bd5f374a788b360dcc1e5a7e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek08d0d6f2013-11-21 13:39:02 -08002/*
3 * Copyright (C) 2013 Xilinx, Inc.
Michal Simek08d0d6f2013-11-21 13:39:02 -08004 */
5#include <common.h>
6#include <command.h>
7#include <clk.h>
Marek Vasutff8eee02018-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 Simek08d0d6f2013-11-21 13:39:02 -080012
13int __weak soc_clk_dump(void)
14{
Marek Vasutff8eee02018-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;
Ismael Luceno Cortes80b44fb2019-03-18 12:27:32 +000020 ulong rate;
Marek Vasutff8eee02018-08-08 22:10:44 +020021
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);
Ismael Luceno Cortes80b44fb2019-03-18 12:27:32 +000030 if (ret)
31 goto noclk;
Marek Vasutff8eee02018-08-08 22:10:44 +020032
33 ret = clk_request(dev, &clk);
Ismael Luceno Cortes80b44fb2019-03-18 12:27:32 +000034 if (ret)
35 goto noclk;
Marek Vasutff8eee02018-08-08 22:10:44 +020036
Ismael Luceno Cortes80b44fb2019-03-18 12:27:32 +000037 rate = clk_get_rate(&clk);
Marek Vasutff8eee02018-08-08 22:10:44 +020038 clk_free(&clk);
Ismael Luceno Cortes80b44fb2019-03-18 12:27:32 +000039
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);
Marek Vasutff8eee02018-08-08 22:10:44 +020047 }
48
49 return 0;
50#else
Michal Simek08d0d6f2013-11-21 13:39:02 -080051 puts("Not implemented\n");
52 return 1;
Marek Vasutff8eee02018-08-08 22:10:44 +020053#endif
Michal Simek08d0d6f2013-11-21 13:39:02 -080054}
55
56static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
57 char *const argv[])
58{
Michal Simekebc675b2018-04-19 15:15:25 +020059 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;
Michal Simek08d0d6f2013-11-21 13:39:02 -080068}
69
70static cmd_tbl_t cmd_clk_sub[] = {
71 U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
72};
73
74static 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
95static char clk_help_text[] =
96 "dump - Print clock frequencies";
97#endif
98
99U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);