blob: 6d17830575f404e852d4b174269f802a8d0ddf50 [file] [log] [blame]
wdenkf8cac652002-08-26 22:36:39 +00001/*
Wolfgang Denk8d82cc02008-09-16 18:02:19 +02002 * (C) Copyright 2000-2008
wdenkf8cac652002-08-26 22:36:39 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkf8cac652002-08-26 22:36:39 +00006 */
7
8#include <common.h>
Heiko Schocher0bdca572010-02-09 15:50:21 +01009#include <hwconfig.h>
wdenkf8cac652002-08-26 22:36:39 +000010#include <mpc8xx.h>
wdenkb983fa22004-01-16 00:30:56 +000011#ifdef CONFIG_PS2MULT
12#include <ps2mult.h>
13#endif
wdenkf8cac652002-08-26 22:36:39 +000014
Heiko Schocher0bdca572010-02-09 15:50:21 +010015#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
16#include <libfdt.h>
17#endif
18
Wolfgang Denk8d82cc02008-09-16 18:02:19 +020019extern flash_info_t flash_info[]; /* FLASH chips info */
20
Wolfgang Denk6405a152006-03-31 18:32:53 +020021DECLARE_GLOBAL_DATA_PTR;
wdenkf8cac652002-08-26 22:36:39 +000022
23static long int dram_size (long int, long int *, long int);
24
wdenkf8cac652002-08-26 22:36:39 +000025#define _NOT_USED_ 0xFFFFFFFF
26
Jens Gehrlein6b206d62007-09-26 17:55:54 +020027/* UPM initialization table for SDRAM: 40, 50, 66 MHz CLKOUT @ CAS latency 2, tWR=2 */
wdenkf8cac652002-08-26 22:36:39 +000028const uint sdram_table[] =
29{
30 /*
31 * Single Read. (Offset 0 in UPMA RAM)
32 */
33 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
34 0x1FF5FC47, /* last */
35 /*
36 * SDRAM Initialization (offset 5 in UPMA RAM)
37 *
38 * This is no UPM entry point. The following definition uses
39 * the remaining space to establish an initialization
40 * sequence, which is executed by a RUN command.
41 *
42 */
43 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
44 /*
45 * Burst Read. (Offset 8 in UPMA RAM)
46 */
47 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
48 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
49 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
50 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
51 /*
52 * Single Write. (Offset 18 in UPMA RAM)
53 */
Jens Gehrlein6b206d62007-09-26 17:55:54 +020054 0x1F0DFC04, 0xEEABBC00, 0x11B77C04, 0xEFFAFC44,
55 0x1FF5FC47, /* last */
56 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +000057 /*
58 * Burst Write. (Offset 20 in UPMA RAM)
59 */
60 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
Jens Gehrlein6b206d62007-09-26 17:55:54 +020061 0xF0AFFC00, 0xF0AFFC04, 0xE1BAFC44, 0x1FF5FC47, /* last */
wdenkf8cac652002-08-26 22:36:39 +000062 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
63 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
64 /*
65 * Refresh (Offset 30 in UPMA RAM)
66 */
67 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
68 0xFFFFFC84, 0xFFFFFC07, /* last */
69 _NOT_USED_, _NOT_USED_,
70 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
71 /*
72 * Exception. (Offset 3c in UPMA RAM)
73 */
Jens Gehrlein6b206d62007-09-26 17:55:54 +020074 0xFFFFFC07, /* last */
wdenkf8cac652002-08-26 22:36:39 +000075 _NOT_USED_, _NOT_USED_, _NOT_USED_,
76};
77
78/* ------------------------------------------------------------------------- */
79
80
81/*
82 * Check Board Identity:
83 *
84 * Test TQ ID string (TQM8xx...)
85 * If present, check for "L" type (no second DRAM bank),
86 * otherwise "L" type is assumed as default.
87 *
wdenk1ebf41e2004-01-02 14:00:00 +000088 * Set board_type to 'L' for "L" type, 'M' for "M" type, 0 else.
wdenkf8cac652002-08-26 22:36:39 +000089 */
90
91int checkboard (void)
92{
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +000093 char buf[64];
94 int i;
95 int l = getenv_f("serial#", buf, sizeof(buf));
wdenkf8cac652002-08-26 22:36:39 +000096
97 puts ("Board: ");
98
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +000099 if (l < 0 || strncmp(buf, "TQM8", 4)) {
wdenkf8cac652002-08-26 22:36:39 +0000100 puts ("### No HW ID - assuming TQM8xxL\n");
101 return (0);
102 }
103
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000104 if ((buf[6] == 'L')) { /* a TQM8xxL type */
wdenkf8cac652002-08-26 22:36:39 +0000105 gd->board_type = 'L';
106 }
107
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000108 if ((buf[6] == 'M')) { /* a TQM8xxM type */
wdenk1ebf41e2004-01-02 14:00:00 +0000109 gd->board_type = 'M';
110 }
111
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000112 if ((buf[6] == 'D')) { /* a TQM885D type */
Markus Klotzbuecher13af9f02006-07-12 15:26:01 +0200113 gd->board_type = 'D';
114 }
115
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000116 for (i = 0; i < l; ++i) {
117 if (buf[i] == ' ')
wdenkf8cac652002-08-26 22:36:39 +0000118 break;
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000119 putc (buf[i]);
wdenkf8cac652002-08-26 22:36:39 +0000120 }
Masahiro Yamada0e9843382014-12-15 23:26:06 +0900121
wdenkf8cac652002-08-26 22:36:39 +0000122 putc ('\n');
123
124 return (0);
125}
126
127/* ------------------------------------------------------------------------- */
128
Becky Brucebd99ae72008-06-09 16:03:40 -0500129phys_size_t initdram (int board_type)
wdenkf8cac652002-08-26 22:36:39 +0000130{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkf8cac652002-08-26 22:36:39 +0000132 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenkb50cde52004-01-24 20:25:54 +0000133 long int size8, size9, size10;
wdenkf8cac652002-08-26 22:36:39 +0000134 long int size_b0 = 0;
135 long int size_b1 = 0;
136
137 upmconfig (UPMA, (uint *) sdram_table,
138 sizeof (sdram_table) / sizeof (uint));
139
140 /*
141 * Preliminary prescaler for refresh (depends on number of
142 * banks): This value is selected for four cycles every 62.4 us
143 * with two SDRAM banks or four cycles every 31.2 us with one
144 * bank. It will be adjusted after memory sizing.
145 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
wdenkf8cac652002-08-26 22:36:39 +0000147
148 /*
149 * The following value is used as an address (i.e. opcode) for
150 * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
151 * the port size is 32bit the SDRAM does NOT "see" the lower two
152 * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
153 * MICRON SDRAMs:
154 * -> 0 00 010 0 010
155 * | | | | +- Burst Length = 4
156 * | | | +----- Burst Type = Sequential
157 * | | +------- CAS Latency = 2
158 * | +----------- Operating Mode = Standard
159 * +-------------- Write Burst Mode = Programmed Burst Length
160 */
161 memctl->memc_mar = 0x00000088;
162
163 /*
164 * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
165 * preliminary addresses - these have to be modified after the
166 * SDRAM size has been determined.
167 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200168 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
169 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
wdenkf8cac652002-08-26 22:36:39 +0000170
171#ifndef CONFIG_CAN_DRIVER
wdenk1ebf41e2004-01-02 14:00:00 +0000172 if ((board_type != 'L') &&
Markus Klotzbuecher13af9f02006-07-12 15:26:01 +0200173 (board_type != 'M') &&
Martin Krausefa83bbb2007-09-26 17:55:56 +0200174 (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200175 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
176 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
wdenkf8cac652002-08-26 22:36:39 +0000177 }
178#endif /* CONFIG_CAN_DRIVER */
179
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200180 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
wdenkf8cac652002-08-26 22:36:39 +0000181
182 udelay (200);
183
184 /* perform SDRAM initializsation sequence */
185
186 memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
187 udelay (1);
188 memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
189 udelay (1);
190
191#ifndef CONFIG_CAN_DRIVER
wdenk1ebf41e2004-01-02 14:00:00 +0000192 if ((board_type != 'L') &&
Markus Klotzbuecher13af9f02006-07-12 15:26:01 +0200193 (board_type != 'M') &&
Wolfgang Denk8bf7e1f2006-07-21 18:51:56 +0200194 (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
wdenkf8cac652002-08-26 22:36:39 +0000195 memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
196 udelay (1);
197 memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */
198 udelay (1);
199 }
200#endif /* CONFIG_CAN_DRIVER */
201
202 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
203
204 udelay (1000);
205
206 /*
207 * Check Bank 0 Memory Size for re-configuration
208 *
209 * try 8 column mode
210 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200211 size8 = dram_size (CONFIG_SYS_MAMR_8COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
wdenk1ebf41e2004-01-02 14:00:00 +0000212 debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size8 >> 20);
wdenkf8cac652002-08-26 22:36:39 +0000213
214 udelay (1000);
215
216 /*
217 * try 9 column mode
218 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200219 size9 = dram_size (CONFIG_SYS_MAMR_9COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
wdenk1ebf41e2004-01-02 14:00:00 +0000220 debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size9 >> 20);
wdenkf8cac652002-08-26 22:36:39 +0000221
wdenkb50cde52004-01-24 20:25:54 +0000222 udelay(1000);
223
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200224#if defined(CONFIG_SYS_MAMR_10COL)
wdenkb50cde52004-01-24 20:25:54 +0000225 /*
226 * try 10 column mode
227 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200228 size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
wdenkb50cde52004-01-24 20:25:54 +0000229 debug ("SDRAM Bank 0 in 10 column mode: %ld MB\n", size10 >> 20);
230#else
231 size10 = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200232#endif /* CONFIG_SYS_MAMR_10COL */
wdenkb50cde52004-01-24 20:25:54 +0000233
234 if ((size8 < size10) && (size9 < size10)) {
235 size_b0 = size10;
236 } else if ((size8 < size9) && (size10 < size9)) {
wdenkf8cac652002-08-26 22:36:39 +0000237 size_b0 = size9;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200238 memctl->memc_mamr = CONFIG_SYS_MAMR_9COL;
wdenkb50cde52004-01-24 20:25:54 +0000239 udelay (500);
240 } else {
wdenkf8cac652002-08-26 22:36:39 +0000241 size_b0 = size8;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200242 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
wdenkf8cac652002-08-26 22:36:39 +0000243 udelay (500);
wdenkf8cac652002-08-26 22:36:39 +0000244 }
wdenk1ebf41e2004-01-02 14:00:00 +0000245 debug ("SDRAM Bank 0: %ld MB\n", size_b0 >> 20);
wdenkf8cac652002-08-26 22:36:39 +0000246
247#ifndef CONFIG_CAN_DRIVER
wdenk1ebf41e2004-01-02 14:00:00 +0000248 if ((board_type != 'L') &&
Markus Klotzbuecher13af9f02006-07-12 15:26:01 +0200249 (board_type != 'M') &&
Martin Krausefa83bbb2007-09-26 17:55:56 +0200250 (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
wdenkf8cac652002-08-26 22:36:39 +0000251 /*
252 * Check Bank 1 Memory Size
253 * use current column settings
254 * [9 column SDRAM may also be used in 8 column mode,
255 * but then only half the real size will be used.]
256 */
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200257 size_b1 = dram_size (memctl->memc_mamr, (long int *)SDRAM_BASE3_PRELIM,
wdenk1ebf41e2004-01-02 14:00:00 +0000258 SDRAM_MAX_SIZE);
259 debug ("SDRAM Bank 1: %ld MB\n", size_b1 >> 20);
wdenkf8cac652002-08-26 22:36:39 +0000260 } else {
261 size_b1 = 0;
262 }
wdenk1ebf41e2004-01-02 14:00:00 +0000263#endif /* CONFIG_CAN_DRIVER */
wdenkf8cac652002-08-26 22:36:39 +0000264
265 udelay (1000);
266
267 /*
268 * Adjust refresh rate depending on SDRAM type, both banks
269 * For types > 128 MBit leave it at the current (fast) rate
270 */
271 if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
272 /* reduce to 15.6 us (62.4 us / quad) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200273 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
wdenkf8cac652002-08-26 22:36:39 +0000274 udelay (1000);
275 }
276
277 /*
278 * Final mapping: map bigger bank first
279 */
280 if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
281
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200282 memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
283 memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenkf8cac652002-08-26 22:36:39 +0000284
285 if (size_b0 > 0) {
286 /*
287 * Position Bank 0 immediately above Bank 1
288 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200289 memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
290 memctl->memc_br2 = ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
wdenkb50cde52004-01-24 20:25:54 +0000291 + size_b1;
wdenkf8cac652002-08-26 22:36:39 +0000292 } else {
293 unsigned long reg;
294
295 /*
296 * No bank 0
297 *
298 * invalidate bank
299 */
300 memctl->memc_br2 = 0;
301
302 /* adjust refresh rate depending on SDRAM type, one bank */
303 reg = memctl->memc_mptpr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200304 reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
wdenkf8cac652002-08-26 22:36:39 +0000305 memctl->memc_mptpr = reg;
306 }
307
308 } else { /* SDRAM Bank 0 is bigger - map first */
309
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200310 memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
wdenkf8cac652002-08-26 22:36:39 +0000311 memctl->memc_br2 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200312 (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenkf8cac652002-08-26 22:36:39 +0000313
314 if (size_b1 > 0) {
315 /*
316 * Position Bank 1 immediately above Bank 0
317 */
318 memctl->memc_or3 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200319 ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
wdenkf8cac652002-08-26 22:36:39 +0000320 memctl->memc_br3 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200321 ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
wdenkf8cac652002-08-26 22:36:39 +0000322 + size_b0;
323 } else {
324 unsigned long reg;
325
326#ifndef CONFIG_CAN_DRIVER
327 /*
328 * No bank 1
329 *
330 * invalidate bank
331 */
332 memctl->memc_br3 = 0;
333#endif /* CONFIG_CAN_DRIVER */
334
335 /* adjust refresh rate depending on SDRAM type, one bank */
336 reg = memctl->memc_mptpr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200337 reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
wdenkf8cac652002-08-26 22:36:39 +0000338 memctl->memc_mptpr = reg;
339 }
340 }
341
342 udelay (10000);
343
344#ifdef CONFIG_CAN_DRIVER
Jens Gehrlein74120132007-09-26 17:55:54 +0200345 /* UPM initialization for CAN @ CLKOUT <= 66 MHz */
346
wdenkf8cac652002-08-26 22:36:39 +0000347 /* Initialize OR3 / BR3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200348 memctl->memc_or3 = CONFIG_SYS_OR3_CAN;
349 memctl->memc_br3 = CONFIG_SYS_BR3_CAN;
wdenkf8cac652002-08-26 22:36:39 +0000350
351 /* Initialize MBMR */
wdenkc0d54ae2003-11-25 16:55:19 +0000352 memctl->memc_mbmr = MBMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */
wdenkf8cac652002-08-26 22:36:39 +0000353
354 /* Initialize UPMB for CAN: single read */
Jens Gehrlein74120132007-09-26 17:55:54 +0200355 memctl->memc_mdr = 0xFFFFCC04;
wdenkf8cac652002-08-26 22:36:39 +0000356 memctl->memc_mcr = 0x0100 | UPMB;
357
358 memctl->memc_mdr = 0x0FFFD004;
359 memctl->memc_mcr = 0x0101 | UPMB;
360
361 memctl->memc_mdr = 0x0FFFC000;
362 memctl->memc_mcr = 0x0102 | UPMB;
363
364 memctl->memc_mdr = 0x3FFFC004;
365 memctl->memc_mcr = 0x0103 | UPMB;
366
Jens Gehrlein74120132007-09-26 17:55:54 +0200367 memctl->memc_mdr = 0xFFFFDC07;
wdenkf8cac652002-08-26 22:36:39 +0000368 memctl->memc_mcr = 0x0104 | UPMB;
369
370 /* Initialize UPMB for CAN: single write */
Jens Gehrlein74120132007-09-26 17:55:54 +0200371 memctl->memc_mdr = 0xFFFCCC04;
wdenkf8cac652002-08-26 22:36:39 +0000372 memctl->memc_mcr = 0x0118 | UPMB;
373
Jens Gehrlein74120132007-09-26 17:55:54 +0200374 memctl->memc_mdr = 0xCFFCDC04;
wdenkf8cac652002-08-26 22:36:39 +0000375 memctl->memc_mcr = 0x0119 | UPMB;
376
Jens Gehrlein74120132007-09-26 17:55:54 +0200377 memctl->memc_mdr = 0x3FFCC000;
wdenkf8cac652002-08-26 22:36:39 +0000378 memctl->memc_mcr = 0x011A | UPMB;
379
Jens Gehrlein74120132007-09-26 17:55:54 +0200380 memctl->memc_mdr = 0xFFFCC004;
wdenkf8cac652002-08-26 22:36:39 +0000381 memctl->memc_mcr = 0x011B | UPMB;
382
Jens Gehrlein74120132007-09-26 17:55:54 +0200383 memctl->memc_mdr = 0xFFFDC405;
wdenkf8cac652002-08-26 22:36:39 +0000384 memctl->memc_mcr = 0x011C | UPMB;
385#endif /* CONFIG_CAN_DRIVER */
386
wdenk0a658552003-08-05 17:43:17 +0000387#ifdef CONFIG_ISP1362_USB
388 /* Initialize OR5 / BR5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200389 memctl->memc_or5 = CONFIG_SYS_OR5_ISP1362;
390 memctl->memc_br5 = CONFIG_SYS_BR5_ISP1362;
wdenk0a658552003-08-05 17:43:17 +0000391#endif /* CONFIG_ISP1362_USB */
wdenkf8cac652002-08-26 22:36:39 +0000392 return (size_b0 + size_b1);
393}
394
395/* ------------------------------------------------------------------------- */
396
397/*
398 * Check memory range for valid RAM. A simple memory test determines
399 * the actually available RAM size between addresses `base' and
400 * `base + maxsize'. Some (not all) hardware errors are detected:
401 * - short between address lines
402 * - short between data lines
403 */
404
wdenk1ebf41e2004-01-02 14:00:00 +0000405static long int dram_size (long int mamr_value, long int *base, long int maxsize)
wdenkf8cac652002-08-26 22:36:39 +0000406{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200407 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkf8cac652002-08-26 22:36:39 +0000408 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenkf8cac652002-08-26 22:36:39 +0000409
410 memctl->memc_mamr = mamr_value;
411
wdenk87249ba2004-01-06 22:38:14 +0000412 return (get_ram_size(base, maxsize));
wdenkf8cac652002-08-26 22:36:39 +0000413}
414
415/* ------------------------------------------------------------------------- */
wdenkb983fa22004-01-16 00:30:56 +0000416
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200417#ifdef CONFIG_MISC_INIT_R
Mike Frysingerdcc95c42009-02-11 20:09:52 -0500418extern void load_sernum_ethaddr(void);
wdenkb983fa22004-01-16 00:30:56 +0000419int misc_init_r (void)
420{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200421 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200422 volatile memctl8xx_t *memctl = &immap->im_memctl;
423
Mike Frysingerdcc95c42009-02-11 20:09:52 -0500424 load_sernum_ethaddr();
425
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200426#ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200427 int scy, trlx, flash_or_timing, clk_diff;
428
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200429 scy = (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_SCY_MSK) >> 4;
430 if (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_TRLX) {
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200431 trlx = OR_TRLX;
432 scy *= 2;
Wolfgang Denk1837f822008-09-17 10:17:55 +0200433 } else {
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200434 trlx = 0;
Wolfgang Denk1837f822008-09-17 10:17:55 +0200435 }
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200436
Wolfgang Denk1837f822008-09-17 10:17:55 +0200437 /*
438 * We assume that each 10MHz of bus clock require 1-clk SCY
439 * adjustment.
440 */
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200441 clk_diff = (gd->bus_clk / 1000000) - 50;
442
Wolfgang Denk1837f822008-09-17 10:17:55 +0200443 /*
444 * We need proper rounding here. This is what the "+5" and "-5"
445 * are here for.
446 */
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200447 if (clk_diff >= 0)
448 scy += (clk_diff + 5) / 10;
449 else
450 scy += (clk_diff - 5) / 10;
451
Wolfgang Denk1837f822008-09-17 10:17:55 +0200452 /*
453 * For bus frequencies above 50MHz, we want to use relaxed timing
454 * (OR_TRLX).
455 */
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200456 if (gd->bus_clk >= 50000000)
457 trlx = OR_TRLX;
458 else
459 trlx = 0;
460
461 if (trlx)
462 scy /= 2;
463
464 if (scy > 0xf)
465 scy = 0xf;
466 if (scy < 1)
467 scy = 1;
468
469 flash_or_timing = (scy << 4) | trlx |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200470 (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & ~(OR_TRLX | OR_SCY_MSK));
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200471
Wolfgang Denk1837f822008-09-17 10:17:55 +0200472 memctl->memc_or0 =
473 flash_or_timing | (-flash_info[0].size & OR_AM_MSK);
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200474#else
Wolfgang Denk1837f822008-09-17 10:17:55 +0200475 memctl->memc_or0 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200476 CONFIG_SYS_OR_TIMING_FLASH | (-flash_info[0].size & OR_AM_MSK);
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200477#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200478 memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V;
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200479
480 debug ("## BR0: 0x%08x OR0: 0x%08x\n",
Wolfgang Denk1837f822008-09-17 10:17:55 +0200481 memctl->memc_br0, memctl->memc_or0);
wdenkb983fa22004-01-16 00:30:56 +0000482
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200483 if (flash_info[1].size) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200484#ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200485 memctl->memc_or1 = flash_or_timing |
Wolfgang Denk1837f822008-09-17 10:17:55 +0200486 (-flash_info[1].size & 0xFFFF8000);
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200487#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200488 memctl->memc_or1 = CONFIG_SYS_OR_TIMING_FLASH |
Wolfgang Denk1837f822008-09-17 10:17:55 +0200489 (-flash_info[1].size & 0xFFFF8000);
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200490#endif
Wolfgang Denk1837f822008-09-17 10:17:55 +0200491 memctl->memc_br1 =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200492 ((CONFIG_SYS_FLASH_BASE +
Wolfgang Denk1837f822008-09-17 10:17:55 +0200493 flash_info[0].
494 size) & BR_BA_MSK) | BR_MS_GPCM | BR_V;
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200495
496 debug ("## BR1: 0x%08x OR1: 0x%08x\n",
Wolfgang Denk1837f822008-09-17 10:17:55 +0200497 memctl->memc_br1, memctl->memc_or1);
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200498 } else {
Wolfgang Denk1837f822008-09-17 10:17:55 +0200499 memctl->memc_br1 = 0; /* invalidate bank */
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200500
501 debug ("## DISABLE BR1: 0x%08x OR1: 0x%08x\n",
Wolfgang Denk1837f822008-09-17 10:17:55 +0200502 memctl->memc_br1, memctl->memc_or1);
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200503 }
504
505# ifdef CONFIG_IDE_LED
wdenkb983fa22004-01-16 00:30:56 +0000506 /* Configure PA15 as output port */
507 immap->im_ioport.iop_padir |= 0x0001;
508 immap->im_ioport.iop_paodr |= 0x0001;
509 immap->im_ioport.iop_papar &= ~0x0001;
510 immap->im_ioport.iop_padat &= ~0x0001; /* turn it off */
wdenk3cc599e2004-08-01 13:09:47 +0000511# endif
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200512
wdenkb983fa22004-01-16 00:30:56 +0000513 return (0);
514}
Wolfgang Denk8d82cc02008-09-16 18:02:19 +0200515#endif /* CONFIG_MISC_INIT_R */
516
wdenkb983fa22004-01-16 00:30:56 +0000517
wdenk3cc599e2004-08-01 13:09:47 +0000518# ifdef CONFIG_IDE_LED
wdenkb983fa22004-01-16 00:30:56 +0000519void ide_led (uchar led, uchar status)
520{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200521 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkb983fa22004-01-16 00:30:56 +0000522
523 /* We have one led for both pcmcia slots */
524 if (status) { /* led on */
525 immap->im_ioport.iop_padat |= 0x0001;
526 } else {
527 immap->im_ioport.iop_padat &= ~0x0001;
528 }
529}
wdenk3cc599e2004-08-01 13:09:47 +0000530# endif
wdenkb983fa22004-01-16 00:30:56 +0000531
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200532#ifdef CONFIG_LCD_INFO
533#include <lcd.h>
Anatolij Gustschine94895d2008-11-03 15:30:34 +0100534#include <version.h>
Peter Tyser62948502008-11-03 09:30:59 -0600535#include <timestamp.h>
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200536
537void lcd_show_board_info(void)
538{
Anatolij Gustschine94895d2008-11-03 15:30:34 +0100539 char temp[32];
540
Peter Tyser62948502008-11-03 09:30:59 -0600541 lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200542 lcd_printf ("(C) 2008 DENX Software Engineering GmbH\n");
543 lcd_printf (" Wolfgang DENK, wd@denx.de\n");
544#ifdef CONFIG_LCD_INFO_BELOW_LOGO
545 lcd_printf ("MPC823 CPU at %s MHz\n",
546 strmhz(temp, gd->cpu_clk));
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200547 lcd_printf (" %ld MB RAM, %ld MB Flash\n",
548 gd->ram_size >> 20,
549 gd->bd->bi_flashsize >> 20 );
550#else
551 /* leave one blank line */
552 lcd_printf ("\nMPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash\n",
553 strmhz(temp, gd->cpu_clk),
554 gd->ram_size >> 20,
555 gd->bd->bi_flashsize >> 20 );
556#endif /* CONFIG_LCD_INFO_BELOW_LOGO */
557}
558#endif /* CONFIG_LCD_INFO */
559
Heiko Schocher0bdca572010-02-09 15:50:21 +0100560/*
561 * Device Tree Support
562 */
563#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
564int fdt_set_node_and_value (void *blob,
565 char *nodename,
566 char *regname,
567 void *var,
568 int size)
569{
570 int ret = 0;
571 int nodeoffset = 0;
572
573 nodeoffset = fdt_path_offset (blob, nodename);
574 if (nodeoffset >= 0) {
575 ret = fdt_setprop (blob, nodeoffset, regname, var,
576 size);
577 if (ret < 0) {
578 printf("ft_blob_update(): "
579 "cannot set %s/%s property; err: %s\n",
580 nodename, regname, fdt_strerror (ret));
581 }
582 } else {
583 printf("ft_blob_update(): "
584 "cannot find %s node err:%s\n",
585 nodename, fdt_strerror (nodeoffset));
586 }
587 return ret;
588}
589
590int fdt_del_node_name (void *blob, char *nodename)
591{
592 int ret = 0;
593 int nodeoffset = 0;
594
595 nodeoffset = fdt_path_offset (blob, nodename);
596 if (nodeoffset >= 0) {
597 ret = fdt_del_node (blob, nodeoffset);
598 if (ret < 0) {
599 printf("%s: cannot delete %s; err: %s\n",
600 __func__, nodename, fdt_strerror (ret));
601 }
602 } else {
603 printf("%s: cannot find %s node err:%s\n",
604 __func__, nodename, fdt_strerror (nodeoffset));
605 }
606 return ret;
607}
608
609int fdt_del_prop_name (void *blob, char *nodename, char *propname)
610{
611 int ret = 0;
612 int nodeoffset = 0;
613
614 nodeoffset = fdt_path_offset (blob, nodename);
615 if (nodeoffset >= 0) {
616 ret = fdt_delprop (blob, nodeoffset, propname);
617 if (ret < 0) {
618 printf("%s: cannot delete %s %s; err: %s\n",
619 __func__, nodename, propname,
620 fdt_strerror (ret));
621 }
622 } else {
623 printf("%s: cannot find %s node err:%s\n",
624 __func__, nodename, fdt_strerror (nodeoffset));
625 }
626 return ret;
627}
628
629/*
630 * update "brg" property in the blob
631 */
632void ft_blob_update (void *blob, bd_t *bd)
633{
634 uchar enetaddr[6];
635 ulong brg_data = 0;
636
637 /* BRG */
638 brg_data = cpu_to_be32(bd->bi_busfreq);
639 fdt_set_node_and_value(blob,
640 "/soc/cpm", "brg-frequency",
641 &brg_data, sizeof(brg_data));
642
643 /* MAC addr */
644 if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
645 fdt_set_node_and_value(blob,
646 "ethernet0", "local-mac-address",
647 enetaddr, sizeof(u8) * 6);
648 }
649
650 if (hwconfig_arg_cmp("fec", "off")) {
651 /* no FEC on this plattform, delete DTS nodes */
652 fdt_del_node_name (blob, "ethernet1");
653 fdt_del_node_name (blob, "mdio1");
654 /* also the aliases entries */
655 fdt_del_prop_name (blob, "/aliases", "ethernet1");
656 fdt_del_prop_name (blob, "/aliases", "mdio1");
657 } else {
658 /* adjust local-mac-address for FEC ethernet */
659 if (eth_getenv_enetaddr("eth1addr", enetaddr)) {
660 fdt_set_node_and_value(blob,
661 "ethernet1", "local-mac-address",
662 enetaddr, sizeof(u8) * 6);
663 }
664 }
665}
666
Simon Glass2aec3cc2014-10-23 18:58:47 -0600667int ft_board_setup(void *blob, bd_t *bd)
Heiko Schocher0bdca572010-02-09 15:50:21 +0100668{
669 ft_cpu_setup(blob, bd);
670 ft_blob_update(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600671
672 return 0;
Heiko Schocher0bdca572010-02-09 15:50:21 +0100673}
674#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */