blob: 65d45c197f0053cc6ad9c4c1d4ca036a818f9167 [file] [log] [blame]
wdenkf8cac652002-08-26 22:36:39 +00001/*
2 * (C) Copyright 2001
3 * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
4 *
5 * (C) Copyright 2001-2002
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <malloc.h>
29#include <mpc8xx.h>
30
31/* ------------------------------------------------------------------------- */
32
33static long int dram_size (long int, long int *, long int);
34
35/* ------------------------------------------------------------------------- */
36
37#define _NOT_USED_ 0xFFFFFFFF
38
wdenkc83bf6a2004-01-06 22:38:14 +000039const uint sdram_table[] = {
wdenkf8cac652002-08-26 22:36:39 +000040#if (MPC8XX_SPEED <= 50000000L)
41 /*
42 * Single Read. (Offset 0 in UPMA RAM)
43 */
wdenkc83bf6a2004-01-06 22:38:14 +000044 0x0F07EC04, 0x01BBD804, 0x1FF7F440, 0xFFFFFC07,
wdenkf8cac652002-08-26 22:36:39 +000045 0xFFFFFFFF,
46
47 /*
48 * SDRAM Initialization (offset 5 in UPMA RAM)
49 *
50 * This is no UPM entry point. The following definition uses
51 * the remaining space to establish an initialization
52 * sequence, which is executed by a RUN command.
53 *
54 */
wdenkc83bf6a2004-01-06 22:38:14 +000055 0x1FE7F434, 0xEFABE834, 0x1FA7D435,
wdenkf8cac652002-08-26 22:36:39 +000056
57 /*
58 * Burst Read. (Offset 8 in UPMA RAM)
59 */
wdenkc83bf6a2004-01-06 22:38:14 +000060 0x0F07EC04, 0x10EFDC04, 0xF0AFFC00, 0xF0AFFC00,
61 0xF1AFFC00, 0xFFAFFC40, 0xFFAFFC07, 0xFFFFFFFF,
62 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
63 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000064
65 /*
66 * Single Write. (Offset 18 in UPMA RAM)
67 */
wdenkc83bf6a2004-01-06 22:38:14 +000068 0x0E07E804, 0x01BBD000, 0x1FF7F447, 0xFFFFFFFF,
69 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000070
71 /*
72 * Burst Write. (Offset 20 in UPMA RAM)
73 */
wdenkc83bf6a2004-01-06 22:38:14 +000074 0x0E07E800, 0x10EFD400, 0xF0AFFC00, 0xF0AFFC00,
75 0xF1AFFC47, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
76 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
77 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000078
79 /*
80 * Refresh (Offset 30 in UPMA RAM)
81 */
wdenkc83bf6a2004-01-06 22:38:14 +000082 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC84, 0xFFFFFC07,
83 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
84 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000085
86 /*
87 * Exception. (Offset 3c in UPMA RAM)
88 */
wdenkc83bf6a2004-01-06 22:38:14 +000089 0x7FFFFC07, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
wdenkf8cac652002-08-26 22:36:39 +000090#else
91
92 /*
93 * Single Read. (Offset 0 in UPMA RAM)
94 */
wdenkc83bf6a2004-01-06 22:38:14 +000095 0x1F07FC04, 0xEEAFEC04, 0x11AFDC04, 0xEFBBF800,
wdenkf8cac652002-08-26 22:36:39 +000096 0x1FF7F447,
97
98 /*
99 * SDRAM Initialization (offset 5 in UPMA RAM)
100 *
101 * This is no UPM entry point. The following definition uses
102 * the remaining space to establish an initialization
103 * sequence, which is executed by a RUN command.
104 *
105 */
wdenkc83bf6a2004-01-06 22:38:14 +0000106 0x1FF7F434, 0xEFEBE834, 0x1FB7D435,
wdenkf8cac652002-08-26 22:36:39 +0000107
108 /*
109 * Burst Read. (Offset 8 in UPMA RAM)
110 */
wdenkc83bf6a2004-01-06 22:38:14 +0000111 0x1F07FC04, 0xEEAFEC04, 0x10AFDC04, 0xF0AFFC00,
112 0xF0AFFC00, 0xF1AFFC00, 0xEFBBF800, 0x1FF7F447,
wdenkf8cac652002-08-26 22:36:39 +0000113 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
114 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
115
116 /*
117 * Single Write. (Offset 18 in UPMA RAM)
118 */
wdenkc83bf6a2004-01-06 22:38:14 +0000119 0x1F07FC04, 0xEEAFE800, 0x01BBD004, 0x1FF7F447,
wdenkf8cac652002-08-26 22:36:39 +0000120 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
121
122 /*
123 * Burst Write. (Offset 20 in UPMA RAM)
124 */
wdenkc83bf6a2004-01-06 22:38:14 +0000125 0x1F07FC04, 0xEEAFE800, 0x10AFD400, 0xF0AFFC00,
126 0xF0AFFC00, 0xE1BBF804, 0x1FF7F447, _NOT_USED_,
127 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000128 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
129
130 /*
131 * Refresh (Offset 30 in UPMA RAM)
132 */
wdenkc83bf6a2004-01-06 22:38:14 +0000133 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
134 0xFFFFFC84, 0xFFFFFC07,
wdenkf8cac652002-08-26 22:36:39 +0000135 _NOT_USED_, _NOT_USED_, _NOT_USED_,
136 _NOT_USED_, _NOT_USED_, _NOT_USED_,
137
138 /*
139 * Exception. (Offset 3c in UPMA RAM)
140 */
141 0x7FFFFC07, /* last */
wdenkc83bf6a2004-01-06 22:38:14 +0000142 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000143#endif
144};
145
146/* ------------------------------------------------------------------------- */
147
148
149/*
150 * Check Board Identity:
151 *
152 */
153
154int checkboard (void)
155{
wdenkc83bf6a2004-01-06 22:38:14 +0000156 printf ("Board: Nexus NX823");
157 return (0);
wdenkf8cac652002-08-26 22:36:39 +0000158}
159
160/* ------------------------------------------------------------------------- */
161
162long int initdram (int board_type)
163{
wdenkc83bf6a2004-01-06 22:38:14 +0000164 volatile immap_t *immap = (immap_t *) CFG_IMMR;
165 volatile memctl8xx_t *memctl = &immap->im_memctl;
166 long int size_b0, size_b1, size8, size9;
wdenkf8cac652002-08-26 22:36:39 +0000167
wdenkc83bf6a2004-01-06 22:38:14 +0000168 upmconfig (UPMA, (uint *) sdram_table,
169 sizeof (sdram_table) / sizeof (uint));
wdenkf8cac652002-08-26 22:36:39 +0000170
wdenkc83bf6a2004-01-06 22:38:14 +0000171 /*
172 * Up to 2 Banks of 64Mbit x 2 devices
173 * Initial builds only have 1
174 */
175 memctl->memc_mptpr = CFG_MPTPR_1BK_4K;
176 memctl->memc_mar = 0x00000088;
wdenkf8cac652002-08-26 22:36:39 +0000177
wdenkc83bf6a2004-01-06 22:38:14 +0000178 /*
179 * Map controller SDRAM bank 0
180 */
181 memctl->memc_or1 = CFG_OR1_PRELIM;
182 memctl->memc_br1 = CFG_BR1_PRELIM;
183 memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
184 udelay (200);
wdenkf8cac652002-08-26 22:36:39 +0000185
wdenkc83bf6a2004-01-06 22:38:14 +0000186 /*
187 * Map controller SDRAM bank 1
188 */
189 memctl->memc_or2 = CFG_OR2_PRELIM;
190 memctl->memc_br2 = CFG_BR2_PRELIM;
wdenkf8cac652002-08-26 22:36:39 +0000191
wdenkc83bf6a2004-01-06 22:38:14 +0000192 /*
193 * Perform SDRAM initializsation sequence
194 */
195 memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
196 udelay (1);
197 memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - execute twice */
198 udelay (1);
wdenkf8cac652002-08-26 22:36:39 +0000199
wdenkc83bf6a2004-01-06 22:38:14 +0000200 memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */
201 udelay (1);
202 memctl->memc_mcr = 0x80004230; /* SDRAM bank 1 - execute twice */
203 udelay (1);
wdenkf8cac652002-08-26 22:36:39 +0000204
wdenkc83bf6a2004-01-06 22:38:14 +0000205 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
206 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000207
wdenkc83bf6a2004-01-06 22:38:14 +0000208 /*
209 * Preliminary prescaler for refresh (depends on number of
210 * banks): This value is selected for four cycles every 62.4 us
211 * with two SDRAM banks or four cycles every 31.2 us with one
212 * bank. It will be adjusted after memory sizing.
213 */
214 memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
wdenkf8cac652002-08-26 22:36:39 +0000215
wdenkc83bf6a2004-01-06 22:38:14 +0000216 memctl->memc_mar = 0x00000088;
wdenkf8cac652002-08-26 22:36:39 +0000217
218
wdenkc83bf6a2004-01-06 22:38:14 +0000219 /*
220 * Check Bank 0 Memory Size for re-configuration
221 *
222 * try 8 column mode
223 */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200224 size8 = dram_size (CFG_MAMR_8COL, (long *) SDRAM_BASE1_PRELIM,
wdenkc83bf6a2004-01-06 22:38:14 +0000225 SDRAM_MAX_SIZE);
wdenkf8cac652002-08-26 22:36:39 +0000226
wdenkc83bf6a2004-01-06 22:38:14 +0000227 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000228
wdenkc83bf6a2004-01-06 22:38:14 +0000229 /*
230 * try 9 column mode
231 */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200232 size9 = dram_size (CFG_MAMR_9COL, (long *) SDRAM_BASE1_PRELIM,
wdenkc83bf6a2004-01-06 22:38:14 +0000233 SDRAM_MAX_SIZE);
wdenkf8cac652002-08-26 22:36:39 +0000234
wdenkc83bf6a2004-01-06 22:38:14 +0000235 if (size8 < size9) { /* leave configuration at 9 columns */
236 size_b0 = size9;
wdenkf8cac652002-08-26 22:36:39 +0000237/* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
wdenkc83bf6a2004-01-06 22:38:14 +0000238 } else { /* back to 8 columns */
239 size_b0 = size8;
240 memctl->memc_mamr = CFG_MAMR_8COL;
241 udelay (500);
wdenkf8cac652002-08-26 22:36:39 +0000242/* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
wdenkc83bf6a2004-01-06 22:38:14 +0000243 }
wdenkf8cac652002-08-26 22:36:39 +0000244
245 /*
246 * Check Bank 1 Memory Size
247 * use current column settings
248 * [9 column SDRAM may also be used in 8 column mode,
249 * but then only half the real size will be used.]
250 */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200251 size_b1 = dram_size (memctl->memc_mamr, (long *) SDRAM_BASE2_PRELIM,
wdenkc83bf6a2004-01-06 22:38:14 +0000252 SDRAM_MAX_SIZE);
wdenkf8cac652002-08-26 22:36:39 +0000253/* debug ("SDRAM Bank 1: %ld MB\n", size8 >> 20); */
254
wdenkc83bf6a2004-01-06 22:38:14 +0000255 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000256
wdenkc83bf6a2004-01-06 22:38:14 +0000257 /*
258 * Adjust refresh rate depending on SDRAM type, both banks
259 * For types > 128 MBit leave it at the current (fast) rate
260 */
261 if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
262 /* reduce to 15.6 us (62.4 us / quad) */
263 memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
264 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000265 }
266
wdenkc83bf6a2004-01-06 22:38:14 +0000267 /*
268 * Final mapping: map bigger bank first
269 */
270 if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
wdenkf8cac652002-08-26 22:36:39 +0000271
wdenkc83bf6a2004-01-06 22:38:14 +0000272 memctl->memc_or2 =
273 ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
274 memctl->memc_br2 =
275 (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenkf8cac652002-08-26 22:36:39 +0000276
wdenkc83bf6a2004-01-06 22:38:14 +0000277 if (size_b0 > 0) {
278 /*
279 * Position Bank 0 immediately above Bank 1
280 */
281 memctl->memc_or1 =
282 ((-size_b0) & 0xFFFF0000) |
283 CFG_OR_TIMING_SDRAM;
284 memctl->memc_br1 =
285 ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA |
286 BR_V)
287 + size_b1;
288 } else {
289 unsigned long reg;
wdenkf8cac652002-08-26 22:36:39 +0000290
wdenkc83bf6a2004-01-06 22:38:14 +0000291 /*
292 * No bank 0
293 *
294 * invalidate bank
295 */
296 memctl->memc_br1 = 0;
297
298 /* adjust refresh rate depending on SDRAM type, one bank */
299 reg = memctl->memc_mptpr;
300 reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
301 memctl->memc_mptpr = reg;
302 }
303
304 } else { /* SDRAM Bank 0 is bigger - map first */
305
306 memctl->memc_or1 =
307 ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
308 memctl->memc_br1 =
309 (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
310
311 if (size_b1 > 0) {
312 /*
313 * Position Bank 1 immediately above Bank 0
314 */
315 memctl->memc_or2 =
316 ((-size_b1) & 0xFFFF0000) |
317 CFG_OR_TIMING_SDRAM;
318 memctl->memc_br2 =
319 ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA |
320 BR_V)
321 + size_b0;
322 } else {
323 unsigned long reg;
324
325 /*
326 * No bank 1
327 *
328 * invalidate bank
329 */
330 memctl->memc_br2 = 0;
331
332 /* adjust refresh rate depending on SDRAM type, one bank */
333 reg = memctl->memc_mptpr;
334 reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
335 memctl->memc_mptpr = reg;
336 }
wdenkf8cac652002-08-26 22:36:39 +0000337 }
wdenkf8cac652002-08-26 22:36:39 +0000338
wdenkc83bf6a2004-01-06 22:38:14 +0000339 udelay (10000);
wdenkf8cac652002-08-26 22:36:39 +0000340
wdenkc83bf6a2004-01-06 22:38:14 +0000341 return (size_b0 + size_b1);
wdenkf8cac652002-08-26 22:36:39 +0000342}
343
344/* ------------------------------------------------------------------------- */
345
346/*
347 * Check memory range for valid RAM. A simple memory test determines
348 * the actually available RAM size between addresses `base' and
349 * `base + maxsize'. Some (not all) hardware errors are detected:
350 * - short between address lines
351 * - short between data lines
352 */
353
wdenkc83bf6a2004-01-06 22:38:14 +0000354static long int dram_size (long int mamr_value, long int *base,
355 long int maxsize)
wdenkf8cac652002-08-26 22:36:39 +0000356{
wdenkc83bf6a2004-01-06 22:38:14 +0000357 volatile immap_t *immap = (immap_t *) CFG_IMMR;
358 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenkf8cac652002-08-26 22:36:39 +0000359
wdenkc83bf6a2004-01-06 22:38:14 +0000360 memctl->memc_mamr = mamr_value;
wdenkf8cac652002-08-26 22:36:39 +0000361
wdenkc83bf6a2004-01-06 22:38:14 +0000362 return (get_ram_size (base, maxsize));
wdenkf8cac652002-08-26 22:36:39 +0000363}
364
365u_long *my_sernum;
366
367int misc_init_r (void)
368{
369 DECLARE_GLOBAL_DATA_PTR;
370
371 char tmp[50];
372 u_char *e = gd->bd->bi_enetaddr;
373
374 /* save serial numbre from flash (uniquely programmed) */
wdenkc83bf6a2004-01-06 22:38:14 +0000375 my_sernum = malloc (8);
376 memcpy (my_sernum, gd->bd->bi_sernum, 8);
wdenkf8cac652002-08-26 22:36:39 +0000377
378 /* save env variables according to sernum */
wdenkc83bf6a2004-01-06 22:38:14 +0000379 sprintf (tmp, "%08lx%08lx", my_sernum[0], my_sernum[1]);
380 setenv ("serial#", tmp);
wdenkf8cac652002-08-26 22:36:39 +0000381
wdenkc83bf6a2004-01-06 22:38:14 +0000382 sprintf (tmp, "%02x:%02x:%02x:%02x:%02x:%02x", e[0], e[1], e[2], e[3],
383 e[4], e[5]);
384 setenv ("ethaddr", tmp);
wdenkf8cac652002-08-26 22:36:39 +0000385 return (0);
386}
387
388void load_sernum_ethaddr (void)
389{
390 DECLARE_GLOBAL_DATA_PTR;
391
392 int i;
wdenkc83bf6a2004-01-06 22:38:14 +0000393 bd_t *bd = gd->bd;
wdenkf8cac652002-08-26 22:36:39 +0000394
395 for (i = 0; i < 8; i++) {
396 bd->bi_sernum[i] = *(u_char *) (CFG_FLASH_SN_BASE + i);
397 }
398 bd->bi_enetaddr[0] = 0x10;
399 bd->bi_enetaddr[1] = 0x20;
400 bd->bi_enetaddr[2] = 0x30;
401 bd->bi_enetaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2];
402 bd->bi_enetaddr[4] = bd->bi_sernum[5];
403 bd->bi_enetaddr[5] = bd->bi_sernum[6];
404}