blob: d49fa8ca21af98754e7588ae30b582cbb15ac1c7 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkf8cac652002-08-26 22:36:39 +00009 */
10
11#include <common.h>
12#include <malloc.h>
13#include <mpc8xx.h>
Heiko Schocher50219e62009-03-26 07:33:59 +010014#include <net.h>
wdenkf8cac652002-08-26 22:36:39 +000015
Wolfgang Denk6405a152006-03-31 18:32:53 +020016DECLARE_GLOBAL_DATA_PTR;
wdenkf8cac652002-08-26 22:36:39 +000017
18static long int dram_size (long int, long int *, long int);
19
wdenkf8cac652002-08-26 22:36:39 +000020#define _NOT_USED_ 0xFFFFFFFF
21
wdenk87249ba2004-01-06 22:38:14 +000022const uint sdram_table[] = {
wdenkf8cac652002-08-26 22:36:39 +000023#if (MPC8XX_SPEED <= 50000000L)
24 /*
25 * Single Read. (Offset 0 in UPMA RAM)
26 */
wdenk87249ba2004-01-06 22:38:14 +000027 0x0F07EC04, 0x01BBD804, 0x1FF7F440, 0xFFFFFC07,
wdenkf8cac652002-08-26 22:36:39 +000028 0xFFFFFFFF,
29
30 /*
31 * SDRAM Initialization (offset 5 in UPMA RAM)
32 *
33 * This is no UPM entry point. The following definition uses
34 * the remaining space to establish an initialization
35 * sequence, which is executed by a RUN command.
36 *
37 */
wdenk87249ba2004-01-06 22:38:14 +000038 0x1FE7F434, 0xEFABE834, 0x1FA7D435,
wdenkf8cac652002-08-26 22:36:39 +000039
40 /*
41 * Burst Read. (Offset 8 in UPMA RAM)
42 */
wdenk87249ba2004-01-06 22:38:14 +000043 0x0F07EC04, 0x10EFDC04, 0xF0AFFC00, 0xF0AFFC00,
44 0xF1AFFC00, 0xFFAFFC40, 0xFFAFFC07, 0xFFFFFFFF,
45 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
46 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000047
48 /*
49 * Single Write. (Offset 18 in UPMA RAM)
50 */
wdenk87249ba2004-01-06 22:38:14 +000051 0x0E07E804, 0x01BBD000, 0x1FF7F447, 0xFFFFFFFF,
52 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000053
54 /*
55 * Burst Write. (Offset 20 in UPMA RAM)
56 */
wdenk87249ba2004-01-06 22:38:14 +000057 0x0E07E800, 0x10EFD400, 0xF0AFFC00, 0xF0AFFC00,
58 0xF1AFFC47, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
59 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
60 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000061
62 /*
63 * Refresh (Offset 30 in UPMA RAM)
64 */
wdenk87249ba2004-01-06 22:38:14 +000065 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC84, 0xFFFFFC07,
66 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
67 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
wdenkf8cac652002-08-26 22:36:39 +000068
69 /*
70 * Exception. (Offset 3c in UPMA RAM)
71 */
wdenk87249ba2004-01-06 22:38:14 +000072 0x7FFFFC07, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
wdenkf8cac652002-08-26 22:36:39 +000073#else
74
75 /*
76 * Single Read. (Offset 0 in UPMA RAM)
77 */
wdenk87249ba2004-01-06 22:38:14 +000078 0x1F07FC04, 0xEEAFEC04, 0x11AFDC04, 0xEFBBF800,
wdenkf8cac652002-08-26 22:36:39 +000079 0x1FF7F447,
80
81 /*
82 * SDRAM Initialization (offset 5 in UPMA RAM)
83 *
84 * This is no UPM entry point. The following definition uses
85 * the remaining space to establish an initialization
86 * sequence, which is executed by a RUN command.
87 *
88 */
wdenk87249ba2004-01-06 22:38:14 +000089 0x1FF7F434, 0xEFEBE834, 0x1FB7D435,
wdenkf8cac652002-08-26 22:36:39 +000090
91 /*
92 * Burst Read. (Offset 8 in UPMA RAM)
93 */
wdenk87249ba2004-01-06 22:38:14 +000094 0x1F07FC04, 0xEEAFEC04, 0x10AFDC04, 0xF0AFFC00,
95 0xF0AFFC00, 0xF1AFFC00, 0xEFBBF800, 0x1FF7F447,
wdenkf8cac652002-08-26 22:36:39 +000096 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
97 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
98
99 /*
100 * Single Write. (Offset 18 in UPMA RAM)
101 */
wdenk87249ba2004-01-06 22:38:14 +0000102 0x1F07FC04, 0xEEAFE800, 0x01BBD004, 0x1FF7F447,
wdenkf8cac652002-08-26 22:36:39 +0000103 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
104
105 /*
106 * Burst Write. (Offset 20 in UPMA RAM)
107 */
wdenk87249ba2004-01-06 22:38:14 +0000108 0x1F07FC04, 0xEEAFE800, 0x10AFD400, 0xF0AFFC00,
109 0xF0AFFC00, 0xE1BBF804, 0x1FF7F447, _NOT_USED_,
110 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000111 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
112
113 /*
114 * Refresh (Offset 30 in UPMA RAM)
115 */
wdenk87249ba2004-01-06 22:38:14 +0000116 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
117 0xFFFFFC84, 0xFFFFFC07,
wdenkf8cac652002-08-26 22:36:39 +0000118 _NOT_USED_, _NOT_USED_, _NOT_USED_,
119 _NOT_USED_, _NOT_USED_, _NOT_USED_,
120
121 /*
122 * Exception. (Offset 3c in UPMA RAM)
123 */
124 0x7FFFFC07, /* last */
wdenk87249ba2004-01-06 22:38:14 +0000125 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000126#endif
127};
128
129/* ------------------------------------------------------------------------- */
130
131
132/*
133 * Check Board Identity:
134 *
135 */
136
137int checkboard (void)
138{
wdenk87249ba2004-01-06 22:38:14 +0000139 printf ("Board: Nexus NX823");
140 return (0);
wdenkf8cac652002-08-26 22:36:39 +0000141}
142
143/* ------------------------------------------------------------------------- */
144
Becky Brucebd99ae72008-06-09 16:03:40 -0500145phys_size_t initdram (int board_type)
wdenkf8cac652002-08-26 22:36:39 +0000146{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200147 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk87249ba2004-01-06 22:38:14 +0000148 volatile memctl8xx_t *memctl = &immap->im_memctl;
149 long int size_b0, size_b1, size8, size9;
wdenkf8cac652002-08-26 22:36:39 +0000150
wdenk87249ba2004-01-06 22:38:14 +0000151 upmconfig (UPMA, (uint *) sdram_table,
152 sizeof (sdram_table) / sizeof (uint));
wdenkf8cac652002-08-26 22:36:39 +0000153
wdenk87249ba2004-01-06 22:38:14 +0000154 /*
155 * Up to 2 Banks of 64Mbit x 2 devices
156 * Initial builds only have 1
157 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158 memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_4K;
wdenk87249ba2004-01-06 22:38:14 +0000159 memctl->memc_mar = 0x00000088;
wdenkf8cac652002-08-26 22:36:39 +0000160
wdenk87249ba2004-01-06 22:38:14 +0000161 /*
162 * Map controller SDRAM bank 0
163 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164 memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
165 memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
166 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
wdenk87249ba2004-01-06 22:38:14 +0000167 udelay (200);
wdenkf8cac652002-08-26 22:36:39 +0000168
wdenk87249ba2004-01-06 22:38:14 +0000169 /*
170 * Map controller SDRAM bank 1
171 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
173 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
wdenkf8cac652002-08-26 22:36:39 +0000174
wdenk87249ba2004-01-06 22:38:14 +0000175 /*
176 * Perform SDRAM initializsation sequence
177 */
178 memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
179 udelay (1);
180 memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - execute twice */
181 udelay (1);
wdenkf8cac652002-08-26 22:36:39 +0000182
wdenk87249ba2004-01-06 22:38:14 +0000183 memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */
184 udelay (1);
185 memctl->memc_mcr = 0x80004230; /* SDRAM bank 1 - execute twice */
186 udelay (1);
wdenkf8cac652002-08-26 22:36:39 +0000187
wdenk87249ba2004-01-06 22:38:14 +0000188 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
189 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000190
wdenk87249ba2004-01-06 22:38:14 +0000191 /*
192 * Preliminary prescaler for refresh (depends on number of
193 * banks): This value is selected for four cycles every 62.4 us
194 * with two SDRAM banks or four cycles every 31.2 us with one
195 * bank. It will be adjusted after memory sizing.
196 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200197 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
wdenkf8cac652002-08-26 22:36:39 +0000198
wdenk87249ba2004-01-06 22:38:14 +0000199 memctl->memc_mar = 0x00000088;
wdenkf8cac652002-08-26 22:36:39 +0000200
201
wdenk87249ba2004-01-06 22:38:14 +0000202 /*
203 * Check Bank 0 Memory Size for re-configuration
204 *
205 * try 8 column mode
206 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200207 size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *) SDRAM_BASE1_PRELIM,
wdenk87249ba2004-01-06 22:38:14 +0000208 SDRAM_MAX_SIZE);
wdenkf8cac652002-08-26 22:36:39 +0000209
wdenk87249ba2004-01-06 22:38:14 +0000210 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000211
wdenk87249ba2004-01-06 22:38:14 +0000212 /*
213 * try 9 column mode
214 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200215 size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE1_PRELIM,
wdenk87249ba2004-01-06 22:38:14 +0000216 SDRAM_MAX_SIZE);
wdenkf8cac652002-08-26 22:36:39 +0000217
wdenk87249ba2004-01-06 22:38:14 +0000218 if (size8 < size9) { /* leave configuration at 9 columns */
219 size_b0 = size9;
wdenkf8cac652002-08-26 22:36:39 +0000220/* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
wdenk87249ba2004-01-06 22:38:14 +0000221 } else { /* back to 8 columns */
222 size_b0 = size8;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200223 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
wdenk87249ba2004-01-06 22:38:14 +0000224 udelay (500);
wdenkf8cac652002-08-26 22:36:39 +0000225/* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
wdenk87249ba2004-01-06 22:38:14 +0000226 }
wdenkf8cac652002-08-26 22:36:39 +0000227
228 /*
229 * Check Bank 1 Memory Size
230 * use current column settings
231 * [9 column SDRAM may also be used in 8 column mode,
232 * but then only half the real size will be used.]
233 */
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200234 size_b1 = dram_size (memctl->memc_mamr, (long *) SDRAM_BASE2_PRELIM,
wdenk87249ba2004-01-06 22:38:14 +0000235 SDRAM_MAX_SIZE);
wdenkf8cac652002-08-26 22:36:39 +0000236/* debug ("SDRAM Bank 1: %ld MB\n", size8 >> 20); */
237
wdenk87249ba2004-01-06 22:38:14 +0000238 udelay (1000);
239
240 /*
241 * Adjust refresh rate depending on SDRAM type, both banks
242 * For types > 128 MBit leave it at the current (fast) rate
243 */
244 if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
245 /* reduce to 15.6 us (62.4 us / quad) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200246 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
wdenk87249ba2004-01-06 22:38:14 +0000247 udelay (1000);
248 }
wdenkf8cac652002-08-26 22:36:39 +0000249
wdenk87249ba2004-01-06 22:38:14 +0000250 /*
251 * Final mapping: map bigger bank first
252 */
253 if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
wdenkf8cac652002-08-26 22:36:39 +0000254
wdenk87249ba2004-01-06 22:38:14 +0000255 memctl->memc_or2 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200256 ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
wdenk87249ba2004-01-06 22:38:14 +0000257 memctl->memc_br2 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200258 (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenkf8cac652002-08-26 22:36:39 +0000259
wdenk87249ba2004-01-06 22:38:14 +0000260 if (size_b0 > 0) {
261 /*
262 * Position Bank 0 immediately above Bank 1
263 */
264 memctl->memc_or1 =
265 ((-size_b0) & 0xFFFF0000) |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200266 CONFIG_SYS_OR_TIMING_SDRAM;
wdenk87249ba2004-01-06 22:38:14 +0000267 memctl->memc_br1 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200268 ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA |
wdenk87249ba2004-01-06 22:38:14 +0000269 BR_V)
270 + size_b1;
271 } else {
272 unsigned long reg;
wdenkf8cac652002-08-26 22:36:39 +0000273
wdenk87249ba2004-01-06 22:38:14 +0000274 /*
275 * No bank 0
276 *
277 * invalidate bank
278 */
279 memctl->memc_br1 = 0;
wdenkf8cac652002-08-26 22:36:39 +0000280
wdenk87249ba2004-01-06 22:38:14 +0000281 /* adjust refresh rate depending on SDRAM type, one bank */
282 reg = memctl->memc_mptpr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200283 reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
wdenk87249ba2004-01-06 22:38:14 +0000284 memctl->memc_mptpr = reg;
285 }
wdenkf8cac652002-08-26 22:36:39 +0000286
wdenk87249ba2004-01-06 22:38:14 +0000287 } else { /* SDRAM Bank 0 is bigger - map first */
wdenkf8cac652002-08-26 22:36:39 +0000288
wdenk87249ba2004-01-06 22:38:14 +0000289 memctl->memc_or1 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200290 ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
wdenk87249ba2004-01-06 22:38:14 +0000291 memctl->memc_br1 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200292 (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenkf8cac652002-08-26 22:36:39 +0000293
wdenk87249ba2004-01-06 22:38:14 +0000294 if (size_b1 > 0) {
295 /*
296 * Position Bank 1 immediately above Bank 0
297 */
298 memctl->memc_or2 =
299 ((-size_b1) & 0xFFFF0000) |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200300 CONFIG_SYS_OR_TIMING_SDRAM;
wdenk87249ba2004-01-06 22:38:14 +0000301 memctl->memc_br2 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200302 ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA |
wdenk87249ba2004-01-06 22:38:14 +0000303 BR_V)
304 + size_b0;
305 } else {
306 unsigned long reg;
wdenkf8cac652002-08-26 22:36:39 +0000307
wdenk87249ba2004-01-06 22:38:14 +0000308 /*
309 * No bank 1
310 *
311 * invalidate bank
312 */
313 memctl->memc_br2 = 0;
314
315 /* adjust refresh rate depending on SDRAM type, one bank */
316 reg = memctl->memc_mptpr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200317 reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
wdenk87249ba2004-01-06 22:38:14 +0000318 memctl->memc_mptpr = reg;
319 }
wdenkf8cac652002-08-26 22:36:39 +0000320 }
wdenkf8cac652002-08-26 22:36:39 +0000321
wdenk87249ba2004-01-06 22:38:14 +0000322 udelay (10000);
wdenkf8cac652002-08-26 22:36:39 +0000323
wdenk87249ba2004-01-06 22:38:14 +0000324 return (size_b0 + size_b1);
wdenkf8cac652002-08-26 22:36:39 +0000325}
326
327/* ------------------------------------------------------------------------- */
328
329/*
330 * Check memory range for valid RAM. A simple memory test determines
331 * the actually available RAM size between addresses `base' and
332 * `base + maxsize'. Some (not all) hardware errors are detected:
333 * - short between address lines
334 * - short between data lines
335 */
336
wdenk87249ba2004-01-06 22:38:14 +0000337static long int dram_size (long int mamr_value, long int *base,
338 long int maxsize)
wdenkf8cac652002-08-26 22:36:39 +0000339{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200340 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk87249ba2004-01-06 22:38:14 +0000341 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenkf8cac652002-08-26 22:36:39 +0000342
wdenk87249ba2004-01-06 22:38:14 +0000343 memctl->memc_mamr = mamr_value;
wdenkf8cac652002-08-26 22:36:39 +0000344
wdenk87249ba2004-01-06 22:38:14 +0000345 return (get_ram_size (base, maxsize));
wdenkf8cac652002-08-26 22:36:39 +0000346}
347
wdenkf8cac652002-08-26 22:36:39 +0000348int misc_init_r (void)
349{
Mike Frysinger5a3d56d2009-02-11 19:36:20 -0500350 int i;
wdenkf8cac652002-08-26 22:36:39 +0000351 char tmp[50];
Mike Frysinger5a3d56d2009-02-11 19:36:20 -0500352 uchar ethaddr[6];
353 bd_t *bd = gd->bd;
Heiko Schocher50219e62009-03-26 07:33:59 +0100354 ulong *my_sernum = (unsigned long *)&bd->bi_sernum;
wdenkf8cac652002-08-26 22:36:39 +0000355
Mike Frysinger5a3d56d2009-02-11 19:36:20 -0500356 /* load unique serial number */
357 for (i = 0; i < 8; ++i)
358 bd->bi_sernum[i] = *(u_char *) (CONFIG_SYS_FLASH_SN_BASE + i);
wdenkf8cac652002-08-26 22:36:39 +0000359
360 /* save env variables according to sernum */
wdenk87249ba2004-01-06 22:38:14 +0000361 sprintf (tmp, "%08lx%08lx", my_sernum[0], my_sernum[1]);
362 setenv ("serial#", tmp);
wdenkf8cac652002-08-26 22:36:39 +0000363
Mike Frysinger5a3d56d2009-02-11 19:36:20 -0500364 if (!eth_getenv_enetaddr("ethaddr", ethaddr)) {
365 ethaddr[0] = 0x10;
366 ethaddr[1] = 0x20;
367 ethaddr[2] = 0x30;
368 ethaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2];
369 ethaddr[4] = bd->bi_sernum[5];
370 ethaddr[5] = bd->bi_sernum[6];
wdenkf8cac652002-08-26 22:36:39 +0000371 }
Mike Frysinger5a3d56d2009-02-11 19:36:20 -0500372
373 return 0;
wdenkf8cac652002-08-26 22:36:39 +0000374}