2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 One Laptop per Child, Association, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 void DRAMSetVRNum(DRAM_SYS_ATTR *DramAttr, u8 PhyRank /* physical rank */,
21 u8 VirRank /* virtual rank */, BOOLEAN Enable);
22 void SetEndingAddr(DRAM_SYS_ATTR *DramAttr, u8 VirRank /* Ending address
23 register number indicator (INDEX */, INT8 Value /* (value)
24 add or subtract value to this and after banks. */);
25 void InitDDR2CHA(DRAM_SYS_ATTR *DramAttr);
26 void InitDDR2CHB(DRAM_SYS_ATTR *DramAttr);
27 void InitDDR2CHC(DRAM_SYS_ATTR *DramAttr);
29 CB_STATUS VerifyChc(void);
31 /*===================================================================
32 Function : DRAMRegInitValue()
35 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
38 Purpose : Set necessary register before DRAM initialize
39 ===================================================================*/
41 static const u8 DramRegTbl[][3] = {
43 {0x50, 0x11, 0xEE}, // DDR default MA7 for DRAM init
44 {0x51, 0x11, 0x60}, // DDR default MA3 for CHB init
45 {0x52, 0x00, 0x33}, // DDR use BA0=M17, BA1=M18,
46 {0x53, 0x00, 0x3F}, // DDR BA2=M19
48 {0x54, 0x00, 0x00}, // default PR0=VR0; PR1=VR1
49 {0x55, 0x00, 0x00}, // default PR2=VR2; PR3=VR3
50 {0x56, 0x00, 0x00}, // default PR4=VR4; PR5=VR5
51 {0x57, 0x00, 0x00}, // default PR4=VR4; PR5=VR5
53 {0x60, 0x00, 0x00}, // disable fast turn-around
54 {0x65, 0x00, 0xD9}, // AGP timer = 0XD; Host timer = 8;
55 {0x66, 0x00, 0x88}, // DRAMC Queue Size = 4; park at the last bus
56 // owner,Priority promotion timer = 8
58 {0x69, 0xF0, 0x04}, // set RX69[3:0]=0000b
59 {0x6A, 0x00, 0x00}, // refresh counter
60 {0x6E, 0xF8, 0x80}, // must set 6E[7], or else DDR2 probe test
63 * In here, we not set RX70~RX74, because we just init DRAM but no
64 * need R/W DRAM, when we check DQS input/output delay, then we need
68 // {0x79, 0x00, 0x8F },
70 // {0x90, 0x87, 0x78 },
71 // {0x91, 0x00, 0x46 },
77 void DRAMRegInitValue(DRAM_SYS_ATTR *DramAttr)
81 for (Idx = 0; DramRegTbl[Idx][0] != 0; Idx++) {
82 Data = pci_read_config8(MEMCTRL, DramRegTbl[Idx][0]);
83 Data &= DramRegTbl[Idx][1];
84 Data |= DramRegTbl[Idx][2];
85 pci_write_config8(MEMCTRL, DramRegTbl[Idx][0], Data);
89 pci_write_config8(PCI_DEV(0, 0, 4), 0xa3, Data);
91 // Set DRAM controller mode. */
92 Data = pci_read_config8(MEMCTRL, 0x6c);
94 if (ENABLE_CHC == 0) {
95 Data |= 0x4; /* Only CHA 64 bit mode */
96 pci_write_config8(MEMCTRL, 0x6c, Data);
98 Data |= 0x0; /* CHA + CHC */
99 pci_write_config8(MEMCTRL, 0x6c, Data);
102 // pci_write_config8(MEMCTRL, 0xb1, Data);
104 // set CHB DQSB input delay, or else will meet error which
105 // is some byte is right but another bit is error.
106 Data = pci_read_config8(MEMCTRL, 0xff);
107 Data = (Data & 0x03) | 0x3D;
108 pci_write_config8(MEMCTRL, 0xff, Data);
110 // enable CHC RXDB[7]
111 // Data = pci_read_config8(MEMCTRL, 0xdb);
112 // Data = (Data & 0x7F) | 0x80;
113 // pci_write_config8(MEMCTRL, 0xdb, Data);
115 // rx62[2:0], CHA and CHB CL
116 Data = pci_read_config8(MEMCTRL, 0x62);
119 // If CL = 6, so I set CHB CL = 5 default.
123 /* Set CHC Read CL rxDC[6:7]. */
124 Data = pci_read_config8(MEMCTRL, 0xdc);
125 Data = (Data & 0x3F) | (CL << 6);
126 pci_write_config8(MEMCTRL, 0xdc, Data);
128 /* Set CHC write CL rxDF[6:7]. */
129 Data = pci_read_config8(MEMCTRL, 0xdf);
130 Data = (Data & 0x3F) | (CL << 6);
131 pci_write_config8(MEMCTRL, 0xdf, Data);
133 /* Set CHC ODT RxDC[5:0] */
134 Data = pci_read_config8(MEMCTRL, 0xdc);
135 Data = (Data & 0xC0) | 0x03;
136 pci_write_config8(MEMCTRL, 0xdc, Data);
138 /* Set column type RXDD[6] and enable ODT PAD RXDD[7]. */
139 Data = pci_read_config8(MEMCTRL, 0xdd);
141 Idx = DramAttr->DimmInfo[2].SPDDataBuf[SPD_SDRAM_COL_ADDR];
142 if ((Idx & 0x0F) == 10)
143 Data |= 0x40; /* MA9~MA0 */
145 Data &= 0xBF; /* MA8~MA0 */
146 pci_write_config8(MEMCTRL, 0xdd, Data);
149 // Disable Read DRAM fast ready ;Rx51[7]
150 // Disable Read Around Write ;Rx51[6]
152 // Disable Consecutive Read ;RX52[1:0]
153 // Disable Speculative Read
156 /*===================================================================
157 Function : DRAMInitializeProc()
160 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
163 Purpose : DRAM initialize according to the bios porting guid
164 ===================================================================*/
166 #define EXIST_TEST_PATTERN 0x55555555
167 #define NOT_EXIST_TEST_PATTERN 0xAAAAAAAA
169 BOOLEAN ChkForExistLowBank(void)
171 u32 *Address, data32;
175 *Address = EXIST_TEST_PATTERN;
177 *Address = EXIST_TEST_PATTERN;
183 if (data32 != EXIST_TEST_PATTERN)
187 if (data32 != EXIST_TEST_PATTERN)
190 /* Check not Pattern */
192 *Address = NOT_EXIST_TEST_PATTERN;
194 *Address = NOT_EXIST_TEST_PATTERN;
200 if (data32 != (u32) (NOT_EXIST_TEST_PATTERN))
204 if (data32 != (u32) (NOT_EXIST_TEST_PATTERN))
210 void InitDDR2CHC(DRAM_SYS_ATTR *DramAttr);
211 void InitDDR2CHB(DRAM_SYS_ATTR *DramAttr);
213 void DRAMInitializeProc(DRAM_SYS_ATTR *DramAttr)
219 for (idx = 0; idx < MAX_RANKS; idx++) {
220 if ((DramAttr->RankPresentMap & shift) != 0) {
222 * Set VR# to physical rank indicated = PR + physical
225 DRAMSetVRNum(DramAttr, idx, idx, TRUE);
226 SetEndingAddr(DramAttr, idx, 0x10); /* Assume 1G size */
227 if (idx < 4) /* CHA init */
228 InitDDR2CHA(DramAttr); // temp wjb 2007/1 only for compiling
229 // in the function InitDDR2,the parameter is no need
230 Status = ChkForExistLowBank();
231 if (Status == TRUE) {
232 PRINT_DEBUG_MEM(" S\r");
234 PRINT_DEBUG_MEM(" F\r");
238 * Set VR# to physical rank indicated = 00h + physical
241 DRAMSetVRNum(DramAttr, idx, 0, FALSE);
242 SetEndingAddr(DramAttr, idx, -16);
247 InitDDR2CHC(DramAttr);
251 /*===================================================================
252 Function : DRAMSetVRNUM()
255 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
257 PhyRank: Physical Rank number
258 VirRank: Virtual Rank number
259 Enable: Enable/Disable Physical Rank
261 Purpose : Set virtual rank number for physical rank
262 Program the specific physical rank with specific virtual rank number
263 Program when necessary, otherwise don't touch the pr-vr-mapping registers
264 ===================================================================*/
266 void DRAMSetVRNum(DRAM_SYS_ATTR *DramAttr, u8 PhyRank /* physical rank */,
267 u8 VirRank /* virtual rank */, BOOLEAN Enable)
269 u8 Data, AndData, OrData;
271 Data = pci_read_config8(MEMCTRL, (0x54 + (PhyRank >> 1)));
277 if ((PhyRank & 0x01) == 0x00) {
278 AndData = 0x0F; // keep the value of odd rank on PR # is even(keep 1,3,5,7)
279 OrData <<= 4; // VR #, value to be set
281 AndData = 0xF0; // keep the value of even rank on PR # is odd(keep 0,2,4,6)
286 pci_write_config8(MEMCTRL, (0x54 + (PhyRank >> 1)), Data);
289 /*===================================================================
290 Function : SetEndingAddr()
293 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
295 VirRank: Virtual Rank number
296 Value: (value) add or subtract value to this and after banks
298 Purpose : Set ending address of virtual rank specified by VirRank
299 ===================================================================*/
301 void SetEndingAddr(DRAM_SYS_ATTR *DramAttr, u8 VirRank /* ending address
302 register number indicator (INDEX */, INT8 Value /* (value)
303 add or subtract value to this and after banks */) {
306 /* Read register,Rx40-Rx47(0,1,2,3,4,5,6,7) and set ending address. */
307 Data = pci_read_config8(MEMCTRL, 0x40 + VirRank);
308 Data = (u8) (Data + Value);
309 pci_write_config8(MEMCTRL, 0x40 + VirRank, Data);
311 /* Program the virank's begining address to zero. */
313 pci_write_config8(MEMCTRL, 0x48 + VirRank, Data);
316 /*===================================================================
317 Function : InitDDR2()
320 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
323 Purpose : Initialize DDR2 by standard sequence
324 ===================================================================*/
327 static const u32 CHA_MRS_DLL_150[2] = { 0x00020200, 0x00000800 }; // with 150 ohm (A17=1, A9=1), (A11=1)(cpu address)
328 static const u32 CHA_MRS_DLL_75[2] = { 0x00020020, 0x00000800 }; // with 75 ohm (A17=1, A5=1), (A11=1)(cpu address)
331 // { DLL: Enable. A17(BA0)=1 and A3(MA0)=0 }
332 // { DLL: reset. A11(MA8)=1 }
334 // DDR2 CL=2 CL=3 CL=4 CL=5 CL=6(Burst type=interleave)(WR fine tune in code)
335 static const u16 CHA_DDR2_MRS_table[5] = { 0x0150, 0x01D0, 0x0250, 0x02D0, 0x350 }; // BL=4 ;Use 1X-bandwidth MA table to init DRAM
338 #define CHA_MRS_DDR2_TWR2 (0 << 13) + (0 << 20) + (1 << 12) // Value = 001000h
339 #define CHA_MRS_DDR2_TWR3 (0 << 13) + (1 << 20) + (0 << 12) // Value = 100000h
340 #define CHA_MRS_DDR2_TWR4 (0 << 13) + (1 << 20) + (1 << 12) // Value = 101000h
341 #define CHA_MRS_DDR2_TWR5 (1 << 13) + (0 << 20) + (0 << 12) // Value = 002000h
342 #define CHA_MRS_DDR2_TWR6 (1 << 13) + (0 << 20) + (1 << 12) // Value = 003000h
344 // DDR2 Twr=2 Twr=3 Twr=4 Twr=5
345 static const u32 CHA_DDR2_Twr_table[5] = {
346 CHA_MRS_DDR2_TWR2, CHA_MRS_DDR2_TWR3, CHA_MRS_DDR2_TWR4,
347 CHA_MRS_DDR2_TWR5, CHA_MRS_DDR2_TWR6
350 #define CHA_OCD_Exit_150ohm 0x20200 // EMRS(1), BA0=1, MA9=MA8=MA7=0,MA6=1,MA2=0 (DRAM bus address)
351 // A17=1, A12=A11=A10=0,A9=1 ,A5=0 (CPU address)
352 #define CHA_OCD_Default_150ohm 0x21E00 // EMRS(1), BA0=1, MA9=MA8=MA7=1,MA6=1,MA2=0 (DRAM bus address)
353 // A17=1, A12=A11=A10=1,A9=1 ,A5=0 (CPU address)
354 #define CHA_OCD_Exit_75ohm 0x20020 // EMRS(1), BA0=1, MA9=MA8=MA7=0,MA6=0,MA2=1 (DRAM bus address)
355 // A17=1, A12=A11=A10=0,A9=0 ,A5=1 (CPU address)
356 #define CHA_OCD_Default_75ohm 0x21C20 // EMRS(1), BA0=1, MA9=MA8=MA7=1,MA6=0,MA2=1 (DRAM bus address)
357 // A17=1, A12=A11=A10=1,A9=0 ,A5=1 (CPU address)
359 void InitDDR2CHA(DRAM_SYS_ATTR *DramAttr)
361 u8 Data, Reg6BVal, Idx, CL, BL, Twr, DimmNum;
365 /* Disable bank paging and multi page. */
366 Data = pci_read_config8(MEMCTRL, 0x69);
368 pci_write_config8(MEMCTRL, 0x69, Data);
370 Reg6BVal = pci_read_config8(MEMCTRL, 0x6b);
374 /* At least one NOP cycle will be issued after the 1m sec device
377 Data = Reg6BVal | 0x01;
378 pci_write_config8(MEMCTRL, 0x6b, Data);
381 /* Read a double word from any address of the DIMM. */
386 * A minimum pause of 200u sec will be provided after the NOP.
387 * - <<< reduce BOOT UP time >>> -
390 for (Idx = 0; Idx < 0x10; Idx++)
394 // Precharge all (PALL) will be issued to the DDR.
395 Data = Reg6BVal | 0x02;
396 pci_write_config8(MEMCTRL, 0x6b, Data);
399 // Read a double word from any address of the DIMM
403 // MSR Eable will be issued to the DDR
404 Data = Reg6BVal | 0x03;
405 pci_write_config8(MEMCTRL, 0x6b, Data);
409 * Check ODT value for EMRS(1) command according to ODTLookUp_TBL
410 * in driving_setting.c if there is one DIMM in MB's one channel,
411 * the DDR2's ODT is 150ohm if there is two DIMM in MB's one channel,
412 * the DDR2's ODT is 75 ohm.
414 DimmNum = DramAttr->DimmNumChA;
416 if (DimmNum == 1) { /* DDR's ODT is 150ohm */
417 AccessAddr = (u32) CHA_MRS_DLL_150[0];
418 DimmRead(AccessAddr); /* Issue EMRS DLL Enable. */
419 PRINT_DEBUG_MEM("Step 9 Address ");
420 PRINT_DEBUG_MEM_HEX32(AccessAddr);
421 PRINT_DEBUG_MEM("\r");
423 AccessAddr = (u32) CHA_MRS_DLL_150[1];
424 DimmRead(AccessAddr); /* Issue MRS DLL Reset. */
425 PRINT_DEBUG_MEM("Step 10 Address ");
426 PRINT_DEBUG_MEM_HEX32(AccessAddr);
427 PRINT_DEBUG_MEM("\r");
428 } else if (DimmNum == 2) { /* DDR's ODT is 75ohm */
429 AccessAddr = (u32) CHA_MRS_DLL_75[0];
430 DimmRead(AccessAddr); /* Issue EMRS DLL Enable. */
431 AccessAddr = (u32) CHA_MRS_DLL_75[1];
432 DimmRead(AccessAddr); /* Issue MRS DLL Reset. */
434 PRINT_DEBUG_MEM("Dimm NUM ERROR:");
435 PRINT_DEBUG_MEM_HEX8(DimmNum);
436 PRINT_DEBUG_MEM("\r");
439 /* Step 11. Precharge all (PALL) will be issued to the DDR. */
440 Data = Reg6BVal | 0x02;
441 pci_write_config8(MEMCTRL, 0x6b, Data);
443 /* Step 12. Read a double word from any address of the DIMM. */
446 /* Step 13. Execute 8 CBR refresh. */
447 Data = Reg6BVal | 0x04;
448 pci_write_config8(MEMCTRL, 0x6b, Data);
451 //reads and wait 100us between each read
452 for (Idx = 0; Idx < 8; Idx++) {
457 /* Step 17. Enable MRS for MAA. */
458 Data = Reg6BVal | 0x03;
459 pci_write_config8(MEMCTRL, 0x6b, Data);
462 * Step 18. The SDRAM parameters (Burst Length, CAS# Latency,
463 * Write recovery etc.)
466 /* Burst Length: really offset Rx6c[3] */
467 Data = pci_read_config8(MEMCTRL, 0x6c);
468 BL = (Data & 0x08) >> 3;
470 /* CL: really offset RX62[2:0] */
471 Data = pci_read_config8(MEMCTRL, 0x62);
474 AccessAddr = (u32) (CHA_DDR2_MRS_table[CL]);
478 /* Write recovery: really offset Rx63[7-5] */
479 Data = pci_read_config8(MEMCTRL, 0x63);
480 Twr = (Data & 0xE0) >> 5;
482 AccessAddr += CHA_DDR2_Twr_table[Twr];
483 // AccessAddr = 0x1012D8;
484 DimmRead(AccessAddr); /* Set MRS command. */
485 PRINT_DEBUG_MEM("Step 18 Address");
486 PRINT_DEBUG_MEM_HEX32(AccessAddr);
487 PRINT_DEBUG_MEM("\r");
490 if (DimmNum == 1) { /* DDR's ODT is 150ohm */
491 AccessAddr = (u32) CHA_OCD_Default_150ohm;
492 DimmRead(AccessAddr); /* Issue EMRS OCD Default. */
493 PRINT_DEBUG_MEM("Step 19 Address ");
494 PRINT_DEBUG_MEM_HEX32(AccessAddr);
495 PRINT_DEBUG_MEM("\r");
497 AccessAddr = (u32) CHA_OCD_Exit_150ohm;
498 DimmRead(AccessAddr); /* Issue EMRS OCD Calibration Mode Exit. */
499 PRINT_DEBUG_MEM("Step 20 Address ");
500 PRINT_DEBUG_MEM_HEX32(AccessAddr);
501 PRINT_DEBUG_MEM("\r");
502 } else if (DimmNum == 2) { /* DDR's ODT is 75ohm */
503 AccessAddr = (u32) CHA_OCD_Default_75ohm;
504 DimmRead(AccessAddr); /* Issue EMRS OCD Default. */
505 AccessAddr = (u32) CHA_OCD_Exit_75ohm;
506 DimmRead(AccessAddr); /* Issue EMRS OCD Calibration Mode Exit. */
508 PRINT_DEBUG_MEM("Dimm NUM ERROR: ");
509 PRINT_DEBUG_MEM_HEX8(DimmNum);
510 PRINT_DEBUG_MEM("\r");
514 * Step 21. After MRS the device should be ready for full
515 * functionality within 3 clocks after Tmrd is met.
518 pci_write_config8(MEMCTRL, 0x6b, Data);
520 /* Enable bank paging and multi page. */
521 Data = pci_read_config8(MEMCTRL, 0x69);
523 pci_write_config8(MEMCTRL, 0x69, Data);
526 /*===================================================================
527 Function : InitDDR2_CHB()
530 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
533 Purpose : Initialize DDR2 of CHB by standard sequence
535 ===================================================================*/
536 /*// DLL: Enable Reset
537 static const u32 CHB_MRS_DLL_150[2] = { 0x00020200 | (1 << 20), 0x00000800 }; // with 150 ohm (A17=1, A9=1), (A11=1)(cpu address)
538 //u32 CHB_MRS_DLL_75[2] = { 0x00020020 | (1 << 20), 0x00000800 }; // with 75 ohm (A17=1, A5=1), (A11=1)(cpu address)
540 // { DLL: Enable. A17(BA0)=1 and A3(MA0)=0 }
541 // { DLL: reset. A11(MA8)=1 }
543 // DDR2 CL=2 CL=3 CL=4 CL=5 (Burst type=interleave)(WR fine tune in code)
544 static const u16 CHB_DDR2_MRS_table[4] ={ 0x0150, 0x01D0, 0x0250, 0x02D0 }; // BL=4 ;Use 1X-bandwidth MA table to init DRAM
547 #define CHB_MRS_DDR2_TWR2 (0 << 13) + (0 << 20) + (1 << 12) // Value = 001000h
548 #define CHB_MRS_DDR2_TWR3 (0 << 13) + (1 << 20) + (0 << 12) // Value = 100000h
549 #define CHB_MRS_DDR2_TWR4 (0 << 13) + (1 << 20) + (1 << 12) // Value = 101000h
550 #define CHB_MRS_DDR2_TWR5 (1 << 13) + (0 << 20) + (0 << 12) // Value = 002000h
551 #define CHB_MRS_DDR2_TWR6 (1 << 13) + (0 << 20) + (1 << 12) // Value = 003000h
553 // DDR2 Twr=2 Twr=3 Twr=4 Twr=5
554 static const u32 CHB_DDR2_Twr_table[5] = { CHB_MRS_DDR2_TWR2, CHB_MRS_DDR2_TWR3, CHB_MRS_DDR2_TWR4, CHB_MRS_DDR2_TWR5, CHB_MRS_DDR2_TWR6 };
556 #define CHB_OCD_Exit_150ohm 0x20200 | (1 << 20) // EMRS(1), BA0=1, MA9=MA8=MA7=0,MA6=1,MA2=0 (DRAM bus address)
557 // A17=1, A12=A11=A10=0,A9=1 ,A5=0 (CPU address)
558 #define CHB_OCD_Default_150ohm 0x21E00 | (1 << 20) // EMRS(1), BA0=1, MA9=MA8=MA7=1,MA6=1,MA2=0 (DRAM bus address)
559 // A17=1, A12=A11=A10=1,A9=1 ,A5=0 (CPU address)
560 //#define CHB_OCD_Exit_75ohm 0x20020 | (1 << 20) // EMRS(1), BA0=1, MA9=MA8=MA7=0,MA6=0,MA2=1 (DRAM bus address)
561 // A17=1, A12=A11=A10=0,A9=0 ,A5=1 (CPU address)
562 //#define CHB_OCD_Default_75ohm 0x21C20 | (1 << 20) // EMRS(1), BA0=1, MA9=MA8=MA7=1,MA6=0,MA2=1 (DRAM bus address)
563 // A17=1, A12=A11=A10=1,A9=0 ,A5=1 (CPU address)
565 DRAM_SYS_ATTR *DramAttr
574 pci_write_config8(MEMCTRL, 0x54, Data);
577 //disable bank paging and multi page
578 Data=pci_read_config8(MEMCTRL, 0x69);
580 pci_write_config8(MEMCTRL, 0x69, Data);
582 Data=pci_read_config8(MEMCTRL, 0xd3);
584 pci_write_config8(MEMCTRL, 0xd3, Data);
586 //step 4. Initialize CHB begin
587 Data=pci_read_config8(MEMCTRL, 0xd3);
589 pci_write_config8(MEMCTRL, 0xd3, Data);
591 //Step 5. NOP command enable
592 Data=pci_read_config8(MEMCTRL, 0xd7);
595 pci_write_config8(MEMCTRL, 0xd7, Data);
597 //Step 6. issue a nop cycle,RegD3[7] 0 -> 1
598 Data=pci_read_config8(MEMCTRL, 0xd3);
600 pci_write_config8(MEMCTRL, 0xd3, Data);
602 pci_write_config8(MEMCTRL, 0xd3, Data);
605 // A minimum pause of 200u sec will be provided after the NOP.
606 // - <<< reduce BOOT UP time >>> -
608 for (Idx = 0; Idx < 0x10; Idx++)
612 // all banks precharge command enable
613 Data=pci_read_config8(MEMCTRL, 0xd7);
616 pci_write_config8(MEMCTRL, 0xd7, Data);
618 //step 9. issue a precharge all cycle,RegD3[7] 0 -> 1
619 Data=pci_read_config8(MEMCTRL, 0xd3);
621 pci_write_config8(MEMCTRL, 0xd3, Data);
623 pci_write_config8(MEMCTRL, 0xd3, Data);
625 //step10. EMRS enable
626 Data=pci_read_config8(MEMCTRL, 0xd7);
629 pci_write_config8(MEMCTRL, 0xd7, Data);
631 Data=pci_read_config8(MEMCTRL, 0xd3);
634 pci_write_config8(MEMCTRL, 0xd3, Data);
636 //step11. EMRS DLL Enable and Disable DQS
637 AccessAddr = CHB_MRS_DLL_150[0] >> 3;
638 Data =(u8) (AccessAddr & 0xff);
639 pci_write_config8(MEMCTRL, 0xd9, Data);
641 Data = (u8)((AccessAddr & 0xff00) >> 8);
642 pci_write_config8(MEMCTRL, 0xda, Data);
644 Data=pci_read_config8(MEMCTRL, 0xd7);
646 Data |= (u8)((AccessAddr & 0x30000) >> 15);
647 pci_write_config8(MEMCTRL, 0xd7, Data);
649 //step12. issue EMRS cycle
650 Data=pci_read_config8(MEMCTRL, 0xd3);
652 pci_write_config8(MEMCTRL, 0xd3, Data);
654 pci_write_config8(MEMCTRL, 0xd3, Data);
657 Data=pci_read_config8(MEMCTRL, 0xd7);
660 pci_write_config8(MEMCTRL, 0xd7, Data);
662 Data=pci_read_config8(MEMCTRL, 0xd3);
665 pci_write_config8(MEMCTRL, 0xd3, Data);
667 //step 14. MSR DLL Reset
668 AccessAddr = CHB_MRS_DLL_150[1] >> 3;
669 Data =(u8) (AccessAddr & 0xff);
670 pci_write_config8(MEMCTRL, 0xd9, Data);
672 Data = (u8)((AccessAddr & 0xff00) >> 8);
673 pci_write_config8(MEMCTRL, 0xda, Data);
675 Data=pci_read_config8(MEMCTRL, 0xd7);
677 Data |= (u8)((AccessAddr & 0x30000) >> 15);
678 pci_write_config8(MEMCTRL, 0xd7, Data);
680 //step15. issue MRS cycle
681 Data=pci_read_config8(MEMCTRL, 0xd3);
683 pci_write_config8(MEMCTRL, 0xd3, Data);
685 pci_write_config8(MEMCTRL, 0xd3, Data);
689 pci_write_config8(MEMCTRL, 0xda, Data);
691 //step16. all banks precharge command enable
692 Data=pci_read_config8(MEMCTRL, 0xd7);
695 pci_write_config8(MEMCTRL, 0xd7, Data);
698 // step17. issue precharge all cycle
699 Data=pci_read_config8(MEMCTRL, 0xd3);
701 pci_write_config8(MEMCTRL, 0xd3, Data);
703 pci_write_config8(MEMCTRL, 0xd3, Data);
705 //step18. CBR cycle enable
706 Data=pci_read_config8(MEMCTRL, 0xd7);
709 pci_write_config8(MEMCTRL, 0xd7, Data);
712 //repeat issue 8 CBR cycle, between each cycle stop 100us
713 for (Idx = 0; Idx < 8; Idx++)
716 Data=pci_read_config8(MEMCTRL, 0xd3);
718 pci_write_config8(MEMCTRL, 0xd3, Data);
720 pci_write_config8(MEMCTRL, 0xd3, Data);
726 Data=pci_read_config8(MEMCTRL, 0xd7);
729 pci_write_config8(MEMCTRL, 0xd7, Data);
731 Data=pci_read_config8(MEMCTRL, 0xd3);
734 pci_write_config8(MEMCTRL, 0xd3, Data);
737 //the SDRAM parameters.(Burst Length, CAS# Latency , Write recovery etc.)
738 //-------------------------------------------------------------
739 //Burst Length : really offset Rx6c[1]
740 Data=pci_read_config8(MEMCTRL, 0x6C);
741 BL = (Data & 0x02) >> 1;
743 // CL = really offset RX62[2:0]
744 Data=pci_read_config8(MEMCTRL, 0x62);
747 AccessAddr = (u32)(CHB_DDR2_MRS_table[CL]);
753 //Write recovery : really offset Rx63[7:5]
754 Data=pci_read_config8(MEMCTRL, 0x63);
755 Twr = (Data & 0xE0) >> 5;
757 AccessAddr += CHB_DDR2_Twr_table[Twr];
758 //MSR Address use addr[20:3]
761 //step 23. MSR command
762 Data = (u8)(AccessAddr & 0xFF);
763 pci_write_config8(MEMCTRL, 0xD9, Data);
765 Data = (u8)((AccessAddr & 0xFF00) >> 8);
766 pci_write_config8(MEMCTRL, 0xda, Data);
768 Data=pci_read_config8(MEMCTRL, 0xd7);
770 Data |= (u8)(((AccessAddr & 0x30000)>>16) << 1);
771 pci_write_config8(MEMCTRL, 0xd7, Data);
773 //step 24. issue MRS cycle
774 Data=pci_read_config8(MEMCTRL, 0xd3);
776 pci_write_config8(MEMCTRL, 0xd3, Data);
778 pci_write_config8(MEMCTRL, 0xd3, Data);
780 //step 25. EMRS enable
781 Data=pci_read_config8(MEMCTRL, 0xd7);
784 pci_write_config8(MEMCTRL, 0xd7, Data);
786 Data=pci_read_config8(MEMCTRL, 0xd3);
789 pci_write_config8(MEMCTRL, 0xd3, Data);
792 //step 26. OCD default
793 AccessAddr = (CHB_OCD_Default_150ohm) >> 3;
794 Data =(u8) (AccessAddr & 0xff);
795 pci_write_config8(MEMCTRL, 0xd9, Data);
797 Data = (u8)((AccessAddr & 0xff00) >> 8);
798 pci_write_config8(MEMCTRL, 0xda, Data);
800 Data=pci_read_config8(MEMCTRL, 0xd7);
802 Data |= (u8)((AccessAddr & 0x30000) >> 15);
803 pci_write_config8(MEMCTRL, 0xd7, Data);
805 //step 27. issue EMRS cycle
806 Data=pci_read_config8(MEMCTRL, 0xd3);
808 pci_write_config8(MEMCTRL, 0xd3, Data);
810 pci_write_config8(MEMCTRL, 0xd3, Data);
812 //step 25. EMRS enable
813 Data=pci_read_config8(MEMCTRL, 0xd7);
816 pci_write_config8(MEMCTRL, 0xd7, Data);
818 Data=pci_read_config8(MEMCTRL, 0xd3);
821 pci_write_config8(MEMCTRL, 0xd3, Data);
824 AccessAddr = (CHB_OCD_Exit_150ohm) >> 3;
825 Data =(u8) (AccessAddr & 0xff);
826 pci_write_config8(MEMCTRL, 0xd9, Data);
828 Data = (u8)((AccessAddr & 0xff00) >> 8);
829 pci_write_config8(MEMCTRL, 0xda, Data);
831 Data=pci_read_config8(MEMCTRL, 0xd7);
833 Data |= (u8)((AccessAddr & 0x30000) >> 15);
834 pci_write_config8(MEMCTRL, 0xd7, Data);
836 //step 29. issue EMRS cycle
837 Data=pci_read_config8(MEMCTRL, 0xd3);
839 pci_write_config8(MEMCTRL, 0xd3, Data);
841 pci_write_config8(MEMCTRL, 0xd3, Data);
843 //clear all the address
845 pci_write_config8(MEMCTRL, 0xd9, Data);
848 pci_write_config8(MEMCTRL, 0xda, Data);
850 Data=pci_read_config8(MEMCTRL, 0xd7);
852 pci_write_config8(MEMCTRL, 0xd7, Data);
854 //step 30. normal SDRAM Mode
855 Data=pci_read_config8(MEMCTRL, 0xd7);
858 pci_write_config8(MEMCTRL, 0xd7, Data);
860 Data=pci_read_config8(MEMCTRL, 0xd3);
863 pci_write_config8(MEMCTRL, 0xd3, Data);
865 //step 31. exit the initialization mode
866 Data=pci_read_config8(MEMCTRL, 0xd3);
868 pci_write_config8(MEMCTRL, 0xd3, Data);
871 //step 32. Enable bank paging and multi page
872 Data=pci_read_config8(MEMCTRL, 0x69);
874 pci_write_config8(MEMCTRL, 0x69, Data);
878 /*===================================================================
879 Function : InitDDR2CHC()
882 DramAttr: pointer point to DRAM_SYS_ATTR which consist the DDR and Dimm information
885 Purpose : Initialize DDR2 of CHC by standard sequence
887 ===================================================================*/
888 // DDR2 CL=2 CL=3 CL=4 CL=5 (Burst type=interleave)(WR fine tune in code)
889 static const u16 CHC_MRS_table[4] = { 0x22B, 0x23B, 0x24B, 0x25B }; // Use 1X-bandwidth MA table to init DRAM
891 void InitDDR2CHC(DRAM_SYS_ATTR *DramAttr)
893 u8 Data, Idx, CL, Twr;
897 /* Step 3. Clear RxDF[2] to disable Tri-state output. */
898 Data = pci_read_config8(MEMCTRL, 0xdf);
900 pci_write_config8(MEMCTRL, 0xdf, Data);
903 * Step 4. Enable the initialization mode of DRAM Controller C with
906 Data = pci_read_config8(MEMCTRL, 0xdb);
908 pci_write_config8(MEMCTRL, 0xdb, Data);
910 /* Step 5. NOP command enable. */
911 Data = pci_read_config8(MEMCTRL, 0xdb);
914 pci_write_config8(MEMCTRL, 0xdb, Data);
916 /* Step 6. Issue a nop cycle, RegDB[1] 0 -> 1. */
917 Data = pci_read_config8(MEMCTRL, 0xdb);
919 pci_write_config8(MEMCTRL, 0xdb, Data);
921 pci_write_config8(MEMCTRL, 0xdb, Data);
925 * A minimum pause of 200u sec will be provided after the NOP.
926 * - <<< reduce BOOT UP time >>> -
929 for (Idx = 0; Idx < 0x10; Idx++)
932 /* Step 8. Signal bank precharge command enable. */
933 Data = pci_read_config8(MEMCTRL, 0xdb);
936 pci_write_config8(MEMCTRL, 0xdb, Data);
938 /* Set MA10 = 1, precharge all bank. */
940 pci_write_config8(MEMCTRL, 0xf8, Data);
943 pci_write_config8(MEMCTRL, 0xf9, Data);
945 /* step 9. Issue a precharge all cycle, RegD3[7] 0 -> 1. */
946 Data = pci_read_config8(MEMCTRL, 0xdb);
948 pci_write_config8(MEMCTRL, 0xdb, Data);
950 pci_write_config8(MEMCTRL, 0xdb, Data);
952 /* Step 10. MRS enable. */
953 Data = pci_read_config8(MEMCTRL, 0xdb);
956 pci_write_config8(MEMCTRL, 0xdb, Data);
958 /* Step 11. EMRS DLL enable and Disable DQS. */
960 pci_write_config8(MEMCTRL, 0xf8, Data);
963 pci_write_config8(MEMCTRL, 0xf9, Data);
965 /* Step 12. Issue EMRS cycle. */
966 Data = pci_read_config8(MEMCTRL, 0xdb);
968 pci_write_config8(MEMCTRL, 0xdb, Data);
970 pci_write_config8(MEMCTRL, 0xdb, Data);
972 /* Step 13. MSR enable. */
973 Data = pci_read_config8(MEMCTRL, 0xdb);
976 pci_write_config8(MEMCTRL, 0xdb, Data);
978 /* Step 14. MSR DLL Reset. */
980 pci_write_config8(MEMCTRL, 0xf8, Data);
983 pci_write_config8(MEMCTRL, 0xf9, Data);
985 /* Step 15. Issue MRS cycle. */
986 Data = pci_read_config8(MEMCTRL, 0xdb);
988 pci_write_config8(MEMCTRL, 0xdb, Data);
990 pci_write_config8(MEMCTRL, 0xdb, Data);
992 /* Step 16. Signal banks precharge command enable. */
993 Data = pci_read_config8(MEMCTRL, 0xdb);
996 pci_write_config8(MEMCTRL, 0xdb, Data);
998 /* Set MA10 = 1, precharge all bank. */
1000 pci_write_config8(MEMCTRL, 0xf8, Data);
1003 pci_write_config8(MEMCTRL, 0xf9, Data);
1005 /* Step 17. Issue precharge all cycle. */
1006 Data = pci_read_config8(MEMCTRL, 0xdb);
1008 pci_write_config8(MEMCTRL, 0xdb, Data);
1010 pci_write_config8(MEMCTRL, 0xdb, Data);
1012 /* Step 18. CBR cycle enable. */
1013 Data = pci_read_config8(MEMCTRL, 0xdb);
1016 pci_write_config8(MEMCTRL, 0xdb, Data);
1019 pci_write_config8(MEMCTRL, 0xf8, Data);
1022 pci_write_config8(MEMCTRL, 0xf9, Data);
1025 //repeat issue 8 CBR cycle, between each cycle stop 100us
1026 for (Idx = 0; Idx < 8; Idx++) {
1028 Data = pci_read_config8(MEMCTRL, 0xdb);
1030 pci_write_config8(MEMCTRL, 0xdb, Data);
1032 pci_write_config8(MEMCTRL, 0xdb, Data);
1036 //the SDRAM parameters.(, CAS# Latency , Write recovery etc.)
1037 //------------------------------------------------------------
1039 // CL = really offset RXDC[7:6]
1040 Data = pci_read_config8(MEMCTRL, 0xdc);
1041 CL = (Data & 0xC0) >> 6;
1043 AccessAddr = (u32) (CHC_MRS_table[CL]);
1045 //Write recovery : really offset Rx63[7:5]
1046 Data = pci_read_config8(MEMCTRL, 0x63);
1047 Twr = (Data & 0xE0) >> 5;
1049 AccessAddr += Twr * 0x200;
1051 //step22. MSR enable
1052 Data = pci_read_config8(MEMCTRL, 0xdb);
1055 pci_write_config8(MEMCTRL, 0xdb, Data);
1057 //step 23. MSR command
1058 Data = (u8) (AccessAddr & 0xFF);
1059 pci_write_config8(MEMCTRL, 0xf8, Data);
1061 Data = (u8) ((AccessAddr & 0xFF00) >> 8);
1062 pci_write_config8(MEMCTRL, 0xf9, Data);
1064 //step 24. issue MRS cycle
1065 Data = pci_read_config8(MEMCTRL, 0xdb);
1067 pci_write_config8(MEMCTRL, 0xdb, Data);
1069 pci_write_config8(MEMCTRL, 0xdb, Data);
1071 //step 25. EMRS enable
1072 Data = pci_read_config8(MEMCTRL, 0xdb);
1075 pci_write_config8(MEMCTRL, 0xdb, Data);
1077 //step 26. OCD default
1079 pci_write_config8(MEMCTRL, 0xf8, Data);
1082 pci_write_config8(MEMCTRL, 0xf9, Data);
1084 //step 27. issue EMRS cycle
1085 Data = pci_read_config8(MEMCTRL, 0xdb);
1087 pci_write_config8(MEMCTRL, 0xdb, Data);
1089 pci_write_config8(MEMCTRL, 0xdb, Data);
1093 pci_write_config8(MEMCTRL, 0xf8, Data);
1096 pci_write_config8(MEMCTRL, 0xf9, Data);
1098 //step 29. issue EMRS cycle
1099 Data = pci_read_config8(MEMCTRL, 0xdb);
1101 pci_write_config8(MEMCTRL, 0xdb, Data);
1103 pci_write_config8(MEMCTRL, 0xdb, Data);
1105 Status = VerifyChc();
1106 if (Status != CB_SUCCESS)
1107 PRINT_DEBUG_MEM("Error!!!!CHC init error!\r");
1108 //step 31. exit the initialization mode
1109 Data = pci_read_config8(MEMCTRL, 0xdb);
1111 pci_write_config8(MEMCTRL, 0xdb, Data);
1114 CB_STATUS VerifyChc(void)
1116 u8 Data, ByteVal, Index, pad;
1119 //first write the pad to all the address
1121 //the row bits is 13 and rank bit is 2, so the address bits is 15 and the value is 0x7fff
1122 //verify each MA[0:12],BA[0:1]
1124 for (row = 0; row < 0x8000; row++) {
1125 /* Set the write value, Verify each MD[15:0]. */
1126 for (Data = pad, Index = 0; Index < 16; Index++) {
1130 pci_write_config8(PCI_DEV(0, 0, 7), 0xC0 + Index, Data);
1133 /* Issue the bank active command. */
1134 // bank active command enable
1135 Data = pci_read_config8(MEMCTRL, 0xdb);
1138 pci_write_config8(MEMCTRL, 0xdb, Data);
1140 Data = (u8) (row && 0xFF);
1141 pci_write_config8(MEMCTRL, 0xf8, Data);
1143 Data = (u8) ((row && 0xFF) >> 8);
1144 pci_write_config8(MEMCTRL, 0xf9, Data);
1146 /* Issue active cycle. */
1147 Data = pci_read_config8(MEMCTRL, 0xdb);
1149 pci_write_config8(MEMCTRL, 0xdb, Data);
1151 pci_write_config8(MEMCTRL, 0xdb, Data);
1153 /* Issue ready/completion for read/write. */
1154 // read/completion command enable
1155 Data = pci_read_config8(MEMCTRL, 0xdb);
1158 pci_write_config8(MEMCTRL, 0xdb, Data);
1161 pci_write_config8(MEMCTRL, 0xf8, Data);
1164 pci_write_config8(MEMCTRL, 0xf9, Data);
1166 /* Issue read/completion cycle. */
1167 Data = pci_read_config8(MEMCTRL, 0xdb);
1169 pci_write_config8(MEMCTRL, 0xdb, Data);
1171 pci_write_config8(MEMCTRL, 0xdb, Data);
1173 /* Issue write command. */
1174 // write command enable
1175 Data = pci_read_config8(MEMCTRL, 0xdb);
1178 pci_write_config8(MEMCTRL, 0xdb, Data);
1181 pci_write_config8(MEMCTRL, 0xf8, Data);
1183 Data = (u8) ((row & 0x60) << 5);
1184 pci_write_config8(MEMCTRL, 0xf9, Data);
1186 /* Issue write cycle. */
1187 Data = pci_read_config8(MEMCTRL, 0xdb);
1189 pci_write_config8(MEMCTRL, 0xdb, Data);
1191 pci_write_config8(MEMCTRL, 0xdb, Data);
1193 ////issue ready/completion for read/write
1194 // read/completion command enable
1195 Data = pci_read_config8(MEMCTRL, 0xdb);
1198 pci_write_config8(MEMCTRL, 0xdb, Data);
1201 pci_write_config8(MEMCTRL, 0xf8, Data);
1204 pci_write_config8(MEMCTRL, 0xf9, Data);
1206 /* Issue read/completion cycle. */
1207 Data = pci_read_config8(MEMCTRL, 0xdb);
1209 pci_write_config8(MEMCTRL, 0xdb, Data);
1211 pci_write_config8(MEMCTRL, 0xdb, Data);
1213 /* Issue the bank active command. */
1214 // bank active command enable
1215 Data = pci_read_config8(MEMCTRL, 0xdb);
1218 pci_write_config8(MEMCTRL, 0xdb, Data);
1220 Data = (u8) (row && 0xFF);
1221 pci_write_config8(MEMCTRL, 0xf8, Data);
1223 Data = (u8) ((row && 0xFF) >> 8);
1224 pci_write_config8(MEMCTRL, 0xf9, Data);
1226 // issue active cycle
1227 Data = pci_read_config8(MEMCTRL, 0xdb);
1229 pci_write_config8(MEMCTRL, 0xdb, Data);
1231 pci_write_config8(MEMCTRL, 0xdb, Data);
1233 ////issue ready/completion for read/write
1234 // read/completion command enable
1235 Data = pci_read_config8(MEMCTRL, 0xdb);
1238 pci_write_config8(MEMCTRL, 0xdb, Data);
1241 pci_write_config8(MEMCTRL, 0xf8, Data);
1244 pci_write_config8(MEMCTRL, 0xf9, Data);
1246 // issue read/completion cycle
1247 Data = pci_read_config8(MEMCTRL, 0xdb);
1249 pci_write_config8(MEMCTRL, 0xdb, Data);
1251 pci_write_config8(MEMCTRL, 0xdb, Data);
1253 ////issue read command
1254 // read/completion command enable
1255 Data = pci_read_config8(MEMCTRL, 0xdb);
1258 pci_write_config8(MEMCTRL, 0xdb, Data);
1261 pci_write_config8(MEMCTRL, 0xf8, Data);
1263 Data = (u8) ((row & 0x60) << 5);
1264 pci_write_config8(MEMCTRL, 0xf9, Data);
1267 Data = pci_read_config8(MEMCTRL, 0xdb);
1269 pci_write_config8(MEMCTRL, 0xdb, Data);
1271 pci_write_config8(MEMCTRL, 0xdb, Data);
1273 ////issue ready/completion for read/write
1274 // read/completion command enable
1275 Data = pci_read_config8(MEMCTRL, 0xdb);
1278 pci_write_config8(MEMCTRL, 0xdb, Data);
1281 pci_write_config8(MEMCTRL, 0xf8, Data);
1284 pci_write_config8(MEMCTRL, 0xf9, Data);
1286 /* Issue read/completion cycle. */
1287 Data = pci_read_config8(MEMCTRL, 0xdb);
1289 pci_write_config8(MEMCTRL, 0xdb, Data);
1291 pci_write_config8(MEMCTRL, 0xdb, Data);
1293 /* Verify the value. */
1294 for (ByteVal = pad, Index = 0; Index < 16; Index++) {
1295 Data = pci_read_config8(PCI_DEV(0, 0, 7), 0xD0 + Index);
1296 if (ByteVal != Data) {
1297 PRINT_DEBUG_MEM("Error! row = %x, index =%x, "
1298 "data = %x, byteval=%x\r");