5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/processor.h>
30 #ifdef CONFIG_SDRAM_BANK0
33 #define MAGIC0 0x00000000
34 #define MAGIC1 0x11111111
35 #define MAGIC2 0x22222222
36 #define MAGIC3 0x33333333
37 #define MAGIC4 0x44444444
38 #define MAGIC5 0x55555555
39 #define MAGIC6 0x66666666
41 #define ADDR_ZERO 0x00000000
42 #define ADDR_400 0x00000400
43 #define ADDR_01MB 0x00100000
44 #define ADDR_08MB 0x00800000
45 #define ADDR_16MB 0x01000000
46 #define ADDR_32MB 0x02000000
47 #define ADDR_64MB 0x04000000
48 #define ADDR_128MB 0x08000000
50 #define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data)
53 /*-----------------------------------------------------------------------
62 * Determine SDRAM speed
64 speed = get_bus_freq(0); /* parameter not used on ppc4xx */
67 * Support for 100MHz and 133MHz SDRAM
69 if (speed > 100000000) {
77 * default: 100 MHz SDRAM
84 * Set MB0CF for bank 0. (0-128MB) Address Mode 3 since 13x10(4)
86 mtsdram0(mem_mb0cf, 0x000A4001);
88 mtsdram0(mem_sdtr1, sdtr1);
89 mtsdram0(mem_rtr, rtr);
97 * Set memory controller options reg, MCOPT1.
98 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
101 mtsdram0(mem_mcopt1, 0x80800000);
109 * Test if 128 MByte are equipped (mirror test)
111 *(volatile ulong *)ADDR_ZERO = MAGIC0;
112 *(volatile ulong *)ADDR_08MB = MAGIC1;
113 *(volatile ulong *)ADDR_16MB = MAGIC2;
114 *(volatile ulong *)ADDR_32MB = MAGIC3;
115 *(volatile ulong *)ADDR_64MB = MAGIC4;
117 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
118 (*(volatile ulong *)ADDR_08MB == MAGIC1) &&
119 (*(volatile ulong *)ADDR_16MB == MAGIC2) &&
120 (*(volatile ulong *)ADDR_32MB == MAGIC3)) {
122 * OK, 128MB detected -> all done
128 * Now test for 64 MByte...
132 * Disable memory controller.
134 mtsdram0(mem_mcopt1, 0x00000000);
137 * Set MB0CF for bank 0. (0-64MB) Address Mode 3 since 13x9(4)
139 mtsdram0(mem_mb0cf, 0x00084001);
141 mtsdram0(mem_sdtr1, sdtr1);
142 mtsdram0(mem_rtr, rtr);
150 * Set memory controller options reg, MCOPT1.
151 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
154 mtsdram0(mem_mcopt1, 0x80800000);
162 * Test if 64 MByte are equipped (mirror test)
164 *(volatile ulong *)ADDR_ZERO = MAGIC0;
165 *(volatile ulong *)ADDR_08MB = MAGIC1;
166 *(volatile ulong *)ADDR_16MB = MAGIC2;
167 *(volatile ulong *)ADDR_32MB = MAGIC3;
169 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
170 (*(volatile ulong *)ADDR_08MB == MAGIC1) &&
171 (*(volatile ulong *)ADDR_16MB == MAGIC2)) {
173 * OK, 64MB detected -> all done
179 * Now test for 32 MByte...
183 * Disable memory controller.
185 mtsdram0(mem_mcopt1, 0x00000000);
188 * Set MB0CF for bank 0. (0-32MB) Address Mode 2 since 12x9(4)
190 mtsdram0(mem_mb0cf, 0x00062001);
193 * Set memory controller options reg, MCOPT1.
194 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
197 mtsdram0(mem_mcopt1, 0x80800000);
205 * Test if 32 MByte are equipped (mirror test)
207 *(volatile ulong *)ADDR_ZERO = MAGIC0;
208 *(volatile ulong *)ADDR_400 = MAGIC1;
209 *(volatile ulong *)ADDR_08MB = MAGIC2;
210 *(volatile ulong *)ADDR_16MB = MAGIC3;
212 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
213 (*(volatile ulong *)ADDR_400 == MAGIC1) &&
214 (*(volatile ulong *)ADDR_08MB == MAGIC2)) {
216 * OK, 32MB detected -> all done
222 * Now test for 16 MByte...
225 * Disable memory controller.
227 mtsdram0(mem_mcopt1, 0x00000000);
230 * Set MB0CF for bank 0. (0-16MB) Address Mode 4 since 12x8(4)
232 mtsdram0(mem_mb0cf, 0x00046001);
235 * Set memory controller options reg, MCOPT1.
236 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
239 mtsdram0(mem_mcopt1, 0x80800000);
247 * Test if 16 MByte are equipped (mirror test)
249 *(volatile ulong *)ADDR_ZERO = MAGIC0;
250 *(volatile ulong *)ADDR_400 = MAGIC1;
251 *(volatile ulong *)ADDR_01MB = MAGIC5;
252 *(volatile ulong *)ADDR_08MB = MAGIC2;
253 /* *(volatile ulong *)ADDR_16MB = MAGIC3;*/
255 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
256 (*(volatile ulong *)ADDR_400 == MAGIC1) &&
257 (*(volatile ulong *)ADDR_01MB == MAGIC5) &&
258 (*(volatile ulong *)ADDR_08MB == MAGIC2)) {
260 * OK, 16MB detected -> all done
266 * Setup for 4 MByte...
270 * Disable memory controller.
272 mtsdram0(mem_mcopt1, 0x00000000);
275 * Set MB0CF for bank 0. (0-4MB) Address Mode 5 since 11x8(2)
277 mtsdram0(mem_mb0cf, 0x00008001);
280 * Set memory controller options reg, MCOPT1.
281 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
284 mtsdram0(mem_mcopt1, 0x80800000);
292 #endif /* CONFIG_SDRAM_BANK0 */