blob: 095e2b866d166659ff7a6fe26cf28aac7676aabc [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Stefan Roese31ce7de2006-05-10 14:10:41 +02002 * (C) Copyright 2000-2006
wdenkc6097192002-11-03 00:24:07 +00003 * 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/*
wdenkc6097192002-11-03 00:24:07 +000025 * 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
Wolfgang Denk6405a152006-03-31 18:32:53 +020040#if !defined(CONFIG_405)
41DECLARE_GLOBAL_DATA_PTR;
42#endif
43
wdenkc6097192002-11-03 00:24:07 +000044
Stefan Roese99644742005-11-29 18:18:21 +010045#if defined(CONFIG_440)
46#define FREQ_EBC (sys_info.freqEPB)
47#else
48#define FREQ_EBC (sys_info.freqPLB / sys_info.pllExtBusDiv)
Stefan Roese42f2a822005-11-27 19:36:26 +010049#endif
50
Stefan Roese99644742005-11-29 18:18:21 +010051#if defined(CONFIG_405GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
52
53#define PCI_ASYNC
54
55int pci_async_enabled(void)
56{
57#if defined(CONFIG_405GP)
58 return (mfdcr(strap) & PSR_PCI_ASYNC_EN);
Stefan Roese42f2a822005-11-27 19:36:26 +010059#endif
60
61#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese99644742005-11-29 18:18:21 +010062 unsigned long val;
63
Wolfgang Denkaaa7c002005-12-12 16:06:05 +010064 mfsdr(sdr_sdstp1, val);
Stefan Roese99644742005-11-29 18:18:21 +010065 return (val & SDR0_SDSTP1_PAME_MASK);
66#endif
67}
68#endif
69
Stefan Roesee2c34122005-11-29 19:13:38 +010070#if defined(CONFIG_PCI) && !defined(CONFIG_IOP480) && !defined(CONFIG_405)
Stefan Roese99644742005-11-29 18:18:21 +010071int pci_arbiter_enabled(void)
72{
73#if defined(CONFIG_405GP)
74 return (mfdcr(strap) & PSR_PCI_ARBIT_EN);
75#endif
Stefan Roese42f2a822005-11-27 19:36:26 +010076
Stefan Roese99644742005-11-29 18:18:21 +010077#if defined(CONFIG_405EP)
78 return (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN);
Stefan Roese42f2a822005-11-27 19:36:26 +010079#endif
80
81#if defined(CONFIG_440GP)
Stefan Roese99644742005-11-29 18:18:21 +010082 return (mfdcr(cpc0_strp1) & CPC0_STRP1_PAE_MASK);
83#endif
Stefan Roese42f2a822005-11-27 19:36:26 +010084
Stefan Roese99644742005-11-29 18:18:21 +010085#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);
Stefan Roese42f2a822005-11-27 19:36:26 +010090#endif
Stefan Roese99644742005-11-29 18:18:21 +010091}
92#endif
93
94#if defined(CONFIG_405EP)|| defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
95 defined(CONFIG_440GX) || defined(CONFIG_440SP)
Stefan Roese42f2a822005-11-27 19:36:26 +010096
Stefan Roese99644742005-11-29 18:18:21 +010097#define I2C_BOOTROM
Stefan Roese42f2a822005-11-27 19:36:26 +010098
Stefan Roese99644742005-11-29 18:18:21 +010099int i2c_bootrom_enabled(void)
100{
101#if defined(CONFIG_405EP)
102 return (mfdcr(cpc0_boot) & CPC0_BOOT_SEP);
Stefan Roese42f2a822005-11-27 19:36:26 +0100103#endif
104
Stefan Roese99644742005-11-29 18:18:21 +0100105#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}
Stefan Roese42f2a822005-11-27 19:36:26 +0100112#endif
113
114
wdenkc6097192002-11-03 00:24:07 +0000115#if defined(CONFIG_440)
Stefan Roese42f2a822005-11-27 19:36:26 +0100116static int do_chip_reset(unsigned long sys0, unsigned long sys1);
wdenkc6097192002-11-03 00:24:07 +0000117#endif
118
wdenkc6097192002-11-03 00:24:07 +0000119
120int checkcpu (void)
121{
Stefan Roese42f2a822005-11-27 19:36:26 +0100122#if !defined(CONFIG_405) /* not used on Xilinx 405 FPGA implementations */
Stefan Roese42f2a822005-11-27 19:36:26 +0100123 uint pvr = get_pvr();
wdenkc6097192002-11-03 00:24:07 +0000124 ulong clock = gd->cpu_clk;
125 char buf[32];
wdenkc6097192002-11-03 00:24:07 +0000126
Stefan Roese42f2a822005-11-27 19:36:26 +0100127#if !defined(CONFIG_IOP480)
128 sys_info_t sys_info;
wdenkc6097192002-11-03 00:24:07 +0000129
130 puts ("CPU: ");
131
132 get_sys_info(&sys_info);
133
Stefan Roese42f2a822005-11-27 19:36:26 +0100134 puts("AMCC PowerPC 4");
135
136#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405EP)
137 puts("05");
wdenkc6097192002-11-03 00:24:07 +0000138#endif
Stefan Roese42f2a822005-11-27 19:36:26 +0100139#if defined(CONFIG_440)
140 puts("40");
stroese434979e2003-05-23 11:18:02 +0000141#endif
Stefan Roese42f2a822005-11-27 19:36:26 +0100142
wdenkc6097192002-11-03 00:24:07 +0000143 switch (pvr) {
144 case PVR_405GP_RB:
Stefan Roese42f2a822005-11-27 19:36:26 +0100145 puts("GP Rev. B");
wdenkc6097192002-11-03 00:24:07 +0000146 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100147
wdenkc6097192002-11-03 00:24:07 +0000148 case PVR_405GP_RC:
Stefan Roese42f2a822005-11-27 19:36:26 +0100149 puts("GP Rev. C");
wdenkc6097192002-11-03 00:24:07 +0000150 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100151
wdenkc6097192002-11-03 00:24:07 +0000152 case PVR_405GP_RD:
Stefan Roese42f2a822005-11-27 19:36:26 +0100153 puts("GP Rev. D");
wdenkc6097192002-11-03 00:24:07 +0000154 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100155
wdenkc35ba4e2004-03-14 22:25:36 +0000156#ifdef CONFIG_405GP
Stefan Roese42f2a822005-11-27 19:36:26 +0100157 case PVR_405GP_RE: /* 405GP rev E and 405CR rev C have same PVR */
158 puts("GP Rev. E");
wdenkc6097192002-11-03 00:24:07 +0000159 break;
160#endif
Stefan Roese42f2a822005-11-27 19:36:26 +0100161
wdenkc6097192002-11-03 00:24:07 +0000162 case PVR_405CR_RA:
Stefan Roese42f2a822005-11-27 19:36:26 +0100163 puts("CR Rev. A");
wdenkc6097192002-11-03 00:24:07 +0000164 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100165
wdenkc6097192002-11-03 00:24:07 +0000166 case PVR_405CR_RB:
Stefan Roese42f2a822005-11-27 19:36:26 +0100167 puts("CR Rev. B");
wdenkc6097192002-11-03 00:24:07 +0000168 break;
wdenkc6097192002-11-03 00:24:07 +0000169
Stefan Roese42f2a822005-11-27 19:36:26 +0100170#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;
wdenkc6097192002-11-03 00:24:07 +0000174#endif
175
Stefan Roese42f2a822005-11-27 19:36:26 +0100176 case PVR_405GPR_RB:
177 puts("GPr Rev. B");
178 break;
wdenkc6097192002-11-03 00:24:07 +0000179
Stefan Roese42f2a822005-11-27 19:36:26 +0100180 case PVR_405EP_RB:
181 puts("EP Rev. B");
182 break;
wdenkc6097192002-11-03 00:24:07 +0000183
184#if defined(CONFIG_440)
wdenk57b2d802003-06-27 21:31:46 +0000185 case PVR_440GP_RB:
Stefan Roese326c9712005-08-01 16:41:48 +0200186 puts("GP Rev. B");
wdenka4685fe2003-09-03 14:03:26 +0000187 /* 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 }
wdenkc6097192002-11-03 00:24:07 +0000196 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100197
wdenk57b2d802003-06-27 21:31:46 +0000198 case PVR_440GP_RC:
Stefan Roese326c9712005-08-01 16:41:48 +0200199 puts("GP Rev. C");
wdenk544e9732004-02-06 23:19:44 +0000200 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100201
wdenk544e9732004-02-06 23:19:44 +0000202 case PVR_440GX_RA:
Stefan Roese326c9712005-08-01 16:41:48 +0200203 puts("GX Rev. A");
wdenk544e9732004-02-06 23:19:44 +0000204 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100205
wdenk544e9732004-02-06 23:19:44 +0000206 case PVR_440GX_RB:
Stefan Roese326c9712005-08-01 16:41:48 +0200207 puts("GX Rev. B");
wdenkc6097192002-11-03 00:24:07 +0000208 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100209
stroesec0125272005-04-07 05:33:41 +0000210 case PVR_440GX_RC:
Stefan Roese326c9712005-08-01 16:41:48 +0200211 puts("GX Rev. C");
stroesec0125272005-04-07 05:33:41 +0000212 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100213
Stefan Roese08fb4042005-11-01 10:08:03 +0100214 case PVR_440GX_RF:
215 puts("GX Rev. F");
216 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100217
Stefan Roese326c9712005-08-01 16:41:48 +0200218 case PVR_440EP_RA:
219 puts("EP Rev. A");
220 break;
Stefan Roese42f2a822005-11-27 19:36:26 +0100221
Stefan Roese95258d52005-10-04 15:00:30 +0200222#ifdef CONFIG_440EP
223 case PVR_440EP_RB: /* 440EP rev B and 440GR rev A have same PVR */
Stefan Roese326c9712005-08-01 16:41:48 +0200224 puts("EP Rev. B");
225 break;
Stefan Roese31ce7de2006-05-10 14:10:41 +0200226
227 case PVR_440EP_RC: /* 440EP rev C and 440GR rev B have same PVR */
228 puts("EP Rev. C");
229 break;
Stefan Roese95258d52005-10-04 15:00:30 +0200230#endif /* CONFIG_440EP */
Stefan Roese42f2a822005-11-27 19:36:26 +0100231
Stefan Roese95258d52005-10-04 15:00:30 +0200232#ifdef CONFIG_440GR
233 case PVR_440GR_RA: /* 440EP rev B and 440GR rev A have same PVR */
234 puts("GR Rev. A");
235 break;
Stefan Roese31ce7de2006-05-10 14:10:41 +0200236
237 case PVR_440EP_RB: /* 440EP rev C and 440GR rev B have same PVR */
238 puts("GR Rev. B");
239 break;
Stefan Roese95258d52005-10-04 15:00:30 +0200240#endif /* CONFIG_440GR */
Stefan Roese42f2a822005-11-27 19:36:26 +0100241#endif /* CONFIG_440 */
242
Stefan Roese99644742005-11-29 18:18:21 +0100243 case PVR_440SP_RA:
244 puts("SP Rev. A");
245 break;
246
247 case PVR_440SP_RB:
248 puts("SP Rev. B");
249 break;
250
wdenk57b2d802003-06-27 21:31:46 +0000251 default:
Stefan Roese363330b2005-08-04 17:09:16 +0200252 printf (" UNKNOWN (PVR=%08x)", pvr);
wdenkc6097192002-11-03 00:24:07 +0000253 break;
254 }
Stefan Roese42f2a822005-11-27 19:36:26 +0100255
256 printf (" at %s MHz (PLB=%lu, OPB=%lu, EBC=%lu MHz)\n", strmhz(buf, clock),
257 sys_info.freqPLB / 1000000,
258 sys_info.freqPLB / sys_info.pllOpbDiv / 1000000,
259 FREQ_EBC / 1000000);
260
Stefan Roese99644742005-11-29 18:18:21 +0100261#if defined(I2C_BOOTROM)
262 printf (" I2C boot EEPROM %sabled\n", i2c_bootrom_enabled() ? "en" : "dis");
Stefan Roese42f2a822005-11-27 19:36:26 +0100263#endif
264
Stefan Roese99644742005-11-29 18:18:21 +0100265#if defined(CONFIG_PCI)
266 printf (" Internal PCI arbiter %sabled", pci_arbiter_enabled() ? "en" : "dis");
Stefan Roese42f2a822005-11-27 19:36:26 +0100267#endif
268
Stefan Roese99644742005-11-29 18:18:21 +0100269#if defined(PCI_ASYNC)
270 if (pci_async_enabled()) {
Stefan Roese42f2a822005-11-27 19:36:26 +0100271 printf (", PCI async ext clock used");
272 } else {
273 printf (", PCI sync clock at %lu MHz",
274 sys_info.freqPLB / sys_info.pllPciDiv / 1000000);
275 }
wdenkc6097192002-11-03 00:24:07 +0000276#endif
Stefan Roese42f2a822005-11-27 19:36:26 +0100277
Stefan Roese99644742005-11-29 18:18:21 +0100278#if defined(CONFIG_PCI)
Stefan Roese42f2a822005-11-27 19:36:26 +0100279 putc('\n');
280#endif
281
282#if defined(CONFIG_405EP)
283 printf (" 16 kB I-Cache 16 kB D-Cache");
284#elif defined(CONFIG_440)
285 printf (" 32 kB I-Cache 32 kB D-Cache");
286#else
287 printf (" 16 kB I-Cache %d kB D-Cache",
288 ((pvr | 0x00000001) == PVR_405GPR_RB) ? 16 : 8);
289#endif
290#endif /* !defined(CONFIG_IOP480) */
291
292#if defined(CONFIG_IOP480)
293 printf ("PLX IOP480 (PVR=%08x)", pvr);
294 printf (" at %s MHz:", strmhz(buf, clock));
295 printf (" %u kB I-Cache", 4);
296 printf (" %u kB D-Cache", 2);
297#endif
298
299#endif /* !defined(CONFIG_405) */
300
301 putc ('\n');
wdenkc6097192002-11-03 00:24:07 +0000302
303 return 0;
304}
305
306
307/* ------------------------------------------------------------------------- */
308
wdenk57b2d802003-06-27 21:31:46 +0000309int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenkc6097192002-11-03 00:24:07 +0000310{
Stefan Roese326c9712005-08-01 16:41:48 +0200311#if defined(CONFIG_YOSEMITE) || defined(CONFIG_YELLOWSTONE)
312 /*give reset to BCSR*/
313 *(unsigned char*)(CFG_BCSR_BASE | 0x06) = 0x09;
314
315#else
316
wdenk57b2d802003-06-27 21:31:46 +0000317 /*
318 * Initiate system reset in debug control register DBCR
319 */
wdenkc6097192002-11-03 00:24:07 +0000320 __asm__ __volatile__("lis 3, 0x3000" ::: "r3");
321#if defined(CONFIG_440)
322 __asm__ __volatile__("mtspr 0x134, 3");
323#else
324 __asm__ __volatile__("mtspr 0x3f2, 3");
325#endif
Stefan Roese326c9712005-08-01 16:41:48 +0200326
327#endif/* defined(CONFIG_YOSEMITE) || defined(CONFIG_YELLOWSTONE)*/
wdenkc6097192002-11-03 00:24:07 +0000328 return 1;
329}
330
331#if defined(CONFIG_440)
Stefan Roese42f2a822005-11-27 19:36:26 +0100332static int do_chip_reset (unsigned long sys0, unsigned long sys1)
wdenkc6097192002-11-03 00:24:07 +0000333{
wdenka4685fe2003-09-03 14:03:26 +0000334 /* Changes to cpc0_sys0 and cpc0_sys1 require chip
335 * reset.
336 */
337 mtdcr (cntrl0, mfdcr (cntrl0) | 0x80000000); /* Set SWE */
338 mtdcr (cpc0_sys0, sys0);
339 mtdcr (cpc0_sys1, sys1);
340 mtdcr (cntrl0, mfdcr (cntrl0) & ~0x80000000); /* Clr SWE */
341 mtspr (dbcr0, 0x20000000); /* Reset the chip */
wdenkc6097192002-11-03 00:24:07 +0000342
wdenka4685fe2003-09-03 14:03:26 +0000343 return 1;
wdenkc6097192002-11-03 00:24:07 +0000344}
345#endif
346
347
348/*
349 * Get timebase clock frequency
350 */
351unsigned long get_tbclk (void)
352{
Stefan Roese42f2a822005-11-27 19:36:26 +0100353#if !defined(CONFIG_IOP480)
wdenkc6097192002-11-03 00:24:07 +0000354 sys_info_t sys_info;
355
356 get_sys_info(&sys_info);
357 return (sys_info.freqProcessor);
wdenkc6097192002-11-03 00:24:07 +0000358#else
Stefan Roese42f2a822005-11-27 19:36:26 +0100359 return (66000000);
wdenkc6097192002-11-03 00:24:07 +0000360#endif
361
362}
363
364
365#if defined(CONFIG_WATCHDOG)
366void
367watchdog_reset(void)
368{
369 int re_enable = disable_interrupts();
370 reset_4xx_watchdog();
371 if (re_enable) enable_interrupts();
372}
373
374void
375reset_4xx_watchdog(void)
376{
377 /*
378 * Clear TSR(WIS) bit
379 */
380 mtspr(tsr, 0x40000000);
381}
382#endif /* CONFIG_WATCHDOG */