3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
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 * Disable memory controller.
86 mtsdram0(mem_mcopt1, 0x00000000);
89 * Set MB0CF for bank 0. (0-128MB) Address Mode 3 since 13x10(4)
91 mtsdram0(mem_mb0cf, 0x000A4001);
93 mtsdram0(mem_sdtr1, sdtr1);
94 mtsdram0(mem_rtr, rtr);
102 * Set memory controller options reg, MCOPT1.
103 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
106 mtsdram0(mem_mcopt1, 0x80800000);
114 * Test if 128 MByte are equipped (mirror test)
116 *(volatile ulong *)ADDR_ZERO = MAGIC0;
117 *(volatile ulong *)ADDR_08MB = MAGIC1;
118 *(volatile ulong *)ADDR_16MB = MAGIC2;
119 *(volatile ulong *)ADDR_32MB = MAGIC3;
120 *(volatile ulong *)ADDR_64MB = MAGIC4;
122 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
123 (*(volatile ulong *)ADDR_08MB == MAGIC1) &&
124 (*(volatile ulong *)ADDR_16MB == MAGIC2) &&
125 (*(volatile ulong *)ADDR_32MB == MAGIC3)) {
127 * OK, 128MB detected -> all done
133 * Now test for 64 MByte...
137 * Disable memory controller.
139 mtsdram0(mem_mcopt1, 0x00000000);
142 * Set MB0CF for bank 0. (0-64MB) Address Mode 3 since 13x9(4)
144 mtsdram0(mem_mb0cf, 0x00084001);
146 mtsdram0(mem_sdtr1, sdtr1);
147 mtsdram0(mem_rtr, rtr);
155 * Set memory controller options reg, MCOPT1.
156 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
159 mtsdram0(mem_mcopt1, 0x80800000);
167 * Test if 64 MByte are equipped (mirror test)
169 *(volatile ulong *)ADDR_ZERO = MAGIC0;
170 *(volatile ulong *)ADDR_08MB = MAGIC1;
171 *(volatile ulong *)ADDR_16MB = MAGIC2;
172 *(volatile ulong *)ADDR_32MB = MAGIC3;
174 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
175 (*(volatile ulong *)ADDR_08MB == MAGIC1) &&
176 (*(volatile ulong *)ADDR_16MB == MAGIC2)) {
178 * OK, 64MB detected -> all done
184 * Now test for 32 MByte...
188 * Disable memory controller.
190 mtsdram0(mem_mcopt1, 0x00000000);
193 * Set MB0CF for bank 0. (0-32MB) Address Mode 2 since 12x9(4)
195 mtsdram0(mem_mb0cf, 0x00062001);
198 * Set memory controller options reg, MCOPT1.
199 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
202 mtsdram0(mem_mcopt1, 0x80800000);
210 * Test if 32 MByte are equipped (mirror test)
212 *(volatile ulong *)ADDR_ZERO = MAGIC0;
213 *(volatile ulong *)ADDR_400 = MAGIC1;
214 *(volatile ulong *)ADDR_08MB = MAGIC2;
215 *(volatile ulong *)ADDR_16MB = MAGIC3;
217 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
218 (*(volatile ulong *)ADDR_400 == MAGIC1) &&
219 (*(volatile ulong *)ADDR_08MB == MAGIC2)) {
221 * OK, 32MB detected -> all done
227 * Now test for 16 MByte...
230 * Disable memory controller.
232 mtsdram0(mem_mcopt1, 0x00000000);
235 * Set MB0CF for bank 0. (0-16MB) Address Mode 4 since 12x8(4)
237 mtsdram0(mem_mb0cf, 0x00046001);
240 * Set memory controller options reg, MCOPT1.
241 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
244 mtsdram0(mem_mcopt1, 0x80800000);
252 * Test if 16 MByte are equipped (mirror test)
254 *(volatile ulong *)ADDR_ZERO = MAGIC0;
255 *(volatile ulong *)ADDR_400 = MAGIC1;
256 *(volatile ulong *)ADDR_01MB = MAGIC5;
257 *(volatile ulong *)ADDR_08MB = MAGIC2;
258 /* *(volatile ulong *)ADDR_16MB = MAGIC3;*/
260 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
261 (*(volatile ulong *)ADDR_400 == MAGIC1) &&
262 (*(volatile ulong *)ADDR_01MB == MAGIC5) &&
263 (*(volatile ulong *)ADDR_08MB == MAGIC2)) {
265 * OK, 16MB detected -> all done
271 * Setup for 4 MByte...
275 * Disable memory controller.
277 mtsdram0(mem_mcopt1, 0x00000000);
280 * Set MB0CF for bank 0. (0-4MB) Address Mode 5 since 11x8(2)
282 mtsdram0(mem_mb0cf, 0x00008001);
285 * Set memory controller options reg, MCOPT1.
286 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
289 mtsdram0(mem_mcopt1, 0x80800000);
297 #endif /* CONFIG_SDRAM_BANK0 */