blob: 4dbf4926c2dc87fa5849e01563188578698dce3d [file] [log] [blame]
wdenk858b1a62002-09-30 16:12:23 +00001/*
2 * (C) Copyright 2001
3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
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 * TODO: clean-up
25 */
26
27/*
28 * How do I program the SDRAM Timing Register (SDRAM0_TR) for a specific SDRAM or DIMM?
29 *
30 * As an example, consider a case where PC133 memory with CAS Latency equal to 2 is being
31 * used with a 200MHz 405GP. For a typical 128Mb, PC133 SDRAM, the relevant minimum
32 * parameters from the datasheet are:
33 * Tclk = 7.5ns (CL = 2)
34 * Trp = 15ns
35 * Trc = 60ns
36 * Trcd = 15ns
37 * Trfc = 66ns
38 *
39 * If we are operating the 405GP with the MemClk output frequency set to 100 MHZ, the clock
40 * period is 10ns and the parameters needed for the Timing Register are:
41 * CASL = CL = 2 clock cycles
42 * PTA = Trp = 15ns / 10ns = 2 clock cycles
43 * CTP = Trc - Trcd - Trp = (60ns - 15ns - 15ns) / 10ns= 3 clock cycles
44 * LDF = 2 clock cycles (but can be extended to meet board-level timing)
45 * RFTA = Trfc = 66ns / 10ns= 7 clock cycles
46 * RCD = Trcd = 15ns / 10ns= 2 clock cycles
47 *
48 * The actual bit settings in the register would be:
49 *
50 * CASL = 0b01
51 * PTA = 0b01
52 * CTP = 0b10
53 * LDF = 0b01
54 * RFTA = 0b011
55 * RCD = 0b01
56 *
57 * If Trfc is not specified in the datasheet for PC100 or PC133 memory, set RFTA = Trc
58 * instead. Figure 24 in the PC SDRAM Specification Rev. 1.7 shows refresh to active delay
59 * defined as Trc rather than Trfc.
60 * When using DIMM modules, most but not all of the required timing parameters can be read
61 * from the Serial Presence Detect (SPD) EEPROM on the module. Specifically, Trc and Trfc
62 * are not available from the EEPROM
63 */
64
65#include <common.h>
66#include "mip405.h"
67#include <asm/processor.h>
Stefan Roesed07117e2007-02-20 10:27:08 +010068#include <4xx_i2c.h>
wdenk858b1a62002-09-30 16:12:23 +000069#include <miiphy.h>
70#include "../common/common_util.h"
71#include <i2c.h>
wdenk874ac262003-07-24 23:38:38 +000072#include <rtc.h>
Wolfgang Denk6405a152006-03-31 18:32:53 +020073
74DECLARE_GLOBAL_DATA_PTR;
75
wdenk858b1a62002-09-30 16:12:23 +000076extern block_dev_desc_t * scsi_get_dev(int dev);
77extern block_dev_desc_t * ide_get_dev(int dev);
78
79#undef SDRAM_DEBUG
wdenke39c2842003-06-04 15:05:30 +000080#define ENABLE_ECC /* for ecc boards */
wdenk858b1a62002-09-30 16:12:23 +000081#define FALSE 0
82#define TRUE 1
83
84/* stdlib.h causes some compatibility problems; should fixe these! -- wd */
85#ifndef __ldiv_t_defined
86typedef struct {
87 long int quot; /* Quotient */
88 long int rem; /* Remainder */
89} ldiv_t;
90extern ldiv_t ldiv (long int __numer, long int __denom);
91# define __ldiv_t_defined 1
92#endif
93
94
95#define PLD_PART_REG PER_PLD_ADDR + 0
96#define PLD_VERS_REG PER_PLD_ADDR + 1
97#define PLD_BOARD_CFG_REG PER_PLD_ADDR + 2
98#define PLD_IRQ_REG PER_PLD_ADDR + 3
99#define PLD_COM_MODE_REG PER_PLD_ADDR + 4
100#define PLD_EXT_CONF_REG PER_PLD_ADDR + 5
101
102#define MEGA_BYTE (1024*1024)
103
104typedef struct {
105 unsigned char boardtype; /* Board revision and Population Options */
106 unsigned char cal; /* cas Latency (will be programmend as cal-1) */
107 unsigned char trp; /* datain27 in clocks */
108 unsigned char trcd; /* datain29 in clocks */
109 unsigned char tras; /* datain30 in clocks */
110 unsigned char tctp; /* tras - trcd in clocks */
111 unsigned char am; /* Address Mod (will be programmed as am-1) */
112 unsigned char sz; /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */
113 unsigned char ecc; /* if true, ecc is enabled */
114} sdram_t;
wdenke39c2842003-06-04 15:05:30 +0000115#if defined(CONFIG_MIP405T)
116const sdram_t sdram_table[] = {
wdenk874ac262003-07-24 23:38:38 +0000117 { 0x0F, /* MIP405T Rev A, 64MByte -1 Board */
wdenke39c2842003-06-04 15:05:30 +0000118 3, /* Case Latenty = 3 */
119 3, /* trp 20ns / 7.5 ns datain[27] */
120 3, /* trcd 20ns /7.5 ns (datain[29]) */
121 6, /* tras 44ns /7.5 ns (datain[30]) */
122 4, /* tcpt 44 - 20ns = 24ns */
wdenk874ac262003-07-24 23:38:38 +0000123 2, /* Address Mode = 2 (12x9x4) */
124 3, /* size value (32MByte) */
wdenke39c2842003-06-04 15:05:30 +0000125 0}, /* ECC disabled */
126 { 0xff, /* terminator */
127 0xff,
128 0xff,
129 0xff,
130 0xff,
131 0xff,
132 0xff,
133 0xff }
134};
135#else
wdenk858b1a62002-09-30 16:12:23 +0000136const sdram_t sdram_table[] = {
137 { 0x0f, /* Rev A, 128MByte -1 Board */
138 3, /* Case Latenty = 3 */
139 3, /* trp 20ns / 7.5 ns datain[27] */
wdenk7d076412003-05-23 11:38:58 +0000140 3, /* trcd 20ns /7.5 ns (datain[29]) */
141 6, /* tras 44ns /7.5 ns (datain[30]) */
wdenk858b1a62002-09-30 16:12:23 +0000142 4, /* tcpt 44 - 20ns = 24ns */
wdenk7d076412003-05-23 11:38:58 +0000143 3, /* Address Mode = 3 */
wdenk858b1a62002-09-30 16:12:23 +0000144 5, /* size value */
145 1}, /* ECC enabled */
146 { 0x07, /* Rev A, 64MByte -2 Board */
147 3, /* Case Latenty = 3 */
148 3, /* trp 20ns / 7.5 ns datain[27] */
wdenk7d076412003-05-23 11:38:58 +0000149 3, /* trcd 20ns /7.5 ns (datain[29]) */
150 6, /* tras 44ns /7.5 ns (datain[30]) */
wdenk858b1a62002-09-30 16:12:23 +0000151 4, /* tcpt 44 - 20ns = 24ns */
wdenk7d076412003-05-23 11:38:58 +0000152 2, /* Address Mode = 2 */
wdenk858b1a62002-09-30 16:12:23 +0000153 4, /* size value */
154 1}, /* ECC enabled */
wdenkb02744a2003-04-05 00:53:31 +0000155 { 0x03, /* Rev A, 128MByte -4 Board */
156 3, /* Case Latenty = 3 */
157 3, /* trp 20ns / 7.5 ns datain[27] */
wdenk7d076412003-05-23 11:38:58 +0000158 3, /* trcd 20ns /7.5 ns (datain[29]) */
159 6, /* tras 44ns /7.5 ns (datain[30]) */
wdenkb02744a2003-04-05 00:53:31 +0000160 4, /* tcpt 44 - 20ns = 24ns */
wdenk7d076412003-05-23 11:38:58 +0000161 3, /* Address Mode = 3 */
wdenkb02744a2003-04-05 00:53:31 +0000162 5, /* size value */
163 1}, /* ECC enabled */
wdenk7d076412003-05-23 11:38:58 +0000164 { 0x1f, /* Rev B, 128MByte -3 Board */
165 3, /* Case Latenty = 3 */
166 3, /* trp 20ns / 7.5 ns datain[27] */
167 3, /* trcd 20ns /7.5 ns (datain[29]) */
168 6, /* tras 44ns /7.5 ns (datain[30]) */
169 4, /* tcpt 44 - 20ns = 24ns */
170 3, /* Address Mode = 3 */
171 5, /* size value */
172 1}, /* ECC enabled */
wdenk60164a82003-10-08 23:26:14 +0000173 { 0x2f, /* Rev C, 128MByte -3 Board */
174 3, /* Case Latenty = 3 */
175 3, /* trp 20ns / 7.5 ns datain[27] */
176 3, /* trcd 20ns /7.5 ns (datain[29]) */
177 6, /* tras 44ns /7.5 ns (datain[30]) */
178 4, /* tcpt 44 - 20ns = 24ns */
179 3, /* Address Mode = 3 */
180 5, /* size value */
181 1}, /* ECC enabled */
wdenk858b1a62002-09-30 16:12:23 +0000182 { 0xff, /* terminator */
183 0xff,
184 0xff,
185 0xff,
186 0xff,
187 0xff,
188 0xff,
189 0xff }
190};
wdenke39c2842003-06-04 15:05:30 +0000191#endif /*CONFIG_MIP405T */
wdenk858b1a62002-09-30 16:12:23 +0000192void SDRAM_err (const char *s)
193{
194#ifndef SDRAM_DEBUG
wdenk858b1a62002-09-30 16:12:23 +0000195 (void) get_clocks ();
196 gd->baudrate = 9600;
197 serial_init ();
198#endif
199 serial_puts ("\n");
200 serial_puts (s);
201 serial_puts ("\n enable SDRAM_DEBUG for more info\n");
202 for (;;);
203}
204
205
206unsigned char get_board_revcfg (void)
207{
208 out8 (PER_BOARD_ADDR, 0);
209 return (in8 (PER_BOARD_ADDR));
210}
211
212
213#ifdef SDRAM_DEBUG
214
215void write_hex (unsigned char i)
216{
217 char cc;
218
219 cc = i >> 4;
220 cc &= 0xf;
221 if (cc > 9)
222 serial_putc (cc + 55);
223 else
224 serial_putc (cc + 48);
225 cc = i & 0xf;
226 if (cc > 9)
227 serial_putc (cc + 55);
228 else
229 serial_putc (cc + 48);
230}
231
232void write_4hex (unsigned long val)
233{
234 write_hex ((unsigned char) (val >> 24));
235 write_hex ((unsigned char) (val >> 16));
236 write_hex ((unsigned char) (val >> 8));
237 write_hex ((unsigned char) val);
238}
239
240#endif
241
242
243int init_sdram (void)
244{
wdenk858b1a62002-09-30 16:12:23 +0000245 unsigned long tmp, baseaddr;
246 unsigned short i;
247 unsigned char trp_clocks,
248 trcd_clocks,
249 tras_clocks,
250 trc_clocks,
251 tctp_clocks;
252 unsigned char cal_val;
253 unsigned char bc;
wdenke39c2842003-06-04 15:05:30 +0000254 unsigned long sdram_tim, sdram_bank;
wdenk858b1a62002-09-30 16:12:23 +0000255
wdenke39c2842003-06-04 15:05:30 +0000256 /*i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);*/
wdenk858b1a62002-09-30 16:12:23 +0000257 (void) get_clocks ();
258 gd->baudrate = 9600;
259 serial_init ();
wdenke39c2842003-06-04 15:05:30 +0000260 /* set up the pld */
261 mtdcr (ebccfga, pb7ap);
262 mtdcr (ebccfgd, PLD_AP);
263 mtdcr (ebccfga, pb7cr);
264 mtdcr (ebccfgd, PLD_CR);
265 /* THIS IS OBSOLETE */
266 /* set up the board rev reg*/
267 mtdcr (ebccfga, pb5ap);
268 mtdcr (ebccfgd, BOARD_AP);
269 mtdcr (ebccfga, pb5cr);
270 mtdcr (ebccfgd, BOARD_CR);
271#ifdef SDRAM_DEBUG
272 /* get all informations from PLD */
273 serial_puts ("\nPLD Part 0x");
274 bc = in8 (PLD_PART_REG);
275 write_hex (bc);
276 serial_puts ("\nPLD Vers 0x");
277 bc = in8 (PLD_VERS_REG);
278 write_hex (bc);
279 serial_puts ("\nBoard Rev 0x");
280 bc = in8 (PLD_BOARD_CFG_REG);
281 write_hex (bc);
282 serial_puts ("\n");
283#endif
284 /* check board */
285 bc = in8 (PLD_PART_REG);
286#if defined(CONFIG_MIP405T)
287 if((bc & 0x80)==0)
288 SDRAM_err ("U-Boot configured for a MIP405T not for a MIP405!!!\n");
289#else
290 if((bc & 0x80)==0x80)
291 SDRAM_err ("U-Boot configured for a MIP405 not for a MIP405T!!!\n");
292#endif
wdenke39c2842003-06-04 15:05:30 +0000293 /* set-up the chipselect machine */
wdenk858b1a62002-09-30 16:12:23 +0000294 mtdcr (ebccfga, pb0cr); /* get cs0 config reg */
wdenke39c2842003-06-04 15:05:30 +0000295 tmp = mfdcr (ebccfgd);
296 if ((tmp & 0x00002000) == 0) {
wdenk858b1a62002-09-30 16:12:23 +0000297 /* MPS Boot, set up the flash */
298 mtdcr (ebccfga, pb1ap);
299 mtdcr (ebccfgd, FLASH_AP);
300 mtdcr (ebccfga, pb1cr);
301 mtdcr (ebccfgd, FLASH_CR);
302 } else {
303 /* Flash boot, set up the MPS */
304 mtdcr (ebccfga, pb1ap);
305 mtdcr (ebccfgd, MPS_AP);
306 mtdcr (ebccfga, pb1cr);
307 mtdcr (ebccfgd, MPS_CR);
308 }
309 /* set up UART0 (CS2) and UART1 (CS3) */
310 mtdcr (ebccfga, pb2ap);
311 mtdcr (ebccfgd, UART0_AP);
312 mtdcr (ebccfga, pb2cr);
313 mtdcr (ebccfgd, UART0_CR);
314 mtdcr (ebccfga, pb3ap);
315 mtdcr (ebccfgd, UART1_AP);
316 mtdcr (ebccfga, pb3cr);
317 mtdcr (ebccfgd, UART1_CR);
wdenke39c2842003-06-04 15:05:30 +0000318 bc = in8 (PLD_BOARD_CFG_REG);
wdenk858b1a62002-09-30 16:12:23 +0000319#ifdef SDRAM_DEBUG
320 serial_puts ("\nstart SDRAM Setup\n");
321 serial_puts ("\nBoard Rev: ");
322 write_hex (bc);
323 serial_puts ("\n");
324#endif
325 i = 0;
326 baseaddr = CFG_SDRAM_BASE;
327 while (sdram_table[i].sz != 0xff) {
328 if (sdram_table[i].boardtype == bc)
329 break;
330 i++;
331 }
332 if (sdram_table[i].boardtype != bc)
333 SDRAM_err ("No SDRAM table found for this board!!!\n");
334#ifdef SDRAM_DEBUG
335 serial_puts (" found table ");
336 write_hex (i);
337 serial_puts (" \n");
338#endif
wdenk874ac262003-07-24 23:38:38 +0000339 /* since the ECC initialisation needs some time,
340 * we show that we're alive
341 */
342 if (sdram_table[i].ecc)
343 serial_puts ("\nInitializing SDRAM, Please stand by");
wdenk858b1a62002-09-30 16:12:23 +0000344 cal_val = sdram_table[i].cal - 1; /* Cas Latency */
345 trp_clocks = sdram_table[i].trp; /* 20ns / 7.5 ns datain[27] */
346 trcd_clocks = sdram_table[i].trcd; /* 20ns /7.5 ns (datain[29]) */
347 tras_clocks = sdram_table[i].tras; /* 44ns /7.5 ns (datain[30]) */
348 /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */
349 tctp_clocks = sdram_table[i].tctp; /* 44 - 20ns = 24ns */
350 /* trc_clocks is sum of trp_clocks + tras_clocks */
351 trc_clocks = trp_clocks + tras_clocks;
352 /* get SDRAM timing register */
353 mtdcr (memcfga, mem_sdtr1);
354 sdram_tim = mfdcr (memcfgd) & ~0x018FC01F;
355 /* insert CASL value */
356 sdram_tim |= ((unsigned long) (cal_val)) << 23;
357 /* insert PTA value */
358 sdram_tim |= ((unsigned long) (trp_clocks - 1)) << 18;
359 /* insert CTP value */
360 sdram_tim |=
361 ((unsigned long) (trc_clocks - trp_clocks -
362 trcd_clocks)) << 16;
363 /* insert LDF (always 01) */
364 sdram_tim |= ((unsigned long) 0x01) << 14;
365 /* insert RFTA value */
366 sdram_tim |= ((unsigned long) (trc_clocks - 4)) << 2;
367 /* insert RCD value */
368 sdram_tim |= ((unsigned long) (trcd_clocks - 1)) << 0;
369
370 tmp = ((unsigned long) (sdram_table[i].am - 1) << 13); /* AM = 3 */
371 /* insert SZ value; */
372 tmp |= ((unsigned long) sdram_table[i].sz << 17);
373 /* get SDRAM bank 0 register */
374 mtdcr (memcfga, mem_mb0cf);
375 sdram_bank = mfdcr (memcfgd) & ~0xFFCEE001;
376 sdram_bank |= (baseaddr | tmp | 0x01);
377
378#ifdef SDRAM_DEBUG
379 serial_puts ("sdtr: ");
380 write_4hex (sdram_tim);
381 serial_puts ("\n");
382#endif
383
384 /* write SDRAM timing register */
385 mtdcr (memcfga, mem_sdtr1);
386 mtdcr (memcfgd, sdram_tim);
387
388#ifdef SDRAM_DEBUG
389 serial_puts ("mb0cf: ");
390 write_4hex (sdram_bank);
391 serial_puts ("\n");
392#endif
393
394 /* write SDRAM bank 0 register */
395 mtdcr (memcfga, mem_mb0cf);
396 mtdcr (memcfgd, sdram_bank);
397
398 if (get_bus_freq (tmp) > 110000000) { /* > 110MHz */
399 /* get SDRAM refresh interval register */
400 mtdcr (memcfga, mem_rtr);
401 tmp = mfdcr (memcfgd) & ~0x3FF80000;
402 tmp |= 0x07F00000;
403 } else {
404 /* get SDRAM refresh interval register */
405 mtdcr (memcfga, mem_rtr);
406 tmp = mfdcr (memcfgd) & ~0x3FF80000;
407 tmp |= 0x05F00000;
408 }
409 /* write SDRAM refresh interval register */
410 mtdcr (memcfga, mem_rtr);
411 mtdcr (memcfgd, tmp);
412 /* enable ECC if used */
wdenke39c2842003-06-04 15:05:30 +0000413#if defined(ENABLE_ECC) && !defined(CONFIG_BOOT_PCI)
wdenk858b1a62002-09-30 16:12:23 +0000414 if (sdram_table[i].ecc) {
415 /* disable checking for all banks */
wdenke39c2842003-06-04 15:05:30 +0000416 unsigned long *p;
wdenk858b1a62002-09-30 16:12:23 +0000417#ifdef SDRAM_DEBUG
418 serial_puts ("disable ECC.. ");
419#endif
420 mtdcr (memcfga, mem_ecccf);
421 tmp = mfdcr (memcfgd);
422 tmp &= 0xff0fffff; /* disable all banks */
423 mtdcr (memcfga, mem_ecccf);
424 /* set up SDRAM Controller with ECC enabled */
425#ifdef SDRAM_DEBUG
426 serial_puts ("setup SDRAM Controller.. ");
427#endif
428 mtdcr (memcfgd, tmp);
429 mtdcr (memcfga, mem_mcopt1);
430 tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000;
431 mtdcr (memcfga, mem_mcopt1);
432 mtdcr (memcfgd, tmp);
433 udelay (600);
434#ifdef SDRAM_DEBUG
435 serial_puts ("fill the memory..\n");
436#endif
437 serial_puts (".");
438 /* now, fill all the memory */
439 tmp = ((4 * MEGA_BYTE) << sdram_table[i].sz);
440 p = (unsigned long) 0;
441 while ((unsigned long) p < tmp) {
442 *p++ = 0L;
443 if (!((unsigned long) p % 0x00800000)) /* every 8MByte */
444 serial_puts (".");
wdenk858b1a62002-09-30 16:12:23 +0000445 }
446 /* enable bank 0 */
447 serial_puts (".");
448#ifdef SDRAM_DEBUG
449 serial_puts ("enable ECC\n");
450#endif
451 udelay (400);
452 mtdcr (memcfga, mem_ecccf);
453 tmp = mfdcr (memcfgd);
454 tmp |= 0x00800000; /* enable bank 0 */
455 mtdcr (memcfgd, tmp);
456 udelay (400);
457 } else
458#endif
459 {
460 /* enable SDRAM controller with no ECC, 32-bit SDRAM width, 16 byte burst */
461 mtdcr (memcfga, mem_mcopt1);
462 tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x80C00000;
463 mtdcr (memcfga, mem_mcopt1);
464 mtdcr (memcfgd, tmp);
465 udelay (400);
466 }
467 serial_puts ("\n");
468 return (0);
469}
470
wdenkda55c6e2004-01-20 23:12:12 +0000471int board_early_init_f (void)
wdenk858b1a62002-09-30 16:12:23 +0000472{
473 init_sdram ();
474
475 /*-------------------------------------------------------------------------+
476 | Interrupt controller setup for the PIP405 board.
477 | Note: IRQ 0-15 405GP internally generated; active high; level sensitive
478 | IRQ 16 405GP internally generated; active low; level sensitive
479 | IRQ 17-24 RESERVED
480 | IRQ 25 (EXT IRQ 0) SouthBridge; active low; level sensitive
481 | IRQ 26 (EXT IRQ 1) NMI: active low; level sensitive
482 | IRQ 27 (EXT IRQ 2) SMI: active Low; level sensitive
483 | IRQ 28 (EXT IRQ 3) PCI SLOT 3; active low; level sensitive
484 | IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
485 | IRQ 30 (EXT IRQ 5) PCI SLOT 1; active low; level sensitive
486 | IRQ 31 (EXT IRQ 6) PCI SLOT 0; active low; level sensitive
487 | Note for MIP405 board:
488 | An interrupt taken for the SouthBridge (IRQ 25) indicates that
489 | the Interrupt Controller in the South Bridge has caused the
490 | interrupt. The IC must be read to determine which device
491 | caused the interrupt.
492 |
493 +-------------------------------------------------------------------------*/
494 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
495 mtdcr (uicer, 0x00000000); /* disable all ints */
496 mtdcr (uiccr, 0x00000000); /* set all to be non-critical (for now) */
497 mtdcr (uicpr, 0xFFFFFF80); /* set int polarities */
498 mtdcr (uictr, 0x10000000); /* set int trigger levels */
499 mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
500 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
501 return 0;
502}
503
504
505/*
506 * Get some PLD Registers
507 */
508
509unsigned short get_pld_parvers (void)
510{
511 unsigned short result;
512 unsigned char rc;
513
514 rc = in8 (PLD_PART_REG);
515 result = (unsigned short) rc << 8;
516 rc = in8 (PLD_VERS_REG);
517 result |= rc;
518 return result;
519}
520
521
wdenk858b1a62002-09-30 16:12:23 +0000522void user_led0 (unsigned char on)
523{
524 if (on)
525 out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x4));
526 else
527 out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfb));
528}
529
530
531void ide_set_reset (int idereset)
532{
533 /* if reset = 1 IDE reset will be asserted */
534 if (idereset)
535 out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x1));
536 else {
537 udelay (10000);
538 out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfe));
539 }
540}
541
542
543/* ------------------------------------------------------------------------- */
544
wdenke39c2842003-06-04 15:05:30 +0000545void get_pcbrev_var(unsigned char *pcbrev, unsigned char *var)
wdenk858b1a62002-09-30 16:12:23 +0000546{
wdenke39c2842003-06-04 15:05:30 +0000547#if !defined(CONFIG_MIP405T)
548 unsigned char bc,rc,tmp;
wdenk858b1a62002-09-30 16:12:23 +0000549 int i;
wdenk858b1a62002-09-30 16:12:23 +0000550
wdenke39c2842003-06-04 15:05:30 +0000551 bc = in8 (PLD_BOARD_CFG_REG);
552 tmp = ~bc;
553 tmp &= 0xf;
wdenk858b1a62002-09-30 16:12:23 +0000554 rc = 0;
555 for (i = 0; i < 4; i++) {
556 rc <<= 1;
wdenke39c2842003-06-04 15:05:30 +0000557 rc += (tmp & 0x1);
558 tmp >>= 1;
wdenk858b1a62002-09-30 16:12:23 +0000559 }
560 rc++;
wdenk60164a82003-10-08 23:26:14 +0000561 if(( (((bc>>4) & 0xf)==0x2) /* Rev C PCB or */
562 || (((bc>>4) & 0xf)==0x1)) /* Rev B PCB with */
wdenk7d076412003-05-23 11:38:58 +0000563 && (rc==0x1)) /* Population Option 1 is a -3 */
564 rc=3;
wdenke39c2842003-06-04 15:05:30 +0000565 *pcbrev=(bc >> 4) & 0xf;
566 *var=rc;
567#else
568 unsigned char bc;
569 bc = in8 (PLD_BOARD_CFG_REG);
570 *pcbrev=(bc >> 4) & 0xf;
wdenk874ac262003-07-24 23:38:38 +0000571 *var=16-(bc & 0xf);
wdenke39c2842003-06-04 15:05:30 +0000572#endif
573}
574
575/*
576 * Check Board Identity:
577 */
578/* serial String: "MIP405_1000" OR "MIP405T_1000" */
579#if !defined(CONFIG_MIP405T)
580#define BOARD_NAME "MIP405"
581#else
582#define BOARD_NAME "MIP405T"
583#endif
584
585int checkboard (void)
586{
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200587 char s[50];
wdenke39c2842003-06-04 15:05:30 +0000588 unsigned char bc, var;
589 int i;
590 backup_t *b = (backup_t *) s;
591
592 puts ("Board: ");
593 get_pcbrev_var(&bc,&var);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200594 i = getenv_r ("serial#", (char *)s, 32);
595 if ((i == 0) || strncmp ((char *)s, BOARD_NAME,sizeof(BOARD_NAME))) {
wdenk858b1a62002-09-30 16:12:23 +0000596 get_backup_values (b);
597 if (strncmp (b->signature, "MPL\0", 4) != 0) {
wdenke39c2842003-06-04 15:05:30 +0000598 puts ("### No HW ID - assuming " BOARD_NAME);
599 printf ("-%d Rev %c", var, 'A' + bc);
wdenk858b1a62002-09-30 16:12:23 +0000600 } else {
wdenke39c2842003-06-04 15:05:30 +0000601 b->serial_name[sizeof(BOARD_NAME)-1] = 0;
602 printf ("%s-%d Rev %c SN: %s", b->serial_name, var,
603 'A' + bc, &b->serial_name[sizeof(BOARD_NAME)]);
wdenk858b1a62002-09-30 16:12:23 +0000604 }
605 } else {
wdenke39c2842003-06-04 15:05:30 +0000606 s[sizeof(BOARD_NAME)-1] = 0;
607 printf ("%s-%d Rev %c SN: %s", s, var,'A' + bc,
608 &s[sizeof(BOARD_NAME)]);
wdenk858b1a62002-09-30 16:12:23 +0000609 }
610 bc = in8 (PLD_EXT_CONF_REG);
611 printf (" Boot Config: 0x%x\n", bc);
612 return (0);
613}
614
615
616/* ------------------------------------------------------------------------- */
617/* ------------------------------------------------------------------------- */
618/*
619 initdram(int board_type) reads EEPROM via I2c. EEPROM contains all of
620 the necessary info for SDRAM controller configuration
621*/
622/* ------------------------------------------------------------------------- */
623/* ------------------------------------------------------------------------- */
624static int test_dram (unsigned long ramsize);
625
626long int initdram (int board_type)
627{
628
629 unsigned long bank_reg[4], tmp, bank_size;
630 int i, ds;
631 unsigned long TotalSize;
632
633 ds = 0;
634 /* since the DRAM controller is allready set up, calculate the size with the
635 bank registers */
636 mtdcr (memcfga, mem_mb0cf);
637 bank_reg[0] = mfdcr (memcfgd);
638 mtdcr (memcfga, mem_mb1cf);
639 bank_reg[1] = mfdcr (memcfgd);
640 mtdcr (memcfga, mem_mb2cf);
641 bank_reg[2] = mfdcr (memcfgd);
642 mtdcr (memcfga, mem_mb3cf);
643 bank_reg[3] = mfdcr (memcfgd);
644 TotalSize = 0;
645 for (i = 0; i < 4; i++) {
646 if ((bank_reg[i] & 0x1) == 0x1) {
647 tmp = (bank_reg[i] >> 17) & 0x7;
648 bank_size = 4 << tmp;
649 TotalSize += bank_size;
650 } else
651 ds = 1;
652 }
653 mtdcr (memcfga, mem_ecccf);
654 tmp = mfdcr (memcfgd);
655
656 if (!tmp)
657 printf ("No ");
658 printf ("ECC ");
659
660 test_dram (TotalSize * MEGA_BYTE);
661 return (TotalSize * MEGA_BYTE);
662}
663
664/* ------------------------------------------------------------------------- */
665
wdenk858b1a62002-09-30 16:12:23 +0000666
667static int test_dram (unsigned long ramsize)
668{
669#ifdef SDRAM_DEBUG
670 mem_test (0L, ramsize, 1);
671#endif
672 /* not yet implemented */
673 return (1);
674}
675
wdenk874ac262003-07-24 23:38:38 +0000676/* used to check if the time in RTC is valid */
677static unsigned long start;
678static struct rtc_time tm;
wdenk2c9b05d2003-09-10 22:30:53 +0000679extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk874ac262003-07-24 23:38:38 +0000680
wdenk858b1a62002-09-30 16:12:23 +0000681int misc_init_r (void)
682{
wdenk2c9b05d2003-09-10 22:30:53 +0000683 /* adjust flash start and size as well as the offset */
684 gd->bd->bi_flashstart=0-flash_info[0].size;
685 gd->bd->bi_flashsize=flash_info[0].size-CFG_MONITOR_LEN;
686 gd->bd->bi_flashoffset=0;
687
wdenk874ac262003-07-24 23:38:38 +0000688 /* check, if RTC is running */
689 rtc_get (&tm);
690 start=get_timer(0);
wdenke39c2842003-06-04 15:05:30 +0000691 /* if MIP405 has booted from PCI, reset CCR0[24] as described in errata PCI_18 */
692 if (mfdcr(strap) & PSR_ROM_LOC)
693 mtspr(ccr0, (mfspr(ccr0) & ~0x80));
694
wdenk858b1a62002-09-30 16:12:23 +0000695 return (0);
696}
697
698
699void print_mip405_rev (void)
700{
wdenke39c2842003-06-04 15:05:30 +0000701 unsigned char part, vers, pcbrev, var;
wdenk858b1a62002-09-30 16:12:23 +0000702
wdenke39c2842003-06-04 15:05:30 +0000703 get_pcbrev_var(&pcbrev,&var);
wdenk858b1a62002-09-30 16:12:23 +0000704 part = in8 (PLD_PART_REG);
705 vers = in8 (PLD_VERS_REG);
wdenke39c2842003-06-04 15:05:30 +0000706 printf ("Rev: " BOARD_NAME "-%d Rev %c PLD %d Vers %d\n",
707 var, pcbrev + 'A', part & 0x7F, vers);
wdenk858b1a62002-09-30 16:12:23 +0000708}
709
wdenke97d3d92004-02-23 22:22:28 +0000710
711#ifdef CONFIG_POST
712/*
713 * Returns 1 if keys pressed to start the power-on long-running tests
714 * Called from board_init_f().
715 */
716int post_hotkeys_pressed(void)
717{
718 return 0; /* No hotkeys supported */
719}
720#endif
721
wdenk7d076412003-05-23 11:38:58 +0000722extern void mem_test_reloc(void);
wdenk874ac262003-07-24 23:38:38 +0000723extern int mk_date (char *, struct rtc_time *);
wdenk858b1a62002-09-30 16:12:23 +0000724
725int last_stage_init (void)
726{
wdenk874ac262003-07-24 23:38:38 +0000727 unsigned long stop;
728 struct rtc_time newtm;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200729 char *s;
wdenk7d076412003-05-23 11:38:58 +0000730 mem_test_reloc();
wdenkb02744a2003-04-05 00:53:31 +0000731 /* write correct LED configuration */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200732 if (miiphy_write("ppc_4xx_eth0", 0x1, 0x14, 0x2402) != 0) {
wdenk858b1a62002-09-30 16:12:23 +0000733 printf ("Error writing to the PHY\n");
734 }
wdenkb02744a2003-04-05 00:53:31 +0000735 /* since LED/CFG2 is not connected on the -2,
736 * write to correct capability information */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200737 if (miiphy_write("ppc_4xx_eth0", 0x1, 0x4, 0x01E1) != 0) {
wdenkb02744a2003-04-05 00:53:31 +0000738 printf ("Error writing to the PHY\n");
739 }
wdenk858b1a62002-09-30 16:12:23 +0000740 print_mip405_rev ();
741 show_stdio_dev ();
742 check_env ();
wdenk874ac262003-07-24 23:38:38 +0000743 /* check if RTC time is valid */
744 stop=get_timer(start);
745 while(stop<1200) { /* we wait 1.2 sec to check if the RTC is running */
746 udelay(1000);
747 stop=get_timer(start);
748 }
749 rtc_get (&newtm);
750 if(tm.tm_sec==newtm.tm_sec) {
751 s=getenv("defaultdate");
752 if(!s)
753 mk_date ("010112001970", &newtm);
754 else
755 if(mk_date (s, &newtm)!=0) {
756 printf("RTC: Bad date format in defaultdate\n");
757 return 0;
758 }
759 rtc_reset ();
760 rtc_set(&newtm);
761 }
wdenk858b1a62002-09-30 16:12:23 +0000762 return 0;
763}
764
765/***************************************************************************
766 * some helping routines
767 */
768
769int overwrite_console (void)
770{
771 return ((in8 (PLD_EXT_CONF_REG) & 0x1)==0); /* return TRUE if console should be overwritten */
772}
773
774
775/************************************************************************
776* Print MIP405 Info
777************************************************************************/
778void print_mip405_info (void)
779{
780 unsigned char part, vers, cfg, irq_reg, com_mode, ext;
781
782 part = in8 (PLD_PART_REG);
783 vers = in8 (PLD_VERS_REG);
784 cfg = in8 (PLD_BOARD_CFG_REG);
785 irq_reg = in8 (PLD_IRQ_REG);
786 com_mode = in8 (PLD_COM_MODE_REG);
787 ext = in8 (PLD_EXT_CONF_REG);
788
wdenke39c2842003-06-04 15:05:30 +0000789 printf ("PLD Part %d version %d\n", part & 0x7F, vers);
wdenk858b1a62002-09-30 16:12:23 +0000790 printf ("Board Revision %c\n", ((cfg >> 4) & 0xf) + 'A');
791 printf ("Population Options %d %d %d %d\n", (cfg) & 0x1,
792 (cfg >> 1) & 0x1, (cfg >> 2) & 0x1, (cfg >> 3) & 0x1);
793 printf ("User LED %s\n", (com_mode & 0x4) ? "on" : "off");
794 printf ("UART Clocks %d\n", (com_mode >> 4) & 0x3);
wdenke39c2842003-06-04 15:05:30 +0000795#if !defined(CONFIG_MIP405T)
wdenk858b1a62002-09-30 16:12:23 +0000796 printf ("User Config Switch %d %d %d %d %d %d %d %d\n",
797 (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1,
798 (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1,
799 (ext >> 6) & 0x1, (ext >> 7) & 0x1);
800 printf ("SER1 uses handshakes %s\n",
801 (ext & 0x80) ? "DTR/DSR" : "RTS/CTS");
wdenke39c2842003-06-04 15:05:30 +0000802#else
wdenk874ac262003-07-24 23:38:38 +0000803 printf ("User Config Switch %d %d %d %d %d %d %d %d\n",
wdenke39c2842003-06-04 15:05:30 +0000804 (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1,
805 (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1,
wdenk874ac262003-07-24 23:38:38 +0000806 (ext >> 6) & 0x1,(ext >> 7) & 0x1);
wdenke39c2842003-06-04 15:05:30 +0000807#endif
wdenk858b1a62002-09-30 16:12:23 +0000808 printf ("IDE Reset %s\n", (ext & 0x01) ? "asserted" : "not asserted");
809 printf ("IRQs:\n");
810 printf (" PIIX INTR: %s\n", (irq_reg & 0x80) ? "inactive" : "active");
wdenke39c2842003-06-04 15:05:30 +0000811#if !defined(CONFIG_MIP405T)
wdenk858b1a62002-09-30 16:12:23 +0000812 printf (" UART0 IRQ: %s\n", (irq_reg & 0x40) ? "inactive" : "active");
813 printf (" UART1 IRQ: %s\n", (irq_reg & 0x20) ? "inactive" : "active");
wdenke39c2842003-06-04 15:05:30 +0000814#endif
wdenk858b1a62002-09-30 16:12:23 +0000815 printf (" PIIX SMI: %s\n", (irq_reg & 0x10) ? "inactive" : "active");
816 printf (" PIIX INIT: %s\n", (irq_reg & 0x8) ? "inactive" : "active");
817 printf (" PIIX NMI: %s\n", (irq_reg & 0x4) ? "inactive" : "active");
818}