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
35 #define ENABLE_CHC 0 //CHC enable, how ever, this CHC,used some reg define in CHB
36 #define ENABLE_CHB 0 //CHB enable , CHB is VX800's, VX855 no this CHB.
38 #define DIMMFREQ_800 400
39 #define DIMMFREQ_667 333
40 //#define DIMMFREQ_600 300
41 #define DIMMFREQ_533 266
42 #define DIMMFREQ_400 200
43 #define DIMMFREQ_333 166
44 #define DIMMFREQ_266 133
45 #define DIMMFREQ_200 100
48 #define RAMTYPE_FPMDRAM 1
50 #define RAMTYPE_PipelinedNibble 3
51 #define RAMTYPE_SDRAM 4
53 #define RAMTYPE_SGRAMDDR 6
54 #define RAMTYPE_SDRAMDDR 7
55 #define RAMTYPE_SDRAMDDR2 8
57 /* CAS latency constant */
66 #define CASLAN_NULL 00
69 #define BURSTLENGTH8 8
70 #define BURSTLENGTH4 4
73 //#define DATAWIDTHX16 16
74 //#define DATAWIDTHX8 8
75 //#define DATAWIDTHX4 4
77 #define SPD_MEMORY_TYPE 2 /*Memory type FPM,EDO,SDRAM,DDR,DDR2 */
78 #define SPD_SDRAM_ROW_ADDR 3 /*Number of row addresses on this assembly */
79 #define SPD_SDRAM_COL_ADDR 4 /*Number of column addresses on this assembly */
80 #define SPD_SDRAM_DIMM_RANKS 5 /*Number of RANKS on this assembly */
81 #define SPD_SDRAM_MOD_DATA_WIDTH 6 /*Data width of this assembly */
82 #define SPD_SDRAM_TCLK_X 9 /*Cycle time at Maximum supported CAS latency (CL=X) */
83 #define SPD_SDRAM_TAC_X 10 /*Access time for highest CL */
84 #define SPD_SDRAM_CONFIG_TYPE 11 /*Non-parity , Parity or ECC */
85 #define SPD_SDRAM_REFRESH 12 /*Refresh rate/type */
86 #define SPD_SDRAM_WIDTH 13 /*Primary sdram width */
87 #define SPD_SDRAM_MIN_CLK_DLY 15 /*Minimum clock delay */
88 #define SPD_SDRAM_BURSTLENGTH 16 /*Burst Lengths supported */
89 #define SPD_SDRAM_NO_OF_BANKS 17 /*Number of banks on this assembly */
90 #define SPD_SDRAM_CAS_LATENCY 18 /*CAS latency */
91 #define SPD_SDRAM_DIMM_TYPE_DDR2 20 /*DIMM type information; identifies the DDR2 memory module type */
92 #define SPD_SDRAM_DEV_ATTR_DDR1 20 /*WE latency */
93 #define SPD_SDRAM_MODULES_ATTR 21 /*This byte depicts various aspects of the modules; DDR DDR2 have different aspects */
94 #define SPD_SDRAM_DEV_ATTR_GEN 22 /*General device attributes */
95 #define SPD_SDRAM_TCLK_X_1 23 /*Minimum clock cycle time at Reduced CL, DDR: X-0.5 DDR2: X-1 */
96 #define SPD_SDRAM_TAC_X_1 24 /*Maximum Data Access time from Clock at reduced CL,DDR: X-0.5 DDR2: X-1 */
97 #define SPD_SDRAM_TCLK_X_2 25 /*Minimum clock cycle time at reduced CL, DDR: X-1 DDR2: X-2 */
98 #define SPD_SDRAM_TAC_X_2 26 /*Maximum Data Access time from Clock at reduced CL, DDR: X-1 DDR2: X-2 */
99 #define SPD_SDRAM_TRP 27 /*minimum row precharge time */
100 #define SPD_SDRAM_TRRD 28 /*minimum row active to row active delay */
101 #define SPD_SDRAM_TRCD 29 /*minimum RAS to CAS delay */
102 #define SPD_SDRAM_TRAS 30 /*minimum active to precharge time */
103 #define SPD_SDRAM_TWR 36 /*write recovery time, only DDR2 use it */
104 #define SPD_SDRAM_TWTR 37 /*internal write to read command delay, only DDR2 use it */
105 #define SPD_SDRAM_TRTP 38 /*internal read to prechange command delay, only DDR2 use it */
106 #define SPD_SDRAM_TRFC2 40 /*extension of byte 41 tRC and byte 42 tRFC, only DDR2 use it */
107 #define SPC_SDRAM_TRC 41 /*minimum active to active/refresh time */
108 #define SPD_SDRAM_TRFC 42 /*minimum refresh to active / refresh command period */
110 #define SPD_DATA_SIZE 44
112 /*the most number of socket*/
113 #define MAX_RAM_SLOTS 2
115 #define MAX_SOCKETS MAX_RAM_SLOTS
116 #define MAX_DIMMS MAX_SOCKETS /*every sockets can plug one DIMM */
117 /*the most number of RANKs on a DIMM*/
118 #define MAX_RANKS MAX_SOCKETS*2
120 struct mem_controller {
121 u8 channel0[MAX_DIMMS];
124 static const struct mem_controller ctrl = {
125 .channel0 = {0x50, 0x51},
128 typedef struct _DRAM_CONFIG_DATA {
159 /*DIMM(assembly) information*/
160 typedef struct _DIMM_INFO_tag {
162 u8 SPDDataBuf[SPD_DATA_SIZE]; /*get all information from spd data */
165 typedef struct _DRAM_SYS_ATTR_tag {
166 DIMM_INFO DimmInfo[MAX_DIMMS];
168 u8 RankPresentMap; /*bit0,1 Rank0,1 on DIMM0, bit2,3 Rank2,3 on DIMM1,
169 bit4,5 Rank4,5 on DIMM2, bit6,7 Rank6,7 on DIMM3 */
170 u8 DimmNumChA; /*Dimm number */
172 u8 RankNumChA; /*the number of Ranks on the mortherbaord */
174 u8 LoadNumChA; /*the number of chips on all DIMM */
177 u8 DramType; /*DDR1 or DDR2 */
179 u16 DramCyc; /*10ns, 7.5ns, 6ns, 5ns, 3.75ns, 3ns, 2.5ns =1/SysFreq, unit: 100*ns. */
181 //u16 HFreq; /*100, 133, 166, 200, 266, 333, 400*/
183 u8 CL; /* CAS lantency */
184 u8 CmdRate; /*1T or 2T */
186 u32 RankSize[MAX_RANKS];
188 DRAM_CONFIG_DATA ConfigData;
193 typedef struct _DRAM_SIZE_INFO {
194 u32 RankLength[MAX_RANKS];
198 /*Step1 detect DRAM type, Read SPD data,command rate*/
199 CB_STATUS DRAMDetect(DRAM_SYS_ATTR * DramAttr);
201 /*Step2 set Frequency, calculate CAL*/
202 void DRAMFreqSetting(DRAM_SYS_ATTR * DramAttr);
204 /*Step3 Set DRAM Timing*/
205 void DRAMTimingSetting(DRAM_SYS_ATTR * DramAttr);
208 void DRAMDRDYSetting(DRAM_SYS_ATTR * DramAttr);
210 /*Step5 Burst Length*/
211 void DRAMBurstLength(DRAM_SYS_ATTR * DramAttr);
213 /*Step6 DRAM Driving Adjustment*/
214 void DRAMDriving(DRAM_SYS_ATTR * DramAttr);
217 /*Step7 duty cycle control*/
218 void DutyCycleCtrl(DRAM_SYS_ATTR * DramAttr);
220 /*Step8 DRAM clock phase and delay control*/
221 void DRAMClkCtrl(DRAM_SYS_ATTR * DramAttr);
224 /*Step9 set register before init DRAM device*/
225 void DRAMRegInitValue(DRAM_SYS_ATTR * DramAttr);
228 /*Step10 DDR and DDR2 initialize process*/
229 void DRAMInitializeProc(DRAM_SYS_ATTR * DramAttr);
232 /*Step11 Search DQS and DQ output delay*/
233 void DRAMDQSOutputSearch(DRAM_SYS_ATTR * DramAttr);
236 /*Step12 Search DQS input delay*/
237 void DRAMDQSInputSearch(DRAM_SYS_ATTR * DramAttr);
240 /*Step13 Interleav function in rankmap.c*/
241 void DRAMBankInterleave(DRAM_SYS_ATTR * DramAttr);
245 void DRAMSizingMATypeM(DRAM_SYS_ATTR * DramAttr);
248 /*Step15 DDR fresh counter setting*/
249 void DRAMRefreshCounter(DRAM_SYS_ATTR * DramAttr);
252 /*Step16 Final register setting for improve performance*/
253 void DRAMRegFinalValue(DRAM_SYS_ATTR * DramAttr);
258 CB_STATUS InstallMemory(DRAM_SYS_ATTR * DramAttr, u32 RamSize);
259 CB_STATUS DDR2_DRAM_INIT();