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> |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 10 | #include <dm/device.h> |
| 11 | #include <dm/root.h> |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 12 | #include <dm/device-internal.h> |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 13 | #include <linux/clk-provider.h> |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 14 | #endif |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 15 | |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 16 | #if defined(CONFIG_DM) && defined(CONFIG_CLK) |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 17 | static void show_clks(struct udevice *dev, int depth, int last_flag) |
| 18 | { |
| 19 | int i, is_last; |
| 20 | struct udevice *child; |
| 21 | struct clk *clkp; |
| 22 | u32 rate; |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 23 | |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 24 | clkp = dev_get_clk_ptr(dev); |
| 25 | if (device_get_uclass_id(dev) == UCLASS_CLK && clkp) { |
Patrick Delaunay | 0ca4cc0 | 2020-07-30 14:04:10 +0200 | [diff] [blame] | 26 | depth++; |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 27 | rate = clk_get_rate(clkp); |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 28 | |
Patrick Delaunay | 15c5a34 | 2020-07-30 14:04:09 +0200 | [diff] [blame] | 29 | printf(" %-12u %8d ", rate, clkp->enable_count); |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 30 | |
Patrick Delaunay | 15c5a34 | 2020-07-30 14:04:09 +0200 | [diff] [blame] | 31 | for (i = depth; i >= 0; i--) { |
| 32 | is_last = (last_flag >> i) & 1; |
| 33 | if (i) { |
| 34 | if (is_last) |
| 35 | printf(" "); |
| 36 | else |
| 37 | printf("| "); |
| 38 | } else { |
| 39 | if (is_last) |
| 40 | printf("`-- "); |
| 41 | else |
| 42 | printf("|-- "); |
| 43 | } |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 44 | } |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 45 | |
Patrick Delaunay | 15c5a34 | 2020-07-30 14:04:09 +0200 | [diff] [blame] | 46 | printf("%s\n", dev->name); |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 47 | } |
Ismael Luceno Cortes | 8b5d3a4 | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 48 | |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 49 | list_for_each_entry(child, &dev->child_head, sibling_node) { |
| 50 | is_last = list_is_last(&child->sibling_node, &dev->child_head); |
Patrick Delaunay | 0ca4cc0 | 2020-07-30 14:04:10 +0200 | [diff] [blame] | 51 | show_clks(child, depth, (last_flag << 1) | is_last); |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 52 | } |
| 53 | } |
Ismael Luceno Cortes | 8b5d3a4 | 2019-03-18 12:27:32 +0000 | [diff] [blame] | 54 | |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 55 | int __weak soc_clk_dump(void) |
| 56 | { |
| 57 | struct udevice *root; |
| 58 | |
| 59 | root = dm_root(); |
| 60 | if (root) { |
| 61 | printf(" Rate Usecnt Name\n"); |
| 62 | printf("------------------------------------------\n"); |
| 63 | show_clks(root, -1, 0); |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | return 0; |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 67 | } |
Marek Vasut | 9254f99 | 2018-08-08 22:10:44 +0200 | [diff] [blame] | 68 | #else |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 69 | int __weak soc_clk_dump(void) |
| 70 | { |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 71 | puts("Not implemented\n"); |
| 72 | return 1; |
| 73 | } |
Peng Fan | 51709f7 | 2019-08-21 13:35:14 +0000 | [diff] [blame] | 74 | #endif |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 75 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 76 | static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int argc, |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 77 | char *const argv[]) |
| 78 | { |
Michal Simek | 7f6992b | 2018-04-19 15:15:25 +0200 | [diff] [blame] | 79 | int ret; |
| 80 | |
| 81 | ret = soc_clk_dump(); |
| 82 | if (ret < 0) { |
| 83 | printf("Clock dump error %d\n", ret); |
| 84 | ret = CMD_RET_FAILURE; |
| 85 | } |
| 86 | |
| 87 | return ret; |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 90 | static struct cmd_tbl cmd_clk_sub[] = { |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 91 | U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""), |
| 92 | }; |
| 93 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 94 | static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc, |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 95 | char *const argv[]) |
| 96 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 97 | struct cmd_tbl *c; |
Michal Simek | a0d2802 | 2013-11-21 13:39:02 -0800 | [diff] [blame] | 98 | |
| 99 | if (argc < 2) |
| 100 | return CMD_RET_USAGE; |
| 101 | |
| 102 | /* Strip off leading 'clk' command argument */ |
| 103 | argc--; |
| 104 | argv++; |
| 105 | |
| 106 | c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub)); |
| 107 | |
| 108 | if (c) |
| 109 | return c->cmd(cmdtp, flag, argc, argv); |
| 110 | else |
| 111 | return CMD_RET_USAGE; |
| 112 | } |
| 113 | |
| 114 | #ifdef CONFIG_SYS_LONGHELP |
| 115 | static char clk_help_text[] = |
| 116 | "dump - Print clock frequencies"; |
| 117 | #endif |
| 118 | |
| 119 | U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text); |