1
2
3
4
5
6
7
8#include <common.h>
9#include <hwconfig.h>
10#include <mpc8xx.h>
11#ifdef CONFIG_PS2MULT
12#include <ps2mult.h>
13#endif
14
15#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
16#include <libfdt.h>
17#endif
18
19extern flash_info_t flash_info[];
20
21DECLARE_GLOBAL_DATA_PTR;
22
23static long int dram_size (long int, long int *, long int);
24
25#define _NOT_USED_ 0xFFFFFFFF
26
27
28const uint sdram_table[] =
29{
30
31
32
33 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
34 0x1FF5FC47,
35
36
37
38
39
40
41
42
43 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35,
44
45
46
47 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
48 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47,
49 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
50 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
51
52
53
54 0x1F0DFC04, 0xEEABBC00, 0x11B77C04, 0xEFFAFC44,
55 0x1FF5FC47,
56 _NOT_USED_, _NOT_USED_, _NOT_USED_,
57
58
59
60 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
61 0xF0AFFC00, 0xF0AFFC04, 0xE1BAFC44, 0x1FF5FC47,
62 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
63 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
64
65
66
67 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
68 0xFFFFFC84, 0xFFFFFC07,
69 _NOT_USED_, _NOT_USED_,
70 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
71
72
73
74 0xFFFFFC07,
75 _NOT_USED_, _NOT_USED_, _NOT_USED_,
76};
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91int checkboard (void)
92{
93 char buf[64];
94 int i;
95 int l = getenv_f("serial#", buf, sizeof(buf));
96
97 puts ("Board: ");
98
99 if (l < 0 || strncmp(buf, "TQM8", 4)) {
100 puts ("### No HW ID - assuming TQM8xxL\n");
101 return (0);
102 }
103
104 if ((buf[6] == 'L')) {
105 gd->board_type = 'L';
106 }
107
108 if ((buf[6] == 'M')) {
109 gd->board_type = 'M';
110 }
111
112 if ((buf[6] == 'D')) {
113 gd->board_type = 'D';
114 }
115
116 for (i = 0; i < l; ++i) {
117 if (buf[i] == ' ')
118 break;
119 putc (buf[i]);
120 }
121
122 putc ('\n');
123
124 return (0);
125}
126
127
128
129phys_size_t initdram (int board_type)
130{
131 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
132 volatile memctl8xx_t *memctl = &immap->im_memctl;
133 long int size8, size9, size10;
134 long int size_b0 = 0;
135 long int size_b1 = 0;
136
137 upmconfig (UPMA, (uint *) sdram_table,
138 sizeof (sdram_table) / sizeof (uint));
139
140
141
142
143
144
145
146 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 memctl->memc_mar = 0x00000088;
162
163
164
165
166
167
168 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
169 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
170
171#ifndef CONFIG_CAN_DRIVER
172 if ((board_type != 'L') &&
173 (board_type != 'M') &&
174 (board_type != 'D') ) {
175 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
176 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
177 }
178#endif
179
180 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE));
181
182 udelay (200);
183
184
185
186 memctl->memc_mcr = 0x80004105;
187 udelay (1);
188 memctl->memc_mcr = 0x80004230;
189 udelay (1);
190
191#ifndef CONFIG_CAN_DRIVER
192 if ((board_type != 'L') &&
193 (board_type != 'M') &&
194 (board_type != 'D') ) {
195 memctl->memc_mcr = 0x80006105;
196 udelay (1);
197 memctl->memc_mcr = 0x80006230;
198 udelay (1);
199 }
200#endif
201
202 memctl->memc_mamr |= MAMR_PTAE;
203
204 udelay (1000);
205
206
207
208
209
210
211 size8 = dram_size (CONFIG_SYS_MAMR_8COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
212 debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size8 >> 20);
213
214 udelay (1000);
215
216
217
218
219 size9 = dram_size (CONFIG_SYS_MAMR_9COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
220 debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size9 >> 20);
221
222 udelay(1000);
223
224#if defined(CONFIG_SYS_MAMR_10COL)
225
226
227
228 size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
229 debug ("SDRAM Bank 0 in 10 column mode: %ld MB\n", size10 >> 20);
230#else
231 size10 = 0;
232#endif
233
234 if ((size8 < size10) && (size9 < size10)) {
235 size_b0 = size10;
236 } else if ((size8 < size9) && (size10 < size9)) {
237 size_b0 = size9;
238 memctl->memc_mamr = CONFIG_SYS_MAMR_9COL;
239 udelay (500);
240 } else {
241 size_b0 = size8;
242 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
243 udelay (500);
244 }
245 debug ("SDRAM Bank 0: %ld MB\n", size_b0 >> 20);
246
247#ifndef CONFIG_CAN_DRIVER
248 if ((board_type != 'L') &&
249 (board_type != 'M') &&
250 (board_type != 'D') ) {
251
252
253
254
255
256
257 size_b1 = dram_size (memctl->memc_mamr, (long int *)SDRAM_BASE3_PRELIM,
258 SDRAM_MAX_SIZE);
259 debug ("SDRAM Bank 1: %ld MB\n", size_b1 >> 20);
260 } else {
261 size_b1 = 0;
262 }
263#endif
264
265 udelay (1000);
266
267
268
269
270
271 if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
272
273 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
274 udelay (1000);
275 }
276
277
278
279
280 if (size_b1 > size_b0) {
281
282 memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
283 memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
284
285 if (size_b0 > 0) {
286
287
288
289 memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
290 memctl->memc_br2 = ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
291 + size_b1;
292 } else {
293 unsigned long reg;
294
295
296
297
298
299
300 memctl->memc_br2 = 0;
301
302
303 reg = memctl->memc_mptpr;
304 reg >>= 1;
305 memctl->memc_mptpr = reg;
306 }
307
308 } else {
309
310 memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
311 memctl->memc_br2 =
312 (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
313
314 if (size_b1 > 0) {
315
316
317
318 memctl->memc_or3 =
319 ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
320 memctl->memc_br3 =
321 ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
322 + size_b0;
323 } else {
324 unsigned long reg;
325
326#ifndef CONFIG_CAN_DRIVER
327
328
329
330
331
332 memctl->memc_br3 = 0;
333#endif
334
335
336 reg = memctl->memc_mptpr;
337 reg >>= 1;
338 memctl->memc_mptpr = reg;
339 }
340 }
341
342 udelay (10000);
343
344#ifdef CONFIG_CAN_DRIVER
345
346
347
348 memctl->memc_or3 = CONFIG_SYS_OR3_CAN;
349 memctl->memc_br3 = CONFIG_SYS_BR3_CAN;
350
351
352 memctl->memc_mbmr = MBMR_GPL_B4DIS;
353
354
355 memctl->memc_mdr = 0xFFFFCC04;
356 memctl->memc_mcr = 0x0100 | UPMB;
357
358 memctl->memc_mdr = 0x0FFFD004;
359 memctl->memc_mcr = 0x0101 | UPMB;
360
361 memctl->memc_mdr = 0x0FFFC000;
362 memctl->memc_mcr = 0x0102 | UPMB;
363
364 memctl->memc_mdr = 0x3FFFC004;
365 memctl->memc_mcr = 0x0103 | UPMB;
366
367 memctl->memc_mdr = 0xFFFFDC07;
368 memctl->memc_mcr = 0x0104 | UPMB;
369
370
371 memctl->memc_mdr = 0xFFFCCC04;
372 memctl->memc_mcr = 0x0118 | UPMB;
373
374 memctl->memc_mdr = 0xCFFCDC04;
375 memctl->memc_mcr = 0x0119 | UPMB;
376
377 memctl->memc_mdr = 0x3FFCC000;
378 memctl->memc_mcr = 0x011A | UPMB;
379
380 memctl->memc_mdr = 0xFFFCC004;
381 memctl->memc_mcr = 0x011B | UPMB;
382
383 memctl->memc_mdr = 0xFFFDC405;
384 memctl->memc_mcr = 0x011C | UPMB;
385#endif
386
387#ifdef CONFIG_ISP1362_USB
388
389 memctl->memc_or5 = CONFIG_SYS_OR5_ISP1362;
390 memctl->memc_br5 = CONFIG_SYS_BR5_ISP1362;
391#endif
392 return (size_b0 + size_b1);
393}
394
395
396
397
398
399
400
401
402
403
404
405static long int dram_size (long int mamr_value, long int *base, long int maxsize)
406{
407 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
408 volatile memctl8xx_t *memctl = &immap->im_memctl;
409
410 memctl->memc_mamr = mamr_value;
411
412 return (get_ram_size(base, maxsize));
413}
414
415
416
417#ifdef CONFIG_MISC_INIT_R
418extern void load_sernum_ethaddr(void);
419int misc_init_r (void)
420{
421 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
422 volatile memctl8xx_t *memctl = &immap->im_memctl;
423
424 load_sernum_ethaddr();
425
426#ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
427 int scy, trlx, flash_or_timing, clk_diff;
428
429 scy = (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_SCY_MSK) >> 4;
430 if (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_TRLX) {
431 trlx = OR_TRLX;
432 scy *= 2;
433 } else {
434 trlx = 0;
435 }
436
437
438
439
440
441 clk_diff = (gd->bus_clk / 1000000) - 50;
442
443
444
445
446
447 if (clk_diff >= 0)
448 scy += (clk_diff + 5) / 10;
449 else
450 scy += (clk_diff - 5) / 10;
451
452
453
454
455
456 if (gd->bus_clk >= 50000000)
457 trlx = OR_TRLX;
458 else
459 trlx = 0;
460
461 if (trlx)
462 scy /= 2;
463
464 if (scy > 0xf)
465 scy = 0xf;
466 if (scy < 1)
467 scy = 1;
468
469 flash_or_timing = (scy << 4) | trlx |
470 (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & ~(OR_TRLX | OR_SCY_MSK));
471
472 memctl->memc_or0 =
473 flash_or_timing | (-flash_info[0].size & OR_AM_MSK);
474#else
475 memctl->memc_or0 =
476 CONFIG_SYS_OR_TIMING_FLASH | (-flash_info[0].size & OR_AM_MSK);
477#endif
478 memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V;
479
480 debug ("## BR0: 0x%08x OR0: 0x%08x\n",
481 memctl->memc_br0, memctl->memc_or0);
482
483 if (flash_info[1].size) {
484#ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
485 memctl->memc_or1 = flash_or_timing |
486 (-flash_info[1].size & 0xFFFF8000);
487#else
488 memctl->memc_or1 = CONFIG_SYS_OR_TIMING_FLASH |
489 (-flash_info[1].size & 0xFFFF8000);
490#endif
491 memctl->memc_br1 =
492 ((CONFIG_SYS_FLASH_BASE +
493 flash_info[0].
494 size) & BR_BA_MSK) | BR_MS_GPCM | BR_V;
495
496 debug ("## BR1: 0x%08x OR1: 0x%08x\n",
497 memctl->memc_br1, memctl->memc_or1);
498 } else {
499 memctl->memc_br1 = 0;
500
501 debug ("## DISABLE BR1: 0x%08x OR1: 0x%08x\n",
502 memctl->memc_br1, memctl->memc_or1);
503 }
504
505# ifdef CONFIG_IDE_LED
506
507 immap->im_ioport.iop_padir |= 0x0001;
508 immap->im_ioport.iop_paodr |= 0x0001;
509 immap->im_ioport.iop_papar &= ~0x0001;
510 immap->im_ioport.iop_padat &= ~0x0001;
511# endif
512
513 return (0);
514}
515#endif
516
517
518# ifdef CONFIG_IDE_LED
519void ide_led (uchar led, uchar status)
520{
521 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
522
523
524 if (status) {
525 immap->im_ioport.iop_padat |= 0x0001;
526 } else {
527 immap->im_ioport.iop_padat &= ~0x0001;
528 }
529}
530# endif
531
532#ifdef CONFIG_LCD_INFO
533#include <lcd.h>
534#include <version.h>
535#include <timestamp.h>
536
537void lcd_show_board_info(void)
538{
539 char temp[32];
540
541 lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
542 lcd_printf ("(C) 2008 DENX Software Engineering GmbH\n");
543 lcd_printf (" Wolfgang DENK, wd@denx.de\n");
544#ifdef CONFIG_LCD_INFO_BELOW_LOGO
545 lcd_printf ("MPC823 CPU at %s MHz\n",
546 strmhz(temp, gd->cpu_clk));
547 lcd_printf (" %ld MB RAM, %ld MB Flash\n",
548 gd->ram_size >> 20,
549 gd->bd->bi_flashsize >> 20 );
550#else
551
552 lcd_printf ("\nMPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash\n",
553 strmhz(temp, gd->cpu_clk),
554 gd->ram_size >> 20,
555 gd->bd->bi_flashsize >> 20 );
556#endif
557}
558#endif
559
560
561
562
563#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
564int fdt_set_node_and_value (void *blob,
565 char *nodename,
566 char *regname,
567 void *var,
568 int size)
569{
570 int ret = 0;
571 int nodeoffset = 0;
572
573 nodeoffset = fdt_path_offset (blob, nodename);
574 if (nodeoffset >= 0) {
575 ret = fdt_setprop (blob, nodeoffset, regname, var,
576 size);
577 if (ret < 0) {
578 printf("ft_blob_update(): "
579 "cannot set %s/%s property; err: %s\n",
580 nodename, regname, fdt_strerror (ret));
581 }
582 } else {
583 printf("ft_blob_update(): "
584 "cannot find %s node err:%s\n",
585 nodename, fdt_strerror (nodeoffset));
586 }
587 return ret;
588}
589
590int fdt_del_node_name (void *blob, char *nodename)
591{
592 int ret = 0;
593 int nodeoffset = 0;
594
595 nodeoffset = fdt_path_offset (blob, nodename);
596 if (nodeoffset >= 0) {
597 ret = fdt_del_node (blob, nodeoffset);
598 if (ret < 0) {
599 printf("%s: cannot delete %s; err: %s\n",
600 __func__, nodename, fdt_strerror (ret));
601 }
602 } else {
603 printf("%s: cannot find %s node err:%s\n",
604 __func__, nodename, fdt_strerror (nodeoffset));
605 }
606 return ret;
607}
608
609int fdt_del_prop_name (void *blob, char *nodename, char *propname)
610{
611 int ret = 0;
612 int nodeoffset = 0;
613
614 nodeoffset = fdt_path_offset (blob, nodename);
615 if (nodeoffset >= 0) {
616 ret = fdt_delprop (blob, nodeoffset, propname);
617 if (ret < 0) {
618 printf("%s: cannot delete %s %s; err: %s\n",
619 __func__, nodename, propname,
620 fdt_strerror (ret));
621 }
622 } else {
623 printf("%s: cannot find %s node err:%s\n",
624 __func__, nodename, fdt_strerror (nodeoffset));
625 }
626 return ret;
627}
628
629
630
631
632void ft_blob_update (void *blob, bd_t *bd)
633{
634 uchar enetaddr[6];
635 ulong brg_data = 0;
636
637
638 brg_data = cpu_to_be32(bd->bi_busfreq);
639 fdt_set_node_and_value(blob,
640 "/soc/cpm", "brg-frequency",
641 &brg_data, sizeof(brg_data));
642
643
644 if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
645 fdt_set_node_and_value(blob,
646 "ethernet0", "local-mac-address",
647 enetaddr, sizeof(u8) * 6);
648 }
649
650 if (hwconfig_arg_cmp("fec", "off")) {
651
652 fdt_del_node_name (blob, "ethernet1");
653 fdt_del_node_name (blob, "mdio1");
654
655 fdt_del_prop_name (blob, "/aliases", "ethernet1");
656 fdt_del_prop_name (blob, "/aliases", "mdio1");
657 } else {
658
659 if (eth_getenv_enetaddr("eth1addr", enetaddr)) {
660 fdt_set_node_and_value(blob,
661 "ethernet1", "local-mac-address",
662 enetaddr, sizeof(u8) * 6);
663 }
664 }
665}
666
667int ft_board_setup(void *blob, bd_t *bd)
668{
669 ft_cpu_setup(blob, bd);
670 ft_blob_update(blob, bd);
671
672 return 0;
673}
674#endif
675