blob: 06acb8162e08563d0e819e33a87326423288193a [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
wdenka4685fe2003-09-03 14:03:26 +00002 * (C) Copyright 2000-2003
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
40
41#if defined(CONFIG_440)
42static int do_chip_reset( unsigned long sys0, unsigned long sys1 );
43#endif
44
45/* ------------------------------------------------------------------------- */
46
47int checkcpu (void)
48{
stroese434979e2003-05-23 11:18:02 +000049#if defined(CONFIG_405GP) || \
50 defined(CONFIG_405CR) || \
wdenk232fe0b2003-09-02 22:48:03 +000051 defined(CONFIG_405EP) || \
52 defined(CONFIG_440) || \
53 defined(CONFIG_IOP480)
wdenkc6097192002-11-03 00:24:07 +000054 uint pvr = get_pvr();
55#endif
stroese434979e2003-05-23 11:18:02 +000056#if defined(CONFIG_405GP) || \
57 defined(CONFIG_405CR) || \
wdenk232fe0b2003-09-02 22:48:03 +000058 defined(CONFIG_405EP) || \
59 defined(CONFIG_IOP480)
wdenkc6097192002-11-03 00:24:07 +000060 DECLARE_GLOBAL_DATA_PTR;
61
62 ulong clock = gd->cpu_clk;
63 char buf[32];
64#endif
65
stroese434979e2003-05-23 11:18:02 +000066#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405EP)
wdenkc6097192002-11-03 00:24:07 +000067 PPC405_SYS_INFO sys_info;
68
69 puts ("CPU: ");
70
71 get_sys_info(&sys_info);
72
wdenkc35ba4e2004-03-14 22:25:36 +000073#ifdef CONFIG_405GP
wdenka4685fe2003-09-03 14:03:26 +000074 puts ("IBM PowerPC 405GP");
stroeseff90f802003-04-04 16:00:33 +000075 if (pvr == PVR_405GPR_RB) {
wdenkc6097192002-11-03 00:24:07 +000076 putc('r');
77 }
wdenka4685fe2003-09-03 14:03:26 +000078 puts (" Rev. ");
wdenkc6097192002-11-03 00:24:07 +000079#endif
wdenkc35ba4e2004-03-14 22:25:36 +000080#ifdef CONFIG_405CR
wdenka4685fe2003-09-03 14:03:26 +000081 puts ("IBM PowerPC 405CR Rev. ");
wdenkc6097192002-11-03 00:24:07 +000082#endif
wdenkc35ba4e2004-03-14 22:25:36 +000083#ifdef CONFIG_405EP
wdenka4685fe2003-09-03 14:03:26 +000084 puts ("IBM PowerPC 405EP Rev. ");
stroese434979e2003-05-23 11:18:02 +000085#endif
wdenkc6097192002-11-03 00:24:07 +000086 switch (pvr) {
87 case PVR_405GP_RB:
stroeseff90f802003-04-04 16:00:33 +000088 case PVR_405GPR_RB:
wdenkc6097192002-11-03 00:24:07 +000089 putc('B');
90 break;
91 case PVR_405GP_RC:
wdenkc35ba4e2004-03-14 22:25:36 +000092#ifdef CONFIG_405CR
wdenkc6097192002-11-03 00:24:07 +000093 case PVR_405CR_RC:
94#endif
95 putc('C');
96 break;
97 case PVR_405GP_RD:
98 putc('D');
99 break;
wdenkc35ba4e2004-03-14 22:25:36 +0000100#ifdef CONFIG_405GP
wdenkc6097192002-11-03 00:24:07 +0000101 case PVR_405GP_RE:
102 putc('E');
103 break;
104#endif
105 case PVR_405CR_RA:
wdenkc6097192002-11-03 00:24:07 +0000106 putc('A');
107 break;
108 case PVR_405CR_RB:
stroese434979e2003-05-23 11:18:02 +0000109 case PVR_405EP_RB:
wdenkc6097192002-11-03 00:24:07 +0000110 putc('B');
111 break;
112 default:
wdenka4685fe2003-09-03 14:03:26 +0000113 printf ("? (PVR=%08x)", pvr);
wdenkc6097192002-11-03 00:24:07 +0000114 break;
115 }
116
wdenka4685fe2003-09-03 14:03:26 +0000117 printf (" at %s MHz (PLB=%lu, OPB=%lu, EBC=%lu MHz)\n", strmhz(buf, clock),
wdenkc6097192002-11-03 00:24:07 +0000118 sys_info.freqPLB / 1000000,
119 sys_info.freqPLB / sys_info.pllOpbDiv / 1000000,
120 sys_info.freqPLB / sys_info.pllExtBusDiv / 1000000);
121
stroese434979e2003-05-23 11:18:02 +0000122#if defined(CONFIG_405GP)
wdenka4685fe2003-09-03 14:03:26 +0000123 if (mfdcr(strap) & PSR_PCI_ASYNC_EN) {
124 printf (" PCI async ext clock used, ");
125 } else {
126 printf (" PCI sync clock at %lu MHz, ",
wdenkc6097192002-11-03 00:24:07 +0000127 sys_info.freqPLB / sys_info.pllPciDiv / 1000000);
wdenka4685fe2003-09-03 14:03:26 +0000128 }
129 printf ("%sternal PCI arbiter enabled\n",
130 (mfdcr(strap) & PSR_PCI_ARBIT_EN) ? "in" : "ex");
stroese434979e2003-05-23 11:18:02 +0000131#elif defined(CONFIG_405EP)
wdenka4685fe2003-09-03 14:03:26 +0000132 printf (" IIC Boot EEPROM %sabled\n",
133 (mfdcr(cpc0_boot) & CPC0_BOOT_SEP) ? "en" : "dis");
134 printf (" PCI async ext clock used, ");
135 printf ("%sternal PCI arbiter enabled\n",
136 (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN) ? "in" : "ex");
wdenkc6097192002-11-03 00:24:07 +0000137#endif
138
stroese434979e2003-05-23 11:18:02 +0000139#if defined(CONFIG_405EP)
wdenka4685fe2003-09-03 14:03:26 +0000140 printf (" 16 kB I-Cache 16 kB D-Cache");
stroese434979e2003-05-23 11:18:02 +0000141#else
wdenka4685fe2003-09-03 14:03:26 +0000142 printf (" 16 kB I-Cache %d kB D-Cache",
143 ((pvr | 0x00000001) == PVR_405GPR_RB) ? 16 : 8);
stroese434979e2003-05-23 11:18:02 +0000144#endif
wdenkc6097192002-11-03 00:24:07 +0000145#endif /* defined(CONFIG_405GP) || defined(CONFIG_405CR) */
146
147#ifdef CONFIG_IOP480
wdenka4685fe2003-09-03 14:03:26 +0000148 printf ("PLX IOP480 (PVR=%08x)", pvr);
149 printf (" at %s MHz:", strmhz(buf, clock));
150 printf (" %u kB I-Cache", 4);
151 printf (" %u kB D-Cache", 2);
wdenkc6097192002-11-03 00:24:07 +0000152#endif
153
154#if defined(CONFIG_440)
wdenk544e9732004-02-06 23:19:44 +0000155 puts ("IBM PowerPC 440 G");
wdenka4685fe2003-09-03 14:03:26 +0000156 switch(pvr) {
wdenk57b2d802003-06-27 21:31:46 +0000157 case PVR_440GP_RB:
wdenk544e9732004-02-06 23:19:44 +0000158 puts("P Rev. B");
wdenka4685fe2003-09-03 14:03:26 +0000159 /* See errata 1.12: CHIP_4 */
160 if ((mfdcr(cpc0_sys0) != mfdcr(cpc0_strp0)) ||
161 (mfdcr(cpc0_sys1) != mfdcr(cpc0_strp1)) ){
162 puts ( "\n\t CPC0_SYSx DCRs corrupted. "
163 "Resetting chip ...\n");
164 udelay( 1000 * 1000 ); /* Give time for serial buf to clear */
165 do_chip_reset ( mfdcr(cpc0_strp0),
166 mfdcr(cpc0_strp1) );
167 }
wdenkc6097192002-11-03 00:24:07 +0000168 break;
wdenk57b2d802003-06-27 21:31:46 +0000169 case PVR_440GP_RC:
wdenk544e9732004-02-06 23:19:44 +0000170 puts("P Rev. C");
171 break;
172 case PVR_440GX_RA:
173 puts("X Rev. A");
174 break;
175 case PVR_440GX_RB:
176 puts("X Rev. B");
wdenkc6097192002-11-03 00:24:07 +0000177 break;
stroesec0125272005-04-07 05:33:41 +0000178 case PVR_440GX_RC:
179 puts("X Rev. C");
180 break;
wdenk57b2d802003-06-27 21:31:46 +0000181 default:
stroesec0125272005-04-07 05:33:41 +0000182 printf (" UNKNOWN (PVR=%08x)", pvr);
wdenkc6097192002-11-03 00:24:07 +0000183 break;
184 }
185#endif
wdenka4685fe2003-09-03 14:03:26 +0000186 puts ("\n");
wdenkc6097192002-11-03 00:24:07 +0000187
188 return 0;
189}
190
191
192/* ------------------------------------------------------------------------- */
193
wdenk57b2d802003-06-27 21:31:46 +0000194int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenkc6097192002-11-03 00:24:07 +0000195{
wdenk57b2d802003-06-27 21:31:46 +0000196 /*
197 * Initiate system reset in debug control register DBCR
198 */
wdenkc6097192002-11-03 00:24:07 +0000199 __asm__ __volatile__("lis 3, 0x3000" ::: "r3");
200#if defined(CONFIG_440)
201 __asm__ __volatile__("mtspr 0x134, 3");
202#else
203 __asm__ __volatile__("mtspr 0x3f2, 3");
204#endif
205 return 1;
206}
207
208#if defined(CONFIG_440)
209static
wdenka4685fe2003-09-03 14:03:26 +0000210int do_chip_reset (unsigned long sys0, unsigned long sys1)
wdenkc6097192002-11-03 00:24:07 +0000211{
wdenka4685fe2003-09-03 14:03:26 +0000212 /* Changes to cpc0_sys0 and cpc0_sys1 require chip
213 * reset.
214 */
215 mtdcr (cntrl0, mfdcr (cntrl0) | 0x80000000); /* Set SWE */
216 mtdcr (cpc0_sys0, sys0);
217 mtdcr (cpc0_sys1, sys1);
218 mtdcr (cntrl0, mfdcr (cntrl0) & ~0x80000000); /* Clr SWE */
219 mtspr (dbcr0, 0x20000000); /* Reset the chip */
wdenkc6097192002-11-03 00:24:07 +0000220
wdenka4685fe2003-09-03 14:03:26 +0000221 return 1;
wdenkc6097192002-11-03 00:24:07 +0000222}
223#endif
224
225
226/*
227 * Get timebase clock frequency
228 */
229unsigned long get_tbclk (void)
230{
231#if defined(CONFIG_440)
232
233 sys_info_t sys_info;
234
235 get_sys_info(&sys_info);
236 return (sys_info.freqProcessor);
237
stroese434979e2003-05-23 11:18:02 +0000238#elif defined(CONFIG_405GP) || \
239 defined(CONFIG_405CR) || \
240 defined(CONFIG_405) || \
241 defined(CONFIG_405EP)
wdenkc6097192002-11-03 00:24:07 +0000242
243 PPC405_SYS_INFO sys_info;
244
245 get_sys_info(&sys_info);
246 return (sys_info.freqProcessor);
247
248#elif defined(CONFIG_IOP480)
249
250 return (66000000);
251
252#else
253
254# error get_tbclk() not implemented
255
256#endif
257
258}
259
260
261#if defined(CONFIG_WATCHDOG)
262void
263watchdog_reset(void)
264{
265 int re_enable = disable_interrupts();
266 reset_4xx_watchdog();
267 if (re_enable) enable_interrupts();
268}
269
270void
271reset_4xx_watchdog(void)
272{
273 /*
274 * Clear TSR(WIS) bit
275 */
276 mtspr(tsr, 0x40000000);
277}
278#endif /* CONFIG_WATCHDOG */