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 DECLARE_GLOBAL_DATA_PTR;
44 static char *cpu_warning = "\n " \
45 "*** Warning: CPU Core has Silicon Bugs -- Check the Errata ***";
47 #if ((defined(CONFIG_MPC86x) || defined(CONFIG_MPC855)) && \
48 !defined(CONFIG_MPC862))
50 static int check_CPU (long clock, uint pvr, uint immr)
53 # if defined(CONFIG_MPC855)
55 # elif defined(CONFIG_MPC860P)
60 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
67 /* the highest 16 bits should be 0x0050 for a 860 */
69 if ((pvr >> 16) != 0x0050)
72 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
77 * Some boards use sockets so different CPUs can be used.
78 * We have to check chip version in run time.
81 case 0x00020001: pre = 'P'; break;
82 case 0x00030001: break;
83 case 0x00120003: suf = "A"; break;
84 case 0x00130003: suf = "A3"; break;
86 case 0x00200004: suf = "B"; break;
88 case 0x00300004: suf = "C"; break;
89 case 0x00310004: suf = "C1"; m = 1; break;
91 case 0x00200064: mid = "SR"; suf = "B"; break;
92 case 0x00300065: mid = "SR"; suf = "C"; break;
93 case 0x00310065: mid = "SR"; suf = "C1"; m = 1; break;
94 case 0x05010000: suf = "D3"; m = 1; break;
95 case 0x05020000: suf = "D4"; m = 1; break;
96 /* this value is not documented anywhere */
97 case 0x40000000: pre = 'P'; suf = "D"; m = 1; break;
98 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
99 case 0x08010004: /* Rev. A.0 */
102 case 0x08000003: /* Rev. 0.3 */
106 # if defined(CONFIG_MPC852T)
108 # elif defined(CONFIG_MPC859T)
110 # elif defined(CONFIG_MPC859DSL)
112 # elif defined(CONFIG_MPC866T)
115 "PC866x"; /* Unknown chip from MPC866 family */
118 case 0x09000000: pre = 'M'; mid = suf = ""; m = 1;
120 id_str = "PC885"; /* 870/875/880/885 */
123 default: suf = NULL; break;
127 id_str = "PC86x"; /* Unknown 86x chip */
129 printf ("%c%s%sZPnn%s", pre, id_str, mid, suf);
131 printf ("unknown M%s (0x%08x)", id_str, k);
134 #if defined(CFG_8xx_CPUCLK_MIN) && defined(CFG_8xx_CPUCLK_MAX)
135 printf (" at %s MHz [%d.%d...%d.%d MHz]\n ",
137 CFG_8xx_CPUCLK_MIN / 1000000,
138 ((CFG_8xx_CPUCLK_MIN % 1000000) + 50000) / 100000,
139 CFG_8xx_CPUCLK_MAX / 1000000,
140 ((CFG_8xx_CPUCLK_MAX % 1000000) + 50000) / 100000
143 printf (" at %s MHz: ", strmhz (buf, clock));
145 printf ("%u kB I-Cache %u kB D-Cache",
146 checkicache () >> 10,
150 /* do we have a FEC (860T/P or 852/859/866/885)? */
152 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
153 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
154 printf (" FEC present");
164 if(clock != measure_gclk()) {
165 printf ("clock %ldHz != %dHz\n", clock, measure_gclk());
172 #elif defined(CONFIG_MPC862)
174 static int check_CPU (long clock, uint pvr, uint immr)
176 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 /* this value is not documented anywhere */
194 case 0x06000000: mid = "P"; suf = "0"; break;
195 case 0x06010001: mid = "P"; suf = "A"; m = 1; break;
196 case 0x07000003: mid = "P"; suf = "B"; m = 1; break;
197 default: suf = NULL; break;
200 #ifndef CONFIG_MPC857
202 printf ("%cPC862%sZPnn%s", pre, mid, suf);
204 printf ("unknown MPC862 (0x%08x)", k);
207 printf ("%cPC857TZPnn%s", pre, suf); /* only 857T tested right now! */
209 printf ("unknown MPC857 (0x%08x)", k);
212 printf (" at %s MHz:", strmhz (buf, clock));
214 printf (" %u kB I-Cache", checkicache () >> 10);
215 printf (" %u kB D-Cache", checkdcache () >> 10);
217 /* lets check and see if we're running on a 862T (or P?) */
219 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
220 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
221 printf (" FEC present");
233 #elif defined(CONFIG_MPC823)
235 static int check_CPU (long clock, uint pvr, uint immr)
237 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 case 0x20000000: suf = "0"; break;
253 case 0x20010000: suf = "0.1"; break;
254 case 0x20020000: suf = "Z2/3"; break;
255 case 0x20020001: suf = "Z3"; break;
256 case 0x21000000: suf = "A"; break;
257 case 0x21010000: suf = "B"; m = 1; break;
258 case 0x21010001: suf = "B2"; m = 1; break;
260 case 0x24010000: suf = NULL;
261 puts ("PPC823EZTnnB2");
266 printf ("unknown MPC823 (0x%08x)", k);
270 printf ("PPC823ZTnn%s", suf);
272 printf (" at %s MHz:", strmhz (buf, clock));
274 printf (" %u kB I-Cache", checkicache () >> 10);
275 printf (" %u kB D-Cache", checkdcache () >> 10);
277 /* lets check and see if we're running on a 860T (or P?) */
279 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
280 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
281 puts (" FEC present");
293 #elif defined(CONFIG_MPC850)
295 static int check_CPU (long clock, uint pvr, uint immr)
297 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
301 /* the highest 16 bits should be 0x0050 for a 8xx */
303 if ((pvr >> 16) != 0x0050)
306 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
311 printf ("XPC850xxZT");
314 printf ("XPC850xxZTA");
317 printf ("XPC850xxZTB");
321 printf ("XPC850xxZTC");
325 printf ("unknown MPC850 (0x%08x)", k);
327 printf (" at %s MHz:", strmhz (buf, clock));
329 printf (" %u kB I-Cache", checkicache () >> 10);
330 printf (" %u kB D-Cache", checkdcache () >> 10);
332 /* lets check and see if we're running on a 850T (or P?) */
334 immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
335 if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
336 printf (" FEC present");
350 /* ------------------------------------------------------------------------- */
354 ulong clock = gd->cpu_clk;
355 uint immr = get_immr (0); /* Return full IMMR contents */
356 uint pvr = get_pvr ();
360 /* 850 has PARTNUM 20 */
361 /* 801 has PARTNUM 10 */
362 return check_CPU (clock, pvr, immr);
365 /* ------------------------------------------------------------------------- */
367 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
368 /* the 860 P (plus) has 256 sets of 16 bytes in 4 ways (= 16 kB) */
370 int checkicache (void)
372 volatile immap_t *immap = (immap_t *) CFG_IMMR;
373 volatile memctl8xx_t *memctl = &immap->im_memctl;
374 u32 cacheon = rd_ic_cst () & IDC_ENABLED;
377 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
379 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
384 wr_ic_cst (IDC_UNALL);
385 wr_ic_cst (IDC_INVALL);
386 wr_ic_cst (IDC_DISABLE);
387 __asm__ volatile ("isync");
389 while (!((m = rd_ic_cst ()) & IDC_CERR2)) {
391 wr_ic_cst (IDC_LDLCK);
392 __asm__ volatile ("isync");
395 k += 0x10; /* the number of bytes in a cacheline */
398 wr_ic_cst (IDC_UNALL);
399 wr_ic_cst (IDC_INVALL);
402 wr_ic_cst (IDC_ENABLE);
404 wr_ic_cst (IDC_DISABLE);
406 __asm__ volatile ("isync");
411 /* ------------------------------------------------------------------------- */
413 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
414 /* the 860 P (plus) has 256 sets of 16 bytes in 2 ways (= 8 kB) */
415 /* call with cache disabled */
417 int checkdcache (void)
419 volatile immap_t *immap = (immap_t *) CFG_IMMR;
420 volatile memctl8xx_t *memctl = &immap->im_memctl;
421 u32 cacheon = rd_dc_cst () & IDC_ENABLED;
424 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
426 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
431 wr_dc_cst (IDC_UNALL);
432 wr_dc_cst (IDC_INVALL);
433 wr_dc_cst (IDC_DISABLE);
435 while (!((m = rd_dc_cst ()) & IDC_CERR2)) {
437 wr_dc_cst (IDC_LDLCK);
439 k += 0x10; /* the number of bytes in a cacheline */
442 wr_dc_cst (IDC_UNALL);
443 wr_dc_cst (IDC_INVALL);
446 wr_dc_cst (IDC_ENABLE);
448 wr_dc_cst (IDC_DISABLE);
453 /* ------------------------------------------------------------------------- */
455 void upmconfig (uint upm, uint * table, uint size)
459 volatile immap_t *immap = (immap_t *) CFG_IMMR;
460 volatile memctl8xx_t *memctl = &immap->im_memctl;
462 for (i = 0; i < size; i++) {
463 memctl->memc_mdr = table[i]; /* (16-15) */
464 memctl->memc_mcr = addr | upm; /* (16-16) */
469 /* ------------------------------------------------------------------------- */
473 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
477 volatile immap_t *immap = (immap_t *) CFG_IMMR;
479 immap->im_clkrst.car_plprcr |= PLPRCR_CSR; /* Checkstop Reset enable */
481 /* Interrupts and MMU off */
482 __asm__ volatile ("mtspr 81, 0");
483 __asm__ volatile ("mfmsr %0":"=r" (msr));
486 __asm__ volatile ("mtmsr %0"::"r" (msr));
489 * Trying to execute the next instruction at a non-existing address
490 * should cause a machine check, resulting in reset
492 #ifdef CFG_RESET_ADDRESS
493 addr = CFG_RESET_ADDRESS;
496 * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
497 * - sizeof (ulong) is usually a valid address. Better pick an address
498 * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
499 * "(ulong)-1" used to be a good choice for many systems...
501 addr = CFG_MONITOR_BASE - sizeof (ulong);
503 ((void (*)(void)) addr) ();
507 #else /* CONFIG_LWMON */
510 * On the LWMON board, the MCLR reset input of the PIC's on the board
511 * uses a 47K/1n RC combination which has a 47us time constant. The
512 * low signal on the HRESET pin of the CPU is only 512 clocks = 8 us
513 * and thus too short to reset the external hardware. So we use the
514 * watchdog to reset the board.
516 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
518 /* prevent triggering the watchdog */
519 disable_interrupts ();
521 /* make sure the watchdog is running */
522 reset_8xx_watchdog ((immap_t *) CFG_IMMR);
524 /* wait for watchdog reset */
531 #endif /* CONFIG_LWMON */
533 /* ------------------------------------------------------------------------- */
536 * Get timebase clock frequency (like cpu_clk in Hz)
538 * See sections 14.2 and 14.6 of the User's Manual
540 unsigned long get_tbclk (void)
542 uint immr = get_immr (0); /* Return full IMMR contents */
543 volatile immap_t *immap = (volatile immap_t *)(immr & 0xFFFF0000);
544 ulong oscclk, factor, pll;
546 if (immap->im_clkrst.car_sccr & SCCR_TBS) {
547 return (gd->cpu_clk / 16);
550 pll = immap->im_clkrst.car_plprcr;
552 #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
555 * For newer PQ1 chips (MPC866/87x/88x families), PLL multiplication
556 * factor is calculated as follows:
561 * factor = -----------------
564 * For older chips, it's just MF field of PLPRCR plus one.
566 if ((immr & 0x0FFF) >= MPC8xx_NEW_CLK) { /* MPC866/87x/88x series */
567 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN)/(PLPRCR_val(MFD)+1))/
568 (PLPRCR_val(PDF)+1) / (1<<PLPRCR_val(S));
570 factor = PLPRCR_val(MF)+1;
573 oscclk = gd->cpu_clk / factor;
575 if ((immap->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
578 return (oscclk / 16);
581 /* ------------------------------------------------------------------------- */
583 #if defined(CONFIG_WATCHDOG)
584 void watchdog_reset (void)
586 int re_enable = disable_interrupts ();
588 reset_8xx_watchdog ((immap_t *) CFG_IMMR);
590 enable_interrupts ();
592 #endif /* CONFIG_WATCHDOG */
594 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_LWMON)
596 void reset_8xx_watchdog (volatile immap_t * immr)
598 # if defined(CONFIG_LWMON)
600 * The LWMON board uses a MAX6301 Watchdog
601 * with the trigger pin connected to port PA.7
603 * (The old board version used a MAX706TESA Watchdog, which
604 * had to be handled exactly the same.)
606 # define WATCHDOG_BIT 0x0100
607 immr->im_ioport.iop_papar &= ~(WATCHDOG_BIT); /* GPIO */
608 immr->im_ioport.iop_padir |= WATCHDOG_BIT; /* Output */
609 immr->im_ioport.iop_paodr &= ~(WATCHDOG_BIT); /* active output */
611 immr->im_ioport.iop_padat ^= WATCHDOG_BIT; /* Toggle WDI */
612 # elif defined(CONFIG_KUP4K) || defined(CONFIG_KUP4X)
614 * The KUP4 boards uses a TPS3705 Watchdog
615 * with the trigger pin connected to port PA.5
617 # define WATCHDOG_BIT 0x0400
618 immr->im_ioport.iop_papar &= ~(WATCHDOG_BIT); /* GPIO */
619 immr->im_ioport.iop_padir |= WATCHDOG_BIT; /* Output */
620 immr->im_ioport.iop_paodr &= ~(WATCHDOG_BIT); /* active output */
622 immr->im_ioport.iop_padat ^= WATCHDOG_BIT; /* Toggle WDI */
625 * All other boards use the MPC8xx Internal Watchdog
627 immr->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
628 immr->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
629 # endif /* CONFIG_LWMON */
632 #endif /* CONFIG_WATCHDOG */
634 /* ------------------------------------------------------------------------- */