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