Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 08d0d6f | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Xilinx, Inc. |
Michal Simek | 08d0d6f | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <command.h> |
| 7 | #include <clk.h> |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 8 | #if defined(CONFIG_DM) && defined(CONFIG_CLK) |
| 9 | #include <dm.h> |
| 10 | #include <dm/device-internal.h> |
| 11 | #endif |
Michal Simek | 08d0d6f | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 12 | |
| 13 | int __weak soc_clk_dump(void) |
| 14 | { |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 15 | #if defined(CONFIG_DM) && defined(CONFIG_CLK) |
| 16 | struct udevice *dev; |
| 17 | struct uclass *uc; |
| 18 | struct clk clk; |
| 19 | int ret; |
Ismael Luceno Cortes | 80b44fb | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 20 | ulong rate; |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 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); |
Ismael Luceno Cortes | 80b44fb | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 30 | if (ret) |
| 31 | goto noclk; |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 32 | |
| 33 | ret = clk_request(dev, &clk); |
Ismael Luceno Cortes | 80b44fb | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 34 | if (ret) |
| 35 | goto noclk; |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 36 | |
Ismael Luceno Cortes | 80b44fb | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 37 | rate = clk_get_rate(&clk); |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 38 | clk_free(&clk); |
Ismael Luceno Cortes | 80b44fb | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 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); |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | #else |
Michal Simek | 08d0d6f | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 51 | puts("Not implemented\n"); |
| 52 | return 1; |
Marek Vasut | ff8eee0 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 53 | #endif |
Michal Simek | 08d0d6f | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc, |
| 57 | char *const argv[]) |
| 58 | { |
Michal Simek | ebc675b | 2018-04-19 15:15:25 +0200 | [diff] [blame] | 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; |
Michal Simek | 08d0d6f | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 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); |