blob: e3832e23f347ead5292947a1c9ec2c9be33cc201 [file] [log] [blame]
Tom Warren112a1882011-04-14 12:18:06 +00001/*
2* (C) Copyright 2010-2011
3* NVIDIA Corporation <www.nvidia.com>
4*
5* See file CREDITS for list of people who contributed to this
6* project.
7*
8* This program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public License as
10* published by the Free Software Foundation; either version 2 of
11* the License, or (at your option) any later version.
12*
13* This program is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16* GNU General Public License for more details.
17*
18* You should have received a copy of the GNU General Public License
19* along with this program; if not, write to the Free Software
20* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21* MA 02111-1307 USA
22*/
23
24#include "ap20.h"
25#include <asm/io.h>
26#include <asm/arch/tegra2.h>
27#include <asm/arch/clk_rst.h>
Simon Glass16134fd2011-08-30 06:23:13 +000028#include <asm/arch/clock.h>
Tom Warren112a1882011-04-14 12:18:06 +000029#include <asm/arch/pmc.h>
30#include <asm/arch/pinmux.h>
31#include <asm/arch/scu.h>
32#include <common.h>
33
34u32 s_first_boot = 1;
35
Tom Warren30e80f62011-04-14 12:09:39 +000036void init_pllx(void)
37{
38 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Simon Glass16134fd2011-08-30 06:23:13 +000039 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_PLL_ID_XCPU];
Tom Warren30e80f62011-04-14 12:09:39 +000040 u32 reg;
41
42 /* If PLLX is already enabled, just return */
Simon Glass16134fd2011-08-30 06:23:13 +000043 reg = readl(&pll->pll_base);
Tom Warren30e80f62011-04-14 12:09:39 +000044 if (reg & PLL_ENABLE)
45 return;
46
47 /* Set PLLX_MISC */
48 reg = CPCON; /* CPCON[11:8] = 0001 */
Simon Glass16134fd2011-08-30 06:23:13 +000049 writel(reg, &pll->pll_misc);
Tom Warren30e80f62011-04-14 12:09:39 +000050
51 /* Use 12MHz clock here */
Simon Glass16134fd2011-08-30 06:23:13 +000052 reg = (PLL_BYPASS | PLL_DIVM_VALUE);
Tom Warren30e80f62011-04-14 12:09:39 +000053 reg |= (1000 << 8); /* DIVN = 0x3E8 */
Simon Glass16134fd2011-08-30 06:23:13 +000054 writel(reg, &pll->pll_base);
Tom Warren30e80f62011-04-14 12:09:39 +000055
56 reg |= PLL_ENABLE;
Simon Glass16134fd2011-08-30 06:23:13 +000057 writel(reg, &pll->pll_base);
Tom Warren30e80f62011-04-14 12:09:39 +000058
59 reg &= ~PLL_BYPASS;
Simon Glass16134fd2011-08-30 06:23:13 +000060 writel(reg, &pll->pll_base);
Tom Warren30e80f62011-04-14 12:09:39 +000061}
62
Tom Warren112a1882011-04-14 12:18:06 +000063static void enable_cpu_clock(int enable)
64{
65 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Simon Glass16134fd2011-08-30 06:23:13 +000066 u32 clk;
Tom Warren112a1882011-04-14 12:18:06 +000067
68 /*
69 * NOTE:
70 * Regardless of whether the request is to enable or disable the CPU
71 * clock, every processor in the CPU complex except the master (CPU 0)
72 * will have it's clock stopped because the AVP only talks to the
73 * master. The AVP does not know (nor does it need to know) that there
74 * are multiple processors in the CPU complex.
75 */
76
77 if (enable) {
Tom Warren30e80f62011-04-14 12:09:39 +000078 /* Initialize PLLX */
79 init_pllx();
80
Tom Warren112a1882011-04-14 12:18:06 +000081 /* Wait until all clocks are stable */
82 udelay(PLL_STABILIZATION_DELAY);
83
84 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
85 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
86 }
87
Tom Warren112a1882011-04-14 12:18:06 +000088 /*
89 * Read the register containing the individual CPU clock enables and
90 * always stop the clock to CPU 1.
91 */
92 clk = readl(&clkrst->crc_clk_cpu_cmplx);
93 clk |= CPU1_CLK_STP;
94
95 if (enable) {
96 /* Unstop the CPU clock */
97 clk &= ~CPU0_CLK_STP;
98 } else {
99 /* Stop the CPU clock */
100 clk |= CPU0_CLK_STP;
101 }
102
103 writel(clk, &clkrst->crc_clk_cpu_cmplx);
Simon Glass16134fd2011-08-30 06:23:13 +0000104
105 clock_enable(PERIPH_ID_CPU);
Tom Warren112a1882011-04-14 12:18:06 +0000106}
107
108static int is_cpu_powered(void)
109{
110 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
111
112 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
113}
114
115static void remove_cpu_io_clamps(void)
116{
117 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
118 u32 reg;
119
120 /* Remove the clamps on the CPU I/O signals */
121 reg = readl(&pmc->pmc_remove_clamping);
122 reg |= CPU_CLMP;
123 writel(reg, &pmc->pmc_remove_clamping);
124
125 /* Give I/O signals time to stabilize */
126 udelay(IO_STABILIZATION_DELAY);
127}
128
129static void powerup_cpu(void)
130{
131 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
132 u32 reg;
133 int timeout = IO_STABILIZATION_DELAY;
134
135 if (!is_cpu_powered()) {
136 /* Toggle the CPU power state (OFF -> ON) */
137 reg = readl(&pmc->pmc_pwrgate_toggle);
138 reg &= PARTID_CP;
139 reg |= START_CP;
140 writel(reg, &pmc->pmc_pwrgate_toggle);
141
142 /* Wait for the power to come up */
143 while (!is_cpu_powered()) {
144 if (timeout-- == 0)
145 printf("CPU failed to power up!\n");
146 else
147 udelay(10);
148 }
149
150 /*
151 * Remove the I/O clamps from CPU power partition.
152 * Recommended only on a Warm boot, if the CPU partition gets
153 * power gated. Shouldn't cause any harm when called after a
154 * cold boot according to HW, probably just redundant.
155 */
156 remove_cpu_io_clamps();
157 }
158}
159
160static void enable_cpu_power_rail(void)
161{
162 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
163 u32 reg;
164
165 reg = readl(&pmc->pmc_cntrl);
166 reg |= CPUPWRREQ_OE;
167 writel(reg, &pmc->pmc_cntrl);
168
169 /*
170 * The TI PMU65861C needs a 3.75ms delay between enabling
171 * the power rail and enabling the CPU clock. This delay
172 * between SM1EN and SM1 is for switching time + the ramp
173 * up of the voltage to the CPU (VDD_CPU from PMU).
174 */
175 udelay(3750);
176}
177
178static void reset_A9_cpu(int reset)
179{
180 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Simon Glass16134fd2011-08-30 06:23:13 +0000181 u32 cpu;
Tom Warren112a1882011-04-14 12:18:06 +0000182
183 /*
184 * NOTE: Regardless of whether the request is to hold the CPU in reset
185 * or take it out of reset, every processor in the CPU complex
186 * except the master (CPU 0) will be held in reset because the
187 * AVP only talks to the master. The AVP does not know that there
188 * are multiple processors in the CPU complex.
189 */
190
191 /* Hold CPU 1 in reset */
192 cpu = SET_DBGRESET1 | SET_DERESET1 | SET_CPURESET1;
193 writel(cpu, &clkrst->crc_cpu_cmplx_set);
194
Tom Warren112a1882011-04-14 12:18:06 +0000195 if (reset) {
196 /* Now place CPU0 into reset */
197 cpu |= SET_DBGRESET0 | SET_DERESET0 | SET_CPURESET0;
198 writel(cpu, &clkrst->crc_cpu_cmplx_set);
Tom Warren112a1882011-04-14 12:18:06 +0000199 } else {
200 /* Take CPU0 out of reset */
201 cpu = CLR_DBGRESET0 | CLR_DERESET0 | CLR_CPURESET0;
202 writel(cpu, &clkrst->crc_cpu_cmplx_clr);
Tom Warren112a1882011-04-14 12:18:06 +0000203 }
204
Simon Glass16134fd2011-08-30 06:23:13 +0000205 /* Enable/Disable master CPU reset */
206 reset_set_enable(PERIPH_ID_CPU, reset);
Tom Warren112a1882011-04-14 12:18:06 +0000207}
208
209static void clock_enable_coresight(int enable)
210{
211 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Simon Glass16134fd2011-08-30 06:23:13 +0000212 u32 rst, src;
Tom Warren112a1882011-04-14 12:18:06 +0000213
Simon Glass16134fd2011-08-30 06:23:13 +0000214 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
215 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
Tom Warren112a1882011-04-14 12:18:06 +0000216
217 if (enable) {
218 /*
219 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
220 * 1.5, giving an effective frequency of 144MHz.
221 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
222 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
223 */
224 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
225 writel(src, &clkrst->crc_clk_src_csite);
226
227 /* Unlock the CPU CoreSight interfaces */
228 rst = 0xC5ACCE55;
229 writel(rst, CSITE_CPU_DBG0_LAR);
230 writel(rst, CSITE_CPU_DBG1_LAR);
231 }
232}
233
234void start_cpu(u32 reset_vector)
235{
236 /* Enable VDD_CPU */
237 enable_cpu_power_rail();
238
239 /* Hold the CPUs in reset */
240 reset_A9_cpu(1);
241
242 /* Disable the CPU clock */
243 enable_cpu_clock(0);
244
245 /* Enable CoreSight */
246 clock_enable_coresight(1);
247
248 /*
249 * Set the entry point for CPU execution from reset,
250 * if it's a non-zero value.
251 */
252 if (reset_vector)
253 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
254
255 /* Enable the CPU clock */
256 enable_cpu_clock(1);
257
258 /* If the CPU doesn't already have power, power it up */
259 powerup_cpu();
260
261 /* Take the CPU out of reset */
262 reset_A9_cpu(0);
263}
264
265
266void halt_avp(void)
267{
268 for (;;) {
269 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
270 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
271 FLOW_CTLR_HALT_COP_EVENTS);
272 }
273}
274
275void enable_scu(void)
276{
277 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
278 u32 reg;
279
280 /* If SCU already setup/enabled, return */
281 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
282 return;
283
284 /* Invalidate all ways for all processors */
285 writel(0xFFFF, &scu->scu_inv_all);
286
287 /* Enable SCU - bit 0 */
288 reg = readl(&scu->scu_ctrl);
289 reg |= SCU_CTRL_ENABLE;
290 writel(reg, &scu->scu_ctrl);
291}
292
293void init_pmc_scratch(void)
294{
295 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
296 int i;
297
298 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
299 for (i = 0; i < 23; i++)
300 writel(0, &pmc->pmc_scratch1+i);
301
302 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
303 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
304}
305
306void cpu_start(void)
307{
308 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
309
310 /* enable JTAG */
311 writel(0xC0, &pmt->pmt_cfg_ctl);
312
313 if (s_first_boot) {
314 /*
315 * Need to set this before cold-booting,
316 * otherwise we'll end up in an infinite loop.
317 */
318 s_first_boot = 0;
319 cold_boot();
320 }
321}
322
323void tegra2_start()
324{
325 if (s_first_boot) {
326 /* Init Debug UART Port (115200 8n1) */
327 uart_init();
328
329 /* Init PMC scratch memory */
330 init_pmc_scratch();
331 }
332
333#ifdef CONFIG_ENABLE_CORTEXA9
334 /* take the mpcore out of reset */
335 cpu_start();
336
337 /* configure cache */
338 cache_configure();
339#endif
340}