2 * (C) Copyright 2000-2002
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 * written or collected and sometimes rewritten by
32 * minor modifications by
40 #include <asm/cache.h>
42 static char *cpu_warning = "\n " \
43 "*** Warning: CPU Core has Silicon Bugs -- Check the Errata ***";
45 #if ((defined(CONFIG_MPC860) || defined(CONFIG_MPC855)) && \
46 !defined(CONFIG_MPC862))
48 # define ID_STR "PC855"
50 # define ID_STR "PC860"
53 static int check_CPU (long clock, uint pvr, uint immr)
55 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
62 /* the highest 16 bits should be 0x0050 for a 860 */
64 if ((pvr >> 16) != 0x0050)
67 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
71 case 0x00020001: pre = 'p'; suf = ""; break;
72 case 0x00030001: suf = ""; break;
73 case 0x00120003: suf = "A"; break;
74 case 0x00130003: suf = "A3"; break;
76 case 0x00200004: suf = "B"; break;
78 case 0x00300004: suf = "C"; break;
79 case 0x00310004: suf = "C1"; m = 1;
82 case 0x00200064: mid = "SR"; suf = "B"; break;
83 case 0x00300065: mid = "SR"; suf = "C"; break;
84 case 0x00310065: mid = "SR"; suf = "C1"; m = 1; break;
85 case 0x05010000: suf = "D3"; m = 1; break;
86 case 0x05020000: suf = "D4"; m = 1; break;
88 /* this value is not documented anywhere */
89 case 0x40000000: pre = 'P'; suf = "D"; m = 1; break;
91 default: suf = NULL; break;
95 printf ("%c" ID_STR "%sZPnn%s", pre, mid, suf);
97 printf ("unknown M" ID_STR " (0x%08x)", k);
99 printf (" at %s MHz:", strmhz (buf, clock));
101 printf (" %u kB I-Cache", checkicache () >> 10);
102 printf (" %u kB D-Cache", checkdcache () >> 10);
104 /* lets check and see if we're running on a 860T (or P?) */
106 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
107 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
108 printf (" FEC present");
120 #elif defined(CONFIG_MPC862)
122 static int check_CPU (long clock, uint pvr, uint immr)
124 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
131 /* the highest 16 bits should be 0x0050 for a 8xx */
133 if ((pvr >> 16) != 0x0050)
136 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
141 /* this value is not documented anywhere */
142 case 0x06000000: mid = "P"; suf = "0"; break;
143 case 0x06010001: mid = "P"; suf = "A"; m = 1; break;
144 case 0x07000003: mid = "P"; suf = "B"; m = 1; break;
145 default: suf = NULL; break;
149 printf ("%cPC862%sZPnn%s", pre, mid, suf);
151 printf ("unknown MPC862 (0x%08x)", k);
153 printf (" at %s MHz:", strmhz (buf, clock));
155 printf (" %u kB I-Cache", checkicache () >> 10);
156 printf (" %u kB D-Cache", checkdcache () >> 10);
158 /* lets check and see if we're running on a 862T (or P?) */
160 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
161 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
162 printf (" FEC present");
174 #elif defined(CONFIG_MPC823)
176 static int check_CPU (long clock, uint pvr, uint immr)
178 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
183 /* the highest 16 bits should be 0x0050 for a 8xx */
185 if ((pvr >> 16) != 0x0050)
188 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
193 case 0x20000000: suf = "0"; break;
194 case 0x20010000: suf = "0.1"; break;
195 case 0x20020000: suf = "Z2/3"; break;
196 case 0x20020001: suf = "Z3"; break;
197 case 0x21000000: suf = "A"; break;
198 case 0x21010000: suf = "B"; m = 1; break;
199 case 0x21010001: suf = "B2"; m = 1; break;
201 case 0x24010000: suf = NULL;
202 puts ("PPC823EZTnnB2");
207 printf ("unknown MPC823 (0x%08x)", k);
211 printf ("PPC823ZTnn%s", suf);
213 printf (" at %s MHz:", strmhz (buf, clock));
215 printf (" %u kB I-Cache", checkicache () >> 10);
216 printf (" %u kB D-Cache", checkdcache () >> 10);
218 /* lets check and see if we're running on a 860T (or P?) */
220 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
221 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
222 puts (" FEC present");
234 #elif defined(CONFIG_MPC850)
236 static int check_CPU (long clock, uint pvr, uint immr)
238 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
242 /* the highest 16 bits should be 0x0050 for a 8xx */
244 if ((pvr >> 16) != 0x0050)
247 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
252 printf ("XPC850xxZT");
255 printf ("XPC850xxZTA");
258 printf ("XPC850xxZTB");
262 printf ("XPC850xxZTC");
266 printf ("unknown MPC850 (0x%08x)", k);
268 printf (" at %s MHz:", strmhz (buf, clock));
270 printf (" %u kB I-Cache", checkicache () >> 10);
271 printf (" %u kB D-Cache", checkdcache () >> 10);
273 /* lets check and see if we're running on a 850T (or P?) */
275 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
276 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
277 printf (" FEC present");
291 /* ------------------------------------------------------------------------- */
295 DECLARE_GLOBAL_DATA_PTR;
297 ulong clock = gd->cpu_clk;
298 uint immr = get_immr (0); /* Return full IMMR contents */
299 uint pvr = get_pvr ();
303 /* 850 has PARTNUM 20 */
304 /* 801 has PARTNUM 10 */
305 return check_CPU (clock, pvr, immr);
308 /* ------------------------------------------------------------------------- */
310 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
311 /* the 860 P (plus) has 256 sets of 16 bytes in 4 ways (= 16 kB) */
313 int checkicache (void)
315 volatile immap_t *immap = (immap_t *) CFG_IMMR;
316 volatile memctl8xx_t *memctl = &immap->im_memctl;
317 u32 cacheon = rd_ic_cst () & IDC_ENABLED;
320 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
322 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
327 wr_ic_cst (IDC_UNALL);
328 wr_ic_cst (IDC_INVALL);
329 wr_ic_cst (IDC_DISABLE);
330 __asm__ volatile ("isync");
332 while (!((m = rd_ic_cst ()) & IDC_CERR2)) {
334 wr_ic_cst (IDC_LDLCK);
335 __asm__ volatile ("isync");
338 k += 0x10; /* the number of bytes in a cacheline */
341 wr_ic_cst (IDC_UNALL);
342 wr_ic_cst (IDC_INVALL);
345 wr_ic_cst (IDC_ENABLE);
347 wr_ic_cst (IDC_DISABLE);
349 __asm__ volatile ("isync");
354 /* ------------------------------------------------------------------------- */
356 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
357 /* the 860 P (plus) has 256 sets of 16 bytes in 2 ways (= 8 kB) */
358 /* call with cache disabled */
360 int checkdcache (void)
362 volatile immap_t *immap = (immap_t *) CFG_IMMR;
363 volatile memctl8xx_t *memctl = &immap->im_memctl;
364 u32 cacheon = rd_dc_cst () & IDC_ENABLED;
367 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
369 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
374 wr_dc_cst (IDC_UNALL);
375 wr_dc_cst (IDC_INVALL);
376 wr_dc_cst (IDC_DISABLE);
378 while (!((m = rd_dc_cst ()) & IDC_CERR2)) {
380 wr_dc_cst (IDC_LDLCK);
382 k += 0x10; /* the number of bytes in a cacheline */
385 wr_dc_cst (IDC_UNALL);
386 wr_dc_cst (IDC_INVALL);
389 wr_dc_cst (IDC_ENABLE);
391 wr_dc_cst (IDC_DISABLE);
396 /* ------------------------------------------------------------------------- */
398 void upmconfig (uint upm, uint * table, uint size)
402 volatile immap_t *immap = (immap_t *) CFG_IMMR;
403 volatile memctl8xx_t *memctl = &immap->im_memctl;
405 for (i = 0; i < size; i++) {
406 memctl->memc_mdr = table[i]; /* (16-15) */
407 memctl->memc_mcr = addr | upm; /* (16-16) */
412 /* ------------------------------------------------------------------------- */
414 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
418 volatile immap_t *immap = (immap_t *) CFG_IMMR;
420 immap->im_clkrst.car_plprcr |= PLPRCR_CSR; /* Checkstop Reset enable */
422 /* Interrupts and MMU off */
423 __asm__ volatile ("mtspr 81, 0");
424 __asm__ volatile ("mfmsr %0":"=r" (msr));
427 __asm__ volatile ("mtmsr %0"::"r" (msr));
430 * Trying to execute the next instruction at a non-existing address
431 * should cause a machine check, resulting in reset
433 #ifdef CFG_RESET_ADDRESS
434 addr = CFG_RESET_ADDRESS;
437 * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
438 * - sizeof (ulong) is usually a valid address. Better pick an address
439 * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
440 * "(ulong)-1" used to be a good choice for many systems...
442 addr = CFG_MONITOR_BASE - sizeof (ulong);
444 ((void (*)(void)) addr) ();
448 /* ------------------------------------------------------------------------- */
451 * Get timebase clock frequency (like cpu_clk in Hz)
453 * See table 15-5 pp. 15-16, and SCCR[RTSEL] pp. 15-27.
455 unsigned long get_tbclk (void)
457 DECLARE_GLOBAL_DATA_PTR;
459 volatile immap_t *immr = (volatile immap_t *) CFG_IMMR;
460 ulong oscclk, factor;
462 if (immr->im_clkrst.car_sccr & SCCR_TBS) {
463 return (gd->cpu_clk / 16);
466 factor = (((CFG_PLPRCR) & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT) + 1;
468 oscclk = gd->cpu_clk / factor;
470 if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
473 return (oscclk / 16);
476 /* ------------------------------------------------------------------------- */
478 #if defined(CONFIG_WATCHDOG)
479 void watchdog_reset (void)
481 int re_enable = disable_interrupts ();
483 reset_8xx_watchdog ((immap_t *) CFG_IMMR);
485 enable_interrupts ();
488 void reset_8xx_watchdog (volatile immap_t * immr)
490 # if defined(CONFIG_LWMON)
492 * The LWMON board uses a MAX6301 Watchdog
493 * with the trigger pin connected to port PA.7
495 * (The old board version used a MAX706TESA Watchdog, which
496 * had to be handled exactly the same.)
498 # define WATCHDOG_BIT 0x0100
499 immr->im_ioport.iop_papar &= ~(WATCHDOG_BIT); /* GPIO */
500 immr->im_ioport.iop_padir |= WATCHDOG_BIT; /* Output */
501 immr->im_ioport.iop_paodr &= ~(WATCHDOG_BIT); /* active output */
503 immr->im_ioport.iop_padat ^= WATCHDOG_BIT; /* Toggle WDI */
506 * All other boards use the MPC8xx Internal Watchdog
508 immr->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
509 immr->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
510 # endif /* CONFIG_LWMON */
513 #endif /* CONFIG_WATCHDOG */
515 /* ------------------------------------------------------------------------- */