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