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#include <config.h>
35#include <version.h>
36
37#include <ppc_asm.tmpl>
38#include <ppc_defs.h>
39#include <asm/processor.h>
40
41#include <tsi108.h>
42
43
44
45
46
47
48
49
50
51
52
53
54
55#ifdef SDC_HARDCODED_INIT
56
57
58
59#define VAL_SD_REFRESH (0x61A)
60#define VAL_SD_TIMING (0x0308336b)
61#define VAL_SD_D0_CTRL (0x07100021)
62#define VAL_SD_D0_BAR (0x0FE00000)
63#define VAL_SD_D1_CTRL (0x07100021)
64#define VAL_SD_D1_BAR (0x0FE00200)
65
66#endif
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87#define LOAD_PTR(reg,const32) \
88 addis reg,r0,const32@h; ori reg,reg,const32@l
89
90#define LOAD_U32(reg,const32) \
91 addis reg,r0,const32@h; ori reg,reg,const32@l
92
93
94
95
96
97#define LOAD_MEM(reg,addr32) \
98 addis reg,r0,addr32@ha; lwz reg,addr32@l(reg)
99
100#ifndef SDC_HARDCODED_INIT
101sdc_clk_sync:
102
103 .long 0, 0, 6, 10, 8, 6, 5, 4
104#endif
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 .globl board_asm_init
120board_asm_init:
121 mflr r19
122 bl icache_enable
123
124
125
126 LOAD_PTR(r29,CONFIG_SYS_TSI108_CSR_RST_BASE)
127 ori r4,r29,TSI108_PB_REG_OFFSET
128
129
130
131 mfspr r3, PVR
132 rlwinm r3,r3,16,16,23
133
134 cmpli 0,0,r3,0x8000
135 bne cont_brd_init
136
137
138
139
140
141
142
143 mfspr r5, HID0
144 oris r5, r5, 0x0080
145 ori r5, r5, 0x0380
146 mtspr HID0, r5
147 isync
148 sync
149
150
151 mfspr r3, 1014
152 oris r3, r3, 0x0100
153 mtspr 1014, r3
154 isync
155 sync
156
157
158 mfmsr r3
159 ori r3, r3, 0x2000
160 mtmsr r3
161 isync
162 sync
163
164
165
166
167
168 mfspr r3,1014
169 rlwinm. r3,r3,27,31,31
170 mtspr SPRN_PIR,r3
171 sync
172 bne init_done
173 b do_tsi108_init
174
175cont_brd_init:
176
177
178
179
180
181
182 lwz r3,PB_BUS_MS_SELECT(r4)
183 rlwinm. r3,r3,24,31,31
184 bne init_done
185#else
186
187cont_brd_init:
188
189#endif
190
191
192
193do_tsi108_init:
194
195
196
197
198
199
200
201
202
203#ifdef CONFIG_TSI108EMU
204 ori r4,r29,TSI108_HLP_REG_OFFSET
205 LOAD_U32(r5,0x434422c0)
206 stw r5,0x08(r4)
207 sync
208 LOAD_U32(r5,0xd0012000)
209 stw r5,0x0c(r4)
210 sync
211#endif
212
213
214
215 ori r4,r29,TSI108_PB_REG_OFFSET
216
217
218
219
220
221
222 LOAD_U32(r5,(CONFIG_SYS_TSI108_CSR_BASE | 0x01))
223 stw r5,PB_REG_BAR(r4)
224 andis. r29,r5,0xFFFF
225 sync
226 ori r4,r29,TSI108_PB_REG_OFFSET
227#endif
228
229
230
231 LOAD_U32(r5,0x00002481)
232 lwz r3, PB_RSR(r4)
233 xori r3,r3,0x0001
234 rlwimi r5,r3,14,17,17
235 stw r5,PB_SCR(r4)
236 sync
237
238
239
240 lwz r5,PB_ARB_CTRL(r4)
241 li r3, 0x00F0
242#ifdef DISABLE_PBM
243 ori r3,r3,0x1000
244#endif
245 andc r5,r5,r3
246 ori r5,r5,0x0001
247 stw r5,PB_ARB_CTRL(r4)
248
249
250 LOAD_U32(r5,0x)
251 stw r5,PB_MCR(r4)
252 sync
253
254 LOAD_U32(r5,0x)
255 stw r5,PB_MCMD(r4)
256 sync
257#endif
258
259
260
261
262
263
264
265 LOAD_U32(r3,0xC0002234)
266 lwz r3,0(r3)
267 rlwinm r3,r3,16,29,31
268
269 cmpi 0,0,r3,0x0004
270 bgt sdc_init
271
272#ifndef CONFIG_TSI108EMU
273
274 li r5,0x0101
275 stw r5,PB_PVT_CTRL2(r4)
276 sync
277#endif
278
279
280
281sdc_init:
282
283#ifndef SDC_HARDCODED_INIT
284
285 ori r4,r29,TSI108_CLK_REG_OFFSET
286 lwz r3, CG_PWRUP_STATUS(r4)
287 rlwinm r3,r3,12,29,31
288 lis r5,sdc_clk_sync@h
289 ori r5,r5,sdc_clk_sync@l
290
291
292
293
294 cmpi 0,0,r3,0x0001
295 bne get_nsec
296 lwz r6, CG_PWRUP_STATUS(r4)
297 rlwinm r6,r6,16,29,31
298 mr r3,r6
299
300get_nsec:
301 rlwinm r3,r3,2,0,31
302 lwzx r9,r5,r3
303
304#endif
305
306 ori r4,r29,TSI108_SD_REG_OFFSET
307
308
309
310 LOAD_U32(r5,0x00)
311 stw r5,SD_INT_ENABLE(r4)
312#ifdef ENABLE_SDRAM_ECC
313 li r5, 0x01
314#endif
315 stw r5,SD_ECC_CTRL(r4)
316 sync
317
318#ifdef SDC_HARDCODED_INIT
319
320
321
322
323
324 LOAD_U32(r3,0xC0002234)
325 lwz r3,0(r3)
326 rlwinm r3,r3,12,29,31
327
328
329
330 cmpi 0,0,r3,0x0005
331 bne check_for_200mhz
332
333
334
335
336 LOAD_U32(r5,0x00000515)
337 stw r5,SD_REFRESH(r4)
338 LOAD_U32(r5,0x03073368)
339 stw r5,SD_TIMING(r4)
340 sync
341
342
343 LOAD_U32(r5,VAL_SD_D0_CTRL)
344#ifdef SDC_AUTOPRECH_EN
345 oris r5,r5,0x0001
346#endif
347 stw r5,SD_D0_CTRL(r4)
348 LOAD_U32(r5,VAL_SD_D0_BAR)
349 stw r5,SD_D0_BAR(r4)
350 sync
351
352
353
354
355 LOAD_U32(r5,VAL_SD_D1_CTRL)
356#ifdef SDC_AUTOPRECH_EN
357 oris r5,r5,0x0001
358#endif
359 stw r5,SD_D1_CTRL(r4)
360 LOAD_U32(r5,VAL_SD_D1_BAR)
361 stw r5,SD_D1_BAR(r4)
362 sync
363
364 b sdc_init_done
365
366check_for_200mhz:
367
368 cmpi 0,0,r3,0x0006
369 bne set_default_values
370
371
372
373
374 LOAD_U32(r5,0x0000061a)
375 stw r5,SD_REFRESH(r4)
376 LOAD_U32(r5,0x03083348)
377 stw r5,SD_TIMING(r4)
378 sync
379
380
381 LOAD_U32(r5,VAL_SD_D0_CTRL)
382#ifdef SDC_AUTOPRECH_EN
383 oris r5,r5,0x0001
384#endif
385 stw r5,SD_D0_CTRL(r4)
386 LOAD_U32(r5,VAL_SD_D0_BAR)
387 stw r5,SD_D0_BAR(r4)
388 sync
389
390
391
392
393 LOAD_U32(r5,VAL_SD_D1_CTRL)
394#ifdef SDC_AUTOPRECH_EN
395 oris r5,r5,0x0001
396#endif
397 stw r5,SD_D1_CTRL(r4)
398 LOAD_U32(r5,VAL_SD_D1_BAR)
399 stw r5,SD_D1_BAR(r4)
400 sync
401
402 b sdc_init_done
403
404set_default_values:
405
406
407 LOAD_U32(r5,VAL_SD_REFRESH)
408 stw r5,SD_REFRESH(r4)
409 LOAD_U32(r5,VAL_SD_TIMING)
410 stw r5,SD_TIMING(r4)
411 sync
412
413
414 LOAD_U32(r5,VAL_SD_D0_CTRL)
415#ifdef SDC_AUTOPRECH_EN
416 oris r5,r5,0x0001
417#endif
418 stw r5,SD_D0_CTRL(r4)
419 LOAD_U32(r5,VAL_SD_D0_BAR)
420 stw r5,SD_D0_BAR(r4)
421 sync
422
423
424
425
426 LOAD_U32(r5,VAL_SD_D1_CTRL)
427#ifdef SDC_AUTOPRECH_EN
428 oris r5,r5,0x0001
429#endif
430 stw r5,SD_D1_CTRL(r4)
431 LOAD_U32(r5,VAL_SD_D1_BAR)
432 stw r5,SD_D1_BAR(r4)
433 sync
434#else
435 bl tsi108_sdram_spd
436#endif
437
438sdc_init_done:
439
440#ifdef DISABLE_PBM
441 LOAD_U32(r5,0x00000030)
442#else
443 LOAD_U32(r5,0x00000230)
444#endif
445
446#ifdef CONFIG_TSI108EMU
447 oris r5,r5,0x0010
448#endif
449
450 stw r5,SD_CTRL(r4)
451 eieio
452 sync
453
454
455
456 oris r5,r5,0x8000
457 stw r5,SD_CTRL(r4)
458 sync
459
460wait_init_complete:
461 lwz r5,SD_STATUS(r4)
462 andi. r5,r5,0x0001
463
464 beq wait_init_complete
465
466
467
468 ori r4,r29,TSI108_PB_REG_OFFSET
469
470
471
472
473
474
475
476
477 LOAD_U32(r5, 0x00000011)
478 stw r5,PB_SDRAM_BAR1(r4)
479 sync
480
481
482
483
484 lwz r5,PB_SDRAM_BAR1(r4)
485 sync
486
487
488
489
490
491
492
493
494 LOAD_U32(r5, 0x40010011)
495 stw r5,PB_SDRAM_BAR2(r4)
496 sync
497
498
499
500
501 lwz r5,PB_SDRAM_BAR2(r4)
502 sync
503
504init_done:
505
506
507 mtlr r19
508 blr
509
510
511
512
513
514
515
516
517 .global enable_cpu1
518enable_cpu1:
519
520 lis r3,Tsi108_Base@ha
521 addi r3,r3,Tsi108_Base@l
522 lwz r3,0(r3)
523 ori r4,r3,TSI108_PB_REG_OFFSET
524 lwz r3,PB_ARB_CTRL(r4)
525 ori r3,r3,0x0200
526 stw r3,PB_ARB_CTRL(r4)
527
528 blr
529#endif
530
531
532
533
534
535
536 .global enable_EI
537enable_EI:
538 mfmsr r3
539 ori r3,r3,0x8000
540 mtmsr r3
541 blr
542
543
544
545
546
547
548 .global disable_EI
549disable_EI:
550 mfmsr r3
551 li r4,-32768
552 andc r3,r3,r4
553 mtmsr r3
554 blr
555
556#ifdef ENABLE_SDRAM_ECC
557
558
559 .global enable_ECC
560enable_ECC:
561 ori r4,r29,TSI108_SD_REG_OFFSET
562 lwz r3,SD_ECC_CTRL(r4)
563 ori r3,r3,0x0001
564 stw r3,SD_ECC_CTRL(r4)
565 blr
566
567
568
569
570
571
572
573 .global clear_ECC_err
574clear_ECC_err:
575 ori r4,r29,TSI108_SD_REG_OFFSET
576 ori r3,r0,0x0030
577 stw r3,SD_INT_STATUS(r4)
578 blr
579
580#endif
581
582#ifndef SDC_HARDCODED_INIT
583
584
585#define SD_I2C_CTRL1 (0x400)
586#define SD_I2C_CTRL2 (0x404)
587#define SD_I2C_RD_DATA (0x408)
588#define SD_I2C_WR_DATA (0x40C)
589
590
591
592
593
594#define SPD_DIMM0 (0x00000100)
595#define SPD_DIMM1 (0x00000200)
596
597#define SPD_RDIMM (0x01)
598#define SPD_UDIMM (0x02)
599
600#define SPD_CAS_3 0x8
601#define SPD_CAS_4 0x10
602#define SPD_CAS_5 0x20
603
604#define ERR_NO_DIMM_FOUND (0xdb0)
605#define ERR_TRAS_FAIL (0xdb1)
606#define ERR_TRCD_FAIL (0xdb2)
607#define ERR_TRP_FAIL (0xdb3)
608#define ERR_TWR_FAIL (0xdb4)
609#define ERR_UNKNOWN_PART (0xdb5)
610#define ERR_NRANK_INVALID (0xdb6)
611#define ERR_DIMM_SIZE (0xdb7)
612#define ERR_ADDR_MODE (0xdb8)
613#define ERR_RFRSH_RATE (0xdb9)
614#define ERR_DIMM_TYPE (0xdba)
615#define ERR_CL_VALUE (0xdbb)
616#define ERR_TRFC_FAIL (0xdbc)
617
618
619
620
621
622
623
624
625
626#define READ_SPD(byte_num) \
627 addis r3, 0, byte_num@l; \
628 or r3, r3, r10; \
629 ori r3, r3, 0x0A; \
630 stw r3, SD_I2C_CTRL1(r4); \
631 li r3, I2C_CNTRL2_START; \
632 stw r3, SD_I2C_CTRL2(r4); \
633 eieio; \
634 sync; \
635 li r3, 0x100; \
6361:; \
637 addic. r3, r3, -1; \
638 bne 1b; \
6392:; \
640 lwz r5, SD_I2C_CTRL2(r4); \
641 rlwinm. r3,r5,0,23,23; \
642 bne 2b; \
643 rlwinm. r3,r5,0,3,3; \
644 lwz r3,SD_I2C_RD_DATA(r4)
645
646#define SPD_MIN_RFRSH (0x80)
647#define SPD_MAX_RFRSH (0x85)
648
649refresh_rates:
650 .long 15625
651 .long 3900
652 .long 7800
653 .long 31300
654 .long 62500
655 .long 125000
656
657
658
659
660
661
662
663
664
665
666tsi108_sdram_spd:
667
668 li r10,SPD_DIMM0
669 xor r11,r11,r11
670
671do_first_dimm:
672
673
674
675 READ_SPD(12)
676 beq check_next_slot
677 li r5, ERR_RFRSH_RATE
678 cmpi 0,0,r3,SPD_MIN_RFRSH
679 ble spd_fail
680 cmpi 0,0,r3,SPD_MAX_RFRSH
681 bgt spd_fail
682 addi r3,r3,-SPD_MIN_RFRSH
683 rlwinm r3,r3,2,0,31
684 lis r5,refresh_rates@h
685 ori r5,r5,refresh_rates@l
686 lwzx r5,r5,r3
687 divwu r5,r5,r9
688 stw r5,SD_REFRESH(r4)
689 sync
690
691
692
693 li r7, 0
694
695 READ_SPD(20)
696 beq spd_read_fail
697 li r5, ERR_DIMM_TYPE
698 cmpi 0,0,r3,SPD_UDIMM
699 beq do_cl
700 cmpi 0,0,r3,SPD_RDIMM
701 bne spd_fail
702 oris r7,r7,0x1000
703
704do_cl:
705 READ_SPD(18)
706 beq spd_read_fail
707 li r5,ERR_CL_VALUE
708 andi. r6,r3,SPD_CAS_3
709 beq cl_4
710 li r6,3
711 b set_cl
712cl_4:
713 andi. r6,r3,SPD_CAS_4
714 beq cl_5
715 li r6,4
716 b set_cl
717cl_5:
718 andi. r6,r3,SPD_CAS_5
719 beq spd_fail
720 li r6,5
721set_cl:
722 rlwimi r7,r6,24,5,7
723
724 READ_SPD(30)
725 beq spd_read_fail
726 divwu r6,r3,r9
727 mullw r8,r6,r9
728 subf. r8,r8,r3
729 beq set_tras
730 addi r6,r6,1
731set_tras:
732 li r5,ERR_TRAS_FAIL
733 cmpi 0,0,r6,0x0F
734 bgt spd_fail
735 rlwimi r7,r6,16,12,15
736
737 READ_SPD(29)
738 beq spd_read_fail
739
740 rlwinm r3,r3,30,2,31
741 divwu r6,r3,r9
742 mullw r8,r6,r9
743 subf. r8,r8,r3
744 beq set_trcd
745 addi r6,r6,1
746set_trcd:
747 li r5,ERR_TRCD_FAIL
748 cmpi 0,0,r6,0x07
749 bgt spd_fail
750 rlwimi r7,r6,12,17,19
751
752 READ_SPD(27)
753 beq spd_read_fail
754 rlwinm r3,r3,30,2,31
755 divwu r6,r3,r9
756 mullw r8,r6,r9
757 subf. r8,r8,r3
758 beq set_trp
759 addi r6,r6,1
760set_trp:
761 li r5,ERR_TRP_FAIL
762 cmpi 0,0,r6,0x07
763 bgt spd_fail
764 rlwimi r7,r6,8,21,23
765
766 READ_SPD(36)
767 beq spd_read_fail
768 rlwinm r3,r3,30,2,31
769 divwu r6,r3,r9
770 mullw r8,r6,r9
771 subf. r8,r8,r3
772 beq set_twr
773 addi r6,r6,1
774set_twr:
775 addi r6,r6,-1
776 li r5,ERR_TWR_FAIL
777 cmpi 0,0,r6,0x07
778 bgt spd_fail
779 rlwimi r7,r6,5,24,26
780
781 READ_SPD(42)
782 beq spd_read_fail
783 li r5, ERR_TRFC_FAIL
784
785 addi r3,r3,1
786 rlwinm. r3,r3,31,1,31
787 beq spd_fail
788 divwu r6,r3,r9
789 mullw r8,r6,r9
790 subf. r8,r8,r3
791 beq set_trfc
792 addi r6,r6,1
793set_trfc:
794 cmpi 0,0,r6,0x1F
795 bgt spd_fail
796 rlwimi r7,r6,0,27,31
797
798 stw r7,SD_TIMING(r4)
799 sync
800
801
802
803
804
805
806do_each_dimm:
807
808
809
810 li r7, 0
811
812 READ_SPD(13)
813 beq spd_read_fail
814 cmpi 0,0,r3,4
815 beq do_nbank
816 oris r7,r7,0x0010
817
818do_nbank:
819 READ_SPD(17)
820 beq spd_read_fail
821
822 li r5,ERR_UNKNOWN_PART
823 cmpi 0,0,r3,4
824 beq do_nrank
825 cmpi 0,0,r3,8
826 bne spd_fail
827 ori r7,r7,0x1000
828
829do_nrank:
830 READ_SPD(5)
831 beq spd_read_fail
832 li r5,ERR_NRANK_INVALID
833 andi. r6,r3,0x7
834 beq do_addr_mode
835 cmpi 0,0,r6,1
836 bgt spd_fail
837 rlwimi r7,r6,8,23,23
838
839do_addr_mode:
840 READ_SPD(4)
841 beq spd_read_fail
842 li r5, ERR_ADDR_MODE
843 andi. r3,r3,0x0f
844 cmpi 0,0,r3,8
845 ble spd_fail
846 cmpi 0,0,r3,15
847 bgt spd_fail
848 addi r6,r3,-8
849 rlwimi r7,r6,4,24,27
850
851set_dimm_ctrl:
852#ifdef SDC_AUTOPRECH_EN
853 oris r7,r7,0x0001
854#endif
855 ori r7,r7,1
856 cmpi 0,0,r10,SPD_DIMM0
857 bne 1f
858 stw r7,SD_D0_CTRL(r4)
859 sync
860 b set_dimm_bar
8611:
862 stw r7,SD_D1_CTRL(r4)
863 sync
864
865
866
867
868set_dimm_bar:
869 READ_SPD(5)
870 beq spd_read_fail
871 andi. r7,r3,0x7
872 addi r7,r7,1
873 READ_SPD(31)
874 beq spd_read_fail
875 rlwinm r5,r3,27,29,31
876 rlwinm r6,r3,3,24,28
877 or r5,r6,r5
878 lis r8, 0x0080
879 mullw r8,r8,r5
880 mullw r8,r8,r7
881 neg r7,r8
882 rlwinm r7,r7,28,4,31
883 or r7,r7,r11
884 rlwinm r8,r8,12,20,31
885 add r11,r11,r8
886
887 cmpi 0,0,r10,SPD_DIMM0
888 bne set_dimm1_size
889 stw r7,SD_D0_BAR(r4)
890 sync
891 li r10,SPD_DIMM1
892 READ_SPD(0)
893 bne do_each_dimm
894 b spd_done
895
896set_dimm1_size:
897 stw r7,SD_D1_BAR(r4)
898 sync
899spd_done:
900 blr
901
902check_next_slot:
903 cmpi 0,0,r10,SPD_DIMM1
904 beq spd_read_fail
905 li r10,SPD_DIMM1
906 b do_first_dimm
907spd_read_fail:
908 ori r3,r0,0xdead
909 b err_hung
910spd_fail:
911 li r3,0x0bad
912 sync
913err_hung:
914 nop
915 nop
916 b err_hung
917
918#endif
919