Here's the VIA vx800 patch from OLPC.
[coreboot.git] / src / northbridge / via / vx800 / ddr2init / DramInit.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 #include "lib/memset.c"
21 CB_STATUS DDR2_DRAM_INIT()
22 {
23         CB_STATUS Status;
24         u8 i;
25         u32 RamSize;
26         BOOLEAN bTest;
27         DRAM_SYS_ATTR DramAttr;
28
29         PRINT_DEBUG_MEM("DRAM_INIT \r");
30
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);
34
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);
39         //Step4 DRDY
40         DRAMDRDYSetting(&DramAttr);
41         //Step5 Burst length
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);
53
54         //Step13 Interleave function in rankmap.c
55         DRAMBankInterleave(&DramAttr);
56         //Step14 Sizing
57         DRAMSizingMATypeM(&DramAttr);
58
59         //Step11 Search DQS and DQ output delay
60         DRAMDQSOutputSearch(&DramAttr);
61         //Step12 Search DQS  input delay
62         DRAMDQSInputSearch(&DramAttr);
63
64         //Step15 DDR fresh counter setting
65         DRAMRefreshCounter(&DramAttr);
66         //Step16 Final register setting for improve performance
67         DRAMRegFinalValue(&DramAttr);
68
69         RamSize = 0;
70         for (i = 0; i < MAX_RANKS; i++) {
71                 if (DramAttr.RankSize[i] == 0) {
72                         continue;
73                 }
74                 RamSize += DramAttr.RankSize[i];
75         }
76         PRINT_DEBUG_MEM("RamSize=");
77         PRINT_DEBUG_MEM_HEX32(RamSize);
78         PRINT_DEBUG_MEM("\r");
79         DumpRegisters(0, 3);
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 */
84         SetUMARam();
85         return CB_SUCCESS;
86 }