blob: 5f2a5917102406ddccf887460786f10d76190cfe [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
Simon Glass0f2af882020-05-10 11:40:05 -06006#include <log.h>
Tom Warren9c79abe2012-12-11 13:34:13 +00007#include <asm/io.h>
8#include <asm/arch/clock.h>
9#include <asm/arch/gp_padctrl.h>
10#include <asm/arch/pinmux.h>
11#include <asm/arch/tegra.h>
12#include <asm/arch-tegra/clk_rst.h>
13#include <asm/arch-tegra/pmc.h>
14#include <asm/arch-tegra/scu.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Tom Warren9c79abe2012-12-11 13:34:13 +000016#include "cpu.h"
17
Tom Warrend034d1b2013-01-28 13:32:08 +000018int get_num_cpus(void)
Tom Warren9c79abe2012-12-11 13:34:13 +000019{
Tom Warrend034d1b2013-01-28 13:32:08 +000020 struct apb_misc_gp_ctlr *gp;
21 uint rev;
Tom Warrenab0cc6b2015-03-04 16:36:00 -070022 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +000023
Tom Warrend034d1b2013-01-28 13:32:08 +000024 gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
25 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
Tom Warren9c79abe2012-12-11 13:34:13 +000026
Tom Warrend034d1b2013-01-28 13:32:08 +000027 switch (rev) {
28 case CHIPID_TEGRA20:
29 return 2;
30 break;
31 case CHIPID_TEGRA30:
32 case CHIPID_TEGRA114:
Tom Warrenab0cc6b2015-03-04 16:36:00 -070033 case CHIPID_TEGRA124:
34 case CHIPID_TEGRA210:
Tom Warrend034d1b2013-01-28 13:32:08 +000035 default:
36 return 4;
37 break;
38 }
Tom Warren9c79abe2012-12-11 13:34:13 +000039}
40
41/*
42 * Timing tables for each SOC for all four oscillator options.
43 */
44struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = {
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020045 /*
46 * T20: 1 GHz
47 *
48 * Register Field Bits Width
49 * ------------------------------
50 * PLLX_BASE p 22:20 3
51 * PLLX_BASE n 17: 8 10
52 * PLLX_BASE m 4: 0 5
53 * PLLX_MISC cpcon 11: 8 4
54 */
55 {
56 { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020057 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
58 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
59 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020060 { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020061 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
62 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
63 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020064 { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020065 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
66 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
67 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020068 { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000069 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020070 /*
71 * T25: 1.2 GHz
72 *
73 * Register Field Bits Width
74 * ------------------------------
75 * PLLX_BASE p 22:20 3
76 * PLLX_BASE n 17: 8 10
77 * PLLX_BASE m 4: 0 5
78 * PLLX_MISC cpcon 11: 8 4
79 */
80 {
81 { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020082 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
83 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
84 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020085 { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020086 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
87 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
88 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020089 { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +020090 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
91 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
92 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020093 { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000094 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020095 /*
Stephen Warrenecc75382014-05-08 09:33:45 -060096 * T30: 600 MHz
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020097 *
98 * Register Field Bits Width
99 * ------------------------------
100 * PLLX_BASE p 22:20 3
101 * PLLX_BASE n 17: 8 10
102 * PLLX_BASE m 4: 0 5
103 * PLLX_MISC cpcon 11: 8 4
104 */
105 {
Stephen Warrenecc75382014-05-08 09:33:45 -0600106 { .n = 600, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200107 { .n = 600, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 16.8 MHz */
108 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
109 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Stephen Warrenecc75382014-05-08 09:33:45 -0600110 { .n = 500, .m = 16, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200111 { .n = 500, .m = 16, .p = 0, .cpcon = 8 }, /* OSC: 38.4 MHz */
112 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
113 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Stephen Warrenecc75382014-05-08 09:33:45 -0600114 { .n = 600, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200115 { .n = 600, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 48.0 MHz */
116 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
117 { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* N/A */
Stephen Warrenecc75382014-05-08 09:33:45 -0600118 { .n = 600, .m = 26, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +0000119 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200120 /*
121 * T114: 700 MHz
122 *
123 * Register Field Bits Width
124 * ------------------------------
125 * PLLX_BASE p 23:20 4
126 * PLLX_BASE n 15: 8 8
127 * PLLX_BASE m 7: 0 8
128 */
129 {
130 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200131 { .n = 108, .m = 1, .p = 1 }, /* OSC: 16.8 MHz */
132 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
133 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200134 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200135 { .n = 73, .m = 1, .p = 1 }, /* OSC: 38.4 MHz */
136 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
137 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200138 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200139 { .n = 116, .m = 1, .p = 1 }, /* OSC: 48.0 MHz */
140 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
141 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200142 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
Tom Warrend034d1b2013-01-28 13:32:08 +0000143 },
Tom Warren9588ab72014-01-24 12:46:14 -0700144
145 /*
146 * T124: 700 MHz
147 *
148 * Register Field Bits Width
149 * ------------------------------
150 * PLLX_BASE p 23:20 4
151 * PLLX_BASE n 15: 8 8
152 * PLLX_BASE m 7: 0 8
153 */
154 {
155 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200156 { .n = 108, .m = 1, .p = 1 }, /* OSC: 16.8 MHz */
157 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
158 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Tom Warren9588ab72014-01-24 12:46:14 -0700159 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200160 { .n = 73, .m = 1, .p = 1 }, /* OSC: 38.4 MHz */
161 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
162 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Tom Warren9588ab72014-01-24 12:46:14 -0700163 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200164 { .n = 116, .m = 1, .p = 1 }, /* OSC: 48.0 MHz */
165 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
166 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
Tom Warren9588ab72014-01-24 12:46:14 -0700167 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
168 },
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700169
170 /*
171 * T210: 700 MHz
172 *
173 * Register Field Bits Width
174 * ------------------------------
175 * PLLX_BASE p 24:20 5
176 * PLLX_BASE n 15: 8 8
177 * PLLX_BASE m 7: 0 8
178 */
179 {
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200180 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz = 702 MHz */
181 { .n = 108, .m = 1, .p = 1 }, /* OSC: 16.0 MHz = 702 MHz */
182 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
183 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
184 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz = 700.8 MHz */
Tom Warren27bce712015-06-22 13:03:44 -0700185 { .n = 36, .m = 1, .p = 1 }, /* OSC: 38.4 MHz = 691.2 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200186 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
187 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
188 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz = 696 MHz */
Tom Warren27bce712015-06-22 13:03:44 -0700189 { .n = 58, .m = 2, .p = 1 }, /* OSC: 48.0 MHz = 696 MHz */
Svyatoslav Ryhel7f4ab332023-02-01 10:53:01 +0200190 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
191 { .n = 0, .m = 0, .p = 0 }, /* (N/A) */
192 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz = 702 MHz */
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700193 },
Tom Warren9c79abe2012-12-11 13:34:13 +0000194};
195
Tom Warren9588ab72014-01-24 12:46:14 -0700196static inline void pllx_set_iddq(void)
197{
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700198#if defined(CONFIG_TEGRA124) || defined(CONFIG_TEGRA210)
Tom Warren9588ab72014-01-24 12:46:14 -0700199 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
200 u32 reg;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700201 debug("%s entry\n", __func__);
Tom Warren9588ab72014-01-24 12:46:14 -0700202
203 /* Disable IDDQ */
204 reg = readl(&clkrst->crc_pllx_misc3);
205 reg &= ~PLLX_IDDQ_MASK;
206 writel(reg, &clkrst->crc_pllx_misc3);
207 udelay(2);
208 debug("%s: IDDQ: PLLX IDDQ = 0x%08X\n", __func__,
209 readl(&clkrst->crc_pllx_misc3));
210#endif
211}
212
Tom Warren9c79abe2012-12-11 13:34:13 +0000213int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
214 u32 divp, u32 cpcon)
215{
Tom Warrena8480ef2015-06-25 09:50:44 -0700216 struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
Thierry Reding87baa2a2013-10-01 17:04:45 +0200217 int chip = tegra_get_chip();
Tom Warren9c79abe2012-12-11 13:34:13 +0000218 u32 reg;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700219 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000220
221 /* If PLLX is already enabled, just return */
222 if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700223 debug("%s: PLLX already enabled, returning\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000224 return 0;
225 }
226
Tom Warren9588ab72014-01-24 12:46:14 -0700227 pllx_set_iddq();
228
Tom Warren9c79abe2012-12-11 13:34:13 +0000229 /* Set BYPASS, m, n and p to PLLX_BASE */
Tom Warrena8480ef2015-06-25 09:50:44 -0700230 reg = PLL_BYPASS_MASK | (divm << pllinfo->m_shift);
231 reg |= (divn << pllinfo->n_shift) | (divp << pllinfo->p_shift);
Tom Warren9c79abe2012-12-11 13:34:13 +0000232 writel(reg, &pll->pll_base);
233
234 /* Set cpcon to PLLX_MISC */
Thierry Reding87baa2a2013-10-01 17:04:45 +0200235 if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30)
Tom Warrena8480ef2015-06-25 09:50:44 -0700236 reg = (cpcon << pllinfo->kcp_shift);
Thierry Reding87baa2a2013-10-01 17:04:45 +0200237 else
238 reg = 0;
Tom Warren9c79abe2012-12-11 13:34:13 +0000239
Tom Warrena8480ef2015-06-25 09:50:44 -0700240 /*
241 * TODO(twarren@nvidia.com) Check which SoCs use DCCON
242 * and add to pllinfo table if needed!
243 */
244 /* Set dccon to PLLX_MISC if freq > 600MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +0000245 if (divn > 600)
246 reg |= (1 << PLL_DCCON_SHIFT);
247 writel(reg, &pll->pll_misc);
248
Tom Warren9c79abe2012-12-11 13:34:13 +0000249 /* Disable BYPASS */
Stephen Warren54b76702014-01-24 12:46:09 -0700250 reg = readl(&pll->pll_base);
Tom Warren9c79abe2012-12-11 13:34:13 +0000251 reg &= ~PLL_BYPASS_MASK;
252 writel(reg, &pll->pll_base);
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700253 debug("%s: base = 0x%08X\n", __func__, reg);
Tom Warren9c79abe2012-12-11 13:34:13 +0000254
Tom Warrena8480ef2015-06-25 09:50:44 -0700255 /* Set lock_enable to PLLX_MISC if lock_ena is valid (i.e. 0-31) */
Tom Warren9c79abe2012-12-11 13:34:13 +0000256 reg = readl(&pll->pll_misc);
Tom Warrena8480ef2015-06-25 09:50:44 -0700257 if (pllinfo->lock_ena < 32)
258 reg |= (1 << pllinfo->lock_ena);
Tom Warren9c79abe2012-12-11 13:34:13 +0000259 writel(reg, &pll->pll_misc);
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700260 debug("%s: misc = 0x%08X\n", __func__, reg);
Stephen Warren54b76702014-01-24 12:46:09 -0700261
262 /* Enable PLLX last, once it's all configured */
263 reg = readl(&pll->pll_base);
264 reg |= PLL_ENABLE_MASK;
265 writel(reg, &pll->pll_base);
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700266 debug("%s: base final = 0x%08X\n", __func__, reg);
Tom Warren9c79abe2012-12-11 13:34:13 +0000267
268 return 0;
269}
270
271void init_pllx(void)
272{
273 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
274 struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
Tom Warren8b817112013-04-10 10:32:32 -0700275 int soc_type, sku_info, chip_sku;
Tom Warren9c79abe2012-12-11 13:34:13 +0000276 enum clock_osc_freq osc;
277 struct clk_pll_table *sel;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700278 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000279
Tom Warren8b817112013-04-10 10:32:32 -0700280 /* get SOC (chip) type */
281 soc_type = tegra_get_chip();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700282 debug("%s: SoC = 0x%02X\n", __func__, soc_type);
Tom Warren8b817112013-04-10 10:32:32 -0700283
284 /* get SKU info */
285 sku_info = tegra_get_sku_info();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700286 debug("%s: SKU info byte = 0x%02X\n", __func__, sku_info);
Tom Warren8b817112013-04-10 10:32:32 -0700287
288 /* get chip SKU, combo of the above info */
289 chip_sku = tegra_get_chip_sku();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700290 debug("%s: Chip SKU = %d\n", __func__, chip_sku);
Tom Warren9c79abe2012-12-11 13:34:13 +0000291
292 /* get osc freq */
293 osc = clock_get_osc_freq();
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700294 debug("%s: osc = %d\n", __func__, osc);
Tom Warren9c79abe2012-12-11 13:34:13 +0000295
296 /* set pllx */
Tom Warren8b817112013-04-10 10:32:32 -0700297 sel = &tegra_pll_x_table[chip_sku][osc];
Tom Warren9c79abe2012-12-11 13:34:13 +0000298 pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
Tom Warren9c79abe2012-12-11 13:34:13 +0000299}
300
301void enable_cpu_clock(int enable)
302{
303 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
304 u32 clk;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700305 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000306
307 /*
308 * NOTE:
309 * Regardless of whether the request is to enable or disable the CPU
310 * clock, every processor in the CPU complex except the master (CPU 0)
311 * will have it's clock stopped because the AVP only talks to the
312 * master.
313 */
314
315 if (enable) {
316 /* Initialize PLLX */
317 init_pllx();
318
319 /* Wait until all clocks are stable */
320 udelay(PLL_STABILIZATION_DELAY);
321
322 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
323 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
324 }
325
326 /*
327 * Read the register containing the individual CPU clock enables and
328 * always stop the clocks to CPUs > 0.
329 */
330 clk = readl(&clkrst->crc_clk_cpu_cmplx);
331 clk |= 1 << CPU1_CLK_STP_SHIFT;
Tom Warrend034d1b2013-01-28 13:32:08 +0000332 if (get_num_cpus() == 4)
333 clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
334
Tom Warren9c79abe2012-12-11 13:34:13 +0000335 /* Stop/Unstop the CPU clock */
336 clk &= ~CPU0_CLK_STP_MASK;
337 clk |= !enable << CPU0_CLK_STP_SHIFT;
338 writel(clk, &clkrst->crc_clk_cpu_cmplx);
339
340 clock_enable(PERIPH_ID_CPU);
341}
342
343static int is_cpu_powered(void)
344{
Thierry Redingce7eb162019-04-15 11:32:25 +0200345 return (tegra_pmc_readl(offsetof(struct pmc_ctlr,
346 pmc_pwrgate_status)) & CPU_PWRED) ? 1 : 0;
Tom Warren9c79abe2012-12-11 13:34:13 +0000347}
348
349static void remove_cpu_io_clamps(void)
350{
Tom Warren9c79abe2012-12-11 13:34:13 +0000351 u32 reg;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700352 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000353
354 /* Remove the clamps on the CPU I/O signals */
Thierry Redingce7eb162019-04-15 11:32:25 +0200355 reg = tegra_pmc_readl(offsetof(struct pmc_ctlr, pmc_remove_clamping));
Tom Warren9c79abe2012-12-11 13:34:13 +0000356 reg |= CPU_CLMP;
Thierry Redingce7eb162019-04-15 11:32:25 +0200357 tegra_pmc_writel(reg, offsetof(struct pmc_ctlr, pmc_remove_clamping));
Tom Warren9c79abe2012-12-11 13:34:13 +0000358
359 /* Give I/O signals time to stabilize */
360 udelay(IO_STABILIZATION_DELAY);
361}
362
363void powerup_cpu(void)
364{
Tom Warren9c79abe2012-12-11 13:34:13 +0000365 u32 reg;
366 int timeout = IO_STABILIZATION_DELAY;
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700367 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000368
369 if (!is_cpu_powered()) {
370 /* Toggle the CPU power state (OFF -> ON) */
Thierry Redingce7eb162019-04-15 11:32:25 +0200371 reg = tegra_pmc_readl(offsetof(struct pmc_ctlr,
372 pmc_pwrgate_toggle));
Tom Warren9c79abe2012-12-11 13:34:13 +0000373 reg &= PARTID_CP;
374 reg |= START_CP;
Thierry Redingce7eb162019-04-15 11:32:25 +0200375 tegra_pmc_writel(reg,
376 offsetof(struct pmc_ctlr,
377 pmc_pwrgate_toggle));
Tom Warren9c79abe2012-12-11 13:34:13 +0000378
379 /* Wait for the power to come up */
380 while (!is_cpu_powered()) {
381 if (timeout-- == 0)
382 printf("CPU failed to power up!\n");
383 else
384 udelay(10);
385 }
386
387 /*
388 * Remove the I/O clamps from CPU power partition.
389 * Recommended only on a Warm boot, if the CPU partition gets
390 * power gated. Shouldn't cause any harm when called after a
391 * cold boot according to HW, probably just redundant.
392 */
393 remove_cpu_io_clamps();
394 }
395}
396
397void reset_A9_cpu(int reset)
398{
399 /*
400 * NOTE: Regardless of whether the request is to hold the CPU in reset
401 * or take it out of reset, every processor in the CPU complex
402 * except the master (CPU 0) will be held in reset because the
403 * AVP only talks to the master. The AVP does not know that there
404 * are multiple processors in the CPU complex.
405 */
406 int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
407 int num_cpus = get_num_cpus();
408 int cpu;
409
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700410 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000411 /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
412 for (cpu = 1; cpu < num_cpus; cpu++)
413 reset_cmplx_set_enable(cpu, mask, 1);
414 reset_cmplx_set_enable(0, mask, reset);
415
416 /* Enable/Disable master CPU reset */
417 reset_set_enable(PERIPH_ID_CPU, reset);
418}
419
420void clock_enable_coresight(int enable)
421{
Tom Warrend034d1b2013-01-28 13:32:08 +0000422 u32 rst, src = 2;
Tom Warren9c79abe2012-12-11 13:34:13 +0000423
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700424 debug("%s entry\n", __func__);
Tom Warren9c79abe2012-12-11 13:34:13 +0000425 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
426 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
427
428 if (enable) {
429 /*
Tom Warren8b817112013-04-10 10:32:32 -0700430 * Put CoreSight on PLLP_OUT0 and divide it down as per
Tom Warren9588ab72014-01-24 12:46:14 -0700431 * PLLP base frequency based on SoC type (T20/T30+).
Tom Warren8b817112013-04-10 10:32:32 -0700432 * Clock divider request would setup CSITE clock as 144MHz
433 * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
Tom Warren9c79abe2012-12-11 13:34:13 +0000434 */
Stephen Warren62dd54f2014-01-24 12:46:10 -0700435 src = CLK_DIVIDER(NVBL_PLLP_KHZ, CSITE_KHZ);
Tom Warren9c79abe2012-12-11 13:34:13 +0000436 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
437
438 /* Unlock the CPU CoreSight interfaces */
439 rst = CORESIGHT_UNLOCK;
440 writel(rst, CSITE_CPU_DBG0_LAR);
441 writel(rst, CSITE_CPU_DBG1_LAR);
Tom Warrend034d1b2013-01-28 13:32:08 +0000442 if (get_num_cpus() == 4) {
443 writel(rst, CSITE_CPU_DBG2_LAR);
444 writel(rst, CSITE_CPU_DBG3_LAR);
445 }
Tom Warren9c79abe2012-12-11 13:34:13 +0000446 }
447}
448
449void halt_avp(void)
450{
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700451 debug("%s entry\n", __func__);
452
Tom Warren9c79abe2012-12-11 13:34:13 +0000453 for (;;) {
Stephen Warrenb07badd2014-02-03 14:03:27 -0700454 writel(HALT_COP_EVENT_JTAG | (FLOW_MODE_STOP << 29),
455 FLOW_CTLR_HALT_COP_EVENTS);
Tom Warren9c79abe2012-12-11 13:34:13 +0000456 }
457}