blob: 6cd54bf924d4f8c86d28fce92d320aa865d73bd5 [file] [log] [blame]
wdenk1df49e22002-09-17 21:37:55 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk1df49e22002-09-17 21:37:55 +00006 */
7
8/*
9 * cpu.c
10 *
11 * CPU specific code
12 *
13 * written or collected and sometimes rewritten by
14 * Magnus Damm <damm@bitsmart.com>
15 *
16 * minor modifications by
17 * Wolfgang Denk <wd@denx.de>
18 *
19 * more modifications by
20 * Josh Huber <huber@mclx.com>
21 * added support for the 74xx series of cpus
22 * added support for the 7xx series of cpus
23 * made the code a little less hard-coded, and more auto-detectish
24 */
25
26#include <common.h>
27#include <command.h>
28#include <74xx_7xx.h>
29#include <asm/cache.h>
30
Gerald Van Baren84714ba2008-06-03 20:24:58 -040031#if defined(CONFIG_OF_LIBFDT)
32#include <libfdt.h>
33#include <fdt_support.h>
34#endif
35
Wolfgang Denk6405a152006-03-31 18:32:53 +020036DECLARE_GLOBAL_DATA_PTR;
37
wdenk1df49e22002-09-17 21:37:55 +000038cpu_t
39get_cpu_type(void)
40{
41 uint pvr = get_pvr();
42 cpu_t type;
43
44 type = CPU_UNKNOWN;
45
46 switch (PVR_VER(pvr)) {
47 case 0x000c:
48 type = CPU_7400;
49 break;
50 case 0x0008:
51 type = CPU_750;
52
wdenkaaf48a92003-06-20 23:10:58 +000053 if (((pvr >> 8) & 0xff) == 0x01) {
wdenk1df49e22002-09-17 21:37:55 +000054 type = CPU_750CX; /* old CX (80100 and 8010x?)*/
55 } else if (((pvr >> 8) & 0xff) == 0x22) {
56 type = CPU_750CX; /* CX (82201,82202) and CXe (82214) */
57 } else if (((pvr >> 8) & 0xff) == 0x33) {
58 type = CPU_750CX; /* CXe (83311) */
59 } else if (((pvr >> 12) & 0xF) == 0x3) {
60 type = CPU_755;
wdenkaaf48a92003-06-20 23:10:58 +000061 }
wdenk1df49e22002-09-17 21:37:55 +000062 break;
63
wdenkaaf48a92003-06-20 23:10:58 +000064 case 0x7000:
65 type = CPU_750FX;
66 break;
67
wdenk5da7f2f2004-01-03 00:43:19 +000068 case 0x7002:
69 type = CPU_750GX;
70 break;
71
wdenk1df49e22002-09-17 21:37:55 +000072 case 0x800C:
73 type = CPU_7410;
74 break;
75
wdenkaaf48a92003-06-20 23:10:58 +000076 case 0x8000:
wdenk1df49e22002-09-17 21:37:55 +000077 type = CPU_7450;
78 break;
79
wdenk5da7f2f2004-01-03 00:43:19 +000080 case 0x8001:
81 type = CPU_7455;
82 break;
83
84 case 0x8002:
85 type = CPU_7457;
86 break;
87
roy zangd136d662006-11-02 18:49:51 +080088 case 0x8003:
89 type = CPU_7447A;
90 break;
roy zang373baf42006-12-01 19:01:25 +080091
roy zangd136d662006-11-02 18:49:51 +080092 case 0x8004:
93 type = CPU_7448;
94 break;
roy zang373baf42006-12-01 19:01:25 +080095
wdenk1df49e22002-09-17 21:37:55 +000096 default:
97 break;
98 }
99
100 return type;
101}
102
103/* ------------------------------------------------------------------------- */
104
105#if !defined(CONFIG_BAB7xx)
106int checkcpu (void)
107{
wdenk1df49e22002-09-17 21:37:55 +0000108 uint type = get_cpu_type();
109 uint pvr = get_pvr();
110 ulong clock = gd->cpu_clk;
111 char buf[32];
112 char *str;
113
114 puts ("CPU: ");
115
116 switch (type) {
117 case CPU_750CX:
118 printf ("750CX%s v%d.%d", (pvr&0xf0)?"e":"",
119 (pvr>>8) & 0xf,
120 pvr & 0xf);
121 goto PR_CLK;
122
123 case CPU_750:
124 str = "750";
125 break;
126
wdenkaaf48a92003-06-20 23:10:58 +0000127 case CPU_750FX:
128 str = "750FX";
129 break;
130
wdenk5da7f2f2004-01-03 00:43:19 +0000131 case CPU_750GX:
132 str = "750GX";
133 break;
134
wdenk1df49e22002-09-17 21:37:55 +0000135 case CPU_755:
136 str = "755";
137 break;
138
139 case CPU_7400:
140 str = "MPC7400";
141 break;
142
wdenkaaf48a92003-06-20 23:10:58 +0000143 case CPU_7410:
144 str = "MPC7410";
wdenk1df49e22002-09-17 21:37:55 +0000145 break;
146
roy zang373baf42006-12-01 19:01:25 +0800147 case CPU_7447A:
148 str = "MPC7447A";
149 break;
150
Stefan Roese45993ea2006-11-29 15:42:37 +0100151 case CPU_7448:
152 str = "MPC7448";
153 break;
154
wdenkaaf48a92003-06-20 23:10:58 +0000155 case CPU_7450:
156 str = "MPC7450";
wdenk1df49e22002-09-17 21:37:55 +0000157 break;
158
wdenk5da7f2f2004-01-03 00:43:19 +0000159 case CPU_7455:
160 str = "MPC7455";
161 break;
162
163 case CPU_7457:
164 str = "MPC7457";
165 break;
166
wdenk1df49e22002-09-17 21:37:55 +0000167 default:
wdenkaaf48a92003-06-20 23:10:58 +0000168 printf("Unknown CPU -- PVR: 0x%08x\n", pvr);
wdenk1df49e22002-09-17 21:37:55 +0000169 return -1;
170 }
171
172 printf ("%s v%d.%d", str, (pvr >> 8) & 0xFF, pvr & 0xFF);
173PR_CLK:
174 printf (" @ %s MHz\n", strmhz(buf, clock));
175
176 return (0);
177}
178#endif
179/* these two functions are unimplemented currently [josh] */
180
wdenkaaf48a92003-06-20 23:10:58 +0000181/* -------------------------------------------------------------------- */
182/* L1 i-cache */
wdenk1df49e22002-09-17 21:37:55 +0000183
184int
185checkicache(void)
186{
187 return 0; /* XXX */
188}
189
wdenkaaf48a92003-06-20 23:10:58 +0000190/* -------------------------------------------------------------------- */
191/* L1 d-cache */
wdenk1df49e22002-09-17 21:37:55 +0000192
193int
194checkdcache(void)
195{
196 return 0; /* XXX */
197}
198
wdenkaaf48a92003-06-20 23:10:58 +0000199/* -------------------------------------------------------------------- */
wdenk1df49e22002-09-17 21:37:55 +0000200
201static inline void
202soft_restart(unsigned long addr)
203{
204 /* SRR0 has system reset vector, SRR1 has default MSR value */
205 /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
206
207 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
208 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
209 __asm__ __volatile__ ("mtspr 27, 4");
210 __asm__ __volatile__ ("rfi");
211
212 while(1); /* not reached */
213}
214
215
Stefan Roese39cf43f2013-02-07 01:48:30 +0000216#if !defined(CONFIG_BAB7xx) && \
Heiko Schocherd7f77fb2006-06-19 11:02:41 +0200217 !defined(CONFIG_ELPPC) && \
218 !defined(CONFIG_PPMC7XX)
wdenk1df49e22002-09-17 21:37:55 +0000219/* no generic way to do board reset. simply call soft_reset. */
Peter Tyser693d6382010-12-03 10:28:47 -0600220int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk1df49e22002-09-17 21:37:55 +0000221{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100222 ulong addr;
wdenk1df49e22002-09-17 21:37:55 +0000223 /* flush and disable I/D cache */
224 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
225 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
226 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
227 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
228 __asm__ __volatile__ ("sync");
229 __asm__ __volatile__ ("mtspr 1008, 4");
230 __asm__ __volatile__ ("isync");
231 __asm__ __volatile__ ("sync");
232 __asm__ __volatile__ ("mtspr 1008, 5");
233 __asm__ __volatile__ ("isync");
234 __asm__ __volatile__ ("sync");
235
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200236#ifdef CONFIG_SYS_RESET_ADDRESS
237 addr = CONFIG_SYS_RESET_ADDRESS;
wdenk1df49e22002-09-17 21:37:55 +0000238#else
239 /*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200240 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
241 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid
wdenk1df49e22002-09-17 21:37:55 +0000242 * address. Better pick an address known to be invalid on your
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200243 * system and assign it to CONFIG_SYS_RESET_ADDRESS.
wdenk1df49e22002-09-17 21:37:55 +0000244 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200245 addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
wdenk1df49e22002-09-17 21:37:55 +0000246#endif
247 soft_restart(addr);
Peter Tyser693d6382010-12-03 10:28:47 -0600248
249 /* not reached */
250 while(1)
251 ;
252
253 return 1;
wdenk1df49e22002-09-17 21:37:55 +0000254}
255#endif
256
257/* ------------------------------------------------------------------------- */
258
259/*
260 * For the 7400 the TB clock runs at 1/4 the cpu bus speed.
261 */
Wolfgang Denkb0b104a2010-06-13 18:28:54 +0200262#ifndef CONFIG_SYS_BUS_CLK
Wolfgang Denk7329f252010-06-13 18:38:23 +0200263#define CONFIG_SYS_BUS_CLK gd->bus_clk
264#endif
265
wdenk452cfd62002-11-19 11:04:11 +0000266unsigned long get_tbclk(void)
wdenk1df49e22002-09-17 21:37:55 +0000267{
Wolfgang Denk7329f252010-06-13 18:38:23 +0200268 return CONFIG_SYS_BUS_CLK / 4;
wdenk1df49e22002-09-17 21:37:55 +0000269}
270
wdenk1df49e22002-09-17 21:37:55 +0000271/* ------------------------------------------------------------------------- */
Wolfgang Denk7329f252010-06-13 18:38:23 +0200272
wdenk1df49e22002-09-17 21:37:55 +0000273#if defined(CONFIG_WATCHDOG)
Stefan Roese39cf43f2013-02-07 01:48:30 +0000274#if !defined(CONFIG_BAB7xx)
wdenk1df49e22002-09-17 21:37:55 +0000275void
276watchdog_reset(void)
277{
278
279}
Stefan Roese39cf43f2013-02-07 01:48:30 +0000280#endif /* !CONFIG_BAB7xx */
wdenk1df49e22002-09-17 21:37:55 +0000281#endif /* CONFIG_WATCHDOG */
282
283/* ------------------------------------------------------------------------- */
roy zangd136d662006-11-02 18:49:51 +0800284
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400285#ifdef CONFIG_OF_LIBFDT
286void ft_cpu_setup(void *blob, bd_t *bd)
roy zangd136d662006-11-02 18:49:51 +0800287{
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400288 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
289 "timebase-frequency", bd->bi_busfreq / 4, 1);
290 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
291 "bus-frequency", bd->bi_busfreq, 1);
292 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
293 "clock-frequency", bd->bi_intfreq, 1);
Wolfgang Denkf972e772007-03-04 01:36:05 +0100294
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400295 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Wolfgang Denkf972e772007-03-04 01:36:05 +0100296
Kumar Galafabda922008-08-19 15:41:18 -0500297 fdt_fixup_ethernet(blob);
roy zangd136d662006-11-02 18:49:51 +0800298}
299#endif
300/* ------------------------------------------------------------------------- */