blob: 2ef13212ec1ec222d973c3ba54a5d3fb46aa8c36 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2000-2002
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/*
25 * m8xx.c
26 *
27 * CPU specific code
28 *
29 * written or collected and sometimes rewritten by
30 * Magnus Damm <damm@bitsmart.com>
31 *
32 * minor modifications by
33 * Wolfgang Denk <wd@denx.de>
34 */
35
36#include <common.h>
37#include <watchdog.h>
38#include <command.h>
39#include <mpc8xx.h>
40#include <asm/cache.h>
41
42static char *cpu_warning = "\n " \
43 "*** Warning: CPU Core has Silicon Bugs -- Check the Errata ***";
44
wdenk2bb11052003-07-17 23:16:40 +000045#if ((defined(CONFIG_MPC86x) || defined(CONFIG_MPC855)) && \
wdenkc6097192002-11-03 00:24:07 +000046 !defined(CONFIG_MPC862))
wdenk2bb11052003-07-17 23:16:40 +000047
48# if defined(CONFIG_MPC855)
wdenkc6097192002-11-03 00:24:07 +000049# define ID_STR "PC855"
wdenk2bb11052003-07-17 23:16:40 +000050# 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"
wdenkc6097192002-11-03 00:24:07 +000060# else
wdenk2bb11052003-07-17 23:16:40 +000061# define ID_STR "PC86x" /* unknown 86x chip */
wdenkc6097192002-11-03 00:24:07 +000062# endif
63
64static int check_CPU (long clock, uint pvr, uint immr)
65{
66 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
67 uint k, m;
68 char buf[32];
69 char pre = 'X';
70 char *mid = "xx";
71 char *suf;
72
73 /* the highest 16 bits should be 0x0050 for a 860 */
74
75 if ((pvr >> 16) != 0x0050)
76 return -1;
77
78 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
79 m = 0;
80
81 switch (k) {
wdenk2bb11052003-07-17 23:16:40 +000082#ifdef CONFIG_MPC866_et_al
wdenk9c53f402003-10-15 23:53:47 +000083 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
wdenk2bb11052003-07-17 23:16:40 +000084 case 0x08000003: pre = 'M'; suf = ""; m = 1; break;
85#else
wdenkc6097192002-11-03 00:24:07 +000086 case 0x00020001: pre = 'p'; suf = ""; break;
87 case 0x00030001: suf = ""; break;
88 case 0x00120003: suf = "A"; break;
89 case 0x00130003: suf = "A3"; break;
90
91 case 0x00200004: suf = "B"; break;
92
93 case 0x00300004: suf = "C"; break;
wdenk2bb11052003-07-17 23:16:40 +000094 case 0x00310004: suf = "C1"; m = 1; break;
wdenkc6097192002-11-03 00:24:07 +000095
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;
wdenk84650f52003-08-30 00:05:50 +0000101 case 0x08000003: suf = ""; m = 1; break;
wdenkc6097192002-11-03 00:24:07 +0000102 /* this value is not documented anywhere */
103 case 0x40000000: pre = 'P'; suf = "D"; m = 1; break;
wdenk2bb11052003-07-17 23:16:40 +0000104#endif
wdenkc6097192002-11-03 00:24:07 +0000105
106 default: suf = NULL; break;
107 }
108
109 if (suf)
110 printf ("%c" ID_STR "%sZPnn%s", pre, mid, suf);
111 else
112 printf ("unknown M" ID_STR " (0x%08x)", k);
113
114 printf (" at %s MHz:", strmhz (buf, clock));
115
116 printf (" %u kB I-Cache", checkicache () >> 10);
117 printf (" %u kB D-Cache", checkdcache () >> 10);
118
wdenk2bb11052003-07-17 23:16:40 +0000119 /* do we have a FEC (860T/P or 852/859/866)? */
wdenkc6097192002-11-03 00:24:07 +0000120
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");
124 }
125
126 if (!m) {
127 puts (cpu_warning);
128 }
129
130 putc ('\n');
131
wdenk2bb11052003-07-17 23:16:40 +0000132#ifdef DEBUG
wdenk9c53f402003-10-15 23:53:47 +0000133 if(clock != measure_gclk()) {
134 printf ("clock %ldHz != %dHz\n", clock, measure_gclk());
135 }
wdenk2bb11052003-07-17 23:16:40 +0000136#endif
137
wdenkc6097192002-11-03 00:24:07 +0000138 return 0;
139}
140
141#elif defined(CONFIG_MPC862)
142
143static int check_CPU (long clock, uint pvr, uint immr)
144{
145 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
146 uint k, m;
147 char buf[32];
148 char pre = 'X';
149 char *mid = "xx";
150 char *suf;
151
152 /* the highest 16 bits should be 0x0050 for a 8xx */
153
154 if ((pvr >> 16) != 0x0050)
155 return -1;
156
157 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
158 m = 0;
159
160 switch (k) {
161
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;
167 }
168
169 if (suf)
170 printf ("%cPC862%sZPnn%s", pre, mid, suf);
171 else
172 printf ("unknown MPC862 (0x%08x)", k);
173
174 printf (" at %s MHz:", strmhz (buf, clock));
175
176 printf (" %u kB I-Cache", checkicache () >> 10);
177 printf (" %u kB D-Cache", checkdcache () >> 10);
178
179 /* lets check and see if we're running on a 862T (or P?) */
180
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");
184 }
185
186 if (!m) {
187 puts (cpu_warning);
188 }
189
190 putc ('\n');
191
192 return 0;
193}
194
195#elif defined(CONFIG_MPC823)
196
197static int check_CPU (long clock, uint pvr, uint immr)
198{
199 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
200 uint k, m;
201 char buf[32];
202 char *suf;
203
204 /* the highest 16 bits should be 0x0050 for a 8xx */
205
206 if ((pvr >> 16) != 0x0050)
207 return -1;
208
209 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
210 m = 0;
211
212 switch (k) {
213 /* MPC823 */
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;
221 /* MPC823E */
222 case 0x24010000: suf = NULL;
223 puts ("PPC823EZTnnB2");
224 m = 1;
225 break;
226 default:
227 suf = NULL;
228 printf ("unknown MPC823 (0x%08x)", k);
229 break;
230 }
231 if (suf)
232 printf ("PPC823ZTnn%s", suf);
233
234 printf (" at %s MHz:", strmhz (buf, clock));
235
236 printf (" %u kB I-Cache", checkicache () >> 10);
237 printf (" %u kB D-Cache", checkdcache () >> 10);
238
239 /* lets check and see if we're running on a 860T (or P?) */
240
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");
244 }
245
246 if (!m) {
247 puts (cpu_warning);
248 }
249
250 putc ('\n');
251
252 return 0;
253}
254
255#elif defined(CONFIG_MPC850)
256
257static int check_CPU (long clock, uint pvr, uint immr)
258{
259 volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
260 uint k, m;
261 char buf[32];
262
263 /* the highest 16 bits should be 0x0050 for a 8xx */
264
265 if ((pvr >> 16) != 0x0050)
266 return -1;
267
268 k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
269 m = 0;
270
271 switch (k) {
272 case 0x20020001:
273 printf ("XPC850xxZT");
274 break;
275 case 0x21000065:
276 printf ("XPC850xxZTA");
277 break;
278 case 0x21010067:
279 printf ("XPC850xxZTB");
280 m = 1;
281 break;
282 case 0x21020068:
283 printf ("XPC850xxZTC");
284 m = 1;
285 break;
286 default:
287 printf ("unknown MPC850 (0x%08x)", k);
288 }
289 printf (" at %s MHz:", strmhz (buf, clock));
290
291 printf (" %u kB I-Cache", checkicache () >> 10);
292 printf (" %u kB D-Cache", checkdcache () >> 10);
293
294 /* lets check and see if we're running on a 850T (or P?) */
295
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");
299 }
300
301 if (!m) {
302 puts (cpu_warning);
303 }
304
305 putc ('\n');
306
307 return 0;
308}
309#else
310#error CPU undefined
311#endif
312/* ------------------------------------------------------------------------- */
313
314int checkcpu (void)
315{
316 DECLARE_GLOBAL_DATA_PTR;
317
318 ulong clock = gd->cpu_clk;
319 uint immr = get_immr (0); /* Return full IMMR contents */
320 uint pvr = get_pvr ();
321
322 puts ("CPU: ");
323
324 /* 850 has PARTNUM 20 */
325 /* 801 has PARTNUM 10 */
326 return check_CPU (clock, pvr, immr);
327}
328
329/* ------------------------------------------------------------------------- */
330/* L1 i-cache */
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) */
333
334int checkicache (void)
335{
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;
339
wdenk2bb11052003-07-17 23:16:40 +0000340#ifdef CONFIG_IP86x
wdenkc6097192002-11-03 00:24:07 +0000341 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
342#else
343 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
344#endif
345 u32 m;
346 u32 lines = -1;
347
348 wr_ic_cst (IDC_UNALL);
349 wr_ic_cst (IDC_INVALL);
350 wr_ic_cst (IDC_DISABLE);
351 __asm__ volatile ("isync");
352
353 while (!((m = rd_ic_cst ()) & IDC_CERR2)) {
354 wr_ic_adr (k);
355 wr_ic_cst (IDC_LDLCK);
356 __asm__ volatile ("isync");
357
358 lines++;
359 k += 0x10; /* the number of bytes in a cacheline */
360 }
361
362 wr_ic_cst (IDC_UNALL);
363 wr_ic_cst (IDC_INVALL);
364
365 if (cacheon)
366 wr_ic_cst (IDC_ENABLE);
367 else
368 wr_ic_cst (IDC_DISABLE);
369
370 __asm__ volatile ("isync");
371
372 return lines << 4;
373};
374
375/* ------------------------------------------------------------------------- */
376/* L1 d-cache */
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 */
380
381int checkdcache (void)
382{
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;
386
wdenk2bb11052003-07-17 23:16:40 +0000387#ifdef CONFIG_IP86x
wdenkc6097192002-11-03 00:24:07 +0000388 u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
389#else
390 u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
391#endif
392 u32 m;
393 u32 lines = -1;
394
395 wr_dc_cst (IDC_UNALL);
396 wr_dc_cst (IDC_INVALL);
397 wr_dc_cst (IDC_DISABLE);
398
399 while (!((m = rd_dc_cst ()) & IDC_CERR2)) {
400 wr_dc_adr (k);
401 wr_dc_cst (IDC_LDLCK);
402 lines++;
403 k += 0x10; /* the number of bytes in a cacheline */
404 }
405
406 wr_dc_cst (IDC_UNALL);
407 wr_dc_cst (IDC_INVALL);
408
409 if (cacheon)
410 wr_dc_cst (IDC_ENABLE);
411 else
412 wr_dc_cst (IDC_DISABLE);
413
414 return lines << 4;
415};
416
417/* ------------------------------------------------------------------------- */
418
419void upmconfig (uint upm, uint * table, uint size)
420{
421 uint i;
422 uint addr = 0;
423 volatile immap_t *immap = (immap_t *) CFG_IMMR;
424 volatile memctl8xx_t *memctl = &immap->im_memctl;
425
426 for (i = 0; i < size; i++) {
427 memctl->memc_mdr = table[i]; /* (16-15) */
428 memctl->memc_mcr = addr | upm; /* (16-16) */
429 addr++;
430 }
431}
432
433/* ------------------------------------------------------------------------- */
434
wdenk57b2d802003-06-27 21:31:46 +0000435int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenkc6097192002-11-03 00:24:07 +0000436{
437 ulong msr, addr;
438
439 volatile immap_t *immap = (immap_t *) CFG_IMMR;
440
441 immap->im_clkrst.car_plprcr |= PLPRCR_CSR; /* Checkstop Reset enable */
442
443 /* Interrupts and MMU off */
444 __asm__ volatile ("mtspr 81, 0");
445 __asm__ volatile ("mfmsr %0":"=r" (msr));
446
447 msr &= ~0x1030;
448 __asm__ volatile ("mtmsr %0"::"r" (msr));
449
450 /*
451 * Trying to execute the next instruction at a non-existing address
452 * should cause a machine check, resulting in reset
453 */
454#ifdef CFG_RESET_ADDRESS
455 addr = CFG_RESET_ADDRESS;
456#else
457 /*
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...
462 */
463 addr = CFG_MONITOR_BASE - sizeof (ulong);
464#endif
465 ((void (*)(void)) addr) ();
466 return 1;
467}
468
469/* ------------------------------------------------------------------------- */
470
471/*
472 * Get timebase clock frequency (like cpu_clk in Hz)
473 *
474 * See table 15-5 pp. 15-16, and SCCR[RTSEL] pp. 15-27.
475 */
476unsigned long get_tbclk (void)
477{
478 DECLARE_GLOBAL_DATA_PTR;
479
480 volatile immap_t *immr = (volatile immap_t *) CFG_IMMR;
481 ulong oscclk, factor;
482
483 if (immr->im_clkrst.car_sccr & SCCR_TBS) {
484 return (gd->cpu_clk / 16);
485 }
wdenk2bb11052003-07-17 23:16:40 +0000486#define PLPRCR_val(a) (((CFG_PLPRCR) & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
487#ifdef CONFIG_MPC866_et_al
wdenk9c53f402003-10-15 23:53:47 +0000488 /* MFN
489 MFI + -------
490 MFD + 1
491 factor = -----------------
492 (PDF + 1) * 2^S
493 */
wdenkc6097192002-11-03 00:24:07 +0000494
wdenk2bb11052003-07-17 23:16:40 +0000495 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN)/(PLPRCR_val(MFD)+1))/
wdenk9c53f402003-10-15 23:53:47 +0000496 (PLPRCR_val(PDF)+1) / (1<<PLPRCR_val(S));
wdenk2bb11052003-07-17 23:16:40 +0000497#else
498 factor = PLPRCR_val(MF)+1;
499#endif
wdenkc6097192002-11-03 00:24:07 +0000500
501 oscclk = gd->cpu_clk / factor;
502
503 if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
504 return (oscclk / 4);
505 }
506 return (oscclk / 16);
507}
508
509/* ------------------------------------------------------------------------- */
510
511#if defined(CONFIG_WATCHDOG)
512void watchdog_reset (void)
513{
514 int re_enable = disable_interrupts ();
515
516 reset_8xx_watchdog ((immap_t *) CFG_IMMR);
517 if (re_enable)
518 enable_interrupts ();
519}
520
521void reset_8xx_watchdog (volatile immap_t * immr)
522{
523# if defined(CONFIG_LWMON)
524 /*
525 * The LWMON board uses a MAX6301 Watchdog
526 * with the trigger pin connected to port PA.7
527 *
528 * (The old board version used a MAX706TESA Watchdog, which
529 * had to be handled exactly the same.)
530 */
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 */
535
536 immr->im_ioport.iop_padat ^= WATCHDOG_BIT; /* Toggle WDI */
537# else
538 /*
539 * All other boards use the MPC8xx Internal Watchdog
540 */
541 immr->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
542 immr->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
543# endif /* CONFIG_LWMON */
544}
545
546#endif /* CONFIG_WATCHDOG */
547
548/* ------------------------------------------------------------------------- */