blob: 5cb4b1b6a0e2a14e3ed2e17f3855c83cb1ce32a3 [file] [log] [blame]
Tom Warren74652cf2011-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 Glassb4ba2be2011-08-30 06:23:13 +000028#include <asm/arch/clock.h>
Tom Warren74652cf2011-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 Warren1436d512011-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 Glass03c609f2011-09-21 12:40:02 +000039 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_XCPU];
Tom Warren1436d512011-04-14 12:09:39 +000040 u32 reg;
41
42 /* If PLLX is already enabled, just return */
Simon Glassd07dc492011-08-30 06:23:15 +000043 if (readl(&pll->pll_base) & PLL_ENABLE_MASK)
Tom Warren1436d512011-04-14 12:09:39 +000044 return;
45
46 /* Set PLLX_MISC */
Simon Glassd07dc492011-08-30 06:23:15 +000047 writel(1 << PLL_CPCON_SHIFT, &pll->pll_misc);
Tom Warren1436d512011-04-14 12:09:39 +000048
49 /* Use 12MHz clock here */
Simon Glassd07dc492011-08-30 06:23:15 +000050 reg = PLL_BYPASS_MASK | (12 << PLL_DIVM_SHIFT);
51 reg |= 1000 << PLL_DIVN_SHIFT;
Simon Glassb4ba2be2011-08-30 06:23:13 +000052 writel(reg, &pll->pll_base);
Tom Warren1436d512011-04-14 12:09:39 +000053
Simon Glassd07dc492011-08-30 06:23:15 +000054 reg |= PLL_ENABLE_MASK;
Simon Glassb4ba2be2011-08-30 06:23:13 +000055 writel(reg, &pll->pll_base);
Tom Warren1436d512011-04-14 12:09:39 +000056
Simon Glassd07dc492011-08-30 06:23:15 +000057 reg &= ~PLL_BYPASS_MASK;
Simon Glassb4ba2be2011-08-30 06:23:13 +000058 writel(reg, &pll->pll_base);
Tom Warren1436d512011-04-14 12:09:39 +000059}
60
Tom Warren74652cf2011-04-14 12:18:06 +000061static void enable_cpu_clock(int enable)
62{
63 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Simon Glassb4ba2be2011-08-30 06:23:13 +000064 u32 clk;
Tom Warren74652cf2011-04-14 12:18:06 +000065
66 /*
67 * NOTE:
68 * Regardless of whether the request is to enable or disable the CPU
69 * clock, every processor in the CPU complex except the master (CPU 0)
70 * will have it's clock stopped because the AVP only talks to the
71 * master. The AVP does not know (nor does it need to know) that there
72 * are multiple processors in the CPU complex.
73 */
74
75 if (enable) {
Tom Warren1436d512011-04-14 12:09:39 +000076 /* Initialize PLLX */
77 init_pllx();
78
Tom Warren74652cf2011-04-14 12:18:06 +000079 /* Wait until all clocks are stable */
80 udelay(PLL_STABILIZATION_DELAY);
81
82 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
83 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
84 }
85
Tom Warren74652cf2011-04-14 12:18:06 +000086 /*
87 * Read the register containing the individual CPU clock enables and
88 * always stop the clock to CPU 1.
89 */
90 clk = readl(&clkrst->crc_clk_cpu_cmplx);
Simon Glassd07dc492011-08-30 06:23:15 +000091 clk |= 1 << CPU1_CLK_STP_SHIFT;
Tom Warren74652cf2011-04-14 12:18:06 +000092
Simon Glassd07dc492011-08-30 06:23:15 +000093 /* Stop/Unstop the CPU clock */
94 clk &= ~CPU0_CLK_STP_MASK;
95 clk |= !enable << CPU0_CLK_STP_SHIFT;
Tom Warren74652cf2011-04-14 12:18:06 +000096 writel(clk, &clkrst->crc_clk_cpu_cmplx);
Simon Glassb4ba2be2011-08-30 06:23:13 +000097
98 clock_enable(PERIPH_ID_CPU);
Tom Warren74652cf2011-04-14 12:18:06 +000099}
100
101static int is_cpu_powered(void)
102{
103 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
104
105 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
106}
107
108static void remove_cpu_io_clamps(void)
109{
110 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
111 u32 reg;
112
113 /* Remove the clamps on the CPU I/O signals */
114 reg = readl(&pmc->pmc_remove_clamping);
115 reg |= CPU_CLMP;
116 writel(reg, &pmc->pmc_remove_clamping);
117
118 /* Give I/O signals time to stabilize */
119 udelay(IO_STABILIZATION_DELAY);
120}
121
122static void powerup_cpu(void)
123{
124 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
125 u32 reg;
126 int timeout = IO_STABILIZATION_DELAY;
127
128 if (!is_cpu_powered()) {
129 /* Toggle the CPU power state (OFF -> ON) */
130 reg = readl(&pmc->pmc_pwrgate_toggle);
131 reg &= PARTID_CP;
132 reg |= START_CP;
133 writel(reg, &pmc->pmc_pwrgate_toggle);
134
135 /* Wait for the power to come up */
136 while (!is_cpu_powered()) {
137 if (timeout-- == 0)
138 printf("CPU failed to power up!\n");
139 else
140 udelay(10);
141 }
142
143 /*
144 * Remove the I/O clamps from CPU power partition.
145 * Recommended only on a Warm boot, if the CPU partition gets
146 * power gated. Shouldn't cause any harm when called after a
147 * cold boot according to HW, probably just redundant.
148 */
149 remove_cpu_io_clamps();
150 }
151}
152
153static void enable_cpu_power_rail(void)
154{
155 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
156 u32 reg;
157
158 reg = readl(&pmc->pmc_cntrl);
159 reg |= CPUPWRREQ_OE;
160 writel(reg, &pmc->pmc_cntrl);
161
162 /*
163 * The TI PMU65861C needs a 3.75ms delay between enabling
164 * the power rail and enabling the CPU clock. This delay
165 * between SM1EN and SM1 is for switching time + the ramp
166 * up of the voltage to the CPU (VDD_CPU from PMU).
167 */
168 udelay(3750);
169}
170
171static void reset_A9_cpu(int reset)
172{
Tom Warren74652cf2011-04-14 12:18:06 +0000173 /*
174 * NOTE: Regardless of whether the request is to hold the CPU in reset
175 * or take it out of reset, every processor in the CPU complex
176 * except the master (CPU 0) will be held in reset because the
177 * AVP only talks to the master. The AVP does not know that there
178 * are multiple processors in the CPU complex.
179 */
180
Simon Glassd07dc492011-08-30 06:23:15 +0000181 /* Hold CPU 1 in reset, and CPU 0 if asked */
182 reset_cmplx_set_enable(1, crc_rst_cpu | crc_rst_de | crc_rst_debug, 1);
183 reset_cmplx_set_enable(0, crc_rst_cpu | crc_rst_de | crc_rst_debug,
184 reset);
Tom Warren74652cf2011-04-14 12:18:06 +0000185
Simon Glassb4ba2be2011-08-30 06:23:13 +0000186 /* Enable/Disable master CPU reset */
187 reset_set_enable(PERIPH_ID_CPU, reset);
Tom Warren74652cf2011-04-14 12:18:06 +0000188}
189
190static void clock_enable_coresight(int enable)
191{
Simon Glassb4ba2be2011-08-30 06:23:13 +0000192 u32 rst, src;
Tom Warren74652cf2011-04-14 12:18:06 +0000193
Simon Glassb4ba2be2011-08-30 06:23:13 +0000194 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
195 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
Tom Warren74652cf2011-04-14 12:18:06 +0000196
197 if (enable) {
198 /*
199 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
200 * 1.5, giving an effective frequency of 144MHz.
201 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
202 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
203 */
204 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
Simon Glass4ed59e72011-09-21 12:40:04 +0000205 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
Tom Warren74652cf2011-04-14 12:18:06 +0000206
207 /* Unlock the CPU CoreSight interfaces */
208 rst = 0xC5ACCE55;
209 writel(rst, CSITE_CPU_DBG0_LAR);
210 writel(rst, CSITE_CPU_DBG1_LAR);
211 }
212}
213
214void start_cpu(u32 reset_vector)
215{
216 /* Enable VDD_CPU */
217 enable_cpu_power_rail();
218
219 /* Hold the CPUs in reset */
220 reset_A9_cpu(1);
221
222 /* Disable the CPU clock */
223 enable_cpu_clock(0);
224
225 /* Enable CoreSight */
226 clock_enable_coresight(1);
227
228 /*
229 * Set the entry point for CPU execution from reset,
230 * if it's a non-zero value.
231 */
232 if (reset_vector)
233 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
234
235 /* Enable the CPU clock */
236 enable_cpu_clock(1);
237
238 /* If the CPU doesn't already have power, power it up */
239 powerup_cpu();
240
241 /* Take the CPU out of reset */
242 reset_A9_cpu(0);
243}
244
245
246void halt_avp(void)
247{
248 for (;;) {
249 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
250 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
251 FLOW_CTLR_HALT_COP_EVENTS);
252 }
253}
254
255void enable_scu(void)
256{
257 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
258 u32 reg;
259
260 /* If SCU already setup/enabled, return */
261 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
262 return;
263
264 /* Invalidate all ways for all processors */
265 writel(0xFFFF, &scu->scu_inv_all);
266
267 /* Enable SCU - bit 0 */
268 reg = readl(&scu->scu_ctrl);
269 reg |= SCU_CTRL_ENABLE;
270 writel(reg, &scu->scu_ctrl);
271}
272
273void init_pmc_scratch(void)
274{
275 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
276 int i;
277
278 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
279 for (i = 0; i < 23; i++)
280 writel(0, &pmc->pmc_scratch1+i);
281
282 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
283 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
284}
285
286void cpu_start(void)
287{
288 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
289
290 /* enable JTAG */
291 writel(0xC0, &pmt->pmt_cfg_ctl);
292
293 if (s_first_boot) {
294 /*
295 * Need to set this before cold-booting,
296 * otherwise we'll end up in an infinite loop.
297 */
298 s_first_boot = 0;
299 cold_boot();
300 }
301}
302
303void tegra2_start()
304{
305 if (s_first_boot) {
306 /* Init Debug UART Port (115200 8n1) */
307 uart_init();
308
309 /* Init PMC scratch memory */
310 init_pmc_scratch();
311 }
312
313#ifdef CONFIG_ENABLE_CORTEXA9
314 /* take the mpcore out of reset */
315 cpu_start();
316
317 /* configure cache */
318 cache_configure();
319#endif
320}