blob: 498cf7f600dfa32d2e4b985a42dd4ea8c94efad5 [file] [log] [blame]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +01001/*
2 * Most of this taken from Redboot hal_platform_setup.h with cleanup
3 *
4 * NOTE: I haven't clean this up considerably, just enough to get it
5 * running. See hal_platform_setup.h for the source. See
6 * board/cradle/lowlevel_init.S for another PXA250 setup that is
7 * much cleaner.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Wolfgang Denk951a9542006-03-06 23:18:48 +010019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010020 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <config.h>
29#include <version.h>
30#include <asm/arch/pxa-regs.h>
31
32DRAM_SIZE: .long CFG_DRAM_SIZE
33
34/* wait for coprocessor write complete */
Wolfgang Denk951a9542006-03-06 23:18:48 +010035.macro CPWAIT reg
36 mrc p15,0,\reg,c2,c0,0
37 mov \reg,\reg
38 sub pc,pc,#4
39.endm
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010040
41
42.macro wait time
Wolfgang Denk951a9542006-03-06 23:18:48 +010043 ldr r2, =OSCR
44 mov r3, #0
45 str r3, [r2]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100460:
Wolfgang Denk951a9542006-03-06 23:18:48 +010047 ldr r3, [r2]
48 cmp r3, \time
49 bls 0b
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010050.endm
Markus Klotzbücher48b62422006-02-22 00:06:01 +010051
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010052/*
Wolfgang Denk951a9542006-03-06 23:18:48 +010053 * Memory setup
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010054 */
55
56.globl lowlevel_init
57lowlevel_init:
58 /* Set up GPIO pins first ----------------------------------------- */
Wolfgang Denk951a9542006-03-06 23:18:48 +010059 mov r10, lr
60
61 /* Configure GPIO Pins 97, 98 UART1 / altern. Fkt. 1 */
Markus Klotzbücher48b62422006-02-22 00:06:01 +010062 ldr r0, =GPIO97
63 ldr r1, =0x801
64 str r1, [r0]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010065
Markus Klotzbücher48b62422006-02-22 00:06:01 +010066 ldr r0, =GPIO98
67 ldr r1, =0x801
68 str r1, [r0]
Wolfgang Denk951a9542006-03-06 23:18:48 +010069
70 /* tebrandt - ASCR, clear the RDH bit */
71 ldr r0, =ASCR
72 ldr r1, [r0]
73 bic r1, r1, #0x80000000
74 str r1, [r0]
75
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010076 /* ---------------------------------------------------------------- */
Wolfgang Denk951a9542006-03-06 23:18:48 +010077 /* Enable memory interface */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010078 /* ---------------------------------------------------------------- */
79
80 /* ---------------------------------------------------------------- */
Wolfgang Denk951a9542006-03-06 23:18:48 +010081 /* Step 1: Wait for at least 200 microsedonds to allow internal */
82 /* clocks to settle. Only necessary after hard reset... */
83 /* FIXME: can be optimized later */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010084 /* ---------------------------------------------------------------- */
Wolfgang Denk951a9542006-03-06 23:18:48 +010085; wait #300
86
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010087mem_init:
88
Markus Klotzbücher48b62422006-02-22 00:06:01 +010089#define NEW_SDRAM_INIT 1
90#ifdef NEW_SDRAM_INIT
91
92 /* Configure ACCR Register - enable DMEMC Clock at 260 / 2 MHz */
93 ldr r0, =ACCR
94 ldr r1, [r0]
95 orr r1, r1, #0x3000
96 str r1, [r0]
97 ldr r1, [r0]
98
99 /* 2. Programm MDCNFG, leaving DMCEN de-asserted */
100 ldr r0, =MDCNFG
101 ldr r1, =(MDCNFG_DMAP | MDCNFG_DTYPE | MDCNFG_DTC_2 | MDCNFG_DCSE0 | MDCNFG_DRAC_13)
Wolfgang Denk951a9542006-03-06 23:18:48 +0100102 /* ldr r1, =0x80000403 */
Markus Klotzbücher48b62422006-02-22 00:06:01 +0100103 str r1, [r0]
104 ldr r1, [r0] /* delay until written */
105
Wolfgang Denk951a9542006-03-06 23:18:48 +0100106 /* 3. wait nop power up waiting period (200ms)
Markus Klotzbücher48b62422006-02-22 00:06:01 +0100107 * optimization: Steps 4+6 can be done during this
108 */
109 wait #300
110
111 /* 4. Perform an initial Rcomp-calibration cycle */
112 ldr r0, =RCOMP
113 ldr r1, =0x80000000
114 str r1, [r0]
115 ldr r1, [r0] /* delay until written */
116 /* missing: program for automatic rcomp evaluation cycles */
117
118 /* 5. DDR DRAM strobe delay calibration */
119 ldr r0, =DDR_HCAL
120 ldr r1, =0x88000007
121 str r1, [r0]
122 wait #5
123 ldr r1, [r0] /* delay until written */
124
125 /* Set MDMRS */
126 ldr r0, =MDMRS
Markus Klotzbücherff3c2a92006-02-22 14:05:44 +0100127 ldr r1, =0x60000033
Markus Klotzbücher48b62422006-02-22 00:06:01 +0100128 str r1, [r0]
129 wait #300
Wolfgang Denk951a9542006-03-06 23:18:48 +0100130
Markus Klotzbücher48b62422006-02-22 00:06:01 +0100131 /* Configure MDREFR */
132 ldr r0, =MDREFR
133 ldr r1, =0x00000006
134 str r1, [r0]
135 ldr r1, [r0]
136
137 /* Enable the dynamic memory controller */
138 ldr r0, =MDCNFG
139 ldr r1, [r0]
140 orr r1, r1, #MDCNFG_DMCEN
141 str r1, [r0]
142
143
144#else /* NEW_SDRAM_INIT */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100145
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100146 /* configure the MEMCLKCFG register */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100147 ldr r1, =MEMCLKCFG
148 ldr r2, =0x00010001
149 str r2, [r1] @ WRITE
150 ldr r2, [r1] @ DELAY UNTIL WRITTEN
151
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100152 /* set CSADRCFG[0] to data flash SRAM mode */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100153 ldr r1, =CSADRCFG0
154 ldr r2, =0x00320809
155 str r2, [r1] @ WRITE
156 ldr r2, [r1] @ DELAY UNTIL WRITTEN
157
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100158 /* set CSADRCFG[1] to data flash SRAM mode */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100159 ldr r1, =CSADRCFG1
160 ldr r2, =0x00320809
161 str r2, [r1] @ WRITE
162 ldr r2, [r1] @ DELAY UNTIL WRITTEN
163
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100164 /* set MSC 0 register for SRAM memory */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100165 ldr r1, =MSC0
166 ldr r2, =0x11191119
167 str r2, [r1] @ WRITE
168 ldr r2, [r1] @ DELAY UNTIL WRITTEN
169
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100170 /* set CSADRCFG[2] to data flash SRAM mode */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100171 ldr r1, =CSADRCFG2
172 ldr r2, =0x00320809
173 str r2, [r1] @ WRITE
174 ldr r2, [r1] @ DELAY UNTIL WRITTEN
175
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100176 /* set CSADRCFG[3] to VLIO mode */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100177 ldr r1, =CSADRCFG3
178 ldr r2, =0x0032080B
179 str r2, [r1] @ WRITE
180 ldr r2, [r1] @ DELAY UNTIL WRITTEN
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100181
182 /* set MSC 1 register for VLIO memory */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100183 ldr r1, =MSC1
184 ldr r2, =0x123C1119
185 str r2, [r1] @ WRITE
186 ldr r2, [r1] @ DELAY UNTIL WRITTEN
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100187
188#if 0
189 /* This does not work in Zylonite. -SC */
190 ldr r0, =0x15fffff0
191 ldr r1, =0xb10b
192 str r1, [r0]
193 str r1, [r0, #4]
194#endif
195
196 /* Configure ACCR Register */
197 ldr r0, =ACCR @ ACCR
198 ldr r1, =0x0180b108
199 str r1, [r0]
200 ldr r1, [r0]
201
202 /* Configure MDCNFG Register */
203 ldr r0, =MDCNFG @ MDCNFG
204 ldr r1, =0x403
205 str r1, [r0]
206 ldr r1, [r0]
207
208 /* Perform Resistive Compensation by configuring RCOMP register */
209 ldr r1, =RCOMP @ RCOMP
210 ldr r2, =0x000000ff
211 str r2, [r1]
212 ldr r2, [r1]
213
214 /* Configure MDMRS Register for SDCS0 */
215 ldr r1, =MDMRS @ MDMRS
216 ldr r2, =0x60000023
217 ldr r3, [r1]
218 orr r2, r2, r3
219 str r2, [r1]
220 ldr r2, [r1]
221
222 /* Configure MDMRS Register for SDCS1 */
223 ldr r1, =MDMRS @ MDMRS
224 ldr r2, =0xa0000023
225 ldr r3, [r1]
226 orr r2, r2, r3
227 str r2, [r1]
228 ldr r2, [r1]
229
230 /* Configure MDREFR */
231 ldr r1, =MDREFR @ MDREFR
232 ldr r2, =0x00000006
233 str r2, [r1]
234 ldr r2, [r1]
235
236 /* Configure EMPI */
237 ldr r1, =EMPI @ EMPI
238 ldr r2, =0x80000000
239 str r2, [r1]
240 ldr r2, [r1]
241
242 /* Hardware DDR Read-Strobe Delay Calibration */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100243 ldr r0, =DDR_HCAL @ DDR_HCAL
244 ldr r1, =0x803ffc07 @ the offset is correct? -SC
245 str r1, [r0]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100246 wait #5
Wolfgang Denk951a9542006-03-06 23:18:48 +0100247 ldr r1, [r0]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100248
249 /* Here we assume the hardware calibration alwasy be successful. -SC */
250 /* Set DMCEN bit in MDCNFG Register */
251 ldr r0, =MDCNFG @ MDCNFG
252 ldr r1, [r0]
253 orr r1, r1, #0x40000000 @ enable SDRAM for Normal Access
254 str r1, [r0]
255
Markus Klotzbücher48b62422006-02-22 00:06:01 +0100256#endif /* NEW_SDRAM_INIT */
Wolfgang Denk951a9542006-03-06 23:18:48 +0100257
Markus Klotzbücherff3c2a92006-02-22 14:05:44 +0100258#ifndef CFG_SKIP_DRAM_SCRUB
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100259 /* scrub/init SDRAM if enabled/present */
Markus Klotzbücherff3c2a92006-02-22 14:05:44 +0100260 ldr r8, =CFG_DRAM_BASE /* base address of SDRAM (CFG_DRAM_BASE) */
261 ldr r9, =CFG_DRAM_SIZE /* size of memory to scrub (CFG_DRAM_SIZE) */
262 mov r0, #0 /* scrub with 0x0000:0000 */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100263 mov r1, #0
Wolfgang Denk951a9542006-03-06 23:18:48 +0100264 mov r2, #0
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100265 mov r3, #0
Wolfgang Denk951a9542006-03-06 23:18:48 +0100266 mov r4, #0
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100267 mov r5, #0
Wolfgang Denk951a9542006-03-06 23:18:48 +0100268 mov r6, #0
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100269 mov r7, #0
Wolfgang Denk951a9542006-03-06 23:18:48 +010027010: /* fastScrubLoop */
Markus Klotzbücherff3c2a92006-02-22 14:05:44 +0100271 subs r9, r9, #32 /* 8 words/line */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100272 stmia r8!, {r0-r7}
273 beq 15f
274 b 10b
Markus Klotzbücherff3c2a92006-02-22 14:05:44 +0100275#endif /* CFG_SKIP_DRAM_SCRUB */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100276
27715:
278 /* Mask all interrupts */
279 mov r1, #0
280 mcr p6, 0, r1, c1, c0, 0 @ ICMR
281
282 /* Disable software and data breakpoints */
283 mov r0, #0
Wolfgang Denk951a9542006-03-06 23:18:48 +0100284 mcr p15,0,r0,c14,c8,0 /* ibcr0 */
285 mcr p15,0,r0,c14,c9,0 /* ibcr1 */
286 mcr p15,0,r0,c14,c4,0 /* dbcon */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100287
288 /* Enable all debug functionality */
289 mov r0,#0x80000000
Wolfgang Denk951a9542006-03-06 23:18:48 +0100290 mcr p14,0,r0,c10,c0,0 /* dcsr */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100291
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100292endlowlevel_init:
293
Wolfgang Denk951a9542006-03-06 23:18:48 +0100294 mov pc, lr
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100295
296
297/*
298@********************************************************************************
299@ DDR calibration
Wolfgang Denk951a9542006-03-06 23:18:48 +0100300@
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100301@ This function is used to calibrate DQS delay lines.
Wolfgang Denk951a9542006-03-06 23:18:48 +0100302@ Monahans supports three ways to do it. One is software
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100303@ calibration. Two is hardware calibration. Three is hybrid
304@ calibration.
305@
306@ TBD
307@ -SC
308ddr_calibration:
309
310 @ Case 1: Write the correct delay value once
Wolfgang Denk951a9542006-03-06 23:18:48 +0100311 @ Configure DDR_SCAL Register
312 ldr r0, =DDR_SCAL @ DDR_SCAL
313q ldr r1, =0xaf2f2f2f
314 str r1, [r0]
315 ldr r1, [r0]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100316*/
317/* @ Case 2: Software Calibration
318 @ Write test pattern to memory
Wolfgang Denk951a9542006-03-06 23:18:48 +0100319 ldr r5, =0x0faf0faf @ Data Pattern
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100320 ldr r4, =0xa0000000 @ DDR ram
321 str r5, [r4]
322
323 mov r1, =0x0 @ delay count
324 mov r6, =0x0
325 mov r7, =0x0
326ddr_loop1:
327 add r1, r1, =0x1
328 cmp r1, =0xf
329 ble end_loop
330 mov r3, r1
Wolfgang Denk951a9542006-03-06 23:18:48 +0100331 mov r0, r1, lsl #30
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100332 orr r3, r3, r0
Wolfgang Denk951a9542006-03-06 23:18:48 +0100333 mov r0, r1, lsl #22
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100334 orr r3, r3, r0
Wolfgang Denk951a9542006-03-06 23:18:48 +0100335 mov r0, r1, lsl #14
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100336 orr r3, r3, r0
337 orr r3, r3, =0x80000000
338 ldr r2, =DDR_SCAL
339 str r3, [r2]
340
341 ldr r2, [r4]
342 cmp r2, r5
343 bne ddr_loop1
344 mov r6, r1
345ddr_loop2:
346 add r1, r1, =0x1
347 cmp r1, =0xf
348 ble end_loop
Wolfgang Denk951a9542006-03-06 23:18:48 +0100349 mov r3, r1
350 mov r0, r1, lsl #30
351 orr r3, r3, r0
352 mov r0, r1, lsl #22
353 orr r3, r3, r0
354 mov r0, r1, lsl #14
355 orr r3, r3, r0
356 orr r3, r3, =0x80000000
357 ldr r2, =DDR_SCAL
358 str r3, [r2]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100359
360 ldr r2, [r4]
361 cmp r2, r5
362 be ddr_loop2
363 mov r7, r2
364
365 add r3, r6, r7
366 lsr r3, r3, =0x1
Wolfgang Denk951a9542006-03-06 23:18:48 +0100367 mov r0, r1, lsl #30
368 orr r3, r3, r0
369 mov r0, r1, lsl #22
370 orr r3, r3, r0
371 mov r0, r1, lsl #14
372 orr r3, r3, r0
373 orr r3, r3, =0x80000000
374 ldr r2, =DDR_SCAL
375
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100376end_loop:
377
378 @ Case 3: Hardware Calibratoin
Wolfgang Denk951a9542006-03-06 23:18:48 +0100379 ldr r0, =DDR_HCAL @ DDR_HCAL
380 ldr r1, =0x803ffc07 @ the offset is correct? -SC
381 str r1, [r0]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100382 wait #5
Wolfgang Denk951a9542006-03-06 23:18:48 +0100383 ldr r1, [r0]
384 mov pc, lr
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100385*/