]> git.sur5r.net Git - u-boot/blob - cpu/74xx_7xx/cpu.c
Convert mpc7448hpc2 to CONFIG_OF_LIBFDT
[u-boot] / cpu / 74xx_7xx / cpu.c
1 /*
2  * (C) Copyright 2001
3  * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
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.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  * more modifications by
36  * Josh Huber <huber@mclx.com>
37  * added support for the 74xx series of cpus
38  * added support for the 7xx series of cpus
39  * made the code a little less hard-coded, and more auto-detectish
40  */
41
42 #include <common.h>
43 #include <command.h>
44 #include <74xx_7xx.h>
45 #include <asm/cache.h>
46
47 #if defined(CONFIG_OF_LIBFDT)
48 #include <libfdt.h>
49 #include <fdt_support.h>
50 #endif
51
52 #if defined(CONFIG_OF_FLAT_TREE)
53 #include <ft_build.h>
54 #endif
55
56 #ifdef CONFIG_AMIGAONEG3SE
57 #include "../board/MAI/AmigaOneG3SE/via686.h"
58 #include "../board/MAI/AmigaOneG3SE/memio.h"
59 #endif
60
61 DECLARE_GLOBAL_DATA_PTR;
62
63 cpu_t
64 get_cpu_type(void)
65 {
66         uint pvr = get_pvr();
67         cpu_t type;
68
69         type = CPU_UNKNOWN;
70
71         switch (PVR_VER(pvr)) {
72         case 0x000c:
73                 type = CPU_7400;
74                 break;
75         case 0x0008:
76                 type = CPU_750;
77
78                 if (((pvr >> 8) & 0xff) == 0x01) {
79                         type = CPU_750CX;       /* old CX (80100 and 8010x?)*/
80                 } else if (((pvr >> 8) & 0xff) == 0x22) {
81                         type = CPU_750CX;       /* CX (82201,82202) and CXe (82214) */
82                 } else if (((pvr >> 8) & 0xff) == 0x33) {
83                         type = CPU_750CX;       /* CXe (83311) */
84                 } else if (((pvr >> 12) & 0xF) == 0x3) {
85                         type = CPU_755;
86                 }
87                 break;
88
89         case 0x7000:
90                 type = CPU_750FX;
91                 break;
92
93         case 0x7002:
94                 type = CPU_750GX;
95                 break;
96
97         case 0x800C:
98                 type = CPU_7410;
99                 break;
100
101         case 0x8000:
102                 type = CPU_7450;
103                 break;
104
105         case 0x8001:
106                 type = CPU_7455;
107                 break;
108
109         case 0x8002:
110                 type = CPU_7457;
111                 break;
112
113         case 0x8003:
114                 type = CPU_7447A;
115                 break;
116
117         case 0x8004:
118                 type = CPU_7448;
119                 break;
120
121         default:
122                 break;
123         }
124
125         return type;
126 }
127
128 /* ------------------------------------------------------------------------- */
129
130 #if !defined(CONFIG_BAB7xx)
131 int checkcpu (void)
132 {
133         uint type   = get_cpu_type();
134         uint pvr    = get_pvr();
135         ulong clock = gd->cpu_clk;
136         char buf[32];
137         char *str;
138
139         puts ("CPU:   ");
140
141         switch (type) {
142         case CPU_750CX:
143                 printf ("750CX%s v%d.%d", (pvr&0xf0)?"e":"",
144                         (pvr>>8) & 0xf,
145                         pvr & 0xf);
146                 goto    PR_CLK;
147
148         case CPU_750:
149                 str = "750";
150                 break;
151
152         case CPU_750FX:
153                 str = "750FX";
154                 break;
155
156         case CPU_750GX:
157                 str = "750GX";
158                 break;
159
160         case CPU_755:
161                 str = "755";
162                 break;
163
164         case CPU_7400:
165                 str = "MPC7400";
166                 break;
167
168         case CPU_7410:
169                 str = "MPC7410";
170                 break;
171
172         case CPU_7447A:
173                 str = "MPC7447A";
174                 break;
175
176         case CPU_7448:
177                 str = "MPC7448";
178                 break;
179
180         case CPU_7450:
181                 str = "MPC7450";
182                 break;
183
184         case CPU_7455:
185                 str = "MPC7455";
186                 break;
187
188         case CPU_7457:
189                 str = "MPC7457";
190                 break;
191
192         default:
193                 printf("Unknown CPU -- PVR: 0x%08x\n", pvr);
194                 return -1;
195         }
196
197         printf ("%s v%d.%d", str, (pvr >> 8) & 0xFF, pvr & 0xFF);
198 PR_CLK:
199         printf (" @ %s MHz\n", strmhz(buf, clock));
200
201         return (0);
202 }
203 #endif
204 /* these two functions are unimplemented currently [josh] */
205
206 /* -------------------------------------------------------------------- */
207 /* L1 i-cache                                                           */
208
209 int
210 checkicache(void)
211 {
212         return 0; /* XXX */
213 }
214
215 /* -------------------------------------------------------------------- */
216 /* L1 d-cache                                                           */
217
218 int
219 checkdcache(void)
220 {
221         return 0; /* XXX */
222 }
223
224 /* -------------------------------------------------------------------- */
225
226 static inline void
227 soft_restart(unsigned long addr)
228 {
229         /* SRR0 has system reset vector, SRR1 has default MSR value */
230         /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
231
232         __asm__ __volatile__ ("mtspr    26, %0"         :: "r" (addr));
233         __asm__ __volatile__ ("li       4, (1 << 6)"    ::: "r4");
234         __asm__ __volatile__ ("mtspr    27, 4");
235         __asm__ __volatile__ ("rfi");
236
237         while(1);       /* not reached */
238 }
239
240
241 #if !defined(CONFIG_PCIPPC2) && \
242     !defined(CONFIG_BAB7xx)  && \
243     !defined(CONFIG_ELPPC)   && \
244     !defined(CONFIG_PPMC7XX)
245 /* no generic way to do board reset. simply call soft_reset. */
246 void
247 do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
248 {
249         ulong addr;
250         /* flush and disable I/D cache */
251         __asm__ __volatile__ ("mfspr    3, 1008"        ::: "r3");
252         __asm__ __volatile__ ("ori      5, 5, 0xcc00"   ::: "r5");
253         __asm__ __volatile__ ("ori      4, 3, 0xc00"    ::: "r4");
254         __asm__ __volatile__ ("andc     5, 3, 5"        ::: "r5");
255         __asm__ __volatile__ ("sync");
256         __asm__ __volatile__ ("mtspr    1008, 4");
257         __asm__ __volatile__ ("isync");
258         __asm__ __volatile__ ("sync");
259         __asm__ __volatile__ ("mtspr    1008, 5");
260         __asm__ __volatile__ ("isync");
261         __asm__ __volatile__ ("sync");
262
263 #ifdef CFG_RESET_ADDRESS
264         addr = CFG_RESET_ADDRESS;
265 #else
266         /*
267          * note: when CFG_MONITOR_BASE points to a RAM address,
268          * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
269          * address. Better pick an address known to be invalid on your
270          * system and assign it to CFG_RESET_ADDRESS.
271          */
272         addr = CFG_MONITOR_BASE - sizeof (ulong);
273 #endif
274         soft_restart(addr);
275         while(1);       /* not reached */
276 }
277 #endif
278
279 /* ------------------------------------------------------------------------- */
280
281 /*
282  * For the 7400 the TB clock runs at 1/4 the cpu bus speed.
283  */
284 #if defined(CONFIG_AMIGAONEG3SE) || defined(CFG_CONFIG_BUS_CLK)
285 unsigned long get_tbclk(void)
286 {
287         return (gd->bus_clk / 4);
288 }
289 #else   /* ! CONFIG_AMIGAONEG3SE and !CFG_CONFIG_BUS_CLK*/
290
291 unsigned long get_tbclk (void)
292 {
293         return CFG_BUS_HZ / 4;
294 }
295 #endif  /* CONFIG_AMIGAONEG3SE or CFG_CONFIG_BUS_CLK*/
296 /* ------------------------------------------------------------------------- */
297 #if defined(CONFIG_WATCHDOG)
298 #if !defined(CONFIG_PCIPPC2) && !defined(CONFIG_BAB7xx)
299 void
300 watchdog_reset(void)
301 {
302
303 }
304 #endif  /* !CONFIG_PCIPPC2 && !CONFIG_BAB7xx */
305 #endif  /* CONFIG_WATCHDOG */
306
307 /* ------------------------------------------------------------------------- */
308
309 #ifdef CONFIG_OF_LIBFDT
310 void ft_cpu_setup(void *blob, bd_t *bd)
311 {
312         do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
313                              "timebase-frequency", bd->bi_busfreq / 4, 1);
314         do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
315                              "bus-frequency", bd->bi_busfreq, 1);
316         do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
317                              "clock-frequency", bd->bi_intfreq, 1);
318
319         fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
320
321         fdt_fixup_ethernet(blob, bd);
322 }
323 #endif
324 /* ------------------------------------------------------------------------- */