Add missing Copyright line, sorry.
[coreboot.git] / src / northbridge / via / vx800 / dram_init.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 One Laptop per Child, Association, Inc.
5  *
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.
9  *
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.
14  *
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
18  */
19
20 CB_STATUS DDR2_DRAM_INIT()
21 {
22         CB_STATUS Status;
23         u8 i;
24         u32 RamSize;
25         BOOLEAN bTest;
26         DRAM_SYS_ATTR DramAttr;
27
28         PRINT_DEBUG_MEM("DRAM_INIT \r");
29
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);
33
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);
38         //Step4 DRDY
39         DRAMDRDYSetting(&DramAttr);
40         //Step5 Burst length
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);
52
53         //Step13 Interleave function in rankmap.c
54         DRAMBankInterleave(&DramAttr);
55         //Step14 Sizing
56         DRAMSizingMATypeM(&DramAttr);
57
58         //Step11 Search DQS and DQ output delay
59         DRAMDQSOutputSearch(&DramAttr);
60         //Step12 Search DQS  input delay
61         DRAMDQSInputSearch(&DramAttr);
62
63         //Step15 DDR fresh counter setting
64         DRAMRefreshCounter(&DramAttr);
65         //Step16 Final register setting for improve performance
66         DRAMRegFinalValue(&DramAttr);
67
68         RamSize = 0;
69         for (i = 0; i < MAX_RANKS; i++) {
70                 if (DramAttr.RankSize[i] == 0) {
71                         continue;
72                 }
73                 RamSize += DramAttr.RankSize[i];
74         }
75         PRINT_DEBUG_MEM("RamSize=");
76         PRINT_DEBUG_MEM_HEX32(RamSize);
77         PRINT_DEBUG_MEM("\r");
78         DumpRegisters(0, 3);
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 */
83         SetUMARam();
84         return CB_SUCCESS;
85 }