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