]> git.sur5r.net Git - u-boot/blob - cpu/arm926ejs/davinci/lowlevel_init.S
Removes all board specific code from the arch. part for DM644x (DaVinci) boards
[u-boot] / cpu / arm926ejs / davinci / lowlevel_init.S
1 /*
2  * Low-level board setup code for TI DaVinci SoC based boards.
3  *
4  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
5  *
6  * Copyright (C) 2008 Prodrive BV <pv@prodrive.nl>
7  * Changed:
8  * Made board specific defines such as DDR timing and PLL
9  * dividers. These should be set in the board config file
10  *
11  * Partially based on TI sources, original copyrights follow:
12  */
13
14 /*
15  * Board specific setup info
16  *
17  * (C) Copyright 2003
18  * Texas Instruments, <www.ti.com>
19  * Kshitij Gupta <Kshitij@ti.com>
20  *
21  * Modified for OMAP 1610 H2 board by Nishant Kamat, Jan 2004
22  *
23  * Modified for OMAP 5912 OSK board by Rishi Bhattacharya, Apr 2004
24  * See file CREDITS for list of people who contributed to this
25  * project.
26  *
27  * Modified for DV-EVM board by Rishi Bhattacharya, Apr 2005
28  * See file CREDITS for list of people who contributed to this
29  * project.
30  *
31  * Modified for DV-EVM board by Swaminathan S, Nov 2005
32  * See file CREDITS for list of people who contributed to this
33  * project.
34  *
35  * This program is free software; you can redistribute it and/or
36  * modify it under the terms of the GNU General Public License as
37  * published by the Free Software Foundation; either version 2 of
38  * the License, or (at your option) any later version.
39  *
40  * This program is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43  * GNU General Public License for more details.
44  *
45  * You should have received a copy of the GNU General Public License
46  * along with this program; if not, write to the Free Software
47  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
48  * MA 02111-1307 USA
49  */
50
51 #include <config.h>
52
53 .globl  lowlevel_init
54 lowlevel_init:
55
56         /*-------------------------------------------------------*
57          * Mask all IRQs by setting all bits in the EINT default *
58          *-------------------------------------------------------*/
59         mov     r1, $0
60         ldr     r0, =EINT_ENABLE0
61         str     r1, [r0]
62         ldr     r0, =EINT_ENABLE1
63         str     r1, [r0]
64
65         /*------------------------------------------------------*
66          * Put the GEM in reset                                 *
67          *------------------------------------------------------*/
68
69         /* Put the GEM in reset */
70         ldr     r8, PSC_GEM_FLAG_CLEAR
71         ldr     r6, MDCTL_GEM
72         ldr     r7, [r6]
73         and     r7, r7, r8
74         str     r7, [r6]
75
76         /* Enable the Power Domain Transition Command */
77         ldr     r6, PTCMD
78         ldr     r7, [r6]
79         orr     r7, r7, $0x02
80         str     r7, [r6]
81
82         /* Check for Transition Complete(PTSTAT) */
83 checkStatClkStopGem:
84         ldr     r6, PTSTAT
85         ldr     r7, [r6]
86         ands    r7, r7, $0x02
87         bne     checkStatClkStopGem
88
89         /* Check for GEM Reset Completion */
90 checkGemStatClkStop:
91         ldr     r6, MDSTAT_GEM
92         ldr     r7, [r6]
93         ands    r7, r7, $0x100
94         bne     checkGemStatClkStop
95
96         /* Do this for enabling a WDT initiated reset this is a workaround
97            for a chip bug.  Not required under normal situations */
98         ldr     r6, P1394
99         mov     r10, $0
100         str     r10, [r6]
101
102         /*------------------------------------------------------*
103          * Enable L1 & L2 Memories in Fast mode                 *
104          *------------------------------------------------------*/
105         ldr     r6, DFT_ENABLE
106         mov     r10, $0x01
107         str     r10, [r6]
108
109         ldr     r6, MMARG_BRF0
110         ldr     r10, MMARG_BRF0_VAL
111         str     r10, [r6]
112
113         ldr     r6, DFT_ENABLE
114         mov     r10, $0
115         str     r10, [r6]
116
117         /*------------------------------------------------------*
118          * DDR2 PLL Initialization                              *
119          *------------------------------------------------------*/
120
121         /* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
122         mov     r10, $0
123         ldr     r6, PLL2_CTL
124         ldr     r7, PLL_CLKSRC_MASK
125         ldr     r8, [r6]
126         and     r8, r8, r7
127         mov     r9, r10, lsl $8
128         orr     r8, r8, r9
129         str     r8, [r6]
130
131         /* Select the PLLEN source */
132         ldr     r7, PLL_ENSRC_MASK
133         and     r8, r8, r7
134         str     r8, [r6]
135
136         /* Bypass the PLL */
137         ldr     r7, PLL_BYPASS_MASK
138         and     r8, r8, r7
139         str     r8, [r6]
140
141         /* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
142         mov     r10, $0x20
143 WaitPPL2Loop:
144         subs    r10, r10, $1
145         bne     WaitPPL2Loop
146
147         /* Reset the PLL */
148         ldr     r7, PLL_RESET_MASK
149         and     r8, r8, r7
150         str     r8, [r6]
151
152         /* Power up the PLL */
153         ldr     r7, PLL_PWRUP_MASK
154         and     r8, r8, r7
155         str     r8, [r6]
156
157         /* Enable the PLL from Disable Mode */
158         ldr     r7, PLL_DISABLE_ENABLE_MASK
159         and     r8, r8, r7
160         str     r8, [r6]
161
162         /* Program the PLL Multiplier */
163         ldr     r6, PLL2_PLLM
164         mov     r2, $CFG_DAVINCI_PLL2_PLLM
165         str     r2, [r6]
166
167         /* Program the PLL2 Divisor Value */
168         ldr     r6, PLL2_DIV2
169         mov     r3, $CFG_DAVINCI_PLL2_DIV2
170         str     r3, [r6]
171
172         /* Program the PLL2 Divisor Value */
173         ldr     r6, PLL2_DIV1
174         mov     r4, $CFG_DAVINCI_PLL2_DIV1
175         str     r4, [r6]
176
177         /* PLL2 DIV2 MMR */
178         ldr     r8, PLL2_DIV_MASK
179         ldr     r6, PLL2_DIV2
180         ldr     r9, [r6]
181         and     r8, r8, r9
182         mov     r9, $0x01
183         mov     r9, r9, lsl $15
184         orr     r8, r8, r9
185         str     r8, [r6]
186
187         /* Program the GOSET bit to take new divider values */
188         ldr     r6, PLL2_PLLCMD
189         ldr     r7, [r6]
190         orr     r7, r7, $0x01
191         str     r7, [r6]
192
193         /* Wait for Done */
194         ldr     r6, PLL2_PLLSTAT
195 doneLoop_0:
196         ldr     r7, [r6]
197         ands    r7, r7, $0x01
198         bne     doneLoop_0
199
200         /* PLL2 DIV1 MMR */
201         ldr     r8, PLL2_DIV_MASK
202         ldr     r6, PLL2_DIV1
203         ldr     r9, [r6]
204         and     r8, r8, r9
205         mov     r9, $0x01
206         mov     r9, r9, lsl $15
207         orr     r8, r8, r9
208         str     r8, [r6]
209
210         /* Program the GOSET bit to take new divider values */
211         ldr     r6, PLL2_PLLCMD
212         ldr     r7, [r6]
213         orr     r7, r7, $0x01
214         str     r7, [r6]
215
216         /* Wait for Done */
217         ldr     r6, PLL2_PLLSTAT
218 doneLoop:
219         ldr     r7, [r6]
220         ands    r7, r7, $0x01
221         bne     doneLoop
222
223         /* Wait for PLL to Reset Properly */
224         mov     r10, $0x218
225 ResetPPL2Loop:
226         subs    r10, r10, $1
227         bne     ResetPPL2Loop
228
229         /* Bring PLL out of Reset */
230         ldr     r6, PLL2_CTL
231         ldr     r8, [r6]
232         orr     r8, r8, $0x08
233         str     r8, [r6]
234
235         /* Wait for PLL to Lock */
236         ldr     r10, PLL_LOCK_COUNT
237 PLL2Lock:
238         subs    r10, r10, $1
239         bne     PLL2Lock
240
241         /* Enable the PLL */
242         ldr     r6, PLL2_CTL
243         ldr     r8, [r6]
244         orr     r8, r8, $0x01
245         str     r8, [r6]
246
247         /*------------------------------------------------------*
248          * Issue Soft Reset to DDR Module                       *
249          *------------------------------------------------------*/
250
251         /* Shut down the DDR2 LPSC Module */
252         ldr     r8, PSC_FLAG_CLEAR
253         ldr     r6, MDCTL_DDR2
254         ldr     r7, [r6]
255         and     r7, r7, r8
256         orr     r7, r7, $0x03
257         str     r7, [r6]
258
259         /* Enable the Power Domain Transition Command */
260         ldr     r6, PTCMD
261         ldr     r7, [r6]
262         orr     r7, r7, $0x01
263         str     r7, [r6]
264
265         /* Check for Transition Complete(PTSTAT) */
266 checkStatClkStop:
267         ldr     r6, PTSTAT
268         ldr     r7, [r6]
269         ands    r7, r7, $0x01
270         bne     checkStatClkStop
271
272         /* Check for DDR2 Controller Enable Completion */
273 checkDDRStatClkStop:
274         ldr     r6, MDSTAT_DDR2
275         ldr     r7, [r6]
276         and     r7, r7, $0x1f
277         cmp     r7, $0x03
278         bne     checkDDRStatClkStop
279
280         /*------------------------------------------------------*
281          * Program DDR2 MMRs                                    *
282          *------------------------------------------------------*/
283
284         /* Program PHY Control Register */
285         ldr     r6, DDRCTL
286         ldr     r7, DDRCTL_VAL
287         str     r7, [r6]
288
289         /* Program SDRAM Bank Config Register */
290         ldr     r6, SDCFG
291         ldr     r7, SDCFG_VAL
292         str     r7, [r6]
293
294         /* Program SDRAM TIM-0 Config Register */
295         ldr     r6, SDTIM0
296         ldr     r7, SDTIM0_VAL
297         str     r7, [r6]
298
299         /* Program SDRAM TIM-1 Config Register */
300         ldr     r6, SDTIM1
301         ldr     r7, SDTIM1_VAL
302         str     r7, [r6]
303
304         /* Program the SDRAM Bank Config Control Register */
305         ldr     r10, MASK_VAL
306         ldr     r8, SDCFG
307         ldr     r9, SDCFG_VAL
308         and     r9, r9, r10
309         str     r9, [r8]
310
311         /* Program SDRAM SDREF Config Register */
312         ldr     r6, SDREF
313         ldr     r7, SDREF_VAL
314         str     r7, [r6]
315
316         /*------------------------------------------------------*
317          * Issue Soft Reset to DDR Module                       *
318          *------------------------------------------------------*/
319
320         /* Issue a Dummy DDR2 read/write */
321         ldr     r8, DDR2_START_ADDR
322         ldr     r7, DUMMY_VAL
323         str     r7, [r8]
324         ldr     r7, [r8]
325
326         /* Shut down the DDR2 LPSC Module */
327         ldr     r8, PSC_FLAG_CLEAR
328         ldr     r6, MDCTL_DDR2
329         ldr     r7, [r6]
330         and     r7, r7, r8
331         orr     r7, r7, $0x01
332         str     r7, [r6]
333
334         /* Enable the Power Domain Transition Command */
335         ldr     r6, PTCMD
336         ldr     r7, [r6]
337         orr     r7, r7, $0x01
338         str     r7, [r6]
339
340         /* Check for Transition Complete(PTSTAT) */
341 checkStatClkStop2:
342         ldr     r6, PTSTAT
343         ldr     r7, [r6]
344         ands    r7, r7, $0x01
345         bne     checkStatClkStop2
346
347         /* Check for DDR2 Controller Enable Completion */
348 checkDDRStatClkStop2:
349         ldr     r6, MDSTAT_DDR2
350         ldr     r7, [r6]
351         and     r7, r7, $0x1f
352         cmp     r7, $0x01
353         bne     checkDDRStatClkStop2
354
355         /*------------------------------------------------------*
356          * Turn DDR2 Controller Clocks On                       *
357          *------------------------------------------------------*/
358
359         /* Enable the DDR2 LPSC Module */
360         ldr     r6, MDCTL_DDR2
361         ldr     r7, [r6]
362         orr     r7, r7, $0x03
363         str     r7, [r6]
364
365         /* Enable the Power Domain Transition Command */
366         ldr     r6, PTCMD
367         ldr     r7, [r6]
368         orr     r7, r7, $0x01
369         str     r7, [r6]
370
371         /* Check for Transition Complete(PTSTAT) */
372 checkStatClkEn2:
373         ldr     r6, PTSTAT
374         ldr     r7, [r6]
375         ands    r7, r7, $0x01
376         bne     checkStatClkEn2
377
378         /* Check for DDR2 Controller Enable Completion */
379 checkDDRStatClkEn2:
380         ldr     r6, MDSTAT_DDR2
381         ldr     r7, [r6]
382         and     r7, r7, $0x1f
383         cmp     r7, $0x03
384         bne     checkDDRStatClkEn2
385
386         /*  DDR Writes and Reads */
387         ldr     r6, CFGTEST
388         mov     r3, $0x01
389         str     r3, [r6]
390
391         /*------------------------------------------------------*
392          * System PLL Initialization                            *
393          *------------------------------------------------------*/
394
395         /* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
396         mov     r2, $0
397         ldr     r6, PLL1_CTL
398         ldr     r7, PLL_CLKSRC_MASK
399         ldr     r8, [r6]
400         and     r8, r8, r7
401         mov     r9, r2, lsl $8
402         orr     r8, r8, r9
403         str     r8, [r6]
404
405         /* Select the PLLEN source */
406         ldr     r7, PLL_ENSRC_MASK
407         and     r8, r8, r7
408         str     r8, [r6]
409
410         /* Bypass the PLL */
411         ldr     r7, PLL_BYPASS_MASK
412         and     r8, r8, r7
413         str     r8, [r6]
414
415         /* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
416         mov     r10, $0x20
417
418 WaitLoop:
419         subs    r10, r10, $1
420         bne     WaitLoop
421
422         /* Reset the PLL */
423         ldr     r7, PLL_RESET_MASK
424         and     r8, r8, r7
425         str     r8, [r6]
426
427         /* Disable the PLL */
428         orr     r8, r8, $0x10
429         str     r8, [r6]
430
431         /* Power up the PLL */
432         ldr     r7, PLL_PWRUP_MASK
433         and     r8, r8, r7
434         str     r8, [r6]
435
436         /* Enable the PLL from Disable Mode */
437         ldr     r7, PLL_DISABLE_ENABLE_MASK
438         and     r8, r8, r7
439         str     r8, [r6]
440
441         /* Program the PLL Multiplier */
442         ldr     r6, PLL1_PLLM
443         mov     r3, $CFG_DAVINCI_PLL1_PLLM
444         str     r3, [r6]
445
446         /* Wait for PLL to Reset Properly */
447         mov     r10, $0xff
448
449 ResetLoop:
450         subs    r10, r10, $1
451         bne     ResetLoop
452
453         /* Bring PLL out of Reset */
454         ldr     r6, PLL1_CTL
455         orr     r8, r8, $0x08
456         str     r8, [r6]
457
458         /* Wait for PLL to Lock */
459         ldr     r10, PLL_LOCK_COUNT
460
461 PLL1Lock:
462         subs    r10, r10, $1
463         bne     PLL1Lock
464
465         /* Enable the PLL */
466         orr     r8, r8, $0x01
467         str     r8, [r6]
468
469         nop
470         nop
471         nop
472         nop
473
474         /*------------------------------------------------------*
475          * AEMIF configuration for NAND/NOR Flash               *
476          *------------------------------------------------------*/
477         ldr     r0, _PINMUX0
478         ldr     r1, _DEV_SETTING
479         str     r1, [r0]
480
481         ldr     r0, WAITCFG
482         ldr     r1, WAITCFG_VAL
483         ldr     r2, [r0]
484         orr     r2, r2, r1
485         str     r2, [r0]
486
487         ldr     r0, ACFG2
488         ldr     r1, ACFG2_VAL
489         ldr     r2, [r0]
490         and     r1, r2, r1
491         str     r1, [r0]
492
493         ldr     r0, ACFG3
494         ldr     r1, ACFG3_VAL
495         ldr     r2, [r0]
496         and     r1, r2, r1
497         str     r1, [r0]
498
499         ldr     r0, ACFG4
500         ldr     r1, ACFG4_VAL
501         ldr     r2, [r0]
502         and     r1, r2, r1
503         str     r1, [r0]
504
505         ldr     r0, ACFG5
506         ldr     r1, ACFG5_VAL
507         ldr     r2, [r0]
508         and     r1, r2, r1
509         str     r1, [r0]
510
511         ldr     r0, NANDFCR
512         ldr     r1, NANDFCR_VAL
513         ldr     r2, [r0]
514         and     r1, r2, r1
515         str     r1, [r0]
516
517         /*--------------------------------------*
518          * VTP manual Calibration               *
519          *--------------------------------------*/
520         ldr     r0, VTPIOCR
521         ldr     r1, VTP_MMR0
522         str     r1, [r0]
523
524         ldr     r0, VTPIOCR
525         ldr     r1, VTP_MMR1
526         str     r1, [r0]
527
528         /* Wait for 33 VTP CLK cycles.  VRP operates at 27 MHz */
529         ldr     r10, VTP_LOCK_COUNT
530 VTPLock:
531         subs    r10, r10, $1
532         bne     VTPLock
533
534         ldr     r6, DFT_ENABLE
535         mov     r10, $0x01
536         str     r10, [r6]
537
538         ldr     r6, DDRVTPR
539         ldr     r7, [r6]
540         and     r7, r7, $0x1f
541         and     r8, r7, $0x3e0
542         orr     r8, r7, r8
543         ldr     r7, VTP_RECAL
544         orr     r8, r7, r8
545         ldr     r7, VTP_EN
546         orr     r8, r7, r8
547         str     r8, [r0]
548
549
550         /* Wait for 33 VTP CLK cycles.  VRP operates at 27 MHz */
551         ldr     r10, VTP_LOCK_COUNT
552 VTP1Lock:
553         subs    r10, r10, $1
554         bne     VTP1Lock
555
556         ldr     r1, [r0]
557         ldr     r2, VTP_MASK
558         and     r2, r1, r2
559         str     r2, [r0]
560
561         ldr     r6, DFT_ENABLE
562         mov     r10, $0
563         str     r10, [r6]
564
565         /*
566          * Call board-specific lowlevel init.
567          * That MUST be present and THAT returns
568          * back to arch calling code with "mov pc, lr."
569          */
570         b       dv_board_init
571
572 .ltorg
573
574 _PINMUX0:
575         .word   0x01c40000              /* Device Configuration Registers */
576 _PINMUX1:
577         .word   0x01c40004              /* Device Configuration Registers */
578
579 _DEV_SETTING:
580         .word   CFG_DAVINCI_PINMUX_0
581
582 WAITCFG:
583         .word   0x01e00004
584 WAITCFG_VAL:
585         .word   CFG_DAVINCI_WAITCFG
586 ACFG2:
587         .word   0x01e00010
588 ACFG2_VAL:
589         .word   CFG_DAVINCI_ACFG2
590 ACFG3:
591         .word   0x01e00014
592 ACFG3_VAL:
593         .word   CFG_DAVINCI_ACFG3
594 ACFG4:
595         .word   0x01e00018
596 ACFG4_VAL:
597         .word   CFG_DAVINCI_ACFG4
598 ACFG5:
599         .word   0x01e0001c
600 ACFG5_VAL:
601         .word   CFG_DAVINCI_ACFG5
602 NANDFCR:
603         .word   0x01e00060
604 NANDFCR_VAL:
605 #ifdef CFG_DAVINCI_NANDCE
606         .word   (1 << (CFG_DAVINCI_NANDCE - 2))
607 #else
608         .word   0x00000000
609 #endif
610
611 MDCTL_DDR2:
612         .word   0x01c41a34
613 MDSTAT_DDR2:
614         .word   0x01c41834
615
616 PTCMD:
617         .word   0x01c41120
618 PTSTAT:
619         .word   0x01c41128
620
621 EINT_ENABLE0:
622         .word   0x01c48018
623 EINT_ENABLE1:
624         .word   0x01c4801c
625
626 PSC_FLAG_CLEAR:
627         .word   0xffffffe0
628 PSC_GEM_FLAG_CLEAR:
629         .word   0xfffffeff
630
631 /* DDR2 MMR & CONFIGURATION VALUES */
632 DDRCTL:
633         .word   0x200000e4
634 DDRCTL_VAL:
635         .word   CFG_DAVINCI_DDRCTL
636 SDREF:
637         .word   0x2000000c
638 SDREF_VAL:
639         .word   CFG_DAVINCI_SDREF
640 SDCFG:
641         .word   0x20000008
642 SDCFG_VAL:
643         .word   CFG_DAVINCI_SDCFG
644 SDTIM0:
645         .word   0x20000010
646 SDTIM0_VAL:
647         .word   CFG_DAVINCI_SDTIM0
648 SDTIM1:
649         .word   0x20000014
650 SDTIM1_VAL:
651         .word   CFG_DAVINCI_SDTIM1
652 VTPIOCR:
653         .word   0x200000f0      /* VTP IO Control register */
654 DDRVTPR:
655         .word   0x01c42030      /* DDR VPTR MMR */
656 VTP_MMR0:
657         .word   0x201f
658 VTP_MMR1:
659         .word   0xa01f
660 DFT_ENABLE:
661         .word   0x01c4004c
662 VTP_LOCK_COUNT:
663         .word   0x5b0
664 VTP_MASK:
665         .word   0xffffdfff
666 VTP_RECAL:
667         .word   0x40000
668 VTP_EN:
669         .word   0x02000
670 CFGTEST:
671         .word   0x80010000
672 MASK_VAL:
673         .word   0x00000fff
674
675 /* GEM Power Up & LPSC Control Register */
676 MDCTL_GEM:
677         .word   0x01c41a9c
678 MDSTAT_GEM:
679         .word   0x01c4189c
680
681 /* For WDT reset chip bug */
682 P1394:
683         .word   0x01c41a20
684
685 PLL_CLKSRC_MASK:
686         .word   0xfffffeff      /* Mask the Clock Mode bit */
687 PLL_ENSRC_MASK:
688         .word   0xffffffdf      /* Select the PLLEN source */
689 PLL_BYPASS_MASK:
690         .word   0xfffffffe      /* Put the PLL in BYPASS */
691 PLL_RESET_MASK:
692         .word   0xfffffff7      /* Put the PLL in Reset Mode */
693 PLL_PWRUP_MASK:
694         .word   0xfffffffd      /* PLL Power up Mask Bit  */
695 PLL_DISABLE_ENABLE_MASK:
696         .word   0xffffffef      /* Enable the PLL from Disable */
697 PLL_LOCK_COUNT:
698         .word   0x2000
699
700 /* PLL1-SYSTEM PLL MMRs */
701 PLL1_CTL:
702         .word   0x01c40900
703 PLL1_PLLM:
704         .word   0x01c40910
705
706 /* PLL2-SYSTEM PLL MMRs */
707 PLL2_CTL:
708         .word   0x01c40d00
709 PLL2_PLLM:
710         .word   0x01c40d10
711 PLL2_DIV1:
712         .word   0x01c40d18
713 PLL2_DIV2:
714         .word   0x01c40d1c
715 PLL2_PLLCMD:
716         .word   0x01c40d38
717 PLL2_PLLSTAT:
718         .word   0x01c40d3c
719 PLL2_DIV_MASK:
720         .word   0xffff7fff
721
722 MMARG_BRF0:
723         .word   0x01c42010      /* BRF margin mode 0 (R/W)*/
724 MMARG_BRF0_VAL:
725         .word   CFG_DAVINCI_MMARG_BRF0
726
727 DDR2_START_ADDR:
728         .word   0x80000000
729 DUMMY_VAL:
730         .word   0xa55aa55a