]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/davinci/lowlevel_init.S
Merge branch 'master' of git://git.denx.de/u-boot-microblaze
[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 #ifdef CONFIG_SOC_DM644X
53
54         /*-------------------------------------------------------*
55          * Mask all IRQs by setting all bits in the EINT default *
56          *-------------------------------------------------------*/
57         mov     r1, $0
58         ldr     r0, =EINT_ENABLE0
59         str     r1, [r0]
60         ldr     r0, =EINT_ENABLE1
61         str     r1, [r0]
62
63         /*------------------------------------------------------*
64          * Put the GEM in reset                                 *
65          *------------------------------------------------------*/
66
67         /* Put the GEM in reset */
68         ldr     r8, PSC_GEM_FLAG_CLEAR
69         ldr     r6, MDCTL_GEM
70         ldr     r7, [r6]
71         and     r7, r7, r8
72         str     r7, [r6]
73
74         /* Enable the Power Domain Transition Command */
75         ldr     r6, PTCMD
76         ldr     r7, [r6]
77         orr     r7, r7, $0x02
78         str     r7, [r6]
79
80         /* Check for Transition Complete(PTSTAT) */
81 checkStatClkStopGem:
82         ldr     r6, PTSTAT
83         ldr     r7, [r6]
84         ands    r7, r7, $0x02
85         bne     checkStatClkStopGem
86
87         /* Check for GEM Reset Completion */
88 checkGemStatClkStop:
89         ldr     r6, MDSTAT_GEM
90         ldr     r7, [r6]
91         ands    r7, r7, $0x100
92         bne     checkGemStatClkStop
93
94         /* Do this for enabling a WDT initiated reset this is a workaround
95            for a chip bug.  Not required under normal situations */
96         ldr     r6, P1394
97         mov     r10, $0
98         str     r10, [r6]
99
100         /*------------------------------------------------------*
101          * Enable L1 & L2 Memories in Fast mode                 *
102          *------------------------------------------------------*/
103         ldr     r6, DFT_ENABLE
104         mov     r10, $0x01
105         str     r10, [r6]
106
107         ldr     r6, MMARG_BRF0
108         ldr     r10, MMARG_BRF0_VAL
109         str     r10, [r6]
110
111         ldr     r6, DFT_ENABLE
112         mov     r10, $0
113         str     r10, [r6]
114
115         /*------------------------------------------------------*
116          * DDR2 PLL Initialization                              *
117          *------------------------------------------------------*/
118
119         /* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
120         mov     r10, $0
121         ldr     r6, PLL2_CTL
122         ldr     r7, PLL_CLKSRC_MASK
123         ldr     r8, [r6]
124         and     r8, r8, r7
125         mov     r9, r10, lsl $8
126         orr     r8, r8, r9
127         str     r8, [r6]
128
129         /* Select the PLLEN source */
130         ldr     r7, PLL_ENSRC_MASK
131         and     r8, r8, r7
132         str     r8, [r6]
133
134         /* Bypass the PLL */
135         ldr     r7, PLL_BYPASS_MASK
136         and     r8, r8, r7
137         str     r8, [r6]
138
139         /* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
140         mov     r10, $0x20
141 WaitPPL2Loop:
142         subs    r10, r10, $1
143         bne     WaitPPL2Loop
144
145         /* Reset the PLL */
146         ldr     r7, PLL_RESET_MASK
147         and     r8, r8, r7
148         str     r8, [r6]
149
150         /* Power up the PLL */
151         ldr     r7, PLL_PWRUP_MASK
152         and     r8, r8, r7
153         str     r8, [r6]
154
155         /* Enable the PLL from Disable Mode */
156         ldr     r7, PLL_DISABLE_ENABLE_MASK
157         and     r8, r8, r7
158         str     r8, [r6]
159
160         /* Program the PLL Multiplier */
161         ldr     r6, PLL2_PLLM
162         mov     r2, $0x17       /* 162 MHz */
163         str     r2, [r6]
164
165         /* Program the PLL2 Divisor Value */
166         ldr     r6, PLL2_DIV2
167         mov     r3, $0x01
168         str     r3, [r6]
169
170         /* Program the PLL2 Divisor Value */
171         ldr     r6, PLL2_DIV1
172         mov     r4, $0x0b       /* 54 MHz */
173         str     r4, [r6]
174
175         /* PLL2 DIV2 MMR */
176         ldr     r8, PLL2_DIV_MASK
177         ldr     r6, PLL2_DIV2
178         ldr     r9, [r6]
179         and     r8, r8, r9
180         mov     r9, $0x01
181         mov     r9, r9, lsl $15
182         orr     r8, r8, r9
183         str     r8, [r6]
184
185         /* Program the GOSET bit to take new divider values */
186         ldr     r6, PLL2_PLLCMD
187         ldr     r7, [r6]
188         orr     r7, r7, $0x01
189         str     r7, [r6]
190
191         /* Wait for Done */
192         ldr     r6, PLL2_PLLSTAT
193 doneLoop_0:
194         ldr     r7, [r6]
195         ands    r7, r7, $0x01
196         bne     doneLoop_0
197
198         /* PLL2 DIV1 MMR */
199         ldr     r8, PLL2_DIV_MASK
200         ldr     r6, PLL2_DIV1
201         ldr     r9, [r6]
202         and     r8, r8, r9
203         mov     r9, $0x01
204         mov     r9, r9, lsl $15
205         orr     r8, r8, r9
206         str     r8, [r6]
207
208         /* Program the GOSET bit to take new divider values */
209         ldr     r6, PLL2_PLLCMD
210         ldr     r7, [r6]
211         orr     r7, r7, $0x01
212         str     r7, [r6]
213
214         /* Wait for Done */
215         ldr     r6, PLL2_PLLSTAT
216 doneLoop:
217         ldr     r7, [r6]
218         ands    r7, r7, $0x01
219         bne     doneLoop
220
221         /* Wait for PLL to Reset Properly */
222         mov     r10, $0x218
223 ResetPPL2Loop:
224         subs    r10, r10, $1
225         bne     ResetPPL2Loop
226
227         /* Bring PLL out of Reset */
228         ldr     r6, PLL2_CTL
229         ldr     r8, [r6]
230         orr     r8, r8, $0x08
231         str     r8, [r6]
232
233         /* Wait for PLL to Lock */
234         ldr     r10, PLL_LOCK_COUNT
235 PLL2Lock:
236         subs    r10, r10, $1
237         bne     PLL2Lock
238
239         /* Enable the PLL */
240         ldr     r6, PLL2_CTL
241         ldr     r8, [r6]
242         orr     r8, r8, $0x01
243         str     r8, [r6]
244
245         /*------------------------------------------------------*
246          * Issue Soft Reset to DDR Module                       *
247          *------------------------------------------------------*/
248
249         /* Shut down the DDR2 LPSC Module */
250         ldr     r8, PSC_FLAG_CLEAR
251         ldr     r6, MDCTL_DDR2
252         ldr     r7, [r6]
253         and     r7, r7, r8
254         orr     r7, r7, $0x03
255         str     r7, [r6]
256
257         /* Enable the Power Domain Transition Command */
258         ldr     r6, PTCMD
259         ldr     r7, [r6]
260         orr     r7, r7, $0x01
261         str     r7, [r6]
262
263         /* Check for Transition Complete(PTSTAT) */
264 checkStatClkStop:
265         ldr     r6, PTSTAT
266         ldr     r7, [r6]
267         ands    r7, r7, $0x01
268         bne     checkStatClkStop
269
270         /* Check for DDR2 Controller Enable Completion */
271 checkDDRStatClkStop:
272         ldr     r6, MDSTAT_DDR2
273         ldr     r7, [r6]
274         and     r7, r7, $MDSTAT_STATE
275         cmp     r7, $0x03
276         bne     checkDDRStatClkStop
277
278         /*------------------------------------------------------*
279          * Program DDR2 MMRs for 162MHz Setting                 *
280          *------------------------------------------------------*/
281
282         /* Program PHY Control Register */
283         ldr     r6, DDRCTL
284         ldr     r7, DDRCTL_VAL
285         str     r7, [r6]
286
287         /* Program SDRAM Bank Config Register */
288         ldr     r6, SDCFG
289         ldr     r7, SDCFG_VAL
290         str     r7, [r6]
291
292         /* Program SDRAM TIM-0 Config Register */
293         ldr     r6, SDTIM0
294         ldr     r7, SDTIM0_VAL_162MHz
295         str     r7, [r6]
296
297         /* Program SDRAM TIM-1 Config Register */
298         ldr     r6, SDTIM1
299         ldr     r7, SDTIM1_VAL_162MHz
300         str     r7, [r6]
301
302         /* Program the SDRAM Bank Config Control Register */
303         ldr     r10, MASK_VAL
304         ldr     r8, SDCFG
305         ldr     r9, SDCFG_VAL
306         and     r9, r9, r10
307         str     r9, [r8]
308
309         /* Program SDRAM SDREF Config Register */
310         ldr     r6, SDREF
311         ldr     r7, SDREF_VAL
312         str     r7, [r6]
313
314         /*------------------------------------------------------*
315          * Issue Soft Reset to DDR Module                       *
316          *------------------------------------------------------*/
317
318         /* Issue a Dummy DDR2 read/write */
319         ldr     r8, DDR2_START_ADDR
320         ldr     r7, DUMMY_VAL
321         str     r7, [r8]
322         ldr     r7, [r8]
323
324         /* Shut down the DDR2 LPSC Module */
325         ldr     r8, PSC_FLAG_CLEAR
326         ldr     r6, MDCTL_DDR2
327         ldr     r7, [r6]
328         and     r7, r7, r8
329         orr     r7, r7, $0x01
330         str     r7, [r6]
331
332         /* Enable the Power Domain Transition Command */
333         ldr     r6, PTCMD
334         ldr     r7, [r6]
335         orr     r7, r7, $0x01
336         str     r7, [r6]
337
338         /* Check for Transition Complete(PTSTAT) */
339 checkStatClkStop2:
340         ldr     r6, PTSTAT
341         ldr     r7, [r6]
342         ands    r7, r7, $0x01
343         bne     checkStatClkStop2
344
345         /* Check for DDR2 Controller Enable Completion */
346 checkDDRStatClkStop2:
347         ldr     r6, MDSTAT_DDR2
348         ldr     r7, [r6]
349         and     r7, r7, $MDSTAT_STATE
350         cmp     r7, $0x01
351         bne     checkDDRStatClkStop2
352
353         /*------------------------------------------------------*
354          * Turn DDR2 Controller Clocks On                       *
355          *------------------------------------------------------*/
356
357         /* Enable the DDR2 LPSC Module */
358         ldr     r6, MDCTL_DDR2
359         ldr     r7, [r6]
360         orr     r7, r7, $0x03
361         str     r7, [r6]
362
363         /* Enable the Power Domain Transition Command */
364         ldr     r6, PTCMD
365         ldr     r7, [r6]
366         orr     r7, r7, $0x01
367         str     r7, [r6]
368
369         /* Check for Transition Complete(PTSTAT) */
370 checkStatClkEn2:
371         ldr     r6, PTSTAT
372         ldr     r7, [r6]
373         ands    r7, r7, $0x01
374         bne     checkStatClkEn2
375
376         /* Check for DDR2 Controller Enable Completion */
377 checkDDRStatClkEn2:
378         ldr     r6, MDSTAT_DDR2
379         ldr     r7, [r6]
380         and     r7, r7, $MDSTAT_STATE
381         cmp     r7, $0x03
382         bne     checkDDRStatClkEn2
383
384         /*  DDR Writes and Reads */
385         ldr     r6, CFGTEST
386         mov     r3, $0x01
387         str     r3, [r6]
388
389         /*------------------------------------------------------*
390          * System PLL Initialization                            *
391          *------------------------------------------------------*/
392
393         /* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
394         mov     r2, $0
395         ldr     r6, PLL1_CTL
396         ldr     r7, PLL_CLKSRC_MASK
397         ldr     r8, [r6]
398         and     r8, r8, r7
399         mov     r9, r2, lsl $8
400         orr     r8, r8, r9
401         str     r8, [r6]
402
403         /* Select the PLLEN source */
404         ldr     r7, PLL_ENSRC_MASK
405         and     r8, r8, r7
406         str     r8, [r6]
407
408         /* Bypass the PLL */
409         ldr     r7, PLL_BYPASS_MASK
410         and     r8, r8, r7
411         str     r8, [r6]
412
413         /* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
414         mov     r10, $0x20
415
416 WaitLoop:
417         subs    r10, r10, $1
418         bne     WaitLoop
419
420         /* Reset the PLL */
421         ldr     r7, PLL_RESET_MASK
422         and     r8, r8, r7
423         str     r8, [r6]
424
425         /* Disable the PLL */
426         orr     r8, r8, $0x10
427         str     r8, [r6]
428
429         /* Power up the PLL */
430         ldr     r7, PLL_PWRUP_MASK
431         and     r8, r8, r7
432         str     r8, [r6]
433
434         /* Enable the PLL from Disable Mode */
435         ldr     r7, PLL_DISABLE_ENABLE_MASK
436         and     r8, r8, r7
437         str     r8, [r6]
438
439         /* Program the PLL Multiplier */
440         ldr     r6, PLL1_PLLM
441         mov     r3, $0x15       /* For 594MHz */
442         str     r3, [r6]
443
444         /* Wait for PLL to Reset Properly */
445         mov     r10, $0xff
446
447 ResetLoop:
448         subs    r10, r10, $1
449         bne     ResetLoop
450
451         /* Bring PLL out of Reset */
452         ldr     r6, PLL1_CTL
453         orr     r8, r8, $0x08
454         str     r8, [r6]
455
456         /* Wait for PLL to Lock */
457         ldr     r10, PLL_LOCK_COUNT
458
459 PLL1Lock:
460         subs    r10, r10, $1
461         bne     PLL1Lock
462
463         /* Enable the PLL */
464         orr     r8, r8, $0x01
465         str     r8, [r6]
466
467         nop
468         nop
469         nop
470         nop
471
472         /*------------------------------------------------------*
473          * AEMIF configuration for NOR Flash (double check)     *
474          *------------------------------------------------------*/
475         ldr     r0, _PINMUX0
476         ldr     r1, _DEV_SETTING
477         str     r1, [r0]
478
479         ldr     r0, WAITCFG
480         ldr     r1, WAITCFG_VAL
481         ldr     r2, [r0]
482         orr     r2, r2, r1
483         str     r2, [r0]
484
485         ldr     r0, ACFG3
486         ldr     r1, ACFG3_VAL
487         ldr     r2, [r0]
488         and     r1, r2, r1
489         str     r1, [r0]
490
491         ldr     r0, ACFG4
492         ldr     r1, ACFG4_VAL
493         ldr     r2, [r0]
494         and     r1, r2, r1
495         str     r1, [r0]
496
497         ldr     r0, ACFG5
498         ldr     r1, ACFG5_VAL
499         ldr     r2, [r0]
500         and     r1, r2, r1
501         str     r1, [r0]
502
503         /*--------------------------------------*
504          * VTP manual Calibration               *
505          *--------------------------------------*/
506         ldr     r0, VTPIOCR
507         ldr     r1, VTP_MMR0
508         str     r1, [r0]
509
510         ldr     r0, VTPIOCR
511         ldr     r1, VTP_MMR1
512         str     r1, [r0]
513
514         /* Wait for 33 VTP CLK cycles.  VRP operates at 27 MHz */
515         ldr     r10, VTP_LOCK_COUNT
516 VTPLock:
517         subs    r10, r10, $1
518         bne     VTPLock
519
520         ldr     r6, DFT_ENABLE
521         mov     r10, $0x01
522         str     r10, [r6]
523
524         ldr     r6, DDRVTPR
525         ldr     r7, [r6]
526         mov     r8, r7, LSL #32-10
527         mov     r8, r8, LSR #32-10        /* grab low 10 bits  */
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   0x08000
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
710 #else /* CONFIG_SOC_DM644X */
711         mov pc, lr
712 #endif