2 /* This was originally for the e7500, modified for i855pm
6 * memory type (must be ddr)
7 * number of row addresses, not counting bank addresses
8 * number of column addresses
9 * number of so-dimm banks
12 * number banks on each device
14 * that's it. No other bytes are used.
16 * 2, 3, 4, 5, 11, 12 17
19 /* converted to C 6/2004 yhlu */
21 #define DEBUG_RAM_CONFIG 1
22 #define ASM_CONSOLE_LOGLEVEL 9
23 #define dumpnorth() dump_pci_device(PCI_DEV(0, 0, 1))
25 /* DDR DIMM Mode register Definitions */
27 #define BURST_2 (1<<0)
28 #define BURST_4 (2<<0)
29 #define BURST_8 (3<<0)
31 #define BURST_SEQUENTIAL (0<<3)
32 #define BURST_INTERLEAVED (1<<3)
34 #define CAS_2_0 (0x2<<4)
35 #define CAS_3_0 (0x3<<4)
36 #define CAS_1_5 (0x5<<4)
37 #define CAS_2_5 (0x6<<4)
39 #define MODE_NORM (0 << 7)
40 #define MODE_DLL_RESET (2 << 7)
41 #define MODE_TEST (1 << 7)
43 #define BURST_LENGTH BURST_4
44 #define BURST_TYPE BURST_INTERLEAVED
45 #define CAS_LATENCY CAS_2_0
46 //#define CAS_LATENCY CAS_2_5
47 //#define CAS_LATENCY CAS_1_5
49 /* WOW! this could be bad! sets casl to 2 without checking! */
50 #define MRS_VALUE (MODE_NORM | CAS_LATENCY | BURST_TYPE | BURST_LENGTH)
51 #define EMRS_VALUE 0x000
55 #define RAM_COMMAND_NONE 0x0
56 #define RAM_COMMAND_NOP 0x1
57 #define RAM_COMMAND_PRECHARGE 0x2
58 #define RAM_COMMAND_MRS 0x3
59 #define RAM_COMMAND_EMRS 0x4
60 #define RAM_COMMAND_CBR 0x6
61 #define RAM_COMMAND_NORMAL 0x7
64 static inline void do_ram_command (const struct mem_controller *ctrl, uint32_t value) {
69 #if DEBUG_RAM_CONFIG >=2
71 print_debug_hex8(value);
74 /* %ecx - initial address to read from */
75 /* Compute the offset */
79 /* Set the ram command */
80 byte = pci_read_config8(ctrl->d0, 0x70);
82 byte |= (uint8_t)(value & 0xff);
85 print_debug_hex8(byte);
89 pci_write_config8(ctrl->d0, 0x70, byte);
91 /* Assert the command to the memory */
92 #if DEBUG_RAM_CONFIG >= 2
94 print_debug_hex32(dword);
98 result = read32(dword);
101 print_debug("Done\r\n");
103 /* Go to the next base address */
108 /* The command has been sent to all dimms so get out */
111 static inline void RAM_CMD(const struct mem_controller *ctrl, uint32_t command, uint32_t offset) {
112 uint32_t value = ((offset) << (MD_SHIFT + 16))|((command << 4) & 0x70) ;
113 do_ram_command(ctrl, value);
116 #define RAM_NOP(ctrl) RAM_CMD(ctrl, RAM_COMMAND_NOP, 0)
117 #define RAM_PRECHARGE(ctrl) RAM_CMD(ctrl, RAM_COMMAND_PRECHARGE, 0)
118 #define RAM_CBR(ctrl) RAM_CMD(ctrl, RAM_COMMAND_CBR, 0)
119 #define RAM_EMRS(ctrl) RAM_CMD(ctrl, RAM_COMMAND_EMRS, EMRS_VALUE)
121 static const uint8_t ram_cas_latency[] = {
122 CAS_2_5, CAS_2_0, CAS_1_5, CAS_2_5
125 static inline void ram_mrs(const struct mem_controller *ctrl, uint32_t value){
126 /* Read the cas latency setting */
129 byte = pci_read_config8(ctrl->d0, 0x60);
130 /* Transform it into the form expected by SDRAM */
131 dword = ram_cas_latency[(byte>>5) & 1];
132 #warning RAM_MRS -- using BROKEN hard-wired CAS 2.0. FIX ME SOON
133 value |= (dword<<(16+MD_SHIFT));
135 value |= (MODE_NORM | BURST_TYPE | BURST_LENGTH) << (16+MD_SHIFT);
137 do_ram_command(ctrl, value);
140 #define RAM_MRS(ctrl, dll_reset) ram_mrs( ctrl, (dll_reset << (8+MD_SHIFT+ 16)) | ((RAM_COMMAND_MRS <<4)& 0x70) )
142 static void RAM_NORMAL(const struct mem_controller *ctrl) {
144 byte = pci_read_config8(ctrl->d0, 0x70);
146 byte |= (RAM_COMMAND_NORMAL << 4);
147 pci_write_config8(ctrl->d0, 0x70, byte);
150 static void RAM_RESET_DDR_PTR(const struct mem_controller *ctrl) {
152 byte = pci_read_config8(ctrl->d0, 0x88);
154 pci_write_config8(ctrl->d0, 0x88, byte);
155 byte = pci_read_config8(ctrl->d0, 0x88);
157 pci_write_config8(ctrl->d0, 0x88, byte);
160 static void ENABLE_REFRESH(const struct mem_controller *ctrl)
163 dword = pci_read_config32(ctrl->d0, 0x70);
165 pci_write_config32(ctrl->d0, 0x70, dword);
169 * Table: constant_register_values
171 static const long register_values[] = {
172 /* DRB - DRAM Row Boundary Registers
174 * An array of 8 byte registers, which hold the ending
175 * memory address assigned to each pair of DIMMS, in 32MB
178 /* Conservatively say each row has 32MB of ram, we will fix this up later */
179 0x40, 0x00000000, (0x01 << 0) | (0x02 << 8) | (0x03 << 16) | (0x04 << 24),
180 /* DRA - DRAM Row Attribute Register
183 * [2:0] Row Attributes for both rows
190 /* leave it alone for now -- seems bad to set it at all
192 (((0<<3)|(0<<0))<< 0) |
193 (((0<<3)|(0<<0))<< 4) |
194 (((0<<3)|(0<<0))<< 8) |
195 (((0<<3)|(0<<0))<<12) |
196 (((0<<3)|(0<<0))<<16) |
197 (((0<<3)|(0<<0))<<20) |
198 (((0<<3)|(0<<0))<<24) |
199 (((0<<3)|(0<<0))<<28),
201 /* DRT - DRAM Time Register
203 * [31:31] tWTR -- MBZ
204 * [30:30] tWR 0 is 2, 1 is 3 clocks
205 * [29:28] back to back write-read commands spacing
207 * 00 4, 01 3, 10 2, 11 reserved
209 * [27:26] same or different
210 * CL + .5x BL + TA(RD-WR) - DQSS
212 * 00 7, 01 6, 10 5, 11 4
213 * 00 4, 01 3, 10 2, 11 reserved
215 * [25:25] Back to Back Read-read spacing
221 * [14:12] Refresh cycle time
222 * 000 14, 001 13, 010 12, 011 11, 100 10, 101 9, 110 8, 111 7
225 * 0 120 us, 1 reserved
227 * [10:09] Active to Precharge (tRAS)
233 * [06:05] Cas Latency (tCL)
235 * 01 == 2.0 Clocks (default)
239 * [03:02] Ras# to Cas# Delay (tRCD)
240 * 00 == 4 DRAM Clocks
241 * 01 == 3 DRAM Clocks
242 * 10 == 2 DRAM Clocks
244 * [01:00] DRAM RAS# to Precharge (tRP)
245 * 00 == 4 DRAM Clocks
246 * 01 == 3 DRAM Clocks
247 * 10 == 2 DRAM Clocks
251 #define DRT_CAS_2_5 (0<<5)
252 #define DRT_CAS_2_0 (1<<5)
253 #define DRT_CAS_MASK (3<<5)
255 #if CAS_LATENCY == CAS_2_5
256 #define DRT_CL DRT_CAS_2_5
257 #elif CAS_LATENCY == CAS_2_0
258 #define DRT_CL DRT_CAS_2_0
261 /* bios is 0x2a004425 */
262 /* default hardware is 18004425 */
263 /* no setting for now */
265 /* FDHC - Fixed DRAM Hole Control
268 * 0 == No memory Hole
269 * 1 == Memory Hole from 15MB to 16MB
272 * PAM - Programmable Attribute Map
273 * 0x90 [3:0] Reserved
274 * 0x90 [5:4] 0xF0000 - 0xFFFFF
275 * 0x91 [1:0] 0xC0000 - 0xC3FFF
276 * 0x91 [5:4] 0xC4000 - 0xC7FFF
277 * 0x92 [1:0] 0xC8000 - 0xCBFFF
278 * 0x92 [5:4] 0xCC000 - 0xCFFFF
279 * 0x93 [1:0] 0xD0000 - 0xD3FFF
280 * 0x93 [5:4] 0xD4000 - 0xD7FFF
281 * 0x94 [1:0] 0xD8000 - 0xDBFFF
282 * 0x94 [5:4] 0xDC000 - 0xDFFFF
283 * 0x95 [1:0] 0xE0000 - 0xE3FFF
284 * 0x95 [5:4] 0xE4000 - 0xE7FFF
285 * 0x96 [1:0] 0xE8000 - 0xEBFFF
286 * 0x96 [5:4] 0xEC000 - 0xEFFFF
287 * 00 == DRAM Disabled (All Access go to memory mapped I/O space)
288 * 01 == Read Only (Reads to DRAM, Writes to memory mapped I/O space)
289 * 10 == Write Only (Writes to DRAM, Reads to memory mapped I/O space)
290 * 11 == Normal (All Access go to DRAM)
292 // 0x90, 0xcccccf7f, (0x00 << 0) | (0x30 << 8) | (0x33 << 16) | (0x33 << 24),
293 //0x94, 0xcccccccc, (0x33 << 0) | (0x33 << 8) | (0x33 << 16) | (0x33 << 24),
296 /* FIXME why was I attempting to set a reserved bit? */
299 /* DRC - DRAM Contoller Mode Register
302 * [29:29] Initialization Complete
305 * [28:27] Dynamic Power Down Enable (leave at 0 for now)
307 * [23:23] Reduced Comamnd Drive Delay (leave at 0 for now)
308 * [22:22] Reduced Command Drive Enable (leave at 0 for now)
309 * [21:21] DRAM Data Integrity Mode
310 * 0 == Disabled, no ECC
311 * 1 == Error checking, with correction
315 * [17:17] (Intel Undocumented) should always be set to
316 * [16:16] Disable SCK Tri-state in C3/S1-m
320 * [13:13] Dynamic CS Disable
321 * [12:12] SM Interface Tristate enable
323 * [10:08] Refresh mode select
324 * 000 == Refresh disabled
325 * 001 == Refresh interval 15.6 usec
326 * 010 == Refresh interval 7.8 usec
327 * 011 == Refresh interval 64 usec
330 * [06:04] Mode Select (SMS)
331 * 000 == Self Refresh Mode
333 * 010 == All Banks Precharge
334 * 011 == Mode Register Set
335 * 100 == Extended Mode Register Set
338 * 111 == Normal Operation
340 * [00:00] DRAM type --hardwired to 1 to indicate DDR
343 /* undocumnted shit */
350 * Routine: ram_set_registers
353 * Trashed: %eax, %ebx, %ecx, %edx, %esi, %eflags
354 * Effects: Do basic ram setup that does not depend on serial
355 * presence detect information.
356 * This sets PCI configuration registers to known good
357 * values based on the table:
358 * constant_register_values
359 * Which are a triple of configuration regiser, mask, and value.
363 static void write_8dwords(uint32_t src_addr, uint32_t dst_addr) {
367 dword = read32(src_addr);
368 write32(dst_addr, dword);
375 //#define SLOW_DOWN_IO inb(0x80);
376 #define SLOW_DOWN_IO udelay(40);
379 static void ram_set_d0f0_regs(const struct mem_controller *ctrl) {
385 max = sizeof(register_values)/sizeof(register_values[0]);
386 for(i = 0; i < max; i += 3) {
389 print_debug_hex32(register_values[i]);
391 print_debug_hex32(register_values[i+2]);
394 reg = pci_read_config32(ctrl->d0,register_values[i]);
395 reg &= register_values[i+1];
396 reg |= register_values[i+2] & ~(register_values[i+1]);
397 pci_write_config32(ctrl->d0,register_values[i], reg);
405 static void sdram_set_registers(const struct mem_controller *ctrl){
406 ram_set_d0f0_regs(ctrl);
411 * Routine: sdram_spd_get_page_size
412 * Arguments: %bl SMBUS_MEM_DEVICE
414 * %edi log base 2 page size of DIMM side 1 in bits
415 * %esi log base 2 page size of DIMM side 2 in bits
417 * Preserved: %ebx (except %bh), %ebp
419 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
420 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
422 * Effects: Uses serial presence detect to set %edi & %esi
423 * to the page size of a dimm.
425 * %bl SMBUS_MEM_DEVICE
426 * %edi holds the page size for the first side of the DIMM.
427 * %esi holds the page size for the second side of the DIMM.
428 * memory size is represent as a power of 2.
430 * This routine may be worth moving into generic code somewhere.
432 struct dimm_page_size {
437 static struct dimm_page_size sdram_spd_get_page_size(unsigned device) {
441 struct dimm_page_size pgsz;
446 value = spd_read_byte(device, 4); /* columns */
447 if(value < 0) goto hw_err;
448 pgsz.side1 = value & 0xf;
450 /* Get the module data width and convert it to a power of two */
451 value = spd_read_byte(device,7); /* (high byte) */
452 if(value < 0) goto hw_err;
456 value = spd_read_byte(device, 6); /* (low byte) */
457 if(value < 0) goto hw_err;
458 ecx |= (value & 0xff);
460 pgsz.side1 += log2(ecx); /* compute cheap log base 2 */
463 value = spd_read_byte(device, 5); /* number of physical banks */
464 if(value < 0) goto hw_err;
465 if(value==1) goto out;
466 if(value!=2) goto val_err;
468 /* Start with the symmetrical case */
469 pgsz.side2 = pgsz.side1;
470 value = spd_read_byte(device,4); /* columns */
471 if(value < 0) goto hw_err;
472 if((value & 0xf0)==0 ) goto out;
473 pgsz.side2 -=value & 0xf; /* Subtract out columns on side 1 */
474 pgsz.side2 +=(value>>4)& 0xf; /* Add in columns on side 2 */
478 die("Bad SPD value\r\n");
479 /* If an hw_error occurs report that I have no memory */
489 * Routine: sdram_spd_get_width
490 * Arguments: %bl SMBUS_MEM_DEVICE
492 * %edi width of SDRAM chips on DIMM side 1 in bits
493 * %esi width of SDRAM chips on DIMM side 2 in bits
495 * Preserved: %ebx (except %bh), %ebp
497 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
498 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
500 * Effects: Uses serial presence detect to set %edi & %esi
501 * to the width of a dimm.
503 * %bl SMBUS_MEM_DEVICE
504 * %edi holds the width for the first side of the DIMM.
505 * %esi holds the width for the second side of the DIMM.
506 * memory size is represent as a power of 2.
508 * This routine may be worth moving into generic code somewhere.
515 static struct dimm_width sdram_spd_get_width(unsigned device) {
517 struct dimm_width wd;
523 value = spd_read_byte(device, 13); /* sdram width */
524 if(value < 0 ) goto hw_err;
527 wd.side1 = value & 0x7f;
530 value = spd_read_byte(device, 5); /* number of physical banks */
531 if(value < 0 ) goto hw_err;
532 if(value <=1 ) goto out;
534 /* Start with the symmetrical case */
537 if((ecx & 0x80)==0) goto out;
549 * Routine: sdram_spd_get_dimm_size
550 * Arguments: %bl SMBUS_MEM_DEVICE
552 * %edi log base 2 size of DIMM side 1 in bits
553 * %esi log base 2 size of DIMM side 2 in bits
555 * Preserved: %ebx (except %bh), %ebp
557 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
558 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
560 * Effects: Uses serial presence detect to set %edi & %esi
561 * the size of a dimm.
563 * %bl SMBUS_MEM_DEVICE
564 * %edi holds the memory size for the first side of the DIMM.
565 * %esi holds the memory size for the second side of the DIMM.
566 * memory size is represent as a power of 2.
568 * This routine may be worth moving into generic code somewhere.
576 static struct dimm_size spd_get_dimm_size(unsigned device)
578 /* Calculate the log base 2 size of a DIMM in bits */
584 /* Note it might be easier to use byte 31 here, it has the DIMM size as
585 * a multiple of 4MB. The way we do it now we can size both
586 * sides of an assymetric dimm.
588 /* the hell with that! just use byte 31 -- rgm */
589 value = spd_read_byte(device, 31); /* size * 4 MB */
591 /* this is in 4 MB chunks, or 32 MBits chunks.
592 * log base 2 of 32 Mbits is log2 of (32*1024*1024) is 25
599 print_debug("returned size log 2 in bits is :");
600 print_debug_hex32(value);
605 value = spd_read_byte(device, 3); /* rows */
606 if (value < 0) goto hw_err;
607 // if ((value & 0xf) == 0) goto val_err;
608 sz.side1 += value & 0xf;
610 value = spd_read_byte(device, 4); /* columns */
611 if (value < 0) goto hw_err;
612 // if ((value & 0xf) == 0) goto val_err;
613 sz.side1 += value & 0xf;
615 value = spd_read_byte(device, 17); /* banks */
616 if (value < 0) goto hw_err;
617 // if ((value & 0xff) == 0) goto val_err;
619 sz.side1 += log2(value);
621 /* Get the module data width and convert it to a power of two */
622 value = spd_read_byte(device, 7); /* (high byte) */
623 if (value < 0) goto hw_err;
627 low = spd_read_byte(device, 6); /* (low byte) */
628 if (low < 0) goto hw_err;
629 value |= (low & 0xff);
630 // if ((value != 72) && (value != 64)) goto val_err;
631 sz.side1 += log2(value);
634 value = spd_read_byte(device, 5); /* number of physical banks */
635 if (value < 0) goto hw_err;
636 if (value == 1) goto out;
637 // if (value != 2) goto val_err;
639 /* Start with the symmetrical case */
642 value = spd_read_byte(device, 3); /* rows */
643 if (value < 0) goto hw_err;
644 if ((value & 0xf0) == 0) goto out; /* If symmetrical we are done */
645 sz.side2 -= (value & 0x0f); /* Subtract out rows on side 1 */
646 sz.side2 += ((value >> 4) & 0x0f); /* Add in rows on side 2 */
648 value = spd_read_byte(device, 4); /* columns */
649 if (value < 0) goto hw_err;
650 // if ((value & 0xff) == 0) goto val_err;
651 sz.side2 -= (value & 0x0f); /* Subtract out columns on side 1 */
652 sz.side2 += ((value >> 4) & 0x0f); /* Add in columsn on side 2 */
657 die("Bad SPD value\r\n");
658 /* If an hw_error occurs report that I have no memory */
669 * This is a place holder fill this out
670 * Routine: spd_set_row_attributes
671 * Arguments: %bl SMBUS_MEM_DEVICE
673 * %edi log base 2 size of DIMM side 1 in bits
674 * %esi log base 2 size of DIMM side 2 in bits
676 * Preserved: %ebx (except %bh), %ebp
678 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
679 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
681 * Effects: Uses serial presence detect to set %edi & %esi
682 * the size of a dimm.
684 * %bl SMBUS_MEM_DEVICE
685 * %edi holds the memory size for the first side of the DIMM.
686 * %esi holds the memory size for the second side of the DIMM.
687 * memory size is represent as a power of 2.
689 * This routine may be worth moving into generic code somewhere.
691 static long spd_set_row_attributes(const struct mem_controller *ctrl, long dimm_mask) {
693 uint16_t word=0x7777;
697 /* Walk through all dimms and find the interesection of the support
698 * for ecc sdram and refresh rates
702 for(i = 0; i < DIMM_SOCKETS; i++) {
703 if (!(dimm_mask & (1 << i))) {
706 /* Test to see if I have ecc sdram */
707 struct dimm_page_size sz;
708 sz = sdram_spd_get_page_size(ctrl->channel0[i]); /* SDRAM type */
710 print_debug("page size =");
711 print_debug_hex32(sz.side1);
713 print_debug_hex32(sz.side2);
717 /* Test to see if the dimm is present */
720 /* Test for a valid dimm width */
721 if((sz.side1 <15) || (sz.side1>18) ) {
722 print_err("unsupported page size\r\n");
725 /* Convert to the format needed for the DRA register */
726 /* subtract 3 (there are 8 bytes)
728 * (since 12 bit size should map to a value of 1)
729 * so subtract 14 total
733 /* Place in the %ebp the dra place holder */ //i
735 word |= sz.side1<<(i<<3);
737 /* Test to see if the second side is present */
741 /* Test for a valid dimm width */
742 if((sz.side2 <15) || (sz.side2>18) ) {
743 print_err("unsupported page size\r\n");
746 /* Convert to the format needed for the DRA register */
749 /* Place in the %ebp the dra place holder */ //i
751 word |= sz.side2<<((i<<3) + 4 );
755 /* go to the next DIMM */
758 /* Write the new row attributes register */
759 pci_write_config32(ctrl->d0, 0x50, word);
766 * Routine: sdram_read_paired_byte
767 * Arguments: %esp return address
768 * %bl device on the smbus to read from
769 * %bh address on the smbus to read
777 * Preserved: %ebx, %esi, %edi
779 * Trashed: %eax, %ecx, %edx, %ebp, %esp, %eflags
780 * Used: %eax, %ebx, %ecx, %edx, %esp, %eflags
782 * Effects: Reads two spd bytes from both ram channesl
783 * and errors if they are not equal.
784 * It then returns the equal result.
786 static spd_read_paired_byte () {
788 CALLSP(smbus_read_byte)
791 addb $(SMBUS_MEM_CHANNEL_OFF), %bl
792 CALLSP(smbus_read_byte)
795 subb $(SMBUS_MEM_CHANNEL_OFF), %bl
797 /* See if dimms on both sides are equally present */
799 jne sdram_presence_mismatch
801 /* Leave if I have no data */
803 jz spd_verify_byte_out
805 /* Verify the data is identical */
807 jne sdram_value_mismatch
809 /* Clear the zero flag */
817 * Routine: spd_verify_dimms
821 * Trashed: %eax, %ebx, %ecx, %edx, %ebp, %esi, %edi, %esp, %eflags
822 * Used: %eax, %ebx, %ecx, %edx, %ebp, %esi, %edi, %esp, %eflags
825 * - Verify all interesting spd information
826 * matches for both dimm channels.
827 * - Additional error checks that can be easily done
828 * here are computed as well, so I don't need to
829 * worry about them later.
831 static spd_verify_dimms() {
832 movl $(SMBUS_MEM_DEVICE_START), %ebx
834 /* Verify this is DDR SDRAM */
836 CALLSP(spd_read_paired_byte)
837 jz spd_verify_next_dimm
839 jne invalid_dimm_type
841 /* Verify the row addresses */
843 CALLSP(spd_read_paired_byte)
848 /* Column addresses */
850 CALLSP(spd_read_paired_byte)
857 CALLSP(spd_read_paired_byte)
864 /* Module Data Width */
866 CALLSP(spd_read_paired_byte)
872 CALLSP(spd_read_paired_byte)
878 jmp spd_unsupported_data
881 /* Cycle time at highest CAS latency CL=X */
883 CALLSP(spd_read_paired_byte)
888 CALLSP(spd_read_paired_byte)
891 /* Refresh Interval */
893 CALLSP(spd_read_paired_byte)
898 CALLSP(spd_read_paired_byte)
905 jmp spd_unsupported_data
908 /* Back-to-Back Random Column Accesses */
910 CALLSP(spd_read_paired_byte)
915 ja spd_unsupported_data
919 CALLSP(spd_read_paired_byte)
922 jz spd_unsupported_data
926 CALLSP(spd_read_paired_byte)
931 /* Supported CAS Latencies */
933 CALLSP(spd_read_paired_byte)
935 testb $(1 << 1), %al /* CL 1.5 */
937 testb $(1 << 2), %al /* CL 2.0 */
939 testb $(1 << 3), %al /* CL 2.5 */
941 jmp spd_unsupported_data
944 /* Cycle time at Cas Latency (CLX - 0.5) */
946 CALLSP(spd_read_paired_byte)
949 /* Cycle time at Cas Latency (CLX - 1.0) */
951 CALLSP(spd_read_paired_byte)
954 /* tRP Row precharge time */
956 CALLSP(spd_read_paired_byte)
962 /* tRCD RAS to CAS */
964 CALLSP(spd_read_paired_byte)
969 /* tRAS Activate to Precharge */
971 CALLSP(spd_read_paired_byte)
976 /* Module Bank Density */
978 CALLSP(spd_read_paired_byte)
980 testb $(1<<2), %al /* 16MB */
981 jnz spd_unsupported_data
983 jnz spd_unsupported_data /* 32MB */
985 /* Address and Command Hold Time After Clock */
987 CALLSP(spd_read_paired_byte)
990 spd_verify_next_dimm:
991 /* go to the next DIMM */
992 addb $(SMBUS_MEM_DEVICE_INC), %bl /* increment the smbus device */
993 cmpb $SMBUS_MEM_DEVICE_END, %bl
995 spd_verify_dimms_out:
996 RET_LABEL(spd_verify_dimms)
999 #define spd_pre_init "Reading SPD data...\r\n"
1000 #define spd_pre_set "setting based on SPD data...\r\n"
1001 #define spd_post_init "done\r\n"
1004 static const uint32_t refresh_rate_rank[]= {
1005 /* Refresh rates ordered from most conservative (lowest)
1006 * to most agressive (highest)
1007 * disabled 0 -> rank 3
1008 * 15.6usec 1 -> rank 1
1009 * 7.8 usec 2 -> rank 0
1010 * 64usec 3 -> rank 2
1013 static const uint32_t refresh_rate_index[] = {
1014 /* Map the spd refresh rates to memory controller settings
1015 * 15.625us -> 15.6us
1024 #define MAX_SPD_REFRESH_RATE 5
1026 static long spd_set_dram_controller_mode (const struct mem_controller *ctrl, long dimm_mask) {
1033 /* on this chipset we only do refresh "slow" or "fast" for now */
1034 /* we start out assuming "slow" (15.6 microseconds) */
1035 uint32_t refrate = 1; /* better than 7.8 */
1037 /* Read the inititial state */
1038 dword = pci_read_config32(ctrl->d0, 0x70);
1041 #if 0 // DEBUG_RAM_CONFIG
1042 print_debug("spd_detect_dimms: 0x70.l is:");
1043 print_debug_hex32(dword);
1044 print_debug("\r\n");
1048 /* Test if ECC cmos option is enabled */
1049 movb $RTC_BOOT_BYTE, %al
1054 /* Clear the ecc enable */
1055 andl $~(3 << 20), %esi
1060 /* Walk through all dimms and find the interesection of the support
1061 * for ecc sdram and refresh rates
1065 for(i = 0; i < DIMM_SOCKETS; i++) {
1066 if (!(dimm_mask & (1 << i))) {
1069 /* Test to see if I have ecc sdram */
1070 value = spd_read_byte(ctrl->channel0[i], 11); /* SDRAM type */
1071 if(value < 0) continue;
1073 #if DEBUG_RAM_CONFIG
1074 print_debug("spd_detect_dimms:\r\n");
1076 /* Clear the ecc enable */
1077 dword &= ~(3 << 20);
1078 #if 0 &&DEBUG_RAM_CONFIG
1079 print_debug("spd_detect_dimms: no ecc so set:");
1080 print_debug_hex32(dword);
1081 print_debug("\r\n");
1085 value = spd_read_byte(ctrl->channel0[i], 12); /* SDRAM refresh rate */
1086 if(value < 0 ) continue;
1088 if(value > MAX_SPD_REFRESH_RATE) { print_err("unsupported refresh rate\r\n");}
1089 // if(value == 0xff) { print_err("unsupported refresh rate\r\n");}
1091 #if DEBUG_RAM_CONFIG
1092 print_debug("spd_detect_dimms: ref rate index:");
1093 print_debug_hex8(value);
1094 print_debug("\r\n");
1096 if (value == 2) /* have to go faster */
1098 #if 0 &&DEBUG_RAM_CONFIG
1099 print_debug("spd_detect_dimms: dword is now w/refresh:");
1100 print_debug_hex32(dword);
1101 print_debug("\r\n");
1103 /* no applicability here but there are similar things
1107 value = spd_read_byte(ctrl->channel0[i], 33); /* Address and command hold time after clock */
1108 if(value < 0) continue;
1109 if(value >= 0xa0) { /* At 133Mhz this constant should be 0x75 */
1110 dword &= ~(1<<16); /* Use two clock cyles instead of one */
1114 /* go to the next DIMM */
1117 /* set the refrate now */
1118 dword |= (refrate << 7);
1119 /* Now write the controller mode */
1120 pci_write_config32(ctrl->d0, 0x70, dword);
1125 static long spd_enable_clocks(const struct mem_controller *ctrl, long dimm_mask)
1131 /* Read the inititial state */
1132 dword = pci_read_config32(ctrl->d0, 0x8c);
1134 # Intel clears top bit here, should we?
1135 # No the default is on and for normal timming it should be on. Tom Z
1140 for(i = 0; i < DIMM_SOCKETS; i++) {
1141 if (!(dimm_mask & (1 << i))) {
1144 /* Read any spd byte to see if the dimm is present */
1145 value = spd_read_byte(ctrl->channel0[i], 5); /* Physical Banks */
1146 if(value < 0) continue;
1151 pci_write_config32(ctrl->d0, 0x8c, dword);
1156 static const uint16_t cas_latency_80[] = {
1157 /* For cas latency 2.0 0x01 works and until I see a large test sample
1158 * I am not prepared to change this value, to the intel recommended value
1159 * of 0x0d. Eric Biederman
1161 /* The E7501 requires b1 rather than 01 for CAS2 or memory will be hosed
1162 * CAS 1.5 is claimed to be unsupported, will try to test that
1163 * will need to determine correct values for other CAS values
1164 * (perhaps b5, b1, b6?)
1165 * Steven James 02/06/2003
1168 //# .byte 0x05, 0x01, 0x06
1169 //# .byte 0xb5, 0xb1, 0xb6
1170 0x0, 0x0bb1, 0x0662 /* RCVEN */
1172 static const uint16_t cas_latency_80_4dimms[] = {
1177 static const uint8_t cas_latency_78[] = {
1178 DRT_CAS_2_0, DRT_CAS_2_5
1181 static long spd_set_cas_latency(const struct mem_controller *ctrl, long dimm_mask) {
1182 /* Walk through all dimms and find the interesection of the
1183 * supported cas latencies.
1186 /* Initially allow cas latencies 2.5, 2.0
1187 * which the chipset supports.
1189 uint32_t dword = (1<<3)| (1<<2);// esi
1198 for(i = 0; i < DIMM_SOCKETS; i++) {
1199 if (!(dimm_mask & (1 << i))) {
1202 value = spd_read_byte(ctrl->channel0[i], 18);
1203 if(value < 0) continue;
1204 /* Find the highest supported cas latency */
1205 ecx = log2(value & 0xff);
1208 /* Remember the supported cas latencies */
1209 ecx = (value & 0xff);
1211 /* Verify each cas latency at 133Mhz */
1212 /* Verify slowest/highest CAS latency */
1213 value = spd_read_byte(ctrl->channel0[i], 9);
1214 if(value < 0 ) continue;
1216 /* The bus is too fast so we cannot support this case latency */
1220 /* Verify the highest CAS latency - 0.5 clocks */
1223 value = spd_read_byte(ctrl->channel0[i], 23);
1224 if(value < 0 ) continue;
1226 /* The bus is too fast so we cannot support this cas latency */
1231 /* Verify the highest CAS latency - 1.0 clocks */
1234 value = spd_read_byte(ctrl->channel0[i], 25);
1235 if(value < 0 ) continue;
1237 /* The bus is too fast so we cannot support this cas latency */
1242 /* Now find which cas latencies are supported for the bus */
1244 /* go to the next DIMM */
1247 /* After all of the arduous calculation setup with the fastest
1248 * cas latency I can use.
1250 value = __builtin_bsf(dword); // bsrl = log2 how about bsfl?
1251 if(value ==0 ) return -1;
1254 byte = pci_read_config8(ctrl->d0, 0x78);
1255 byte &= ~(DRT_CAS_MASK);
1256 byte |= cas_latency_78[ecx];
1257 pci_write_config8(ctrl->d0,0x78, byte);
1259 /* set master DLL reset */
1260 dword = pci_read_config32(ctrl->d0, 0x88);
1263 /* the rest of the references are words */
1264 // ecx<<=1; // don't need shift left, because we already define that in u16 array
1265 pci_write_config32(ctrl->d0, 0x88, dword);
1268 dword &= 0x0c0000ff; /* patch try register 88 is undocumented tnz */
1269 dword |= 0xd2109800;
1271 pci_write_config32(ctrl->d0, 0x88, dword);
1273 word = pci_read_config16(ctrl->d0, 0x80);
1275 word |= cas_latency_80[ecx];
1277 dword = pci_read_config32(ctrl->d0, 0x70);
1279 if((dword & 0xff) !=0 ) {
1281 if((dword & 0xff)!=0) {
1283 if((dword & 0xff)!=0) {
1285 if( (dword & 0xff)!=0) {
1286 word &=~(0x0fff); /* we have dimms in all 4 slots */
1287 word |=cas_latency_80_4dimms[ecx];
1293 pci_write_config16(ctrl->d0, 0x80, word);
1295 dword = pci_read_config32(ctrl->d0, 0x88); /* reset master DLL reset */
1297 pci_write_config32(ctrl->d0, 0x88, dword);
1299 RAM_RESET_DDR_PTR(ctrl);
1305 static const unsigned int bustimings[8] = {
1306 /* first four are for GM part */
1308 /* and then the GME part */
1312 static long spd_set_dram_timing(const struct mem_controller *ctrl, long dimm_mask) {
1313 /* Walk through all dimms and find the interesection of the
1314 * supported dram timings.
1321 /* well, shit. Intel has not seen fit to document the observed
1322 * setting for these bits. On my chipset it is 3 right now, and
1323 * that's not in the table documented for this chip.
1324 * What a shame. We will assume 133 mhz I guess? not sure.
1325 * also they say in one place it is two bits and in another
1326 * they say it is 3 bits! we'll assume two bits, that's
1327 * the only one that makes sense.
1329 uint32_t rambusfrequency;
1332 /* what kind of chip is it? */
1333 /* only bit that really matters is high order bit ... */
1334 /* here is a problem with the memory controller struct ...
1335 * ram control is spread across d0/d1 on this part!
1337 ramindex = pci_read_config8(PCI_DEV(0,0,0), 0x44);
1340 /* compute the index into the table. Use the type of chip
1341 * as the high order bit and the 0:0.3:c0 & 7 as the low
1345 ramindex |= pci_read_config8(PCI_DEV(0,0,3), 0xc0) & 7;
1346 /* we now have an index into the clock rate table ... */
1348 rambusfrequency = bustimings[ramindex];
1350 /* Read the inititial state */
1351 dword = pci_read_config32(ctrl->d0, 0x60);
1352 #if DEBUG_RAM_CONFIG >= 10
1353 print_debug("spd_detect_dimms: bus timing index: ");
1354 print_debug_hex32(ramindex);
1355 print_debug(" and speed ");
1356 print_debug_hex32(rambusfrequency);
1357 print_debug("\r\n");
1360 /* for now, since we are on deadline, set to "known good" and
1363 pci_write_config32(ctrl->d0, 0x60, 0x2a004425);
1367 # Intel clears top bit here, should we?
1368 # No the default is on and for normal timming it should be on. Tom Z
1373 // HERE. WHat's the frequency kenneth?
1374 for(i = 0; i < DIMM_SOCKETS; i++) {
1375 if (!(dimm_mask & (1 << i))) {
1379 value = spd_read_byte(ctrl->channel0[i], 27);
1380 if(value < 0) continue;
1381 if(value > (15<<2)) {
1382 /* At 133Mhz if row precharge time is above than 15ns than we
1383 * need 3 clocks not 2 clocks.
1388 value = spd_read_byte(ctrl->channel0[i],29);
1389 if(value < 0 ) continue;
1390 if(value > (15<<2)) {
1391 /* At 133Mhz if the Minimum ras to cas delay is about 15ns we
1392 * need 3 clocks not 2 clocks.
1394 dword &= ~((1<<3)|(1<<1));
1397 value = spd_read_byte(ctrl->channel0[i],30);
1398 if(value < 0 ) continue;
1399 /* Convert tRAS from ns to 133Mhz clock cycles */
1400 value <<=1; /* mult by 2 to make 7.5 15 */
1401 value += 15; /* Make certain we round up */
1403 value &= 0xff; /* Clear the upper bits of eax */
1406 /* Don't even process small timings */
1409 /* Die if the value is to large */
1411 die ("unsupported_rcd\r\n");
1413 /* Convert to clocks - 5 */
1415 /* Convert the existing value into clocks - 5 */
1416 tmp = (~((dword>>9) & 3) - 1) & 3;
1417 /* See if we need a slower timing */
1419 /* O.k. put in our slower timing */
1421 dword |= ((~(value + 1)) & 3)<<9 ;
1426 /* Set to a 7 clock read delay. This is for 133Mhz
1427 * with a CAS latency of 2.5 if 2.0 a 6 clock
1429 if( (pci_read_config8(ctrl->d0, 0x78) & 0x30) ==0 ){
1430 dword &= ~(7<<24); /* CAS latency is 2.5, make 7 clks */
1434 * Back to Back Read Turn Around
1436 /* Set to a 3 clock back to back read turn around. This
1437 * is good for CAS latencys 2.5 and 2.0 */
1440 * Back to Back Read-Write Turn Around
1442 /* Set to a 5 clock back to back read to write turn around.
1443 * 4 is a good delay if the CAS latency is 2.0 */
1444 if( ( pci_read_config8(ctrl->d0, 0x78) & (1<<4)) == 0) {
1448 * Back to Back Write-Read Turn Around
1450 /* Set to a 2 clock back to back write to read turn around.
1451 * This is good for 2.5 and 2.0 CAS Latencies. */
1455 pci_write_config32(ctrl->d0, 0x60, dword);
1460 static unsigned int spd_detect_dimms(const struct mem_controller *ctrl)
1465 #if DEBUG_RAM_CONFIG
1466 print_debug("spd_detect_dimms:\r\n");
1468 for(i = 0; i < DIMM_SOCKETS; i++) {
1471 #if DEBUG_RAM_CONFIG
1472 print_debug_hex32(i);
1473 print_debug("\r\n");
1475 device = ctrl->channel0[i];
1477 byte = spd_read_byte(ctrl->channel0[i], 2); /* Type */
1479 dimm_mask |= (1 << i);
1487 static uint32_t set_dimm_size(const struct mem_controller *ctrl, struct dimm_size sz, uint32_t memsz, unsigned index)
1490 uint32_t base0, base1;
1494 /* I think size2 is always 0 ... */
1495 /* Double the size if we are using dual channel memory */
1496 if (sz.side1 != sz.side2) {
1501 /* Make certain side1 of the dimm is at least 32MB */
1502 /* This 28 is weird.
1503 * sz.size1 is log2 size in bits.
1504 * so what's 28? So think of it as this:
1505 * in log2 space: 10 + 10 + 8, i.e. 1024 * 1024 * 256 or
1506 * 256 Mbits, or 32 Mbytes.
1508 /* this is from the e7500 code and it's just wrong for small dimes (< 64 MB)
1509 * However, realistically, this case will never happen! the dimms are all bigger ...
1510 * so skip the conditional completely.
1511 * if (sz.side1 >= (28)) { }
1513 memsz += (1 << (sz.side1 - (28)) ) ;
1515 /* Write the size of side 1 of the dimm */
1516 #if DEBUG_RAM_CONFIG
1517 print_debug("Write size ");
1518 print_debug_hex8(memsz);
1519 print_debug(" to ");
1520 print_debug_hex8(0x40 + index);
1521 print_debug("\r\n");
1524 pci_write_config8(ctrl->d0, 0x40+index, byte);
1526 /* now, fill in DRBs where no physical slot exists */
1528 for(i=index+1;i<4;i++) {
1529 pci_write_config8(ctrl->d0, 0x40+i, byte);
1536 #define LAST_DRB_SLOT 0x43
1538 static long spd_set_ram_size(const struct mem_controller *ctrl, long dimm_mask)
1544 for(i = 0; i < DIMM_SOCKETS; i++) {
1545 struct dimm_size sz;
1546 if (!(dimm_mask & (1 << i))) {
1549 sz = spd_get_dimm_size(ctrl->channel0[i]);
1550 #if DEBUG_RAM_CONFIG
1551 print_debug("dimm size =");
1552 print_debug_hex32(sz.side1);
1554 print_debug_hex32(sz.side2);
1555 print_debug("\r\n");
1558 if (sz.side1 == 0) {
1559 return -1; /* Report SPD error */
1561 memsz = set_dimm_size(ctrl, sz, memsz, i);
1564 /* For now hardset everything at 128MB boundaries */
1565 /* %ebp has the ram size in multiples of 64MB */
1566 // cmpl $0, %ebp /* test if there is no mem - smbus went bad */
1567 // jz no_memory_bad_smbus
1569 /* I should really adjust all of this in C after I have resources
1570 * to all of the pcie devices.
1573 /* Round up to 128M granularity */
1578 pci_write_config16(ctrl->d0, 0xc4, word);
1581 /* FIXME will this work with 3.5G of ram? */
1582 /* Put TOLM at 3G */
1583 pci_write_config16(ctrl->d0, 0xc4, 0xc000);
1584 /* Hard code a 1G remap window, right after the ram */
1586 word = 0x40; /* Ensure we are over 4G */
1590 pci_write_config16(ctrl->d0, 0xc6, word);
1592 pci_write_config16(ctrl->d0, 0xc8, word);
1600 static void sdram_set_spd_registers(const struct mem_controller *ctrl) {
1602 #if DEBUG_RAM_CONFIG
1603 print_debug(spd_pre_init);
1605 //activate_spd_rom(ctrl);
1606 dimm_mask = spd_detect_dimms(ctrl);
1607 if (!(dimm_mask & ((1 << DIMM_SOCKETS) - 1))) {
1608 print_debug("No memory for this controller\n");
1611 dimm_mask = spd_enable_clocks(ctrl, dimm_mask);
1614 //spd_verify_dimms(ctrl);
1615 #if DEBUG_RAM_CONFIG
1616 print_debug(spd_pre_set);
1618 dimm_mask = spd_set_row_attributes(ctrl,dimm_mask);
1622 dimm_mask = spd_set_dram_controller_mode(ctrl,dimm_mask);
1627 /* skip for now until we just get "known good" up
1628 dimm_mask = spd_set_cas_latency(ctrl,dimm_mask);
1633 dimm_mask = spd_set_dram_timing(ctrl,dimm_mask);
1637 #if DEBUG_RAM_CONFIG
1638 print_debug(spd_post_init);
1640 //moved from dram_post_init
1641 spd_set_ram_size(ctrl, dimm_mask);
1642 dump_pci_device(PCI_DEV(0,0,1));
1646 /* Unrecoverable error reading SPD data */
1647 print_err("SPD error - reset\r\n");
1653 /* I have finally seen ram bad enough to cause LinuxBIOS
1654 * to die in mysterious ways, before booting up far
1655 * enough to run a memory tester. This code attempts
1656 * to catch this blatantly bad ram, with a spot check.
1657 * For most cases you should boot all of the way up
1658 * and run a memory tester.
1660 /* Ensure I read/write each stick of bank of memory &&
1661 * that I do more than 1000 bytes to avoid the northbridge cache.
1662 * Only 64M of each side of each DIMM is currently mapped,
1663 * so we can handle > 4GB of ram here.
1666 #define bank_msg "Bank "
1667 #define side_msg " Side "
1668 static void verify_ram() {
1670 /* Check to see if the RAM is present,
1671 * in the specified bank and side.
1675 addl $((5<<8) | SMBUS_MEM_DEVICE_START), %ebx
1676 CALLSP(smbus_read_byte)
1683 /* Display the bank and side we are spot checking.
1685 2: CONSOLE_INFO_TX_STRING($bank_msg)
1689 CONSOLE_INFO_TX_HEX8(%bl)
1690 CONSOLE_INFO_TX_STRING($side_msg)
1693 CONSOLE_INFO_TX_HEX8(%bl)
1695 /* Compute the memory address to spot check. */
1700 addl $0x04000000, %eax
1704 /* Spot check 512K of RAM */
1706 addl $0x0007ffff, %ebx
1709 /* Now find the next bank and side to spot check */
1711 cmpl $((SMBUS_MEM_DEVICE_END - SMBUS_MEM_DEVICE_START)<<1), %ecx
1713 RET_LABEL(verify_ram)
1719 static void ram_postinit(const struct mem_controller *ctrl) {
1720 #if DEBUG_RAM_CONFIG
1723 /* Include a test to verify that memory is more or less working o.k.
1724 * This test is to catch programming errors and hardware that is out of
1725 * spec, not a test to see if the memory dimms are working 100%
1727 //# CALL_LABEL(verify_ram)
1728 spd_set_ram_size(ctrl);
1730 #define FIRST_NORMAL_REFERENCE() CALL_LABEL(ram_postinit)
1732 #define SPECIAL_FINISHUP() CALL_LABEL(dram_finish)
1736 #define ecc_pre_init "Initializing ECC state...\r\n"
1737 #define ecc_post_init "ECC state initialized.\r\n"
1738 static void dram_finish(const struct mem_controller *ctrl)
1742 /* Test to see if ECC support is enabled */
1743 dword = pci_read_config32(ctrl->d0, 0x70);
1748 #if DEBUG_RAM_CONFIG
1749 print_debug(ecc_pre_init);
1751 #if DEBUG_RAM_CONFIG
1752 print_debug(ecc_post_init);
1755 /* Clear the ECC error bits */
1757 dword = pci_read_config32(ctrl->d0, 0x7c); /* FCS_EN */
1759 pci_write_config32(ctrl->d0, 0x7c, dword);
1764 #if DEBUG_RAM_CONFIG
1771 #define ERRFUNC(x, str) mem_err(x, str)
1774 ERRFUNC(invalid_dimm_type, "Invalid dimm type")
1775 ERRFUNC(spd_missing_data, "Missing sdram spd data")
1776 ERRFUNC(spd_invalid_data, "Invalid sdram spd data")
1777 ERRFUNC(spd_unsupported_data, "Unsupported sdram spd value")
1778 ERRFUNC(unsupported_page_size, "Unsupported page size")
1779 ERRFUNC(sdram_presence_mismatch, "DIMM presence mismatch")
1780 ERRFUNC(sdram_value_mismatch, "spd data does not match")
1781 ERRFUNC(unsupported_refresh_rate, "Unsuported spd refresh rate")
1782 ERRFUNC(inconsistent_cas_latencies, "No cas latency supported by all dimms")
1783 ERRFUNC(unsupported_rcd, "Unsupported ras to cas delay")
1786 #define mem_err_err "ERROR: "
1787 #define mem_err_pair " on dimm pair "
1788 #define mem_err_byte " spd byte "
1789 static void mem_err {
1791 CONSOLE_ERR_TX_STRING($mem_err_err)
1792 CONSOLE_ERR_TX_STRING(%esi)
1793 CONSOLE_ERR_TX_STRING($mem_err_pair)
1795 subb $(SMBUS_MEM_DEVICE_START), %bl
1796 CONSOLE_ERR_TX_HEX8(%bl)
1797 CONSOLE_ERR_TX_STRING($mem_err_byte)
1799 CONSOLE_ERR_TX_HEX8(%bh)
1807 #if ASM_CONSOLE_LOGLEVEL > BIOS_DEBUG
1808 #define ram_enable_1 "Ram Enable 1\r\n"
1809 #define ram_enable_2 "Ram Enable 2\r\n"
1810 #define ram_enable_3 "Ram Enable 3\r\n"
1811 #define ram_enable_4 "Ram Enable 4\r\n"
1812 #define ram_enable_5 "Ram Enable 5\r\n"
1813 #define ram_enable_6 "Ram Enable 6\r\n"
1814 #define ram_enable_7 "Ram Enable 7\r\n"
1815 #define ram_enable_8 "Ram Enable 8\r\n"
1816 #define ram_enable_9 "Ram Enable 9\r\n"
1817 #define ram_enable_10 "Ram Enable 10\r\n"
1818 #define ram_enable_11 "Ram Enable 11\r\n"
1821 /* Estimate that SLOW_DOWN_IO takes about 50&76us*/
1822 /* delay for 200us */
1826 // for(i=0; i<16;i++) { SLOW_DOWN_IO }
1829 #define EXTRA_DELAY DO_DELAY
1831 static void sdram_enable(int controllers, const struct mem_controller *ctrl)
1835 /* 1 & 2 Power up and start clocks */
1836 /* let the games begin. More undocumented shit, so we'll just set it
1839 mchtst = pci_read_config32(ctrl->d0, 0x68);
1840 #if DEBUG_RAM_CONFIG
1841 print_debug(ram_enable_1);
1842 print_debug_hex32(mchtst);
1846 mchtst = 0x10f10038;
1847 pci_write_config32(ctrl->d0, 0x68, mchtst);
1848 * can't find a ram power register ...
1851 #if DEBUG_RAM_CONFIG
1853 print_debug(ram_enable_2);
1856 /* A 200us delay is needed */
1862 #if DEBUG_RAM_CONFIG
1863 dump_pci_device(PCI_DEV(0, 0, 0)) ;
1864 print_debug(ram_enable_3);
1868 #define DEBUG_RAM_CONFIG 0
1869 /* 4 Precharge all */
1870 #if DEBUG_RAM_CONFIG
1871 print_debug(ram_enable_4);
1873 #define DEBUG_RAM_CONFIG 0
1874 RAM_PRECHARGE(ctrl);
1877 /* wait until the all banks idle state... */
1878 /* 5. Issue EMRS to enable DLL */
1879 #if DEBUG_RAM_CONFIG
1880 print_debug(ram_enable_5);
1886 #if DEBUG_RAM_CONFIG
1887 print_debug(ram_enable_6);
1892 /* Ensure a 200us delay between the DLL reset in step 6 and the final
1893 * mode register set in step 9.
1894 * Infineon needs this before any other command is sent to the ram.
1899 /* 7 Precharge all */
1900 #if DEBUG_RAM_CONFIG
1901 print_debug(ram_enable_7);
1903 RAM_PRECHARGE(ctrl);
1906 /* 8 Now we need 2 AUTO REFRESH / CBR cycles to be performed */
1907 #if DEBUG_RAM_CONFIG
1908 print_debug(ram_enable_8);
1914 /* And for good luck 6 more CBRs */
1928 /* 9 mode register set */
1929 #if DEBUG_RAM_CONFIG
1930 print_debug(ram_enable_9);
1935 /* 10 DDR Receive FIFO RE-Sync */
1936 #if DEBUG_RAM_CONFIG
1937 print_debug(ram_enable_10);
1939 RAM_RESET_DDR_PTR(ctrl);
1942 /* 11 normal operation */
1943 #if DEBUG_RAM_CONFIG
1944 print_debug(ram_enable_11);
1950 //FIRST_NORMAL_REFERENCE();
1951 //spd_set_ram_size(ctrl, 0x03);
1953 /* Finally enable refresh */
1954 ENABLE_REFRESH(ctrl);
1956 //SPECIAL_FINISHUP();
1958 { char *c = (char *) 0;
1960 print_debug("Test: ");
1961 print_debug_hex8(*c);
1962 print_debug("\r\n");