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
21 Driving setting: ODT/DQS/DQ/CS/MAA/MAB/DCLK
24 void DrivingODT(DRAM_SYS_ATTR * DramAttr);
26 void DrivingDQS(DRAM_SYS_ATTR * DramAttr);
28 void DrivingDQ(DRAM_SYS_ATTR * DramAttr);
30 void DrivingCS(DRAM_SYS_ATTR * DramAttr);
32 void DrivingMA(DRAM_SYS_ATTR * DramAttr);
34 void DrivingDCLK(DRAM_SYS_ATTR * DramAttr);
36 /* DRAM Driving Adjustment*/
37 void DRAMDriving(DRAM_SYS_ATTR * DramAttr)
39 PRINT_DEBUG_MEM("set ODT!\r");
42 PRINT_DEBUG_MEM("set DQS!\r");
45 PRINT_DEBUG_MEM(("set DQ!\r"));
48 PRINT_DEBUG_MEM("set CS!\r");
51 PRINT_DEBUG_MEM("set MAA!\r");
54 PRINT_DEBUG_MEM("set DCLK!\r");
55 DrivingDCLK(DramAttr);
60 ODT Control for DQ/DQS/CKE/SCMD/DCLKO in ChA & ChB
61 which include driving enable/range and strong/weak selection
63 Processing: According to DRAM frequency to ODT control bits.
64 Because function enable bit must be the last one to be set.
65 So the register VIA_NB3DRAM_REGD4 and VIA_NB3DRAM_REGD3 should be
66 the last register to be programmed.
68 //-------------------------------------------------------------------------------
70 //-------------------------------------------------------------------------------
76 #define NB_ODT_75ohm 0
77 #define NB_ODT_150ohm 1
79 #define DDR2_ODT_75ohm 0x20
80 #define DDR2_ODT_150ohm 0x40
82 // Setting of ODT Lookup TBL
83 // RankMAP , Rank 3 Rank 2 Rank 1 Rank 0 , DRAM & NB ODT setting
84 // db 0000b , Reserved
85 #define ODTLookup_Tbl_count 8
86 static const u8 ODTLookup_TBL[ODTLookup_Tbl_count][3] = {
89 (Rank3_ODT << 6) + (Rank2_ODT << 4) + (Rank1_ODT << 2) +
90 Rank0_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
94 (Rank3_ODT << 6) + (Rank2_ODT << 4) + (Rank0_ODT << 2) +
95 Rank1_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
98 (Rank3_ODT << 6) + (Rank2_ODT << 4) + (Rank1_ODT << 2) +
99 Rank0_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
102 (Rank3_ODT << 6) + (Rank0_ODT << 4) + (Rank1_ODT << 2) +
103 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm},
107 (Rank3_ODT << 6) + (Rank0_ODT << 4) + (Rank2_ODT << 2) +
108 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm},
115 (Rank2_ODT << 6) + (Rank3_ODT << 4) + (Rank1_ODT << 2) +
116 Rank0_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
119 (Rank0_ODT << 6) + (Rank0_ODT << 4) + (Rank1_ODT << 2) +
120 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm},
124 (Rank0_ODT << 6) + (Rank0_ODT << 4) + (Rank2_ODT << 2) +
125 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm}
128 #define ODT_Table_Width_DDR2 4
130 static const u8 ODT_Control_DDR2[ODT_Table_Width_DDR2] = { 0xFC, 0x01 };
132 void DrivingODT(DRAM_SYS_ATTR * DramAttr)
138 pci_write_config8(MEMCTRL, 0xD0, 0x88);
140 Data = ODT_Control_DDR2[0];
141 pci_write_config8(MEMCTRL, 0xd6, Data);
143 Data = ODT_Control_DDR2[1];
144 pci_write_config8(MEMCTRL, 0xd3, Data);
146 Data = pci_read_config8(MEMCTRL, 0x9e);
147 //set MD turn_around wait state
148 Data &= 0xCF; /*clear bit4,5 */
149 if (DIMMFREQ_400 == DramAttr->DramFreq)
151 else if (DIMMFREQ_533 == DramAttr->DramFreq)
153 else if (DIMMFREQ_667 == DramAttr->DramFreq)
155 else if (DIMMFREQ_800 == DramAttr->DramFreq)
159 pci_write_config8(MEMCTRL, 0x9e, Data);
162 if (DIMMFREQ_400 == DramAttr->DramFreq)
164 else if (DIMMFREQ_533 == DramAttr->DramFreq)
166 else if (DIMMFREQ_667 == DramAttr->DramFreq)
168 else if (DIMMFREQ_800 == DramAttr->DramFreq)
172 pci_write_config8(MEMCTRL, 0x9f, Data);
175 /*channel A ODT select */
176 if (DramAttr->DimmNumChA > 0) {
177 Data = pci_read_config8(MEMCTRL, 0xd5);
178 Data &= 0x5F; /*clear bit7,5 */
179 if (DramAttr->RankNumChA > 2)
180 Data |= 0xA0; /*if rank number > 2 (3or4), set bit7,5 */
182 Data |= 0x00; /*if rank number is 1or2, clear bit5 */
183 pci_write_config8(MEMCTRL, 0xd5, Data);
185 Data = pci_read_config8(MEMCTRL, 0xd7);
186 Data &= 0xEF; /*clear bit7 */
187 if (DramAttr->RankNumChA > 2)
188 Data |= 0x80; /*if rank number > 2 (3or4), set bit7 */
190 Data |= 0x00; /*if rank number is 1or2, clear bit7 */
191 pci_write_config8(MEMCTRL, 0xd7, Data);
195 Data = pci_read_config8(MEMCTRL, 0xd5);
196 Data &= 0xF3; //bit2,3
197 if (DramAttr->DimmNumChA == 2) /*2 Dimm, 3or4 Ranks */
199 else if (DramAttr->DimmNumChA == 1)
201 pci_write_config8(MEMCTRL, 0xd5, Data);
203 if ((DramAttr->RankPresentMap & 0x0F) != 0) { /*channel A */
204 // MAA ODT Lookup Table
206 for (i = 0; i < ODTLookup_Tbl_count; i++) {
207 if ((DramAttr->RankPresentMap & 0x0F) ==
208 ODTLookup_TBL[i][0]) {
209 Data = ODTLookup_TBL[i][1];
213 if (!bFound) { /*set default value */
215 ODTLookup_TBL[ODTLookup_Tbl_count -
218 pci_write_config8(MEMCTRL, 0x9c, Data);
221 //set CHA MD ODT control State Dynamic-on
222 Data = pci_read_config8(MEMCTRL, 0xD4);
225 pci_write_config8(MEMCTRL, 0xD4, Data);
227 Data = pci_read_config8(MEMCTRL, 0x9e);
229 pci_write_config8(MEMCTRL, 0x9e, Data);
234 if (1 == ENABLE_CHC) {
235 //CHB has not auto compensation mode ,so must set it manual,or else CHB initialization will not successful
237 //pci_write_config8(MEMCTRL, 0xd0, Data);
239 Data = pci_read_config8(MEMCTRL, 0xd5);
241 if (DramAttr->RankNumChB > 2) /*rank number 3 or 4 */
245 pci_write_config8(MEMCTRL, 0xd5, Data);
247 Data = pci_read_config8(MEMCTRL, 0xd7);
248 Data &= 0xBF; /*clear bit6 */
249 if (DramAttr->RankNumChB > 2)
250 Data |= 0x40; /*if rank number > 2 (3or4), set bit7 */
252 Data |= 0x00; /*if rank number is 1or2, clear bit7 */
253 pci_write_config8(MEMCTRL, 0xd7, Data);
256 Data = pci_read_config8(MEMCTRL, 0xd5);
258 if (DramAttr->DimmNumChB == 2) /*2 Dimm, 3or4 Ranks */
259 Data |= 0x00; // 2 dimm RxD5[2,0]=0,0b
260 else if (DramAttr->DimmNumChB == 1)
261 Data |= 0x01; // 1 dimm RxD5[2,0]=1,1b
262 pci_write_config8(MEMCTRL, 0xd5, Data);
264 //set CHB MD ODT control State Dynamic-on
265 Data = pci_read_config8(MEMCTRL, 0xD4);
268 pci_write_config8(MEMCTRL, 0xD4, Data);
271 //enable CHB differential DQS input
272 Data = pci_read_config8(MEMCTRL, 0x9E);
274 pci_write_config8(MEMCTRL, 0x9E, Data);
277 Data = pci_read_config8(MEMCTRL, 0x9e);
279 pci_write_config8(MEMCTRL, 0x9e, Data);
282 void DrivingDQS(DRAM_SYS_ATTR * DramAttr)
287 if (DramAttr->RankNumChA > 0) {
288 Data = DDR2_DQSA_Driving_Table[DramAttr->RankNumChA - 1];
289 pci_write_config8(MEMCTRL, 0xe0, Data);
293 if (1 == ENABLE_CHC) {
294 Data = DDR2_DQSB_Driving_Table[DramAttr->RankNumChB - 1];
295 pci_write_config8(MEMCTRL, 0xe1, Data);
300 void DrivingDQ(DRAM_SYS_ATTR * DramAttr)
305 if (DramAttr->RankNumChA > 0) {
306 Data = DDR2_DQA_Driving_Table[DramAttr->RankNumChA - 1];
307 pci_write_config8(MEMCTRL, 0xe2, Data);
311 if (1 == ENABLE_CHC) {
312 Data = DDR2_DQB_Driving_Table[DramAttr->RankNumChB - 1];
313 pci_write_config8(MEMCTRL, 0xe3, Data);
317 void DrivingCS(DRAM_SYS_ATTR * DramAttr)
321 if (DramAttr->RankNumChA > 0) {
322 Data = DDR2_CSA_Driving_Table_x8[DramAttr->RankNumChA - 1];
323 pci_write_config8(MEMCTRL, 0xe4, Data);
326 if (1 == ENABLE_CHC) {
327 Data = DDR2_CSB_Driving_Table_x8[DramAttr->RankNumChB - 1];
328 pci_write_config8(MEMCTRL, 0xe5, Data);
332 void DrivingMA(DRAM_SYS_ATTR * DramAttr)
337 if (DramAttr->RankNumChA > 0) {
338 if (DIMMFREQ_400 == DramAttr->DramFreq)
340 else if (DIMMFREQ_533 == DramAttr->DramFreq)
342 else if (DIMMFREQ_667 == DramAttr->DramFreq)
344 else if (DIMMFREQ_800 == DramAttr->DramFreq)
348 for (i = 0; i < MA_Table; i++) {
349 if (DramAttr->LoadNumChA <=
350 DDR2_MAA_Driving_Table[i][0]) {
351 Data = DDR2_MAA_Driving_Table[i][FreqId];
355 pci_write_config8(MEMCTRL, 0xe8, Data);
357 if (1 == ENABLE_CHC) {
358 for (i = 0; i < MA_Table; i++) {
359 if (DramAttr->LoadNumChA <=
360 DDR2_MAB_Driving_Table[i][0]) {
361 Data = DDR2_MAB_Driving_Table[i][1];
365 pci_write_config8(MEMCTRL, 0xe9, Data);
369 void DrivingDCLK(DRAM_SYS_ATTR * DramAttr)
374 if (DIMMFREQ_400 == DramAttr->DramFreq)
376 else if (DIMMFREQ_533 == DramAttr->DramFreq)
378 else if (DIMMFREQ_667 == DramAttr->DramFreq)
380 else if (DIMMFREQ_800 == DramAttr->DramFreq)
386 if (DramAttr->RankNumChA > 0) {
387 Data = DDR2_DCLKA_Driving_Table[FreqId];
388 pci_write_config8(MEMCTRL, 0xe6, Data);
391 if (1 == ENABLE_CHC) {
392 Data = DDR2_DCLKB_Driving_Table[FreqId];
393 pci_write_config8(MEMCTRL, 0xe7, Data);