blob: 7b94a80b725e7e6e4346e7e7d57fcc2c9df5c9cc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04002/*
3 * keystone2: commands for clocks
4 *
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04007 */
8
Andrew Davise30db192023-11-17 16:38:29 -06009#include <vsprintf.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040010#include <command.h>
Tom Rinica140792025-05-14 12:15:31 -060011#include <linux/string.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040012#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
Simon Glassed38aef2020-05-10 11:40:03 -060023int do_pll_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040024{
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
Simon Glassff9b9032021-07-24 09:03:30 -060046 cmd_pll_data.pll_m = dectoul(argv[2], NULL);
47 cmd_pll_data.pll_d = dectoul(argv[3], NULL);
48 cmd_pll_data.pll_od = dectoul(argv[4], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040049
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 +030061U_BOOT_CMD(
62 pllset, 5, 0, do_pll_cmd,
63 "set pll multiplier and pre divider",
Khoronzhuk, Ivan90084ea2014-10-22 16:01:28 +030064 PLLSET_CMD_LIST " <mult> <div> <OD>\n"
Hao Zhang0ecd31e2014-07-16 00:59:23 +030065);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040066
Simon Glassed38aef2020-05-10 11:40:03 -060067int do_getclk_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
68 char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040069{
70 unsigned int clk;
Lokesh Vutla41f7ea82015-07-28 14:16:48 +053071 unsigned long freq;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040072
73 if (argc != 2)
74 goto getclk_cmd_usage;
75
Simon Glassff9b9032021-07-24 09:03:30 -060076 clk = dectoul(argv[1], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040077
Masahiro Yamadaf576ecf2016-09-26 20:45:26 +090078 freq = ks_clk_get_rate(clk);
Lokesh Vutla41f7ea82015-07-28 14:16:48 +053079 if (freq)
80 printf("clock index [%d] - frequency %lu\n", clk, freq);
81 else
82 printf("clock index [%d] Not available\n", clk);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040083 return 0;
84
85getclk_cmd_usage:
86 return cmd_usage(cmdtp);
87}
88
89U_BOOT_CMD(
90 getclk, 2, 0, do_getclk_cmd,
91 "get clock rate",
92 "<clk index>\n"
Khoronzhuk, Ivan90084ea2014-10-22 16:01:28 +030093 "The indexes for clocks:\n"
94 CLOCK_INDEXES_LIST
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040095);
96
Simon Glassed38aef2020-05-10 11:40:03 -060097int do_psc_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040098{
99 int psc_module;
100 int res;
101
102 if (argc != 3)
103 goto psc_cmd_usage;
104
Simon Glassff9b9032021-07-24 09:03:30 -0600105 psc_module = dectoul(argv[1], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400106 if (strcmp(argv[2], "en") == 0) {
107 res = psc_enable_module(psc_module);
108 printf("psc_enable_module(%d) - %s\n", psc_module,
109 (res) ? "ERROR" : "OK");
110 return 0;
111 }
112
113 if (strcmp(argv[2], "di") == 0) {
114 res = psc_disable_module(psc_module);
115 printf("psc_disable_module(%d) - %s\n", psc_module,
116 (res) ? "ERROR" : "OK");
117 return 0;
118 }
119
120 if (strcmp(argv[2], "domain") == 0) {
121 res = psc_disable_domain(psc_module);
122 printf("psc_disable_domain(%d) - %s\n", psc_module,
123 (res) ? "ERROR" : "OK");
124 return 0;
125 }
126
127psc_cmd_usage:
128 return cmd_usage(cmdtp);
129}
130
131U_BOOT_CMD(
132 psc, 3, 0, do_psc_cmd,
133 "<enable/disable psc module os disable domain>",
134 "<mod/domain index> <en|di|domain>\n"
Khoronzhuk, Ivan90084ea2014-10-22 16:01:28 +0300135 "Intended to control Power and Sleep Controller (PSC) domains and\n"
136 "modules. The module or domain index exectly corresponds to ones\n"
137 "listed in official TRM. For instance, to enable MSMC RAM clock\n"
138 "domain use command: psc 14 en.\n"
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400139);