summaryrefslogtreecommitdiff
path: root/src/northbridge/via/vx800/driving_setting.c
blob: c6a7edda056b7584127e20057a3f87dfe54318fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2009 One Laptop per Child, Association, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

/*
      Driving setting:  ODT/DQS/DQ/CS/MAA/MAB/DCLK
    */

void DrivingODT(DRAM_SYS_ATTR * DramAttr);

void DrivingDQS(DRAM_SYS_ATTR * DramAttr);

void DrivingDQ(DRAM_SYS_ATTR * DramAttr);

void DrivingCS(DRAM_SYS_ATTR * DramAttr);

void DrivingMA(DRAM_SYS_ATTR * DramAttr);

void DrivingDCLK(DRAM_SYS_ATTR * DramAttr);

/* DRAM Driving Adjustment*/
void DRAMDriving(DRAM_SYS_ATTR * DramAttr)
{
	PRINT_DEBUG_MEM("set ODT!\r");
	DrivingODT(DramAttr);

	PRINT_DEBUG_MEM("set DQS!\r");
	DrivingDQS(DramAttr);

	PRINT_DEBUG_MEM(("set DQ!\r"));
	DrivingDQ(DramAttr);

	PRINT_DEBUG_MEM("set CS!\r");
	DrivingCS(DramAttr);

	PRINT_DEBUG_MEM("set MAA!\r");
	DrivingMA(DramAttr);

	PRINT_DEBUG_MEM("set DCLK!\r");
	DrivingDCLK(DramAttr);
}

/*
ODT	Control	for DQ/DQS/CKE/SCMD/DCLKO in ChA & ChB
which include driving enable/range and strong/weak selection
 
Processing: According to DRAM frequency to ODT control bits.
      		Because function enable bit must be the last one to be set.
      		So the register VIA_NB3DRAM_REGD4 and VIA_NB3DRAM_REGD3 should be
      		the last register	to be programmed.
*/
//-------------------------------------------------------------------------------
//                      ODT Lookup Table
//-------------------------------------------------------------------------------
#define Rank0_ODT				0
#define Rank1_ODT				1
#define Rank2_ODT				2
#define Rank3_ODT				3
#define NA_ODT					0
#define NB_ODT_75ohm			0
#define NB_ODT_150ohm			1

#define DDR2_ODT_75ohm			0x20
#define DDR2_ODT_150ohm			0x40

// Setting of ODT Lookup TBL
//                      RankMAP , Rank 3               Rank 2              Rank 1              Rank 0           , DRAM & NB ODT setting
//                  db  0000b   , Reserved
#define ODTLookup_Tbl_count 8
static const u8 ODTLookup_TBL[ODTLookup_Tbl_count][3] = {
	// 0001b
	{0x01,
	 (Rank3_ODT << 6) + (Rank2_ODT << 4) + (Rank1_ODT << 2) +
	 Rank0_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
	// 0010b        , Reserved
	// 0011b
	{0x03,
	 (Rank3_ODT << 6) + (Rank2_ODT << 4) + (Rank0_ODT << 2) +
	 Rank1_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
	// 0100b
	{0x04,
	 (Rank3_ODT << 6) + (Rank2_ODT << 4) + (Rank1_ODT << 2) +
	 Rank0_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
	// 0101b
	{0x05,
	 (Rank3_ODT << 6) + (Rank0_ODT << 4) + (Rank1_ODT << 2) +
	 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm},
	// 0110b        , Reserved
	// 0111b
	{0x07,
	 (Rank3_ODT << 6) + (Rank0_ODT << 4) + (Rank2_ODT << 2) +
	 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm},
	// 1000b        , Reserved
	// 1001b        , Reserved
	// 1010b        , Reserved
	// 1011b        , Reserved
	// 1100b
	{0x0c,
	 (Rank2_ODT << 6) + (Rank3_ODT << 4) + (Rank1_ODT << 2) +
	 Rank0_ODT, DDR2_ODT_150ohm + NB_ODT_75ohm},
	// 1101b
	{0x0d,
	 (Rank0_ODT << 6) + (Rank0_ODT << 4) + (Rank1_ODT << 2) +
	 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm},
	// 1110b        , Reserved
	// 1111b
	{0x0f,
	 (Rank0_ODT << 6) + (Rank0_ODT << 4) + (Rank2_ODT << 2) +
	 Rank2_ODT, DDR2_ODT_75ohm + NB_ODT_150ohm}
};

#define ODT_Table_Width_DDR2		4
//                                                                                               RxD6   RxD3 
static const u8 ODT_Control_DDR2[ODT_Table_Width_DDR2] = { 0xFC, 0x01 };

void DrivingODT(DRAM_SYS_ATTR * DramAttr)
{
	u8 Data;
	u8 i;
	BOOLEAN bFound;

	pci_write_config8(MEMCTRL, 0xD0, 0x88);

	Data = ODT_Control_DDR2[0];
	pci_write_config8(MEMCTRL, 0xd6, Data);

	Data = ODT_Control_DDR2[1];
	pci_write_config8(MEMCTRL, 0xd3, Data);

	Data = pci_read_config8(MEMCTRL, 0x9e);
	//set MD turn_around wait state
	Data &= 0xCF;		/*clear bit4,5 */
	if (DIMMFREQ_400 == DramAttr->DramFreq)
		Data |= 0x0;
	else if (DIMMFREQ_533 == DramAttr->DramFreq)
		Data |= 0x10;
	else if (DIMMFREQ_667 == DramAttr->DramFreq)
		Data |= 0x20;
	else if (DIMMFREQ_800 == DramAttr->DramFreq)
		Data |= 0x20;
	else
		Data |= 0;
	pci_write_config8(MEMCTRL, 0x9e, Data);

	if (DIMMFREQ_400 == DramAttr->DramFreq)
		Data = 0x0;
	else if (DIMMFREQ_533 == DramAttr->DramFreq)
		Data = 0x11;
	else if (DIMMFREQ_667 == DramAttr->DramFreq)
		Data = 0x11;
	else if (DIMMFREQ_800 == DramAttr->DramFreq)
		Data = 0x11;
	else
		Data = 0;
	pci_write_config8(MEMCTRL, 0x9f, Data);

	/*channel A ODT select */
	if (DramAttr->DimmNumChA > 0) {
		Data = pci_read_config8(MEMCTRL, 0xd5);
		Data &= 0x5F;	/*clear bit7,5 */
		if (DramAttr->RankNumChA > 2)
			Data |= 0xA0;	/*if rank number > 2 (3or4), set bit7,5 */
		else
			Data |= 0x00;	/*if rank number is 1or2, clear bit5 */
		pci_write_config8(MEMCTRL, 0xd5, Data);

		Data = pci_read_config8(MEMCTRL, 0xd7);
		Data &= 0xEF;	/*clear bit7 */
		if (DramAttr->RankNumChA > 2)
			Data |= 0x80;	/*if rank number > 2 (3or4), set bit7 */
		else
			Data |= 0x00;	/*if rank number is 1or2,  clear bit7 */
		pci_write_config8(MEMCTRL, 0xd7, Data);

		/*channel A */
		Data = pci_read_config8(MEMCTRL, 0xd5);
		Data &= 0xF3;	//bit2,3
		if (DramAttr->DimmNumChA == 2)	/*2 Dimm, 3or4 Ranks */
			Data |= 0x00;
		else if (DramAttr->DimmNumChA == 1)
			Data |= 0x04;
		pci_write_config8(MEMCTRL, 0xd5, Data);

		if ((DramAttr->RankPresentMap & 0x0F) != 0) {	/*channel A */
			// MAA ODT Lookup Table
			bFound = FALSE;
			for (i = 0; i < ODTLookup_Tbl_count; i++) {
				if ((DramAttr->RankPresentMap & 0x0F) ==
				    ODTLookup_TBL[i][0]) {
					Data = ODTLookup_TBL[i][1];
					bFound = TRUE;
				}
			}
			if (!bFound) {	/*set default value */
				Data =
				    ODTLookup_TBL[ODTLookup_Tbl_count - 1][1];
			}
			pci_write_config8(MEMCTRL, 0x9c, Data);

			//set CHA MD ODT control State Dynamic-on
			Data = pci_read_config8(MEMCTRL, 0xD4);
			Data &= 0xC9;
			Data |= 0x30;
			pci_write_config8(MEMCTRL, 0xD4, Data);

			Data = pci_read_config8(MEMCTRL, 0x9e);
			Data |= 0x01;
			pci_write_config8(MEMCTRL, 0x9e, Data);
		}

	}
	/*channel B */
	if (1 == ENABLE_CHC) {
		//CHB has not auto compensation mode ,so must set it manual,or else CHB initialization will not successful
		//   Data =0x88;
		//pci_write_config8(MEMCTRL, 0xd0, Data);

		Data = pci_read_config8(MEMCTRL, 0xd5);
		Data &= 0xAF;
		if (DramAttr->RankNumChB > 2)	/*rank number 3 or 4 */
			Data |= 0x50;
		else
			Data |= 0x00;
		pci_write_config8(MEMCTRL, 0xd5, Data);

		Data = pci_read_config8(MEMCTRL, 0xd7);
		Data &= 0xBF;	/*clear bit6 */
		if (DramAttr->RankNumChB > 2)
			Data |= 0x40;	/*if rank number > 2 (3or4), set bit7 */
		else
			Data |= 0x00;	/*if rank number is 1or2,  clear bit7 */
		pci_write_config8(MEMCTRL, 0xd7, Data);

		Data = pci_read_config8(MEMCTRL, 0xd5);
		Data &= 0xFC;
		if (DramAttr->DimmNumChB == 2)	/*2 Dimm, 3or4 Ranks */
			Data |= 0x00;	// 2 dimm RxD5[2,0]=0,0b
		else if (DramAttr->DimmNumChB == 1)
			Data |= 0x01;	// 1 dimm RxD5[2,0]=1,1b
		pci_write_config8(MEMCTRL, 0xd5, Data);

		//set CHB MD ODT control State Dynamic-on
		Data = pci_read_config8(MEMCTRL, 0xD4);
		Data &= 0xF6;
		Data |= 0x08;
		pci_write_config8(MEMCTRL, 0xD4, Data);

		//enable CHB differential DQS input
		Data = pci_read_config8(MEMCTRL, 0x9E);
		Data |= 0x02;
		pci_write_config8(MEMCTRL, 0x9E, Data);
	}
	//enable ODT Control
	Data = pci_read_config8(MEMCTRL, 0x9e);
	Data |= 0x80;
	pci_write_config8(MEMCTRL, 0x9e, Data);
}

void DrivingDQS(DRAM_SYS_ATTR * DramAttr)
{
	u8 Data;

	/*channel A */
	if (DramAttr->RankNumChA > 0) {
		Data = DDR2_DQSA_Driving_Table[DramAttr->RankNumChA - 1];
		pci_write_config8(MEMCTRL, 0xe0, Data);
	}

	/*channel B */
	if (1 == ENABLE_CHC) {
		Data = DDR2_DQSB_Driving_Table[DramAttr->RankNumChB - 1];
		pci_write_config8(MEMCTRL, 0xe1, Data);
	}

}

void DrivingDQ(DRAM_SYS_ATTR * DramAttr)
{
	u8 Data;

	/*channel A */
	if (DramAttr->RankNumChA > 0) {
		Data = DDR2_DQA_Driving_Table[DramAttr->RankNumChA - 1];
		pci_write_config8(MEMCTRL, 0xe2, Data);

	}
	/*channel B */
	if (1 == ENABLE_CHC) {
		Data = DDR2_DQB_Driving_Table[DramAttr->RankNumChB - 1];
		pci_write_config8(MEMCTRL, 0xe3, Data);
	}
}

void DrivingCS(DRAM_SYS_ATTR * DramAttr)
{
	u8 Data;
	/*Channel A */
	if (DramAttr->RankNumChA > 0) {
		Data = DDR2_CSA_Driving_Table_x8[DramAttr->RankNumChA - 1];
		pci_write_config8(MEMCTRL, 0xe4, Data);
	}
	/*channel B */
	if (1 == ENABLE_CHC) {
		Data = DDR2_CSB_Driving_Table_x8[DramAttr->RankNumChB - 1];
		pci_write_config8(MEMCTRL, 0xe5, Data);
	}
}

void DrivingMA(DRAM_SYS_ATTR * DramAttr)
{
	u8 Data;
	u8 i, FreqId;

	if (DramAttr->RankNumChA > 0) {
		if (DIMMFREQ_400 == DramAttr->DramFreq)
			FreqId = 1;
		else if (DIMMFREQ_533 == DramAttr->DramFreq)
			FreqId = 2;
		else if (DIMMFREQ_667 == DramAttr->DramFreq)
			FreqId = 3;
		else if (DIMMFREQ_800 == DramAttr->DramFreq)
			FreqId = 4;
		else
			FreqId = 1;
		for (i = 0; i < MA_Table; i++) {
			if (DramAttr->LoadNumChA <=
			    DDR2_MAA_Driving_Table[i][0]) {
				Data = DDR2_MAA_Driving_Table[i][FreqId];
				break;
			}
		}
		pci_write_config8(MEMCTRL, 0xe8, Data);
	}
	if (1 == ENABLE_CHC) {
		for (i = 0; i < MA_Table; i++) {
			if (DramAttr->LoadNumChA <=
			    DDR2_MAB_Driving_Table[i][0]) {
				Data = DDR2_MAB_Driving_Table[i][1];
				break;
			}
		}
		pci_write_config8(MEMCTRL, 0xe9, Data);
	}
}

void DrivingDCLK(DRAM_SYS_ATTR * DramAttr)
{
	u8 Data;
	u8 FreqId;

	if (DIMMFREQ_400 == DramAttr->DramFreq)
		FreqId = 0;
	else if (DIMMFREQ_533 == DramAttr->DramFreq)
		FreqId = 1;
	else if (DIMMFREQ_667 == DramAttr->DramFreq)
		FreqId = 2;
	else if (DIMMFREQ_800 == DramAttr->DramFreq)
		FreqId = 4;
	else
		FreqId = 0;

	/*channel A */
	if (DramAttr->RankNumChA > 0) {
		Data = DDR2_DCLKA_Driving_Table[FreqId];
		pci_write_config8(MEMCTRL, 0xe6, Data);
	}
	/*channel B */
	if (1 == ENABLE_CHC) {
		Data = DDR2_DCLKB_Driving_Table[FreqId];
		pci_write_config8(MEMCTRL, 0xe7, Data);
	}

}