1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <common.h>
23#include <command.h>
24#include <mpc5xxx.h>
25#include <pci.h>
26#include <miiphy.h>
27#include <linux/compiler.h>
28#include <asm/processor.h>
29#include <asm/io.h>
30
31#ifdef CONFIG_A4M2K
32#include "is46r16320d.h"
33#else
34#include "mt46v16m16-75.h"
35#endif
36
37DECLARE_GLOBAL_DATA_PTR;
38
39#if !defined(CONFIG_SYS_RAMBOOT) && \
40 (defined(CONFIG_SPL) && defined(CONFIG_SPL_BUILD))
41static void sdram_start(int hi_addr)
42{
43 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
44 long control = SDRAM_CONTROL | hi_addr_bit;
45
46
47 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
48
49
50 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
51
52#ifdef SDRAM_DDR
53
54 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_EMODE);
55
56
57 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE | 0x04000000);
58#endif
59
60
61 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
62
63
64 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
65
66
67 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
68
69
70 out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
71
72
73
74
75
76 udelay(100);
77}
78#endif
79
80
81
82
83
84
85phys_size_t initdram(int board_type)
86{
87 ulong dramsize = 0;
88 ulong dramsize2 = 0;
89 uint svr, pvr;
90#if !defined(CONFIG_SYS_RAMBOOT) && \
91 (defined(CONFIG_SPL) && defined(CONFIG_SPL_BUILD))
92 ulong test1, test2;
93
94
95 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001e);
96 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000);
97
98
99 out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
100 out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
101
102#ifdef SDRAM_DDR
103
104 out_be32((void *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
105#endif
106
107
108 sdram_start(0);
109 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
110 sdram_start(1);
111 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
112 if (test1 > test2) {
113 sdram_start(0);
114 dramsize = test1;
115 } else {
116 dramsize = test2;
117 }
118
119
120 if (dramsize < (1 << 20))
121 dramsize = 0;
122
123
124 if (dramsize > 0) {
125 out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
126 0x13 + __builtin_ffs(dramsize >> 20) - 1);
127 } else {
128 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0);
129 }
130#else
131
132
133 dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
134 if (dramsize >= 0x13)
135 dramsize = (1 << (dramsize - 0x13)) << 20;
136 else
137 dramsize = 0;
138
139
140 dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
141 if (dramsize2 >= 0x13)
142 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
143 else
144 dramsize2 = 0;
145
146#endif
147
148
149
150
151
152
153
154
155
156
157 svr = get_svr();
158 pvr = get_pvr();
159 if ((SVR_MJREV(svr) >= 2) && (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
160 out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
161
162 return dramsize + dramsize2;
163}
164
165static void get_revisions(int *failsavelevel, int *digiboardversion,
166 int *fpgaversion)
167{
168 struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
169 u8 val;
170
171
172 val = 0;
173 val |= (gpt->gpt2.sr & (1 << (31 - 23))) ? (1) : 0;
174 val |= (gpt->gpt3.sr & (1 << (31 - 23))) ? (1 << 1) : 0;
175 val |= (gpt->gpt4.sr & (1 << (31 - 23))) ? (1 << 2) : 0;
176 *digiboardversion = val;
177
178
179
180
181
182#if !defined(CONFIG_A4M2K)
183
184
185
186
187 *failsavelevel = 0;
188
189 if (*digiboardversion == 0) {
190 *failsavelevel = 1;
191
192
193 val = 0;
194 val |= (gpt->gpt5.sr & (1 << (31 - 23))) ? (1) : 0;
195 val |= (gpt->gpt6.sr & (1 << (31 - 23))) ? (1 << 1) : 0;
196 val |= (gpt->gpt7.sr & (1 << (31 - 23))) ? (1 << 2) : 0;
197 *fpgaversion = val;
198
199 if (*fpgaversion == 1)
200 *failsavelevel = 2;
201 }
202#endif
203}
204
205
206
207
208
209
210
211void spl_board_init(void)
212{
213 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
214 struct mpc5xxx_mmap_ctl *mm =
215 (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
216
217#if defined(CONFIG_A4M2K)
218
219 setbits_be32(&mm->ipbi_ws_ctrl, (1 << 19) | (1 << 21));
220#else
221 int digiboardversion;
222 int failsavelevel;
223 int fpgaversion;
224 u32 val;
225
226 get_revisions(&failsavelevel, &digiboardversion, &fpgaversion);
227
228 val = in_be32(&mm->ipbi_ws_ctrl);
229
230
231 val &= ~((1 << 19) | (1 << 20) | (1 << 21));
232 if (failsavelevel == 2) {
233
234 val |= (1 << 19) | (1 << 21);
235 }
236
237 if (failsavelevel >= 1) {
238
239 val |= (1 << 20);
240 }
241
242
243 out_be32(&mm->ipbi_ws_ctrl, val);
244#endif
245
246
247
248
249
250
251
252
253
254
255
256
257
258 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, CONFIG_WDOG_GPIO_PIN);
259
260#if defined(CONFIG_A4M2K)
261
262
263
264 gpio->simple_ddr |= 1 << (31 - 15);
265 gpio->simple_ddr |= 1 << (31 - 14);
266 gpio->simple_ddr |= 1 << (31 - 13);
267 gpio->simple_ddr |= 1 << (31 - 12);
268
269
270 gpio->simple_gpioe |= 1 << (31 - 15);
271 gpio->simple_gpioe |= 1 << (31 - 14);
272 gpio->simple_gpioe |= 1 << (31 - 13);
273 gpio->simple_gpioe |= 1 << (31 - 12);
274
275
276
277
278 gpio->simple_ddr |= 1 << (31 - 27);
279 gpio->simple_ddr |= 1 << (31 - 26);
280 gpio->simple_ddr |= 1 << (31 - 25);
281
282
283 gpio->simple_gpioe |= 1 << (31 - 27);
284 gpio->simple_gpioe |= 1 << (31 - 26);
285 gpio->simple_gpioe |= 1 << (31 - 25);
286
287
288
289
290 gpio->simple_ddr |= 1 << (31 - 3);
291
292
293 gpio->simple_ode |= 1 << (31 - 3);
294
295
296 gpio->simple_dvo |= 1 << (31 - 3);
297
298
299 gpio->simple_gpioe |= 1 << (31 - 3);
300
301
302
303
304 gpio->simple_ddr |= 0 << (31 - 2);
305
306
307 gpio->simple_gpioe |= 1 << (31 - 2);
308#else
309
310 if (failsavelevel > 0) {
311
312
313 gpio->simple_dvo |= 1 << (31 - 12);
314 gpio->simple_dvo |= 1 << (31 - 13);
315
316 gpio->simple_ddr |= 1 << (31 - 12);
317 gpio->simple_ddr |= 1 << (31 - 13);
318
319
320
321
322 gpio->simple_gpioe |= 1 << (31 - 12);
323 gpio->simple_gpioe |= 1 << (31 - 13);
324 }
325
326
327 if (failsavelevel > 1) {
328
329
330
331
332 struct mpc5xxx_intr *intr =
333 (struct mpc5xxx_intr *)(MPC5XXX_ICTL);
334
335 setbits_be32(&intr->ctrl, 0x08C01801);
336
337
338
339
340
341 }
342#endif
343}
344
345int checkboard(void)
346{
347 int digiboardversion;
348 int failsavelevel;
349 int fpgaversion;
350
351 get_revisions(&failsavelevel, &digiboardversion, &fpgaversion);
352
353#ifdef CONFIG_A4M2K
354 puts("Board: A4M2K\n");
355 printf(" digiboard IO version %u\n", digiboardversion);
356#else
357 puts("Board: A3M071\n");
358 printf("Rev: failsave level %u\n", failsavelevel);
359 printf(" digiboard IO version %u\n", digiboardversion);
360 if (failsavelevel > 0)
361 printf(" fpga IO version %u\n", fpgaversion);
362#endif
363
364 return 0;
365}
366
367
368int misc_init_r(void)
369{
370
371 gd->bd->bi_flashstart = flash_info[0].start[0];
372 gd->bd->bi_flashoffset = 0;
373
374
375 out_be32((void *)MPC5XXX_BOOTCS_START,
376 START_REG(gd->bd->bi_flashstart));
377 out_be32((void *)MPC5XXX_CS0_START, START_REG(gd->bd->bi_flashstart));
378 out_be32((void *)MPC5XXX_BOOTCS_STOP,
379 STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize));
380 out_be32((void *)MPC5XXX_CS0_STOP,
381 STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize));
382
383 return 0;
384}
385
386#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
387void ft_board_setup(void *blob, bd_t * bd)
388{
389 ft_cpu_setup(blob, bd);
390}
391#endif
392
393#ifdef CONFIG_SPL_OS_BOOT
394
395
396
397
398
399
400
401int spl_start_uboot(void)
402{
403 char s[8];
404
405 env_init();
406 getenv_f("boot_os", s, sizeof(s));
407 if ((s != NULL) && (strcmp(s, "yes") == 0))
408 return 0;
409
410 return 1;
411}
412#endif
413
414#if defined(CONFIG_HW_WATCHDOG)
415static int watchdog_toggle;
416
417void hw_watchdog_reset(void)
418{
419 int val;
420
421
422
423
424 if ((gd->flags & GD_FLG_RELOC) && watchdog_toggle) {
425
426 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, CONFIG_WDOG_GPIO_PIN);
427
428
429
430
431 val = (in_be32((void *)MPC5XXX_WU_GPIO_DATA_O) &
432 CONFIG_WDOG_GPIO_PIN);
433 if (val) {
434 clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O,
435 CONFIG_WDOG_GPIO_PIN);
436 } else {
437 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O,
438 CONFIG_WDOG_GPIO_PIN);
439 }
440 }
441}
442
443int do_wdog_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
444{
445 if (argc != 2)
446 goto usage;
447
448 if (strncmp(argv[1], "on", 2) == 0)
449 watchdog_toggle = 1;
450 else if (strncmp(argv[1], "off", 3) == 0)
451 watchdog_toggle = 0;
452 else
453 goto usage;
454
455 return 0;
456usage:
457 printf("Usage: wdogtoggle %s\n", cmdtp->usage);
458 return 1;
459}
460
461U_BOOT_CMD(
462 wdogtoggle, CONFIG_SYS_MAXARGS, 2, do_wdog_toggle,
463 "toggle GPIO pin to service watchdog",
464 "[on/off] - Switch watchdog toggling via GPIO pin on/off"
465);
466#endif
467