blob: d62bb9e370e0d4007e28c5ce1063182388b1090c [file] [log] [blame]
Tom Warren9c79abe2012-12-11 13:34:13 +00001/*
Jimmy Zhang2a544db2014-01-24 10:37:36 -07002 * Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved.
Tom Warren9c79abe2012-12-11 13:34:13 +00003 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <common.h>
18#include <asm/io.h>
19#include <asm/arch/clock.h>
20#include <asm/arch/gp_padctrl.h>
21#include <asm/arch/pinmux.h>
22#include <asm/arch/tegra.h>
23#include <asm/arch-tegra/clk_rst.h>
24#include <asm/arch-tegra/pmc.h>
25#include <asm/arch-tegra/scu.h>
26#include "cpu.h"
27
Tom Warrend034d1b2013-01-28 13:32:08 +000028int get_num_cpus(void)
Tom Warren9c79abe2012-12-11 13:34:13 +000029{
Tom Warrend034d1b2013-01-28 13:32:08 +000030 struct apb_misc_gp_ctlr *gp;
31 uint rev;
Tom Warren9c79abe2012-12-11 13:34:13 +000032
Tom Warrend034d1b2013-01-28 13:32:08 +000033 gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
34 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
Tom Warren9c79abe2012-12-11 13:34:13 +000035
Tom Warrend034d1b2013-01-28 13:32:08 +000036 switch (rev) {
37 case CHIPID_TEGRA20:
38 return 2;
39 break;
40 case CHIPID_TEGRA30:
41 case CHIPID_TEGRA114:
42 default:
43 return 4;
44 break;
45 }
Tom Warren9c79abe2012-12-11 13:34:13 +000046}
47
48/*
49 * Timing tables for each SOC for all four oscillator options.
50 */
51struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = {
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020052 /*
53 * T20: 1 GHz
54 *
55 * Register Field Bits Width
56 * ------------------------------
57 * PLLX_BASE p 22:20 3
58 * PLLX_BASE n 17: 8 10
59 * PLLX_BASE m 4: 0 5
60 * PLLX_MISC cpcon 11: 8 4
61 */
62 {
63 { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
64 { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
65 { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
66 { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000067 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020068 /*
69 * T25: 1.2 GHz
70 *
71 * Register Field Bits Width
72 * ------------------------------
73 * PLLX_BASE p 22:20 3
74 * PLLX_BASE n 17: 8 10
75 * PLLX_BASE m 4: 0 5
76 * PLLX_MISC cpcon 11: 8 4
77 */
78 {
79 { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
80 { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
81 { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
82 { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000083 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +020084 /*
85 * T30: 1.4 GHz
86 *
87 * Register Field Bits Width
88 * ------------------------------
89 * PLLX_BASE p 22:20 3
90 * PLLX_BASE n 17: 8 10
91 * PLLX_BASE m 4: 0 5
92 * PLLX_MISC cpcon 11: 8 4
93 */
94 {
95 { .n = 862, .m = 8, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */
96 { .n = 583, .m = 8, .p = 0, .cpcon = 4 }, /* OSC: 19.2 MHz */
97 { .n = 700, .m = 6, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */
98 { .n = 700, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */
Tom Warren9c79abe2012-12-11 13:34:13 +000099 },
Jimmy Zhang08ceb1e2013-09-23 22:07:49 +0200100 /*
101 * T114: 700 MHz
102 *
103 * Register Field Bits Width
104 * ------------------------------
105 * PLLX_BASE p 23:20 4
106 * PLLX_BASE n 15: 8 8
107 * PLLX_BASE m 7: 0 8
108 */
109 {
110 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
111 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
112 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
113 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
Tom Warrend034d1b2013-01-28 13:32:08 +0000114 },
Tom Warren9c79abe2012-12-11 13:34:13 +0000115};
116
Tom Warren9c79abe2012-12-11 13:34:13 +0000117int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
118 u32 divp, u32 cpcon)
119{
Thierry Reding87baa2a2013-10-01 17:04:45 +0200120 int chip = tegra_get_chip();
Tom Warren9c79abe2012-12-11 13:34:13 +0000121 u32 reg;
122
123 /* If PLLX is already enabled, just return */
124 if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
125 debug("pllx_set_rate: PLLX already enabled, returning\n");
126 return 0;
127 }
128
129 debug(" pllx_set_rate entry\n");
130
131 /* Set BYPASS, m, n and p to PLLX_BASE */
132 reg = PLL_BYPASS_MASK | (divm << PLL_DIVM_SHIFT);
133 reg |= ((divn << PLL_DIVN_SHIFT) | (divp << PLL_DIVP_SHIFT));
134 writel(reg, &pll->pll_base);
135
136 /* Set cpcon to PLLX_MISC */
Thierry Reding87baa2a2013-10-01 17:04:45 +0200137 if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30)
138 reg = (cpcon << PLL_CPCON_SHIFT);
139 else
140 reg = 0;
Tom Warren9c79abe2012-12-11 13:34:13 +0000141
142 /* Set dccon to PLLX_MISC if freq > 600MHz */
143 if (divn > 600)
144 reg |= (1 << PLL_DCCON_SHIFT);
145 writel(reg, &pll->pll_misc);
146
Tom Warren9c79abe2012-12-11 13:34:13 +0000147 /* Disable BYPASS */
Stephen Warren54b76702014-01-24 12:46:09 -0700148 reg = readl(&pll->pll_base);
Tom Warren9c79abe2012-12-11 13:34:13 +0000149 reg &= ~PLL_BYPASS_MASK;
150 writel(reg, &pll->pll_base);
Stephen Warren54b76702014-01-24 12:46:09 -0700151 debug("pllx_set_rate: base = 0x%08X\n", reg);
Tom Warren9c79abe2012-12-11 13:34:13 +0000152
153 /* Set lock_enable to PLLX_MISC */
154 reg = readl(&pll->pll_misc);
155 reg |= PLL_LOCK_ENABLE_MASK;
156 writel(reg, &pll->pll_misc);
Stephen Warren54b76702014-01-24 12:46:09 -0700157 debug("pllx_set_rate: misc = 0x%08X\n", reg);
158
159 /* Enable PLLX last, once it's all configured */
160 reg = readl(&pll->pll_base);
161 reg |= PLL_ENABLE_MASK;
162 writel(reg, &pll->pll_base);
163 debug("pllx_set_rate: base final = 0x%08X\n", reg);
Tom Warren9c79abe2012-12-11 13:34:13 +0000164
165 return 0;
166}
167
168void init_pllx(void)
169{
170 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
171 struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
Tom Warren8b817112013-04-10 10:32:32 -0700172 int soc_type, sku_info, chip_sku;
Tom Warren9c79abe2012-12-11 13:34:13 +0000173 enum clock_osc_freq osc;
174 struct clk_pll_table *sel;
175
176 debug("init_pllx entry\n");
177
Tom Warren8b817112013-04-10 10:32:32 -0700178 /* get SOC (chip) type */
179 soc_type = tegra_get_chip();
180 debug(" init_pllx: SoC = 0x%02X\n", soc_type);
181
182 /* get SKU info */
183 sku_info = tegra_get_sku_info();
184 debug(" init_pllx: SKU info byte = 0x%02X\n", sku_info);
185
186 /* get chip SKU, combo of the above info */
187 chip_sku = tegra_get_chip_sku();
188 debug(" init_pllx: Chip SKU = %d\n", chip_sku);
Tom Warren9c79abe2012-12-11 13:34:13 +0000189
190 /* get osc freq */
191 osc = clock_get_osc_freq();
Tom Warren8b817112013-04-10 10:32:32 -0700192 debug(" init_pllx: osc = %d\n", osc);
Tom Warren9c79abe2012-12-11 13:34:13 +0000193
194 /* set pllx */
Tom Warren8b817112013-04-10 10:32:32 -0700195 sel = &tegra_pll_x_table[chip_sku][osc];
Tom Warren9c79abe2012-12-11 13:34:13 +0000196 pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
Tom Warren9c79abe2012-12-11 13:34:13 +0000197}
198
199void enable_cpu_clock(int enable)
200{
201 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
202 u32 clk;
203
204 /*
205 * NOTE:
206 * Regardless of whether the request is to enable or disable the CPU
207 * clock, every processor in the CPU complex except the master (CPU 0)
208 * will have it's clock stopped because the AVP only talks to the
209 * master.
210 */
211
212 if (enable) {
213 /* Initialize PLLX */
214 init_pllx();
215
216 /* Wait until all clocks are stable */
217 udelay(PLL_STABILIZATION_DELAY);
218
219 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
220 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
221 }
222
223 /*
224 * Read the register containing the individual CPU clock enables and
225 * always stop the clocks to CPUs > 0.
226 */
227 clk = readl(&clkrst->crc_clk_cpu_cmplx);
228 clk |= 1 << CPU1_CLK_STP_SHIFT;
Tom Warrend034d1b2013-01-28 13:32:08 +0000229 if (get_num_cpus() == 4)
230 clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
231
Tom Warren9c79abe2012-12-11 13:34:13 +0000232 /* Stop/Unstop the CPU clock */
233 clk &= ~CPU0_CLK_STP_MASK;
234 clk |= !enable << CPU0_CLK_STP_SHIFT;
235 writel(clk, &clkrst->crc_clk_cpu_cmplx);
236
237 clock_enable(PERIPH_ID_CPU);
238}
239
240static int is_cpu_powered(void)
241{
242 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
243
244 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
245}
246
247static void remove_cpu_io_clamps(void)
248{
249 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
250 u32 reg;
251
252 /* Remove the clamps on the CPU I/O signals */
253 reg = readl(&pmc->pmc_remove_clamping);
254 reg |= CPU_CLMP;
255 writel(reg, &pmc->pmc_remove_clamping);
256
257 /* Give I/O signals time to stabilize */
258 udelay(IO_STABILIZATION_DELAY);
259}
260
261void powerup_cpu(void)
262{
263 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
264 u32 reg;
265 int timeout = IO_STABILIZATION_DELAY;
266
267 if (!is_cpu_powered()) {
268 /* Toggle the CPU power state (OFF -> ON) */
269 reg = readl(&pmc->pmc_pwrgate_toggle);
270 reg &= PARTID_CP;
271 reg |= START_CP;
272 writel(reg, &pmc->pmc_pwrgate_toggle);
273
274 /* Wait for the power to come up */
275 while (!is_cpu_powered()) {
276 if (timeout-- == 0)
277 printf("CPU failed to power up!\n");
278 else
279 udelay(10);
280 }
281
282 /*
283 * Remove the I/O clamps from CPU power partition.
284 * Recommended only on a Warm boot, if the CPU partition gets
285 * power gated. Shouldn't cause any harm when called after a
286 * cold boot according to HW, probably just redundant.
287 */
288 remove_cpu_io_clamps();
289 }
290}
291
292void reset_A9_cpu(int reset)
293{
294 /*
295 * NOTE: Regardless of whether the request is to hold the CPU in reset
296 * or take it out of reset, every processor in the CPU complex
297 * except the master (CPU 0) will be held in reset because the
298 * AVP only talks to the master. The AVP does not know that there
299 * are multiple processors in the CPU complex.
300 */
301 int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
302 int num_cpus = get_num_cpus();
303 int cpu;
304
305 debug("reset_a9_cpu entry\n");
306 /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
307 for (cpu = 1; cpu < num_cpus; cpu++)
308 reset_cmplx_set_enable(cpu, mask, 1);
309 reset_cmplx_set_enable(0, mask, reset);
310
311 /* Enable/Disable master CPU reset */
312 reset_set_enable(PERIPH_ID_CPU, reset);
313}
314
315void clock_enable_coresight(int enable)
316{
Tom Warrend034d1b2013-01-28 13:32:08 +0000317 u32 rst, src = 2;
Tom Warren9c79abe2012-12-11 13:34:13 +0000318
319 debug("clock_enable_coresight entry\n");
320 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
321 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
322
323 if (enable) {
324 /*
Tom Warren8b817112013-04-10 10:32:32 -0700325 * Put CoreSight on PLLP_OUT0 and divide it down as per
326 * PLLP base frequency based on SoC type (T20/T30/T114).
327 * Clock divider request would setup CSITE clock as 144MHz
328 * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
Tom Warren9c79abe2012-12-11 13:34:13 +0000329 */
Stephen Warren62dd54f2014-01-24 12:46:10 -0700330 src = CLK_DIVIDER(NVBL_PLLP_KHZ, CSITE_KHZ);
Tom Warren9c79abe2012-12-11 13:34:13 +0000331 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
332
333 /* Unlock the CPU CoreSight interfaces */
334 rst = CORESIGHT_UNLOCK;
335 writel(rst, CSITE_CPU_DBG0_LAR);
336 writel(rst, CSITE_CPU_DBG1_LAR);
Tom Warrend034d1b2013-01-28 13:32:08 +0000337 if (get_num_cpus() == 4) {
338 writel(rst, CSITE_CPU_DBG2_LAR);
339 writel(rst, CSITE_CPU_DBG3_LAR);
340 }
Tom Warren9c79abe2012-12-11 13:34:13 +0000341 }
342}
343
344void halt_avp(void)
345{
346 for (;;) {
347 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
348 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
349 FLOW_CTLR_HALT_COP_EVENTS);
350 }
351}