1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "ap20.h"
25#include <asm/io.h>
26#include <asm/arch/tegra2.h>
27#include <asm/arch/clk_rst.h>
28#include <asm/arch/clock.h>
29#include <asm/arch/pmc.h>
30#include <asm/arch/pinmux.h>
31#include <asm/arch/scu.h>
32#include <common.h>
33
34
35static int ap20_cpu_is_cortexa9(void)
36{
37 u32 id = readb(NV_PA_PG_UP_BASE + PG_UP_TAG_0);
38 return id == (PG_UP_TAG_0_PID_CPU & 0xff);
39}
40
41void init_pllx(void)
42{
43 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
44 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_XCPU];
45 u32 reg;
46
47
48 if (readl(&pll->pll_base) & PLL_ENABLE_MASK)
49 return;
50
51
52 writel(1 << PLL_CPCON_SHIFT, &pll->pll_misc);
53
54
55 reg = PLL_BYPASS_MASK | (12 << PLL_DIVM_SHIFT);
56 reg |= 1000 << PLL_DIVN_SHIFT;
57 writel(reg, &pll->pll_base);
58
59 reg |= PLL_ENABLE_MASK;
60 writel(reg, &pll->pll_base);
61
62 reg &= ~PLL_BYPASS_MASK;
63 writel(reg, &pll->pll_base);
64}
65
66static void enable_cpu_clock(int enable)
67{
68 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
69 u32 clk;
70
71
72
73
74
75
76
77
78
79
80 if (enable) {
81
82 init_pllx();
83
84
85 udelay(PLL_STABILIZATION_DELAY);
86
87 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
88 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
89 }
90
91
92
93
94
95 clk = readl(&clkrst->crc_clk_cpu_cmplx);
96 clk |= 1 << CPU1_CLK_STP_SHIFT;
97
98
99 clk &= ~CPU0_CLK_STP_MASK;
100 clk |= !enable << CPU0_CLK_STP_SHIFT;
101 writel(clk, &clkrst->crc_clk_cpu_cmplx);
102
103 clock_enable(PERIPH_ID_CPU);
104}
105
106static int is_cpu_powered(void)
107{
108 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
109
110 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
111}
112
113static void remove_cpu_io_clamps(void)
114{
115 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
116 u32 reg;
117
118
119 reg = readl(&pmc->pmc_remove_clamping);
120 reg |= CPU_CLMP;
121 writel(reg, &pmc->pmc_remove_clamping);
122
123
124 udelay(IO_STABILIZATION_DELAY);
125}
126
127static void powerup_cpu(void)
128{
129 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
130 u32 reg;
131 int timeout = IO_STABILIZATION_DELAY;
132
133 if (!is_cpu_powered()) {
134
135 reg = readl(&pmc->pmc_pwrgate_toggle);
136 reg &= PARTID_CP;
137 reg |= START_CP;
138 writel(reg, &pmc->pmc_pwrgate_toggle);
139
140
141 while (!is_cpu_powered()) {
142 if (timeout-- == 0)
143 printf("CPU failed to power up!\n");
144 else
145 udelay(10);
146 }
147
148
149
150
151
152
153
154 remove_cpu_io_clamps();
155 }
156}
157
158static void enable_cpu_power_rail(void)
159{
160 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
161 u32 reg;
162
163 reg = readl(&pmc->pmc_cntrl);
164 reg |= CPUPWRREQ_OE;
165 writel(reg, &pmc->pmc_cntrl);
166
167
168
169
170
171
172
173 udelay(3750);
174}
175
176static void reset_A9_cpu(int reset)
177{
178
179
180
181
182
183
184
185
186
187 reset_cmplx_set_enable(1, crc_rst_cpu | crc_rst_de | crc_rst_debug, 1);
188 reset_cmplx_set_enable(0, crc_rst_cpu | crc_rst_de | crc_rst_debug,
189 reset);
190
191
192 reset_set_enable(PERIPH_ID_CPU, reset);
193}
194
195static void clock_enable_coresight(int enable)
196{
197 u32 rst, src;
198
199 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
200 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
201
202 if (enable) {
203
204
205
206
207
208
209 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
210 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
211
212
213 rst = 0xC5ACCE55;
214 writel(rst, CSITE_CPU_DBG0_LAR);
215 writel(rst, CSITE_CPU_DBG1_LAR);
216 }
217}
218
219void start_cpu(u32 reset_vector)
220{
221
222 enable_cpu_power_rail();
223
224
225 reset_A9_cpu(1);
226
227
228 enable_cpu_clock(0);
229
230
231 clock_enable_coresight(1);
232
233
234
235
236
237 if (reset_vector)
238 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
239
240
241 enable_cpu_clock(1);
242
243
244 powerup_cpu();
245
246
247 reset_A9_cpu(0);
248}
249
250
251void halt_avp(void)
252{
253 for (;;) {
254 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
255 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
256 FLOW_CTLR_HALT_COP_EVENTS);
257 }
258}
259
260void enable_scu(void)
261{
262 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
263 u32 reg;
264
265
266 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
267 return;
268
269
270 writel(0xFFFF, &scu->scu_inv_all);
271
272
273 reg = readl(&scu->scu_ctrl);
274 reg |= SCU_CTRL_ENABLE;
275 writel(reg, &scu->scu_ctrl);
276}
277
278void init_pmc_scratch(void)
279{
280 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
281 int i;
282
283
284 for (i = 0; i < 23; i++)
285 writel(0, &pmc->pmc_scratch1+i);
286
287
288 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
289}
290
291void tegra2_start(void)
292{
293 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
294
295
296 if (!ap20_cpu_is_cortexa9()) {
297
298 writel(0xC0, &pmt->pmt_cfg_ctl);
299
300
301
302
303
304 asm volatile("mov sp, %0\n"
305 : : "r"(AVP_EARLY_BOOT_STACK_LIMIT));
306
307 start_cpu((u32)_start);
308 halt_avp();
309
310 }
311
312
313 init_pmc_scratch();
314
315 enable_scu();
316
317
318 asm volatile(
319 "mrc p15, 0, r0, c1, c0, 1\n"
320 "orr r0, r0, #0x41\n"
321 "mcr p15, 0, r0, c1, c0, 1\n");
322
323
324}
325