blob: 59ca8aeabac7ba720c9050052a5915ef1455379d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Tom Warren9c79abe2012-12-11 13:34:13 +00002/*
Thierry Redingce7eb162019-04-15 11:32:25 +02003 * Copyright (c) 2010-2019, NVIDIA CORPORATION. All rights reserved.
Tom Warren9c79abe2012-12-11 13:34:13 +00004 */
5
6#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Tom Warren9c79abe2012-12-11 13:34:13 +00008#include <asm/io.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/gp_padctrl.h>
11#include <asm/arch/pinmux.h>
12#include <asm/arch/tegra.h>
13#include <asm/arch-tegra/clk_rst.h>
14#include <asm/arch-tegra/pmc.h>
15#include <asm/arch-tegra/scu.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Tom Warren9c79abe2012-12-11 13:34:13 +000017#include "cpu.h"
18
Tom Warrend034d1b2013-01-28 13:32:08 +000019int get_num_cpus(void)
Tom Warren9c79abe2012-12-11 13:34:13 +000020{
Tom Warrend034d1b2013-01-28 13:32:08 +000021 struct apb_misc_gp_ctlr *gp;
22 uint rev;
Tom Warrenab0cc6b2015-03-04 16:36:00 -070023 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +000024
Tom Warrend034d1b2013-01-28 13:32:08 +000025 gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
26 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
Tom Warren9c79abe2012-12-11 13:34:13 +000027
Tom Warrend034d1b2013-01-28 13:32:08 +000028 switch (rev) {
29 case CHIPID_TEGRA20:
30 return 2;
31 break;
32 case CHIPID_TEGRA30:
33 case CHIPID_TEGRA114:
Tom Warrenab0cc6b2015-03-04 16:36:00 -070034 case CHIPID_TEGRA124:
35 case CHIPID_TEGRA210:
Tom Warrend034d1b2013-01-28 13:32:08 +000036 default:
37 return 4;
38 break;
39 }
Tom Warren9c79abe2012-12-11 13:34:13 +000040}
41
42/*
43 * Timing tables for each SOC for all four oscillator options.
44 */
45struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = {
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020046 /*
47 * T20: 1 GHz
48 *
49 * Register Field Bits Width
50 * ------------------------------
51 * PLLX_BASE p 22:20 3
52 * PLLX_BASE n 17: 8 10
53 * PLLX_BASE m 4: 0 5
54 * PLLX_MISC cpcon 11: 8 4
55 */
56 {
57 { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020058 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
59 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
60 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020061 { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020062 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
63 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
64 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020065 { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020066 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
67 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
68 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020069 { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000070 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020071 /*
72 * T25: 1.2 GHz
73 *
74 * Register Field Bits Width
75 * ------------------------------
76 * PLLX_BASE p 22:20 3
77 * PLLX_BASE n 17: 8 10
78 * PLLX_BASE m 4: 0 5
79 * PLLX_MISC cpcon 11: 8 4
80 */
81 {
82 { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020083 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
84 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
85 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020086 { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020087 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
88 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
89 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020090 { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020091 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
92 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
93 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020094 { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000095 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020096 /*
Stephen Warrenecc75382014-05-08 09:33:45 -060097 * T30: 600 MHz
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020098 *
99 * Register Field Bits Width
100 * ------------------------------
101 * PLLX_BASE p 22:20 3
102 * PLLX_BASE n 17: 8 10
103 * PLLX_BASE m 4: 0 5
104 * PLLX_MISC cpcon 11: 8 4
105 */
106 {
Stephen Warrenecc75382014-05-08 09:33:45 -0600107 { .n = 600, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200108 { .n = 600, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 16.8 MHz */
109 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
110 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Stephen Warrenecc75382014-05-08 09:33:45 -0600111 { .n = 500, .m = 16, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200112 { .n = 500, .m = 16, .p = 0, .cpcon = 8 }, /* OSC: 38.4 MHz */
113 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
114 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Stephen Warrenecc75382014-05-08 09:33:45 -0600115 { .n = 600, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200116 { .n = 600, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 48.0 MHz */
117 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
118 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Stephen Warrenecc75382014-05-08 09:33:45 -0600119 { .n = 600, .m = 26, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +0000120 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200121 /*
122 * T114: 700 MHz
123 *
124 * Register Field Bits Width
125 * ------------------------------
126 * PLLX_BASE p 23:20 4
127 * PLLX_BASE n 15: 8 8
128 * PLLX_BASE m 7: 0 8
129 */
130 {
131 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200132 { .n = 108, .m = 1, .p = 1 }, /* OSC: 16.8 MHz */
133 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
134 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200135 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200136 { .n = 73, .m = 1, .p = 1 }, /* OSC: 38.4 MHz */
137 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
138 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200139 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200140 { .n = 116, .m = 1, .p = 1 }, /* OSC: 48.0 MHz */
141 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
142 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200143 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
Tom Warrend034d1b2013-01-28 13:32:08 +0000144 },
Tom Warren9588ab72014-01-24 12:46:14 -0700145
146 /*
147 * T124: 700 MHz
148 *
149 * Register Field Bits Width
150 * ------------------------------
151 * PLLX_BASE p 23:20 4
152 * PLLX_BASE n 15: 8 8
153 * PLLX_BASE m 7: 0 8
154 */
155 {
156 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200157 { .n = 108, .m = 1, .p = 1 }, /* OSC: 16.8 MHz */
158 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
159 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Tom Warren9588ab72014-01-24 12:46:14 -0700160 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200161 { .n = 73, .m = 1, .p = 1 }, /* OSC: 38.4 MHz */
162 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
163 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Tom Warren9588ab72014-01-24 12:46:14 -0700164 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200165 { .n = 116, .m = 1, .p = 1 }, /* OSC: 48.0 MHz */
166 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
167 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Tom Warren9588ab72014-01-24 12:46:14 -0700168 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
169 },
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700170
171 /*
172 * T210: 700 MHz
173 *
174 * Register Field Bits Width
175 * ------------------------------
176 * PLLX_BASE p 24:20 5
177 * PLLX_BASE n 15: 8 8
178 * PLLX_BASE m 7: 0 8
179 */
180 {
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200181 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz = 702 MHz */
182 { .n = 108, .m = 1, .p = 1 }, /* OSC: 16.0 MHz = 702 MHz */
183 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
184 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
185 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz = 700.8 MHz */
Tom Warren27bce712015-06-22 13:03:44 -0700186 { .n = 36, .m = 1, .p = 1 }, /* OSC: 38.4 MHz = 691.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200187 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
188 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
189 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz = 696 MHz */
Tom Warren27bce712015-06-22 13:03:44 -0700190 { .n = 58, .m = 2, .p = 1 }, /* OSC: 48.0 MHz = 696 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200191 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
192 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
193 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz = 702 MHz */
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700194 },
Tom Warren9c79abe2012-12-11 13:34:13 +0000195};
196
Tom Warren9588ab72014-01-24 12:46:14 -0700197static inline void pllx_set_iddq(void)
198{
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700199#if defined(CONFIG_TEGRA124) || defined(CONFIG_TEGRA210)
Tom Warren9588ab72014-01-24 12:46:14 -0700200 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
201 u32 reg;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700202 debug("%s entry\n", __func__);
Tom Warren9588ab72014-01-24 12:46:14 -0700203
204 /* Disable IDDQ */
205 reg = readl(&clkrst->crc_pllx_misc3);
206 reg &= ~PLLX_IDDQ_MASK;
207 writel(reg, &clkrst->crc_pllx_misc3);
208 udelay(2);
209 debug("%s: IDDQ: PLLX IDDQ = 0x%08X\n", __func__,
210 readl(&clkrst->crc_pllx_misc3));
211#endif
212}
213
Tom Warren9c79abe2012-12-11 13:34:13 +0000214int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
215 u32 divp, u32 cpcon)
216{
Tom Warrena8480ef2015-06-25 09:50:44 -0700217 struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
Thierry Reding87baa2a2013-10-01 17:04:45 +0200218 int chip = tegra_get_chip();
Tom Warren9c79abe2012-12-11 13:34:13 +0000219 u32 reg;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700220 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000221
222 /* If PLLX is already enabled, just return */
223 if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700224 debug("%s: PLLX already enabled, returning\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000225 return 0;
226 }
227
Tom Warren9588ab72014-01-24 12:46:14 -0700228 pllx_set_iddq();
229
Tom Warren9c79abe2012-12-11 13:34:13 +0000230 /* Set BYPASS, m, n and p to PLLX_BASE */
Tom Warrena8480ef2015-06-25 09:50:44 -0700231 reg = PLL_BYPASS_MASK | (divm << pllinfo->m_shift);
232 reg |= (divn << pllinfo->n_shift) | (divp << pllinfo->p_shift);
Tom Warren9c79abe2012-12-11 13:34:13 +0000233 writel(reg, &pll->pll_base);
234
235 /* Set cpcon to PLLX_MISC */
Thierry Reding87baa2a2013-10-01 17:04:45 +0200236 if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30)
Tom Warrena8480ef2015-06-25 09:50:44 -0700237 reg = (cpcon << pllinfo->kcp_shift);
Thierry Reding87baa2a2013-10-01 17:04:45 +0200238 else
239 reg = 0;
Tom Warren9c79abe2012-12-11 13:34:13 +0000240
Tom Warrena8480ef2015-06-25 09:50:44 -0700241 /*
242 * TODO(twarren@nvidia.com) Check which SoCs use DCCON
243 * and add to pllinfo table if needed!
244 */
245 /* Set dccon to PLLX_MISC if freq > 600MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +0000246 if (divn > 600)
247 reg |= (1 << PLL_DCCON_SHIFT);
248 writel(reg, &pll->pll_misc);
249
Tom Warren9c79abe2012-12-11 13:34:13 +0000250 /* Disable BYPASS */
Stephen Warren54b76702014-01-24 12:46:09 -0700251 reg = readl(&pll->pll_base);
Tom Warren9c79abe2012-12-11 13:34:13 +0000252 reg &= ~PLL_BYPASS_MASK;
253 writel(reg, &pll->pll_base);
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700254 debug("%s: base = 0x%08X\n", __func__, reg);
Tom Warren9c79abe2012-12-11 13:34:13 +0000255
Tom Warrena8480ef2015-06-25 09:50:44 -0700256 /* Set lock_enable to PLLX_MISC if lock_ena is valid (i.e. 0-31) */
Tom Warren9c79abe2012-12-11 13:34:13 +0000257 reg = readl(&pll->pll_misc);
Tom Warrena8480ef2015-06-25 09:50:44 -0700258 if (pllinfo->lock_ena < 32)
259 reg |= (1 << pllinfo->lock_ena);
Tom Warren9c79abe2012-12-11 13:34:13 +0000260 writel(reg, &pll->pll_misc);
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700261 debug("%s: misc = 0x%08X\n", __func__, reg);
Stephen Warren54b76702014-01-24 12:46:09 -0700262
263 /* Enable PLLX last, once it's all configured */
264 reg = readl(&pll->pll_base);
265 reg |= PLL_ENABLE_MASK;
266 writel(reg, &pll->pll_base);
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700267 debug("%s: base final = 0x%08X\n", __func__, reg);
Tom Warren9c79abe2012-12-11 13:34:13 +0000268
269 return 0;
270}
271
272void init_pllx(void)
273{
274 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
275 struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
Tom Warren8b817112013-04-10 10:32:32 -0700276 int soc_type, sku_info, chip_sku;
Tom Warren9c79abe2012-12-11 13:34:13 +0000277 enum clock_osc_freq osc;
278 struct clk_pll_table *sel;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700279 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000280
Tom Warren8b817112013-04-10 10:32:32 -0700281 /* get SOC (chip) type */
282 soc_type = tegra_get_chip();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700283 debug("%s: SoC = 0x%02X\n", __func__, soc_type);
Tom Warren8b817112013-04-10 10:32:32 -0700284
285 /* get SKU info */
286 sku_info = tegra_get_sku_info();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700287 debug("%s: SKU info byte = 0x%02X\n", __func__, sku_info);
Tom Warren8b817112013-04-10 10:32:32 -0700288
289 /* get chip SKU, combo of the above info */
290 chip_sku = tegra_get_chip_sku();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700291 debug("%s: Chip SKU = %d\n", __func__, chip_sku);
Tom Warren9c79abe2012-12-11 13:34:13 +0000292
293 /* get osc freq */
294 osc = clock_get_osc_freq();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700295 debug("%s: osc = %d\n", __func__, osc);
Tom Warren9c79abe2012-12-11 13:34:13 +0000296
297 /* set pllx */
Tom Warren8b817112013-04-10 10:32:32 -0700298 sel = &tegra_pll_x_table[chip_sku][osc];
Tom Warren9c79abe2012-12-11 13:34:13 +0000299 pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
Tom Warren9c79abe2012-12-11 13:34:13 +0000300}
301
302void enable_cpu_clock(int enable)
303{
304 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
305 u32 clk;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700306 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000307
308 /*
309 * NOTE:
310 * Regardless of whether the request is to enable or disable the CPU
311 * clock, every processor in the CPU complex except the master (CPU 0)
312 * will have it's clock stopped because the AVP only talks to the
313 * master.
314 */
315
316 if (enable) {
317 /* Initialize PLLX */
318 init_pllx();
319
320 /* Wait until all clocks are stable */
321 udelay(PLL_STABILIZATION_DELAY);
322
323 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
324 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
325 }
326
327 /*
328 * Read the register containing the individual CPU clock enables and
329 * always stop the clocks to CPUs > 0.
330 */
331 clk = readl(&clkrst->crc_clk_cpu_cmplx);
332 clk |= 1 << CPU1_CLK_STP_SHIFT;
Tom Warrend034d1b2013-01-28 13:32:08 +0000333 if (get_num_cpus() == 4)
334 clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
335
Tom Warren9c79abe2012-12-11 13:34:13 +0000336 /* Stop/Unstop the CPU clock */
337 clk &= ~CPU0_CLK_STP_MASK;
338 clk |= !enable << CPU0_CLK_STP_SHIFT;
339 writel(clk, &clkrst->crc_clk_cpu_cmplx);
340
341 clock_enable(PERIPH_ID_CPU);
342}
343
344static int is_cpu_powered(void)
345{
Thierry Redingce7eb162019-04-15 11:32:25 +0200346 return (tegra_pmc_readl(offsetof(struct pmc_ctlr,
347 pmc_pwrgate_status)) & CPU_PWRED) ? 1 : 0;
Tom Warren9c79abe2012-12-11 13:34:13 +0000348}
349
350static void remove_cpu_io_clamps(void)
351{
Tom Warren9c79abe2012-12-11 13:34:13 +0000352 u32 reg;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700353 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000354
355 /* Remove the clamps on the CPU I/O signals */
Thierry Redingce7eb162019-04-15 11:32:25 +0200356 reg = tegra_pmc_readl(offsetof(struct pmc_ctlr, pmc_remove_clamping));
Tom Warren9c79abe2012-12-11 13:34:13 +0000357 reg |= CPU_CLMP;
Thierry Redingce7eb162019-04-15 11:32:25 +0200358 tegra_pmc_writel(reg, offsetof(struct pmc_ctlr, pmc_remove_clamping));
Tom Warren9c79abe2012-12-11 13:34:13 +0000359
360 /* Give I/O signals time to stabilize */
361 udelay(IO_STABILIZATION_DELAY);
362}
363
364void powerup_cpu(void)
365{
Tom Warren9c79abe2012-12-11 13:34:13 +0000366 u32 reg;
367 int timeout = IO_STABILIZATION_DELAY;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700368 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000369
370 if (!is_cpu_powered()) {
371 /* Toggle the CPU power state (OFF -> ON) */
Thierry Redingce7eb162019-04-15 11:32:25 +0200372 reg = tegra_pmc_readl(offsetof(struct pmc_ctlr,
373 pmc_pwrgate_toggle));
Tom Warren9c79abe2012-12-11 13:34:13 +0000374 reg &= PARTID_CP;
375 reg |= START_CP;
Thierry Redingce7eb162019-04-15 11:32:25 +0200376 tegra_pmc_writel(reg,
377 offsetof(struct pmc_ctlr,
378 pmc_pwrgate_toggle));
Tom Warren9c79abe2012-12-11 13:34:13 +0000379
380 /* Wait for the power to come up */
381 while (!is_cpu_powered()) {
382 if (timeout-- == 0)
383 printf("CPU failed to power up!\n");
384 else
385 udelay(10);
386 }
387
388 /*
389 * Remove the I/O clamps from CPU power partition.
390 * Recommended only on a Warm boot, if the CPU partition gets
391 * power gated. Shouldn't cause any harm when called after a
392 * cold boot according to HW, probably just redundant.
393 */
394 remove_cpu_io_clamps();
395 }
396}
397
398void reset_A9_cpu(int reset)
399{
400 /*
401 * NOTE: Regardless of whether the request is to hold the CPU in reset
402 * or take it out of reset, every processor in the CPU complex
403 * except the master (CPU 0) will be held in reset because the
404 * AVP only talks to the master. The AVP does not know that there
405 * are multiple processors in the CPU complex.
406 */
407 int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
408 int num_cpus = get_num_cpus();
409 int cpu;
410
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700411 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000412 /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
413 for (cpu = 1; cpu < num_cpus; cpu++)
414 reset_cmplx_set_enable(cpu, mask, 1);
415 reset_cmplx_set_enable(0, mask, reset);
416
417 /* Enable/Disable master CPU reset */
418 reset_set_enable(PERIPH_ID_CPU, reset);
419}
420
421void clock_enable_coresight(int enable)
422{
Tom Warrend034d1b2013-01-28 13:32:08 +0000423 u32 rst, src = 2;
Tom Warren9c79abe2012-12-11 13:34:13 +0000424
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700425 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000426 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
427 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
428
429 if (enable) {
430 /*
Tom Warren8b817112013-04-10 10:32:32 -0700431 * Put CoreSight on PLLP_OUT0 and divide it down as per
Tom Warren9588ab72014-01-24 12:46:14 -0700432 * PLLP base frequency based on SoC type (T20/T30+).
Tom Warren8b817112013-04-10 10:32:32 -0700433 * Clock divider request would setup CSITE clock as 144MHz
434 * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
Tom Warren9c79abe2012-12-11 13:34:13 +0000435 */
Stephen Warren62dd54f2014-01-24 12:46:10 -0700436 src = CLK_DIVIDER(NVBL_PLLP_KHZ, CSITE_KHZ);
Tom Warren9c79abe2012-12-11 13:34:13 +0000437 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
438
439 /* Unlock the CPU CoreSight interfaces */
440 rst = CORESIGHT_UNLOCK;
441 writel(rst, CSITE_CPU_DBG0_LAR);
442 writel(rst, CSITE_CPU_DBG1_LAR);
Tom Warrend034d1b2013-01-28 13:32:08 +0000443 if (get_num_cpus() == 4) {
444 writel(rst, CSITE_CPU_DBG2_LAR);
445 writel(rst, CSITE_CPU_DBG3_LAR);
446 }
Tom Warren9c79abe2012-12-11 13:34:13 +0000447 }
448}
449
450void halt_avp(void)
451{
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700452 debug("%s entry\n", __func__);
453
Tom Warren9c79abe2012-12-11 13:34:13 +0000454 for (;;) {
Stephen Warrenb07badd2014-02-03 14:03:27 -0700455 writel(HALT_COP_EVENT_JTAG | (FLOW_MODE_STOP << 29),
456 FLOW_CTLR_HALT_COP_EVENTS);
Tom Warren9c79abe2012-12-11 13:34:13 +0000457 }
458}