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_MPC86x) || defined(CONFIG_MPC855)) && \
46 !defined(CONFIG_MPC862))
48 # if defined(CONFIG_MPC855)
49 # define ID_STR "PC855"
50 # elif defined(CONFIG_MPC852T)
51 # define ID_STR "PC852T"
52 # elif defined(CONFIG_MPC859T)
53 # define ID_STR "PC859T"
54 # elif defined(CONFIG_MPC859DSL)
55 # define ID_STR "PC859DSL"
56 # elif defined(CONFIG_MPC860P)
57 # define ID_STR "PC860P"
58 # elif defined(CONFIG_MPC866T)
59 # define ID_STR "PC866T"
61 # define ID_STR "PC86x" /* unknown 86x chip */
64 static int check_CPU (long clock, uint pvr, uint immr)
66 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
73 /* the highest 16 bits should be 0x0050 for a 860 */
75 if ((pvr >> 16) != 0x0050)
78 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
82 #ifdef CONFIG_MPC866_et_al
83 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
84 case 0x08000003: pre = 'M'; suf = ""; m = 1; break;
86 case 0x00020001: pre = 'p'; suf = ""; break;
87 case 0x00030001: suf = ""; break;
88 case 0x00120003: suf = "A"; break;
89 case 0x00130003: suf = "A3"; break;
91 case 0x00200004: suf = "B"; break;
93 case 0x00300004: suf = "C"; break;
94 case 0x00310004: suf = "C1"; m = 1; break;
96 case 0x00200064: mid = "SR"; suf = "B"; break;
97 case 0x00300065: mid = "SR"; suf = "C"; break;
98 case 0x00310065: mid = "SR"; suf = "C1"; m = 1; break;
99 case 0x05010000: suf = "D3"; m = 1; break;
100 case 0x05020000: suf = "D4"; m = 1; break;
101 case 0x08000003: suf = ""; m = 1; break;
102 /* this value is not documented anywhere */
103 case 0x40000000: pre = 'P'; suf = "D"; m = 1; break;
106 default: suf = NULL; break;
110 printf ("%c" ID_STR "%sZPnn%s", pre, mid, suf);
112 printf ("unknown M" ID_STR " (0x%08x)", k);
114 printf (" at %s MHz:", strmhz (buf, clock));
116 printf (" %u kB I-Cache", checkicache () >> 10);
117 printf (" %u kB D-Cache", checkdcache () >> 10);
119 /* do we have a FEC (860T/P or 852/859/866)? */
121 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
122 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
123 printf (" FEC present");
133 if(clock != measure_gclk()) {
134 printf ("clock %ldHz != %dHz\n", clock, measure_gclk());
141 #elif defined(CONFIG_MPC862)
143 static int check_CPU (long clock, uint pvr, uint immr)
145 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
152 /* the highest 16 bits should be 0x0050 for a 8xx */
154 if ((pvr >> 16) != 0x0050)
157 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
162 /* this value is not documented anywhere */
163 case 0x06000000: mid = "P"; suf = "0"; break;
164 case 0x06010001: mid = "P"; suf = "A"; m = 1; break;
165 case 0x07000003: mid = "P"; suf = "B"; m = 1; break;
166 default: suf = NULL; break;
170 printf ("%cPC862%sZPnn%s", pre, mid, suf);
172 printf ("unknown MPC862 (0x%08x)", k);
174 printf (" at %s MHz:", strmhz (buf, clock));
176 printf (" %u kB I-Cache", checkicache () >> 10);
177 printf (" %u kB D-Cache", checkdcache () >> 10);
179 /* lets check and see if we're running on a 862T (or P?) */
181 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
182 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
183 printf (" FEC present");
195 #elif defined(CONFIG_MPC823)
197 static int check_CPU (long clock, uint pvr, uint immr)
199 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
204 /* the highest 16 bits should be 0x0050 for a 8xx */
206 if ((pvr >> 16) != 0x0050)
209 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
214 case 0x20000000: suf = "0"; break;
215 case 0x20010000: suf = "0.1"; break;
216 case 0x20020000: suf = "Z2/3"; break;
217 case 0x20020001: suf = "Z3"; break;
218 case 0x21000000: suf = "A"; break;
219 case 0x21010000: suf = "B"; m = 1; break;
220 case 0x21010001: suf = "B2"; m = 1; break;
222 case 0x24010000: suf = NULL;
223 puts ("PPC823EZTnnB2");
228 printf ("unknown MPC823 (0x%08x)", k);
232 printf ("PPC823ZTnn%s", suf);
234 printf (" at %s MHz:", strmhz (buf, clock));
236 printf (" %u kB I-Cache", checkicache () >> 10);
237 printf (" %u kB D-Cache", checkdcache () >> 10);
239 /* lets check and see if we're running on a 860T (or P?) */
241 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
242 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
243 puts (" FEC present");
255 #elif defined(CONFIG_MPC850)
257 static int check_CPU (long clock, uint pvr, uint immr)
259 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
263 /* the highest 16 bits should be 0x0050 for a 8xx */
265 if ((pvr >> 16) != 0x0050)
268 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
273 printf ("XPC850xxZT");
276 printf ("XPC850xxZTA");
279 printf ("XPC850xxZTB");
283 printf ("XPC850xxZTC");
287 printf ("unknown MPC850 (0x%08x)", k);
289 printf (" at %s MHz:", strmhz (buf, clock));
291 printf (" %u kB I-Cache", checkicache () >> 10);
292 printf (" %u kB D-Cache", checkdcache () >> 10);
294 /* lets check and see if we're running on a 850T (or P?) */
296 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
297 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
298 printf (" FEC present");
312 /* ------------------------------------------------------------------------- */
316 DECLARE_GLOBAL_DATA_PTR;
318 ulong clock = gd->cpu_clk;
319 uint immr = get_immr (0); /* Return full IMMR contents */
320 uint pvr = get_pvr ();
324 /* 850 has PARTNUM 20 */
325 /* 801 has PARTNUM 10 */
326 return check_CPU (clock, pvr, immr);
329 /* ------------------------------------------------------------------------- */
331 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
332 /* the 860 P (plus) has 256 sets of 16 bytes in 4 ways (= 16 kB) */
334 int checkicache (void)
336 volatile immap_t *immap = (immap_t *) CFG_IMMR;
337 volatile memctl8xx_t *memctl = &immap->im_memctl;
338 u32 cacheon = rd_ic_cst () & IDC_ENABLED;
341 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
343 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
348 wr_ic_cst (IDC_UNALL);
349 wr_ic_cst (IDC_INVALL);
350 wr_ic_cst (IDC_DISABLE);
351 __asm__ volatile ("isync");
353 while (!((m = rd_ic_cst ()) & IDC_CERR2)) {
355 wr_ic_cst (IDC_LDLCK);
356 __asm__ volatile ("isync");
359 k += 0x10; /* the number of bytes in a cacheline */
362 wr_ic_cst (IDC_UNALL);
363 wr_ic_cst (IDC_INVALL);
366 wr_ic_cst (IDC_ENABLE);
368 wr_ic_cst (IDC_DISABLE);
370 __asm__ volatile ("isync");
375 /* ------------------------------------------------------------------------- */
377 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
378 /* the 860 P (plus) has 256 sets of 16 bytes in 2 ways (= 8 kB) */
379 /* call with cache disabled */
381 int checkdcache (void)
383 volatile immap_t *immap = (immap_t *) CFG_IMMR;
384 volatile memctl8xx_t *memctl = &immap->im_memctl;
385 u32 cacheon = rd_dc_cst () & IDC_ENABLED;
388 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
390 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
395 wr_dc_cst (IDC_UNALL);
396 wr_dc_cst (IDC_INVALL);
397 wr_dc_cst (IDC_DISABLE);
399 while (!((m = rd_dc_cst ()) & IDC_CERR2)) {
401 wr_dc_cst (IDC_LDLCK);
403 k += 0x10; /* the number of bytes in a cacheline */
406 wr_dc_cst (IDC_UNALL);
407 wr_dc_cst (IDC_INVALL);
410 wr_dc_cst (IDC_ENABLE);
412 wr_dc_cst (IDC_DISABLE);
417 /* ------------------------------------------------------------------------- */
419 void upmconfig (uint upm, uint * table, uint size)
423 volatile immap_t *immap = (immap_t *) CFG_IMMR;
424 volatile memctl8xx_t *memctl = &immap->im_memctl;
426 for (i = 0; i < size; i++) {
427 memctl->memc_mdr = table[i]; /* (16-15) */
428 memctl->memc_mcr = addr | upm; /* (16-16) */
433 /* ------------------------------------------------------------------------- */
435 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
439 volatile immap_t *immap = (immap_t *) CFG_IMMR;
441 immap->im_clkrst.car_plprcr |= PLPRCR_CSR; /* Checkstop Reset enable */
443 /* Interrupts and MMU off */
444 __asm__ volatile ("mtspr 81, 0");
445 __asm__ volatile ("mfmsr %0":"=r" (msr));
448 __asm__ volatile ("mtmsr %0"::"r" (msr));
451 * Trying to execute the next instruction at a non-existing address
452 * should cause a machine check, resulting in reset
454 #ifdef CFG_RESET_ADDRESS
455 addr = CFG_RESET_ADDRESS;
458 * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
459 * - sizeof (ulong) is usually a valid address. Better pick an address
460 * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
461 * "(ulong)-1" used to be a good choice for many systems...
463 addr = CFG_MONITOR_BASE - sizeof (ulong);
465 ((void (*)(void)) addr) ();
469 /* ------------------------------------------------------------------------- */
472 * Get timebase clock frequency (like cpu_clk in Hz)
474 * See table 15-5 pp. 15-16, and SCCR[RTSEL] pp. 15-27.
476 unsigned long get_tbclk (void)
478 DECLARE_GLOBAL_DATA_PTR;
480 volatile immap_t *immr = (volatile immap_t *) CFG_IMMR;
481 ulong oscclk, factor;
483 if (immr->im_clkrst.car_sccr & SCCR_TBS) {
484 return (gd->cpu_clk / 16);
486 #define PLPRCR_val(a) (((CFG_PLPRCR) & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
487 #ifdef CONFIG_MPC866_et_al
491 factor = -----------------
495 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN)/(PLPRCR_val(MFD)+1))/
496 (PLPRCR_val(PDF)+1) / (1<<PLPRCR_val(S));
498 factor = PLPRCR_val(MF)+1;
501 oscclk = gd->cpu_clk / factor;
503 if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
506 return (oscclk / 16);
509 /* ------------------------------------------------------------------------- */
511 #if defined(CONFIG_WATCHDOG)
512 void watchdog_reset (void)
514 int re_enable = disable_interrupts ();
516 reset_8xx_watchdog ((immap_t *) CFG_IMMR);
518 enable_interrupts ();
521 void reset_8xx_watchdog (volatile immap_t * immr)
523 # if defined(CONFIG_LWMON)
525 * The LWMON board uses a MAX6301 Watchdog
526 * with the trigger pin connected to port PA.7
528 * (The old board version used a MAX706TESA Watchdog, which
529 * had to be handled exactly the same.)
531 # define WATCHDOG_BIT 0x0100
532 immr->im_ioport.iop_papar &= ~(WATCHDOG_BIT); /* GPIO */
533 immr->im_ioport.iop_padir |= WATCHDOG_BIT; /* Output */
534 immr->im_ioport.iop_paodr &= ~(WATCHDOG_BIT); /* active output */
536 immr->im_ioport.iop_padat ^= WATCHDOG_BIT; /* Toggle WDI */
539 * All other boards use the MPC8xx Internal Watchdog
541 immr->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
542 immr->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
543 # endif /* CONFIG_LWMON */
546 #endif /* CONFIG_WATCHDOG */
548 /* ------------------------------------------------------------------------- */