Merge branch 'master' of rsync://rsync.denx.de/git/u-boot
[platform/kernel/u-boot.git] / cpu / ppc4xx / cpu.c
1 /*
2  * (C) Copyright 2000-2003
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  * CPU specific code
26  *
27  * written or collected and sometimes rewritten by
28  * Magnus Damm <damm@bitsmart.com>
29  *
30  * minor modifications by
31  * Wolfgang Denk <wd@denx.de>
32  */
33
34 #include <common.h>
35 #include <watchdog.h>
36 #include <command.h>
37 #include <asm/cache.h>
38 #include <ppc4xx.h>
39
40 #if !defined(CONFIG_405)
41 DECLARE_GLOBAL_DATA_PTR;
42 #endif
43
44
45 #if defined(CONFIG_440)
46 #define FREQ_EBC                (sys_info.freqEPB)
47 #else
48 #define FREQ_EBC                (sys_info.freqPLB / sys_info.pllExtBusDiv)
49 #endif
50
51 #if defined(CONFIG_405GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
52
53 #define PCI_ASYNC
54
55 int pci_async_enabled(void)
56 {
57 #if defined(CONFIG_405GP)
58         return (mfdcr(strap) & PSR_PCI_ASYNC_EN);
59 #endif
60
61 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
62         unsigned long val;
63
64         mfsdr(sdr_sdstp1, val);
65         return (val & SDR0_SDSTP1_PAME_MASK);
66 #endif
67 }
68 #endif
69
70 #if defined(CONFIG_PCI) && !defined(CONFIG_IOP480) && !defined(CONFIG_405)
71 int pci_arbiter_enabled(void)
72 {
73 #if defined(CONFIG_405GP)
74         return (mfdcr(strap) & PSR_PCI_ARBIT_EN);
75 #endif
76
77 #if defined(CONFIG_405EP)
78         return (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN);
79 #endif
80
81 #if defined(CONFIG_440GP)
82         return (mfdcr(cpc0_strp1) & CPC0_STRP1_PAE_MASK);
83 #endif
84
85 #if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP)
86         unsigned long val;
87
88         mfsdr(sdr_sdstp1, val);
89         return (val & SDR0_SDSTP1_PAE_MASK);
90 #endif
91 }
92 #endif
93
94 #if defined(CONFIG_405EP)|| defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
95         defined(CONFIG_440GX) || defined(CONFIG_440SP)
96
97 #define I2C_BOOTROM
98
99 int i2c_bootrom_enabled(void)
100 {
101 #if defined(CONFIG_405EP)
102         return (mfdcr(cpc0_boot) & CPC0_BOOT_SEP);
103 #endif
104
105 #if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP)
106         unsigned long val;
107
108         mfsdr(sdr_sdcs, val);
109         return (val & SDR0_SDCS_SDD);
110 #endif
111 }
112 #endif
113
114
115 #if defined(CONFIG_440)
116 static int do_chip_reset(unsigned long sys0, unsigned long sys1);
117 #endif
118
119
120 int checkcpu (void)
121 {
122 #if !defined(CONFIG_405)        /* not used on Xilinx 405 FPGA implementations */
123         uint pvr = get_pvr();
124         ulong clock = gd->cpu_clk;
125         char buf[32];
126
127 #if !defined(CONFIG_IOP480)
128         sys_info_t sys_info;
129
130         puts ("CPU:   ");
131
132         get_sys_info(&sys_info);
133
134         puts("AMCC PowerPC 4");
135
136 #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405EP)
137         puts("05");
138 #endif
139 #if defined(CONFIG_440)
140         puts("40");
141 #endif
142
143         switch (pvr) {
144         case PVR_405GP_RB:
145                 puts("GP Rev. B");
146                 break;
147
148         case PVR_405GP_RC:
149                 puts("GP Rev. C");
150                 break;
151
152         case PVR_405GP_RD:
153                 puts("GP Rev. D");
154                 break;
155
156 #ifdef CONFIG_405GP
157         case PVR_405GP_RE: /* 405GP rev E and 405CR rev C have same PVR */
158                 puts("GP Rev. E");
159                 break;
160 #endif
161
162         case PVR_405CR_RA:
163                 puts("CR Rev. A");
164                 break;
165
166         case PVR_405CR_RB:
167                 puts("CR Rev. B");
168                 break;
169
170 #ifdef CONFIG_405CR
171         case PVR_405CR_RC: /* 405GP rev E and 405CR rev C have same PVR */
172                 puts("CR Rev. C");
173                 break;
174 #endif
175
176         case PVR_405GPR_RB:
177                 puts("GPr Rev. B");
178                 break;
179
180         case PVR_405EP_RB:
181                 puts("EP Rev. B");
182                 break;
183
184 #if defined(CONFIG_440)
185         case PVR_440GP_RB:
186                 puts("GP Rev. B");
187                 /* See errata 1.12: CHIP_4 */
188                 if ((mfdcr(cpc0_sys0) != mfdcr(cpc0_strp0)) ||
189                     (mfdcr(cpc0_sys1) != mfdcr(cpc0_strp1)) ){
190                         puts (  "\n\t CPC0_SYSx DCRs corrupted. "
191                                 "Resetting chip ...\n");
192                         udelay( 1000 * 1000 ); /* Give time for serial buf to clear */
193                         do_chip_reset ( mfdcr(cpc0_strp0),
194                                         mfdcr(cpc0_strp1) );
195                 }
196                 break;
197
198         case PVR_440GP_RC:
199                 puts("GP Rev. C");
200                 break;
201
202         case PVR_440GX_RA:
203                 puts("GX Rev. A");
204                 break;
205
206         case PVR_440GX_RB:
207                 puts("GX Rev. B");
208                 break;
209
210         case PVR_440GX_RC:
211                 puts("GX Rev. C");
212                 break;
213
214         case PVR_440GX_RF:
215                 puts("GX Rev. F");
216                 break;
217
218         case PVR_440EP_RA:
219                 puts("EP Rev. A");
220                 break;
221
222 #ifdef CONFIG_440EP
223         case PVR_440EP_RB: /* 440EP rev B and 440GR rev A have same PVR */
224                 puts("EP Rev. B");
225                 break;
226 #endif /*  CONFIG_440EP */
227
228 #ifdef CONFIG_440GR
229         case PVR_440GR_RA: /* 440EP rev B and 440GR rev A have same PVR */
230                 puts("GR Rev. A");
231                 break;
232 #endif /* CONFIG_440GR */
233 #endif /* CONFIG_440 */
234
235         case PVR_440SP_RA:
236                 puts("SP Rev. A");
237                 break;
238
239         case PVR_440SP_RB:
240                 puts("SP Rev. B");
241                 break;
242
243         default:
244                 printf (" UNKNOWN (PVR=%08x)", pvr);
245                 break;
246         }
247
248         printf (" at %s MHz (PLB=%lu, OPB=%lu, EBC=%lu MHz)\n", strmhz(buf, clock),
249                sys_info.freqPLB / 1000000,
250                sys_info.freqPLB / sys_info.pllOpbDiv / 1000000,
251                FREQ_EBC / 1000000);
252
253 #if defined(I2C_BOOTROM)
254         printf ("       I2C boot EEPROM %sabled\n", i2c_bootrom_enabled() ? "en" : "dis");
255 #endif
256
257 #if defined(CONFIG_PCI)
258         printf ("       Internal PCI arbiter %sabled", pci_arbiter_enabled() ? "en" : "dis");
259 #endif
260
261 #if defined(PCI_ASYNC)
262         if (pci_async_enabled()) {
263                 printf (", PCI async ext clock used");
264         } else {
265                 printf (", PCI sync clock at %lu MHz",
266                        sys_info.freqPLB / sys_info.pllPciDiv / 1000000);
267         }
268 #endif
269
270 #if defined(CONFIG_PCI)
271         putc('\n');
272 #endif
273
274 #if defined(CONFIG_405EP)
275         printf ("       16 kB I-Cache 16 kB D-Cache");
276 #elif defined(CONFIG_440)
277         printf ("       32 kB I-Cache 32 kB D-Cache");
278 #else
279         printf ("       16 kB I-Cache %d kB D-Cache",
280                 ((pvr | 0x00000001) == PVR_405GPR_RB) ? 16 : 8);
281 #endif
282 #endif /* !defined(CONFIG_IOP480) */
283
284 #if defined(CONFIG_IOP480)
285         printf ("PLX IOP480 (PVR=%08x)", pvr);
286         printf (" at %s MHz:", strmhz(buf, clock));
287         printf (" %u kB I-Cache", 4);
288         printf (" %u kB D-Cache", 2);
289 #endif
290
291 #endif /* !defined(CONFIG_405) */
292
293         putc ('\n');
294
295         return 0;
296 }
297
298
299 /* ------------------------------------------------------------------------- */
300
301 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
302 {
303 #if defined(CONFIG_YOSEMITE) || defined(CONFIG_YELLOWSTONE)
304         /*give reset to BCSR*/
305         *(unsigned char*)(CFG_BCSR_BASE | 0x06) = 0x09;
306
307 #else
308
309         /*
310          * Initiate system reset in debug control register DBCR
311          */
312         __asm__ __volatile__("lis   3, 0x3000" ::: "r3");
313 #if defined(CONFIG_440)
314         __asm__ __volatile__("mtspr 0x134, 3");
315 #else
316         __asm__ __volatile__("mtspr 0x3f2, 3");
317 #endif
318
319 #endif/* defined(CONFIG_YOSEMITE) || defined(CONFIG_YELLOWSTONE)*/
320         return 1;
321 }
322
323 #if defined(CONFIG_440)
324 static int do_chip_reset (unsigned long sys0, unsigned long sys1)
325 {
326         /* Changes to cpc0_sys0 and cpc0_sys1 require chip
327          * reset.
328          */
329         mtdcr (cntrl0, mfdcr (cntrl0) | 0x80000000);    /* Set SWE */
330         mtdcr (cpc0_sys0, sys0);
331         mtdcr (cpc0_sys1, sys1);
332         mtdcr (cntrl0, mfdcr (cntrl0) & ~0x80000000);   /* Clr SWE */
333         mtspr (dbcr0, 0x20000000);      /* Reset the chip */
334
335         return 1;
336 }
337 #endif
338
339
340 /*
341  * Get timebase clock frequency
342  */
343 unsigned long get_tbclk (void)
344 {
345 #if !defined(CONFIG_IOP480)
346         sys_info_t  sys_info;
347
348         get_sys_info(&sys_info);
349         return (sys_info.freqProcessor);
350 #else
351         return (66000000);
352 #endif
353
354 }
355
356
357 #if defined(CONFIG_WATCHDOG)
358 void
359 watchdog_reset(void)
360 {
361         int re_enable = disable_interrupts();
362         reset_4xx_watchdog();
363         if (re_enable) enable_interrupts();
364 }
365
366 void
367 reset_4xx_watchdog(void)
368 {
369         /*
370          * Clear TSR(WIS) bit
371          */
372         mtspr(tsr, 0x40000000);
373 }
374 #endif  /* CONFIG_WATCHDOG */