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; either 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 CB_STATUS DDR2_DRAM_INIT()
26 DRAM_SYS_ATTR DramAttr;
28 PRINT_DEBUG_MEM("DRAM_INIT \r");
30 memset(&DramAttr, 0, sizeof(DRAM_SYS_ATTR));
31 /*Step1 DRAM Detection; DDR1 or DDR2; Get SPD Data; Rank Presence;64 or 128bit; Unbuffered or registered; 1T or 2T */
32 DRAMDetect(&DramAttr);
34 //Step2 set Frequency; calculate CL and Frequncy from SPD data; set the Frequency
35 DRAMFreqSetting(&DramAttr);
36 //Step3 Set DRAM Timing; CL, tRP, tRCD, tRAS, tRFC, tRRD, tWR, tWTR, tRTP
37 DRAMTimingSetting(&DramAttr);
39 DRAMDRDYSetting(&DramAttr);
41 DRAMBurstLength(&DramAttr);
42 //Step6 DRAM Driving Adjustment
43 DRAMDriving(&DramAttr);
44 //Step7 duty cycle control
45 DutyCycleCtrl(&DramAttr);
46 //Step8 DRAM clock phase and delay control
47 DRAMClkCtrl(&DramAttr);
48 //Step9 set register before init DRAM device
49 DRAMRegInitValue(&DramAttr);
50 //Step10 DDR and DDR2 initialize process
51 DRAMInitializeProc(&DramAttr);
53 //Step13 Interleave function in rankmap.c
54 DRAMBankInterleave(&DramAttr);
56 DRAMSizingMATypeM(&DramAttr);
58 //Step11 Search DQS and DQ output delay
59 DRAMDQSOutputSearch(&DramAttr);
60 //Step12 Search DQS input delay
61 DRAMDQSInputSearch(&DramAttr);
63 //Step15 DDR fresh counter setting
64 DRAMRefreshCounter(&DramAttr);
65 //Step16 Final register setting for improve performance
66 DRAMRegFinalValue(&DramAttr);
69 for (i = 0; i < MAX_RANKS; i++) {
70 if (DramAttr.RankSize[i] == 0) {
73 RamSize += DramAttr.RankSize[i];
75 PRINT_DEBUG_MEM("RamSize=");
76 PRINT_DEBUG_MEM_HEX32(RamSize);
77 PRINT_DEBUG_MEM("\r");
79 //bTest = DramBaseTest( M1, RamSize - M1 * 2,SPARE, FALSE);
80 /* the memory can not correct work, this is because the user set the incorrect memory
81 parameter from setup interface.so we must set the boot mode to recovery mode, let
82 the system to reset and use the spd value to initialize the memory */