3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 /*************************************************************************
25 * adaption for the Marvell DB64460 Board
26 * Ingo Assmus (ingo.assmus@keymile.com)
27 ************************************************************************/
30 /* sdram_init.c - automatic memory sizing */
34 #include "../include/memory.h"
35 #include "../include/pci.h"
36 #include "../include/mv_gen_reg.h"
41 #include "../common/i2c.h"
54 int set_dfcdlInit (void); /* setup delay line of Mv64460 */
55 int mvDmaIsChannelActive (int);
56 int mvDmaSetMemorySpace (ulong, ulong, ulong, ulong, ulong);
57 int mvDmaTransfer (int, ulong, ulong, ulong, ulong);
59 /* ------------------------------------------------------------------------- */
62 memory_map_bank (unsigned int bankNo,
63 unsigned int bankBase, unsigned int bankLength)
72 printf ("mapping bank %d at %08x - %08x\n",
73 bankNo, bankBase, bankBase + bankLength - 1);
75 printf ("unmapping bank %d\n", bankNo);
79 memoryMapBank (bankNo, bankBase, bankLength);
82 for (host = PCI_HOST0; host <= PCI_HOST1; host++) {
87 READ_LINE_AGGRESSIVE_PREFETCH |
88 READ_MULTI_AGGRESSIVE_PREFETCH |
89 MAX_BURST_4 | PCI_NO_SWAP;
91 pciMapMemoryBank (host, bankNo, bankBase, bankLength);
93 pciSetRegionSnoopMode (host, bankNo, PCI_SNOOP_WB, bankBase,
96 pciSetRegionFeatures (host, bankNo, features, bankBase,
105 /* much of this code is based on (or is) the code in the pip405 port */
106 /* thanks go to the authors of said port - Josh */
108 /* structure to store the relevant information about an sdram bank */
109 typedef struct sdram_info {
111 uchar registered, ecc;
118 /* Typedefs for 'gtAuxilGetDIMMinfo' function */
120 typedef enum _memoryType { SDRAM, DDR } MEMORY_TYPE;
122 typedef enum _voltageInterface { TTL_5V_TOLERANT, LVTTL, HSTL_1_5V,
123 SSTL_3_3V, SSTL_2_5V, VOLTAGE_UNKNOWN,
126 typedef enum _max_CL_supported_DDR { DDR_CL_1 = 1, DDR_CL_1_5 = 2, DDR_CL_2 =
127 4, DDR_CL_2_5 = 8, DDR_CL_3 = 16, DDR_CL_3_5 =
128 32, DDR_CL_FAULT } MAX_CL_SUPPORTED_DDR;
129 typedef enum _max_CL_supported_SD { SD_CL_1 =
130 1, SD_CL_2, SD_CL_3, SD_CL_4, SD_CL_5, SD_CL_6, SD_CL_7,
131 SD_FAULT } MAX_CL_SUPPORTED_SD;
134 /* SDRAM/DDR information struct */
135 typedef struct _gtMemoryDimmInfo {
136 MEMORY_TYPE memoryType;
137 unsigned int numOfRowAddresses;
138 unsigned int numOfColAddresses;
139 unsigned int numOfModuleBanks;
140 unsigned int dataWidth;
141 VOLTAGE_INTERFACE voltageInterface;
142 unsigned int errorCheckType; /* ECC , PARITY.. */
143 unsigned int sdramWidth; /* 4,8,16 or 32 */ ;
144 unsigned int errorCheckDataWidth; /* 0 - no, 1 - Yes */
145 unsigned int minClkDelay;
146 unsigned int burstLengthSupported;
147 unsigned int numOfBanksOnEachDevice;
148 unsigned int suportedCasLatencies;
149 unsigned int RefreshInterval;
150 unsigned int maxCASlatencySupported_LoP; /* LoP left of point (measured in ns) */
151 unsigned int maxCASlatencySupported_RoP; /* RoP right of point (measured in ns) */
152 MAX_CL_SUPPORTED_DDR maxClSupported_DDR;
153 MAX_CL_SUPPORTED_SD maxClSupported_SD;
154 unsigned int moduleBankDensity;
155 /* module attributes (true for yes) */
156 bool bufferedAddrAndControlInputs;
157 bool registeredAddrAndControlInputs;
159 bool bufferedDQMBinputs;
160 bool registeredDQMBinputs;
161 bool differentialClockInput;
162 bool redundantRowAddressing;
164 /* module general attributes */
165 bool suportedAutoPreCharge;
166 bool suportedPreChargeAll;
167 bool suportedEarlyRasPreCharge;
168 bool suportedWrite1ReadBurst;
169 bool suported5PercentLowVCC;
170 bool suported5PercentUpperVCC;
171 /* module timing parameters */
172 unsigned int minRasToCasDelay;
173 unsigned int minRowActiveRowActiveDelay;
174 unsigned int minRasPulseWidth;
175 unsigned int minRowPrechargeTime; /* measured in ns */
177 int addrAndCommandHoldTime; /* LoP left of point (measured in ns) */
178 int addrAndCommandSetupTime; /* (measured in ns/100) */
179 int dataInputSetupTime; /* LoP left of point (measured in ns) */
180 int dataInputHoldTime; /* LoP left of point (measured in ns) */
181 /* tAC times for highest 2nd and 3rd highest CAS Latency values */
182 unsigned int clockToDataOut_LoP; /* LoP left of point (measured in ns) */
183 unsigned int clockToDataOut_RoP; /* RoP right of point (measured in ns) */
184 unsigned int clockToDataOutMinus1_LoP; /* LoP left of point (measured in ns) */
185 unsigned int clockToDataOutMinus1_RoP; /* RoP right of point (measured in ns) */
186 unsigned int clockToDataOutMinus2_LoP; /* LoP left of point (measured in ns) */
187 unsigned int clockToDataOutMinus2_RoP; /* RoP right of point (measured in ns) */
189 unsigned int minimumCycleTimeAtMaxCasLatancy_LoP; /* LoP left of point (measured in ns) */
190 unsigned int minimumCycleTimeAtMaxCasLatancy_RoP; /* RoP right of point (measured in ns) */
192 unsigned int minimumCycleTimeAtMaxCasLatancyMinus1_LoP; /* LoP left of point (measured in ns) */
193 unsigned int minimumCycleTimeAtMaxCasLatancyMinus1_RoP; /* RoP right of point (measured in ns) */
195 unsigned int minimumCycleTimeAtMaxCasLatancyMinus2_LoP; /* LoP left of point (measured in ns) */
196 unsigned int minimumCycleTimeAtMaxCasLatancyMinus2_RoP; /* RoP right of point (measured in ns) */
198 /* Parameters calculated from
199 the extracted DIMM information */
201 unsigned int deviceDensity; /* 16,64,128,256 or 512 Mbit */
202 unsigned int numberOfDevices;
203 uchar drb_size; /* DRAM size in n*64Mbit */
204 uchar slot; /* Slot Number this module is inserted in */
205 uchar spd_raw_data[128]; /* Content of SPD-EEPROM copied 1:1 */
207 uchar manufactura[8]; /* Content of SPD-EEPROM Byte 64-71 */
208 uchar modul_id[18]; /* Content of SPD-EEPROM Byte 73-90 */
209 uchar vendor_data[27]; /* Content of SPD-EEPROM Byte 99-125 */
210 unsigned long modul_serial_no; /* Content of SPD-EEPROM Byte 95-98 */
211 unsigned int manufac_date; /* Content of SPD-EEPROM Byte 93-94 */
212 unsigned int modul_revision; /* Content of SPD-EEPROM Byte 91-92 */
213 uchar manufac_place; /* Content of SPD-EEPROM Byte 72 */
220 * translate ns.ns/10 coding of SPD timing values
221 * into 10 ps unit values
223 static inline unsigned short NS10to10PS (unsigned char spd_byte)
225 unsigned short ns, ns10;
227 /* isolate upper nibble */
228 ns = (spd_byte >> 4) & 0x0F;
229 /* isolate lower nibble */
230 ns10 = (spd_byte & 0x0F);
232 return (ns * 100 + ns10 * 10);
236 * translate ns coding of SPD timing values
237 * into 10 ps unit values
239 static inline unsigned short NSto10PS (unsigned char spd_byte)
241 return (spd_byte * 100);
244 /* This code reads the SPD chip on the sdram and populates
245 * the array which is passed in with the relevant information */
246 /* static int check_dimm(uchar slot, AUX_MEM_DIMM_INFO *info) */
247 static int check_dimm (uchar slot, AUX_MEM_DIMM_INFO * dimmInfo)
249 DECLARE_GLOBAL_DATA_PTR;
251 unsigned long spd_checksum;
254 /* zero all the values */
255 memset (info, 0, sizeof (*info));
261 info->registered = 0;
262 info->drb_size = 16;*/ /* 16 - 256MBit, 32 - 512MBit */
264 info->tras_clocks = 5;
267 #ifdef CONFIG_MV64460_ECC
268 /* check for ECC/parity [0 = none, 1 = parity, 2 = ecc] */
269 dimmInfo->errorCheckType = 2;
277 uchar addr = slot == 0 ? DIMM0_I2C_ADDR : DIMM1_I2C_ADDR;
279 unsigned int i, j, density = 1, devicesForErrCheck = 0;
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;
289 uchar trp_clocks = 0, trcd_clocks, tras_clocks, trrd_clocks;
292 memclk = gd->bus_clk;
293 tmemclk = 1000000000 / (memclk / 100); /* in 10 ps units */
295 DP (puts ("before i2c read\n"));
297 ret = i2c_read (addr, 0, 1, data, 128);
299 DP (puts ("after i2c read\n"));
301 /* zero all the values */
302 memset (dimmInfo, 0, sizeof (*dimmInfo));
304 /* copy the SPD content 1:1 into the dimmInfo structure */
305 for (i = 0; i <= 127; i++) {
306 dimmInfo->spd_raw_data[i] = data[i];
310 DP (printf ("No DIMM in slot %d [err = %x]\n", slot, ret));
313 dimmInfo->slot = slot; /* start to fill up dimminfo for this "slot" */
315 #ifdef CFG_DISPLAY_DIMM_SPD_CONTENT
317 for (i = 0; i <= 127; i++) {
318 printf ("SPD-EEPROM Byte %3d = %3x (%3d)\n", i, data[i],
324 /* find Manufactura of Dimm Module */
325 for (i = 0; i < sizeof (dimmInfo->manufactura); i++) {
326 dimmInfo->manufactura[i] = data[64 + i];
328 printf ("\nThis RAM-Module is produced by: %s\n",
329 dimmInfo->manufactura);
331 /* find Manul-ID of Dimm Module */
332 for (i = 0; i < sizeof (dimmInfo->modul_id); i++) {
333 dimmInfo->modul_id[i] = data[73 + i];
335 printf ("The Module-ID of this RAM-Module is: %s\n",
338 /* find Vendor-Data of Dimm Module */
339 for (i = 0; i < sizeof (dimmInfo->vendor_data); i++) {
340 dimmInfo->vendor_data[i] = data[99 + i];
342 printf ("Vendor Data of this RAM-Module is: %s\n",
343 dimmInfo->vendor_data);
345 /* find modul_serial_no of Dimm Module */
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);
350 /* find Manufac-Data of Dimm Module */
351 dimmInfo->manufac_date = (*((unsigned int *) (&data[93])));
352 printf ("Manufactoring Date of this RAM-Module is: %d.%d\n", data[93], data[94]); /*dimmInfo->manufac_date */
354 /* find modul_revision of Dimm Module */
355 dimmInfo->modul_revision = (*((unsigned int *) (&data[91])));
356 printf ("Module Revision of this RAM-Module is: %d.%d\n", data[91], data[92]); /* dimmInfo->modul_revision */
358 /* find manufac_place of Dimm Module */
359 dimmInfo->manufac_place = (*((unsigned char *) (&data[72])));
360 printf ("manufac_place of this RAM-Module is: %d\n",
361 dimmInfo->manufac_place);
365 /*------------------------------------------------------------------------------------------------------------------------------*/
366 /* calculate SPD checksum */
367 /*------------------------------------------------------------------------------------------------------------------------------*/
370 for (i = 0; i <= 62; i++) {
371 spd_checksum += data[i];
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]);
380 printf ("SPD Checksum ok!\n");
383 /*------------------------------------------------------------------------------------------------------------------------------*/
384 for (i = 2; i <= 35; i++) {
386 case 2: /* Memory type (DDR / SDRAM) */
387 dimmInfo->memoryType = (data[i] == 0x7) ? DDR : SDRAM;
389 if (dimmInfo->memoryType == 0)
391 ("Dram_type in slot %d is: SDRAM\n",
393 if (dimmInfo->memoryType == 1)
395 ("Dram_type in slot %d is: DDRAM\n",
399 /*------------------------------------------------------------------------------------------------------------------------------*/
401 case 3: /* Number Of Row Addresses */
402 dimmInfo->numOfRowAddresses = data[i];
404 ("Module Number of row addresses: %d\n",
405 dimmInfo->numOfRowAddresses));
407 /*------------------------------------------------------------------------------------------------------------------------------*/
409 case 4: /* Number Of Column Addresses */
410 dimmInfo->numOfColAddresses = data[i];
412 ("Module Number of col addresses: %d\n",
413 dimmInfo->numOfColAddresses));
415 /*------------------------------------------------------------------------------------------------------------------------------*/
417 case 5: /* Number Of Module Banks */
418 dimmInfo->numOfModuleBanks = data[i];
420 ("Number of Banks on Mod. : %d\n",
421 dimmInfo->numOfModuleBanks));
423 /*------------------------------------------------------------------------------------------------------------------------------*/
425 case 6: /* Data Width */
426 dimmInfo->dataWidth = data[i];
428 ("Module Data Width: %d\n",
429 dimmInfo->dataWidth));
431 /*------------------------------------------------------------------------------------------------------------------------------*/
433 case 8: /* Voltage Interface */
436 dimmInfo->voltageInterface = TTL_5V_TOLERANT;
438 ("Module is TTL_5V_TOLERANT\n"));
441 dimmInfo->voltageInterface = LVTTL;
443 ("Module is LVTTL\n"));
446 dimmInfo->voltageInterface = HSTL_1_5V;
448 ("Module is TTL_5V_TOLERANT\n"));
451 dimmInfo->voltageInterface = SSTL_3_3V;
453 ("Module is HSTL_1_5V\n"));
456 dimmInfo->voltageInterface = SSTL_2_5V;
458 ("Module is SSTL_2_5V\n"));
461 dimmInfo->voltageInterface = VOLTAGE_UNKNOWN;
463 ("Module is VOLTAGE_UNKNOWN\n"));
467 /*------------------------------------------------------------------------------------------------------------------------------*/
469 case 9: /* Minimum Cycle Time At Max CasLatancy */
470 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
471 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
473 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
475 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
476 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
477 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
478 dimmInfo->minimumCycleTimeAtMaxCasLatancy_LoP =
480 dimmInfo->minimumCycleTimeAtMaxCasLatancy_RoP =
483 ("Minimum Cycle Time At Max CasLatancy: %d.%d [ns]\n",
484 leftOfPoint, rightOfPoint));
486 /*------------------------------------------------------------------------------------------------------------------------------*/
488 case 10: /* Clock To Data Out */
489 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
491 (((data[i] & 0xf0) >> 4) * 10) +
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)); /*dimmInfo->clockToDataOut */
499 /*------------------------------------------------------------------------------------------------------------------------------*/
501 /*#ifdef CONFIG_ECC */
502 case 11: /* Error Check Type */
503 dimmInfo->errorCheckType = data[i];
505 ("Error Check Type (0=NONE): %d\n",
506 dimmInfo->errorCheckType));
509 /*------------------------------------------------------------------------------------------------------------------------------*/
511 case 12: /* Refresh Interval */
512 dimmInfo->RefreshInterval = data[i];
514 ("RefreshInterval (80= Self refresh Normal, 15.625us) : %x\n",
515 dimmInfo->RefreshInterval));
517 /*------------------------------------------------------------------------------------------------------------------------------*/
519 case 13: /* Sdram Width */
520 dimmInfo->sdramWidth = data[i];
522 ("Sdram Width: %d\n",
523 dimmInfo->sdramWidth));
525 /*------------------------------------------------------------------------------------------------------------------------------*/
527 case 14: /* Error Check Data Width */
528 dimmInfo->errorCheckDataWidth = data[i];
530 ("Error Check Data Width: %d\n",
531 dimmInfo->errorCheckDataWidth));
533 /*------------------------------------------------------------------------------------------------------------------------------*/
535 case 15: /* Minimum Clock Delay */
536 dimmInfo->minClkDelay = data[i];
538 ("Minimum Clock Delay: %d\n",
539 dimmInfo->minClkDelay));
541 /*------------------------------------------------------------------------------------------------------------------------------*/
543 case 16: /* Burst Length Supported */
544 /******-******-******-*******
545 * bit3 | bit2 | bit1 | bit0 *
546 *******-******-******-*******
547 burst length = * 8 | 4 | 2 | 1 *
548 *****************************
550 If for example bit0 and bit2 are set, the burst
551 length supported are 1 and 4. */
553 dimmInfo->burstLengthSupported = data[i];
556 ("Burst Length Supported: "));
557 if (dimmInfo->burstLengthSupported & 0x01)
559 if (dimmInfo->burstLengthSupported & 0x02)
561 if (dimmInfo->burstLengthSupported & 0x04)
563 if (dimmInfo->burstLengthSupported & 0x08)
565 DP (printf (" Bit \n"));
568 /*------------------------------------------------------------------------------------------------------------------------------*/
570 case 17: /* Number Of Banks On Each Device */
571 dimmInfo->numOfBanksOnEachDevice = data[i];
573 ("Number Of Banks On Each Chip: %d\n",
574 dimmInfo->numOfBanksOnEachDevice));
576 /*------------------------------------------------------------------------------------------------------------------------------*/
578 case 18: /* Suported Cas Latencies */
581 *******-******-******-******-******-******-******-*******
582 * bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 *
583 *******-******-******-******-******-******-******-*******
584 CAS = * TBD | TBD | 3.5 | 3 | 2.5 | 2 | 1.5 | 1 *
585 *********************************************************
587 *******-******-******-******-******-******-******-*******
588 * bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 *
589 *******-******-******-******-******-******-******-*******
590 CAS = * TBD | 7 | 6 | 5 | 4 | 3 | 2 | 1 *
591 ********************************************************/
592 dimmInfo->suportedCasLatencies = data[i];
595 ("Suported Cas Latencies: (CL) "));
596 if (dimmInfo->memoryType == 0) { /* SDRAM */
597 for (k = 0; k <= 7; k++) {
599 suportedCasLatencies & (1 << k))
605 } else { /* DDR-RAM */
607 if (dimmInfo->suportedCasLatencies & 1)
609 if (dimmInfo->suportedCasLatencies & 2)
610 DP (printf ("1.5, "));
611 if (dimmInfo->suportedCasLatencies & 4)
613 if (dimmInfo->suportedCasLatencies & 8)
614 DP (printf ("2.5, "));
615 if (dimmInfo->suportedCasLatencies & 16)
617 if (dimmInfo->suportedCasLatencies & 32)
618 DP (printf ("3.5, "));
623 /* Calculating MAX CAS latency */
624 for (j = 7; j > 0; j--) {
626 suportedCasLatencies >> j) & 0x1) ==
628 switch (dimmInfo->memoryType) {
630 /* CAS latency 1, 1.5, 2, 2.5, 3, 3.5 */
634 ("Max. Cas Latencies (DDR): ERROR !!!\n"));
643 ("Max. Cas Latencies (DDR): ERROR !!!\n"));
652 ("Max. Cas Latencies (DDR): 3.5 clk's\n"));
659 ("Max. Cas Latencies (DDR): 3 clk's \n"));
666 ("Max. Cas Latencies (DDR): 2.5 clk's \n"));
673 ("Max. Cas Latencies (DDR): 2 clk's \n"));
680 ("Max. Cas Latencies (DDR): 1.5 clk's \n"));
687 /* ronen - in case we have a DIMM with minimumCycleTimeAtMaxCasLatancy
688 lower then our SDRAM cycle count, we won't be able to support this CAL
689 and we will have to use lower CAL. (minus - means from 3.0 to 2.5) */
691 minimumCycleTimeAtMaxCasLatancy_LoP
693 CFG_DDR_SDRAM_CYCLE_COUNT_LOP)
696 minimumCycleTimeAtMaxCasLatancy_LoP
698 CFG_DDR_SDRAM_CYCLE_COUNT_LOP)
700 minimumCycleTimeAtMaxCasLatancy_RoP
702 CFG_DDR_SDRAM_CYCLE_COUNT_ROP)))
711 ("*** Change actual Cas Latencies cause of minimumCycleTime n"));
713 /* ronen - checkif the Dimm frequency compared to the Sysclock. */
715 minimumCycleTimeAtMaxCasLatancy_LoP
717 CFG_DDR_SDRAM_CYCLE_COUNT_LOP)
720 minimumCycleTimeAtMaxCasLatancy_LoP
722 CFG_DDR_SDRAM_CYCLE_COUNT_LOP)
724 minimumCycleTimeAtMaxCasLatancy_RoP
726 CFG_DDR_SDRAM_CYCLE_COUNT_ROP)))
728 printf ("*********************************************************\n");
729 printf ("*** sysClock is higher than SDRAM's allowed frequency ***\n");
730 printf ("*********************************************************\n");
735 maxCASlatencySupported_LoP
739 if (((5 * j) % 10) != 0)
741 maxCASlatencySupported_RoP
745 maxCASlatencySupported_RoP
748 ("Max. Cas Latencies (DDR LoP.RoP Notation): %d.%d \n",
750 maxCASlatencySupported_LoP,
752 maxCASlatencySupported_RoP));
755 /* CAS latency 1, 2, 3, 4, 5, 6, 7 */
756 dimmInfo->maxClSupported_SD = j; /* Cas Latency DDR-RAM Coded */
758 ("Max. Cas Latencies (SD): %d\n",
762 maxCASlatencySupported_LoP
765 maxCASlatencySupported_RoP
768 ("Max. Cas Latencies (DDR LoP.RoP Notation): %d.%d \n",
770 maxCASlatencySupported_LoP,
772 maxCASlatencySupported_RoP));
779 /*------------------------------------------------------------------------------------------------------------------------------*/
781 case 21: /* Buffered Address And Control Inputs */
782 DP (printf ("\nModul Attributes (SPD Byte 21): \n"));
783 dimmInfo->bufferedAddrAndControlInputs =
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;
796 if (dimmInfo->bufferedAddrAndControlInputs == 1)
798 (" - Buffered Address/Control Input: Yes \n"));
801 (" - Buffered Address/Control Input: No \n"));
803 if (dimmInfo->registeredAddrAndControlInputs == 1)
805 (" - Registered Address/Control Input: Yes \n"));
808 (" - Registered Address/Control Input: No \n"));
810 if (dimmInfo->onCardPLL == 1)
812 (" - On-Card PLL (clock): Yes \n"));
815 (" - On-Card PLL (clock): No \n"));
817 if (dimmInfo->bufferedDQMBinputs == 1)
819 (" - Bufferd DQMB Inputs: Yes \n"));
822 (" - Bufferd DQMB Inputs: No \n"));
824 if (dimmInfo->registeredDQMBinputs == 1)
826 (" - Registered DQMB Inputs: Yes \n"));
829 (" - Registered DQMB Inputs: No \n"));
831 if (dimmInfo->differentialClockInput == 1)
833 (" - Differential Clock Input: Yes \n"));
836 (" - Differential Clock Input: No \n"));
838 if (dimmInfo->redundantRowAddressing == 1)
840 (" - redundant Row Addressing: Yes \n"));
843 (" - redundant Row Addressing: No \n"));
847 /*------------------------------------------------------------------------------------------------------------------------------*/
849 case 22: /* Suported AutoPreCharge */
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;
863 if (dimmInfo->suportedEarlyRasPreCharge == 1)
865 (" - Early Ras Precharge: Yes \n"));
868 (" - Early Ras Precharge: No \n"));
870 if (dimmInfo->suportedAutoPreCharge == 1)
872 (" - AutoPreCharge: Yes \n"));
875 (" - AutoPreCharge: No \n"));
877 if (dimmInfo->suportedPreChargeAll == 1)
879 (" - Precharge All: Yes \n"));
882 (" - Precharge All: No \n"));
884 if (dimmInfo->suportedWrite1ReadBurst == 1)
886 (" - Write 1/ReadBurst: Yes \n"));
889 (" - Write 1/ReadBurst: No \n"));
891 if (dimmInfo->suported5PercentLowVCC == 1)
893 (" - lower VCC tolerance: 5 Percent \n"));
896 (" - lower VCC tolerance: 10 Percent \n"));
898 if (dimmInfo->suported5PercentUpperVCC == 1)
900 (" - upper VCC tolerance: 5 Percent \n"));
903 (" - upper VCC tolerance: 10 Percent \n"));
907 /*------------------------------------------------------------------------------------------------------------------------------*/
909 case 23: /* Minimum Cycle Time At Maximum Cas Latancy Minus 1 (2nd highest CL) */
910 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
911 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
913 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
915 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
916 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
917 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
918 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus1_LoP =
920 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus1_RoP =
922 DP (printf ("Minimum Cycle Time At 2nd highest CasLatancy (0 = Not supported): %d.%d [ns]\n", leftOfPoint, rightOfPoint)); /*dimmInfo->minimumCycleTimeAtMaxCasLatancy */
924 /*------------------------------------------------------------------------------------------------------------------------------*/
926 case 24: /* Clock To Data Out 2nd highest Cas Latency Value */
927 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
929 (((data[i] & 0xf0) >> 4) * 10) +
931 leftOfPoint = time_tmp / div;
932 rightOfPoint = time_tmp % div;
933 dimmInfo->clockToDataOutMinus1_LoP = leftOfPoint;
934 dimmInfo->clockToDataOutMinus1_RoP = rightOfPoint;
936 ("Clock To Data Out (2nd CL value): %d.%2d [ns]\n",
937 leftOfPoint, rightOfPoint));
939 /*------------------------------------------------------------------------------------------------------------------------------*/
941 case 25: /* Minimum Cycle Time At Maximum Cas Latancy Minus 2 (3rd highest CL) */
942 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
943 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
945 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
947 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
948 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
949 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
950 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus2_LoP =
952 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus2_RoP =
954 DP (printf ("Minimum Cycle Time At 3rd highest CasLatancy (0 = Not supported): %d.%d [ns]\n", leftOfPoint, rightOfPoint)); /*dimmInfo->minimumCycleTimeAtMaxCasLatancy */
956 /*------------------------------------------------------------------------------------------------------------------------------*/
958 case 26: /* Clock To Data Out 3rd highest Cas Latency Value */
959 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
961 (((data[i] & 0xf0) >> 4) * 10) +
963 leftOfPoint = time_tmp / div;
964 rightOfPoint = time_tmp % div;
965 dimmInfo->clockToDataOutMinus2_LoP = leftOfPoint;
966 dimmInfo->clockToDataOutMinus2_RoP = rightOfPoint;
968 ("Clock To Data Out (3rd CL value): %d.%2d [ns]\n",
969 leftOfPoint, rightOfPoint));
971 /*------------------------------------------------------------------------------------------------------------------------------*/
973 case 27: /* Minimum Row Precharge Time */
974 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
976 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
978 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
979 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
980 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
982 dimmInfo->minRowPrechargeTime = ((leftOfPoint * 100) + rightOfPoint); /* measured in n times 10ps Intervals */
984 (dimmInfo->minRowPrechargeTime +
985 (tmemclk - 1)) / tmemclk;
987 ("*** 1 clock cycle = %ld 10ps intervalls = %ld.%ld ns****\n",
988 tmemclk, tmemclk / 100, tmemclk % 100));
990 ("Minimum Row Precharge Time [ns]: %d.%2d = in Clk cycles %d\n",
991 leftOfPoint, rightOfPoint, trp_clocks));
993 /*------------------------------------------------------------------------------------------------------------------------------*/
995 case 28: /* Minimum Row Active to Row Active Time */
996 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
998 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
1000 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
1001 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
1002 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
1004 dimmInfo->minRowActiveRowActiveDelay = ((leftOfPoint * 100) + rightOfPoint); /* measured in 100ns Intervals */
1006 (dimmInfo->minRowActiveRowActiveDelay +
1007 (tmemclk - 1)) / tmemclk;
1009 ("Minimum Row Active -To- Row Active Delay [ns]: %d.%2d = in Clk cycles %d\n",
1010 leftOfPoint, rightOfPoint, trp_clocks));
1012 /*------------------------------------------------------------------------------------------------------------------------------*/
1014 case 29: /* Minimum Ras-To-Cas Delay */
1015 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
1017 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
1019 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
1020 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
1021 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
1023 dimmInfo->minRowActiveRowActiveDelay = ((leftOfPoint * 100) + rightOfPoint); /* measured in 100ns Intervals */
1025 (dimmInfo->minRowActiveRowActiveDelay +
1026 (tmemclk - 1)) / tmemclk;
1028 ("Minimum Ras-To-Cas Delay [ns]: %d.%2d = in Clk cycles %d\n",
1029 leftOfPoint, rightOfPoint, trp_clocks));
1031 /*------------------------------------------------------------------------------------------------------------------------------*/
1033 case 30: /* Minimum Ras Pulse Width */
1034 dimmInfo->minRasPulseWidth = data[i];
1036 (NSto10PS (data[i]) +
1037 (tmemclk - 1)) / tmemclk;
1039 ("Minimum Ras Pulse Width [ns]: %d = in Clk cycles %d\n",
1040 dimmInfo->minRasPulseWidth, tras_clocks));
1043 /*------------------------------------------------------------------------------------------------------------------------------*/
1045 case 31: /* Module Bank Density */
1046 dimmInfo->moduleBankDensity = data[i];
1048 ("Module Bank Density: %d\n",
1049 dimmInfo->moduleBankDensity));
1052 ("*** Offered Densities (more than 1 = Multisize-Module): "));
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, "));
1075 /*------------------------------------------------------------------------------------------------------------------------------*/
1077 case 32: /* Address And Command Setup Time (measured in ns/1000) */
1079 switch (dimmInfo->memoryType) {
1082 (((data[i] & 0xf0) >> 4) * 10) +
1084 leftOfPoint = time_tmp / 100;
1085 rightOfPoint = time_tmp % 100;
1088 leftOfPoint = (data[i] & 0xf0) >> 4;
1089 if (leftOfPoint > 7) {
1090 leftOfPoint = data[i] & 0x70 >> 4;
1093 rightOfPoint = (data[i] & 0x0f);
1096 dimmInfo->addrAndCommandSetupTime =
1097 (leftOfPoint * 100 + rightOfPoint) * sign;
1099 ("Address And Command Setup Time [ns]: %d.%d\n",
1100 sign * leftOfPoint, rightOfPoint));
1102 /*------------------------------------------------------------------------------------------------------------------------------*/
1104 case 33: /* Address And Command Hold Time */
1106 switch (dimmInfo->memoryType) {
1109 (((data[i] & 0xf0) >> 4) * 10) +
1111 leftOfPoint = time_tmp / 100;
1112 rightOfPoint = time_tmp % 100;
1115 leftOfPoint = (data[i] & 0xf0) >> 4;
1116 if (leftOfPoint > 7) {
1117 leftOfPoint = data[i] & 0x70 >> 4;
1120 rightOfPoint = (data[i] & 0x0f);
1123 dimmInfo->addrAndCommandHoldTime =
1124 (leftOfPoint * 100 + rightOfPoint) * sign;
1126 ("Address And Command Hold Time [ns]: %d.%d\n",
1127 sign * leftOfPoint, rightOfPoint));
1129 /*------------------------------------------------------------------------------------------------------------------------------*/
1131 case 34: /* Data Input Setup Time */
1133 switch (dimmInfo->memoryType) {
1136 (((data[i] & 0xf0) >> 4) * 10) +
1138 leftOfPoint = time_tmp / 100;
1139 rightOfPoint = time_tmp % 100;
1142 leftOfPoint = (data[i] & 0xf0) >> 4;
1143 if (leftOfPoint > 7) {
1144 leftOfPoint = data[i] & 0x70 >> 4;
1147 rightOfPoint = (data[i] & 0x0f);
1150 dimmInfo->dataInputSetupTime =
1151 (leftOfPoint * 100 + rightOfPoint) * sign;
1153 ("Data Input Setup Time [ns]: %d.%d\n",
1154 sign * leftOfPoint, rightOfPoint));
1156 /*------------------------------------------------------------------------------------------------------------------------------*/
1158 case 35: /* Data Input Hold Time */
1160 switch (dimmInfo->memoryType) {
1163 (((data[i] & 0xf0) >> 4) * 10) +
1165 leftOfPoint = time_tmp / 100;
1166 rightOfPoint = time_tmp % 100;
1169 leftOfPoint = (data[i] & 0xf0) >> 4;
1170 if (leftOfPoint > 7) {
1171 leftOfPoint = data[i] & 0x70 >> 4;
1174 rightOfPoint = (data[i] & 0x0f);
1177 dimmInfo->dataInputHoldTime =
1178 (leftOfPoint * 100 + rightOfPoint) * sign;
1180 ("Data Input Hold Time [ns]: %d.%d\n\n",
1181 sign * leftOfPoint, rightOfPoint));
1183 /*------------------------------------------------------------------------------------------------------------------------------*/
1186 /* calculating the sdram density */
1188 i < dimmInfo->numOfRowAddresses + dimmInfo->numOfColAddresses;
1190 density = density * 2;
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)) {
1203 (dimmInfo->deviceDensity / 8) *
1204 (dimmInfo->numberOfDevices -
1205 /* ronen on the 1G dimm we get wrong value. (was devicesForErrCheck) */
1206 dimmInfo->numberOfDevices / 8);
1209 (dimmInfo->deviceDensity / 8) *
1210 dimmInfo->numberOfDevices;
1213 /* compute the module DRB size */
1215 (dimmInfo->numOfRowAddresses + dimmInfo->numOfColAddresses));
1216 tmp *= dimmInfo->numOfModuleBanks;
1217 tmp *= dimmInfo->sdramWidth;
1218 tmp = tmp >> 24; /* div by 0x4000000 (64M) */
1219 dimmInfo->drb_size = (uchar) tmp;
1220 DP (printf ("Module DRB size (n*64Mbit): %d\n", dimmInfo->drb_size));
1222 /* try a CAS latency of 3 first... */
1224 /* bit 1 is CL2, bit 2 is CL3 */
1225 supp_cal = (dimmInfo->suportedCasLatencies & 0x6) >> 1;
1229 if (NS10to10PS (data[9]) <= tmemclk)
1235 if (NS10to10PS (data[23]) <= tmemclk)
1239 DP (printf ("cal_val = %d\n", cal_val));
1241 /* bummer, did't work... */
1243 DP (printf ("Couldn't find a good CAS latency\n"));
1252 /* sets up the GT properly with information passed in */
1253 int setup_sdram (AUX_MEM_DIMM_INFO * info)
1256 ulong tmp_sdram_mode = 0; /* 0x141c */
1257 ulong tmp_dunit_control_low = 0; /* 0x1404 */
1260 /* added 8/21/2003 P. Marchese */
1261 unsigned int sdram_config_reg;
1263 /* added 10/10/2003 P. Marchese */
1264 ulong sdram_chip_size;
1266 /* sanity checking */
1267 if (!info->numOfModuleBanks) {
1268 printf ("setup_sdram called with 0 banks\n");
1273 set_dfcdlInit (); /* may be its not needed */
1274 DP (printf ("Delay line set done\n"));
1276 /* set SDRAM mode NOP */ /* To_do check it */
1277 GT_REG_WRITE (SDRAM_OPERATION, 0x5);
1278 while (GTREGREAD (SDRAM_OPERATION) != 0) {
1280 ("\n*** SDRAM_OPERATION 1418: Module still busy ... please wait... ***\n"));
1283 /* SDRAM configuration */
1284 /* added 8/21/2003 P. Marchese */
1285 /* code allows usage of registered DIMMS */
1287 /* figure out the memory refresh internal */
1288 switch (info->RefreshInterval) {
1290 case 0x80: /* refresh period is 15.625 usec */
1292 (unsigned int) (((float) 15.625 * (float) CFG_BUS_HZ)
1293 / (float) 1000000.0);
1296 case 0x81: /* refresh period is 3.9 usec */
1298 (unsigned int) (((float) 3.9 * (float) CFG_BUS_HZ) /
1302 case 0x82: /* refresh period is 7.8 usec */
1304 (unsigned int) (((float) 7.8 * (float) CFG_BUS_HZ) /
1308 case 0x83: /* refresh period is 31.3 usec */
1310 (unsigned int) (((float) 31.3 * (float) CFG_BUS_HZ) /
1314 case 0x84: /* refresh period is 62.5 usec */
1316 (unsigned int) (((float) 62.5 * (float) CFG_BUS_HZ) /
1320 case 0x85: /* refresh period is 125 usec */
1322 (unsigned int) (((float) 125 * (float) CFG_BUS_HZ) /
1325 default: /* refresh period undefined */
1326 printf ("DRAM refresh period is unknown!\n");
1327 printf ("Aborting DRAM setup with an error\n");
1331 DP (printf ("calculated refresh interval %0x\n", sdram_config_reg));
1333 /* make sure the refresh value is only 14 bits */
1334 if (sdram_config_reg > 0x1fff)
1335 sdram_config_reg = 0x1fff;
1336 DP (printf ("adjusted refresh interval %0x\n", sdram_config_reg));
1338 /* we want physical bank interleaving and */
1339 /* virtual bank interleaving enabled so do nothing */
1340 /* since these bits need to be zero to enable the interleaving */
1342 /* registered DRAM ? */
1343 if (info->registeredAddrAndControlInputs == 1) {
1344 /* it's registered DRAM, so set the reg. DRAM bit */
1345 sdram_config_reg = sdram_config_reg | BIT17;
1346 DP (printf ("Enabling registered DRAM bit\n"));
1348 /* turn on DRAM ECC? */
1349 #ifdef CONFIG_MV64460_ECC
1350 if (info->errorCheckType == 0x2) {
1351 /* DRAM has ECC, so turn it on */
1352 sdram_config_reg = sdram_config_reg | BIT18;
1353 DP (printf ("Enabling ECC\n"));
1356 /* set the data DQS pin configuration */
1357 switch (info->sdramWidth) {
1358 case 0x4: /* memory is x4 */
1359 sdram_config_reg = sdram_config_reg | BIT20 | BIT21;
1360 DP (printf ("Data DQS pins set for 16 pins\n"));
1362 case 0x8: /* memory is x8 or x16 */
1364 sdram_config_reg = sdram_config_reg | BIT21;
1365 DP (printf ("Data DQS pins set for 8 pins\n"));
1367 case 0x20: /* memory is x32 */
1368 /* both bits are cleared for x32 so nothing to do */
1369 DP (printf ("Data DQS pins set for 2 pins\n"));
1371 default: /* memory width unsupported */
1372 printf ("DRAM chip width is unknown!\n");
1373 printf ("Aborting DRAM setup with an error\n");
1379 /* perform read buffer assignments */
1380 /* we are going to use the Power-up defaults */
1381 /* bit 27 = PCI bus #0 = buffer 0 */
1382 /* bit 28 = PCI bus #1 = buffer 0 */
1383 /* bit 29 = MPSC = buffer 0 */
1384 /* bit 30 = IDMA = buffer 0 */
1385 /* bit 31 = Gigabit = buffer 0 */
1386 sdram_config_reg = sdram_config_reg | 0x58000000;
1387 sdram_config_reg = sdram_config_reg & 0xffffff00;
1388 /* bit 14 FBSplit = FCRAM controller bsplit enable. */
1389 /* bit 15 vw = FCRAM Variable write length enable. */
1390 /* bit 16 DType = Dram Type (0 = FCRAM,1 = Standard) */
1391 sdram_config_reg = sdram_config_reg | BIT14 | BIT15;
1393 /* write the value into the SDRAM configuration register */
1394 GT_REG_WRITE (SDRAM_CONFIG, sdram_config_reg);
1395 DP (printf ("sdram_conf 0x1400: %08x\n", GTREGREAD (SDRAM_CONFIG)));
1397 /* SDRAM open pages control keep open as much as I can */
1398 GT_REG_WRITE (SDRAM_OPEN_PAGES_CONTROL, 0x0);
1400 ("sdram_open_pages_controll 0x1414: %08x\n",
1401 GTREGREAD (SDRAM_OPEN_PAGES_CONTROL)));
1403 /* SDRAM D_UNIT_CONTROL_LOW 0x1404 */
1404 tmp = (GTREGREAD (D_UNIT_CONTROL_LOW) & 0x01); /* Clock Domain Sync from power on reset */
1406 DP (printf ("Core Signals are sync (by HW-Setting)!!!\n"));
1409 ("Core Signals syncs. are bypassed (by HW-Setting)!!!\n"));
1411 /* SDRAM set CAS Latency according to SPD information */
1412 switch (info->memoryType) {
1414 printf ("### SD-RAM not supported !!!\n");
1415 printf ("Aborting!!!\n");
1417 /* ToDo fill SD-RAM if needed !!!!! */
1419 /* Calculate the settings for SDRAM mode and Dunit control low registers */
1420 /* Values set according to technical bulletin TB-92 rev. c */
1422 DP (printf ("### SET-CL for DDR-RAM\n"));
1423 /* ronen db64460 - change the tmp_dunit_control_low setting!!! */
1424 switch (info->maxClSupported_DDR) {
1426 tmp_sdram_mode = 0x32; /* CL=3 Burstlength = 4 */
1427 if (tmp == 1) { /* clocks sync */
1428 if (info->registeredAddrAndControlInputs == 1) /* registerd DDR SDRAM? */
1429 tmp_dunit_control_low = 0x05110051;
1431 tmp_dunit_control_low = 0x24110051;
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 { /* clk sync. bypassed */
1438 if (info->registeredAddrAndControlInputs == 1) /* registerd DDR SDRAM? */
1439 tmp_dunit_control_low = 0xC5000540;
1441 tmp_dunit_control_low = 0xC4000540;
1443 ("Max. CL is 3 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1444 tmp_sdram_mode, tmp_dunit_control_low));
1448 tmp_sdram_mode = 0x62; /* CL=2.5 Burstlength = 4 */
1449 if (tmp == 1) { /* clocks sync */
1450 if (info->registeredAddrAndControlInputs == 1) /* registerd DDR SDRAM? */
1451 tmp_dunit_control_low = 0x25110051;
1453 tmp_dunit_control_low = 0x24110051;
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 { /* clk sync. bypassed */
1460 if (info->registeredAddrAndControlInputs == 1) { /* registerd DDR SDRAM? */
1461 tmp_dunit_control_low = 0xC5000540;
1462 /* printf("CL = 2.5, Clock Unsync'ed, Dunit Control Low register setting undefined\n");1 */
1463 /* printf("Aborting!!!\n");1 */
1466 tmp_dunit_control_low = 0xC4000540;
1468 ("Max. CL is 2.5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1469 tmp_sdram_mode, tmp_dunit_control_low));
1473 tmp_sdram_mode = 0x22; /* CL=2 Burstlength = 4 */
1474 if (tmp == 1) { /* clocks sync */
1475 if (info->registeredAddrAndControlInputs == 1) /* registerd DDR SDRAM? */
1476 tmp_dunit_control_low = 0x04110051;
1478 tmp_dunit_control_low = 0x03110051;
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 { /* clk sync. bypassed */
1485 if (info->registeredAddrAndControlInputs == 1) { /* registerd DDR SDRAM? */
1486 /*printf("CL = 2, Clock Unsync'ed, Dunit Control Low register setting undefined\n");1 */
1487 /*printf("Aborting!!!\n");1 */
1489 tmp_dunit_control_low = 0xC4000540;
1491 tmp_dunit_control_low = 0xC3000540;;
1493 ("Max. CL is 2 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1494 tmp_sdram_mode, tmp_dunit_control_low));
1498 tmp_sdram_mode = 0x52; /* CL=1.5 Burstlength = 4 */
1499 if (tmp == 1) { /* clocks sync */
1500 if (info->registeredAddrAndControlInputs == 1) /* registerd DDR SDRAM? */
1501 tmp_dunit_control_low = 0x24110051;
1503 tmp_dunit_control_low = 0x23110051;
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 { /* clk sync. bypassed */
1510 if (info->registeredAddrAndControlInputs == 1) { /* registerd DDR SDRAM? */
1511 /*printf("CL = 1.5, Clock Unsync'ed, Dunit Control Low register setting undefined\n");1 */
1512 /*printf("Aborting!!!\n");1 */
1514 tmp_dunit_control_low = 0xC4000540;
1516 tmp_dunit_control_low = 0xC3000540;
1518 ("Max. CL is 1.5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1519 tmp_sdram_mode, tmp_dunit_control_low));
1524 printf ("Max. CL is out of range %d\n",
1525 info->maxClSupported_DDR);
1528 } /* end DDR switch */
1530 } /* end CL switch */
1532 /* Write results of CL detection procedure */
1533 /* set SDRAM mode reg. 0x141c */
1534 GT_REG_WRITE (SDRAM_MODE, tmp_sdram_mode);
1536 /* set SDRAM mode SetCommand 0x1418 */
1537 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1538 while (GTREGREAD (SDRAM_OPERATION) != 0) {
1540 ("\n*** SDRAM_OPERATION 0x1418 after SDRAM_MODE: Module still busy ... please wait... ***\n"));
1543 /* SDRAM D_UNIT_CONTROL_LOW 0x1404 */
1544 GT_REG_WRITE (D_UNIT_CONTROL_LOW, tmp_dunit_control_low);
1546 /* set SDRAM mode SetCommand 0x1418 */
1547 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1548 while (GTREGREAD (SDRAM_OPERATION) != 0) {
1550 ("\n*** SDRAM_OPERATION 1418 after D_UNIT_CONTROL_LOW: Module still busy ... please wait... ***\n"));
1553 /*------------------------------------------------------------------------------ */
1555 /* bank parameters */
1556 /* SDRAM address decode register 0x1410 */
1557 /* program this with the default value */
1558 tmp = 0x02; /* power-up default address select decoding value */
1560 DP (printf ("drb_size (n*64Mbit): %d\n", info->drb_size));
1561 /* figure out the DRAM 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 /* divide sdram chip size by 64 Mbits */
1568 sdram_chip_size = sdram_chip_size / 0x4000000;
1569 switch (sdram_chip_size) {
1570 case 1: /* 64 Mbit */
1571 case 2: /* 128 Mbit */
1572 DP (printf ("RAM-Device_size 64Mbit or 128Mbit)\n"));
1575 case 4: /* 256 Mbit */
1576 case 8: /* 512 Mbit */
1577 DP (printf ("RAM-Device_size 256Mbit or 512Mbit)\n"));
1580 case 16: /* 1 Gbit */
1581 case 32: /* 2 Gbit */
1582 DP (printf ("RAM-Device_size 1Gbit or 2Gbit)\n"));
1586 printf ("Error in dram size calculation\n");
1587 printf ("RAM-Device_size is unsupported\n");
1591 /* SDRAM address control */
1592 GT_REG_WRITE (SDRAM_ADDR_CONTROL, tmp);
1594 ("setting up sdram address control (0x1410) with: %08lx \n",
1597 /* ------------------------------------------------------------------------------ */
1598 /* same settings for registerd & non-registerd DDR SDRAM */
1600 ("setting up sdram_timing_control_low (0x1408) with: %08x \n",
1603 GT_REG_WRITE (SDRAM_TIMING_CONTROL_LOW, 0x01501220);
1606 /* ------------------------------------------------------------------------------ */
1608 /* SDRAM configuration */
1609 tmp = GTREGREAD (SDRAM_CONFIG);
1611 if (info->registeredAddrAndControlInputs
1612 || info->registeredDQMBinputs) {
1615 ("SPD says: registered Addr. and Cont.: %d; registered DQMBinputs: %d\n",
1616 info->registeredAddrAndControlInputs,
1617 info->registeredDQMBinputs));
1620 /* Use buffer 1 to return read data to the CPU
1621 * Page 426 MV6indent: Standard input:1464: Warning:old style assignment ambiguity in "=*". Assuming "= *"
1623 indent: Standard input:1465: Warning:old style assignment ambiguity in "=*". Assuming "= *"
1628 ("Before Buffer assignment - sdram_conf (0x1400): %08x\n",
1629 GTREGREAD (SDRAM_CONFIG)));
1631 ("After Buffer assignment - sdram_conf (0x1400): %08x\n",
1632 GTREGREAD (SDRAM_CONFIG)));
1634 /* SDRAM timing To_do: */
1635 /* ------------------------------------------------------------------------------ */
1638 ("setting up sdram_timing_control_high (0x140c) with: %08x \n",
1640 GT_REG_WRITE (SDRAM_TIMING_CONTROL_HIGH, 0xc);
1643 ("setting up sdram address pads control (0x14c0) with: %08x \n",
1645 GT_REG_WRITE (SDRAM_ADDR_CTRL_PADS_CALIBRATION, 0x7d5014a);
1648 ("setting up sdram data pads control (0x14c4) with: %08x \n",
1650 GT_REG_WRITE (SDRAM_DATA_PADS_CALIBRATION, 0x7d5014a);
1652 /* ------------------------------------------------------------------------------ */
1654 /* set the SDRAM configuration for each bank */
1656 /* for (i = info->slot * 2; i < ((info->slot * 2) + info->banks); i++) */
1660 ("\n*** Running a MRS cycle for bank %d ***\n", i));
1663 memory_map_bank (i, 0, GB / 4);
1665 /* set SDRAM mode */ /* To_do check it */
1666 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1667 check = GTREGREAD (SDRAM_OPERATION);
1669 ("\n*** SDRAM_OPERATION 1418 (0 = Normal Operation) = %08lx ***\n",
1673 /* switch back to normal operation mode */
1674 GT_REG_WRITE (SDRAM_OPERATION, 0);
1675 check = GTREGREAD (SDRAM_OPERATION);
1677 ("\n*** SDRAM_OPERATION 1418 (0 = Normal Operation) = %08lx ***\n",
1680 /* unmap the bank */
1681 memory_map_bank (i, 0, 0);
1689 * Check memory range for valid RAM. A simple memory test determines
1690 * the actually available RAM size between addresses `base' and
1691 * `base + maxsize'. Some (not all) hardware errors are detected:
1692 * - short between address lines
1693 * - short between data lines
1695 long int dram_size (long int *base, long int maxsize)
1697 volatile long int *addr, *b = base;
1698 long int cnt, val, save1, save2;
1700 #define STARTVAL (1<<20) /* start test at 1M */
1701 for (cnt = STARTVAL / sizeof (long); cnt < maxsize / sizeof (long);
1703 addr = base + cnt; /* pointer arith! */
1705 save1 = *addr; /* save contents of addr */
1706 save2 = *b; /* save contents of base */
1708 *addr = cnt; /* write cnt to addr */
1709 *b = 0; /* put null at base */
1711 /* check at base address */
1713 *addr = save1; /* restore *addr */
1714 *b = save2; /* restore *b */
1717 val = *addr; /* read *addr */
1718 val = *addr; /* read *addr */
1725 ("Found %08x at Address %08x (failure)\n",
1726 (unsigned int) val, (unsigned int) addr));
1727 /* fix boundary condition.. STARTVAL means zero */
1728 if (cnt == STARTVAL / sizeof (long))
1730 return (cnt * sizeof (long));
1736 /* ------------------------------------------------------------------------- */
1738 /* ppcboot interface function to SDRAM init - this is where all the
1739 * controlling logic happens */
1740 long int initdram (int board_type)
1743 int checkbank[4] = {[0 ... 3] = 0 };
1744 ulong realsize, total, check;
1745 AUX_MEM_DIMM_INFO dimmInfo1;
1746 AUX_MEM_DIMM_INFO dimmInfo2;
1748 ulong dest, memSpaceAttr;
1750 /* first, use the SPD to get info about the SDRAM/ DDRRAM */
1752 /* check the NHR bit and skip mem init if it's already done */
1753 nhr = get_hid0 () & (1 << 16);
1756 printf ("Skipping SD- DDRRAM setup due to NHR bit being set\n");
1759 s0 = check_dimm (0, &dimmInfo1);
1762 s1 = check_dimm (1, &dimmInfo2);
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);
1769 /* ronen check correct set of DIMMS */
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");
1782 if (dimmInfo1.numOfModuleBanks && setup_sdram (&dimmInfo1)) {
1783 printf ("Setup for DIMM1 failed.\n");
1786 if (dimmInfo2.numOfModuleBanks && setup_sdram (&dimmInfo2)) {
1787 printf ("Setup for DIMM2 failed.\n");
1790 /* set the NHR bit */
1791 set_hid0 (get_hid0 () | (1 << 16));
1793 /* next, size the SDRAM banks */
1795 realsize = total = 0;
1797 if (dimmInfo1.numOfModuleBanks > 0) {
1800 if (dimmInfo1.numOfModuleBanks > 1) {
1803 if (dimmInfo1.numOfModuleBanks > 2)
1804 printf ("Error, SPD claims DIMM1 has >2 banks\n");
1806 printf ("-- DIMM1 has %d banks\n", dimmInfo1.numOfModuleBanks);
1808 if (dimmInfo2.numOfModuleBanks > 0) {
1811 if (dimmInfo2.numOfModuleBanks > 1) {
1814 if (dimmInfo2.numOfModuleBanks > 2)
1815 printf ("Error, SPD claims DIMM2 has >2 banks\n");
1817 printf ("-- DIMM2 has %d banks\n", dimmInfo2.numOfModuleBanks);
1819 for (bank_no = 0; bank_no < CFG_DRAM_BANKS; bank_no++) {
1820 /* skip over banks that are not populated */
1821 if (!checkbank[bank_no])
1824 /* ronen - realsize = dram_size((long int *)total, check); */
1825 if (bank_no == 0 || bank_no == 1) {
1826 if (checkbank[1] == 1)
1827 realsize = dimmInfo1.size / 2;
1829 realsize = dimmInfo1.size;
1831 if (bank_no == 2 || bank_no == 3) {
1832 if (checkbank[3] == 1)
1833 realsize = dimmInfo2.size / 2;
1835 realsize = dimmInfo2.size;
1837 memory_map_bank (bank_no, total, realsize);
1839 /* ronen - initialize the DRAM for ECC */
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,
1848 for (dest = total; dest < total + realsize;
1850 mvDmaTransfer (0, total, dest, _8M,
1851 BIT8 /*DMA_DTL_128BYTES */ |
1852 BIT3 /*DMA_HOLD_SOURCE_ADDR */
1855 /*DMA_BLOCK_TRANSFER_MODE */ );
1856 while (mvDmaIsChannelActive (0));
1866 switch ((GTREGREAD (0x141c) >> 4) & 0x7) {
1868 printf ("CAS Latency = 2");
1871 printf ("CAS Latency = 3");
1874 printf ("CAS Latency = 1.5");
1877 printf ("CAS Latency = 2.5");
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);
1885 /* Setup Ethernet DMA Adress window to DRAM Area */
1887 printf ("*** ONLY the first 256MB DRAM memory are used out of the ");
1889 printf ("Total SDRAM memory is ");
1890 /* (cause all the 4 BATS are taken) */
1895 /* ronen- add Idma functions for usage of the ecc dram init. */
1896 /*******************************************************************************
1897 * mvDmaIsChannelActive - Checks if a engine is busy.
1898 ********************************************************************************/
1899 int mvDmaIsChannelActive (int engine)
1903 data = GTREGREAD (MV64460_DMA_CHANNEL0_CONTROL + 4 * engine);
1904 if (data & BIT14 /*activity status */ ) {
1910 /*******************************************************************************
1911 * mvDmaSetMemorySpace - Set a DMA memory window for the DMA's address decoding
1913 *******************************************************************************/
1914 int mvDmaSetMemorySpace (ulong memSpace,
1915 ulong memSpaceTarget,
1916 ulong memSpaceAttr, ulong baseAddress, ulong size)
1920 /* The base address must be aligned to the size. */
1921 if (baseAddress % size != 0) {
1924 if (size >= 0x10000 /*64K */ ) {
1926 baseAddress = (baseAddress & 0xffff0000);
1927 /* Set the new attributes */
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)));
1941 /*******************************************************************************
1942 * mvDmaTransfer - Transfer data from sourceAddr to destAddr on one of the 4
1944 ********************************************************************************/
1945 int mvDmaTransfer (int engine, ulong sourceAddr,
1946 ulong destAddr, ulong numOfBytes, ulong command)
1948 ulong engOffReg = 0; /* Engine Offset Register */
1950 if (numOfBytes > 0xffff) {
1951 command = command | BIT31 /*DMA_16M_DESCRIPTOR_MODE */ ;
1953 command = command | ((command >> 6) & 0x7);
1954 engOffReg = engine * 4;
1955 GT_REG_WRITE (MV64460_DMA_CHANNEL0_BYTE_COUNT + engOffReg,
1957 GT_REG_WRITE (MV64460_DMA_CHANNEL0_SOURCE_ADDR + engOffReg,
1959 GT_REG_WRITE (MV64460_DMA_CHANNEL0_DESTINATION_ADDR + engOffReg,
1962 command | BIT12 /*DMA_CHANNEL_ENABLE */ | BIT9
1963 /*DMA_NON_CHAIN_MODE */ ;
1964 /* Activate DMA engine By writting to mvDmaControlRegister */
1965 GT_REG_WRITE (MV64460_DMA_CHANNEL0_CONTROL + engOffReg, command);
1969 /****************************************************************************************
1971 * This procedure detect all Sdram types: 64, 128, 256, 512 Mbit, 1Gbit and 2Gb *
1972 * This procedure fits only the Atlantis *
1974 ***************************************************************************************/
1977 /****************************************************************************************
1978 * DFCDL initialize MV643xx Design Considerations *
1980 ***************************************************************************************/
1981 int set_dfcdlInit (void)
1983 /*ronen the dfcdl init are done by the I2C */