2 * This file is part of the coreboot project.
4 * Copyright (C) 2005 Nick Barker <nick.barker9@btinternet.com>
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, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 Automatically detect and set up ddr dram on the CLE266 chipset.
23 Assumes DDR memory, though chipset also supports SDRAM
24 Assumes at least 266Mhz memory as no attempt is made to clock
25 the chipset down if slower memory is installed.
27 256 Mb 266Mhz 1 Bank (i.e. single sided)
28 256 Mb 266Mhz 2 Bank (i.e. double sided)
29 512 Mb 266Mhz 2 Bank (i.e. double sided)
31 /* ported and enhanced from assembler level code in coreboot v1 */
34 #include <cpu/x86/mtrr.h>
39 void dimm_read(unsigned long bank,unsigned long x)
42 volatile unsigned long y;
44 y = * (volatile unsigned long *) (x+ bank) ;
50 dumpnorth(device_t north)
53 for(r = 0; r < 256; r += 16) {
56 for(c = 0; c < 16; c++) {
57 print_debug_hex8(pci_read_config8(north, r+c));
63 void print_val(char *str, int val)
66 print_debug_hex8(val);
69 static void ddr_ram_setup(const struct mem_controller *ctrl)
71 device_t north = (device_t) 0;
74 unsigned long bank_address;
76 print_debug("vt8623 init starting\n");
77 north = pci_locate_device(PCI_ID(0x1106, 0x3123), 0);
81 pci_write_config8(north,0x75,0x08);
84 pci_write_config8(north,0x50,0xc8);
85 pci_write_config8(north,0x51,0xde);
86 pci_write_config8(north,0x52,0xcf);
87 pci_write_config8(north,0x53,0x88);
88 pci_write_config8(north,0x55,0x04);
91 DRAM MA Map Type Device 0 Offset 58
93 Determine memory addressing based on the module's memory technology and
94 arrangement. See Table 4-9 of Intel's 82443GX datasheet for details.
96 Bank 1/0 MA map type 58[7-5]
97 Bank 1/0 command rate 58[4]
98 Bank 3/2 MA map type 58[3-1]
99 Bank 3/2 command rate 58[0]
102 Read SPD byte 17, Number of banks on SDRAM device.
105 b = smbus_read_byte(DIMM0,17);
106 print_val("Detecting Memory\nNumber of Banks ",b);
108 if( b != 2 ){ // not 16 Mb type
111 Read SPD byte 3, Number of row addresses.
113 b = smbus_read_byte(DIMM0,3);
114 print_val("\nNumber of Rows ",b);
115 if( b >= 0x0d ){ // not 64/128Mb (rows <=12)
118 Read SPD byte 13, Primary DRAM width.
120 b = smbus_read_byte(DIMM0,13);
121 print_val("\nPriamry DRAM width",b);
122 if( b != 4 ) // mot 64/128Mb (x4)
129 Read SPD byte 4, Number of column addresses.
131 b = smbus_read_byte(DIMM0,4);
132 print_val("\nNo Columns ",b);
133 if( b == 10 || b == 11 ) c |= 0x60; // 10/11 bit col addr
134 if( b == 9 ) c |= 0x40; // 9 bit col addr
135 if( b == 8 ) c |= 0x20; // 8 bit col addr
138 print_val("\nMA type ",c);
139 pci_write_config8(north,0x58,c);
142 DRAM bank size. See 4.3.1 pg 35
144 5a->5d set to end address for each bank. 1 bit == 16MB
147 5c = bank 0 + b1 + b2
148 5d = bank 0 + b1 + b2 + b3
151 // Read SPD byte 31 Module bank density
153 b = smbus_read_byte(DIMM0,31);
154 if( b & 0x02 ) c = 0x80; // 2GB
155 else if( b & 0x01) c = 0x40; // 1GB
156 else if( b & 0x80) c = 0x20; // 512Mb
157 else if( b & 0x40) c = 0x10; // 256Mb
158 else if( b & 0x20) c = 0x08; // 128Mb
159 else if( b & 0x10) c = 0x04; // 64Mb
160 else if( b & 0x08) c = 0x02; // 32Mb
161 else if( b & 0x04) c = 0x01; // 16Mb / 4Gb
162 else c = 0x01; // Error, use default
165 print_val("\nBank 0 (*16 Mb) ",c);
167 // set bank zero size
168 pci_write_config8(north,0x5a,c);
169 // SPD byte 5 # of physical banks
170 b = smbus_read_byte(DIMM0,5);
172 print_val("\nNo Physical Banks ",b);
176 print_val("\nTotal Memory (*16 Mb) ",c);
178 pci_write_config8(north,0x5b,c);
179 pci_write_config8(north,0x5c,c);
180 pci_write_config8(north,0x5d,c);
183 /* Read SPD byte 18 CAS Latency */
184 b = smbus_read_byte(DIMM0,18);
185 print_debug("\nCAS Supported ");
192 print_val("\nCycle time at CL X (nS)",smbus_read_byte(DIMM0,9));
193 print_val("\nCycle time at CL X-0.5 (nS)",smbus_read_byte(DIMM0,23));
194 print_val("\nCycle time at CL X-1 (nS)",smbus_read_byte(DIMM0,25));
197 if( b & 0x10 ){ // DDR offering optional CAS 3
198 print_debug("\nStarting at CAS 3");
200 /* see if we can better it */
201 if( b & 0x08 ){ // DDR mandatory CAS 2.5
202 if( smbus_read_byte(DIMM0,23) <= 0x75 ){ // we can manage 133Mhz at CAS 2.5
203 print_debug("\nWe can do CAS 2.5");
207 if( b & 0x04 ){ // DDR mandatory CAS 2
208 if( smbus_read_byte(DIMM0,25) <= 0x75 ){ // we can manage 133Mhz at CAS 2
209 print_debug("\nWe can do CAS 2");
213 }else{ // no optional CAS values just 2 & 2.5
214 print_debug("\nStarting at CAS 2.5");
215 c = 0x20; // assume CAS 2.5
216 if( b & 0x04){ // Should always happen
217 if( smbus_read_byte(DIMM0,23) <= 0x75){ // we can manage 133Mhz at CAS 2
218 print_debug("\nWe can do CAS 2");
227 DRAM Timing Device 0 Offset 64
230 RAS Pulse width 64[6]
240 Bank Interleave 64[1,0]
243 Determine row pre-charge time (tRP)
254 Read SPD byte 27, min row pre-charge time.
257 b = smbus_read_byte(DIMM0,27);
258 print_val("\ntRP ",b);
259 if( b > 0x3c ) // set tRP = 3T
264 Determine RAS to CAS delay (tRCD)
266 Read SPD byte 29, min row pre-charge time.
269 b = smbus_read_byte(DIMM0,29);
270 print_val("\ntRCD ",b);
271 if( b > 0x3c ) // set tRCD = 3T
275 Determine RAS pulse width (tRAS)
278 Read SPD byte 30, device min active to pre-charge time.
281 b = smbus_read_byte(DIMM0,30);
282 print_val("\ntRAS ",b);
283 if( b > 0x25 ) // set tRAS = 6T
288 Determine bank interleave
290 Read SPD byte 17, Number of banks on SDRAM device.
292 b = smbus_read_byte(DIMM0,17);
293 if( b == 4) c |= 0x02;
294 else if (b == 2) c |= 0x01;
297 /* set DRAM timing for all banks */
298 pci_write_config8(north,0x64,c);
300 /* set DRAM type to DDR */
301 pci_write_config8(north,0x60,0x02);
304 /* DRAM arbitration timer */
305 pci_write_config8(north,0x65,0x32);
309 CPU Frequency Device 0 Offset 54
311 CPU Frequency 54[7,6] bootstraps at 0xc0 (133Mhz)
312 DRAM burst length = 8 54[5]
314 pci_write_config8(north,0x54,0xe0);
318 DRAM Clock Device 0 Offset 69
320 DRAM/CPU speed 69[7,6] (leave at default 00 == CPU)
321 Controller que > 2 69[5]
322 Controller que != 4 69[4]
323 DRAM 8k page size 69[3]
324 DRAM 4k page size 69[2]
325 Multiple page mode 69[0]
328 pci_write_config8(north,0x69,0x2d);
330 /* Delay >= 100ns after DRAM Frequency adjust, See 4.1.1.3 pg 15 */
335 pci_write_config8(north,0x6b,0x10);
338 /* Disable DRAM refresh */
339 pci_write_config8(north,0x6a,0x0);
342 /* Set drive for 1 bank DDR (Table 4.4.2, pg 40) */
343 pci_write_config8(north,0x6d,0x044);
344 pci_write_config8(north,0x67,0x3a);
346 b = smbus_read_byte(DIMM0,5); // SPD byte 5 # of physical banks
348 // Increase drive control when there is more than 1 physical bank
349 pci_write_config8(north,0x6c,0x84); // Drive control: MA, DQS, MD/CKE
350 pci_write_config8(north,0x6d,0x55); // DC: Early clock select, DQM, CS#, MD
352 /* place frame buffer on last bank */
353 if( !b) b++; // make sure at least 1 bank reported
354 pci_write_config8(north,0xe3,b-1);
356 for( bank = 0 , bank_address=0; bank < b ; bank++){
358 DDR init described in Via BIOS Porting Guide. Pg 28 (4.2.3.1)
362 /* NOP command enable */
363 pci_write_config8(north,0x6b,0x11);
365 /* read a double word from any address of the dimm */
366 dimm_read(bank_address,0x1f000);
369 /* All bank precharge Command Enable */
370 pci_write_config8(north,0x6b,0x12);
371 dimm_read(bank_address,0x1f000);
375 pci_write_config8(north,0x6b,0x13);
376 dimm_read(bank_address,0x2000);
378 dimm_read(bank_address,0x800);
381 /* All banks precharge Command Enable */
382 pci_write_config8(north,0x6b,0x12);
383 dimm_read(bank_address,0x1f200);
385 /* CBR Cycle Enable */
386 pci_write_config8(north,0x6b,0x14);
389 dimm_read(bank_address,0x1f300);
391 dimm_read(bank_address,0x1f400);
393 dimm_read(bank_address,0x1f500);
395 dimm_read(bank_address,0x1f600);
397 dimm_read(bank_address,0x1f700);
399 dimm_read(bank_address,0x1f800);
401 dimm_read(bank_address,0x1f900);
403 dimm_read(bank_address,0x1fa00);
407 pci_write_config8(north,0x6b,0x13);
410 Mode Register Definition
411 with adjustement so that address calculation is correct - 64 bit technology, therefore
412 a0-a2 refer to byte within a 64 bit long word, and a3 is the first address line presented
413 to DIMM as a row or column address.
416 MR[6] Burst Type 0 = sequential, 1 = interleaved
417 MR[5-3] burst length 001 = 2, 010 = 4, 011 = 8, others reserved
430 CAS 2 0101011000 = 0x158
431 CAS 2.5 1101011000 = 0x358
432 CAS 3 0111011000 = 0x1d8
435 c = pci_read_config8(north,0x64);
436 if( (c & 0x30) == 0x10 )
437 dimm_read(bank_address,0x150);
438 else if((c & 0x30) == 0x20 )
439 dimm_read(bank_address,0x350);
441 dimm_read(bank_address,0x1d0);
443 //dimm_read(bank_address,0x350);
445 /* Normal SDRAM Mode */
446 pci_write_config8(north,0x6b,0x58 );
449 bank_address = pci_read_config8(north,0x5a+bank) * 0x1000000;
450 } // end of for each bank
452 /* Adjust DQS (data strobe output delay). See 4.2.3.2 pg 29 */
453 pci_write_config8(north,0x66,0x41);
455 /* determine low bond */
457 bank_address = pci_read_config8(north,0x5a) * 0x1000000;
461 for(i = 0 ; i < 0x0ff; i++){
462 c = i ^ (i>>1); // convert to gray code
463 pci_write_config8(north,0x68,c);
465 *(volatile unsigned long*)(0x4000) = 0;
466 *(volatile unsigned long*)(0x4100+bank_address) = 0;
467 *(volatile unsigned long*)(0x4200) = 0;
468 *(volatile unsigned long*)(0x4300+bank_address) = 0;
469 *(volatile unsigned long*)(0x4400) = 0;
470 *(volatile unsigned long*)(0x4500+bank_address) = 0;
474 *(volatile unsigned long*)(0x4000) = 0x12345678;
475 *(volatile unsigned long*)(0x4100+bank_address) = 0x81234567;
476 *(volatile unsigned long*)(0x4200) = 0x78123456;
477 *(volatile unsigned long*)(0x4300+bank_address) = 0x67812345;
478 *(volatile unsigned long*)(0x4400) = 0x56781234;
479 *(volatile unsigned long*)(0x4500+bank_address) = 0x45678123;
482 if( *(volatile unsigned long*)(0x4000) != 0x12345678)
485 if( *(volatile unsigned long*)(0x4100+bank_address) != 0x81234567)
488 if( *(volatile unsigned long*)(0x4200) != 0x78123456)
491 if( *(volatile unsigned long*)(0x4300+bank_address) != 0x67812345)
494 if( *(volatile unsigned long*)(0x4400) != 0x56781234)
497 if( *(volatile unsigned long*)(0x4500+bank_address) != 0x45678123)
500 // if everything verified then found low bond
504 print_val("\nLow Bond ",i);
507 for( ; i <0xff ; i++){
508 pci_write_config8(north,0x68,i ^ (i>>1) );
511 *(volatile unsigned long*)(0x8000) = 0;
512 *(volatile unsigned long*)(0x8100+bank_address) = 0;
513 *(volatile unsigned long*)(0x8200) = 0x0;
514 *(volatile unsigned long*)(0x8300+bank_address) = 0;
515 *(volatile unsigned long*)(0x8400) = 0x0;
516 *(volatile unsigned long*)(0x8500+bank_address) = 0;
519 *(volatile unsigned long*)(0x8000) = 0x12345678;
520 *(volatile unsigned long*)(0x8100+bank_address) = 0x81234567;
521 *(volatile unsigned long*)(0x8200) = 0x78123456;
522 *(volatile unsigned long*)(0x8300+bank_address) = 0x67812345;
523 *(volatile unsigned long*)(0x8400) = 0x56781234;
524 *(volatile unsigned long*)(0x8500+bank_address) = 0x45678123;
527 if( *(volatile unsigned long*)(0x8000) != 0x12345678)
530 if( *(volatile unsigned long*)(0x8100+bank_address) != 0x81234567)
533 if( *(volatile unsigned long*)(0x8200) != 0x78123456)
536 if( *(volatile unsigned long*)(0x8300+bank_address) != 0x67812345)
539 if( *(volatile unsigned long*)(0x8400) != 0x56781234)
542 if( *(volatile unsigned long*)(0x8500+bank_address) != 0x45678123)
546 print_val(" High Bond",i);
547 c = ((i - c)<<1)/3 +c;
548 print_val(" Setting DQS delay",c);
549 c = c ^ (c>>1); // convert to gray code
550 pci_write_config8(north,0x68,c);
551 pci_write_config8(north,0x68,0x42);
553 print_debug("Unable to determine low bond - Setting default\n");
554 pci_write_config8(north,0x68,0x59);
558 pci_write_config8(north,0x66,0x01);
559 pci_write_config8(north,0x55,0x07);
564 DRAM refresh rate Device 0 Offset 6a
566 Units of 16 DRAM clock cycles. (See 4.4.1 pg 39)
568 Rx69 (DRAM freq) Rx58 (chip tech) Rx6a
571 133Mhz 256/512Mb 0x43
573 100Mhz 256/512Mb 0x32
576 b = pci_read_config8(north,0x58);
577 if( b < 0x80 ) // 256 tech
578 pci_write_config8(north,0x6a,0x86);
580 pci_write_config8(north,0x6a,0x43);
582 pci_write_config8(north,0x61,0xff);
583 //pci_write_config8(north,0x67,0x22);
586 pci_write_config8(north,0x70,0x82);
587 pci_write_config8(north,0x73,0x01);
588 pci_write_config8(north,0x76,0x50);
591 pci_write_config8(north,0x71,0xc8);
594 /* graphics aperture base */
596 pci_write_config8(north,0x13,0xd0);
598 //pci_write_config8(north,0xe1,0xdf);
599 //pci_write_config8(north,0xe2,0x42);
600 pci_write_config8(north,0xe0,0x00);
602 pci_write_config8(north,0x84,0x80);
603 pci_write_config16(north,0x80,0x610f);
604 pci_write_config32(north,0x88,0x00000002);
608 pci_write_config8(north,0xa8,0x04);
609 pci_write_config8(north,0xac,0x2f);
610 pci_write_config8(north,0xae,0x04);
612 print_debug("vt8623 done\n");
615 print_debug("AGP\n");
616 north = pci_locate_device(PCI_ID(0x1106, 0xb091), 0);
617 pci_write_config32(north,0x20,0xddf0dc00);
618 pci_write_config32(north,0x24,0xdbf0d800);
619 pci_write_config8(north,0x3e,0x0c);
622 //print_err("VGA\n");
623 //north = pci_locate_device(PCI_ID(0x1106, 0x3122), 0);
624 //pci_write_config32(north,0x10,0xd8000008);
625 //pci_write_config32(north,0x14,0xdc000000);