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