]> Git Repo - u-boot.git/blame - cmd/clk.c
Merge patch series "*** phyCORE-AM62x: DDR detection / Inject DDR timing deltas ***"
[u-boot.git] / cmd / clk.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
08d0d6f3
MS
2/*
3 * Copyright (C) 2013 Xilinx, Inc.
08d0d6f3 4 */
08d0d6f3
MS
5#include <command.h>
6#include <clk.h>
ff8eee03
MV
7#if defined(CONFIG_DM) && defined(CONFIG_CLK)
8#include <dm.h>
aeeb2e6d
PF
9#include <dm/device.h>
10#include <dm/root.h>
ff8eee03 11#include <dm/device-internal.h>
aeeb2e6d 12#include <linux/clk-provider.h>
ff8eee03 13#endif
08d0d6f3 14
ff8eee03 15#if defined(CONFIG_DM) && defined(CONFIG_CLK)
aeeb2e6d
PF
16static void show_clks(struct udevice *dev, int depth, int last_flag)
17{
18 int i, is_last;
19 struct udevice *child;
1a725e22 20 struct clk *clkp, *parent;
aeeb2e6d
PF
21 u32 rate;
22
23 clkp = dev_get_clk_ptr(dev);
c40251c1 24 if (clkp) {
1a725e22
TK
25 parent = clk_get_parent(clkp);
26 if (!IS_ERR(parent) && depth == -1)
27 return;
689ca8c5 28 depth++;
aeeb2e6d
PF
29 rate = clk_get_rate(clkp);
30
cc632841
PD
31 printf(" %-12u %8d ", rate, clkp->enable_count);
32
33 for (i = depth; i >= 0; i--) {
34 is_last = (last_flag >> i) & 1;
35 if (i) {
36 if (is_last)
37 printf(" ");
38 else
39 printf("| ");
40 } else {
41 if (is_last)
42 printf("`-- ");
43 else
44 printf("|-- ");
45 }
aeeb2e6d 46 }
ff8eee03 47
cc632841 48 printf("%s\n", dev->name);
aeeb2e6d 49 }
ff8eee03 50
c40251c1
PD
51 device_foreach_child_probe(child, dev) {
52 if (device_get_uclass_id(child) != UCLASS_CLK)
53 continue;
1a725e22
TK
54 if (child == dev)
55 continue;
aeeb2e6d 56 is_last = list_is_last(&child->sibling_node, &dev->child_head);
689ca8c5 57 show_clks(child, depth, (last_flag << 1) | is_last);
aeeb2e6d
PF
58 }
59}
80b44fb3 60
5666558a 61static int soc_clk_dump(void)
aeeb2e6d 62{
1a725e22 63 struct udevice *dev;
258c1002 64 const struct clk_ops *ops;
1a725e22
TK
65
66 printf(" Rate Usecnt Name\n");
67 printf("------------------------------------------\n");
68
c40251c1 69 uclass_foreach_dev_probe(UCLASS_CLK, dev)
1a725e22 70 show_clks(dev, -1, 0);
ff8eee03 71
258c1002
IP
72 uclass_foreach_dev_probe(UCLASS_CLK, dev) {
73 ops = dev_get_driver_ops(dev);
74 if (ops && ops->dump) {
75 printf("\n%s %s:\n", dev->driver->name, dev->name);
76 ops->dump(dev);
77 }
78 }
79
ff8eee03 80 return 0;
aeeb2e6d 81}
ff8eee03 82#else
5666558a 83static int soc_clk_dump(void)
aeeb2e6d 84{
08d0d6f3
MS
85 puts("Not implemented\n");
86 return 1;
87}
aeeb2e6d 88#endif
08d0d6f3 89
09140113 90static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int argc,
08d0d6f3
MS
91 char *const argv[])
92{
ebc675b9
MS
93 int ret;
94
95 ret = soc_clk_dump();
96 if (ret < 0) {
97 printf("Clock dump error %d\n", ret);
98 ret = CMD_RET_FAILURE;
99 }
100
101 return ret;
08d0d6f3
MS
102}
103
7ab418fb 104#if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(CLK)
7ab418fb
TK
105static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc,
106 char *const argv[])
107{
108 struct clk *clk = NULL;
109 s32 freq;
110 struct udevice *dev;
111
3386fb1e
PD
112 if (argc != 3)
113 return CMD_RET_USAGE;
114
0b1284eb 115 freq = dectoul(argv[2], NULL);
7ab418fb 116
afcc2614 117 if (!uclass_get_device_by_name(UCLASS_CLK, argv[1], &dev))
7ab418fb
TK
118 clk = dev_get_clk_ptr(dev);
119
120 if (!clk) {
121 printf("clock '%s' not found.\n", argv[1]);
534859ac 122 return CMD_RET_FAILURE;
7ab418fb
TK
123 }
124
125 freq = clk_set_rate(clk, freq);
126 if (freq < 0) {
127 printf("set_rate failed: %d\n", freq);
128 return CMD_RET_FAILURE;
129 }
130
131 printf("set_rate returns %u\n", freq);
132 return 0;
133}
134#endif
135
09140113 136static struct cmd_tbl cmd_clk_sub[] = {
08d0d6f3 137 U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
7ab418fb
TK
138#if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(CLK)
139 U_BOOT_CMD_MKENT(setfreq, 3, 1, do_clk_setfreq, "", ""),
140#endif
08d0d6f3
MS
141};
142
09140113 143static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc,
08d0d6f3
MS
144 char *const argv[])
145{
09140113 146 struct cmd_tbl *c;
08d0d6f3
MS
147
148 if (argc < 2)
149 return CMD_RET_USAGE;
150
151 /* Strip off leading 'clk' command argument */
152 argc--;
153 argv++;
154
155 c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
156
157 if (c)
158 return c->cmd(cmdtp, flag, argc, argv);
159 else
160 return CMD_RET_USAGE;
161}
162
3616218b 163U_BOOT_LONGHELP(clk,
7ab418fb 164 "dump - Print clock frequencies\n"
3616218b 165 "clk setfreq [clk] [freq] - Set clock frequency");
08d0d6f3 166
7ab418fb 167U_BOOT_CMD(clk, 4, 1, do_clk, "CLK sub-system", clk_help_text);
This page took 0.228758 seconds and 4 git commands to generate.