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