ppc4xx: Enable Primordial Stack for 40x and Unify ECC Handling
[platform/kernel/u-boot.git] / board / amcc / kilauea / init.S
1 /*
2  * Copyright (c) 2008 Nuovation System Designs, LLC
3  *   Grant Erickson <gerickson@nuovations.com>
4  *
5  * (C) Copyright 2007-2008
6  * Stefan Roese, DENX Software Engineering, sr@denx.de.
7  *
8  * Originally based on code provided from UDTech and AMCC
9  *
10  * See file CREDITS for list of people who contributed to this
11  * project.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of
16  * the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26  * MA 02111-1307 USA
27  */
28
29 #include <config.h>
30 #include <ppc4xx.h>
31
32 #include <ppc_asm.tmpl>
33 #include <ppc_defs.h>
34
35 #define mtsdram_as(reg, value)          \
36         addi    r4,0,reg        ;       \
37         mtdcr   memcfga,r4      ;       \
38         addis   r4,0,value@h    ;       \
39         ori     r4,r4,value@l   ;       \
40         mtdcr   memcfgd,r4      ;
41
42 #if defined(CONFIG_DDR_ECC)
43         .extern ecc_init
44 #endif /* defined(CONFIG_DDR_ECC) */
45
46         .globl  ext_bus_cntlr_init
47 ext_bus_cntlr_init:
48 #if !defined(CFG_INIT_DCACHE_CS)
49 #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
50
51         /*
52          * DDR2 SDRAM Controller Setup
53          */
54
55         /* Set Memory Bank Configuration Registers */
56         mtsdram_as(SDRAM_MB0CF, CFG_SDRAM0_MB0CF);
57         mtsdram_as(SDRAM_MB1CF, CFG_SDRAM0_MB1CF);
58         mtsdram_as(SDRAM_MB2CF, CFG_SDRAM0_MB2CF);
59         mtsdram_as(SDRAM_MB3CF, CFG_SDRAM0_MB3CF);
60
61         /* Set Memory Clock Timing Register */
62         mtsdram_as(SDRAM_CLKTR, CFG_SDRAM0_CLKTR);
63
64         /* Set Refresh Time Register */
65         mtsdram_as(SDRAM_RTR, CFG_SDRAM0_RTR);
66
67         /* Set SDRAM Timing Registers */
68         mtsdram_as(SDRAM_SDTR1, CFG_SDRAM0_SDTR1);
69         mtsdram_as(SDRAM_SDTR2, CFG_SDRAM0_SDTR2);
70         mtsdram_as(SDRAM_SDTR3, CFG_SDRAM0_SDTR3);
71
72         /* Set Mode and Extended Mode Registers */
73         mtsdram_as(SDRAM_MMODE, CFG_SDRAM0_MMODE);
74         mtsdram_as(SDRAM_MEMODE, CFG_SDRAM0_MEMODE);
75
76         /* Set Memory Controller Options 1 Register */
77         mtsdram_as(SDRAM_MCOPT1, CFG_SDRAM0_MCOPT1);
78
79         /* Set Manual Initialization Control Registers */
80         mtsdram_as(SDRAM_INITPLR0, CFG_SDRAM0_INITPLR0);
81         mtsdram_as(SDRAM_INITPLR1, CFG_SDRAM0_INITPLR1);
82         mtsdram_as(SDRAM_INITPLR2, CFG_SDRAM0_INITPLR2);
83         mtsdram_as(SDRAM_INITPLR3, CFG_SDRAM0_INITPLR3);
84         mtsdram_as(SDRAM_INITPLR4, CFG_SDRAM0_INITPLR4);
85         mtsdram_as(SDRAM_INITPLR5, CFG_SDRAM0_INITPLR5);
86         mtsdram_as(SDRAM_INITPLR6, CFG_SDRAM0_INITPLR6);
87         mtsdram_as(SDRAM_INITPLR7, CFG_SDRAM0_INITPLR7);
88         mtsdram_as(SDRAM_INITPLR8, CFG_SDRAM0_INITPLR8);
89         mtsdram_as(SDRAM_INITPLR9, CFG_SDRAM0_INITPLR9);
90         mtsdram_as(SDRAM_INITPLR10, CFG_SDRAM0_INITPLR10);
91         mtsdram_as(SDRAM_INITPLR11, CFG_SDRAM0_INITPLR11);
92         mtsdram_as(SDRAM_INITPLR12, CFG_SDRAM0_INITPLR12);
93         mtsdram_as(SDRAM_INITPLR13, CFG_SDRAM0_INITPLR13);
94         mtsdram_as(SDRAM_INITPLR14, CFG_SDRAM0_INITPLR14);
95         mtsdram_as(SDRAM_INITPLR15, CFG_SDRAM0_INITPLR15);
96
97         /* Set On-Die Termination Registers */
98         mtsdram_as(SDRAM_CODT, CFG_SDRAM0_CODT);
99         mtsdram_as(SDRAM_MODT0, CFG_SDRAM0_MODT0);
100         mtsdram_as(SDRAM_MODT1, CFG_SDRAM0_MODT1);
101
102         /* Set Write Timing Register */
103         mtsdram_as(SDRAM_WRDTR, CFG_SDRAM0_WRDTR);
104
105         /*
106          * Start Initialization by SDRAM0_MCOPT2[SREN] = 0 and
107          * SDRAM0_MCOPT2[IPTR] = 1
108          */
109         mtsdram_as(SDRAM_MCOPT2, SDRAM_MCOPT2_SREN_EXIT | \
110                                  SDRAM_MCOPT2_IPTR_EXECUTE);
111
112         /*
113          * Poll SDRAM0_MCSTAT[MIC] for assertion to indicate the
114          * completion of initialization.
115          *
116          *   do {
117          *           mfsdram(SDRAM_MCSTAT, val);
118          *   } while ((val & SDRAM_MCSTAT_MIC_MASK) != SDRAM_MCSTAT_MIC_COMP);
119          */
120         li      r4,SDRAM_MCSTAT
121         lis     r2,SDRAM_MCSTAT_MIC_COMP@h
122         ori     r2,r2,SDRAM_MCSTAT_MIC_COMP@l
123 0:      mtdcr   memcfga,r4
124         mfdcr   r3,memcfgd
125         clrrwi  r3,r3,31
126         cmpw    cr7,r3,r2
127         bne+    cr7,0b
128
129         /* Set Delay Control Registers */
130         mtsdram_as(SDRAM_DLCR, CFG_SDRAM0_DLCR);
131         mtsdram_as(SDRAM_RDCC, CFG_SDRAM0_RDCC);
132         mtsdram_as(SDRAM_RQDC, CFG_SDRAM0_RQDC);
133         mtsdram_as(SDRAM_RFDC, CFG_SDRAM0_RFDC);
134
135         /*
136          * Enable Controller by SDRAM0_MCOPT2[DCEN] = 1:
137          *
138          *   mcopt2 = mfsdram(SDRAM_MCOPT2);
139          */
140         li      r4,SDRAM_MCOPT2
141         mtdcr   memcfga,r4
142         mfdcr   r3,memcfgd
143
144         /*
145          *   mtsdram(SDRAM_MCOPT2, mcopt2 | SDRAM_MCOPT2_DCEN_ENABLE);
146          */
147         mtdcr   memcfga,r4
148         oris    r3,r3,SDRAM_MCOPT2_DCEN_ENABLE@h
149         ori     r3,r3,SDRAM_MCOPT2_DCEN_ENABLE@l
150         mtdcr   memcfgd,r3
151
152 #if defined(CONFIG_DDR_ECC)
153         /*
154          *   ecc_init(CFG_SDRAM_BASE, CFG_MBYTES_SDRAM << 20);
155          */
156         mflr    r13
157         lis     r3,CFG_SDRAM_BASE@h
158         ori     r3,r3,CFG_SDRAM_BASE@l
159         lis     r4,(CFG_MBYTES_SDRAM << 20)@h
160         ori     r4,r4,(CFG_MBYTES_SDRAM << 20)@l
161         bl      ecc_init
162         mtlr    r13
163 #endif /* defined(CONFIG_DDR_ECC) */
164 #endif /* !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) */
165 #endif /* !defined(CFG_INIT_DCACHE_CS) */
166
167         blr