blob: 45f3dad36adfc4c9276b103ded814d6c36448621 [file] [log] [blame]
wdenk16f21702002-08-26 21:58:50 +00001/*
2 * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <ioports.h>
25#include <mpc8260.h>
26#include <asm/io.h>
27#include <asm/immap_8260.h>
28
29int hwc_flash_size (void);
30int hwc_local_sdram_size (void);
31int hwc_main_sdram_size (void);
32int hwc_serial_number (void);
33int hwc_mac_address (char *str);
34int hwc_manufact_date (char *str);
35int seeprom_read (int addr, uchar * data, int size);
36
37/*
38 * I/O Port configuration table
39 *
40 * if conf is 1, then that port pin will be configured at boot time
41 * according to the five values podr/pdir/ppar/psor/pdat for that entry
42 *
43 * The port definitions are taken from the old firmware (see
44 * also SYS/H/4539.H):
45 *
46 * ppar psor pdir podr pdat
47 * PA: 0x02ffffff 0x02c00000 0xfc403fe6 0x00000000 0x02403fc0
48 * PB: 0x0fffdeb0 0x000000b0 0x0f032347 0x00000000 0x0f000290
49 * PC: 0x030ffa55 0x030f0040 0xbcf005ea 0x00000000 0xc0c0ba7d
50 * PD: 0x09c04e3c 0x01000e3c 0x0a7ff1c3 0x00000000 0x00ce0ae9
51 */
52const iop_conf_t iop_conf_tab[4][32] = {
53
54 /* Port A configuration */
55 { /* conf ppar psor pdir podr pdat */
56 {0, 1, 0, 0, 0, 0}, /* PA31 FCC1_TXENB SLAVE */
57 {0, 1, 0, 1, 0, 0}, /* PA30 FCC1_TXCLAV SLAVE */
58 {0, 1, 0, 1, 0, 0}, /* PA29 FCC1_TXSOC */
59 {0, 1, 0, 0, 0, 0}, /* PA28 FCC1_RXENB SLAVE */
60 {0, 1, 0, 0, 0, 0}, /* PA27 FCC1_RXSOC */
61 {0, 1, 0, 1, 0, 0}, /* PA26 FCC1_RXCLAV SLAVE */
62 {0, 1, 0, 1, 0, 1}, /* PA25 FCC1_TXD0 */
63 {0, 1, 0, 1, 0, 1}, /* PA24 FCC1_TXD1 */
64 {0, 1, 0, 1, 0, 1}, /* PA23 FCC1_TXD2 */
65 {0, 1, 0, 1, 0, 1}, /* PA22 FCC1_TXD3 */
66 {0, 1, 0, 1, 0, 1}, /* PA21 FCC1_TXD4 */
67 {0, 1, 0, 1, 0, 1}, /* PA20 FCC1_TXD5 */
68 {0, 1, 0, 1, 0, 1}, /* PA19 FCC1_TXD6 */
69 {0, 1, 0, 1, 0, 1}, /* PA18 FCC1_TXD7 */
70 {0, 1, 0, 0, 0, 0}, /* PA17 FCC1_RXD7 */
71 {0, 1, 0, 0, 0, 0}, /* PA16 FCC1_RXD6 */
72 {0, 1, 0, 0, 0, 0}, /* PA15 FCC1_RXD5 */
73 {0, 1, 0, 0, 0, 0}, /* PA14 FCC1_RXD4 */
74 {0, 1, 0, 0, 0, 0}, /* PA13 FCC1_RXD3 */
75 {0, 1, 0, 0, 0, 0}, /* PA12 FCC1_RXD2 */
76 {0, 1, 0, 0, 0, 0}, /* PA11 FCC1_RXD1 */
77 {0, 1, 0, 0, 0, 0}, /* PA10 FCC1_RXD0 */
78 {0, 1, 1, 1, 0, 1}, /* PA9 TDMA1_L1TXD */
79 {0, 1, 1, 0, 0, 0}, /* PA8 TDMA1_L1RXD */
80 {0, 0, 0, 0, 0, 0}, /* PA7 CONFIG0 */
81 {0, 1, 1, 0, 0, 1}, /* PA6 TDMA1_L1RSYNC */
82 {0, 0, 0, 1, 0, 0}, /* PA5 FCC2:RxAddr[2] */
83 {0, 0, 0, 1, 0, 0}, /* PA4 FCC2:RxAddr[1] */
84 {0, 0, 0, 1, 0, 0}, /* PA3 FCC2:RxAddr[0] */
85 {0, 0, 0, 1, 0, 0}, /* PA2 FCC2:TxAddr[0] */
86 {0, 0, 0, 1, 0, 0}, /* PA1 FCC2:TxAddr[1] */
87 {0, 0, 0, 1, 0, 0} /* PA0 FCC2:TxAddr[2] */
88 },
89 /* Port B configuration */
90 { /* conf ppar psor pdir podr pdat */
91 {0, 0, 0, 1, 0, 0}, /* PB31 FCC2_RXSOC */
92 {0, 0, 0, 1, 0, 0}, /* PB30 FCC2_TXSOC */
93 {0, 0, 0, 1, 0, 0}, /* PB29 FCC2_RXCLAV */
94 {0, 0, 0, 0, 0, 0}, /* PB28 CONFIG2 */
95 {0, 1, 1, 0, 0, 1}, /* PB27 FCC2_TXD0 */
96 {0, 1, 1, 0, 0, 0}, /* PB26 FCC2_TXD1 */
97 {0, 0, 0, 1, 0, 0}, /* PB25 FCC2_TXD4 */
98 {0, 1, 1, 0, 0, 1}, /* PB24 FCC2_TXD5 */
99 {0, 0, 0, 1, 0, 0}, /* PB23 FCC2_TXD6 */
100 {0, 1, 0, 1, 0, 1}, /* PB22 FCC2_TXD7 */
101 {0, 1, 0, 0, 0, 0}, /* PB21 FCC2_RXD7 */
102 {0, 1, 0, 0, 0, 0}, /* PB20 FCC2_RXD6 */
103 {0, 1, 0, 0, 0, 0}, /* PB19 FCC2_RXD5 */
104 {0, 0, 0, 1, 0, 0}, /* PB18 FCC2_RXD4 */
105 {1, 1, 0, 0, 0, 0}, /* PB17 FCC3_RX_DV */
106 {1, 1, 0, 0, 0, 0}, /* PB16 FCC3_RX_ER */
107 {1, 1, 0, 1, 0, 0}, /* PB15 FCC3_TX_ER */
108 {1, 1, 0, 1, 0, 0}, /* PB14 FCC3_TX_EN */
109 {1, 1, 0, 0, 0, 0}, /* PB13 FCC3_COL */
110 {1, 1, 0, 0, 0, 0}, /* PB12 FCC3_CRS */
111 {1, 1, 0, 0, 0, 0}, /* PB11 FCC3_RXD3 */
112 {1, 1, 0, 0, 0, 0}, /* PB10 FCC3_RXD2 */
113 {1, 1, 0, 0, 0, 0}, /* PB9 FCC3_RXD1 */
114 {1, 1, 0, 0, 0, 0}, /* PB8 FCC3_RXD0 */
115 {1, 1, 0, 1, 0, 1}, /* PB7 FCC3_TXD0 */
116 {1, 1, 0, 1, 0, 1}, /* PB6 FCC3_TXD1 */
117 {1, 1, 0, 1, 0, 1}, /* PB5 FCC3_TXD2 */
118 {1, 1, 0, 1, 0, 1}, /* PB4 FCC3_TXD3 */
119 {0, 0, 0, 0, 0, 0}, /* PB3 */
120 {0, 0, 0, 0, 0, 0}, /* PB2 */
121 {0, 0, 0, 0, 0, 0}, /* PB1 */
122 {0, 0, 0, 0, 0, 0}, /* PB0 */
123 },
124 /* Port C configuration */
125 { /* conf ppar psor pdir podr pdat */
126 {0, 1, 0, 0, 0, 1}, /* PC31 CLK1 */
127 {0, 0, 0, 1, 0, 0}, /* PC30 U1MASTER_N */
128 {0, 1, 0, 0, 0, 1}, /* PC29 CLK3 */
129 {0, 0, 0, 1, 0, 1}, /* PC28 -MT90220_RST */
130 {0, 1, 0, 0, 0, 1}, /* PC27 CLK5 */
131 {0, 0, 0, 1, 0, 1}, /* PC26 -QUADFALC_RST */
132 {0, 1, 1, 1, 0, 1}, /* PC25 BRG4 */
133 {1, 0, 0, 1, 0, 0}, /* PC24 MDIO */
134 {1, 0, 0, 1, 0, 0}, /* PC23 MDC */
135 {0, 1, 0, 0, 0, 1}, /* PC22 CLK10 */
136 {0, 0, 0, 1, 0, 0}, /* PC21 */
137 {0, 1, 0, 0, 0, 1}, /* PC20 CLK12 */
138 {0, 1, 0, 0, 0, 1}, /* PC19 CLK13 */
139 {1, 1, 0, 0, 0, 1}, /* PC18 CLK14 */
140 {0, 1, 0, 0, 0, 0}, /* PC17 CLK15 */
141 {1, 1, 0, 0, 0, 1}, /* PC16 CLK16 */
142 {0, 1, 1, 0, 0, 0}, /* PC15 FCC1_TXADDR0 SLAVE */
143 {0, 1, 1, 0, 0, 0}, /* PC14 FCC1_RXADDR0 SLAVE */
144 {0, 1, 1, 0, 0, 0}, /* PC13 FCC1_TXADDR1 SLAVE */
145 {0, 1, 1, 0, 0, 0}, /* PC12 FCC1_RXADDR1 SLAVE */
146 {0, 0, 0, 1, 0, 0}, /* PC11 FCC2_RXD2 */
147 {0, 0, 0, 1, 0, 0}, /* PC10 FCC2_RXD3 */
148 {0, 0, 0, 1, 0, 1}, /* PC9 LTMODE */
149 {0, 0, 0, 1, 0, 1}, /* PC8 SELSYNC */
150 {0, 1, 1, 0, 0, 0}, /* PC7 FCC1_TXADDR2 SLAVE */
151 {0, 1, 1, 0, 0, 0}, /* PC6 FCC1_RXADDR2 SLAVE */
152 {0, 0, 0, 1, 0, 0}, /* PC5 FCC2_TXCLAV MASTER */
153 {0, 0, 0, 1, 0, 0}, /* PC4 FCC2_RXENB MASTER */
154 {0, 0, 0, 1, 0, 0}, /* PC3 FCC2_TXD2 */
155 {0, 0, 0, 1, 0, 0}, /* PC2 FCC2_TXD3 */
156 {0, 0, 0, 0, 0, 1}, /* PC1 PTMC -PTEENB */
157 {0, 0, 0, 1, 0, 1}, /* PC0 COMCLK_N */
158 },
159 /* Port D configuration */
160 { /* conf ppar psor pdir podr pdat */
161 {0, 0, 0, 1, 0, 1}, /* PD31 -CAM_RST */
162 {0, 0, 0, 1, 0, 0}, /* PD30 FCC2_TXENB */
163 {0, 1, 1, 0, 0, 0}, /* PD29 FCC1_RXADDR3 SLAVE */
164 {0, 1, 1, 0, 0, 1}, /* PD28 TDMC1_L1TXD */
165 {0, 1, 1, 0, 0, 0}, /* PD27 TDMC1_L1RXD */
166 {0, 1, 1, 0, 0, 1}, /* PD26 TDMC1_L1RSYNC */
167 {0, 0, 0, 1, 0, 1}, /* PD25 LED0 -OFF */
168 {0, 0, 0, 1, 0, 1}, /* PD24 LED5 -OFF */
169 {1, 0, 0, 1, 0, 1}, /* PD23 -LXT971_RST */
170 {0, 1, 1, 0, 0, 1}, /* PD22 TDMA2_L1TXD */
171 {0, 1, 1, 0, 0, 0}, /* PD21 TDMA2_L1RXD */
172 {0, 1, 1, 0, 0, 1}, /* PD20 TDMA2_L1RSYNC */
173 {0, 0, 0, 1, 0, 0}, /* PD19 FCC2_TXADDR3 */
174 {0, 0, 0, 1, 0, 0}, /* PD18 FCC2_RXADDR3 */
175 {0, 1, 0, 1, 0, 0}, /* PD17 BRG2 */
176 {0, 0, 0, 1, 0, 0}, /* PD16 */
177 {0, 0, 0, 1, 0, 0}, /* PD15 PT2TO1 */
178 {0, 0, 0, 1, 0, 1}, /* PD14 PT4TO3 */
179 {0, 0, 0, 1, 0, 1}, /* PD13 -SWMODE */
180 {0, 0, 0, 1, 0, 1}, /* PD12 -PTMODE */
181 {0, 0, 0, 1, 0, 0}, /* PD11 FCC2_RXD0 */
182 {0, 0, 0, 1, 0, 0}, /* PD10 FCC2_RXD1 */
183 {1, 1, 0, 1, 0, 1}, /* PD9 SMC1_SMTXD */
184 {1, 1, 0, 0, 0, 1}, /* PD8 SMC1_SMRXD */
185 {0, 1, 1, 0, 0, 0}, /* PD7 FCC1_TXADDR3 SLAVE */
186 {0, 0, 0, 1, 0, 0}, /* PD6 IMAMODE */
187 {0, 0, 0, 0, 0, 0}, /* PD5 CONFIG2 */
188 {0, 1, 0, 1, 0, 0}, /* PD4 BRG8 */
189 {0, 0, 0, 0, 0, 0}, /* PD3 */
190 {0, 0, 0, 0, 0, 0}, /* PD2 */
191 {0, 0, 0, 0, 0, 0}, /* PD1 */
192 {0, 0, 0, 0, 0, 0}, /* PD0 */
193 }
194};
195
196long int initdram (int board_type)
197{
198 volatile immap_t *immap = (immap_t *) CFG_IMMR;
199 volatile memctl8260_t *memctl = &immap->im_memctl;
200 volatile uchar *base;
201 volatile ulong *addr, cnt, val;
202 ulong save[32]; /* to make test non-destructive */
203 int i, maxsize;
204
205 memctl->memc_psrt = CFG_PSRT;
206 memctl->memc_mptpr = CFG_MPTPR;
207
208#ifndef CFG_RAMBOOT
209 immap->im_siu_conf.sc_ppc_acr = 0x00000026;
210 immap->im_siu_conf.sc_ppc_alrh = 0x01276345;
211 immap->im_siu_conf.sc_ppc_alrl = 0x89ABCDEF;
212 immap->im_siu_conf.sc_lcl_acr = 0x00000000;
213 immap->im_siu_conf.sc_lcl_alrh = 0x01234567;
214 immap->im_siu_conf.sc_lcl_alrl = 0x89ABCDEF;
215 immap->im_siu_conf.sc_tescr1 = 0x00004000;
216 immap->im_siu_conf.sc_ltescr1 = 0x00004000;
217
218 /* Init Main SDRAM */
219#define OP_VALUE 0x404A241A
220#define OP_VALUE_M (OP_VALUE & 0x87FFFFFF);
221 base = (uchar *) CFG_SDRAM_BASE;
222 memctl->memc_psdmr = 0x28000000 | OP_VALUE_M;
223 *base = 0xFF;
224 memctl->memc_psdmr = 0x08000000 | OP_VALUE_M;
225 for (i = 0; i < 8; i++)
226 *base = 0xFF;
227 memctl->memc_psdmr = 0x18000000 | OP_VALUE_M;
228 *(base + 0x110) = 0xFF;
229 memctl->memc_psdmr = OP_VALUE;
230 memctl->memc_lsdmr = 0x4086A522;
231 *base = 0xFF;
232
233 /* We must be able to test a location outsize the maximum legal size
234 * to find out THAT we are outside; but this address still has to be
235 * mapped by the controller. That means, that the initial mapping has
236 * to be (at least) twice as large as the maximum expected size.
237 */
238 maxsize = (1 + (~memctl->memc_or1 | 0x7fff)) / 2;
239
240 /*
241 * Check memory range for valid RAM. A simple memory test determines
242 * the actually available RAM size between addresses `base' and
243 * `base + maxsize'. Some (not all) hardware errors are detected:
244 * - short between address lines
245 * - short between data lines
246 */
247 i = 0;
248 for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
249 addr = (volatile ulong *) base + cnt; /* pointer arith! */
250 save[i++] = *addr;
251 *addr = ~cnt;
252 }
253
254 addr = (volatile ulong *) base;
255 save[i] = *addr;
256 *addr = 0;
257
258 if ((val = *addr) != 0) {
259 *addr = save[i];
260 return (0);
261 }
262
263 for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
264 addr = (volatile ulong *) base + cnt; /* pointer arith! */
265 val = *addr;
266 *addr = save[--i];
267 if (val != ~cnt) {
268 /* Write the actual size to ORx
269 */
270 memctl->memc_or1 |= ~(cnt * sizeof (long) - 1);
271 maxsize = cnt * sizeof (long) / 2;
272 break;
273 }
274 }
275
276 maxsize *= 2;
277 if (maxsize != hwc_main_sdram_size ())
278 printf ("Oops: memory test has not found all memory!\n");
279#endif
280
281 icache_enable ();
282 /* return total ram size of SDRAM */
283 return (maxsize);
284}
285
286int checkboard (void)
287{
288 char string[32];
289
290 hwc_manufact_date (string);
291
292 printf ("Board: Interphase 4539 (#%d %s)\n",
293 hwc_serial_number (),
294 string);
295
296#ifdef DEBUG
297 printf ("Manufacturing date: %s\n", string);
298 printf ("Serial number : %d\n", hwc_serial_number ());
299 printf ("FLASH size : %d MB\n", hwc_flash_size () >> 20);
300 printf ("Main SDRAM size : %d MB\n", hwc_main_sdram_size () >> 20);
301 printf ("Local SDRAM size : %d MB\n", hwc_local_sdram_size () >> 20);
302 hwc_mac_address (string);
303 printf ("MAC address : %s\n", string);
304#endif
305
306 return 0;
307}
308
309int misc_init_r (void)
310{
311 char *s, str[32];
312 int num;
313
314 if ((s = getenv ("serial#")) == NULL &&
315 (num = hwc_serial_number ()) != -1) {
316 sprintf (str, "%06d", num);
317 setenv ("serial#", str);
318 }
319 if ((s = getenv ("ethaddr")) == NULL && hwc_mac_address (str) == 0) {
320 setenv ("ethaddr", str);
321 }
322 return (0);
323}
324
325/***************************************************************
326 * We take some basic Hardware Configuration Parameter from the
327 * Serial EEPROM conected to the PSpan bridge. We keep it as
328 * simple as possible.
329 */
330int hwc_flash_size (void)
331{
332 uchar byte;
333
334 if (!seeprom_read (0x40, &byte, sizeof (byte))) {
335 switch ((byte >> 2) & 0x3) {
336 case 0x1:
337 return 0x0400000;
338 break;
339 case 0x2:
340 return 0x0800000;
341 break;
342 case 0x3:
343 return 0x1000000;
344 default:
345 return 0x0100000;
346 }
347 }
348 return -1;
349}
350int hwc_local_sdram_size (void)
351{
352 uchar byte;
353
354 if (!seeprom_read (0x40, &byte, sizeof (byte))) {
355 switch ((byte & 0x03)) {
356 case 0x1:
357 return 0x0800000;
358 case 0x2:
359 return 0x1000000;
360 default:
361 return 0; /* not present */
362 }
363 }
364 return -1;
365}
366int hwc_main_sdram_size (void)
367{
368 uchar byte;
369
370 if (!seeprom_read (0x41, &byte, sizeof (byte))) {
371 return 0x1000000 << ((byte >> 5) & 0x7);
372 }
373 return -1;
374}
375int hwc_serial_number (void)
376{
377 int sn = -1;
378
379 if (!seeprom_read (0xa0, (char *) &sn, sizeof (sn))) {
380 sn = cpu_to_le32 (sn);
381 }
382 return sn;
383}
384int hwc_mac_address (char *str)
385{
386 char mac[6];
387
388 if (!seeprom_read (0xb0, mac, sizeof (mac))) {
389 sprintf (str, "%02x:%02x:%02x:%02x:%02x:%02x\n",
390 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
391 } else {
392 strcpy (str, "ERROR");
393 return -1;
394 }
395 return 0;
396}
397int hwc_manufact_date (char *str)
398{
399 uchar byte;
400 int value;
401
402 if (seeprom_read (0x92, &byte, sizeof (byte)))
403 goto out;
404 value = byte;
405 if (seeprom_read (0x93, &byte, sizeof (byte)))
406 goto out;
407 value += byte << 8;
408 sprintf (str, "%02d/%02d/%04d",
409 value & 0x1F, (value >> 5) & 0xF,
410 1980 + ((value >> 9) & 0x1FF));
411 return 0;
412
413 out:
414 strcpy (str, "ERROR");
415 return -1;
416}
417
418#define PSPAN_ADDR 0xF0020000
419#define EEPROM_REG 0x408
420#define EEPROM_READ_CMD 0xA000
421#define PSPAN_WRITE(a,v) \
422 *((volatile unsigned long *)(PSPAN_ADDR+(a))) = v; eieio()
423#define PSPAN_READ(a) \
424 *((volatile unsigned long *)(PSPAN_ADDR+(a)))
425
426int seeprom_read (int addr, uchar * data, int size)
427{
428 ulong val, cmd;
429 int i;
430
431 for (i = 0; i < size; i++) {
432
433 cmd = EEPROM_READ_CMD;
434 cmd |= ((addr + i) << 24) & 0xff000000;
435
436 /* Wait for ACT to authorize write */
437 while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
438 eieio ();
439
440 /* Write command */
441 PSPAN_WRITE (EEPROM_REG, cmd);
442
443 /* Wait for data to be valid */
444 while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
445 eieio ();
446 /* Do it twice, first read might be erratic */
447 while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
448 eieio ();
449
450 /* Read error */
451 if (val & 0x00000040) {
452 return -1;
453 } else {
454 data[i] = (val >> 16) & 0xff;
455 }
456 }
457 return 0;
458}