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#include <common.h>
33#include <74xx_7xx.h>
34#include "../include/memory.h"
35#include "../include/pci.h"
36#include "../include/mv_gen_reg.h"
37#include <net.h>
38
39#include "eth.h"
40#include "mpsc.h"
41#include "../common/i2c.h"
42#include "64460.h"
43#include "mv_regs.h"
44
45DECLARE_GLOBAL_DATA_PTR;
46
47#undef DEBUG
48#define MAP_PCI
49
50#ifdef DEBUG
51#define DP(x) x
52#else
53#define DP(x)
54#endif
55
56int set_dfcdlInit (void);
57int mvDmaIsChannelActive (int);
58int mvDmaSetMemorySpace (ulong, ulong, ulong, ulong, ulong);
59int mvDmaTransfer (int, ulong, ulong, ulong, ulong);
60
61
62
63int
64memory_map_bank (unsigned int bankNo,
65 unsigned int bankBase, unsigned int bankLength)
66{
67#ifdef MAP_PCI
68 PCI_HOST host;
69#endif
70
71
72#ifdef DEBUG
73 if (bankLength > 0) {
74 printf ("mapping bank %d at %08x - %08x\n",
75 bankNo, bankBase, bankBase + bankLength - 1);
76 } else {
77 printf ("unmapping bank %d\n", bankNo);
78 }
79#endif
80
81 memoryMapBank (bankNo, bankBase, bankLength);
82
83#ifdef MAP_PCI
84 for (host = PCI_HOST0; host <= PCI_HOST1; host++) {
85 const int features =
86 PREFETCH_ENABLE |
87 DELAYED_READ_ENABLE |
88 AGGRESSIVE_PREFETCH |
89 READ_LINE_AGGRESSIVE_PREFETCH |
90 READ_MULTI_AGGRESSIVE_PREFETCH |
91 MAX_BURST_4 | PCI_NO_SWAP;
92
93 pciMapMemoryBank (host, bankNo, bankBase, bankLength);
94
95 pciSetRegionSnoopMode (host, bankNo, PCI_SNOOP_WB, bankBase,
96 bankLength);
97
98 pciSetRegionFeatures (host, bankNo, features, bankBase,
99 bankLength);
100 }
101#endif
102 return 0;
103}
104
105#define GB (1 << 30)
106
107
108
109
110
111typedef struct sdram_info {
112 uchar drb_size;
113 uchar registered, ecc;
114 uchar tpar;
115 uchar tras_clocks;
116 uchar burst_len;
117 uchar banks, slot;
118} sdram_info_t;
119
120
121
122typedef enum _memoryType { SDRAM, DDR } MEMORY_TYPE;
123
124typedef enum _voltageInterface { TTL_5V_TOLERANT, LVTTL, HSTL_1_5V,
125 SSTL_3_3V, SSTL_2_5V, VOLTAGE_UNKNOWN,
126} VOLTAGE_INTERFACE;
127
128typedef enum _max_CL_supported_DDR { DDR_CL_1 = 1, DDR_CL_1_5 = 2, DDR_CL_2 =
129 4, DDR_CL_2_5 = 8, DDR_CL_3 = 16, DDR_CL_3_5 =
130 32, DDR_CL_FAULT } MAX_CL_SUPPORTED_DDR;
131typedef enum _max_CL_supported_SD { SD_CL_1 =
132 1, SD_CL_2, SD_CL_3, SD_CL_4, SD_CL_5, SD_CL_6, SD_CL_7,
133 SD_FAULT } MAX_CL_SUPPORTED_SD;
134
135
136
137typedef struct _gtMemoryDimmInfo {
138 MEMORY_TYPE memoryType;
139 unsigned int numOfRowAddresses;
140 unsigned int numOfColAddresses;
141 unsigned int numOfModuleBanks;
142 unsigned int dataWidth;
143 VOLTAGE_INTERFACE voltageInterface;
144 unsigned int errorCheckType;
145 unsigned int sdramWidth; ;
146 unsigned int errorCheckDataWidth;
147 unsigned int minClkDelay;
148 unsigned int burstLengthSupported;
149 unsigned int numOfBanksOnEachDevice;
150 unsigned int suportedCasLatencies;
151 unsigned int RefreshInterval;
152 unsigned int maxCASlatencySupported_LoP;
153 unsigned int maxCASlatencySupported_RoP;
154 MAX_CL_SUPPORTED_DDR maxClSupported_DDR;
155 MAX_CL_SUPPORTED_SD maxClSupported_SD;
156 unsigned int moduleBankDensity;
157
158 bool bufferedAddrAndControlInputs;
159 bool registeredAddrAndControlInputs;
160 bool onCardPLL;
161 bool bufferedDQMBinputs;
162 bool registeredDQMBinputs;
163 bool differentialClockInput;
164 bool redundantRowAddressing;
165
166
167 bool suportedAutoPreCharge;
168 bool suportedPreChargeAll;
169 bool suportedEarlyRasPreCharge;
170 bool suportedWrite1ReadBurst;
171 bool suported5PercentLowVCC;
172 bool suported5PercentUpperVCC;
173
174 unsigned int minRasToCasDelay;
175 unsigned int minRowActiveRowActiveDelay;
176 unsigned int minRasPulseWidth;
177 unsigned int minRowPrechargeTime;
178
179 int addrAndCommandHoldTime;
180 int addrAndCommandSetupTime;
181 int dataInputSetupTime;
182 int dataInputHoldTime;
183
184 unsigned int clockToDataOut_LoP;
185 unsigned int clockToDataOut_RoP;
186 unsigned int clockToDataOutMinus1_LoP;
187 unsigned int clockToDataOutMinus1_RoP;
188 unsigned int clockToDataOutMinus2_LoP;
189 unsigned int clockToDataOutMinus2_RoP;
190
191 unsigned int minimumCycleTimeAtMaxCasLatancy_LoP;
192 unsigned int minimumCycleTimeAtMaxCasLatancy_RoP;
193
194 unsigned int minimumCycleTimeAtMaxCasLatancyMinus1_LoP;
195 unsigned int minimumCycleTimeAtMaxCasLatancyMinus1_RoP;
196
197 unsigned int minimumCycleTimeAtMaxCasLatancyMinus2_LoP;
198 unsigned int minimumCycleTimeAtMaxCasLatancyMinus2_RoP;
199
200
201
202 unsigned int size;
203 unsigned int deviceDensity;
204 unsigned int numberOfDevices;
205 uchar drb_size;
206 uchar slot;
207 uchar spd_raw_data[128];
208#ifdef DEBUG
209 uchar manufactura[8];
210 uchar modul_id[18];
211 uchar vendor_data[27];
212 unsigned long modul_serial_no;
213 unsigned int manufac_date;
214 unsigned int modul_revision;
215 uchar manufac_place;
216
217#endif
218} AUX_MEM_DIMM_INFO;
219
220
221
222
223
224
225static inline unsigned short NS10to10PS (unsigned char spd_byte)
226{
227 unsigned short ns, ns10;
228
229
230 ns = (spd_byte >> 4) & 0x0F;
231
232 ns10 = (spd_byte & 0x0F);
233
234 return (ns * 100 + ns10 * 10);
235}
236
237
238
239
240
241static inline unsigned short NSto10PS (unsigned char spd_byte)
242{
243 return (spd_byte * 100);
244}
245
246
247
248
249static int check_dimm (uchar slot, AUX_MEM_DIMM_INFO * dimmInfo)
250{
251 unsigned long spd_checksum;
252
253#ifdef ZUMA_NTL
254
255 memset (info, 0, sizeof (*info));
256
257
258
259
260
261
262
263
264
265
266
267#ifdef CONFIG_MV64460_ECC
268
269 dimmInfo->errorCheckType = 2;
270
271#endif
272}
273
274return 0;
275
276#else
277 uchar addr = slot == 0 ? DIMM0_I2C_ADDR : DIMM1_I2C_ADDR;
278 int ret;
279 unsigned int i, j, density = 1, devicesForErrCheck = 0;
280
281#ifdef DEBUG
282 unsigned int k;
283#endif
284 unsigned int rightOfPoint = 0, leftOfPoint = 0, mult, div, time_tmp;
285 int sign = 1, shift, maskLeftOfPoint, maskRightOfPoint;
286 uchar supp_cal, cal_val;
287 ulong memclk, tmemclk;
288 ulong tmp;
289 uchar trp_clocks = 0, trcd_clocks, tras_clocks, trrd_clocks;
290 uchar data[128];
291
292 memclk = gd->bus_clk;
293 tmemclk = 1000000000 / (memclk / 100);
294
295 DP (puts ("before i2c read\n"));
296
297 ret = i2c_read (addr, 0, 1, data, 128);
298
299 DP (puts ("after i2c read\n"));
300
301
302 memset (dimmInfo, 0, sizeof (*dimmInfo));
303
304
305 for (i = 0; i <= 127; i++) {
306 dimmInfo->spd_raw_data[i] = data[i];
307 }
308
309 if (ret) {
310 DP (printf ("No DIMM in slot %d [err = %x]\n", slot, ret));
311 return 0;
312 } else
313 dimmInfo->slot = slot;
314
315#ifdef CONFIG_SYS_DISPLAY_DIMM_SPD_CONTENT
316
317 for (i = 0; i <= 127; i++) {
318 printf ("SPD-EEPROM Byte %3d = %3x (%3d)\n", i, data[i],
319 data[i]);
320 }
321
322#endif
323#ifdef DEBUG
324
325 for (i = 0; i < sizeof (dimmInfo->manufactura); i++) {
326 dimmInfo->manufactura[i] = data[64 + i];
327 }
328 printf ("\nThis RAM-Module is produced by: %s\n",
329 dimmInfo->manufactura);
330
331
332 for (i = 0; i < sizeof (dimmInfo->modul_id); i++) {
333 dimmInfo->modul_id[i] = data[73 + i];
334 }
335 printf ("The Module-ID of this RAM-Module is: %s\n",
336 dimmInfo->modul_id);
337
338
339 for (i = 0; i < sizeof (dimmInfo->vendor_data); i++) {
340 dimmInfo->vendor_data[i] = data[99 + i];
341 }
342 printf ("Vendor Data of this RAM-Module is: %s\n",
343 dimmInfo->vendor_data);
344
345
346 dimmInfo->modul_serial_no = (*((unsigned long *) (&data[95])));
347 printf ("Serial No. of this RAM-Module is: %ld (%lx)\n",
348 dimmInfo->modul_serial_no, dimmInfo->modul_serial_no);
349
350
351 dimmInfo->manufac_date = (*((unsigned int *) (&data[93])));
352 printf ("Manufactoring Date of this RAM-Module is: %d.%d\n", data[93], data[94]);
353
354
355 dimmInfo->modul_revision = (*((unsigned int *) (&data[91])));
356 printf ("Module Revision of this RAM-Module is: %d.%d\n", data[91], data[92]);
357
358
359 dimmInfo->manufac_place = (*((unsigned char *) (&data[72])));
360 printf ("manufac_place of this RAM-Module is: %d\n",
361 dimmInfo->manufac_place);
362
363#endif
364
365
366
367
368 spd_checksum = 0;
369
370 for (i = 0; i <= 62; i++) {
371 spd_checksum += data[i];
372 }
373
374 if ((spd_checksum & 0xff) != data[63]) {
375 printf ("### Error in SPD Checksum !!! Is_value: %2x should value %2x\n", (unsigned int) (spd_checksum & 0xff), data[63]);
376 hang ();
377 }
378
379 else
380 printf ("SPD Checksum ok!\n");
381
382
383
384 for (i = 2; i <= 35; i++) {
385 switch (i) {
386 case 2:
387 dimmInfo->memoryType = (data[i] == 0x7) ? DDR : SDRAM;
388#ifdef DEBUG
389 if (dimmInfo->memoryType == 0)
390 DP (printf
391 ("Dram_type in slot %d is: SDRAM\n",
392 dimmInfo->slot));
393 if (dimmInfo->memoryType == 1)
394 DP (printf
395 ("Dram_type in slot %d is: DDRAM\n",
396 dimmInfo->slot));
397#endif
398 break;
399
400
401 case 3:
402 dimmInfo->numOfRowAddresses = data[i];
403 DP (printf
404 ("Module Number of row addresses: %d\n",
405 dimmInfo->numOfRowAddresses));
406 break;
407
408
409 case 4:
410 dimmInfo->numOfColAddresses = data[i];
411 DP (printf
412 ("Module Number of col addresses: %d\n",
413 dimmInfo->numOfColAddresses));
414 break;
415
416
417 case 5:
418 dimmInfo->numOfModuleBanks = data[i];
419 DP (printf
420 ("Number of Banks on Mod. : %d\n",
421 dimmInfo->numOfModuleBanks));
422 break;
423
424
425 case 6:
426 dimmInfo->dataWidth = data[i];
427 DP (printf
428 ("Module Data Width: %d\n",
429 dimmInfo->dataWidth));
430 break;
431
432
433 case 8:
434 switch (data[i]) {
435 case 0x0:
436 dimmInfo->voltageInterface = TTL_5V_TOLERANT;
437 DP (printf
438 ("Module is TTL_5V_TOLERANT\n"));
439 break;
440 case 0x1:
441 dimmInfo->voltageInterface = LVTTL;
442 DP (printf
443 ("Module is LVTTL\n"));
444 break;
445 case 0x2:
446 dimmInfo->voltageInterface = HSTL_1_5V;
447 DP (printf
448 ("Module is TTL_5V_TOLERANT\n"));
449 break;
450 case 0x3:
451 dimmInfo->voltageInterface = SSTL_3_3V;
452 DP (printf
453 ("Module is HSTL_1_5V\n"));
454 break;
455 case 0x4:
456 dimmInfo->voltageInterface = SSTL_2_5V;
457 DP (printf
458 ("Module is SSTL_2_5V\n"));
459 break;
460 default:
461 dimmInfo->voltageInterface = VOLTAGE_UNKNOWN;
462 DP (printf
463 ("Module is VOLTAGE_UNKNOWN\n"));
464 break;
465 }
466 break;
467
468
469 case 9:
470 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
471 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
472 maskLeftOfPoint =
473 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
474 maskRightOfPoint =
475 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
476 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
477 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
478 dimmInfo->minimumCycleTimeAtMaxCasLatancy_LoP =
479 leftOfPoint;
480 dimmInfo->minimumCycleTimeAtMaxCasLatancy_RoP =
481 rightOfPoint;
482 DP (printf
483 ("Minimum Cycle Time At Max CasLatancy: %d.%d [ns]\n",
484 leftOfPoint, rightOfPoint));
485 break;
486
487
488 case 10:
489 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
490 time_tmp =
491 (((data[i] & 0xf0) >> 4) * 10) +
492 ((data[i] & 0x0f));
493 leftOfPoint = time_tmp / div;
494 rightOfPoint = time_tmp % div;
495 dimmInfo->clockToDataOut_LoP = leftOfPoint;
496 dimmInfo->clockToDataOut_RoP = rightOfPoint;
497 DP (printf ("Clock To Data Out: %d.%2d [ns]\n", leftOfPoint, rightOfPoint));
498 break;
499
500
501
502 case 11:
503 dimmInfo->errorCheckType = data[i];
504 DP (printf
505 ("Error Check Type (0=NONE): %d\n",
506 dimmInfo->errorCheckType));
507 break;
508
509
510
511 case 12:
512 dimmInfo->RefreshInterval = data[i];
513 DP (printf
514 ("RefreshInterval (80= Self refresh Normal, 15.625us) : %x\n",
515 dimmInfo->RefreshInterval));
516 break;
517
518
519 case 13:
520 dimmInfo->sdramWidth = data[i];
521 DP (printf
522 ("Sdram Width: %d\n",
523 dimmInfo->sdramWidth));
524 break;
525
526
527 case 14:
528 dimmInfo->errorCheckDataWidth = data[i];
529 DP (printf
530 ("Error Check Data Width: %d\n",
531 dimmInfo->errorCheckDataWidth));
532 break;
533
534
535 case 15:
536 dimmInfo->minClkDelay = data[i];
537 DP (printf
538 ("Minimum Clock Delay: %d\n",
539 dimmInfo->minClkDelay));
540 break;
541
542
543 case 16:
544
545
546
547
548
549
550
551
552
553 dimmInfo->burstLengthSupported = data[i];
554#ifdef DEBUG
555 DP (printf
556 ("Burst Length Supported: "));
557 if (dimmInfo->burstLengthSupported & 0x01)
558 DP (printf ("1, "));
559 if (dimmInfo->burstLengthSupported & 0x02)
560 DP (printf ("2, "));
561 if (dimmInfo->burstLengthSupported & 0x04)
562 DP (printf ("4, "));
563 if (dimmInfo->burstLengthSupported & 0x08)
564 DP (printf ("8, "));
565 DP (printf (" Bit \n"));
566#endif
567 break;
568
569
570 case 17:
571 dimmInfo->numOfBanksOnEachDevice = data[i];
572 DP (printf
573 ("Number Of Banks On Each Chip: %d\n",
574 dimmInfo->numOfBanksOnEachDevice));
575 break;
576
577
578 case 18:
579
580
581
582
583
584
585
586
587
588
589
590
591
592 dimmInfo->suportedCasLatencies = data[i];
593#ifdef DEBUG
594 DP (printf
595 ("Suported Cas Latencies: (CL) "));
596 if (dimmInfo->memoryType == 0) {
597 for (k = 0; k <= 7; k++) {
598 if (dimmInfo->
599 suportedCasLatencies & (1 << k))
600 DP (printf
601 ("%d, ",
602 k + 1));
603 }
604
605 } else {
606
607 if (dimmInfo->suportedCasLatencies & 1)
608 DP (printf ("1, "));
609 if (dimmInfo->suportedCasLatencies & 2)
610 DP (printf ("1.5, "));
611 if (dimmInfo->suportedCasLatencies & 4)
612 DP (printf ("2, "));
613 if (dimmInfo->suportedCasLatencies & 8)
614 DP (printf ("2.5, "));
615 if (dimmInfo->suportedCasLatencies & 16)
616 DP (printf ("3, "));
617 if (dimmInfo->suportedCasLatencies & 32)
618 DP (printf ("3.5, "));
619
620 }
621 DP (printf ("\n"));
622#endif
623
624 for (j = 7; j > 0; j--) {
625 if (((dimmInfo->
626 suportedCasLatencies >> j) & 0x1) ==
627 1) {
628 switch (dimmInfo->memoryType) {
629 case DDR:
630
631 switch (j) {
632 case 7:
633 DP (printf
634 ("Max. Cas Latencies (DDR): ERROR !!!\n"));
635 dimmInfo->
636 maxClSupported_DDR
637 =
638 DDR_CL_FAULT;
639 hang ();
640 break;
641 case 6:
642 DP (printf
643 ("Max. Cas Latencies (DDR): ERROR !!!\n"));
644 dimmInfo->
645 maxClSupported_DDR
646 =
647 DDR_CL_FAULT;
648 hang ();
649 break;
650 case 5:
651 DP (printf
652 ("Max. Cas Latencies (DDR): 3.5 clk's\n"));
653 dimmInfo->
654 maxClSupported_DDR
655 = DDR_CL_3_5;
656 break;
657 case 4:
658 DP (printf
659 ("Max. Cas Latencies (DDR): 3 clk's \n"));
660 dimmInfo->
661 maxClSupported_DDR
662 = DDR_CL_3;
663 break;
664 case 3:
665 DP (printf
666 ("Max. Cas Latencies (DDR): 2.5 clk's \n"));
667 dimmInfo->
668 maxClSupported_DDR
669 = DDR_CL_2_5;
670 break;
671 case 2:
672 DP (printf
673 ("Max. Cas Latencies (DDR): 2 clk's \n"));
674 dimmInfo->
675 maxClSupported_DDR
676 = DDR_CL_2;
677 break;
678 case 1:
679 DP (printf
680 ("Max. Cas Latencies (DDR): 1.5 clk's \n"));
681 dimmInfo->
682 maxClSupported_DDR
683 = DDR_CL_1_5;
684 break;
685 }
686
687
688
689
690 if ((dimmInfo->
691 minimumCycleTimeAtMaxCasLatancy_LoP
692 <
693 CONFIG_SYS_DDR_SDRAM_CYCLE_COUNT_LOP)
694 ||
695 ((dimmInfo->
696 minimumCycleTimeAtMaxCasLatancy_LoP
697 ==
698 CONFIG_SYS_DDR_SDRAM_CYCLE_COUNT_LOP)
699 && (dimmInfo->
700 minimumCycleTimeAtMaxCasLatancy_RoP
701 <
702 CONFIG_SYS_DDR_SDRAM_CYCLE_COUNT_ROP)))
703 {
704 dimmInfo->
705 maxClSupported_DDR
706 =
707 dimmInfo->
708 maxClSupported_DDR
709 >> 1;
710 DP (printf
711 ("*** Change actual Cas Latencies cause of minimumCycleTime n"));
712 }
713
714 if ((dimmInfo->
715 minimumCycleTimeAtMaxCasLatancy_LoP
716 >
717 CONFIG_SYS_DDR_SDRAM_CYCLE_COUNT_LOP)
718 ||
719 ((dimmInfo->
720 minimumCycleTimeAtMaxCasLatancy_LoP
721 ==
722 CONFIG_SYS_DDR_SDRAM_CYCLE_COUNT_LOP)
723 && (dimmInfo->
724 minimumCycleTimeAtMaxCasLatancy_RoP
725 >
726 CONFIG_SYS_DDR_SDRAM_CYCLE_COUNT_ROP)))
727 {
728 printf ("*********************************************************\n");
729 printf ("*** sysClock is higher than SDRAM's allowed frequency ***\n");
730 printf ("*********************************************************\n");
731 hang ();
732 }
733
734 dimmInfo->
735 maxCASlatencySupported_LoP
736 =
737 1 +
738 (int) (5 * j / 10);
739 if (((5 * j) % 10) != 0)
740 dimmInfo->
741 maxCASlatencySupported_RoP
742 = 5;
743 else
744 dimmInfo->
745 maxCASlatencySupported_RoP
746 = 0;
747 DP (printf
748 ("Max. Cas Latencies (DDR LoP.RoP Notation): %d.%d \n",
749 dimmInfo->
750 maxCASlatencySupported_LoP,
751 dimmInfo->
752 maxCASlatencySupported_RoP));
753 break;
754 case SDRAM:
755
756 dimmInfo->maxClSupported_SD = j;
757 DP (printf
758 ("Max. Cas Latencies (SD): %d\n",
759 dimmInfo->
760 maxClSupported_SD));
761 dimmInfo->
762 maxCASlatencySupported_LoP
763 = j;
764 dimmInfo->
765 maxCASlatencySupported_RoP
766 = 0;
767 DP (printf
768 ("Max. Cas Latencies (DDR LoP.RoP Notation): %d.%d \n",
769 dimmInfo->
770 maxCASlatencySupported_LoP,
771 dimmInfo->
772 maxCASlatencySupported_RoP));
773 break;
774 }
775 break;
776 }
777 }
778 break;
779
780
781 case 21:
782 DP (printf ("\nModul Attributes (SPD Byte 21): \n"));
783 dimmInfo->bufferedAddrAndControlInputs =
784 data[i] & BIT0;
785 dimmInfo->registeredAddrAndControlInputs =
786 (data[i] & BIT1) >> 1;
787 dimmInfo->onCardPLL = (data[i] & BIT2) >> 2;
788 dimmInfo->bufferedDQMBinputs = (data[i] & BIT3) >> 3;
789 dimmInfo->registeredDQMBinputs =
790 (data[i] & BIT4) >> 4;
791 dimmInfo->differentialClockInput =
792 (data[i] & BIT5) >> 5;
793 dimmInfo->redundantRowAddressing =
794 (data[i] & BIT6) >> 6;
795#ifdef DEBUG
796 if (dimmInfo->bufferedAddrAndControlInputs == 1)
797 DP (printf
798 (" - Buffered Address/Control Input: Yes \n"));
799 else
800 DP (printf
801 (" - Buffered Address/Control Input: No \n"));
802
803 if (dimmInfo->registeredAddrAndControlInputs == 1)
804 DP (printf
805 (" - Registered Address/Control Input: Yes \n"));
806 else
807 DP (printf
808 (" - Registered Address/Control Input: No \n"));
809
810 if (dimmInfo->onCardPLL == 1)
811 DP (printf
812 (" - On-Card PLL (clock): Yes \n"));
813 else
814 DP (printf
815 (" - On-Card PLL (clock): No \n"));
816
817 if (dimmInfo->bufferedDQMBinputs == 1)
818 DP (printf
819 (" - Bufferd DQMB Inputs: Yes \n"));
820 else
821 DP (printf
822 (" - Bufferd DQMB Inputs: No \n"));
823
824 if (dimmInfo->registeredDQMBinputs == 1)
825 DP (printf
826 (" - Registered DQMB Inputs: Yes \n"));
827 else
828 DP (printf
829 (" - Registered DQMB Inputs: No \n"));
830
831 if (dimmInfo->differentialClockInput == 1)
832 DP (printf
833 (" - Differential Clock Input: Yes \n"));
834 else
835 DP (printf
836 (" - Differential Clock Input: No \n"));
837
838 if (dimmInfo->redundantRowAddressing == 1)
839 DP (printf
840 (" - redundant Row Addressing: Yes \n"));
841 else
842 DP (printf
843 (" - redundant Row Addressing: No \n"));
844
845#endif
846 break;
847
848
849 case 22:
850 DP (printf ("\nModul Attributes (SPD Byte 22): \n"));
851 dimmInfo->suportedEarlyRasPreCharge = data[i] & BIT0;
852 dimmInfo->suportedAutoPreCharge =
853 (data[i] & BIT1) >> 1;
854 dimmInfo->suportedPreChargeAll =
855 (data[i] & BIT2) >> 2;
856 dimmInfo->suportedWrite1ReadBurst =
857 (data[i] & BIT3) >> 3;
858 dimmInfo->suported5PercentLowVCC =
859 (data[i] & BIT4) >> 4;
860 dimmInfo->suported5PercentUpperVCC =
861 (data[i] & BIT5) >> 5;
862#ifdef DEBUG
863 if (dimmInfo->suportedEarlyRasPreCharge == 1)
864 DP (printf
865 (" - Early Ras Precharge: Yes \n"));
866 else
867 DP (printf
868 (" - Early Ras Precharge: No \n"));
869
870 if (dimmInfo->suportedAutoPreCharge == 1)
871 DP (printf
872 (" - AutoPreCharge: Yes \n"));
873 else
874 DP (printf
875 (" - AutoPreCharge: No \n"));
876
877 if (dimmInfo->suportedPreChargeAll == 1)
878 DP (printf
879 (" - Precharge All: Yes \n"));
880 else
881 DP (printf
882 (" - Precharge All: No \n"));
883
884 if (dimmInfo->suportedWrite1ReadBurst == 1)
885 DP (printf
886 (" - Write 1/ReadBurst: Yes \n"));
887 else
888 DP (printf
889 (" - Write 1/ReadBurst: No \n"));
890
891 if (dimmInfo->suported5PercentLowVCC == 1)
892 DP (printf
893 (" - lower VCC tolerance: 5 Percent \n"));
894 else
895 DP (printf
896 (" - lower VCC tolerance: 10 Percent \n"));
897
898 if (dimmInfo->suported5PercentUpperVCC == 1)
899 DP (printf
900 (" - upper VCC tolerance: 5 Percent \n"));
901 else
902 DP (printf
903 (" - upper VCC tolerance: 10 Percent \n"));
904
905#endif
906 break;
907
908
909 case 23:
910 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
911 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
912 maskLeftOfPoint =
913 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
914 maskRightOfPoint =
915 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
916 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
917 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
918 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus1_LoP =
919 leftOfPoint;
920 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus1_RoP =
921 rightOfPoint;
922 DP (printf ("Minimum Cycle Time At 2nd highest CasLatancy (0 = Not supported): %d.%d [ns]\n", leftOfPoint, rightOfPoint));
923 break;
924
925
926 case 24:
927 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
928 time_tmp =
929 (((data[i] & 0xf0) >> 4) * 10) +
930 ((data[i] & 0x0f));
931 leftOfPoint = time_tmp / div;
932 rightOfPoint = time_tmp % div;
933 dimmInfo->clockToDataOutMinus1_LoP = leftOfPoint;
934 dimmInfo->clockToDataOutMinus1_RoP = rightOfPoint;
935 DP (printf
936 ("Clock To Data Out (2nd CL value): %d.%2d [ns]\n",
937 leftOfPoint, rightOfPoint));
938 break;
939
940
941 case 25:
942 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
943 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
944 maskLeftOfPoint =
945 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
946 maskRightOfPoint =
947 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
948 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
949 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
950 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus2_LoP =
951 leftOfPoint;
952 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus2_RoP =
953 rightOfPoint;
954 DP (printf ("Minimum Cycle Time At 3rd highest CasLatancy (0 = Not supported): %d.%d [ns]\n", leftOfPoint, rightOfPoint));
955 break;
956
957
958 case 26:
959 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
960 time_tmp =
961 (((data[i] & 0xf0) >> 4) * 10) +
962 ((data[i] & 0x0f));
963 leftOfPoint = time_tmp / div;
964 rightOfPoint = time_tmp % div;
965 dimmInfo->clockToDataOutMinus2_LoP = leftOfPoint;
966 dimmInfo->clockToDataOutMinus2_RoP = rightOfPoint;
967 DP (printf
968 ("Clock To Data Out (3rd CL value): %d.%2d [ns]\n",
969 leftOfPoint, rightOfPoint));
970 break;
971
972
973 case 27:
974 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
975 maskLeftOfPoint =
976 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
977 maskRightOfPoint =
978 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
979 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
980 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
981
982 dimmInfo->minRowPrechargeTime = ((leftOfPoint * 100) + rightOfPoint);
983 trp_clocks =
984 (dimmInfo->minRowPrechargeTime +
985 (tmemclk - 1)) / tmemclk;
986 DP (printf
987 ("*** 1 clock cycle = %ld 10ps intervalls = %ld.%ld ns****\n",
988 tmemclk, tmemclk / 100, tmemclk % 100));
989 DP (printf
990 ("Minimum Row Precharge Time [ns]: %d.%2d = in Clk cycles %d\n",
991 leftOfPoint, rightOfPoint, trp_clocks));
992 break;
993
994
995 case 28:
996 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
997 maskLeftOfPoint =
998 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
999 maskRightOfPoint =
1000 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
1001 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
1002 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
1003
1004 dimmInfo->minRowActiveRowActiveDelay = ((leftOfPoint * 100) + rightOfPoint);
1005 trrd_clocks =
1006 (dimmInfo->minRowActiveRowActiveDelay +
1007 (tmemclk - 1)) / tmemclk;
1008 DP (printf
1009 ("Minimum Row Active -To- Row Active Delay [ns]: %d.%2d = in Clk cycles %d\n",
1010 leftOfPoint, rightOfPoint, trp_clocks));
1011 break;
1012
1013
1014 case 29:
1015 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
1016 maskLeftOfPoint =
1017 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
1018 maskRightOfPoint =
1019 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
1020 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
1021 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
1022
1023 dimmInfo->minRowActiveRowActiveDelay = ((leftOfPoint * 100) + rightOfPoint);
1024 trcd_clocks =
1025 (dimmInfo->minRowActiveRowActiveDelay +
1026 (tmemclk - 1)) / tmemclk;
1027 DP (printf
1028 ("Minimum Ras-To-Cas Delay [ns]: %d.%2d = in Clk cycles %d\n",
1029 leftOfPoint, rightOfPoint, trp_clocks));
1030 break;
1031
1032
1033 case 30:
1034 dimmInfo->minRasPulseWidth = data[i];
1035 tras_clocks =
1036 (NSto10PS (data[i]) +
1037 (tmemclk - 1)) / tmemclk;
1038 DP (printf
1039 ("Minimum Ras Pulse Width [ns]: %d = in Clk cycles %d\n",
1040 dimmInfo->minRasPulseWidth, tras_clocks));
1041
1042 break;
1043
1044
1045 case 31:
1046 dimmInfo->moduleBankDensity = data[i];
1047 DP (printf
1048 ("Module Bank Density: %d\n",
1049 dimmInfo->moduleBankDensity));
1050#ifdef DEBUG
1051 DP (printf
1052 ("*** Offered Densities (more than 1 = Multisize-Module): "));
1053 {
1054 if (dimmInfo->moduleBankDensity & 1)
1055 DP (printf ("4MB, "));
1056 if (dimmInfo->moduleBankDensity & 2)
1057 DP (printf ("8MB, "));
1058 if (dimmInfo->moduleBankDensity & 4)
1059 DP (printf ("16MB, "));
1060 if (dimmInfo->moduleBankDensity & 8)
1061 DP (printf ("32MB, "));
1062 if (dimmInfo->moduleBankDensity & 16)
1063 DP (printf ("64MB, "));
1064 if (dimmInfo->moduleBankDensity & 32)
1065 DP (printf ("128MB, "));
1066 if ((dimmInfo->moduleBankDensity & 64)
1067 || (dimmInfo->moduleBankDensity & 128)) {
1068 DP (printf ("ERROR, "));
1069 hang ();
1070 }
1071 }
1072 DP (printf ("\n"));
1073#endif
1074 break;
1075
1076
1077 case 32:
1078 sign = 1;
1079 switch (dimmInfo->memoryType) {
1080 case DDR:
1081 time_tmp =
1082 (((data[i] & 0xf0) >> 4) * 10) +
1083 ((data[i] & 0x0f));
1084 leftOfPoint = time_tmp / 100;
1085 rightOfPoint = time_tmp % 100;
1086 break;
1087 case SDRAM:
1088 leftOfPoint = (data[i] & 0xf0) >> 4;
1089 if (leftOfPoint > 7) {
1090 leftOfPoint = data[i] & 0x70 >> 4;
1091 sign = -1;
1092 }
1093 rightOfPoint = (data[i] & 0x0f);
1094 break;
1095 }
1096 dimmInfo->addrAndCommandSetupTime =
1097 (leftOfPoint * 100 + rightOfPoint) * sign;
1098 DP (printf
1099 ("Address And Command Setup Time [ns]: %d.%d\n",
1100 sign * leftOfPoint, rightOfPoint));
1101 break;
1102
1103
1104 case 33:
1105 sign = 1;
1106 switch (dimmInfo->memoryType) {
1107 case DDR:
1108 time_tmp =
1109 (((data[i] & 0xf0) >> 4) * 10) +
1110 ((data[i] & 0x0f));
1111 leftOfPoint = time_tmp / 100;
1112 rightOfPoint = time_tmp % 100;
1113 break;
1114 case SDRAM:
1115 leftOfPoint = (data[i] & 0xf0) >> 4;
1116 if (leftOfPoint > 7) {
1117 leftOfPoint = data[i] & 0x70 >> 4;
1118 sign = -1;
1119 }
1120 rightOfPoint = (data[i] & 0x0f);
1121 break;
1122 }
1123 dimmInfo->addrAndCommandHoldTime =
1124 (leftOfPoint * 100 + rightOfPoint) * sign;
1125 DP (printf
1126 ("Address And Command Hold Time [ns]: %d.%d\n",
1127 sign * leftOfPoint, rightOfPoint));
1128 break;
1129
1130
1131 case 34:
1132 sign = 1;
1133 switch (dimmInfo->memoryType) {
1134 case DDR:
1135 time_tmp =
1136 (((data[i] & 0xf0) >> 4) * 10) +
1137 ((data[i] & 0x0f));
1138 leftOfPoint = time_tmp / 100;
1139 rightOfPoint = time_tmp % 100;
1140 break;
1141 case SDRAM:
1142 leftOfPoint = (data[i] & 0xf0) >> 4;
1143 if (leftOfPoint > 7) {
1144 leftOfPoint = data[i] & 0x70 >> 4;
1145 sign = -1;
1146 }
1147 rightOfPoint = (data[i] & 0x0f);
1148 break;
1149 }
1150 dimmInfo->dataInputSetupTime =
1151 (leftOfPoint * 100 + rightOfPoint) * sign;
1152 DP (printf
1153 ("Data Input Setup Time [ns]: %d.%d\n",
1154 sign * leftOfPoint, rightOfPoint));
1155 break;
1156
1157
1158 case 35:
1159 sign = 1;
1160 switch (dimmInfo->memoryType) {
1161 case DDR:
1162 time_tmp =
1163 (((data[i] & 0xf0) >> 4) * 10) +
1164 ((data[i] & 0x0f));
1165 leftOfPoint = time_tmp / 100;
1166 rightOfPoint = time_tmp % 100;
1167 break;
1168 case SDRAM:
1169 leftOfPoint = (data[i] & 0xf0) >> 4;
1170 if (leftOfPoint > 7) {
1171 leftOfPoint = data[i] & 0x70 >> 4;
1172 sign = -1;
1173 }
1174 rightOfPoint = (data[i] & 0x0f);
1175 break;
1176 }
1177 dimmInfo->dataInputHoldTime =
1178 (leftOfPoint * 100 + rightOfPoint) * sign;
1179 DP (printf
1180 ("Data Input Hold Time [ns]: %d.%d\n\n",
1181 sign * leftOfPoint, rightOfPoint));
1182 break;
1183
1184 }
1185 }
1186
1187 for (i = 0;
1188 i < dimmInfo->numOfRowAddresses + dimmInfo->numOfColAddresses;
1189 i++) {
1190 density = density * 2;
1191 }
1192 dimmInfo->deviceDensity = density * dimmInfo->numOfBanksOnEachDevice *
1193 dimmInfo->sdramWidth;
1194 dimmInfo->numberOfDevices =
1195 (dimmInfo->dataWidth / dimmInfo->sdramWidth) *
1196 dimmInfo->numOfModuleBanks;
1197 devicesForErrCheck =
1198 (dimmInfo->dataWidth - 64) / dimmInfo->sdramWidth;
1199 if ((dimmInfo->errorCheckType == 0x1)
1200 || (dimmInfo->errorCheckType == 0x2)
1201 || (dimmInfo->errorCheckType == 0x3)) {
1202 dimmInfo->size =
1203 (dimmInfo->deviceDensity / 8) *
1204 (dimmInfo->numberOfDevices -
1205
1206 dimmInfo->numberOfDevices / 8);
1207 } else {
1208 dimmInfo->size =
1209 (dimmInfo->deviceDensity / 8) *
1210 dimmInfo->numberOfDevices;
1211 }
1212
1213
1214 tmp = (1 <<
1215 (dimmInfo->numOfRowAddresses + dimmInfo->numOfColAddresses));
1216 tmp *= dimmInfo->numOfModuleBanks;
1217 tmp *= dimmInfo->sdramWidth;
1218 tmp = tmp >> 24;
1219 dimmInfo->drb_size = (uchar) tmp;
1220 DP (printf ("Module DRB size (n*64Mbit): %d\n", dimmInfo->drb_size));
1221
1222
1223
1224
1225 supp_cal = (dimmInfo->suportedCasLatencies & 0x6) >> 1;
1226
1227 cal_val = 0;
1228 if (supp_cal & 3) {
1229 if (NS10to10PS (data[9]) <= tmemclk)
1230 cal_val = 3;
1231 }
1232
1233
1234 if (supp_cal & 2) {
1235 if (NS10to10PS (data[23]) <= tmemclk)
1236 cal_val = 2;
1237 }
1238
1239 DP (printf ("cal_val = %d\n", cal_val));
1240
1241
1242 if (cal_val == 0) {
1243 DP (printf ("Couldn't find a good CAS latency\n"));
1244 hang ();
1245 return 0;
1246 }
1247
1248 return true;
1249#endif
1250}
1251
1252
1253int setup_sdram (AUX_MEM_DIMM_INFO * info)
1254{
1255 ulong tmp, check;
1256 ulong tmp_sdram_mode = 0;
1257 ulong tmp_dunit_control_low = 0;
1258 int i;
1259
1260
1261 unsigned int sdram_config_reg;
1262
1263
1264 ulong sdram_chip_size;
1265
1266
1267 if (!info->numOfModuleBanks) {
1268 printf ("setup_sdram called with 0 banks\n");
1269 return 1;
1270 }
1271
1272
1273 set_dfcdlInit ();
1274 DP (printf ("Delay line set done\n"));
1275
1276
1277 GT_REG_WRITE (SDRAM_OPERATION, 0x5);
1278 while (GTREGREAD (SDRAM_OPERATION) != 0) {
1279 DP (printf
1280 ("\n*** SDRAM_OPERATION 1418: Module still busy ... please wait... ***\n"));
1281 }
1282
1283
1284
1285
1286
1287
1288 switch (info->RefreshInterval) {
1289 case 0x0:
1290 case 0x80:
1291 sdram_config_reg =
1292 (unsigned int) (((float) 15.625 * (float) CONFIG_SYS_BUS_HZ)
1293 / (float) 1000000.0);
1294 break;
1295 case 0x1:
1296 case 0x81:
1297 sdram_config_reg =
1298 (unsigned int) (((float) 3.9 * (float) CONFIG_SYS_BUS_HZ) /
1299 (float) 1000000.0);
1300 break;
1301 case 0x2:
1302 case 0x82:
1303 sdram_config_reg =
1304 (unsigned int) (((float) 7.8 * (float) CONFIG_SYS_BUS_HZ) /
1305 (float) 1000000.0);
1306 break;
1307 case 0x3:
1308 case 0x83:
1309 sdram_config_reg =
1310 (unsigned int) (((float) 31.3 * (float) CONFIG_SYS_BUS_HZ) /
1311 (float) 1000000.0);
1312 break;
1313 case 0x4:
1314 case 0x84:
1315 sdram_config_reg =
1316 (unsigned int) (((float) 62.5 * (float) CONFIG_SYS_BUS_HZ) /
1317 (float) 1000000.0);
1318 break;
1319 case 0x5:
1320 case 0x85:
1321 sdram_config_reg =
1322 (unsigned int) (((float) 125 * (float) CONFIG_SYS_BUS_HZ) /
1323 (float) 1000000.0);
1324 break;
1325 default:
1326 printf ("DRAM refresh period is unknown!\n");
1327 printf ("Aborting DRAM setup with an error\n");
1328 hang ();
1329 break;
1330 }
1331 DP (printf ("calculated refresh interval %0x\n", sdram_config_reg));
1332
1333
1334 if (sdram_config_reg > 0x1fff)
1335 sdram_config_reg = 0x1fff;
1336 DP (printf ("adjusted refresh interval %0x\n", sdram_config_reg));
1337
1338
1339
1340
1341
1342
1343 if (info->registeredAddrAndControlInputs == 1) {
1344
1345 sdram_config_reg = sdram_config_reg | BIT17;
1346 DP (printf ("Enabling registered DRAM bit\n"));
1347 }
1348
1349#ifdef CONFIG_MV64460_ECC
1350 if (info->errorCheckType == 0x2) {
1351
1352 sdram_config_reg = sdram_config_reg | BIT18;
1353 DP (printf ("Enabling ECC\n"));
1354 }
1355#endif
1356
1357 switch (info->sdramWidth) {
1358 case 0x4:
1359 sdram_config_reg = sdram_config_reg | BIT20 | BIT21;
1360 DP (printf ("Data DQS pins set for 16 pins\n"));
1361 break;
1362 case 0x8:
1363 case 0x10:
1364 sdram_config_reg = sdram_config_reg | BIT21;
1365 DP (printf ("Data DQS pins set for 8 pins\n"));
1366 break;
1367 case 0x20:
1368
1369 DP (printf ("Data DQS pins set for 2 pins\n"));
1370 break;
1371 default:
1372 printf ("DRAM chip width is unknown!\n");
1373 printf ("Aborting DRAM setup with an error\n");
1374 hang ();
1375 break;
1376 }
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386 sdram_config_reg = sdram_config_reg | 0x58000000;
1387 sdram_config_reg = sdram_config_reg & 0xffffff00;
1388
1389
1390
1391 sdram_config_reg = sdram_config_reg | BIT14 | BIT15;
1392
1393
1394 GT_REG_WRITE (SDRAM_CONFIG, sdram_config_reg);
1395 DP (printf ("sdram_conf 0x1400: %08x\n", GTREGREAD (SDRAM_CONFIG)));
1396
1397
1398 GT_REG_WRITE (SDRAM_OPEN_PAGES_CONTROL, 0x0);
1399 DP (printf
1400 ("sdram_open_pages_controll 0x1414: %08x\n",
1401 GTREGREAD (SDRAM_OPEN_PAGES_CONTROL)));
1402
1403
1404 tmp = (GTREGREAD (D_UNIT_CONTROL_LOW) & 0x01);
1405 if (tmp == 0)
1406 DP (printf ("Core Signals are sync (by HW-Setting)!!!\n"));
1407 else
1408 DP (printf
1409 ("Core Signals syncs. are bypassed (by HW-Setting)!!!\n"));
1410
1411
1412 switch (info->memoryType) {
1413 case SDRAM:
1414 printf ("### SD-RAM not supported !!!\n");
1415 printf ("Aborting!!!\n");
1416 hang ();
1417
1418 break;
1419
1420
1421 case DDR:
1422 DP (printf ("### SET-CL for DDR-RAM\n"));
1423
1424 switch (info->maxClSupported_DDR) {
1425 case DDR_CL_3:
1426 tmp_sdram_mode = 0x32;
1427 if (tmp == 1) {
1428 if (info->registeredAddrAndControlInputs == 1)
1429 tmp_dunit_control_low = 0x05110051;
1430 else
1431 tmp_dunit_control_low = 0x24110051;
1432 DP (printf
1433 ("Max. CL is 3 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1434 tmp_sdram_mode, tmp_dunit_control_low));
1435 printf ("Warnning: DRAM ClkSync was never tested(db64460)!!!!!\n");
1436 } else {
1437
1438 if (info->registeredAddrAndControlInputs == 1)
1439 tmp_dunit_control_low = 0xC5000540;
1440 else
1441 tmp_dunit_control_low = 0xC4000540;
1442 DP (printf
1443 ("Max. CL is 3 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1444 tmp_sdram_mode, tmp_dunit_control_low));
1445 }
1446 break;
1447 case DDR_CL_2_5:
1448 tmp_sdram_mode = 0x62;
1449 if (tmp == 1) {
1450 if (info->registeredAddrAndControlInputs == 1)
1451 tmp_dunit_control_low = 0x25110051;
1452 else
1453 tmp_dunit_control_low = 0x24110051;
1454 DP (printf
1455 ("Max. CL is 2.5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1456 tmp_sdram_mode, tmp_dunit_control_low));
1457 printf ("Warnning: DRAM ClkSync was never tested(db64460)!!!!!\n");
1458 } else {
1459
1460 if (info->registeredAddrAndControlInputs == 1) {
1461 tmp_dunit_control_low = 0xC5000540;
1462
1463
1464
1465 } else
1466 tmp_dunit_control_low = 0xC4000540;
1467 DP (printf
1468 ("Max. CL is 2.5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1469 tmp_sdram_mode, tmp_dunit_control_low));
1470 }
1471 break;
1472 case DDR_CL_2:
1473 tmp_sdram_mode = 0x22;
1474 if (tmp == 1) {
1475 if (info->registeredAddrAndControlInputs == 1)
1476 tmp_dunit_control_low = 0x04110051;
1477 else
1478 tmp_dunit_control_low = 0x03110051;
1479 DP (printf
1480 ("Max. CL is 2 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1481 tmp_sdram_mode, tmp_dunit_control_low));
1482 printf ("Warnning: DRAM ClkSync was never tested(db64460)!!!!!\n");
1483 } else {
1484
1485 if (info->registeredAddrAndControlInputs == 1) {
1486
1487
1488
1489 tmp_dunit_control_low = 0xC4000540;
1490 } else
1491 tmp_dunit_control_low = 0xC3000540;;
1492 DP (printf
1493 ("Max. CL is 2 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1494 tmp_sdram_mode, tmp_dunit_control_low));
1495 }
1496 break;
1497 case DDR_CL_1_5:
1498 tmp_sdram_mode = 0x52;
1499 if (tmp == 1) {
1500 if (info->registeredAddrAndControlInputs == 1)
1501 tmp_dunit_control_low = 0x24110051;
1502 else
1503 tmp_dunit_control_low = 0x23110051;
1504 DP (printf
1505 ("Max. CL is 1.5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1506 tmp_sdram_mode, tmp_dunit_control_low));
1507 printf ("Warnning: DRAM ClkSync was never tested(db64460)!!!!!\n");
1508 } else {
1509
1510 if (info->registeredAddrAndControlInputs == 1) {
1511
1512
1513
1514 tmp_dunit_control_low = 0xC4000540;
1515 } else
1516 tmp_dunit_control_low = 0xC3000540;
1517 DP (printf
1518 ("Max. CL is 1.5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1519 tmp_sdram_mode, tmp_dunit_control_low));
1520 }
1521 break;
1522
1523 default:
1524 printf ("Max. CL is out of range %d\n",
1525 info->maxClSupported_DDR);
1526 hang ();
1527 break;
1528 }
1529 break;
1530 }
1531
1532
1533
1534 GT_REG_WRITE (SDRAM_MODE, tmp_sdram_mode);
1535
1536
1537 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1538 while (GTREGREAD (SDRAM_OPERATION) != 0) {
1539 DP (printf
1540 ("\n*** SDRAM_OPERATION 0x1418 after SDRAM_MODE: Module still busy ... please wait... ***\n"));
1541 }
1542
1543
1544 GT_REG_WRITE (D_UNIT_CONTROL_LOW, tmp_dunit_control_low);
1545
1546
1547 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1548 while (GTREGREAD (SDRAM_OPERATION) != 0) {
1549 DP (printf
1550 ("\n*** SDRAM_OPERATION 1418 after D_UNIT_CONTROL_LOW: Module still busy ... please wait... ***\n"));
1551 }
1552
1553
1554
1555
1556
1557
1558 tmp = 0x02;
1559
1560 DP (printf ("drb_size (n*64Mbit): %d\n", info->drb_size));
1561
1562 sdram_chip_size =
1563 (1 << (info->numOfRowAddresses + info->numOfColAddresses));
1564 sdram_chip_size *= info->sdramWidth;
1565 sdram_chip_size *= 4;
1566 DP (printf ("computed sdram chip size is %#lx\n", sdram_chip_size));
1567
1568 sdram_chip_size = sdram_chip_size / 0x4000000;
1569 switch (sdram_chip_size) {
1570 case 1:
1571 case 2:
1572 DP (printf ("RAM-Device_size 64Mbit or 128Mbit)\n"));
1573 tmp |= (0x00 << 4);
1574 break;
1575 case 4:
1576 case 8:
1577 DP (printf ("RAM-Device_size 256Mbit or 512Mbit)\n"));
1578 tmp |= (0x01 << 4);
1579 break;
1580 case 16:
1581 case 32:
1582 DP (printf ("RAM-Device_size 1Gbit or 2Gbit)\n"));
1583 tmp |= (0x02 << 4);
1584 break;
1585 default:
1586 printf ("Error in dram size calculation\n");
1587 printf ("RAM-Device_size is unsupported\n");
1588 hang ();
1589 }
1590
1591
1592 GT_REG_WRITE (SDRAM_ADDR_CONTROL, tmp);
1593 DP (printf
1594 ("setting up sdram address control (0x1410) with: %08lx \n",
1595 tmp));
1596
1597
1598
1599 DP (printf
1600 ("setting up sdram_timing_control_low (0x1408) with: %08x \n",
1601 0x01501220));
1602
1603 GT_REG_WRITE (SDRAM_TIMING_CONTROL_LOW, 0x01501220);
1604
1605
1606
1607
1608
1609 tmp = GTREGREAD (SDRAM_CONFIG);
1610
1611 if (info->registeredAddrAndControlInputs
1612 || info->registeredDQMBinputs) {
1613 tmp |= (1 << 17);
1614 DP (printf
1615 ("SPD says: registered Addr. and Cont.: %d; registered DQMBinputs: %d\n",
1616 info->registeredAddrAndControlInputs,
1617 info->registeredDQMBinputs));
1618 }
1619
1620
1621
1622
1623
1624
1625
1626 tmp |= (1 << 26);
1627 DP (printf
1628 ("Before Buffer assignment - sdram_conf (0x1400): %08x\n",
1629 GTREGREAD (SDRAM_CONFIG)));
1630 DP (printf
1631 ("After Buffer assignment - sdram_conf (0x1400): %08x\n",
1632 GTREGREAD (SDRAM_CONFIG)));
1633
1634
1635
1636
1637 DP (printf
1638 ("setting up sdram_timing_control_high (0x140c) with: %08x \n",
1639 0xc));
1640 GT_REG_WRITE (SDRAM_TIMING_CONTROL_HIGH, 0xc);
1641
1642 DP (printf
1643 ("setting up sdram address pads control (0x14c0) with: %08x \n",
1644 0x7d5014a));
1645 GT_REG_WRITE (SDRAM_ADDR_CTRL_PADS_CALIBRATION, 0x7d5014a);
1646
1647 DP (printf
1648 ("setting up sdram data pads control (0x14c4) with: %08x \n",
1649 0x7d5014a));
1650 GT_REG_WRITE (SDRAM_DATA_PADS_CALIBRATION, 0x7d5014a);
1651
1652
1653
1654
1655
1656
1657 {
1658 i = info->slot;
1659 DP (printf
1660 ("\n*** Running a MRS cycle for bank %d ***\n", i));
1661
1662
1663 memory_map_bank (i, 0, GB / 4);
1664
1665
1666 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1667 check = GTREGREAD (SDRAM_OPERATION);
1668 DP (printf
1669 ("\n*** SDRAM_OPERATION 1418 (0 = Normal Operation) = %08lx ***\n",
1670 check));
1671
1672
1673
1674 GT_REG_WRITE (SDRAM_OPERATION, 0);
1675 check = GTREGREAD (SDRAM_OPERATION);
1676 DP (printf
1677 ("\n*** SDRAM_OPERATION 1418 (0 = Normal Operation) = %08lx ***\n",
1678 check));
1679
1680
1681 memory_map_bank (i, 0, 0);
1682 }
1683
1684 return 0;
1685
1686}
1687
1688
1689
1690
1691
1692
1693
1694
1695long int dram_size (long int *base, long int maxsize)
1696{
1697 volatile long int *addr, *b = base;
1698 long int cnt, val, save1, save2;
1699
1700#define STARTVAL (1<<20)
1701 for (cnt = STARTVAL / sizeof (long); cnt < maxsize / sizeof (long);
1702 cnt <<= 1) {
1703 addr = base + cnt;
1704
1705 save1 = *addr;
1706 save2 = *b;
1707
1708 *addr = cnt;
1709 *b = 0;
1710
1711
1712 if ((*b) != 0) {
1713 *addr = save1;
1714 *b = save2;
1715 return (0);
1716 }
1717 val = *addr;
1718 val = *addr;
1719
1720 *addr = save1;
1721 *b = save2;
1722
1723 if (val != cnt) {
1724 DP (printf
1725 ("Found %08x at Address %08x (failure)\n",
1726 (unsigned int) val, (unsigned int) addr));
1727
1728 if (cnt == STARTVAL / sizeof (long))
1729 cnt = 0;
1730 return (cnt * sizeof (long));
1731 }
1732 }
1733 return maxsize;
1734}
1735
1736
1737
1738
1739
1740phys_size_t initdram (int board_type)
1741{
1742 int s0 = 0, s1 = 0;
1743 int checkbank[4] = {[0 ... 3] = 0 };
1744 ulong realsize, total, check;
1745 AUX_MEM_DIMM_INFO dimmInfo1;
1746 AUX_MEM_DIMM_INFO dimmInfo2;
1747 int nhr, bank_no;
1748 ulong dest, memSpaceAttr;
1749
1750
1751
1752
1753 nhr = get_hid0 () & (1 << 16);
1754
1755 if (nhr) {
1756 printf ("Skipping SD- DDRRAM setup due to NHR bit being set\n");
1757 } else {
1758
1759 s0 = check_dimm (0, &dimmInfo1);
1760
1761
1762 s1 = check_dimm (1, &dimmInfo2);
1763
1764 memory_map_bank (0, 0, 0);
1765 memory_map_bank (1, 0, 0);
1766 memory_map_bank (2, 0, 0);
1767 memory_map_bank (3, 0, 0);
1768
1769
1770 if (dimmInfo1.numOfModuleBanks && dimmInfo2.numOfModuleBanks) {
1771 if (dimmInfo1.errorCheckType !=
1772 dimmInfo2.errorCheckType)
1773 printf ("***WARNNING***!!!! different ECC support of the DIMMS\n");
1774 if (dimmInfo1.maxClSupported_DDR !=
1775 dimmInfo2.maxClSupported_DDR)
1776 printf ("***WARNNING***!!!! different CAL setting of the DIMMS\n");
1777 if (dimmInfo1.registeredAddrAndControlInputs !=
1778 dimmInfo2.registeredAddrAndControlInputs)
1779 printf ("***WARNNING***!!!! different Registration setting of the DIMMS\n");
1780 }
1781
1782 if (dimmInfo1.numOfModuleBanks && setup_sdram (&dimmInfo1)) {
1783 printf ("Setup for DIMM1 failed.\n");
1784 }
1785
1786 if (dimmInfo2.numOfModuleBanks && setup_sdram (&dimmInfo2)) {
1787 printf ("Setup for DIMM2 failed.\n");
1788 }
1789
1790
1791 set_hid0 (get_hid0 () | (1 << 16));
1792 }
1793
1794
1795 realsize = total = 0;
1796 check = GB / 4;
1797 if (dimmInfo1.numOfModuleBanks > 0) {
1798 checkbank[0] = 1;
1799 }
1800 if (dimmInfo1.numOfModuleBanks > 1) {
1801 checkbank[1] = 1;
1802 }
1803 if (dimmInfo1.numOfModuleBanks > 2)
1804 printf ("Error, SPD claims DIMM1 has >2 banks\n");
1805
1806 printf ("-- DIMM1 has %d banks\n", dimmInfo1.numOfModuleBanks);
1807
1808 if (dimmInfo2.numOfModuleBanks > 0) {
1809 checkbank[2] = 1;
1810 }
1811 if (dimmInfo2.numOfModuleBanks > 1) {
1812 checkbank[3] = 1;
1813 }
1814 if (dimmInfo2.numOfModuleBanks > 2)
1815 printf ("Error, SPD claims DIMM2 has >2 banks\n");
1816
1817 printf ("-- DIMM2 has %d banks\n", dimmInfo2.numOfModuleBanks);
1818
1819 for (bank_no = 0; bank_no < CONFIG_SYS_DRAM_BANKS; bank_no++) {
1820
1821 if (!checkbank[bank_no])
1822 continue;
1823
1824
1825 if (bank_no == 0 || bank_no == 1) {
1826 if (checkbank[1] == 1)
1827 realsize = dimmInfo1.size / 2;
1828 else
1829 realsize = dimmInfo1.size;
1830 }
1831 if (bank_no == 2 || bank_no == 3) {
1832 if (checkbank[3] == 1)
1833 realsize = dimmInfo2.size / 2;
1834 else
1835 realsize = dimmInfo2.size;
1836 }
1837 memory_map_bank (bank_no, total, realsize);
1838
1839
1840#ifdef CONFIG_MV64460_ECC
1841 if ((dimmInfo1.errorCheckType != 0) &&
1842 ((dimmInfo2.errorCheckType != 0)
1843 || (dimmInfo2.numOfModuleBanks == 0))) {
1844 printf ("ECC Initialization of Bank %d:", bank_no);
1845 memSpaceAttr = ((~(BIT0 << bank_no)) & 0xf) << 8;
1846 mvDmaSetMemorySpace (0, 0, memSpaceAttr, total,
1847 realsize);
1848 for (dest = total; dest < total + realsize;
1849 dest += _8M) {
1850 mvDmaTransfer (0, total, dest, _8M,
1851 BIT8 |
1852 BIT3
1853 |
1854 BIT11
1855 );
1856 while (mvDmaIsChannelActive (0));
1857 }
1858 printf (" PASS\n");
1859 }
1860#endif
1861
1862 total += realsize;
1863 }
1864
1865
1866 switch ((GTREGREAD (0x141c) >> 4) & 0x7) {
1867 case 0x2:
1868 printf ("CAS Latency = 2");
1869 break;
1870 case 0x3:
1871 printf ("CAS Latency = 3");
1872 break;
1873 case 0x5:
1874 printf ("CAS Latency = 1.5");
1875 break;
1876 case 0x6:
1877 printf ("CAS Latency = 2.5");
1878 break;
1879 }
1880 printf (" tRP = %d tRAS = %d tRCD=%d\n",
1881 ((GTREGREAD (0x1408) >> 8) & 0xf) + 1,
1882 ((GTREGREAD (0x1408) >> 20) & 0xf) + 1,
1883 ((GTREGREAD (0x1408) >> 4) & 0xf) + 1);
1884
1885
1886 if (total > _256M)
1887 printf ("*** ONLY the first 256MB DRAM memory are used out of the ");
1888 else
1889 printf ("Total SDRAM memory is ");
1890
1891 return (total);
1892}
1893
1894
1895
1896
1897
1898
1899int mvDmaIsChannelActive (int engine)
1900{
1901 ulong data;
1902
1903 data = GTREGREAD (MV64460_DMA_CHANNEL0_CONTROL + 4 * engine);
1904 if (data & BIT14 ) {
1905 return 1;
1906 }
1907 return 0;
1908}
1909
1910
1911
1912
1913
1914int mvDmaSetMemorySpace (ulong memSpace,
1915 ulong memSpaceTarget,
1916 ulong memSpaceAttr, ulong baseAddress, ulong size)
1917{
1918 ulong temp;
1919
1920
1921 if (baseAddress % size != 0) {
1922 return 0;
1923 }
1924 if (size >= 0x10000 ) {
1925 size &= 0xffff0000;
1926 baseAddress = (baseAddress & 0xffff0000);
1927
1928 GT_REG_WRITE (MV64460_DMA_BASE_ADDR_REG0 + memSpace * 8,
1929 (baseAddress | memSpaceTarget | memSpaceAttr));
1930 GT_REG_WRITE ((MV64460_DMA_SIZE_REG0 + memSpace * 8),
1931 (size - 1) & 0xffff0000);
1932 temp = GTREGREAD (MV64460_DMA_BASE_ADDR_ENABLE_REG);
1933 GT_REG_WRITE (DMA_BASE_ADDR_ENABLE_REG,
1934 (temp & ~(BIT0 << memSpace)));
1935 return 1;
1936 }
1937 return 0;
1938}
1939
1940
1941
1942
1943
1944
1945int mvDmaTransfer (int engine, ulong sourceAddr,
1946 ulong destAddr, ulong numOfBytes, ulong command)
1947{
1948 ulong engOffReg = 0;
1949
1950 if (numOfBytes > 0xffff) {
1951 command = command | BIT31 ;
1952 }
1953 command = command | ((command >> 6) & 0x7);
1954 engOffReg = engine * 4;
1955 GT_REG_WRITE (MV64460_DMA_CHANNEL0_BYTE_COUNT + engOffReg,
1956 numOfBytes);
1957 GT_REG_WRITE (MV64460_DMA_CHANNEL0_SOURCE_ADDR + engOffReg,
1958 sourceAddr);
1959 GT_REG_WRITE (MV64460_DMA_CHANNEL0_DESTINATION_ADDR + engOffReg,
1960 destAddr);
1961 command =
1962 command | BIT12 | BIT9
1963 ;
1964
1965 GT_REG_WRITE (MV64460_DMA_CHANNEL0_CONTROL + engOffReg, command);
1966 return 1;
1967}
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981int set_dfcdlInit (void)
1982{
1983
1984 return (0);
1985}
1986