1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <common.h>
37#include <74xx_7xx.h>
38#include "../../Marvell/include/memory.h"
39#include "../../Marvell/include/pci.h"
40#include "../../Marvell/include/mv_gen_reg.h"
41#include <net.h>
42#include <i2c.h>
43
44#include "eth.h"
45#include "mpsc.h"
46#include "64460.h"
47#include "mv_regs.h"
48#include "p3mx.h"
49
50DECLARE_GLOBAL_DATA_PTR;
51
52#undef DEBUG
53
54
55#ifdef CONFIG_PCI
56#define MAP_PCI
57#endif
58
59#ifdef DEBUG
60#define DP(x) x
61#else
62#define DP(x)
63#endif
64
65extern flash_info_t flash_info[];
66
67
68
69
70
71
72
73
74
75
76
77
78void board_prebootm_init (void);
79unsigned int INTERNAL_REG_BASE_ADDR = CONFIG_SYS_GT_REGS;
80int display_mem_map (void);
81void set_led(int);
82
83
84
85
86
87
88
89
90
91
92
93void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
94{
95 u32 temp;
96
97
98 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
99 if ((temp & 0xffff) == new_loc >> 16)
100 return;
101
102 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
103 0xffff0000) | (new_loc >> 16);
104
105 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
106
107 while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
108}
109
110#ifdef CONFIG_PCI
111
112static void gt_pci_config (void)
113{
114 unsigned int stat;
115 unsigned int val = 0x00fff864;
116
117
118
119
120
121
122
123
124
125 if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) {
126 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
127
128 GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
129
130 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
131 GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
132 (stat & 0xffff0000) | CONFIG_SYS_PCI_IDSEL);
133
134 }
135 if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) {
136 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
137 GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
138
139 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
140 GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
141 (stat & 0xffff0000) | CONFIG_SYS_PCI_IDSEL);
142 }
143
144
145 PCI_MASTER_ENABLE (0, SELF);
146 PCI_MASTER_ENABLE (1, SELF);
147
148
149 GT_REG_READ (BASE_ADDR_ENABLE, &stat);
150 stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) |
151 (1 << 18);
152 stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
153 GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
154
155
156
157
158
159
160 GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CONFIG_SYS_PCI0_IO_SPACE >> 16);
161 GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CONFIG_SYS_PCI0_IO_SPACE_PCI >> 16);
162 GT_REG_WRITE (PCI_0_IO_SIZE, (CONFIG_SYS_PCI0_IO_SIZE - 1) >> 16);
163
164 GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CONFIG_SYS_PCI0_MEM_BASE >> 16);
165 GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CONFIG_SYS_PCI0_MEM_BASE >> 16);
166 GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CONFIG_SYS_PCI0_MEM_SIZE - 1) >> 16);
167
168 GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CONFIG_SYS_PCI1_IO_SPACE >> 16);
169 GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CONFIG_SYS_PCI1_IO_SPACE_PCI >> 16);
170 GT_REG_WRITE (PCI_1_IO_SIZE, (CONFIG_SYS_PCI1_IO_SIZE - 1) >> 16);
171
172 GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CONFIG_SYS_PCI1_MEM_BASE >> 16);
173 GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CONFIG_SYS_PCI1_MEM_BASE >> 16);
174 GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CONFIG_SYS_PCI1_MEM_SIZE - 1) >> 16);
175
176
177
178 GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
179 GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
180
181
182 GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
183 GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
184
185
186
187
188#ifdef MAP_PCI
189 for (stat = 0; stat <= PCI_HOST1; stat++)
190 pciWriteConfigReg (stat,
191 PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
192 SELF, CONFIG_SYS_GT_REGS);
193#endif
194
195}
196#endif
197
198
199static void gt_cpu_config (void)
200{
201 cpu_t cpu = get_cpu_type ();
202 ulong tmp;
203
204
205 tmp = GTREGREAD (CPU_CONFIGURATION);
206
207#ifndef CONFIG_SYS_GT_DUAL_CPU
208 tmp |= CPU_CONF_SINGLE_CPU;
209#endif
210 tmp &= ~CPU_CONF_AACK_DELAY_2;
211 tmp |= CPU_CONF_DP_VALID;
212 tmp |= CPU_CONF_AP_VALID;
213 tmp |= CPU_CONF_PIPELINE;
214 GT_REG_WRITE (CPU_CONFIGURATION, tmp);
215
216
217 tmp = GTREGREAD (CPU_MASTER_CONTROL);
218 tmp |= CPU_MAST_CTL_ARB_EN;
219
220 if ((cpu == CPU_7400) ||
221 (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
222
223 tmp |= CPU_MAST_CTL_CLEAN_BLK;
224 tmp |= CPU_MAST_CTL_FLUSH_BLK;
225
226 } else {
227
228
229
230 tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
231 tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
232 }
233 GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
234}
235
236
237
238
239
240
241int board_early_init_f (void)
242{
243
244
245
246
247
248
249 my_remap_gt_regs (CONFIG_SYS_DFL_GT_REGS, CONFIG_SYS_GT_REGS);
250
251#ifdef CONFIG_PCI
252 gt_pci_config ();
253#endif
254
255 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
256 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
257
258 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
259 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
260
261 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
262 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
263 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
264 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
265
266
267
268 memoryMapDeviceSpace(DEVICE0, 0, 0);
269 GT_REG_WRITE(DEVICE_BANK0PARAMETERS, 0);
270 memoryMapDeviceSpace(DEVICE1, 0, 0);
271 GT_REG_WRITE(DEVICE_BANK1PARAMETERS, 0);
272 memoryMapDeviceSpace(DEVICE2, 0, 0);
273 GT_REG_WRITE(DEVICE_BANK2PARAMETERS, 0);
274 memoryMapDeviceSpace(DEVICE3, 0, 0);
275 GT_REG_WRITE(DEVICE_BANK3PARAMETERS, 0);
276
277 GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CONFIG_SYS_BOOT_PAR);
278
279 gt_cpu_config();
280
281
282 GT_REG_WRITE (MPP_CONTROL0, CONFIG_SYS_MPP_CONTROL_0);
283 GT_REG_WRITE (MPP_CONTROL1, CONFIG_SYS_MPP_CONTROL_1);
284 GT_REG_WRITE (MPP_CONTROL2, CONFIG_SYS_MPP_CONTROL_2);
285 GT_REG_WRITE (MPP_CONTROL3, CONFIG_SYS_MPP_CONTROL_3);
286
287 GT_REG_WRITE (GPP_LEVEL_CONTROL, CONFIG_SYS_GPP_LEVEL_CONTROL);
288
289 set_led(LED_RED);
290
291 return 0;
292}
293
294
295
296int misc_init_r ()
297{
298 u8 val;
299
300 icache_enable ();
301#ifdef CONFIG_SYS_L2
302 l2cache_enable ();
303#endif
304#ifdef CONFIG_MPSC
305 mpsc_sdma_init ();
306 mpsc_init2 ();
307#endif
308
309
310
311
312
313 val = 0xa5;
314 i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 8, 1, &val, 1);
315
316 return 0;
317}
318
319void after_reloc (ulong dest_addr, gd_t * gd)
320{
321 memoryMapDeviceSpace (BOOT_DEVICE, CONFIG_SYS_BOOT_SPACE, CONFIG_SYS_BOOT_SIZE);
322
323
324
325
326 set_led(LED_GREEN);
327 board_init_r (gd, dest_addr);
328
329}
330
331
332
333
334
335
336int checkboard (void)
337{
338 char *s = getenv("serial#");
339
340 printf("Board: %s", CONFIG_SYS_BOARD_NAME);
341
342 if (s != NULL) {
343 puts(", serial# ");
344 puts(s);
345 }
346 putc('\n');
347
348 return (0);
349}
350
351void set_led(int col)
352{
353 int tmp;
354 int on_pin;
355 int off_pin;
356
357
358
359
360 tmp = GTREGREAD(MPP_CONTROL2);
361 tmp &= 0x00ffffff;
362 GT_REG_WRITE(MPP_CONTROL2,tmp);
363
364
365
366 tmp = GTREGREAD(GPP_IO_CONTROL);
367 tmp |= 0x00C00000;
368 GT_REG_WRITE(GPP_IO_CONTROL, tmp);
369
370
371
372 tmp = GTREGREAD(GPP_LEVEL_CONTROL);
373 tmp &= 0xff3fffff;
374 GT_REG_WRITE(GPP_LEVEL_CONTROL, tmp);
375
376 switch(col) {
377 default:
378 case LED_OFF :
379 on_pin = 0;
380 off_pin = ((1 << 23) | (1 << 22));
381 break;
382 case LED_RED :
383 on_pin = (1 << 23);
384 off_pin = (1 << 22);
385 break;
386 case LED_GREEN :
387 on_pin = (1 << 22);
388 off_pin = (1 << 23);
389 break;
390 case LED_ORANGE :
391 on_pin = ((1 << 23) | (1 << 22));
392 off_pin = 0;
393 break;
394 }
395
396
397
398 tmp = GTREGREAD(GPP_VALUE);
399 tmp |= on_pin;
400 tmp &= ~off_pin;
401 GT_REG_WRITE(GPP_VALUE, tmp);
402}
403
404int display_mem_map (void)
405{
406 int i;
407 unsigned int base, size, width;
408#ifdef CONFIG_PCI
409 int j;
410#endif
411
412
413 printf ("SD (DDR) RAM\n");
414 for (i = 0; i <= BANK3; i++) {
415 base = memoryGetBankBaseAddress (i);
416 size = memoryGetBankSize (i);
417 if (size != 0)
418 printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
419 i, base, size >> 20);
420 }
421#ifdef CONFIG_PCI
422
423 for (i = 0; i <= PCI_HOST1; i++) {
424 printf ("\nCPU's PCI %d windows\n", i);
425 base = pciGetSpaceBase (i, PCI_IO);
426 size = pciGetSpaceSize (i, PCI_IO);
427 printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
428 size >> 20);
429
430 for (j = 0; j <= PCI_REGION0; j++) {
431 base = pciGetSpaceBase (i, j);
432 size = pciGetSpaceSize (i, j);
433 printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n",
434 j, base, size >> 20);
435 }
436 }
437#endif
438
439
440 base = memoryGetDeviceBaseAddress (BOOT_DEVICE);
441 size = memoryGetDeviceSize (BOOT_DEVICE);
442 width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
443 printf (" BOOT: base - 0x%08x size - %dM bytes\twidth - %d bits\t- FLASH\n",
444 base, size >> 20, width);
445
446 return (0);
447}
448
449
450
451#if defined (CONFIG_SYS_DRAM_TEST)
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473static void move64 (unsigned long long *src, unsigned long long *dest)
474{
475 asm ("lfd 0, 0(3)\n\t"
476 "stfd 0, 0(4)"
477 : : : "fr0");
478 return;
479}
480
481
482#if defined (CONFIG_SYS_DRAM_TEST_DATA)
483
484unsigned long long pattern[] = {
485 0xaaaaaaaaaaaaaaaaULL,
486 0xccccccccccccccccULL,
487 0xf0f0f0f0f0f0f0f0ULL,
488 0xff00ff00ff00ff00ULL,
489 0xffff0000ffff0000ULL,
490 0xffffffff00000000ULL,
491 0x00000000ffffffffULL,
492 0x0000ffff0000ffffULL,
493 0x00ff00ff00ff00ffULL,
494 0x0f0f0f0f0f0f0f0fULL,
495 0x3333333333333333ULL,
496 0x5555555555555555ULL
497};
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543int mem_test_data (void)
544{
545 unsigned long long *pmem = (unsigned long long *) CONFIG_SYS_MEMTEST_START;
546 unsigned long long temp64 = 0;
547 int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
548 int i;
549 unsigned int hi, lo;
550
551 for (i = 0; i < num_patterns; i++) {
552 move64 (&(pattern[i]), pmem);
553 move64 (pmem, &temp64);
554
555
556
557
558
559 hi = (pattern[i] >> 32) & 0xffffffff;
560 lo = pattern[i] & 0xffffffff;
561
562
563 if (temp64 != pattern[i]) {
564 printf ("\n Data Test Failed, pattern 0x%08x%08x",
565 hi, lo);
566 return 1;
567 }
568 }
569
570 return 0;
571}
572#endif
573
574#if defined (CONFIG_SYS_DRAM_TEST_ADDRESS)
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596int mem_test_address (void)
597{
598 volatile unsigned int *pmem =
599 (volatile unsigned int *) CONFIG_SYS_MEMTEST_START;
600 const unsigned int size = (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START) / 4;
601 unsigned int i;
602
603
604 for (i = 0; i < size; i++)
605 pmem[i] = i;
606
607
608 for (i = 0; i < size; i++) {
609 if (pmem[i] != i) {
610 printf ("\n Address Test Failed at 0x%x", i);
611 return 1;
612 }
613 }
614 return 0;
615}
616#endif
617
618#if defined (CONFIG_SYS_DRAM_TEST_WALK)
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646int mem_march (volatile unsigned long long *base,
647 unsigned int size,
648 unsigned long long rmask,
649 unsigned long long wmask, short read, short write)
650{
651 unsigned int i;
652 unsigned long long temp = 0;
653 unsigned int hitemp, lotemp, himask, lomask;
654
655 for (i = 0; i < size; i++) {
656 if (read != 0) {
657
658 move64 ((unsigned long long *) &(base[i]), &temp);
659 if (rmask != temp) {
660 hitemp = (temp >> 32) & 0xffffffff;
661 lotemp = temp & 0xffffffff;
662 himask = (rmask >> 32) & 0xffffffff;
663 lomask = rmask & 0xffffffff;
664
665 printf ("\n Walking one's test failed: address = 0x%08x," "\n\texpected 0x%08x%08x, found 0x%08x%08x", i << 3, himask, lomask, hitemp, lotemp);
666 return 1;
667 }
668 }
669 if (write != 0) {
670
671 move64 (&wmask, (unsigned long long *) &(base[i]));
672 }
673 }
674 return 0;
675}
676#endif
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704int mem_test_walk (void)
705{
706 unsigned long long mask;
707 volatile unsigned long long *pmem =
708 (volatile unsigned long long *) CONFIG_SYS_MEMTEST_START;
709 const unsigned long size = (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START) / 8;
710
711 unsigned int i;
712
713 mask = 0x01;
714
715 printf ("Initial Pass");
716 mem_march (pmem, size, 0x0, 0x1, 0, 1);
717
718 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
719 printf (" ");
720 printf (" ");
721 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
722
723 for (i = 0; i < 63; i++) {
724 printf ("Pass %2d", i + 2);
725 if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
726
727 return 1;
728 }
729 mask = mask << 1;
730 printf ("\b\b\b\b\b\b\b");
731 }
732
733 printf ("Last Pass");
734 if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
735
736 return 1;
737 }
738 printf ("\b\b\b\b\b\b\b\b\b");
739 printf (" ");
740 printf ("\b\b\b\b\b\b\b\b\b");
741
742 return 0;
743}
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768int testdram (void)
769{
770 char *s;
771 int rundata = 0;
772 int runaddress = 0;
773 int runwalk = 0;
774
775#ifdef CONFIG_SYS_DRAM_TEST_DATA
776 s = getenv ("testdramdata");
777 rundata = (s && (*s == 'y')) ? 1 : 0;
778#endif
779#ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
780 s = getenv ("testdramaddress");
781 runaddress = (s && (*s == 'y')) ? 1 : 0;
782#endif
783#ifdef CONFIG_SYS_DRAM_TEST_WALK
784 s = getenv ("testdramwalk");
785 runwalk = (s && (*s == 'y')) ? 1 : 0;
786#endif
787
788 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
789 printf ("Testing RAM from 0x%08x to 0x%08x ... "
790 "(don't panic... that will take a moment !!!!)\n",
791 CONFIG_SYS_MEMTEST_START, CONFIG_SYS_MEMTEST_END);
792#ifdef CONFIG_SYS_DRAM_TEST_DATA
793 if (rundata == 1) {
794 printf ("Test DATA ... ");
795 if (mem_test_data () == 1) {
796 printf ("failed \n");
797 return 1;
798 } else
799 printf ("ok \n");
800 }
801#endif
802#ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
803 if (runaddress == 1) {
804 printf ("Test ADDRESS ... ");
805 if (mem_test_address () == 1) {
806 printf ("failed \n");
807 return 1;
808 } else
809 printf ("ok \n");
810 }
811#endif
812#ifdef CONFIG_SYS_DRAM_TEST_WALK
813 if (runwalk == 1) {
814 printf ("Test WALKING ONEs ... ");
815 if (mem_test_walk () == 1) {
816 printf ("failed \n");
817 return 1;
818 } else
819 printf ("ok \n");
820 }
821#endif
822 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
823 printf ("passed\n");
824 return 0;
825
826}
827#endif
828
829
830
831
832
833
834void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
835{
836 u32 temp;
837
838 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
839 if ((temp & 0xffff) == new_loc >> 16)
840 return;
841
842 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
843 0xffff0000) | (new_loc >> 16);
844
845 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
846
847 while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
848 new_loc |
849 (INTERNAL_SPACE_DECODE)))))
850 != temp);
851
852}
853