2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2008 Uwe Hermann <uwe@hermann-uwe.de>
5 * Copyright (C) 2010 Keith Hui <buurin@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sdram_mode.h>
29 /*-----------------------------------------------------------------------------
30 Macros and definitions.
31 -----------------------------------------------------------------------------*/
33 /* Debugging macros. */
34 #if CONFIG_DEBUG_RAM_SETUP
35 #define PRINT_DEBUG(x) print_debug(x)
36 #define PRINT_DEBUG_HEX8(x) print_debug_hex8(x)
37 #define PRINT_DEBUG_HEX16(x) print_debug_hex16(x)
38 #define PRINT_DEBUG_HEX32(x) print_debug_hex32(x)
39 // no dump_pci_device in src/northbridge/intel/i440bx
40 // #define DUMPNORTH() dump_pci_device(PCI_DEV(0, 0, 0))
43 #define PRINT_DEBUG(x)
44 #define PRINT_DEBUG_HEX8(x)
45 #define PRINT_DEBUG_HEX16(x)
46 #define PRINT_DEBUG_HEX32(x)
50 #define NB PCI_DEV(0, 0, 0)
52 /* SDRAMC[7:5] - SDRAM Mode Select (SMS). */
53 #define RAM_COMMAND_NORMAL 0x0
54 #define RAM_COMMAND_NOP 0x1
55 #define RAM_COMMAND_PRECHARGE 0x2
56 #define RAM_COMMAND_MRS 0x3
57 #define RAM_COMMAND_CBR 0x4
59 /* Map the JEDEC SPD refresh rates (array index) to 440BX refresh rates as
60 * defined in DRAMC[2:0].
62 * [0] == Normal 15.625 us -> 15.6 us
63 * [1] == Reduced(.25X) 3.9 us -> 7.8 ns
64 * [2] == Reduced(.5X) 7.8 us -> 7.8 us
65 * [3] == Extended(2x) 31.3 us -> 31.2 us
66 * [4] == Extended(4x) 62.5 us -> 62.4 us
67 * [5] == Extended(8x) 125 us -> 124.8 us
69 static const uint32_t refresh_rate_map[] = {
73 /* Table format: register, bitmask, value. */
74 static const long register_values[] = {
75 /* NBXCFG - NBX Configuration Register
78 * [31:24] SDRAM Row Without ECC
79 * 0 = ECC components are populated in this row
80 * 1 = ECC components are not populated in this row
82 * [18:18] Host Bus Fast Data Ready Enable (HBFDRE)
83 * Assertion of DRAM data on host bus occurs...
84 * 0 = ...one clock after sampling snoop results (default)
85 * 1 = ...on the same clock the snoop result is being sampled
86 * (this mode is faster by one clock cycle)
87 * [17:17] ECC - EDO static Drive mode
88 * 0 = Normal mode (default)
89 * 1 = ECC signals are always driven
90 * [16:16] IDSEL_REDIRECT
91 * 0 = IDSEL1 is allocated to this bridge (default)
92 * 1 = IDSEL7 is allocated to this bridge
93 * [15:15] WSC# Handshake Disable
94 * 1 = Uni-processor mode
95 * 0 = Dual-processor mode with external IOAPIC (default)
96 * [14:14] Intel Reserved
97 * [13:12] Host/DRAM Frequency
102 * [11:11] AGP to PCI Access Enable
105 * [10:10] PCI Agent to Aperture Access Disable
107 * 0 = Enable (default)
108 * [09:09] Aperture Access Global Enable
111 * [08:07] DRAM Data Integrity Mode (DDIM)
115 * 11 = ECC Mode with hardware scrubbing enabled
116 * [06:06] ECC Diagnostic Mode Enable (EDME)
118 * 0 = Normal operation mode (default)
119 * [05:05] MDA Present (MDAP)
120 * Works in conjunction with the VGA_EN bit.
122 * 0 x All VGA cycles are sent to PCI
123 * 1 0 All VGA cycles are sent to AGP
124 * 1 1 All VGA cycles are sent to AGP, except for
125 * cycles in the MDA range.
127 * [03:03] USWC Write Post During I/O Bridge Access Enable (UWPIO)
130 * [02:02] In-Order Queue Depth (IOQD)
131 * 1 = In-order queue = maximum
132 * 0 = A7# is sampled asserted (i.e., 0)
136 NBXCFG + 0, 0x00, 0x0c,
137 // NBXCFG + 1, 0x00, 0xa0,
138 NBXCFG + 1, 0x00, 0x80,
139 NBXCFG + 2, 0x00, 0x00,
140 NBXCFG + 3, 0x00, 0xff,
142 /* DRAMC - DRAM Control Register
146 * [5:5] Module Mode Configuration (MMCONFIG)
148 * [4:3] DRAM Type (DT)
151 * 10 = Registered SDRAM
153 * Note: EDO, SDRAM and Registered SDRAM cannot be mixed.
154 * [2:0] DRAM Refresh Rate (DRR)
155 * 000 = Refresh disabled
164 /* Choose SDRAM (not registered), and disable refresh for now. */
168 * PAM[6:0] - Programmable Attribute Map Registers
171 * 0x59 [3:0] Reserved
172 * 0x59 [5:4] 0xF0000 - 0xFFFFF BIOS area
173 * 0x5a [1:0] 0xC0000 - 0xC3FFF ISA add-on BIOS
174 * 0x5a [5:4] 0xC4000 - 0xC7FFF ISA add-on BIOS
175 * 0x5b [1:0] 0xC8000 - 0xCBFFF ISA add-on BIOS
176 * 0x5b [5:4] 0xCC000 - 0xCFFFF ISA add-on BIOS
177 * 0x5c [1:0] 0xD0000 - 0xD3FFF ISA add-on BIOS
178 * 0x5c [5:4] 0xD4000 - 0xD7FFF ISA add-on BIOS
179 * 0x5d [1:0] 0xD8000 - 0xDBFFF ISA add-on BIOS
180 * 0x5d [5:4] 0xDC000 - 0xDFFFF ISA add-on BIOS
181 * 0x5e [1:0] 0xE0000 - 0xE3FFF BIOS entension
182 * 0x5e [5:4] 0xE4000 - 0xE7FFF BIOS entension
183 * 0x5f [1:0] 0xE8000 - 0xEBFFF BIOS entension
184 * 0x5f [5:4] 0xEC000 - 0xEFFFF BIOS entension
187 * 00 = DRAM Disabled (all access goes to memory mapped I/O space)
188 * 01 = Read Only (Reads to DRAM, writes to memory mapped I/O space)
189 * 10 = Write Only (Writes to DRAM, reads to memory mapped I/O space)
190 * 11 = Read/Write (all access goes to DRAM)
194 * Map all legacy regions to RAM (read/write). This is required if
195 * you want to use the RAM area from 768 KB - 1 MB. If the PAM
196 * registers are not set here appropriately, the RAM in that region
197 * will not be accessible, thus a RAM check of it will also fail.
199 * TODO: This was set in sdram_set_spd_registers().
200 * Test if it still works when set here.
210 /* DRB[0:7] - DRAM Row Boundary Registers
213 * An array of 8 byte registers, which hold the ending memory address
214 * assigned to each pair of DIMMs, in 8MB granularity.
216 * 0x60 DRB0 = Total memory in row0 (in 8 MB)
217 * 0x61 DRB1 = Total memory in row0+1 (in 8 MB)
218 * 0x62 DRB2 = Total memory in row0+1+2 (in 8 MB)
219 * 0x63 DRB3 = Total memory in row0+1+2+3 (in 8 MB)
220 * 0x64 DRB4 = Total memory in row0+1+2+3+4 (in 8 MB)
221 * 0x65 DRB5 = Total memory in row0+1+2+3+4+5 (in 8 MB)
222 * 0x66 DRB6 = Total memory in row0+1+2+3+4+5+6 (in 8 MB)
223 * 0x67 DRB7 = Total memory in row0+1+2+3+4+5+6+7 (in 8 MB)
225 /* Set the DRBs to zero for now, this will be fixed later. */
235 /* FDHC - Fixed DRAM Hole Control Register
238 * Controls two fixed DRAM holes: 512 KB - 640 KB and 15 MB - 16 MB.
240 * [7:6] Hole Enable (HEN)
242 * 01 = 512 KB - 640 KB (128 KB)
243 * 10 = 15 MB - 16 MB (1 MB)
247 /* No memory holes. */
250 /* RPS - SDRAM Row Page Size Register
253 * Sets the row page size for SDRAM. For EDO memory, the page
254 * size is fixed at 2 KB.
256 * [15:0] Page Size (PS)
263 /* SDRAMC - SDRAM Control Register
267 * [09:08] Idle/Pipeline DRAM Leadoff Timing (IPDLT)
269 * 01 = Add a clock delay to the lead-off clock count
272 * [07:05] SDRAM Mode Select (SMS)
273 * 000 = Normal SDRAM Operation (default)
274 * 001 = NOP Command Enable
275 * 010 = All Banks Precharge Enable
276 * 011 = Mode Register Set Enable
282 * 0 = 3 DIMM configuration
283 * 1 = 4 DIMM configuration
284 * [03:03] Leadoff Command Timing (LCT)
287 * [02:02] CAS# Latency (CL)
288 * 0 = 3 DCLK CAS# latency
289 * 1 = 2 DCLK CAS# latency
290 * [01:01] SDRAM RAS# to CAS# Delay (SRCD)
291 * 0 = 3 clocks between a row activate and a read or write cmd.
292 * 1 = 2 clocks between a row activate and a read or write cmd.
293 * [00:00] SDRAM RAS# Precharge (SRP)
294 * 0 = 3 clocks of RAS# precharge
295 * 1 = 2 clocks of RAS# precharge
297 #if CONFIG_SDRAMPWR_4DIMM
298 SDRAMC + 0, 0x00, 0x10, /* The board has 4 DIMM slots. */
300 SDRAMC + 0, 0x00, 0x00, /* The board has 3 DIMM slots.*/
302 SDRAMC + 1, 0x00, 0x00,
304 /* PGPOL - Paging Policy Register
307 * [15:08] Banks per Row (BPR)
312 * [04:04] Intel Reserved
313 * [03:00] DRAM Idle Timer (DIT)
322 * 1xxx = Infinite (pages are not closed for idle condition)
325 PGPOL + 0, 0x00, 0x00,
326 PGPOL + 1, 0x00, 0xff,
328 /* PMCR - Power Management Control Register
331 * [07:07] Power Down SDRAM Enable (PDSE)
334 * [06:06] ACPI Control Register Enable (SCRE)
336 * 0 = Disable (default)
337 * [05:05] Suspend Refresh Type (SRT)
338 * 1 = Self refresh mode
340 * [04:04] Normal Refresh Enable (NREF_EN)
343 * [03:03] Quick Start Mode (QSTART)
344 * 1 = Quick start mode for the processor is enabled
345 * [02:02] Gated Clock Enable (GCLKEN)
348 * [01:01] AGP Disable (AGP_DIS)
351 * [00:00] CPU reset without PCIRST enable (CRst_En)
355 /* Enable normal refresh and the gated clock. */
356 // TODO: Only do this later?
361 /* Enable SCRR.SRRAEN and let BX choose the SRR. */
362 SCRR + 1, 0x00, 0x10,
365 /*-----------------------------------------------------------------------------
366 SDRAM configuration functions.
367 -----------------------------------------------------------------------------*/
370 * Send the specified RAM command to all DIMMs.
372 * @param command The RAM command to send to the DIMM(s).
374 static void do_ram_command(u32 command)
377 u8 dimm_start, dimm_end;
379 u32 addr, addr_offset;
381 /* Configure the RAM command. */
382 reg16 = pci_read_config16(NB, SDRAMC);
383 reg16 &= 0xff1f; /* Clear bits 7-5. */
384 reg16 |= (u16) (command << 5); /* Write command into bits 7-5. */
385 pci_write_config16(NB, SDRAMC, reg16);
388 * RAM_COMMAND_NORMAL affects only the memory controller and
389 * doesn't need to be "sent" to the DIMMs.
391 if (command == RAM_COMMAND_NORMAL)
394 /* Send the RAM command to each row of memory. */
396 for (i = 0; i < (DIMM_SOCKETS * 2); i++) {
398 caslatency = 3; /* TODO: Dynamically get CAS latency later. */
399 if (command == RAM_COMMAND_MRS) {
401 * MAA[12:11,9:0] must be inverted when sent to DIMM
402 * 2 or 3 (no inversion if sent to DIMM 0 or 1).
404 if ((i >= 0 && i <= 3) && caslatency == 3)
406 if ((i >= 4 && i <= 7) && caslatency == 3)
407 addr_offset = 0x1e28;
408 if ((i >= 0 && i <= 3) && caslatency == 2)
410 if ((i >= 4 && i <= 7) && caslatency == 2)
411 addr_offset = 0x1ea8;
414 dimm_end = pci_read_config8(NB, DRB + i);
416 addr = (dimm_start * 8 * 1024 * 1024) + addr_offset;
417 if (dimm_end > dimm_start) {
419 PRINT_DEBUG(" Sending RAM command 0x");
420 PRINT_DEBUG_HEX16(reg16);
421 PRINT_DEBUG(" to 0x");
422 PRINT_DEBUG_HEX32(addr);
429 /* Set the start of the next DIMM. */
430 dimm_start = dimm_end;
434 static void set_dram_buffer_strength(void)
436 /* To give some breathing room for romcc,
437 * mbsc0 doubles as drb
438 * mbsc1 doubles as drb1
439 * mbfs0 doubles as i and reg
441 uint8_t mbsc0,mbsc1,mbsc3,mbsc4,mbfs0,mbfs2,fsb;
443 /* Tally how many rows between rows 0-3 and rows 4-7 are populated.
444 * This determines how to program MBFS and MBSC.
450 for (mbfs0 = DRB0; mbfs0 <= DRB7; mbfs0++) {
451 mbsc1 = pci_read_config8(NB, mbfs0);
452 if (mbsc0 != mbsc1) {
462 /* Algorithm bitmap for programming MBSC[39:0] and MBFS[23:0]
464 * 440BX datasheet says buffer frequency is independent from bus frequency
465 * and mismatch both ways are possible. This is how it is programmed
468 * There are four main conditions to check when programming DRAM buffer
469 * frequency and strength:
471 * a: >2 rows populated across DIMM0,1
472 * b: >2 rows populated across DIMM2,3
473 * c: >4 rows populated across all DIMM slots
475 * 1: NBXCFG[13] strapped as 100MHz, or
476 * 6: NBXCFG[13] strapped as 66MHz
478 * CKE0/FENA ----------------------------------------------------------+
479 * CKE1/GCKE -------------------[ MBFS ]------------------------+|
480 * DQMA/CASA[764320]# ----------[ 0 = 66MHz ]-----------------------+||
481 * DQMB1/CASB1# ----------------[ 1 = 100MHz ]----------------------+|||
482 * DQMB5/CASB5# ---------------------------------------------------+||||
483 * DQMA1/CASA1# --------------------------------------------------+|||||
484 * DQMA5/CASA5# -------------------------------------------------+||||||
485 * CSA0-5#,CSB0-5# ----------------------------------------++++++|||||||
486 * CSA6#/CKE2# -------------------------------------------+|||||||||||||
487 * CSB6#/CKE4# ------------------------------------------+||||||||||||||
488 * CSA7#/CKE3# -----------------------------------------+|||||||||||||||
489 * CSB7#/CKE5# ----------------------------------------+||||||||||||||||
490 * MECC[7:0] #2/#1 (100MHz) -------------------------++|||||||||||||||||
491 * MD[63:0] #2/#1 (100MHz) ------------------------++|||||||||||||||||||
492 * MAB[12:11,9:0]#,MAB[13,10],WEB#,SRASB#,SCASB# -+|||||||||||||||||||||
493 * MAA[13:0],WEA#,SRASA#,SCASA# -----------------+||||||||||||||||||||||
494 * Reserved ------------------------------------+|||||||||||||||||||||||
495 * ||||||||||||||||||||||||
496 * 3 32 21 10 0 * 2 21 10 0
497 * 9876543210987654321098765432109876543210 * 321098765432109876543210
498 * a 10------------------------1010---------- * -1---------------11----- a
499 *!a 11------------------------1111---------- * -0---------------00----- !a
500 * b --10--------------------------1010------ * --1----------------11--- b
501 *!b --11--------------------------1111------ * --0----------------00--- !b
502 * c ----------------------------------1100-- * ----------------------1- c
503 *!c ----------------------------------1011-- * ----------------------0- !c
504 * 1 ----1010101000000000000000------------00 * ---11111111111111----1-0 1
505 * 6 ----000000000000000000000010101010----00 * ---1111111111111100000-0 6
506 * | | | | | | | | | | ||||||| | | | | | |
507 * | | | | | | | | | | ||||||| | | | | | +- CKE0/FENA
508 * | | | | | | | | | | ||||||| | | | | +--- CKE1/GCKE
509 * | | | | | | | | | | ||||||| | | | +----- DQMA/CASA[764320]#
510 * | | | | | | | | | | ||||||| | | +------- DQMB1/CASB1#
511 * | | | | | | | | | | ||||||| | +--------- DQMB5/CASB5#
512 * | | | | | | | | | | ||||||| +----------- DQMA1/CASA1#
513 * | | | | | | | | | | ||||||+------------- DQMA5/CASA5#
514 * | | | | | | | | | | ++++++-------------- CSA0-5#,CSB0-5# [ 0=1x;1=2x ]
515 * | | | | | | | | | +--------------------- CSA6#/CKE2#
516 * | | | | | | | | +---[ MBSC ]------ CSB6#/CKE4#
517 * | | | | | | | +-----[ 00 = 1x ]------ CSA7#/CKE3#
518 * | | | | | | +-------[ 01 invalid ]------ CSB7#/CKE5#
519 * | | | | | +---------[ 10 = 2x ]------ MECC[7:0] #1 (2x)
520 * | | | | +-----------[ 11 = 3x ]------ MECC[7:0] #2 (2x)
521 * | | | +--------------------------------- MD[63:0] #1 (2x)
522 * | | +----------------------------------- MD[63:0] #2 (2x)
523 * | +------------------------------------- MAB[12:11,9:0]#,MAB[13,10],WEB#,SRASB#,SCASB#
524 * +--------------------------------------- MAA[13:0],WEA#,SRASA#,SCASA#
525 * MBSC[47:40] and MBFS[23] are reserved.
527 * This algorithm is checked against P2B-LS factory BIOS. It has 4 DIMM slots.
528 * Therefore it assumes a board with 4 slots, and will need testing
529 * on boards with 3 DIMM slots.
535 if (pci_read_config8(NB, NBXCFG + 1) & 0x30) {
548 mbsc4 = mbsc4 | 0x80;
549 mbsc1 = mbsc1 | 0x28;
550 mbfs2 = mbfs2 | 0x40;
551 mbfs0 = mbfs0 | 0x60;
553 mbsc4 = mbsc4 | 0xc0;
555 mbsc1 = mbsc1 | 0x3c;
559 mbsc4 = mbsc4 | 0x20;
560 mbsc1 = mbsc1 | 0x02;
561 mbsc0 = mbsc0 | 0x80;
562 mbfs2 = mbfs2 | 0x20;
563 mbfs0 = mbfs0 | 0x18;
565 mbsc4 = mbsc4 | 0x30;
567 mbsc1 = mbsc1 | 0x03;
568 mbsc0 = mbsc0 | 0xc0;
571 if ((dimm03 + dimm47) > 4) {
572 mbsc0 = mbsc0 | 0x30;
573 mbfs0 = mbfs0 | 0x02;
575 mbsc0 = mbsc0 | 0x2c;
578 pci_write_config8(NB, MBSC + 0, mbsc0);
579 pci_write_config8(NB, MBSC + 1, mbsc1);
580 pci_write_config8(NB, MBSC + 2, 0x00);
581 pci_write_config8(NB, MBSC + 3, mbsc3);
582 pci_write_config8(NB, MBSC + 4, mbsc4);
583 pci_write_config8(NB, MBFS + 0, mbfs0);
584 pci_write_config8(NB, MBFS + 1, 0xff);
585 pci_write_config8(NB, MBFS + 2, mbfs2);
588 /*-----------------------------------------------------------------------------
589 DIMM-independant configuration functions.
590 -----------------------------------------------------------------------------*/
592 static void spd_enable_refresh(void)
597 reg = pci_read_config8(NB, DRAMC);
599 for (i = 0; i < DIMM_SOCKETS; i++) {
600 value = spd_read_byte(DIMM_SPD_BASE + i, SPD_REFRESH);
603 reg = (reg & 0xf8) | refresh_rate_map[(value & 0x7f)];
605 PRINT_DEBUG(" Enabling refresh (DRAMC = 0x");
606 PRINT_DEBUG_HEX8(reg);
607 PRINT_DEBUG(") for DIMM ");
612 pci_write_config8(NB, DRAMC, reg);
615 /*-----------------------------------------------------------------------------
617 -----------------------------------------------------------------------------*/
619 static void sdram_set_registers(void)
624 PRINT_DEBUG("Northbridge prior to SDRAM init:\r\n");
627 max = ARRAY_SIZE(register_values);
629 /* Set registers as specified in the register_values[] array. */
630 for (i = 0; i < max; i += 3) {
631 reg = pci_read_config8(NB, register_values[i]);
632 reg &= register_values[i + 1];
633 reg |= register_values[i + 2] & ~(register_values[i + 1]);
634 pci_write_config8(NB, register_values[i], reg);
636 PRINT_DEBUG(" Set register 0x");
637 PRINT_DEBUG_HEX8(register_values[i]);
638 PRINT_DEBUG(" to 0x");
639 PRINT_DEBUG_HEX8(reg);
650 static struct dimm_size spd_get_dimm_size(unsigned int device)
653 int i, module_density, dimm_banks;
655 module_density = spd_read_byte(device, SPD_DENSITY_OF_EACH_ROW_ON_MODULE);
656 dimm_banks = spd_read_byte(device, SPD_NUM_DIMM_BANKS);
658 /* Find the size of side1. */
659 /* Find the larger value. The larger value is always side1. */
660 for (i = 512; i >= 0; i >>= 1) {
661 if ((module_density & i) == i) {
667 /* Set to 0 in case it's single sided. */
670 /* Test if it's a dual-sided DIMM. */
671 if (dimm_banks > 1) {
672 /* Test if there's a second value. If so it's asymmetrical. */
673 if (module_density != i) {
675 * Find second value, picking up where we left off.
676 * i >>= 1 done initially to make sure we don't get
677 * the same value again.
679 for (i >>= 1; i >= 0; i >>= 1) {
680 if (module_density == (sz.side1 | i)) {
685 /* If not, it's symmetrical. */
692 * SPD byte 31 is the memory size divided by 4 so we
693 * need to muliply by 4 to get the total size.
701 * Sets DRAM attributes one DIMM at a time, based on SPD data.
702 * Northbridge settings that are set: NBXCFG[31:24], DRB0-DRB7, RPS, DRAMC.
704 static void set_dram_row_attributes(void)
706 int i, dra, drb, col, width, value, rps, edosd, ecc, nbxecc;
707 u8 bpr; /* Top 8 bits of PGPOL */
715 for (i = 0; i < DIMM_SOCKETS; i++) {
717 device = DIMM_SPD_BASE + i;
720 /* First check if a DIMM is actually present. */
721 value = spd_read_byte(device, SPD_MEMORY_TYPE);
722 /* This is 440BX! We do EDO too! */
723 if (value == SPD_MEMORY_TYPE_EDO
724 || value == SPD_MEMORY_TYPE_SDRAM) {
726 PRINT_DEBUG("Found ");
727 if (value == SPD_MEMORY_TYPE_EDO) {
729 } else if (value == SPD_MEMORY_TYPE_SDRAM) {
732 PRINT_DEBUG("DIMM in slot ");
737 print_err("Mixing EDO/SDRAM unsupported!\r\n");
741 /* "DRA" is our RPS for the two rows on this DIMM. */
745 col = spd_read_byte(device, SPD_NUM_COLUMNS);
748 * Is this an ECC DIMM? Actually will be a 2 if so.
749 * TODO: Other register than NBXCFG also needs this
752 ecc = spd_read_byte(device, SPD_DIMM_CONFIG_TYPE);
755 width = spd_read_byte(device, SPD_MODULE_DATA_WIDTH_LSB);
757 /* Exclude error checking data width from page size calculations */
759 value = spd_read_byte(device,
760 SPD_ERROR_CHECKING_SDRAM_WIDTH);
763 /* Clear top 2 bits to help set up NBXCFG. */
766 /* Without ECC, top 2 bits should be 11. */
770 /* Calculate page size in bits. */
771 value = ((1 << col) * width);
776 /* Number of banks of DIMM (single or double sided). */
777 value = spd_read_byte(device, SPD_NUM_DIMM_BANKS);
779 /* Once we have dra, col is done and can be reused.
780 * So it's reused for number of banks.
782 col = spd_read_byte(device, SPD_NUM_BANKS_PER_SDRAM);
786 * Second bank of 1-bank DIMMs "doesn't have
787 * ECC" - or anything.
792 } else if (dra == 4) {
794 } else if (dra == 8) {
800 * Sets a flag in PGPOL[BPR] if this DIMM has
805 } else if (value == 2) {
808 } else if (dra == 4) {
809 dra = 0x05; /* 4KB */
810 } else if (dra == 8) {
811 dra = 0x0a; /* 8KB */
819 print_err("# of banks of DIMM unsupported!\r\n");
823 print_err("Page size not supported\r\n");
828 * 440BX supports asymmetrical dual-sided DIMMs,
829 * but can't handle DIMMs smaller than 8MB per
830 * side or larger than 128MB per side.
832 struct dimm_size sz = spd_get_dimm_size(device);
833 if ((sz.side1 < 8)) {
834 print_err("DIMMs smaller than 8MB per side\r\n"
835 "are not supported on this NB.\r\n");
838 if ((sz.side1 > 128)) {
839 print_err("DIMMs > 128MB per side\r\n"
840 "are not supported on this NB\r\n");
844 /* Divide size by 8 to set up the DRB registers. */
845 drb += (sz.side1 / 8);
848 * Build the DRB for the next row in MSB so it gets
849 * placed in DRB[n+1] where it belongs when written
853 drb |= (drb + (sz.side2 / 8)) << 8;
856 PRINT_DEBUG("No DIMM found in slot ");
861 /* If there's no DIMM in the slot, set dra to 0x00. */
864 /* Still have to propagate DRB over. */
869 pci_write_config16(NB, DRB + (2 * i), drb);
871 PRINT_DEBUG("DRB has been set to 0x");
872 PRINT_DEBUG_HEX16(drb);
876 /* Brings the upper DRB back down to be base for
877 * DRB calculations for the next two rows.
881 rps |= (dra & 0x0f) << (i * 4);
882 nbxecc = (nbxecc >> 2) | (ecc & 0xc0);
885 /* Set paging policy register. */
886 pci_write_config8(NB, PGPOL + 1, bpr);
887 PRINT_DEBUG("PGPOL[BPR] has been set to 0x");
888 PRINT_DEBUG_HEX8(bpr);
891 /* Set DRAM row page size register. */
892 pci_write_config16(NB, RPS, rps);
893 PRINT_DEBUG("RPS has been set to 0x");
894 PRINT_DEBUG_HEX16(rps);
898 pci_write_config8(NB, NBXCFG + 3, nbxecc);
899 PRINT_DEBUG("NBXECC[31:24] has been set to 0x");
900 PRINT_DEBUG_HEX8(nbxecc);
903 /* Set DRAMC[4:3] to proper memory type (EDO/SDRAM).
904 * TODO: Registered SDRAM support.
909 } else if (edosd & 0x04) {
914 /* edosd is now in the form needed for DRAMC[4:3]. */
915 value = pci_read_config8(NB, DRAMC) & 0xe7;
917 pci_write_config8(NB, DRAMC, value);
918 PRINT_DEBUG("DRAMC has been set to 0x");
919 PRINT_DEBUG_HEX8(value);
923 static void sdram_set_spd_registers(void)
925 /* Setup DRAM row boundary registers and other attributes. */
926 set_dram_row_attributes();
928 /* TODO: Set SDRAMC. */
929 pci_write_config16(NB, SDRAMC, 0x0010); /* SDRAMPWR=1: 4 DIMM config */
932 set_dram_buffer_strength();
934 /* TODO: Set PMCR? */
935 // pci_write_config8(NB, PMCR, 0x14);
936 pci_write_config8(NB, PMCR, 0x10);
939 pci_write_config8(NB, DRAMT, 0x03);
942 static void sdram_enable(void)
946 /* 0. Wait until power/voltages and clocks are stable (200us). */
949 /* 1. Apply NOP. Wait 200 clock cycles (200us should do). */
950 PRINT_DEBUG("RAM Enable 1: Apply NOP\r\n");
951 do_ram_command(RAM_COMMAND_NOP);
954 /* 2. Precharge all. Wait tRP. */
955 PRINT_DEBUG("RAM Enable 2: Precharge all\r\n");
956 do_ram_command(RAM_COMMAND_PRECHARGE);
959 /* 3. Perform 8 refresh cycles. Wait tRC each time. */
960 PRINT_DEBUG("RAM Enable 3: CBR\r\n");
961 for (i = 0; i < 8; i++) {
962 do_ram_command(RAM_COMMAND_CBR);
966 /* 4. Mode register set. Wait two memory cycles. */
967 PRINT_DEBUG("RAM Enable 4: Mode register set\r\n");
968 do_ram_command(RAM_COMMAND_MRS);
971 /* 5. Normal operation. */
972 PRINT_DEBUG("RAM Enable 5: Normal operation\r\n");
973 do_ram_command(RAM_COMMAND_NORMAL);
976 /* 6. Finally enable refresh. */
977 PRINT_DEBUG("RAM Enable 6: Enable refresh\r\n");
978 // pci_write_config8(NB, PMCR, 0x10);
979 spd_enable_refresh();
982 PRINT_DEBUG("Northbridge following SDRAM init:\r\n");