blob: 9477a15fbb025dcb7d5b55eafe0ca47c7b8b7523 [file] [log] [blame]
wdenkf8cac652002-08-26 22:36:39 +00001/*
2 * (C) Copyright 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <ioports.h>
26#include <mpc8260.h>
27#include "cpu86.h"
28
29/*
30 * I/O Port configuration table
31 *
32 * if conf is 1, then that port pin will be configured at boot time
33 * according to the five values podr/pdir/ppar/psor/pdat for that entry
34 */
35
36const iop_conf_t iop_conf_tab[4][32] = {
37
38 /* Port A configuration */
39 { /* conf ppar psor pdir podr pdat */
40 /* PA31 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII COL */
41 /* PA30 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII CRS */
42 /* PA29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 MII TX_ER */
43 /* PA28 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 MII TX_EN */
44 /* PA27 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII RX_DV */
45 /* PA26 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII RX_ER */
46 /* PA25 */ { 1, 0, 0, 1, 0, 0 }, /* FCC2 MII MDIO */
47 /* PA24 */ { 1, 0, 0, 1, 0, 0 }, /* FCC2 MII MDC */
48 /* PA23 */ { 1, 0, 0, 1, 0, 0 }, /* FCC1 MII MDIO */
49 /* PA22 */ { 1, 0, 0, 1, 0, 0 }, /* FCC1 MII MDC */
50 /* PA21 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[3] */
51 /* PA20 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[2] */
52 /* PA19 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[1] */
53 /* PA18 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[0] */
54 /* PA17 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[0] */
55 /* PA16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[1] */
56 /* PA15 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[2] */
57 /* PA14 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[3] */
58 /* PA13 */ { 1, 0, 0, 1, 0, 0 }, /* FCC2 MII TXSL1 */
59 /* PA12 */ { 1, 0, 0, 1, 0, 1 }, /* FCC2 MII TXSL0 */
60 /* PA11 */ { 1, 0, 0, 1, 0, 0 }, /* FCC1 MII TXSL1 */
61 /* PA10 */ { 1, 0, 0, 1, 0, 1 }, /* FCC1 MII TXSL0 */
62 /* PA9 */ { 0, 1, 0, 1, 0, 0 }, /* SMC2 TXD */
63 /* PA8 */ { 0, 1, 0, 0, 0, 0 }, /* SMC2 RXD */
64 /* PA7 */ { 0, 0, 0, 0, 0, 0 }, /* PA7 */
65 /* PA6 */ { 1, 0, 0, 1, 0, 1 }, /* FCC2 MII PAUSE */
66 /* PA5 */ { 1, 0, 0, 1, 0, 1 }, /* FCC1 MII PAUSE */
67 /* PA4 */ { 1, 0, 0, 1, 0, 0 }, /* FCC2 MII PWRDN */
68 /* PA3 */ { 1, 0, 0, 1, 0, 0 }, /* FCC1 MII PWRDN */
69 /* PA2 */ { 0, 0, 0, 0, 0, 0 }, /* PA2 */
70 /* PA1 */ { 1, 0, 0, 0, 0, 0 }, /* FCC2 MII MDINT */
71 /* PA0 */ { 1, 0, 0, 1, 0, 0 } /* FCC1 MII MDINT */
72 },
73
74 /* Port B configuration */
75 { /* conf ppar psor pdir podr pdat */
76 /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
77 /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
78 /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
79 /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
80 /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
81 /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
82 /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
83 /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
84 /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
85 /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
86 /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
87 /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
88 /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
89 /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
90 /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* PB17 */
91 /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* PB16 */
92 /* PB15 */ { 0, 0, 0, 0, 0, 0 }, /* PB15 */
93 /* PB14 */ { 0, 0, 0, 0, 0, 0 }, /* PB14 */
94 /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* PB13 */
95 /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* PB12 */
96 /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* PB11 */
97 /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* PB10 */
98 /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* PB9 */
99 /* PB8 */ { 0, 0, 0, 0, 0, 0 }, /* PB8 */
100 /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* PB7 */
101 /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* PB6 */
102 /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* PB5 */
103 /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* PB4 */
104 /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* PB3 */
105 /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* PB2 */
106 /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* PB1 */
107 /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* PB0 */
108 },
109
110 /* Port C */
111 { /* conf ppar psor pdir podr pdat */
112 /* PC31 */ { 0, 0, 0, 0, 0, 0 }, /* PC31 */
113 /* PC30 */ { 0, 0, 0, 0, 0, 0 }, /* PC30 */
114 /* PC29 */ { 1, 0, 0, 0, 0, 0 }, /* SCC1 CTS */
115 /* PC28 */ { 1, 0, 0, 0, 0, 0 }, /* SCC2 CTS */
116 /* PC27 */ { 0, 0, 0, 0, 0, 0 }, /* PC27 */
117 /* PC26 */ { 0, 0, 0, 0, 0, 0 }, /* PC26 */
118 /* PC25 */ { 0, 0, 0, 0, 0, 0 }, /* PC25 */
119 /* PC24 */ { 0, 0, 0, 0, 0, 0 }, /* PC24 */
120 /* PC23 */ { 0, 0, 0, 0, 0, 0 }, /* FDC37C78 DACFD */
121 /* PC22 */ { 0, 0, 0, 0, 0, 0 }, /* FDC37C78 DNFD */
122 /* PC21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RX_CLK */
123 /* PC20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII TX_CLK */
124 /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK */
125 /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII TX_CLK */
126 /* PC17 */ { 0, 0, 0, 0, 0, 0 }, /* PC17 */
127 /* PC16 */ { 0, 0, 0, 0, 0, 0 }, /* PC16 */
128 /* PC15 */ { 0, 0, 0, 0, 0, 0 }, /* PC15 */
129 /* PC14 */ { 0, 0, 0, 0, 0, 0 }, /* PC14 */
130 /* PC13 */ { 0, 0, 0, 0, 0, 0 }, /* PC13 */
131 /* PC12 */ { 0, 0, 0, 0, 0, 0 }, /* PC12 */
132 /* PC11 */ { 0, 0, 0, 0, 0, 0 }, /* PC11 */
133 /* PC10 */ { 0, 0, 0, 0, 0, 0 }, /* PC10 */
134 /* PC9 */ { 0, 0, 0, 0, 0, 0 }, /* FC9 */
135 /* PC8 */ { 0, 0, 0, 0, 0, 0 }, /* PC8 */
136 /* PC7 */ { 0, 0, 0, 0, 0, 0 }, /* PC7 */
137 /* PC6 */ { 0, 0, 0, 0, 0, 0 }, /* PC6 */
138 /* PC5 */ { 0, 0, 0, 0, 0, 0 }, /* PC5 */
139 /* PC4 */ { 0, 0, 0, 0, 0, 0 }, /* PC4 */
140 /* PC3 */ { 0, 0, 0, 0, 0, 0 }, /* PC3 */
141 /* PC2 */ { 0, 0, 0, 0, 0, 0 }, /* PC2 */
142 /* PC1 */ { 0, 0, 0, 0, 0, 0 }, /* PC1 */
143 /* PC0 */ { 0, 0, 0, 0, 0, 0 }, /* FDC37C78 DRQFD */
144 },
145
146 /* Port D */
147 { /* conf ppar psor pdir podr pdat */
148 /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 RXD */
149 /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 TXD */
150 /* PD29 */ { 1, 0, 0, 1, 0, 0 }, /* SCC1 RTS */
151 /* PD28 */ { 1, 1, 0, 0, 0, 0 }, /* SCC2 RXD */
152 /* PD27 */ { 1, 1, 0, 1, 0, 0 }, /* SCC2 TXD */
153 /* PD26 */ { 1, 0, 0, 1, 0, 0 }, /* SCC2 RTS */
154 /* PD25 */ { 0, 0, 0, 0, 0, 0 }, /* PD25 */
155 /* PD24 */ { 0, 0, 0, 0, 0, 0 }, /* PD24 */
156 /* PD23 */ { 0, 0, 0, 0, 0, 0 }, /* PD23 */
157 /* PD22 */ { 0, 0, 0, 0, 0, 0 }, /* PD22 */
158 /* PD21 */ { 0, 0, 0, 0, 0, 0 }, /* PD21 */
159 /* PD20 */ { 0, 0, 0, 0, 0, 0 }, /* PD20 */
160 /* PD19 */ { 0, 0, 0, 0, 0, 0 }, /* PD19 */
161 /* PD18 */ { 0, 0, 0, 0, 0, 0 }, /* PD18 */
162 /* PD17 */ { 0, 0, 0, 0, 0, 0 }, /* PD17 */
163 /* PD16 */ { 0, 0, 0, 0, 0, 0 }, /* PD16 */
164#if defined(CONFIG_SOFT_I2C)
165 /* PD15 */ { 1, 0, 0, 1, 1, 1 }, /* I2C SDA */
166 /* PD14 */ { 1, 0, 0, 1, 1, 1 }, /* I2C SCL */
167#else
168#if defined(CONFIG_HARD_I2C)
169 /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
170 /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
171#else /* normal I/O port pins */
172 /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
173 /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
174#endif
175#endif
176 /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
177 /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
178 /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
179 /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
180 /* PD9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC1 TXD */
181 /* PD8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC1 RXD */
182 /* PD7 */ { 0, 0, 0, 0, 0, 0 }, /* PD7 */
183 /* PD6 */ { 0, 0, 0, 0, 0, 0 }, /* PD6 */
184 /* PD5 */ { 0, 0, 0, 0, 0, 0 }, /* PD5 */
185 /* PD4 */ { 0, 0, 0, 0, 0, 0 }, /* PD4 */
186 /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* PD3 */
187 /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* PD2 */
188 /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* PD1 */
189 /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* PD0 */
190 }
191};
192
193/* ------------------------------------------------------------------------- */
194
195/* Check Board Identity:
196 */
197int checkboard (void)
198{
199 printf ("Board: CPU86 (Rev %02x)\n", CPU86_REV);
200 return 0;
201}
202
203/* ------------------------------------------------------------------------- */
204
205/* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
206 *
207 * This routine performs standard 8260 initialization sequence
208 * and calculates the available memory size. It may be called
209 * several times to try different SDRAM configurations on both
210 * 60x and local buses.
211 */
212static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
213 ulong orx, volatile uchar * base)
214{
215 volatile uchar c = 0xff;
216 ulong cnt, val;
217 volatile ulong *addr;
218 volatile uint *sdmr_ptr;
219 volatile uint *orx_ptr;
220 int i;
221 ulong save[32]; /* to make test non-destructive */
222 ulong maxsize;
223
224 /* We must be able to test a location outsize the maximum legal size
225 * to find out THAT we are outside; but this address still has to be
226 * mapped by the controller. That means, that the initial mapping has
227 * to be (at least) twice as large as the maximum expected size.
228 */
229 maxsize = (1 + (~orx | 0x7fff)) / 2;
230
231 /* Since CFG_SDRAM_BASE is always 0 (??), we assume that
232 * we are configuring CS1 if base != 0
233 */
234 sdmr_ptr = &memctl->memc_psdmr;
235 orx_ptr = &memctl->memc_or2;
236
237 *orx_ptr = orx;
238
239 /*
240 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
241 *
242 * "At system reset, initialization software must set up the
243 * programmable parameters in the memory controller banks registers
244 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
245 * system software should execute the following initialization sequence
246 * for each SDRAM device.
247 *
248 * 1. Issue a PRECHARGE-ALL-BANKS command
249 * 2. Issue eight CBR REFRESH commands
250 * 3. Issue a MODE-SET command to initialize the mode register
251 *
252 * The initial commands are executed by setting P/LSDMR[OP] and
253 * accessing the SDRAM with a single-byte transaction."
254 *
255 * The appropriate BRx/ORx registers have already been set when we
256 * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
257 */
258
259 *sdmr_ptr = sdmr | PSDMR_OP_PREA;
260 *base = c;
261
262 *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
263 for (i = 0; i < 8; i++)
264 *base = c;
265
266 *sdmr_ptr = sdmr | PSDMR_OP_MRW;
267 *(base + CFG_MRS_OFFS) = c; /* setting MR on address lines */
268
269 *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
270 *base = c;
271
272 /*
273 * Check memory range for valid RAM. A simple memory test determines
274 * the actually available RAM size between addresses `base' and
275 * `base + maxsize'. Some (not all) hardware errors are detected:
276 * - short between address lines
277 * - short between data lines
278 */
279 i = 0;
280 for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
281 addr = (volatile ulong *) base + cnt; /* pointer arith! */
282 save[i++] = *addr;
283 *addr = ~cnt;
284 }
285
286 addr = (volatile ulong *) base;
287 save[i] = *addr;
288 *addr = 0;
289
290 if ((val = *addr) != 0) {
291 *addr = save[i];
292 return (0);
293 }
294
295 for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
296 addr = (volatile ulong *) base + cnt; /* pointer arith! */
297 val = *addr;
298 *addr = save[--i];
299 if (val != ~cnt) {
300 /* Write the actual size to ORx
301 */
302 *orx_ptr = orx | ~(cnt * sizeof (long) - 1);
303 return (cnt * sizeof (long));
304 }
305 }
306 return (maxsize);
307}
308
309long int initdram (int board_type)
310{
311 volatile immap_t *immap = (immap_t *) CFG_IMMR;
312 volatile memctl8260_t *memctl = &immap->im_memctl;
313
314#ifndef CFG_RAMBOOT
315 ulong size8, size9;
316#endif
317 long psize;
318
319 psize = 32 * 1024 * 1024;
320
321 memctl->memc_mptpr = CFG_MPTPR;
322 memctl->memc_psrt = CFG_PSRT;
323
324#ifndef CFG_RAMBOOT
325 /* 60x SDRAM setup:
326 */
327 size8 = try_init (memctl, CFG_PSDMR_8COL, CFG_OR2_8COL,
328 (uchar *) CFG_SDRAM_BASE);
329 size9 = try_init (memctl, CFG_PSDMR_9COL, CFG_OR2_9COL,
330 (uchar *) CFG_SDRAM_BASE);
331
332 if (size8 < size9) {
333 psize = size9;
334 printf ("(60x:9COL) ");
335 } else {
336 psize = try_init (memctl, CFG_PSDMR_8COL, CFG_OR2_8COL,
337 (uchar *) CFG_SDRAM_BASE);
338 printf ("(60x:8COL) ");
339 }
340
341#endif /* CFG_RAMBOOT */
342
343 icache_enable ();
344
345 return (psize);
346}
347
348#if (CONFIG_COMMANDS & CFG_CMD_DOC)
349extern void doc_probe (ulong physadr);
350void doc_init (void)
351{
352 doc_probe (CFG_DOC_BASE);
353}
354#endif