1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <common.h>
20#include <cpu_func.h>
21#include <net.h>
22#include <time.h>
23#include <vsprintf.h>
24#include <watchdog.h>
25#include <command.h>
26#include <mpc8xx.h>
27#include <netdev.h>
28#include <asm/cache.h>
29#include <asm/cpm_8xx.h>
30#include <asm/global_data.h>
31#include <linux/compiler.h>
32#include <asm/io.h>
33
34#if defined(CONFIG_OF_LIBFDT)
35#include <linux/libfdt.h>
36#include <fdt_support.h>
37#endif
38
39DECLARE_GLOBAL_DATA_PTR;
40
41
42
43
44int checkicache(void)
45{
46 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
47 memctl8xx_t __iomem *memctl = &immap->im_memctl;
48 u32 cacheon = rd_ic_cst() & IDC_ENABLED;
49
50 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
51 u32 m;
52 u32 lines = -1;
53
54 wr_ic_cst(IDC_UNALL);
55 wr_ic_cst(IDC_INVALL);
56 wr_ic_cst(IDC_DISABLE);
57 __asm__ volatile ("isync");
58
59 while (!((m = rd_ic_cst()) & IDC_CERR2)) {
60 wr_ic_adr(k);
61 wr_ic_cst(IDC_LDLCK);
62 __asm__ volatile ("isync");
63
64 lines++;
65 k += 0x10;
66 }
67
68 wr_ic_cst(IDC_UNALL);
69 wr_ic_cst(IDC_INVALL);
70
71 if (cacheon)
72 wr_ic_cst(IDC_ENABLE);
73 else
74 wr_ic_cst(IDC_DISABLE);
75
76 __asm__ volatile ("isync");
77
78 return lines << 4;
79};
80
81
82
83
84
85static int checkdcache(void)
86{
87 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
88 memctl8xx_t __iomem *memctl = &immap->im_memctl;
89 u32 cacheon = rd_dc_cst() & IDC_ENABLED;
90
91 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
92 u32 m;
93 u32 lines = -1;
94
95 wr_dc_cst(IDC_UNALL);
96 wr_dc_cst(IDC_INVALL);
97 wr_dc_cst(IDC_DISABLE);
98
99 while (!((m = rd_dc_cst()) & IDC_CERR2)) {
100 wr_dc_adr(k);
101 wr_dc_cst(IDC_LDLCK);
102 lines++;
103 k += 0x10;
104 }
105
106 wr_dc_cst(IDC_UNALL);
107 wr_dc_cst(IDC_INVALL);
108
109 if (cacheon)
110 wr_dc_cst(IDC_ENABLE);
111 else
112 wr_dc_cst(IDC_DISABLE);
113
114 return lines << 4;
115};
116
117static int check_CPU(long clock, uint pvr, uint immr)
118{
119 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
120 uint k;
121 char buf[32];
122
123
124
125 if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
126 return -1;
127
128 k = (immr << 16) |
129 in_be16(&immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
130
131
132
133
134
135 switch (k) {
136
137 case 0x08010004:
138 printf("MPC866xxxZPnnA");
139 break;
140 case 0x08000003:
141 printf("MPC866xxxZPnn");
142 break;
143 case 0x09000000:
144 puts("MPC885ZPnn");
145 break;
146
147 default:
148 printf("unknown MPC86x (0x%08x)", k);
149 break;
150 }
151
152 printf(" at %s MHz: ", strmhz(buf, clock));
153
154 print_size(checkicache(), " I-Cache ");
155 print_size(checkdcache(), " D-Cache");
156
157
158
159 out_be32(&immap->im_cpm.cp_fec.fec_addr_low, 0x12345678);
160 if (in_be32(&immap->im_cpm.cp_fec.fec_addr_low) == 0x12345678)
161 printf(" FEC present");
162
163 putc('\n');
164
165 return 0;
166}
167
168
169
170int checkcpu(void)
171{
172 ulong clock = gd->cpu_clk;
173 uint immr = get_immr();
174 uint pvr = get_pvr();
175
176 puts("CPU: ");
177
178 return check_CPU(clock, pvr, immr);
179}
180
181
182
183void upmconfig(uint upm, uint *table, uint size)
184{
185 uint i;
186 uint addr = 0;
187 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
188 memctl8xx_t __iomem *memctl = &immap->im_memctl;
189
190 for (i = 0; i < size; i++) {
191 out_be32(&memctl->memc_mdr, table[i]);
192 out_be32(&memctl->memc_mcr, addr | upm);
193 addr++;
194 }
195}
196
197
198
199int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
200{
201 ulong msr, addr;
202
203 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
204
205
206 setbits_be32(&immap->im_clkrst.car_plprcr, PLPRCR_CSR);
207
208
209 __asm__ volatile ("mtspr 81, 0");
210 __asm__ volatile ("mfmsr %0" : "=r" (msr));
211
212 msr &= ~0x1030;
213 __asm__ volatile ("mtmsr %0" : : "r" (msr));
214
215
216
217
218
219#ifdef CONFIG_SYS_RESET_ADDRESS
220 addr = CONFIG_SYS_RESET_ADDRESS;
221#else
222
223
224
225
226
227
228
229 addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
230#endif
231 ((void (*)(void)) addr)();
232 return 1;
233}
234
235
236
237
238
239
240
241
242unsigned long get_tbclk(void)
243{
244 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
245 ulong oscclk, factor, pll;
246
247 if (in_be32(&immap->im_clkrst.car_sccr) & SCCR_TBS)
248 return gd->cpu_clk / 16;
249
250 pll = in_be32(&immap->im_clkrst.car_plprcr);
251
252#define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
253
254
255
256
257
258
259
260
261
262
263
264
265 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN) / (PLPRCR_val(MFD) + 1)) /
266 (PLPRCR_val(PDF) + 1) / (1 << PLPRCR_val(S));
267
268 oscclk = gd->cpu_clk / factor;
269
270 if ((in_be32(&immap->im_clkrst.car_sccr) & SCCR_RTSEL) == 0 ||
271 factor > 2)
272 return oscclk / 4;
273
274 return oscclk / 16;
275}
276
277
278
279
280
281int cpu_eth_init(struct bd_info *bis)
282{
283#if defined(CONFIG_MPC8XX_FEC)
284 fec_initialize(bis);
285#endif
286 return 0;
287}
288