blob: d97c95be11ddad8ff8b99cad1e1dafc91c5c24c6 [file] [log] [blame]
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04001/*
2 * keystone2: commands for clocks
3 *
4 * (C) Copyright 2012-2014
5 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <command.h>
12#include <asm/arch/hardware.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/psc_defs.h>
15
16struct pll_init_data cmd_pll_data = {
Hao Zhang0ecd31e2014-07-16 00:59:23 +030017 .pll = MAIN_PLL,
18 .pll_m = 16,
19 .pll_d = 1,
20 .pll_od = 2,
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040021};
22
23int do_pll_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
24{
25 if (argc != 5)
26 goto pll_cmd_usage;
27
28 if (strncmp(argv[1], "pa", 2) == 0)
29 cmd_pll_data.pll = PASS_PLL;
Hao Zhang0ecd31e2014-07-16 00:59:23 +030030#ifndef CONFIG_SOC_K2E
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040031 else if (strncmp(argv[1], "arm", 3) == 0)
32 cmd_pll_data.pll = TETRIS_PLL;
Hao Zhang0ecd31e2014-07-16 00:59:23 +030033#endif
34#ifdef CONFIG_SOC_K2HK
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040035 else if (strncmp(argv[1], "ddr3a", 5) == 0)
36 cmd_pll_data.pll = DDR3A_PLL;
37 else if (strncmp(argv[1], "ddr3b", 5) == 0)
38 cmd_pll_data.pll = DDR3B_PLL;
Hao Zhang0ecd31e2014-07-16 00:59:23 +030039#else
40 else if (strncmp(argv[1], "ddr3", 4) == 0)
41 cmd_pll_data.pll = DDR3_PLL;
42#endif
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040043 else
44 goto pll_cmd_usage;
45
46 cmd_pll_data.pll_m = simple_strtoul(argv[2], NULL, 10);
47 cmd_pll_data.pll_d = simple_strtoul(argv[3], NULL, 10);
48 cmd_pll_data.pll_od = simple_strtoul(argv[4], NULL, 10);
49
50 printf("Trying to set pll %d; mult %d; div %d; OD %d\n",
51 cmd_pll_data.pll, cmd_pll_data.pll_m,
52 cmd_pll_data.pll_d, cmd_pll_data.pll_od);
53 init_pll(&cmd_pll_data);
54
55 return 0;
56
57pll_cmd_usage:
58 return cmd_usage(cmdtp);
59}
60
Hao Zhang0ecd31e2014-07-16 00:59:23 +030061#ifdef CONFIG_SOC_K2HK
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040062U_BOOT_CMD(
63 pllset, 5, 0, do_pll_cmd,
64 "set pll multiplier and pre divider",
65 "<pa|arm|ddr3a|ddr3b> <mult> <div> <OD>\n"
66);
Hao Zhang0ecd31e2014-07-16 00:59:23 +030067#endif
68#ifdef CONFIG_SOC_K2E
69U_BOOT_CMD(
70 pllset, 5, 0, do_pll_cmd,
71 "set pll multiplier and pre divider",
72 "<pa|ddr3> <mult> <div> <OD>\n"
73);
74#endif
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040075
76int do_getclk_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
77{
78 unsigned int clk;
79 unsigned int freq;
80
81 if (argc != 2)
82 goto getclk_cmd_usage;
83
84 clk = simple_strtoul(argv[1], NULL, 10);
85
86 freq = clk_get_rate(clk);
87 printf("clock index [%d] - frequency %u\n", clk, freq);
88 return 0;
89
90getclk_cmd_usage:
91 return cmd_usage(cmdtp);
92}
93
94U_BOOT_CMD(
95 getclk, 2, 0, do_getclk_cmd,
96 "get clock rate",
97 "<clk index>\n"
Hao Zhang0ecd31e2014-07-16 00:59:23 +030098#ifdef CONFIG_SOC_K2HK
99 "See the 'enum clk_e' in the clock-k2hk.h for clk indexes\n"
100#endif
101#ifdef CONFIG_SOC_K2E
102 "See the 'enum clk_e' in the clock-k2e.h for clk indexes\n"
103#endif
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400104);
105
106int do_psc_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
107{
108 int psc_module;
109 int res;
110
111 if (argc != 3)
112 goto psc_cmd_usage;
113
114 psc_module = simple_strtoul(argv[1], NULL, 10);
115 if (strcmp(argv[2], "en") == 0) {
116 res = psc_enable_module(psc_module);
117 printf("psc_enable_module(%d) - %s\n", psc_module,
118 (res) ? "ERROR" : "OK");
119 return 0;
120 }
121
122 if (strcmp(argv[2], "di") == 0) {
123 res = psc_disable_module(psc_module);
124 printf("psc_disable_module(%d) - %s\n", psc_module,
125 (res) ? "ERROR" : "OK");
126 return 0;
127 }
128
129 if (strcmp(argv[2], "domain") == 0) {
130 res = psc_disable_domain(psc_module);
131 printf("psc_disable_domain(%d) - %s\n", psc_module,
132 (res) ? "ERROR" : "OK");
133 return 0;
134 }
135
136psc_cmd_usage:
137 return cmd_usage(cmdtp);
138}
139
140U_BOOT_CMD(
141 psc, 3, 0, do_psc_cmd,
142 "<enable/disable psc module os disable domain>",
143 "<mod/domain index> <en|di|domain>\n"
144 "See the hardware.h for Power and Sleep Controller (PSC) Domains\n"
145);