]> git.sur5r.net Git - u-boot/blob - cpu/mpc8xx/cpu.c
* Patch by Martin Krause, 17 Jul 2003:
[u-boot] / cpu / mpc8xx / cpu.c
1 /*
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
42 static char *cpu_warning = "\n         " \
43         "*** Warning: CPU Core has Silicon Bugs -- Check the Errata ***";
44
45 #if ((defined(CONFIG_MPC86x) || defined(CONFIG_MPC855)) && \
46      !defined(CONFIG_MPC862))
47
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"
60 # else
61 #  define       ID_STR  "PC86x" /* unknown 86x chip */
62 # endif
63
64 static 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) {
82 #ifdef CONFIG_MPC866_et_al
83                 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
84         case 0x08000003: pre = 'M'; suf = ""; m = 1; break;
85 #else
86         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;
94         case 0x00310004: suf = "C1"; m = 1; break;
95
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                 /* this value is not documented anywhere */
102         case 0x40000000: pre = 'P'; suf = "D"; m = 1; break;
103 #endif
104
105         default: suf = NULL; break;
106         }
107
108         if (suf)
109                 printf ("%c" ID_STR "%sZPnn%s", pre, mid, suf);
110         else
111                 printf ("unknown M" ID_STR " (0x%08x)", k);
112
113         printf (" at %s MHz:", strmhz (buf, clock));
114
115         printf (" %u kB I-Cache", checkicache () >> 10);
116         printf (" %u kB D-Cache", checkdcache () >> 10);
117
118         /* do we have a FEC (860T/P or 852/859/866)? */
119
120         immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
121         if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
122                 printf (" FEC present");
123         }
124
125         if (!m) {
126                 puts (cpu_warning);
127         }
128
129         putc ('\n');
130
131 #ifdef DEBUG
132         if(clock != measure_gclk()) {
133             printf ("clock %ldHz != %dHz\n", clock, measure_gclk());
134         }
135 #endif
136
137         return 0;
138 }
139
140 #elif defined(CONFIG_MPC862)
141
142 static int check_CPU (long clock, uint pvr, uint immr)
143 {
144         volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
145         uint k, m;
146         char buf[32];
147         char pre = 'X';
148         char *mid = "xx";
149         char *suf;
150
151         /* the highest 16 bits should be 0x0050 for a 8xx */
152
153         if ((pvr >> 16) != 0x0050)
154                 return -1;
155
156         k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
157         m = 0;
158
159         switch (k) {
160
161                 /* this value is not documented anywhere */
162         case 0x06000000: mid = "P"; suf = "0"; break;
163         case 0x06010001: mid = "P"; suf = "A"; m = 1; break;
164         case 0x07000003: mid = "P"; suf = "B"; m = 1; break;
165         default: suf = NULL; break;
166         }
167
168         if (suf)
169                 printf ("%cPC862%sZPnn%s", pre, mid, suf);
170         else
171                 printf ("unknown MPC862 (0x%08x)", k);
172
173         printf (" at %s MHz:", strmhz (buf, clock));
174
175         printf (" %u kB I-Cache", checkicache () >> 10);
176         printf (" %u kB D-Cache", checkdcache () >> 10);
177
178         /* lets check and see if we're running on a 862T (or P?) */
179
180         immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
181         if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
182                 printf (" FEC present");
183         }
184
185         if (!m) {
186                 puts (cpu_warning);
187         }
188
189         putc ('\n');
190
191         return 0;
192 }
193
194 #elif defined(CONFIG_MPC823)
195
196 static int check_CPU (long clock, uint pvr, uint immr)
197 {
198         volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
199         uint k, m;
200         char buf[32];
201         char *suf;
202
203         /* the highest 16 bits should be 0x0050 for a 8xx */
204
205         if ((pvr >> 16) != 0x0050)
206                 return -1;
207
208         k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
209         m = 0;
210
211         switch (k) {
212                 /* MPC823 */
213         case 0x20000000: suf = "0"; break;
214         case 0x20010000: suf = "0.1"; break;
215         case 0x20020000: suf = "Z2/3"; break;
216         case 0x20020001: suf = "Z3"; break;
217         case 0x21000000: suf = "A"; break;
218         case 0x21010000: suf = "B"; m = 1; break;
219         case 0x21010001: suf = "B2"; m = 1; break;
220                 /* MPC823E */
221         case 0x24010000: suf = NULL;
222                         puts ("PPC823EZTnnB2");
223                         m = 1;
224                         break;
225         default:
226                         suf = NULL;
227                         printf ("unknown MPC823 (0x%08x)", k);
228                         break;
229         }
230         if (suf)
231                 printf ("PPC823ZTnn%s", suf);
232
233         printf (" at %s MHz:", strmhz (buf, clock));
234
235         printf (" %u kB I-Cache", checkicache () >> 10);
236         printf (" %u kB D-Cache", checkdcache () >> 10);
237
238         /* lets check and see if we're running on a 860T (or P?) */
239
240         immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
241         if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
242                 puts (" FEC present");
243         }
244
245         if (!m) {
246                 puts (cpu_warning);
247         }
248
249         putc ('\n');
250
251         return 0;
252 }
253
254 #elif defined(CONFIG_MPC850)
255
256 static int check_CPU (long clock, uint pvr, uint immr)
257 {
258         volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
259         uint k, m;
260         char buf[32];
261
262         /* the highest 16 bits should be 0x0050 for a 8xx */
263
264         if ((pvr >> 16) != 0x0050)
265                 return -1;
266
267         k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
268         m = 0;
269
270         switch (k) {
271         case 0x20020001:
272                 printf ("XPC850xxZT");
273                 break;
274         case 0x21000065:
275                 printf ("XPC850xxZTA");
276                 break;
277         case 0x21010067:
278                 printf ("XPC850xxZTB");
279                 m = 1;
280                 break;
281         case 0x21020068:
282                 printf ("XPC850xxZTC");
283                 m = 1;
284                 break;
285         default:
286                 printf ("unknown MPC850 (0x%08x)", k);
287         }
288         printf (" at %s MHz:", strmhz (buf, clock));
289
290         printf (" %u kB I-Cache", checkicache () >> 10);
291         printf (" %u kB D-Cache", checkdcache () >> 10);
292
293         /* lets check and see if we're running on a 850T (or P?) */
294
295         immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
296         if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
297                 printf (" FEC present");
298         }
299
300         if (!m) {
301                 puts (cpu_warning);
302         }
303
304         putc ('\n');
305
306         return 0;
307 }
308 #else
309 #error CPU undefined
310 #endif
311 /* ------------------------------------------------------------------------- */
312
313 int checkcpu (void)
314 {
315         DECLARE_GLOBAL_DATA_PTR;
316
317         ulong clock = gd->cpu_clk;
318         uint immr = get_immr (0);       /* Return full IMMR contents */
319         uint pvr = get_pvr ();
320
321         puts ("CPU:   ");
322
323         /* 850 has PARTNUM 20 */
324         /* 801 has PARTNUM 10 */
325         return check_CPU (clock, pvr, immr);
326 }
327
328 /* ------------------------------------------------------------------------- */
329 /* L1 i-cache                                                                */
330 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB)              */
331 /* the 860 P (plus) has 256 sets of 16 bytes in 4 ways (= 16 kB)             */
332
333 int checkicache (void)
334 {
335         volatile immap_t *immap = (immap_t *) CFG_IMMR;
336         volatile memctl8xx_t *memctl = &immap->im_memctl;
337         u32 cacheon = rd_ic_cst () & IDC_ENABLED;
338
339 #ifdef CONFIG_IP86x
340         u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
341 #else
342         u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
343 #endif
344         u32 m;
345         u32 lines = -1;
346
347         wr_ic_cst (IDC_UNALL);
348         wr_ic_cst (IDC_INVALL);
349         wr_ic_cst (IDC_DISABLE);
350         __asm__ volatile ("isync");
351
352         while (!((m = rd_ic_cst ()) & IDC_CERR2)) {
353                 wr_ic_adr (k);
354                 wr_ic_cst (IDC_LDLCK);
355                 __asm__ volatile ("isync");
356
357                 lines++;
358                 k += 0x10;                              /* the number of bytes in a cacheline */
359         }
360
361         wr_ic_cst (IDC_UNALL);
362         wr_ic_cst (IDC_INVALL);
363
364         if (cacheon)
365                 wr_ic_cst (IDC_ENABLE);
366         else
367                 wr_ic_cst (IDC_DISABLE);
368
369         __asm__ volatile ("isync");
370
371         return lines << 4;
372 };
373
374 /* ------------------------------------------------------------------------- */
375 /* L1 d-cache                                                                */
376 /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB)              */
377 /* the 860 P (plus) has 256 sets of 16 bytes in 2 ways (= 8 kB)              */
378 /* call with cache disabled                                                  */
379
380 int checkdcache (void)
381 {
382         volatile immap_t *immap = (immap_t *) CFG_IMMR;
383         volatile memctl8xx_t *memctl = &immap->im_memctl;
384         u32 cacheon = rd_dc_cst () & IDC_ENABLED;
385
386 #ifdef CONFIG_IP86x
387         u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
388 #else
389         u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
390 #endif
391         u32 m;
392         u32 lines = -1;
393
394         wr_dc_cst (IDC_UNALL);
395         wr_dc_cst (IDC_INVALL);
396         wr_dc_cst (IDC_DISABLE);
397
398         while (!((m = rd_dc_cst ()) & IDC_CERR2)) {
399                 wr_dc_adr (k);
400                 wr_dc_cst (IDC_LDLCK);
401                 lines++;
402                 k += 0x10;      /* the number of bytes in a cacheline */
403         }
404
405         wr_dc_cst (IDC_UNALL);
406         wr_dc_cst (IDC_INVALL);
407
408         if (cacheon)
409                 wr_dc_cst (IDC_ENABLE);
410         else
411                 wr_dc_cst (IDC_DISABLE);
412
413         return lines << 4;
414 };
415
416 /* ------------------------------------------------------------------------- */
417
418 void upmconfig (uint upm, uint * table, uint size)
419 {
420         uint i;
421         uint addr = 0;
422         volatile immap_t *immap = (immap_t *) CFG_IMMR;
423         volatile memctl8xx_t *memctl = &immap->im_memctl;
424
425         for (i = 0; i < size; i++) {
426                 memctl->memc_mdr = table[i];    /* (16-15) */
427                 memctl->memc_mcr = addr | upm;  /* (16-16) */
428                 addr++;
429         }
430 }
431
432 /* ------------------------------------------------------------------------- */
433
434 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
435 {
436         ulong msr, addr;
437
438         volatile immap_t *immap = (immap_t *) CFG_IMMR;
439
440         immap->im_clkrst.car_plprcr |= PLPRCR_CSR;      /* Checkstop Reset enable */
441
442         /* Interrupts and MMU off */
443         __asm__ volatile ("mtspr    81, 0");
444         __asm__ volatile ("mfmsr    %0":"=r" (msr));
445
446         msr &= ~0x1030;
447         __asm__ volatile ("mtmsr    %0"::"r" (msr));
448
449         /*
450          * Trying to execute the next instruction at a non-existing address
451          * should cause a machine check, resulting in reset
452          */
453 #ifdef CFG_RESET_ADDRESS
454         addr = CFG_RESET_ADDRESS;
455 #else
456         /*
457          * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
458          * - sizeof (ulong) is usually a valid address. Better pick an address
459          * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
460          * "(ulong)-1" used to be a good choice for many systems...
461          */
462         addr = CFG_MONITOR_BASE - sizeof (ulong);
463 #endif
464         ((void (*)(void)) addr) ();
465         return 1;
466 }
467
468 /* ------------------------------------------------------------------------- */
469
470 /*
471  * Get timebase clock frequency (like cpu_clk in Hz)
472  *
473  * See table 15-5 pp. 15-16, and SCCR[RTSEL] pp. 15-27.
474  */
475 unsigned long get_tbclk (void)
476 {
477         DECLARE_GLOBAL_DATA_PTR;
478
479         volatile immap_t *immr = (volatile immap_t *) CFG_IMMR;
480         ulong oscclk, factor;
481
482         if (immr->im_clkrst.car_sccr & SCCR_TBS) {
483                 return (gd->cpu_clk / 16);
484         }
485 #define PLPRCR_val(a) (((CFG_PLPRCR) & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
486 #ifdef CONFIG_MPC866_et_al
487         /*                   MFN
488                      MFI + -------
489                            MFD + 1
490           factor =  -----------------
491                      (PDF + 1) * 2^S
492          */
493
494         factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN)/(PLPRCR_val(MFD)+1))/
495                  (PLPRCR_val(PDF)+1) / (1<<PLPRCR_val(S));
496 #else
497         factor = PLPRCR_val(MF)+1;
498 #endif
499
500         oscclk = gd->cpu_clk / factor;
501
502         if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
503                 return (oscclk / 4);
504         }
505         return (oscclk / 16);
506 }
507
508 /* ------------------------------------------------------------------------- */
509
510 #if defined(CONFIG_WATCHDOG)
511 void watchdog_reset (void)
512 {
513         int re_enable = disable_interrupts ();
514
515         reset_8xx_watchdog ((immap_t *) CFG_IMMR);
516         if (re_enable)
517                 enable_interrupts ();
518 }
519
520 void reset_8xx_watchdog (volatile immap_t * immr)
521 {
522 # if defined(CONFIG_LWMON)
523         /*
524          * The LWMON board uses a MAX6301 Watchdog
525          * with the trigger pin connected to port PA.7
526          *
527          * (The old board version used a MAX706TESA Watchdog, which
528          * had to be handled exactly the same.)
529          */
530 # define WATCHDOG_BIT   0x0100
531         immr->im_ioport.iop_papar &= ~(WATCHDOG_BIT);   /* GPIO     */
532         immr->im_ioport.iop_padir |= WATCHDOG_BIT;      /* Output   */
533         immr->im_ioport.iop_paodr &= ~(WATCHDOG_BIT);   /* active output */
534
535         immr->im_ioport.iop_padat ^= WATCHDOG_BIT;      /* Toggle WDI   */
536 # else
537         /*
538          * All other boards use the MPC8xx Internal Watchdog
539          */
540         immr->im_siu_conf.sc_swsr = 0x556c;     /* write magic1 */
541         immr->im_siu_conf.sc_swsr = 0xaa39;     /* write magic2 */
542 # endif /* CONFIG_LWMON */
543 }
544
545 #endif /* CONFIG_WATCHDOG */
546
547 /* ------------------------------------------------------------------------- */