2 * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
4 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #include <asm/immap_8260.h>
29 int hwc_flash_size (void);
30 int hwc_local_sdram_size (void);
31 int hwc_main_sdram_size (void);
32 int hwc_serial_number (void);
33 int hwc_mac_address (char *str);
34 int hwc_manufact_date (char *str);
35 int seeprom_read (int addr, uchar * data, int size);
38 * I/O Port configuration table
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
43 * The port definitions are taken from the old firmware (see
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
52 const iop_conf_t iop_conf_tab[4][32] = {
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] */
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 */
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 */
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 */
196 long int initdram (int board_type)
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 */
205 memctl->memc_psrt = CFG_PSRT;
206 memctl->memc_mptpr = CFG_MPTPR;
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;
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;
224 memctl->memc_psdmr = 0x08000000 | OP_VALUE_M;
225 for (i = 0; i < 8; i++)
227 memctl->memc_psdmr = 0x18000000 | OP_VALUE_M;
228 *(base + 0x110) = 0xFF;
229 memctl->memc_psdmr = OP_VALUE;
230 memctl->memc_lsdmr = 0x4086A522;
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.
238 maxsize = (1 + (~memctl->memc_or1 | 0x7fff)) / 2;
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
248 for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
249 addr = (volatile ulong *) base + cnt; /* pointer arith! */
254 addr = (volatile ulong *) base;
258 if ((val = *addr) != 0) {
263 for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
264 addr = (volatile ulong *) base + cnt; /* pointer arith! */
268 /* Write the actual size to ORx
270 memctl->memc_or1 |= ~(cnt * sizeof (long) - 1);
271 maxsize = cnt * sizeof (long) / 2;
277 if (maxsize != hwc_main_sdram_size ())
278 printf ("Oops: memory test has not found all memory!\n");
282 /* return total ram size of SDRAM */
286 int checkboard (void)
290 hwc_manufact_date (string);
292 printf ("Board: Interphase 4539 (#%d %s)\n",
293 hwc_serial_number (),
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);
309 int misc_init_r (void)
314 if ((s = getenv ("serial#")) == NULL &&
315 (num = hwc_serial_number ()) != -1) {
316 sprintf (str, "%06d", num);
317 setenv ("serial#", str);
319 if ((s = getenv ("ethaddr")) == NULL && hwc_mac_address (str) == 0) {
320 setenv ("ethaddr", str);
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.
330 int hwc_flash_size (void)
334 if (!seeprom_read (0x40, &byte, sizeof (byte))) {
335 switch ((byte >> 2) & 0x3) {
350 int hwc_local_sdram_size (void)
354 if (!seeprom_read (0x40, &byte, sizeof (byte))) {
355 switch ((byte & 0x03)) {
361 return 0; /* not present */
366 int hwc_main_sdram_size (void)
370 if (!seeprom_read (0x41, &byte, sizeof (byte))) {
371 return 0x1000000 << ((byte >> 5) & 0x7);
375 int hwc_serial_number (void)
379 if (!seeprom_read (0xa0, (char *) &sn, sizeof (sn))) {
380 sn = cpu_to_le32 (sn);
384 int hwc_mac_address (char *str)
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]);
392 strcpy (str, "ERROR");
397 int hwc_manufact_date (char *str)
402 if (seeprom_read (0x92, &byte, sizeof (byte)))
405 if (seeprom_read (0x93, &byte, sizeof (byte)))
408 sprintf (str, "%02d/%02d/%04d",
409 value & 0x1F, (value >> 5) & 0xF,
410 1980 + ((value >> 9) & 0x1FF));
414 strcpy (str, "ERROR");
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)))
426 int seeprom_read (int addr, uchar * data, int size)
431 for (i = 0; i < size; i++) {
433 cmd = EEPROM_READ_CMD;
434 cmd |= ((addr + i) << 24) & 0xff000000;
436 /* Wait for ACT to authorize write */
437 while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
441 PSPAN_WRITE (EEPROM_REG, cmd);
443 /* Wait for data to be valid */
444 while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
446 /* Do it twice, first read might be erratic */
447 while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
451 if (val & 0x00000040) {
454 data[i] = (val >> 16) & 0xff;