blob: 4e3b1b5a84267753422388787b05896d4a6c4719 [file] [log] [blame]
wdenk16f21702002-08-26 21:58:50 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk16f21702002-08-26 21:58:50 +00006 */
7
8#include <common.h>
9#include <commproc.h>
10#include <mpc8xx.h>
11
12/* ------------------------------------------------------------------------- */
13
14static long int dram_size (long int, long int *, long int);
wdenk3bac3512003-03-12 10:41:04 +000015unsigned long ip860_get_dram_size(void);
16unsigned long ip860_get_clk_freq (void);
wdenk16f21702002-08-26 21:58:50 +000017/* ------------------------------------------------------------------------- */
18
19#define _NOT_USED_ 0xFFFFFFFF
20
21const uint sdram_table[] = {
22 /*
23 * Single Read. (Offset 0 in UPMA RAM)
24 */
25 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
26 0x1ff77c47, /* last */
27 /*
28 * SDRAM Initialization (offset 5 in UPMA RAM)
29 *
30 * This is no UPM entry point. The following definition uses
31 * the remaining space to establish an initialization
32 * sequence, which is executed by a RUN command.
33 *
34 */
35 0x1ff77c34, 0xefeabc34, 0x1fb57c35, /* last */
36 /*
37 * Burst Read. (Offset 8 in UPMA RAM)
38 */
39 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
40 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, /* last */
41 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
42 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
43 /*
44 * Single Write. (Offset 18 in UPMA RAM)
45 */
46 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, /* last */
47 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
48 /*
49 * Burst Write. (Offset 20 in UPMA RAM)
50 */
51 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
52 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, /* last */
53 _NOT_USED_,
54 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
55 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
56 /*
57 * Refresh (Offset 30 in UPMA RAM)
58 */
59 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
60 0xfffffc84, 0xfffffc07, /* last */
61 _NOT_USED_, _NOT_USED_,
62 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
63 /*
64 * Exception. (Offset 3c in UPMA RAM)
65 */
66 0x7ffffc07, /* last */
67 _NOT_USED_, _NOT_USED_, _NOT_USED_,
68};
69
wdenk16f21702002-08-26 21:58:50 +000070
wdenk3bac3512003-03-12 10:41:04 +000071/* ------------------------------------------------------------------------- */
wdenkc837dcb2004-01-20 23:12:12 +000072int board_early_init_f(void)
wdenk3bac3512003-03-12 10:41:04 +000073{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020074 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenk3bac3512003-03-12 10:41:04 +000075 volatile memctl8xx_t *memctl = &immap->im_memctl;
76
77/* init BCSR chipselect line for ip860_get_clk_freq() and ip860_get_dram_size() */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020078 memctl->memc_or4 = CONFIG_SYS_OR4;
79 memctl->memc_br4 = CONFIG_SYS_BR4;
wdenk3bac3512003-03-12 10:41:04 +000080
81 return 0;
82}
83
84
85/* ------------------------------------------------------------------------- */
wdenk16f21702002-08-26 21:58:50 +000086
87/*
88 * Check Board Identity:
89 *
90 * Test ID string (IP860...)
91 */
92
93int checkboard (void)
94{
95 unsigned char *s, *e;
96 unsigned char buf[64];
97 int i;
98
99 puts ("Board: ");
100
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200101 i = getenv_f("serial#", (char *)buf, sizeof (buf));
wdenk16f21702002-08-26 21:58:50 +0000102 s = (i > 0) ? buf : NULL;
103
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200104 if (!s || strncmp ((char *)s, "IP860", 5)) {
wdenk16f21702002-08-26 21:58:50 +0000105 puts ("### No HW ID - assuming IP860");
106 } else {
107 for (e = s; *e; ++e) {
108 if (*e == ' ')
109 break;
110 }
111
112 for (; s < e; ++s) {
113 putc (*s);
114 }
115 }
116
117 putc ('\n');
118
119 return (0);
120}
121
122/* ------------------------------------------------------------------------- */
123
Becky Bruce9973e3c2008-06-09 16:03:40 -0500124phys_size_t initdram (int board_type)
wdenk16f21702002-08-26 21:58:50 +0000125{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200126 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk16f21702002-08-26 21:58:50 +0000127 volatile memctl8xx_t *memctl = &immap->im_memctl;
128 long int size;
wdenk3bac3512003-03-12 10:41:04 +0000129 ulong refresh_val;
wdenk16f21702002-08-26 21:58:50 +0000130
131 upmconfig (UPMA, (uint *) sdram_table,
132 sizeof (sdram_table) / sizeof (uint));
133
134 /*
135 * Preliminary prescaler for refresh
136 */
wdenk3bac3512003-03-12 10:41:04 +0000137 if (ip860_get_clk_freq() == 50000000)
138 {
139 memctl->memc_mptpr = 0x0400;
140 refresh_val = 0xC3000000;
141 }
142 else
143 {
144 memctl->memc_mptpr = 0x0200;
145 refresh_val = 0x9C000000;
146 }
147
wdenk16f21702002-08-26 21:58:50 +0000148
149 memctl->memc_mar = 0x00000088;
150
151 /*
152 * Map controller banks 2 to the SDRAM address
153 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200154 memctl->memc_or2 = CONFIG_SYS_OR2;
155 memctl->memc_br2 = CONFIG_SYS_BR2;
wdenk16f21702002-08-26 21:58:50 +0000156
157 /* IP860 boards have only one bank SDRAM */
158
159
160 udelay (200);
161
162 /* perform SDRAM initializsation sequence */
163
wdenk3bac3512003-03-12 10:41:04 +0000164 memctl->memc_mamr = 0x00804114 | refresh_val;
165 memctl->memc_mcr = 0x80004105; /* run precharge pattern from loc 5 */
166 udelay(1);
167 memctl->memc_mamr = 0x00804118 | refresh_val;
168 memctl->memc_mcr = 0x80004130; /* run refresh pattern 8 times */
169
wdenk16f21702002-08-26 21:58:50 +0000170
171 udelay (1000);
172
173 /*
174 * Check SDRAM Memory Size
175 */
wdenk3bac3512003-03-12 10:41:04 +0000176 if (ip860_get_dram_size() == 16)
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200177 size = dram_size (refresh_val | 0x00804114, SDRAM_BASE, SDRAM_MAX_SIZE);
wdenk3bac3512003-03-12 10:41:04 +0000178 else
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200179 size = dram_size (refresh_val | 0x00906114, SDRAM_BASE, SDRAM_MAX_SIZE);
wdenk16f21702002-08-26 21:58:50 +0000180
181 udelay (1000);
182
183 memctl->memc_or2 = ((-size) & 0xFFFF0000) | SDRAM_TIMING;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200184 memctl->memc_br2 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenk16f21702002-08-26 21:58:50 +0000185
186 udelay (10000);
187
188 /*
189 * Also, map other memory to correct position
190 */
191
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200192#if (defined(CONFIG_SYS_OR1) && defined(CONFIG_SYS_BR1_PRELIM))
193 memctl->memc_or1 = CONFIG_SYS_OR1;
194 memctl->memc_br1 = CONFIG_SYS_BR1;
wdenk16f21702002-08-26 21:58:50 +0000195#endif
196
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200197#if defined(CONFIG_SYS_OR3) && defined(CONFIG_SYS_BR3)
198 memctl->memc_or3 = CONFIG_SYS_OR3;
199 memctl->memc_br3 = CONFIG_SYS_BR3;
wdenk16f21702002-08-26 21:58:50 +0000200#endif
201
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202#if defined(CONFIG_SYS_OR4) && defined(CONFIG_SYS_BR4)
203 memctl->memc_or4 = CONFIG_SYS_OR4;
204 memctl->memc_br4 = CONFIG_SYS_BR4;
wdenk16f21702002-08-26 21:58:50 +0000205#endif
206
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200207#if defined(CONFIG_SYS_OR5) && defined(CONFIG_SYS_BR5)
208 memctl->memc_or5 = CONFIG_SYS_OR5;
209 memctl->memc_br5 = CONFIG_SYS_BR5;
wdenk16f21702002-08-26 21:58:50 +0000210#endif
211
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200212#if defined(CONFIG_SYS_OR6) && defined(CONFIG_SYS_BR6)
213 memctl->memc_or6 = CONFIG_SYS_OR6;
214 memctl->memc_br6 = CONFIG_SYS_BR6;
wdenk16f21702002-08-26 21:58:50 +0000215#endif
216
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200217#if defined(CONFIG_SYS_OR7) && defined(CONFIG_SYS_BR7)
218 memctl->memc_or7 = CONFIG_SYS_OR7;
219 memctl->memc_br7 = CONFIG_SYS_BR7;
wdenk16f21702002-08-26 21:58:50 +0000220#endif
221
222 return (size);
223}
224
225/* ------------------------------------------------------------------------- */
226
227/*
228 * Check memory range for valid RAM. A simple memory test determines
229 * the actually available RAM size between addresses `base' and
230 * `base + maxsize'. Some (not all) hardware errors are detected:
231 * - short between address lines
232 * - short between data lines
233 */
234
235static long int dram_size (long int mamr_value, long int *base,
236 long int maxsize)
237{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200238 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk16f21702002-08-26 21:58:50 +0000239 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenk16f21702002-08-26 21:58:50 +0000240
241 memctl->memc_mamr = mamr_value;
242
wdenkc83bf6a2004-01-06 22:38:14 +0000243 return (get_ram_size(base, maxsize));
wdenk16f21702002-08-26 21:58:50 +0000244}
245
246/* ------------------------------------------------------------------------- */
247
248void reset_phy (void)
249{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200250 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk16f21702002-08-26 21:58:50 +0000251 ulong mask = PB_ENET_RESET | PB_ENET_JABD;
252 ulong reg;
253
254 /* Make sure PHY is not in low-power mode */
255 immr->im_cpm.cp_pbpar &= ~(mask); /* GPIO */
256 immr->im_cpm.cp_pbodr &= ~(mask); /* active output */
257
258 /* Set JABD low (no JABber Disable),
259 * and RESET high (Reset PHY)
260 */
261 reg = immr->im_cpm.cp_pbdat;
262 reg = (reg & ~PB_ENET_JABD) | PB_ENET_RESET;
263 immr->im_cpm.cp_pbdat = reg;
264
265 /* now drive outputs */
266 immr->im_cpm.cp_pbdir |= mask; /* output */
267 udelay (1000);
268 /*
269 * Release RESET signal
270 */
271 immr->im_cpm.cp_pbdat &= ~(PB_ENET_RESET);
272 udelay (1000);
273}
274
275/* ------------------------------------------------------------------------- */
wdenk3bac3512003-03-12 10:41:04 +0000276
277unsigned long ip860_get_clk_freq(void)
278{
279 volatile ip860_bcsr_t *bcsr = (ip860_bcsr_t *)BCSR_BASE;
280 ulong temp;
281 uchar sysclk;
282
283 if ((bcsr->bd_status & 0x80) == 0x80) /* bd_rev valid ? */
284 sysclk = (bcsr->bd_rev & 0x18) >> 3;
285 else
286 sysclk = 0x00;
287
288 switch (sysclk)
289 {
290 case 0x00:
291 temp = 50000000;
292 break;
293
294 case 0x01:
295 temp = 80000000;
296 break;
297
298 default:
299 temp = 50000000;
300 break;
301 }
302
303 return (temp);
304
305}
306
307
308/* ------------------------------------------------------------------------- */
309
310unsigned long ip860_get_dram_size(void)
311{
312 volatile ip860_bcsr_t *bcsr = (ip860_bcsr_t *)BCSR_BASE;
313 ulong temp;
314 uchar dram_size;
315
316 if ((bcsr->bd_status & 0x80) == 0x80) /* bd_rev valid ? */
317 dram_size = (bcsr->bd_rev & 0xE0) >> 5;
318 else
319 dram_size = 0x00; /* default is 16 MB */
320
321 switch (dram_size)
322 {
323 case 0x00:
324 temp = 16;
325 break;
326
327 case 0x01:
328 temp = 32;
329 break;
330
331 default:
332 temp = 16;
333 break;
334 }
335
336 return (temp);
337
338}
339
340/* ------------------------------------------------------------------------- */