Various license header consistency fixes (trivial).
[coreboot.git] / src / northbridge / via / vx800 / dram_init.h
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; 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 #ifndef __DRAMINIT_H_
21 #define __DRAMINIT_H_
22
23 //Dram Size
24 #define M   (1024*1024)
25 #define M1  (1*M)
26 #define M64  (64*M)
27 #define M128  (128*M)
28 #define M256  (256*M)
29 #define M384  (384*M)
30 #define M512  (512*M)
31
32 // UMA size
33 #define         UMASIZE  M64
34
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.
37 //Dram Freq
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
46
47 //Dram Type
48 #define  RAMTYPE_FPMDRAM   1
49 #define  RAMTYPE_EDO       2
50 #define  RAMTYPE_PipelinedNibble 3
51 #define  RAMTYPE_SDRAM     4
52 #define  RAMTYPE_ROM       5
53 #define  RAMTYPE_SGRAMDDR  6
54 #define  RAMTYPE_SDRAMDDR  7
55 #define  RAMTYPE_SDRAMDDR2 8
56
57 /* CAS latency constant */
58 #define CASLAN_15         15
59 #define CASLAN_2           20
60 #define CASLAN_25         25
61 #define CASLAN_3           30
62 #define CASLAN_35         35
63 #define CASLAN_4           40
64 #define CASLAN_45         45
65 #define CASLAN_5           50
66 #define CASLAN_NULL     00
67
68 //Burst length
69 #define  BURSTLENGTH8    8
70 #define  BURSTLENGTH4    4
71
72 //Data Width
73 //#define  DATAWIDTHX16    16
74 //#define  DATAWIDTHX8       8
75 //#define  DATAWIDTHX4       4
76
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 */
109
110 #define  SPD_DATA_SIZE 44
111 //Dram cofig are
112 /*the most number of socket*/
113 #define  MAX_RAM_SLOTS  2
114
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
119
120 struct mem_controller {
121         u8 channel0[MAX_DIMMS];
122 };
123
124 static const struct mem_controller ctrl = {
125         .channel0 = {0x50, 0x51},
126 };
127
128 typedef struct _DRAM_CONFIG_DATA {
129         u8 DramClk;
130         u8 DramTiming;
131         u8 CasLatency;
132         u8 BankIntlv;
133         u8 Trp;
134         u8 Tras;
135         u8 Trcd;
136         u8 Trfc;
137         u8 Trrd;
138         u8 Trtp;
139         u8 Twtr;
140         u8 Twr;
141
142         u8 CmdRate;
143         u8 DualEn;
144         //u8    IntLv0;
145         //u8    IntLv1;
146         //u8    Ba0Sel;
147         //u8    Ba1Sel;
148         //u8    Ba2Sel;
149         u8 BaScmb;
150         u8 DrdyTiming;
151         //u8    Above4G;
152         //u8    RdsaitMode;
153         //u8    Rdsait;
154         //u8    TopPerf;
155
156         u16 UMASize;
157 } DRAM_CONFIG_DATA;
158
159 /*DIMM(assembly) information*/
160 typedef struct _DIMM_INFO_tag {
161         u8 bPresence;
162         u8 SPDDataBuf[SPD_DATA_SIZE];   /*get all information from spd data */
163 } DIMM_INFO;
164
165 typedef struct _DRAM_SYS_ATTR_tag {
166         DIMM_INFO DimmInfo[MAX_DIMMS];
167
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 */
171         u8 DimmNumChB;
172         u8 RankNumChA;          /*the number of Ranks on the mortherbaord */
173         u8 RankNumChB;
174         u8 LoadNumChA;          /*the number of chips on all DIMM */
175         u8 LoadNumChB;
176
177         u8 DramType;            /*DDR1 or DDR2 */
178         u16 DramFreq;
179         u16 DramCyc;            /*10ns, 7.5ns, 6ns, 5ns, 3.75ns, 3ns, 2.5ns   =1/SysFreq, unit: 100*ns. */
180
181         //u16    HFreq; /*100, 133, 166, 200, 266, 333, 400*/
182
183         u8 CL;                  /* CAS lantency */
184         u8 CmdRate;             /*1T or 2T */
185
186         u32 RankSize[MAX_RANKS];
187         u8 Dual_Channel;
188         DRAM_CONFIG_DATA ConfigData;
189         u8 reserved[4];
190
191 } DRAM_SYS_ATTR;
192
193 typedef struct _DRAM_SIZE_INFO {
194         u32 RankLength[MAX_RANKS];
195 } DRAM_SIZE_INFO;
196
197 //detection.c
198 /*Step1 detect DRAM type, Read SPD data,command rate*/
199 CB_STATUS DRAMDetect(DRAM_SYS_ATTR * DramAttr);
200 //freq_setting.c
201 /*Step2 set Frequency, calculate CAL*/
202 void DRAMFreqSetting(DRAM_SYS_ATTR * DramAttr);
203 //timing_setting.c
204 /*Step3 Set DRAM        Timing*/
205 void DRAMTimingSetting(DRAM_SYS_ATTR * DramAttr);
206 //drdy_bl.c
207 /*Step4 DRDY*/
208 void DRAMDRDYSetting(DRAM_SYS_ATTR * DramAttr);
209 //drdy_bl.c
210 /*Step5 Burst Length*/
211 void DRAMBurstLength(DRAM_SYS_ATTR * DramAttr);
212 //driving_setting.c
213 /*Step6 DRAM Driving Adjustment*/
214 void DRAMDriving(DRAM_SYS_ATTR * DramAttr);
215
216 //clk_ctrl.c
217 /*Step7 duty cycle control*/
218 void DutyCycleCtrl(DRAM_SYS_ATTR * DramAttr);
219 //clk_ctrl.c
220 /*Step8 DRAM clock phase and delay control*/
221 void DRAMClkCtrl(DRAM_SYS_ATTR * DramAttr);
222
223 //dev_init.c
224 /*Step9 set register before init DRAM device*/
225 void DRAMRegInitValue(DRAM_SYS_ATTR * DramAttr);
226
227 //dev_init.c
228 /*Step10 DDR and DDR2 initialize process*/
229 void DRAMInitializeProc(DRAM_SYS_ATTR * DramAttr);
230
231 //dqs_search.c
232 /*Step11 Search DQS and DQ output delay*/
233 void DRAMDQSOutputSearch(DRAM_SYS_ATTR * DramAttr);
234
235 //dqs_search.c
236 /*Step12 Search DQS  input delay*/
237 void DRAMDQSInputSearch(DRAM_SYS_ATTR * DramAttr);
238
239 //rank_map.c
240 /*Step13 Interleav function in rankmap.c*/
241 void DRAMBankInterleave(DRAM_SYS_ATTR * DramAttr);
242
243 //rank_map.c
244 /*Step14 Sizing*/
245 void DRAMSizingMATypeM(DRAM_SYS_ATTR * DramAttr);
246
247 //final_setting.c
248 /*Step15 DDR fresh counter setting*/
249 void DRAMRefreshCounter(DRAM_SYS_ATTR * DramAttr);
250
251 //final_setting.c
252 /*Step16 Final register setting for improve performance*/
253 void DRAMRegFinalValue(DRAM_SYS_ATTR * DramAttr);
254
255 /*set UMA*/
256 void SetUMARam();
257
258 CB_STATUS InstallMemory(DRAM_SYS_ATTR * DramAttr, u32 RamSize);
259 CB_STATUS DDR2_DRAM_INIT();
260
261 #endif