Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Xilinx, Inc. |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <command.h> |
| 7 | #include <clk.h> |
Marek Vasut | 9254f99 | 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 | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 12 | |
| 13 | int __weak soc_clk_dump(void) |
| 14 | { |
Marek Vasut | 9254f99 | 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; |
| 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 Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 47 | puts("Not implemented\n"); |
| 48 | return 1; |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 49 | #endif |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc, |
| 53 | char *const argv[]) |
| 54 | { |
Michal Simek | 7f6992b | 2018-04-19 15:15:25 +0200 | [diff] [blame] | 55 | 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 Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static cmd_tbl_t cmd_clk_sub[] = { |
| 67 | U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""), |
| 68 | }; |
| 69 | |
| 70 | static 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 |
| 91 | static char clk_help_text[] = |
| 92 | "dump - Print clock frequencies"; |
| 93 | #endif |
| 94 | |
| 95 | U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text); |