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 <common.h>
25#include <asm/io.h>
26#include <asm/arch/ap20.h>
27#include <asm/arch/clk_rst.h>
28#include <asm/arch/clock.h>
29#include <asm/arch/flow.h>
30#include <asm/arch/pinmux.h>
31#include <asm/arch/pmc.h>
32#include <asm/arch/tegra2.h>
33#include <asm/arch/warmboot.h>
34#include "warmboot_avp.h"
35
36#define DEBUG_RESET_CORESIGHT
37
38void wb_start(void)
39{
40 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
41 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
42 struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
43 struct clk_rst_ctlr *clkrst =
44 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
45 union osc_ctrl_reg osc_ctrl;
46 union pllx_base_reg pllx_base;
47 union pllx_misc_reg pllx_misc;
48 union scratch3_reg scratch3;
49 u32 reg;
50
51
52 writel(CONFIG_CTL_TBE | CONFIG_CTL_JTAG, &pmt->pmt_cfg_ctl);
53
54
55 asm volatile (
56 "adr %0, wb_start;"
57 : "=r"(reg)
58
59 );
60
61 if (reg != AP20_WB_RUN_ADDRESS)
62 goto do_reset;
63
64
65 if (readl(NV_PA_PG_UP_BASE + PG_UP_TAG_0) != PG_UP_TAG_AVP)
66 goto do_reset;
67
68#ifdef DEBUG_RESET_CORESIGHT
69
70 reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_U]);
71 reg |= SWR_CSITE_RST;
72 writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_U]);
73#endif
74
75
76 osc_ctrl.word = readl(&clkrst->crc_osc_ctrl);
77 osc_ctrl.xofs = 4;
78 osc_ctrl.xoe = 1;
79 writel(osc_ctrl.word, &clkrst->crc_osc_ctrl);
80
81
82 if (!(readl(&pmc->pmc_pwrgate_status) & PWRGATE_STATUS_CPU)) {
83 reg = PWRGATE_TOGGLE_PARTID_CPU | PWRGATE_TOGGLE_START;
84 writel(reg, &pmc->pmc_pwrgate_toggle);
85 while (!(readl(&pmc->pmc_pwrgate_status) & PWRGATE_STATUS_CPU))
86 ;
87 }
88
89
90 reg = readl(&pmc->pmc_remove_clamping);
91 reg |= CPU_CLMP;
92 writel(reg, &pmc->pmc_remove_clamping);
93
94 reg = EVENT_ZERO_VAL_20 | EVENT_MSEC | EVENT_MODE_STOP;
95 writel(reg, &flow->halt_cop_events);
96
97
98 reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_L]);
99 reg |= CPU_RST;
100 writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
101
102
103 reg = CPU_CMPLX_CPURESET0 | CPU_CMPLX_CPURESET1 | CPU_CMPLX_DERESET0 |
104 CPU_CMPLX_DERESET1 | CPU_CMPLX_DBGRESET0 | CPU_CMPLX_DBGRESET1;
105 writel(reg, &clkrst->crc_cpu_cmplx_set);
106
107
108 writel(EVENT_MODE_STOP, &flow->halt_cpu1_events);
109
110
111
112
113
114 reg = readl(&pmc->pmc_scratch41);
115 writel(reg, EXCEP_VECTOR_CPU_RESET_VECTOR);
116
117
118 writel(CCLK_PLLP_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
119
120
121 reg = CPU_CMPLX_CPU_BRIDGE_CLKDIV_4 | CPU_CMPLX_CPU0_CLK_STP_RUN |
122 CPU_CMPLX_CPU1_CLK_STP_STOP;
123 writel(reg, &clkrst->crc_clk_cpu_cmplx);
124
125
126 reg = readl(&clkrst->crc_clk_out_enb[TEGRA_DEV_L]);
127 reg |= CLK_ENB_CPU;
128 writel(reg, &clkrst->crc_clk_out_enb[TEGRA_DEV_L]);
129
130
131 reg = readl(TIMER_USEC_CNTR);
132 while (readl(TIMER_USEC_CNTR) <= (reg + 2))
133 ;
134
135#ifdef DEBUG_RESET_CORESIGHT
136
137
138
139
140
141
142 reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_U]);
143 reg &= ~SWR_CSITE_RST;
144 writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_U]);
145#endif
146
147
148 reg = 0xC5ACCE55;
149 writel(reg, CSITE_CPU_DBG0_LAR);
150 writel(reg, CSITE_CPU_DBG1_LAR);
151
152
153
154
155
156 reg = readl(TIMER_USEC_CNTR);
157 writel(reg, &pmc->pmc_scratch1);
158
159 pllx_base.word = 0;
160 pllx_misc.word = 0;
161 scratch3.word = readl(&pmc->pmc_scratch3);
162
163
164 reg = (readl(TIMER_USEC_CFG) & USEC_CFG_DIVISOR_MASK) + 1;
165
166
167
168
169
170
171
172
173 if (reg > 26)
174 reg = 19;
175
176
177 if (scratch3.pllx_base_divm == reg)
178 reg = 0;
179 else
180 reg = 1;
181
182
183 pllx_base.divn = scratch3.pllx_base_divn;
184 reg = scratch3.pllx_base_divn << reg;
185
186
187 pllx_base.divp = scratch3.pllx_base_divp;
188 reg = reg >> scratch3.pllx_base_divp;
189
190 pllx_base.bypass = 1;
191
192
193 if (reg > 600)
194 pllx_misc.dccon = 1;
195
196
197 pllx_misc.lfcon = scratch3.pllx_misc_lfcon;
198
199
200 pllx_misc.cpcon = scratch3.pllx_misc_cpcon;
201
202 writel(pllx_misc.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_misc);
203 writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
204
205 pllx_base.enable = 1;
206 writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
207 pllx_base.bypass = 0;
208 writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
209
210 writel(0, flow->halt_cpu_events);
211
212 reg = CPU_CMPLX_CPURESET0 | CPU_CMPLX_DBGRESET0 | CPU_CMPLX_DERESET0;
213 writel(reg, &clkrst->crc_cpu_cmplx_clr);
214
215 reg = PLLM_OUT1_RSTN_RESET_DISABLE | PLLM_OUT1_CLKEN_ENABLE |
216 PLLM_OUT1_RATIO_VAL_8;
217 writel(reg, &clkrst->crc_pll[CLOCK_ID_MEMORY].pll_out);
218
219 reg = SCLK_SWAKE_FIQ_SRC_PLLM_OUT1 | SCLK_SWAKE_IRQ_SRC_PLLM_OUT1 |
220 SCLK_SWAKE_RUN_SRC_PLLM_OUT1 | SCLK_SWAKE_IDLE_SRC_PLLM_OUT1 |
221 SCLK_SYS_STATE_IDLE;
222 writel(reg, &clkrst->crc_sclk_brst_pol);
223
224
225 reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_L]);
226 reg &= ~CPU_RST;
227 writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
228
229
230avp_halt:
231 reg = EVENT_MODE_STOP | EVENT_JTAG;
232 writel(reg, flow->halt_cop_events);
233 goto avp_halt;
234
235do_reset:
236
237
238
239
240 writel(SWR_TRIG_SYS_RST, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
241 goto do_reset;
242}
243
244
245
246
247
248void wb_end(void)
249{
250}
251