35716f245efcead117b57388bda8cae4b9fa5e5d
[platform/kernel/u-boot.git] / board / delta / lowlevel_init.S
1 /*
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
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * 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
32 DRAM_SIZE:  .long   CFG_DRAM_SIZE
33
34 /* wait for coprocessor write complete */
35    .macro CPWAIT reg
36    mrc  p15,0,\reg,c2,c0,0
37    mov  \reg,\reg
38    sub  pc,pc,#4
39    .endm
40
41
42 .macro wait time
43         ldr             r2, =OSCR
44         mov             r3, #0
45         str             r3, [r2]
46 0:
47         ldr             r3, [r2]
48         cmp             r3, \time
49         bls             0b
50 .endm
51
52
53 #define SDRAM_CMD_NOP   0x40000000
54
55 .macro do_nop_cmd num
56         ldr             r2, =MDMRS
57         ldr             r3, =SDRAM_CMD_NOP
58         ldr             r4, =0x0
59 loop:   
60         str             r3, [r2]
61         add             r4, r4, #1
62         cmp             r4, \num
63         bls             loop
64 .endm
65         
66 /*
67  *      Memory setup
68  */
69
70 .globl lowlevel_init
71 lowlevel_init:
72         /* Set up GPIO pins first ----------------------------------------- */
73         mov      r10, lr
74         
75         /*  Configure GPIO  Pins 97, 98 UART1 / altern. Fkt. 1 */
76         ldr             r0, =GPIO97
77         ldr             r1, =0x801
78         str             r1, [r0]
79
80         ldr             r0, =GPIO98
81         ldr             r1, =0x801
82         str             r1, [r0]
83                 
84         /* tebrandt - ASCR, clear the RDH bit */
85         ldr             r0, =ASCR       
86         ldr             r1, [r0]
87         bic             r1, r1, #0x80000000
88         str             r1, [r0]
89         
90         /* ---------------------------------------------------------------- */
91         /* Enable memory interface                                          */
92         /* ---------------------------------------------------------------- */
93
94         /* ---------------------------------------------------------------- */
95         /* Step 1: Wait for at least 200 microsedonds to allow internal     */
96         /*         clocks to settle. Only necessary after hard reset...     */
97         /*         FIXME: can be optimized later                            */
98         /* ---------------------------------------------------------------- */
99         wait #300
100         
101 mem_init:
102
103 #define NEW_SDRAM_INIT 1
104 #ifdef NEW_SDRAM_INIT
105
106         /* Configure ACCR Register - enable DMEMC Clock at 260 / 2 MHz */
107         ldr             r0, =ACCR
108         ldr             r1, [r0]
109         orr             r1, r1, #0x3000
110         str             r1, [r0]
111         ldr             r1, [r0]
112
113         /* 2. Programm MDCNFG, leaving DMCEN de-asserted */
114         ldr             r0, =MDCNFG
115         ldr             r1, =(MDCNFG_DMAP | MDCNFG_DTYPE | MDCNFG_DTC_2 | MDCNFG_DCSE0 | MDCNFG_DRAC_13)
116         /*      ldr             r1, =0x80000403 */
117         str             r1, [r0]
118         ldr             r1, [r0]        /* delay until written */
119
120         /* 3. wait nop power up waiting period (200ms) 
121          * optimization: Steps 4+6 can be done during this
122          */
123         wait #300
124
125         /* 4. Perform an initial Rcomp-calibration cycle */
126         ldr             r0, =RCOMP
127         ldr             r1, =0x80000000
128         str             r1, [r0]
129         ldr             r1, [r0]        /* delay until written */
130         /* missing: program for automatic rcomp evaluation cycles */
131
132         /* 5. DDR DRAM strobe delay calibration */
133         ldr             r0, =DDR_HCAL
134         ldr             r1, =0x88000007
135         str             r1, [r0]
136         wait            #5
137         ldr             r1, [r0]        /* delay until written */
138
139         /* Set MDMRS */
140         ldr             r0, =MDMRS
141         ldr             r1, =0x60000023
142         str             r1, [r0]
143         wait    #300
144         
145         /* Configure MDREFR */
146         ldr             r0, =MDREFR
147         ldr             r1, =0x00000006
148         str             r1, [r0]
149         ldr             r1, [r0]
150
151         /* Enable the dynamic memory controller */
152         ldr             r0, =MDCNFG
153         ldr             r1, [r0]
154         orr             r1, r1, #MDCNFG_DMCEN
155         str             r1, [r0]
156
157
158 #else /* NEW_SDRAM_INIT */
159         
160         /* configure the MEMCLKCFG register */
161         ldr             r1, =MEMCLKCFG
162         ldr             r2, =0x00010001
163         str             r2, [r1]             @ WRITE
164         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
165         
166         /* set CSADRCFG[0] to data flash SRAM mode */
167         ldr             r1, =CSADRCFG0
168         ldr             r2, =0x00320809
169         str             r2, [r1]             @ WRITE
170         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
171         
172         /* set CSADRCFG[1] to data flash SRAM mode */
173         ldr             r1, =CSADRCFG1
174         ldr             r2, =0x00320809
175         str             r2, [r1]             @ WRITE
176         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
177         
178         /* set MSC 0 register for SRAM memory */
179         ldr             r1, =MSC0
180         ldr             r2, =0x11191119
181         str             r2, [r1]             @ WRITE
182         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
183          
184         /* set CSADRCFG[2] to data flash SRAM mode */
185         ldr             r1, =CSADRCFG2
186         ldr             r2, =0x00320809
187         str             r2, [r1]             @ WRITE
188         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
189         
190         /* set CSADRCFG[3] to VLIO mode */
191         ldr             r1, =CSADRCFG3
192         ldr             r2, =0x0032080B
193         str             r2, [r1]             @ WRITE
194         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
195
196         /* set MSC 1 register for VLIO memory */
197         ldr             r1, =MSC1
198         ldr             r2, =0x123C1119
199         str             r2, [r1]             @ WRITE
200         ldr             r2, [r1]             @ DELAY UNTIL WRITTEN
201
202 #if 0
203         /* This does not work in Zylonite. -SC */
204         ldr             r0, =0x15fffff0
205         ldr             r1, =0xb10b
206         str             r1, [r0]
207         str             r1, [r0, #4]
208 #endif
209
210         /* Configure ACCR Register */
211         ldr             r0, =ACCR               @ ACCR
212         ldr             r1, =0x0180b108
213         str             r1, [r0]
214         ldr             r1, [r0]
215
216         /* Configure MDCNFG Register */
217         ldr             r0, =MDCNFG             @ MDCNFG
218         ldr             r1, =0x403
219         str             r1, [r0]
220         ldr             r1, [r0]
221
222         /* Perform Resistive Compensation by configuring RCOMP register */
223         ldr             r1, =RCOMP              @ RCOMP
224         ldr             r2, =0x000000ff
225         str             r2, [r1]
226         ldr             r2, [r1]
227
228         /* Configure MDMRS Register for SDCS0 */
229         ldr             r1, =MDMRS              @ MDMRS
230         ldr             r2, =0x60000023
231         ldr             r3, [r1]
232         orr             r2, r2, r3
233         str             r2, [r1]
234         ldr             r2, [r1]
235
236         /* Configure MDMRS Register for SDCS1 */
237         ldr             r1, =MDMRS              @ MDMRS
238         ldr             r2, =0xa0000023
239         ldr             r3, [r1]
240         orr             r2, r2, r3
241         str             r2, [r1]
242         ldr             r2, [r1]
243
244         /* Configure MDREFR */
245         ldr             r1, =MDREFR             @ MDREFR
246         ldr             r2, =0x00000006
247         str             r2, [r1]
248         ldr             r2, [r1]
249
250         /* Configure EMPI */
251         ldr             r1, =EMPI               @ EMPI
252         ldr             r2, =0x80000000
253         str             r2, [r1]
254         ldr             r2, [r1]
255
256         /* Hardware DDR Read-Strobe Delay Calibration */
257         ldr             r0, =DDR_HCAL           @ DDR_HCAL
258         ldr             r1, =0x803ffc07     @ the offset is correct? -SC
259         str             r1, [r0]
260         wait            #5
261         ldr             r1, [r0]
262
263         /* Here we assume the hardware calibration alwasy be successful. -SC */
264         /* Set DMCEN bit in MDCNFG Register */
265         ldr             r0, =MDCNFG             @ MDCNFG
266         ldr             r1, [r0]
267         orr             r1, r1, #0x40000000     @ enable SDRAM for Normal Access
268         str             r1, [r0]
269
270 #endif /* NEW_SDRAM_INIT */
271         
272         /* scrub/init SDRAM if enabled/present */
273 /*      ldr     r11, =0xa0000000 /\* base address of SDRAM (CFG_DRAM_BASE) *\/ */
274 /*      ldr     r12, =0x04000000 /\* size of memory to scrub (CFG_DRAM_SIZE) *\/ */
275 /*      mov     r8,r12           /\* save DRAM size (mk: why???) *\/ */
276         ldr     r8, =0xa0000000  /* base address of SDRAM (CFG_DRAM_BASE) */
277         ldr     r9, =0x04000000  /* size of memory to scrub (CFG_DRAM_SIZE) */
278         mov     r0, #0           /* scrub with 0x0000:0000 */
279         mov     r1, #0
280         mov     r2, #0                          
281         mov     r3, #0
282         mov     r4, #0                                  
283         mov     r5, #0
284         mov     r6, #0                                  
285         mov     r7, #0
286 10:     /* fastScrubLoop */
287         subs    r9, r9, #32     // 32 bytes/line
288         stmia   r8!, {r0-r7}
289         beq     15f
290         b       10b
291
292 15:
293         /* Mask all interrupts */
294         mov     r1, #0
295         mcr     p6, 0, r1, c1, c0, 0    @ ICMR
296
297         /* Disable software and data breakpoints */
298         mov     r0, #0
299         mcr     p15,0,r0,c14,c8,0  // ibcr0
300         mcr     p15,0,r0,c14,c9,0  // ibcr1
301         mcr     p15,0,r0,c14,c4,0  // dbcon
302
303         /* Enable all debug functionality */
304         mov     r0,#0x80000000
305         mcr     p14,0,r0,c10,c0,0  // dcsr
306
307 endlowlevel_init:
308
309         mov     pc, lr
310
311
312 /*
313 @********************************************************************************
314 @ DDR calibration
315 @  
316 @  This function is used to calibrate DQS delay lines.
317 @ Monahans supports three ways to do it. One is software 
318 @ calibration. Two is hardware calibration. Three is hybrid
319 @ calibration.
320 @
321 @ TBD
322 @ -SC
323 ddr_calibration:
324
325         @ Case 1:       Write the correct delay value once
326         @ Configure DDR_SCAL Register
327         ldr             r0, =DDR_SCAL           @ DDR_SCAL
328 q       ldr             r1, =0xaf2f2f2f
329         str             r1, [r0]
330         ldr             r1, [r0]
331 */
332 /*      @ Case 2:       Software Calibration
333         @ Write test pattern to memory
334         ldr             r5, =0x0faf0faf         @ Data Pattern
335         ldr             r4, =0xa0000000         @ DDR ram
336         str             r5, [r4]
337
338         mov             r1, =0x0                @ delay count
339         mov             r6, =0x0
340         mov             r7, =0x0
341 ddr_loop1:
342         add             r1, r1, =0x1
343         cmp             r1, =0xf
344         ble             end_loop
345         mov             r3, r1
346         mov             r0, r1, lsl #30
347         orr             r3, r3, r0
348         mov             r0, r1, lsl #22
349         orr             r3, r3, r0
350         mov             r0, r1, lsl #14
351         orr             r3, r3, r0
352         orr             r3, r3, =0x80000000
353         ldr             r2, =DDR_SCAL
354         str             r3, [r2]
355
356         ldr             r2, [r4]
357         cmp             r2, r5
358         bne             ddr_loop1
359         mov             r6, r1
360 ddr_loop2:
361         add             r1, r1, =0x1
362         cmp             r1, =0xf
363         ble             end_loop
364         mov             r3, r1
365         mov             r0, r1, lsl #30
366         orr             r3, r3, r0
367         mov             r0, r1, lsl #22
368         orr             r3, r3, r0
369         mov             r0, r1, lsl #14
370         orr             r3, r3, r0
371         orr             r3, r3, =0x80000000
372         ldr             r2, =DDR_SCAL
373         str             r3, [r2]
374
375         ldr             r2, [r4]
376         cmp             r2, r5
377         be              ddr_loop2
378         mov             r7, r2
379
380         add             r3, r6, r7
381         lsr             r3, r3, =0x1
382         mov             r0, r1, lsl #30
383         orr             r3, r3, r0
384         mov             r0, r1, lsl #22
385         orr             r3, r3, r0
386         mov             r0, r1, lsl #14
387         orr             r3, r3, r0
388         orr             r3, r3, =0x80000000
389         ldr             r2, =DDR_SCAL
390         
391 end_loop:
392
393         @ Case 3:       Hardware Calibratoin
394         ldr             r0, =DDR_HCAL           @ DDR_HCAL
395         ldr             r1, =0x803ffc07     @ the offset is correct? -SC
396         str             r1, [r0]
397         wait            #5
398         ldr             r1, [r0]
399         mov             pc, lr  
400 */