blob: cdeb381b2b8c335b70959f477d07a0d954f7fcee [file] [log] [blame]
Brian Swetlanddfdb4612009-01-01 11:44:36 -08001/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * Copyright (c) 2008-2009, The Linux Foundation. All rights reserved.
Brian Swetlanddfdb4612009-01-01 11:44:36 -08003 * Copyright (c) 2008, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33
34/* TODO:
35 * - style cleanup
36 * - do we need to do *all* of this at boot?
37 */
38
39.text
40.code 32
41
42#define DSB .byte 0x4f, 0xf0, 0x7f, 0xf5
43#define ISB .byte 0x6f, 0xf0, 0x7f, 0xf5
44
45/*
46 ; LVT Ring Osc counter
47 ; used to determine sense amp settings
48 ; Clobbers registers r0, r4, r5, r6, r7, r9, r10, r11
49*/
50.equ CLK_CTL_BASE, 0xA8600000
51.equ A_GLBL_CLK_ENA, 0x0000
52.equ A_PRPH_WEB_NS_REG,0x0080
53.equ A_MSM_CLK_RINGOSC,0x00D0
54.equ A_TCXO_CNT, 0x00D4
55.equ A_TCXO_CNT_DONE, 0x00D8
56.equ A_RINGOSC_CNT, 0x00DC
57.equ A_MISC_CLK_CTL, 0x0108
58.equ CLK_TEST, 0xA8600114
59.equ SPSS_CSR_BASE, 0xAC100000
60.equ A_SCRINGOSC, 0x0510
61
62//;; Number of TCXO cycles to count ring oscillations
63.equ TCXO_CNT_VAL, 0x100
Brian Swetlanddfdb4612009-01-01 11:44:36 -080064
Ajay Dudaniae80c6e2009-11-28 14:15:03 -080065//; Raptor addresses
66.equ TCSR_SPARE2, 0xA8700060
Brian Swetlanddfdb4612009-01-01 11:44:36 -080067
Ajay Dudani232ce812009-12-02 00:14:11 -080068
69.globl SET_SA
Ajay Dudaniae80c6e2009-11-28 14:15:03 -080070SET_SA:
71 //; no stack at this point and any registers we use will be 0'd
72 //; after we return
73 LDR r0, =TCSR_SPARE2
74 LDR r1, [r0]
75 LDR r0, = 0x010F
76 AND r2, r1, r0 //; concerned with bits [8, 3:0]
Brian Swetlanddfdb4612009-01-01 11:44:36 -080077
Ajay Dudaniae80c6e2009-11-28 14:15:03 -080078 //;--------------------------------------------------------------------
79 //; Fuse bits used to determine sense amp settings
80 //;--------------------------------------------------------------------
Brian Swetlanddfdb4612009-01-01 11:44:36 -080081
Ajay Dudaniae80c6e2009-11-28 14:15:03 -080082 LDR r0, = 0x0105
83 AND r4, r2, r0 //; mask off all but L1 ACC2, L1 ACC1 and L1 ACC0
84 //;set to default of FC00
85 LDR r5, =PVR0F0_6bits //; point to PVR0F0
86 LDR r3, =PVR2F0_6bits //; point to PVR2F0
Brian Swetlanddfdb4612009-01-01 11:44:36 -080087
Ajay Dudaniae80c6e2009-11-28 14:15:03 -080088ck_0:
89 //; if L1_[2:0] == 000 then ACC setting = FC00
90 LDR r1, = 0x0
91 CMP r4, r1
92 BNE ck_1
93 B WRITE_L1_SA_SETTINGS
Brian Swetlanddfdb4612009-01-01 11:44:36 -080094
Ajay Dudaniae80c6e2009-11-28 14:15:03 -080095ck_1:
96 //; if L1_[2:0] == 001 then ACC setting = FC00
97 LDR r1, = 0x01
98 CMP r4, r1
99 BNE ck_2
100 B WRITE_L1_SA_SETTINGS
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800101
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800102ck_2:
103 //; if L1_[2:0] == 010 then ACC setting = 7C00
104 LDR r1, = 0x04
105 CMP r4, r1
106 BNE ck_3
107 LDR r5, =PVR0F0_5bits //; point to PVR0F0
108 LDR r3, =PVR2F0_5bits //; point to PVR2F0
109 B WRITE_L1_SA_SETTINGS
110
111ck_3:
112 //; if L1_[2:0] == 011 then ACC setting = FC00
113 LDR r1, = 0x05
114 CMP r4, r1
115 BNE ck_4
116 LDR r5, =PVR0F0_6bits //; point to PVR0F0
117 LDR r3, =PVR2F0_6bits //; point to PVR2F0
118 B WRITE_L1_SA_SETTINGS
119
120ck_4:
121 //; if L1_[2:0] == 0100 then ACC setting = 3C00
122 LDR r1, = 0x0100
123 CMP r4, r1
124 BNE ck_5
125 LDR r5, =PVR0F0_4bits //; point to PVR0F0
126 LDR r3, =PVR2F0_4bits //; point to PVR2F0
127 B WRITE_L1_SA_SETTINGS
128
129ck_5:
130 //; if L1_[2:0] == 0101 then ACC setting = 0400
131 LDR r1, = 0x0101
132 CMP r4, r1
133 BNE ck_6
134 LDR r5, =PVR0F0_1bits //; point to PVR0F0
135 LDR r3, =PVR2F0_1bits //; point to PVR2F0
136 B WRITE_L1_SA_SETTINGS
137
138ck_6:
139 //; if L1_[2:0] == 0110 then ACC setting = 0C00
140 LDR r1, = 0x0104
141 CMP r4, r1
142 BNE ck_7
143 LDR r5, =PVR0F0_2bits //; point to PVR0F0
144 LDR r3, =PVR2F0_2bits //; point to PVR2F0
145 B WRITE_L1_SA_SETTINGS
146
147ck_7:
148 //; if L1_[2:0] == 0111 then ACC setting = 1C00
149 LDR r1, = 0x0105
150 CMP r4, r1
151 LDREQ r5, =PVR0F0_3bits //; point to PVR0F0
152 LDREQ r3, =PVR2F0_3bits //; point to PVR2F0
153
154WRITE_L1_SA_SETTINGS:
155
156 LDR r5, [r5]
157 LDR r3, [r3]
158
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800159 //;WCP15_PVR0F0 r5
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800160 MCR p15,0x0,r5,c15,c15,0 //; write R5 to PVR0F0
161
162 //;WCP15_PVR2F0 r3
163 MCR p15,0x2,r3,c15,c15,0 //; write R3 to PVR2F0
164
165 AND r4, r2, #0x000A //; mask off all but L2 array SA settings
166 LDR r5, =HVT_010102 //; point to L2VR3F1 setting
167 //;it gets ovewritten if its one of the other two cases
168 //; if L2_1 and L2_0 == 0 ACC setting = 010102
169 LDR r1, = 0x0000
170 CMP r4, r1
171 BEQ WRITE_L2_SA_SETTINGS
172
173 //; if L2_1 = 0 & L2_0 = 1 ACC setting = 010102
174 LDR R1, = 0x0002
175 CMP r4, r1
176 BEQ WRITE_L2_SA_SETTINGS
177
178 //; if L2_1 = 1 & L2_0 = 0 ACC setting = 010101
179 LDR r5, =HVT_010101
180 LDR R1, = 0x0008
181 CMP r4, r1
182 BEQ WRITE_L2_SA_SETTINGS
183
184 //; else L2_1 = 1 & L2_0 = 1 ACC setting = 212102
185 LDR r5, =HVT_212102
186
187
188WRITE_L2_SA_SETTINGS:
189 //;WCP15_L2VR3F1 r4
190 LDR r5, [r5]
191 MCR p15,0x3,r5,c15,c15,1 //;write r4 to L2VR3F1
192
193 LDR r0, =0 //;make sure the registers we touched
194 LDR r1, =0 //;are cleared when we return
195 LDR r2, =0
196 LDR r3, =0
197 LDR r4, =0
198 LDR r5, =0
199
200 //; routine complete
Ajay Dudani083d0dd2010-07-08 13:16:13 -0700201 B _cpu_early_init_complete
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800202
203//; L1 SA settings according to LVT speed
204PVR0F0_0bits:
205.word 0x38000000 //; PVR0F0
206PVR2F0_0bits:
207.word 0x00000000 //; PVR2F0 0 bits set
208
209PVR0F0_1bits:
210.word 0x38000400 //; PVR0F0
211PVR2F0_1bits:
212.word 0x04000000 //; PVR2F0 1 bits set
213
214PVR0F0_2bits:
215.word 0x38000C00 //; PVR0F0
216PVR2F0_2bits:
217.word 0x0C000000 //; PVR2F0 2 bits set
218
219PVR0F0_3bits:
220.word 0x38001C00 //; PVR0F0
221PVR2F0_3bits:
222.word 0x1C000000 //; PVR2F0 3 bits set
223
224PVR0F0_4bits:
225.word 0x38003C00 //; PVR0F0
226PVR2F0_4bits:
227.word 0x3C000000 //; PVR2F0 4 bits set
228
229PVR0F0_5bits:
230.word 0x38007C00 //; PVR0F0
231PVR2F0_5bits:
232.word 0x7C000000 //; PVR2F0 5 bits set
233
234PVR0F0_6bits:
235.word 0x3800FC00 //; PVR0F0
236PVR2F0_6bits:
237.word 0xFC000000 //; PVR2F0 6 bits set
238
239//; L2 SA settings according to HVT speed
240HVT_212102:
241.word 0x00212102 //; L2VR3F1
242
243HVT_010102:
244.word 0x00010102 //; L2VR3F1
245
246HVT_010101:
247.word 0x00010101 //; L2VR3F1
Ajay Dudani232ce812009-12-02 00:14:11 -0800248
249
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800250.ltorg
251
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800252
253.globl __cpu_early_init
254__cpu_early_init:
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800255 //; Zero out r0 for use throughout this code. All other GPRs
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800256 //; (r1-r3) are set throughout this code to help establish
257 //; a consistent startup state for any code that follows.
258 //; Users should add code at the end of this routine to establish
259 //; their own stack address (r13), add translation page tables, enable
260 //; the caches, etc.
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800261 MOV r0, #0x0
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800262
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800263
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800264 //; Remove hardcoded cache settings. appsbl_handler.s calls Set_SA
265 //; API to dynamically configure cache for slow/nominal/fast parts
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800266
267 //; DCIALL to invalidate L2 cache bank (needs to be run 4 times, once per bank)
268 //; This must be done early in code (prior to enabling the caches)
269 MOV r1, #0x2
270 MCR p15, 0, r1, c9, c0, 6 //; DCIALL bank D ([15:14] == 2'b00)
271 ORR r1, r1, #0x00004000
272 MCR p15, 0, r1, c9, c0, 6 //; DCIALL bank C ([15:14] == 2'b01)
273 ADD r1, r1, #0x00004000
274 MCR p15, 0, r1, c9, c0, 6 //; DCIALL bank B ([15:14] == 2'b10)
275 ADD r1, r1, #0x00004000
276 MCR p15, 0, r1, c9, c0, 6 //; DCIALL bank A ([15:14] == 2'b11)
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800277
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800278 //; Initialize the BPCR - setup Global History Mask (GHRM) to all 1's
279 //; and have all address bits (AM) participate.
280 //; Different settings can be used to improve performance
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800281 // MOVW r1, #0x01FF
282.word 0xe30011ff // hardcoded MOVW instruction due to lack of compiler support
283 // MOVT r1, #0x01FF
284.word 0xe34011ff // hardcoded MOVT instruction due to lack of compiler support
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800285 MCR p15, 7, r1, c15, c0, 2 //; WCP15_BPCR
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800286
287
288 //; Initialize all I$ Victim Registers to 0 for startup
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800289 MCR p15, 0, r0, c9, c1, 0 //; WCP15_ICVIC0 r0
290 MCR p15, 0, r0, c9, c1, 1 //; WCP15_ICVIC1 r0
291 MCR p15, 0, r0, c9, c1, 2 //; WCP15_ICVIC2 r0
292 MCR p15, 0, r0, c9, c1, 3 //; WCP15_ICVIC3 r0
293 MCR p15, 0, r0, c9, c1, 4 //; WCP15_ICVIC4 r0
294 MCR p15, 0, r0, c9, c1, 5 //; WCP15_ICVIC5 r0
295 MCR p15, 0, r0, c9, c1, 6 //; WCP15_ICVIC5 r0
296 MCR p15, 0, r0, c9, c1, 7 //; WCP15_ICVIC7 r0
297
298 //; Initialize all I$ Locked Victim Registers (Unlocked Floors) to 0
299 MCR p15, 1, r0, c9, c1, 0 //; WCP15_ICFLOOR0 r0
300 MCR p15, 1, r0, c9, c1, 1 //; WCP15_ICFLOOR1 r0
301 MCR p15, 1, r0, c9, c1, 2 //; WCP15_ICFLOOR2 r0
302 MCR p15, 1, r0, c9, c1, 3 //; WCP15_ICFLOOR3 r0
303 MCR p15, 1, r0, c9, c1, 4 //; WCP15_ICFLOOR4 r0
304 MCR p15, 1, r0, c9, c1, 5 //; WCP15_ICFLOOR5 r0
305 MCR p15, 1, r0, c9, c1, 6 //; WCP15_ICFLOOR6 r0
306 MCR p15, 1, r0, c9, c1, 7 //; WCP15_ICFLOOR7 r0
307
308 //; Initialize all D$ Victim Registers to 0
309 MCR p15, 2, r0, c9, c1, 0 //; WP15_DCVIC0 r0
310 MCR p15, 2, r0, c9, c1, 1 //; WP15_DCVIC1 r0
311 MCR p15, 2, r0, c9, c1, 2 //; WP15_DCVIC2 r0
312 MCR p15, 2, r0, c9, c1, 3 //; WP15_DCVIC3 r0
313 MCR p15, 2, r0, c9, c1, 4 //; WP15_DCVIC4 r0
314 MCR p15, 2, r0, c9, c1, 5 //; WP15_DCVIC5 r0
315 MCR p15, 2, r0, c9, c1, 6 //; WP15_DCVIC6 r0
316 MCR p15, 2, r0, c9, c1, 7 //; WP15_DCVIC7 r0
317
318 //; Initialize all D$ Locked VDCtim Registers (Unlocked Floors) to 0
319 MCR p15, 3, r0, c9, c1, 0 //; WCP15_DCFLOOR0 r0
320 MCR p15, 3, r0, c9, c1, 1 //; WCP15_DCFLOOR1 r0
321 MCR p15, 3, r0, c9, c1, 2 //; WCP15_DCFLOOR2 r0
322 MCR p15, 3, r0, c9, c1, 3 //; WCP15_DCFLOOR3 r0
323 MCR p15, 3, r0, c9, c1, 4 //; WCP15_DCFLOOR4 r0
324 MCR p15, 3, r0, c9, c1, 5 //; WCP15_DCFLOOR5 r0
325 MCR p15, 3, r0, c9, c1, 6 //; WCP15_DCFLOOR6 r0
326 MCR p15, 3, r0, c9, c1, 7 //; WCP15_DCFLOOR7 r0
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800327
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800328 //; Initialize ASID to zero
329 MCR p15, 0, r0, c13, c0, 1 //; WCP15_CONTEXTIDR r0
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800330
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800331 //; ICIALL to invalidate entire I-Cache
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800332 MCR p15, 0, r0, c7, c5, 0 //; ICIALLU
333
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800334 //; DCIALL to invalidate entire D-Cache
335 MCR p15, 0, r0, c9, c0, 6 //; DCIALL r0
336
Chandan Uddaraju66292822010-03-11 18:07:42 -0800337 //; Initialize ADFSR to zero
338 MCR p15, 0, r0, c5, c1, 0 //; ADFSR r0
339
340 //; Initialize EFSR to zero
341 MCR p15, 7, r0, c15, c0, 1 //; EFSR r0
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800342
343 //; The VBAR (Vector Base Address Register) should be initialized
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800344 //; early in your code. We are setting it to zero
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800345 MCR p15, 0, r0, c12, c0, 0 //; WCP15_VBAR r0
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800346
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800347 //; Ensure the MCR's above have completed their operation before continuing
348 DSB
349 ISB
350
351 //;-------------------------------------------------------------------
352 //; There are a number of registers that must be set prior to enabling
353 //; the MMU. The DCAR is one of these registers. We are setting
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800354 //; it to zero (no access) to easily detect improper setup in subsequent
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800355 //; code sequences
356 //;-------------------------------------------------------------------
357 //; Setup DACR (Domain Access Control Register) to zero
358 MCR p15, 0, r0, c3, c0, 0 //; WCP15_DACR r0
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800359
360 //; Setup DCLKCR to allow normal D-Cache line fills
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800361 MCR p15, 1, r0, c9, c0, 7 //; WCP15_DCLKCR r0
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800362
363 //; Setup the TLBLKCR
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800364 //; Victim = 6'b000000; Floor = 6'b000000;
365 //; IASIDCFG = 2'b00 (State-Machine); IALLCFG = 2'b01 (Flash); BNA = 1'b0;
366 MOV r1, #0x02
367 MCR p15, 0, r1, c10, c1, 3 //; WCP15_TLBLKCR r1
368
369 //;Make sure TLBLKCR is complete before continuing
370 ISB
371
372 //; Invalidate the UTLB
373 MCR p15, 0, r0, c8, c7, 0 //; UTLBIALL
374
375 //; Make sure UTLB request has been presented to macro before continuing
376 ISB
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800377
378 // Disable predecode repair cache on certain Scorpion revisions
379 // (Raptor V2 and earlier, or Halcyon V1)
380 MRC p15, 0, r1, c0, c0, 0 //; MIDR
381 BIC r2, r1, #0xf7 //; check for Raptor2 or below
382 LDR r3, =0x510f0000
383 CMP r2, r3
384 BEQ DPRC
385 BIC r2, r1, #0xf0 //; check for Halcyon V1
386 LDR r3, =0x511f0000
387 CMP r2, r3
388 BNE SYSI2
389
390DPRC:
391 MRC p15, 0, r1, c15, c15, 2 //; PVR0F2
392 ORR r1, r1, #0x10 //; enable bit 4
393 MCR p15, 0, r1, c15, c15, 2 //; disable predecode repair cache
394
395SYSI2:
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800396 //; setup L2CR1 to some default Instruction and data prefetching values
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800397 //; Users may want specific settings for various performance enhancements
Ajay Dudanid8a91a82010-02-26 15:04:09 -0800398 MOV r2, #0x33
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800399 MCR p15, 3, r2, c15, c0, 3 //; WCP15_L2CR1 r0
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800400
401
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800402 //; Enable Z bit to enable branch prediction (default is off)
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800403 MRC p15, 0, r2, c1, c0, 0 //; RCP15_SCTLR r2
404 ORR r2, r2, #0x00000800
405 MCR p15, 0, r2, c1, c0, 0 //; WCP15_SCTLR r2
406
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800407 //; Make sure Link stack is initialized with branch and links to sequential addresses
408 //; This aids in creating a predictable startup environment
Ajay Dudani083d0dd2010-07-08 13:16:13 -0700409 BL SEQ1
410SEQ1: BL SEQ2
411SEQ2: BL SEQ3
412SEQ3: BL SEQ4
413SEQ4: BL SEQ5
414SEQ5: BL SEQ6
415SEQ6: BL SEQ7
416SEQ7: BL SEQ8
417SEQ8:
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800418
419 //; REMOVE FOLLOWING THREE INSTRUCTIONS WHEN POWER COLLAPSE IS ENA
420 //;Make sure the DBGOSLSR[LOCK] bit is cleared to allow access to the debug registers
421 //; Writing anything but the "secret code" to the DBGOSLAR clears the DBGOSLSR[LOCK] bit
422 MCR p14, 0, r0, c1, c0, 4 //; WCP14_DBGOSLAR r0
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800423
424
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800425 //; Read the DBGPRSR to clear the DBGPRSR[STICKYPD]
426 //; Any read to DBGPRSR clear the STICKYPD bit
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800427 //; ISB guarantees the read completes before attempting to
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800428 //; execute a CP14 instruction.
429 MRC p14, 0, r3, c1, c5, 4 //; RCP14_DBGPRSR r3
430 ISB
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800431
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800432 //; Initialize the Watchpoint Control Registers to zero (optional)
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800433 //;;; MCR p14, 0, r0, c0, c0, 7 ; WCP14_DBGWCR0 r0
434 //;;; MCR p14, 0, r0, c0, c1, 7 ; WCP14_DBGWCR1 r0
435
436
437 //;----------------------------------------------------------------------
438 //; The saved Program Status Registers (SPSRs) should be setup
439 //; prior to any automatic mode switches. The following
440 //; code sets these registers up to a known state. Users will need to
441 //; customize these settings to meet their needs.
442 //;----------------------------------------------------------------------
443 MOV r2, #0x1f
David Ngdb6b6a82010-02-18 14:16:37 -0800444 MOV r1, #0xd7 //;ABT mode
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800445 msr cpsr_c, r1 //;ABT mode
446 msr spsr_cxfs, r2 //;clear the spsr
David Ngdb6b6a82010-02-18 14:16:37 -0800447 MOV r1, #0xdb //;UND mode
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800448 msr cpsr_c, r1 //;UND mode
449 msr spsr_cxfs, r2 //;clear the spsr
David Ngdb6b6a82010-02-18 14:16:37 -0800450 MOV r1, #0xd1 //;FIQ mode
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800451 msr cpsr_c, r1 //;FIQ mode
452 msr spsr_cxfs, r2 //;clear the spsr
David Ngdb6b6a82010-02-18 14:16:37 -0800453 MOV r1, #0xd2 //;IRQ mode
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800454 msr cpsr_c, r1 //;IRQ mode
455 msr spsr_cxfs, r2 //;clear the spsr
David Ngdb6b6a82010-02-18 14:16:37 -0800456 MOV r1, #0xd6 //;Monitor mode
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800457 msr cpsr_c, r1 //;Monitor mode
458 msr spsr_cxfs, r2 //;clear the spsr
David Ngdb6b6a82010-02-18 14:16:37 -0800459 MOV r1, #0xd3 //;SVC mode
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800460 msr cpsr_c, r1 //;SVC mode
461 msr spsr_cxfs, r2 //;clear the spsr
462
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800463
464 //;----------------------------------------------------------------------
465 //; Enabling Error reporting is something users may want to do at
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800466 //; some other point in time. We have chosen some default settings
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800467 //; that should be reviewed. Most of these registers come up in an
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800468 //; unpredictable state after reset.
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800469 //;----------------------------------------------------------------------
470//;Start of error and control setting
471
472 //; setup L2CR0 with various L2/TCM control settings
473 //; enable out of order bus attributes and error reporting
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800474 //; this register comes up unpredictable after reset
475 // MOVW r1, #0x0F0F
476.word 0xe3001f0f // hardcoded MOVW instruction due to lack of compiler support
477 // MOVT r1, #0xC005
478.word 0xe34c1005 // hardcoded MOVW instruction due to lack of compiler support
479 MCR p15, 3, r1, c15, c0, 1 //; WCP15_L2CR0 r1
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800480
481 //; setup L2CPUCR
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800482 //; MOV r2, #0xFF
483 //; Enable I and D cache parity
484 //;L2CPUCR[7:5] = 3~Rh7 ~V enable parity error reporting for modified,
485 //;tag, and data parity errors
486 MOV r2, #0xe0
487 MCR p15, 3, r2, c15, c0, 2 //; WCP15_L2CPUCR r2
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800488
489 //; setup SPCR
490 //; enable all error reporting (reset value is unpredicatble for most bits)
491 MOV r3, #0x0F
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800492 MCR p15, 0, r3, c9, c7, 0 //; WCP15_SPCR r3
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800493
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800494 //; setup DMACHCRs (reset value unpredictable)
495 //; control setting and enable all error reporting
496 MOV r1, #0x0F
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800497
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800498 //; DMACHCR0 = 0000000F
499 MOV r2, #0x00 //; channel 0
500 MCR p15, 0, r2, c11, c0, 0 //; WCP15_DMASELR r2
501 MCR p15, 0, r1, c11, c0, 2 //; WCP15_DMACHCR r1
502
503 //; DMACHCR1 = 0000000F
504 MOV r2, #0x01 //; channel 1
505 MCR p15, 0, r2, c11, c0, 0 //; WCP15_DMASELR r2
506 MCR p15, 0, r1, c11, c0, 2 //; WCP15_DMACHCR r1
507
508 //; DMACHCR2 = 0000000F
509 MOV r2, #0x02 //; channel 2
510 MCR p15, 0, r2, c11, c0, 0 //; WCP15_DMASELR r2
511 MCR p15, 0, r1, c11, c0, 2 //; WCP15_DMACHCR r1
512
513 //; DMACHCR3 = 0000000F
514 MOV r2, #0x03 //; channel 3
515 MCR p15, 0, r2, c11, c0, 0 //; WCP15_DMASELR r2
516 MCR p15, 0, r1, c11, c0, 2 //; WCP15_DMACHCR r1
517
518 //; Set ACTLR (reset unpredictable)
519 //; Set AVIVT control, error reporting, etc.
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800520 //; MOV r3, #0x07
521 //; Enable I and D cache parity
522 //;ACTLR[2:0] = 3'h7 - enable parity error reporting from L2/I$/D$)
523 //;ACTLR[5:4] = 2'h3 - enable parity
524 //;ACTLR[19:18] =2'h3 - always generate and check parity(when MMU disabled).
525 //;Value to be written #0xC0037
526 // MOVW r3, #0x0037
527.word 0xe3003037 // hardcoded MOVW instruction due to lack of compiler support
528 // MOVT r3, #0x000C
529.word 0xe340300c // hardcoded MOVW instruction due to lack of compiler support
530 //; read the version_id to determine if d-cache should be disabled
531 LDR r2, = 0xa8e00270 //;Read HW_REVISION_NUMBER, HWIO_HW_REVISION_NUMBER_ADDR
532 LDR r2,[r2]
533 AND r2,r2,#0xf0000000 //;hw_revision mask off bits 28-31
534 //;if HW_revision is 1.0 or older, (revision==0)
535 CMP r2,#0
536 //; Disable d-cache on older QSD8650 (Rev 1.0) silicon
Ajay Dudani232ce812009-12-02 00:14:11 -0800537 //;orreq r3, r3, #0x4000 //;disable dcache
538 //;MCR p15, 0, r3, c1, c0, 1 //; WCP15_ACTLR r3
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800539
540//;End of error and control setting
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800541
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800542 //;----------------------------------------------------------------------
543 //; Unlock ETM and read StickyPD to halt the ETM clocks from running.
544 //; This is required for power saving whether the ETM is used or not.
545 //;----------------------------------------------------------------------
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800546
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800547 //;Clear ETMOSLSR[LOCK] bit
548 MOV r1, #0x00000000
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800549 MCR p14, 1, r1, c1, c0, 4 //; WCP14_ETMOSLAR r1
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800550
551 //;Clear ETMPDSR[STICKYPD] bit
552 MRC p14, 1, r2, c1, c5, 4 //; RCP14_ETMPDSR r2
553
554/*
555#ifdef APPSBL_ETM_ENABLE
556 ;----------------------------------------------------------------------
557 ; Optionally Enable the ETM (Embedded Trace Macro) which is used for debug
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800558 ;----------------------------------------------------------------------
559
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800560 ; enable ETM clock if disabled
561 MRC p15, 7, r1, c15, c0, 5 ; RCP15_CPMR r1
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800562 ORR r1, r1, #0x00000008
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800563 MCR p15, 7, r1, c15, c0, 5 ; WCP15_CPMR r1
564 ISB
565
566 ; set trigger event to counter1 being zero
567 MOV r3, #0x00000040
568 MCR p14, 1, r3, c0, c2, 0 ; WCP14_ETMTRIGGER r3
569
570 ; clear ETMSR
571 MOV r2, #0x00000000
572 MCR p14, 1, r2, c0, c4, 0 ; WCP14_ETMSR r2
573
574 ; clear trace enable single address comparator usage
575 MCR p14, 1, r2, c0, c7, 0 ; WCP14_ETMTECR2 r2
576
577 ; set trace enable to always
578 MOV r2, #0x0000006F
579 MCR p14, 1, r2, c0, c8, 0 ; WCP14_ETMTEEVR r2
580
581 ; clear trace enable address range comparator usage and exclude nothing
582 MOV r2, #0x01000000
583 MCR p14, 1, r2, c0, c9, 0 ; WCP14_ETMTECR1 r2
584
585 ; set view data to always
586 MOV r2, #0x0000006F
587 MCR p14, 1, r2, c0, c12, 0 ; WCP14_ETMVDEVR r2
588
589 ; clear view data single address comparator usage
590 MOV r2, #0x00000000
591 MCR p14, 1, r2, c0, c13, 0 ; WCP14_ETMVDCR1 r2
592
593 ; clear view data address range comparator usage and exclude nothing
594 MOV r2, #0x00010000
595 MCR p14, 1, r2, c0, c15, 0 ; WCP14_ETMVDCR3 r2
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800596
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800597 ; set counter1 to 194
598 MOV r2, #0x000000C2
599 MCR p14, 1, r2, c0, c0, 5 ; WCP14_ETMCNTRLDVR1 r2
600
601 ; set counter1 to never reload
602 MOV r2, #0x0000406F
603 MCR p14, 1, r2, c0, c8, 5 ; WCP14_ETMCNTRLDEVR1 r2
604
605 ; set counter1 to decrement every cycle
606 MOV r2, #0x0000006F
607 MCR p14, 1, r2, c0, c4, 5 ; WCP14_ETMCNTENR1 r2
608
609 ; Set trace synchronization frequency 1024 bytes
610 MOV r2, #0x00000400
611 MCR p14, 1, r2, c0, c8, 7 ; WCP14_ETMSYNCFR r2
612
613 ; Program etm control register
614 ; - Set the CPU to ETM clock ratio to 1:1
615 ; - Set the ETM to perform data address tracing
616 MOV r2, #0x00002008
617 MCR p14, 1, r2, c0, c0, 0 ; WCP14_ETMCR r2
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800618 ISB
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800619#endif *//* APPSBL_ETM_ENABLE */
620
621/*
622#ifdef APPSBL_VFP_ENABLE
623 ;----------------------------------------------------------------------
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800624 ; Perform the following operations if you intend to make use of
625 ; the VFP/Neon unit. Note that the FMXR instruction requires a CPU ID
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800626 ; indicating the VFP unit is present (i.e.Cortex-A8). .
627 ; Some tools will require full double precision floating point support
628 ; which will become available in Scorpion pass 2
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800629 ;----------------------------------------------------------------------
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800630 ; allow full access to CP 10 and 11 space for VFP/NEON use
631 MRC p15, 0, r1, c1, c0, 2 ; Read CP Access Control Register
632 ORR r1, r1, #0x00F00000 ; enable full access for p10,11
633 MCR p15, 0, r1, c1, c0, 2 ; Write CPACR
634
635 ;make sure the CPACR is complete before continuing
636 ISB
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800637
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800638 ; Enable VFP itself (certain OSes may want to dynamically set/clear
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800639 ; the enable bit based on the application being executed
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800640 MOV r1, #0x40000000
641 FMXR FPEXC, r1
642#endif *//* APPSBL_VFP_ENABLE */
643
Ajay Dudani232ce812009-12-02 00:14:11 -0800644 /* we have no stack, so just tail-call into the SET_SA routine... */
645 b SET_SA
Ajay Dudaniae80c6e2009-11-28 14:15:03 -0800646
Brian Swetlanddfdb4612009-01-01 11:44:36 -0800647
648.ltorg