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