blob: 7c931f03988ac6c1dd7bf61d052e240e6aa2cd6c [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <ppc4xx.h>
26#include <asm/processor.h>
27#include <pci.h>
28
29
30#ifdef CONFIG_SDRAM_BANK0
31
32
33#define MAGIC0 0x00000000
34#define MAGIC1 0x11111111
35#define MAGIC2 0x22222222
36#define MAGIC3 0x33333333
37#define MAGIC4 0x44444444
stroese61774452003-02-10 16:26:37 +000038#define MAGIC5 0x55555555
39#define MAGIC6 0x66666666
wdenkc6097192002-11-03 00:24:07 +000040
41#define ADDR_ZERO 0x00000000
42#define ADDR_400 0x00000400
stroese61774452003-02-10 16:26:37 +000043#define ADDR_01MB 0x00100000
wdenkc6097192002-11-03 00:24:07 +000044#define ADDR_08MB 0x00800000
45#define ADDR_16MB 0x01000000
46#define ADDR_32MB 0x02000000
47#define ADDR_64MB 0x04000000
stroese61774452003-02-10 16:26:37 +000048#define ADDR_128MB 0x08000000
wdenkc6097192002-11-03 00:24:07 +000049
50#define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data)
51
52
53/*-----------------------------------------------------------------------
54 */
55void sdram_init(void)
56{
57 ulong speed;
58 ulong sdtr1;
59 ulong rtr;
60
61 /*
62 * Determine SDRAM speed
63 */
64 speed = get_bus_freq(0); /* parameter not used on ppc4xx */
65
66 /*
67 * Support for 100MHz and 133MHz SDRAM
68 */
69 if (speed > 100000000) {
70 /*
71 * 133 MHz SDRAM
72 */
73 sdtr1 = 0x01074015;
74 rtr = 0x07f00000;
75 } else {
76 /*
77 * default: 100 MHz SDRAM
78 */
79 sdtr1 = 0x0086400d;
80 rtr = 0x05f00000;
81 }
82
83 /*
stroese342f5512003-09-12 08:49:58 +000084 * Disable memory controller.
85 */
86 mtsdram0(mem_mcopt1, 0x00000000);
87
88 /*
stroese61774452003-02-10 16:26:37 +000089 * Set MB0CF for bank 0. (0-128MB) Address Mode 3 since 13x10(4)
90 */
91 mtsdram0(mem_mb0cf, 0x000A4001);
92
93 mtsdram0(mem_sdtr1, sdtr1);
94 mtsdram0(mem_rtr, rtr);
95
96 /*
97 * Wait for 200us
98 */
99 udelay(200);
100
101 /*
102 * Set memory controller options reg, MCOPT1.
103 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
104 * read/prefetch.
105 */
106 mtsdram0(mem_mcopt1, 0x80800000);
107
108 /*
109 * Wait for 10ms
110 */
111 udelay(10000);
112
113 /*
114 * Test if 128 MByte are equipped (mirror test)
115 */
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;
121
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)) {
126 /*
127 * OK, 128MB detected -> all done
128 */
129 return;
130 }
wdenke5ad56b2003-02-11 01:49:43 +0000131
stroese61774452003-02-10 16:26:37 +0000132 /*
133 * Now test for 64 MByte...
134 */
wdenke5ad56b2003-02-11 01:49:43 +0000135
wdenk8bde7f72003-06-27 21:31:46 +0000136 /*
stroese61774452003-02-10 16:26:37 +0000137 * Disable memory controller.
138 */
139 mtsdram0(mem_mcopt1, 0x00000000);
140
141 /*
wdenkc6097192002-11-03 00:24:07 +0000142 * Set MB0CF for bank 0. (0-64MB) Address Mode 3 since 13x9(4)
143 */
144 mtsdram0(mem_mb0cf, 0x00084001);
145
146 mtsdram0(mem_sdtr1, sdtr1);
147 mtsdram0(mem_rtr, rtr);
148
149 /*
150 * Wait for 200us
151 */
152 udelay(200);
153
154 /*
155 * Set memory controller options reg, MCOPT1.
156 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
157 * read/prefetch.
158 */
159 mtsdram0(mem_mcopt1, 0x80800000);
160
161 /*
162 * Wait for 10ms
163 */
164 udelay(10000);
165
166 /*
167 * Test if 64 MByte are equipped (mirror test)
168 */
169 *(volatile ulong *)ADDR_ZERO = MAGIC0;
170 *(volatile ulong *)ADDR_08MB = MAGIC1;
171 *(volatile ulong *)ADDR_16MB = MAGIC2;
172 *(volatile ulong *)ADDR_32MB = MAGIC3;
173
174 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
175 (*(volatile ulong *)ADDR_08MB == MAGIC1) &&
176 (*(volatile ulong *)ADDR_16MB == MAGIC2)) {
177 /*
178 * OK, 64MB detected -> all done
179 */
180 return;
181 }
wdenke5ad56b2003-02-11 01:49:43 +0000182
wdenkc6097192002-11-03 00:24:07 +0000183 /*
184 * Now test for 32 MByte...
185 */
wdenke5ad56b2003-02-11 01:49:43 +0000186
wdenk8bde7f72003-06-27 21:31:46 +0000187 /*
wdenkc6097192002-11-03 00:24:07 +0000188 * Disable memory controller.
189 */
190 mtsdram0(mem_mcopt1, 0x00000000);
191
192 /*
193 * Set MB0CF for bank 0. (0-32MB) Address Mode 2 since 12x9(4)
194 */
195 mtsdram0(mem_mb0cf, 0x00062001);
196
197 /*
198 * Set memory controller options reg, MCOPT1.
199 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
200 * read/prefetch.
201 */
202 mtsdram0(mem_mcopt1, 0x80800000);
203
204 /*
205 * Wait for 10ms
206 */
207 udelay(10000);
208
209 /*
210 * Test if 32 MByte are equipped (mirror test)
211 */
212 *(volatile ulong *)ADDR_ZERO = MAGIC0;
213 *(volatile ulong *)ADDR_400 = MAGIC1;
214 *(volatile ulong *)ADDR_08MB = MAGIC2;
215 *(volatile ulong *)ADDR_16MB = MAGIC3;
216
217 if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) &&
218 (*(volatile ulong *)ADDR_400 == MAGIC1) &&
219 (*(volatile ulong *)ADDR_08MB == MAGIC2)) {
220 /*
221 * OK, 32MB detected -> all done
222 */
223 return;
224 }
225
226 /*
stroese61774452003-02-10 16:26:37 +0000227 * Now test for 16 MByte...
wdenkc6097192002-11-03 00:24:07 +0000228 */
wdenk8bde7f72003-06-27 21:31:46 +0000229 /*
wdenkc6097192002-11-03 00:24:07 +0000230 * Disable memory controller.
231 */
232 mtsdram0(mem_mcopt1, 0x00000000);
233
234 /*
235 * Set MB0CF for bank 0. (0-16MB) Address Mode 4 since 12x8(4)
236 */
237 mtsdram0(mem_mb0cf, 0x00046001);
238
239 /*
240 * Set memory controller options reg, MCOPT1.
241 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
242 * read/prefetch.
243 */
244 mtsdram0(mem_mcopt1, 0x80800000);
245
246 /*
247 * Wait for 10ms
248 */
249 udelay(10000);
stroese61774452003-02-10 16:26:37 +0000250
251 /*
252 * Test if 16 MByte are equipped (mirror test)
253 */
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;*/
259
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)) {
264 /*
265 * OK, 16MB detected -> all done
266 */
267 return;
268 }
269
270 /*
271 * Setup for 4 MByte...
272 */
wdenke5ad56b2003-02-11 01:49:43 +0000273
wdenk8bde7f72003-06-27 21:31:46 +0000274 /*
stroese61774452003-02-10 16:26:37 +0000275 * Disable memory controller.
276 */
277 mtsdram0(mem_mcopt1, 0x00000000);
278
279 /*
280 * Set MB0CF for bank 0. (0-4MB) Address Mode 5 since 11x8(2)
281 */
282 mtsdram0(mem_mb0cf, 0x00008001);
283
284 /*
285 * Set memory controller options reg, MCOPT1.
286 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
287 * read/prefetch.
288 */
289 mtsdram0(mem_mcopt1, 0x80800000);
290
291 /*
292 * Wait for 10ms
293 */
294 udelay(10000);
wdenkc6097192002-11-03 00:24:07 +0000295}
296
297#endif /* CONFIG_SDRAM_BANK0 */