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
28 /*-----------------------------------------------------------------------------
29 Macros and definitions.
30 -----------------------------------------------------------------------------*/
32 #define NB PCI_DEV(0, 0, 0)
34 /* Debugging macros. */
35 #if CONFIG_DEBUG_RAM_SETUP
36 #define PRINT_DEBUG(x) print_debug(x)
37 #define PRINT_DEBUG_HEX8(x) print_debug_hex8(x)
38 #define PRINT_DEBUG_HEX16(x) print_debug_hex16(x)
39 #define PRINT_DEBUG_HEX32(x) print_debug_hex32(x)
40 #define DUMPNORTH() dump_pci_device(NB)
42 #define PRINT_DEBUG(x)
43 #define PRINT_DEBUG_HEX8(x)
44 #define PRINT_DEBUG_HEX16(x)
45 #define PRINT_DEBUG_HEX32(x)
49 /* SDRAMC[7:5] - SDRAM Mode Select (SMS). */
50 #define RAM_COMMAND_NORMAL 0x0
51 #define RAM_COMMAND_NOP 0x1
52 #define RAM_COMMAND_PRECHARGE 0x2
53 #define RAM_COMMAND_MRS 0x3
54 #define RAM_COMMAND_CBR 0x4
56 /* Map the JEDEC SPD refresh rates (array index) to 440BX refresh rates as
57 * defined in DRAMC[2:0].
59 * [0] == Normal 15.625 us -> 15.6 us
60 * [1] == Reduced(.25X) 3.9 us -> 7.8 ns
61 * [2] == Reduced(.5X) 7.8 us -> 7.8 us
62 * [3] == Extended(2x) 31.3 us -> 31.2 us
63 * [4] == Extended(4x) 62.5 us -> 62.4 us
64 * [5] == Extended(8x) 125 us -> 124.8 us
66 static const uint32_t refresh_rate_map[] = {
70 /* Table format: register, bitmask, value. */
71 static const u8 register_values[] = {
72 /* NBXCFG - NBX Configuration Register
75 * [31:24] SDRAM Row Without ECC
76 * 0 = ECC components are populated in this row
77 * 1 = ECC components are not populated in this row
79 * [18:18] Host Bus Fast Data Ready Enable (HBFDRE)
80 * Assertion of DRAM data on host bus occurs...
81 * 0 = ...one clock after sampling snoop results (default)
82 * 1 = ...on the same clock the snoop result is being sampled
83 * (this mode is faster by one clock cycle)
84 * [17:17] ECC - EDO static Drive mode
85 * 0 = Normal mode (default)
86 * 1 = ECC signals are always driven
87 * [16:16] IDSEL_REDIRECT
88 * 0 = IDSEL1 is allocated to this bridge (default)
89 * 1 = IDSEL7 is allocated to this bridge
90 * [15:15] WSC# Handshake Disable
91 * 1 = Uni-processor mode
92 * 0 = Dual-processor mode with external IOAPIC (default)
93 * [14:14] Intel Reserved
94 * [13:12] Host/DRAM Frequency
99 * [11:11] AGP to PCI Access Enable
102 * [10:10] PCI Agent to Aperture Access Disable
104 * 0 = Enable (default)
105 * [09:09] Aperture Access Global Enable
108 * [08:07] DRAM Data Integrity Mode (DDIM)
112 * 11 = ECC Mode with hardware scrubbing enabled
113 * [06:06] ECC Diagnostic Mode Enable (EDME)
115 * 0 = Normal operation mode (default)
116 * [05:05] MDA Present (MDAP)
117 * Works in conjunction with the VGA_EN bit.
119 * 0 x All VGA cycles are sent to PCI
120 * 1 0 All VGA cycles are sent to AGP
121 * 1 1 All VGA cycles are sent to AGP, except for
122 * cycles in the MDA range.
124 * [03:03] USWC Write Post During I/O Bridge Access Enable (UWPIO)
127 * [02:02] In-Order Queue Depth (IOQD)
128 * 1 = In-order queue = maximum
129 * 0 = A7# is sampled asserted (i.e., 0)
132 NBXCFG + 0, 0x00, 0x0c,
133 // TODO: Bit 15 should be 0 for multiprocessor boards
134 NBXCFG + 1, 0x00, 0x80,
135 NBXCFG + 2, 0x00, 0x00,
136 NBXCFG + 3, 0x00, 0xff,
138 /* DRAMC - DRAM Control Register
142 * [5:5] Module Mode Configuration (MMCONFIG)
143 * The combination of SDRAMPWR and this bit (which is set by an
144 * external strapping option) determine how CKE works.
146 * 0 0 = 3 DIMM, CKE0[5:0] driven
147 * X 1 = 3 DIMM, CKE0 only
148 * 1 0 = 4 DIMM, GCKE only
149 * [4:3] DRAM Type (DT)
152 * 10 = Registered SDRAM
154 * Note: EDO, SDRAM and Registered SDRAM cannot be mixed.
155 * [2:0] DRAM Refresh Rate (DRR)
156 * 000 = Refresh disabled
165 /* Choose SDRAM (not registered), and disable refresh for now. */
169 * PAM[6:0] - Programmable Attribute Map Registers
172 * 0x59 [3:0] Reserved
173 * 0x59 [5:4] 0xF0000 - 0xFFFFF BIOS area
174 * 0x5a [1:0] 0xC0000 - 0xC3FFF ISA add-on BIOS
175 * 0x5a [5:4] 0xC4000 - 0xC7FFF ISA add-on BIOS
176 * 0x5b [1:0] 0xC8000 - 0xCBFFF ISA add-on BIOS
177 * 0x5b [5:4] 0xCC000 - 0xCFFFF ISA add-on BIOS
178 * 0x5c [1:0] 0xD0000 - 0xD3FFF ISA add-on BIOS
179 * 0x5c [5:4] 0xD4000 - 0xD7FFF ISA add-on BIOS
180 * 0x5d [1:0] 0xD8000 - 0xDBFFF ISA add-on BIOS
181 * 0x5d [5:4] 0xDC000 - 0xDFFFF ISA add-on BIOS
182 * 0x5e [1:0] 0xE0000 - 0xE3FFF BIOS entension
183 * 0x5e [5:4] 0xE4000 - 0xE7FFF BIOS entension
184 * 0x5f [1:0] 0xE8000 - 0xEBFFF BIOS entension
185 * 0x5f [5:4] 0xEC000 - 0xEFFFF BIOS entension
188 * 00 = DRAM Disabled (all access goes to memory mapped I/O space)
189 * 01 = Read Only (Reads to DRAM, writes to memory mapped I/O space)
190 * 10 = Write Only (Writes to DRAM, reads to memory mapped I/O space)
191 * 11 = Read/Write (all access goes to DRAM)
195 * Map all legacy regions to RAM (read/write). This is required if
196 * you want to use the RAM area from 768 KB - 1 MB. If the PAM
197 * registers are not set here appropriately, the RAM in that region
198 * will not be accessible, thus a RAM check of it will also fail.
200 * TODO: This was set in sdram_set_spd_registers().
201 * Test if it still works when set here.
211 /* DRB[0:7] - DRAM Row Boundary Registers
214 * An array of 8 byte registers, which hold the ending memory address
215 * assigned to each pair of DIMMs, in 8MB granularity.
217 * 0x60 DRB0 = Total memory in row0 (in 8 MB)
218 * 0x61 DRB1 = Total memory in row0+1 (in 8 MB)
219 * 0x62 DRB2 = Total memory in row0+1+2 (in 8 MB)
220 * 0x63 DRB3 = Total memory in row0+1+2+3 (in 8 MB)
221 * 0x64 DRB4 = Total memory in row0+1+2+3+4 (in 8 MB)
222 * 0x65 DRB5 = Total memory in row0+1+2+3+4+5 (in 8 MB)
223 * 0x66 DRB6 = Total memory in row0+1+2+3+4+5+6 (in 8 MB)
224 * 0x67 DRB7 = Total memory in row0+1+2+3+4+5+6+7 (in 8 MB)
226 /* Set the DRBs to zero for now, this will be fixed later. */
236 /* FDHC - Fixed DRAM Hole Control Register
239 * Controls two fixed DRAM holes: 512 KB - 640 KB and 15 MB - 16 MB.
241 * [7:6] Hole Enable (HEN)
243 * 01 = 512 KB - 640 KB (128 KB)
244 * 10 = 15 MB - 16 MB (1 MB)
248 /* No memory holes. */
251 /* RPS - SDRAM Row Page Size Register
254 * Sets the row page size for SDRAM. For EDO memory, the page
255 * size is fixed at 2 KB.
257 * Bits[1:0] Page Size
263 * RPS bits Corresponding DRB register
264 * [01:00] DRB[0], row 0
265 * [03:02] DRB[1], row 1
266 * [05:04] DRB[2], row 2
267 * [07:06] DRB[3], row 3
268 * [09:08] DRB[4], row 4
269 * [11:10] DRB[5], row 5
270 * [13:12] DRB[6], row 6
271 * [15:14] DRB[7], row 7
273 /* Power on defaults to 2KB. Will be set later. */
274 // RPS + 0, 0x00, 0x00,
275 // RPS + 1, 0x00, 0x00,
277 /* SDRAMC - SDRAM Control Register
281 * [09:08] Idle/Pipeline DRAM Leadoff Timing (IPDLT)
283 * 01 = Add a clock delay to the lead-off clock count
285 * [07:05] SDRAM Mode Select (SMS)
286 * 000 = Normal SDRAM Operation (default)
287 * 001 = NOP Command Enable
288 * 010 = All Banks Precharge Enable
289 * 011 = Mode Register Set Enable
295 * 0 = 3 DIMM configuration
296 * 1 = 4 DIMM configuration
297 * [03:03] Leadoff Command Timing (LCT)
300 * [02:02] CAS# Latency (CL)
301 * 0 = 3 DCLK CAS# latency
302 * 1 = 2 DCLK CAS# latency
303 * [01:01] SDRAM RAS# to CAS# Delay (SRCD)
304 * 0 = 3 clocks between a row activate and a read or write cmd.
305 * 1 = 2 clocks between a row activate and a read or write cmd.
306 * [00:00] SDRAM RAS# Precharge (SRP)
307 * 0 = 3 clocks of RAS# precharge
308 * 1 = 2 clocks of RAS# precharge
310 #if CONFIG_SDRAMPWR_4DIMM
311 SDRAMC + 0, 0x00, 0x10, /* The board has 4 DIMM slots. */
313 SDRAMC + 0, 0x00, 0x00, /* The board has 3 DIMM slots. */
315 SDRAMC + 1, 0x00, 0x00,
317 /* PGPOL - Paging Policy Register
320 * [15:08] Banks per Row (BPR)
321 * Each bit in this field corresponds to one row of the memory
322 * array. Bit 15 corresponds to row 7 while bit 8 corresponds
323 * to row 0. Bits for empty rows are "don't care".
327 * [04:04] Intel Reserved
328 * [03:00] DRAM Idle Timer (DIT)
337 * 1xxx = Infinite (pages are not closed for idle condition)
339 PGPOL + 0, 0x00, 0x00,
340 PGPOL + 1, 0x00, 0xff,
342 /* PMCR - Power Management Control Register
345 * [07:07] Power Down SDRAM Enable (PDSE)
348 * [06:06] ACPI Control Register Enable (SCRE)
350 * 0 = Disable (default)
351 * [05:05] Suspend Refresh Type (SRT)
352 * 1 = Self refresh mode
354 * [04:04] Normal Refresh Enable (NREF_EN)
357 * [03:03] Quick Start Mode (QSTART)
358 * 1 = Quick start mode for the processor is enabled
359 * [02:02] Gated Clock Enable (GCLKEN)
362 * [01:01] AGP Disable (AGP_DIS)
365 * [00:00] CPU reset without PCIRST enable (CRst_En)
369 /* Enable normal refresh and the gated clock. */
370 // TODO: Only do this later?
374 /* Enable SCRR.SRRAEN and let BX choose the SRR. */
375 SCRR + 1, 0x00, 0x10,
378 /*-----------------------------------------------------------------------------
379 SDRAM configuration functions.
380 -----------------------------------------------------------------------------*/
383 * Send the specified RAM command to all DIMMs.
385 * @param command The RAM command to send to the DIMM(s).
387 static void do_ram_command(u32 command)
390 u8 dimm_start, dimm_end;
392 u32 addr, addr_offset;
394 /* Configure the RAM command. */
395 reg16 = pci_read_config16(NB, SDRAMC);
396 reg16 &= 0xff1f; /* Clear bits 7-5. */
397 reg16 |= (u16) (command << 5); /* Write command into bits 7-5. */
398 pci_write_config16(NB, SDRAMC, reg16);
401 * RAM_COMMAND_NORMAL affects only the memory controller and
402 * doesn't need to be "sent" to the DIMMs.
404 if (command == RAM_COMMAND_NORMAL)
407 /* Send the RAM command to each row of memory. */
409 for (i = 0; i < (DIMM_SOCKETS * 2); i++) {
411 caslatency = 3; /* TODO: Dynamically get CAS latency later. */
412 if (command == RAM_COMMAND_MRS) {
414 * MAA[12:11,9:0] must be inverted when sent to DIMM
415 * 2 or 3 (no inversion if sent to DIMM 0 or 1).
417 if ((i >= 0 && i <= 3) && caslatency == 3)
419 if ((i >= 4 && i <= 7) && caslatency == 3)
420 addr_offset = 0x1e28;
421 if ((i >= 0 && i <= 3) && caslatency == 2)
423 if ((i >= 4 && i <= 7) && caslatency == 2)
424 addr_offset = 0x1ea8;
427 dimm_end = pci_read_config8(NB, DRB + i);
429 addr = (dimm_start * 8 * 1024 * 1024) + addr_offset;
430 if (dimm_end > dimm_start) {
432 PRINT_DEBUG(" Sending RAM command 0x");
433 PRINT_DEBUG_HEX16(reg16);
434 PRINT_DEBUG(" to 0x");
435 PRINT_DEBUG_HEX32(addr);
442 /* Set the start of the next DIMM. */
443 dimm_start = dimm_end;
447 static void set_dram_buffer_strength(void)
449 /* To give some breathing room for romcc,
450 * mbsc0 doubles as drb
451 * mbsc1 doubles as drb1
452 * mbfs0 doubles as i and reg
454 uint8_t mbsc0,mbsc1,mbsc3,mbsc4,mbfs0,mbfs2,fsb;
456 /* Tally how many rows between rows 0-3 and rows 4-7 are populated.
457 * This determines how to program MBFS and MBSC.
463 for (mbfs0 = DRB0; mbfs0 <= DRB7; mbfs0++) {
464 mbsc1 = pci_read_config8(NB, mbfs0);
465 if (mbsc0 != mbsc1) {
475 /* Algorithm bitmap for programming MBSC[39:0] and MBFS[23:0].
477 * The 440BX datasheet says buffer frequency is independent from bus
478 * frequency and mismatch both ways are possible. This is how it is
479 * programmed in the ASUS P2B-LS mainboard.
481 * There are four main conditions to check when programming DRAM buffer
482 * frequency and strength:
484 * a: >2 rows populated across DIMM0,1
485 * b: >2 rows populated across DIMM2,3
486 * c: >4 rows populated across all DIMM slots
488 * 1: NBXCFG[13] strapped as 100MHz, or
489 * 6: NBXCFG[13] strapped as 66MHz
491 * CKE0/FENA ----------------------------------------------------------+
492 * CKE1/GCKE -------------------[ MBFS ]------------------------+|
493 * DQMA/CASA[764320]# ----------[ 0 = 66MHz ]-----------------------+||
494 * DQMB1/CASB1# ----------------[ 1 = 100MHz ]----------------------+|||
495 * DQMB5/CASB5# ---------------------------------------------------+||||
496 * DQMA1/CASA1# --------------------------------------------------+|||||
497 * DQMA5/CASA5# -------------------------------------------------+||||||
498 * CSA0-5#,CSB0-5# ----------------------------------------++++++|||||||
499 * CSA6#/CKE2# -------------------------------------------+|||||||||||||
500 * CSB6#/CKE4# ------------------------------------------+||||||||||||||
501 * CSA7#/CKE3# -----------------------------------------+|||||||||||||||
502 * CSB7#/CKE5# ----------------------------------------+||||||||||||||||
503 * MECC[7:0] #2/#1 (100MHz) -------------------------++|||||||||||||||||
504 * MD[63:0] #2/#1 (100MHz) ------------------------++|||||||||||||||||||
505 * MAB[12:11,9:0]#,MAB[13,10],WEB#,SRASB#,SCASB# -+|||||||||||||||||||||
506 * MAA[13:0],WEA#,SRASA#,SCASA# -----------------+||||||||||||||||||||||
507 * Reserved ------------------------------------+|||||||||||||||||||||||
508 * ||||||||||||||||||||||||
509 * 3 32 21 10 0 * 2 21 10 0
510 * 9876543210987654321098765432109876543210 * 321098765432109876543210
511 * a 10------------------------1010---------- * -1---------------11----- a
512 *!a 11------------------------1111---------- * -0---------------00----- !a
513 * b --10--------------------------1010------ * --1----------------11--- b
514 *!b --11--------------------------1111------ * --0----------------00--- !b
515 * c ----------------------------------1100-- * ----------------------1- c
516 *!c ----------------------------------1011-- * ----------------------0- !c
517 * 1 ----1010101000000000000000------------00 * ---11111111111111----1-0 1
518 * 6 ----000000000000000000000010101010----00 * ---1111111111111100000-0 6
519 * | | | | | | | | | | ||||||| | | | | | |
520 * | | | | | | | | | | ||||||| | | | | | +- CKE0/FENA
521 * | | | | | | | | | | ||||||| | | | | +--- CKE1/GCKE
522 * | | | | | | | | | | ||||||| | | | +----- DQMA/CASA[764320]#
523 * | | | | | | | | | | ||||||| | | +------- DQMB1/CASB1#
524 * | | | | | | | | | | ||||||| | +--------- DQMB5/CASB5#
525 * | | | | | | | | | | ||||||| +----------- DQMA1/CASA1#
526 * | | | | | | | | | | ||||||+------------- DQMA5/CASA5#
527 * | | | | | | | | | | ++++++-------------- CSA0-5#,CSB0-5# [ 0=1x;1=2x ]
528 * | | | | | | | | | +--------------------- CSA6#/CKE2#
529 * | | | | | | | | +---[ MBSC ]------ CSB6#/CKE4#
530 * | | | | | | | +-----[ 00 = 1x ]------ CSA7#/CKE3#
531 * | | | | | | +-------[ 01 invalid ]------ CSB7#/CKE5#
532 * | | | | | +---------[ 10 = 2x ]------ MECC[7:0] #1 (2x)
533 * | | | | +-----------[ 11 = 3x ]------ MECC[7:0] #2 (2x)
534 * | | | +--------------------------------- MD[63:0] #1 (2x)
535 * | | +----------------------------------- MD[63:0] #2 (2x)
536 * | +------------------------------------- MAB[12:11,9:0]#,MAB[13,10],WEB#,SRASB#,SCASB#
537 * +--------------------------------------- MAA[13:0],WEA#,SRASA#,SCASA#
538 * MBSC[47:40] and MBFS[23] are reserved.
540 * This algorithm is checked against the ASUS P2B-LS (which has
541 * 4 DIMM slots) factory BIOS.
542 * Therefore it assumes a board with 4 slots, and will need testing
543 * on boards with 3 DIMM slots.
549 if (pci_read_config8(NB, NBXCFG + 1) & 0x30) {
562 mbsc4 = mbsc4 | 0x80;
563 mbsc1 = mbsc1 | 0x28;
564 mbfs2 = mbfs2 | 0x40;
565 mbfs0 = mbfs0 | 0x60;
567 mbsc4 = mbsc4 | 0xc0;
569 mbsc1 = mbsc1 | 0x3c;
573 mbsc4 = mbsc4 | 0x20;
574 mbsc1 = mbsc1 | 0x02;
575 mbsc0 = mbsc0 | 0x80;
576 mbfs2 = mbfs2 | 0x20;
577 mbfs0 = mbfs0 | 0x18;
579 mbsc4 = mbsc4 | 0x30;
581 mbsc1 = mbsc1 | 0x03;
582 mbsc0 = mbsc0 | 0xc0;
585 if ((dimm03 + dimm47) > 4) {
586 mbsc0 = mbsc0 | 0x30;
587 mbfs0 = mbfs0 | 0x02;
589 mbsc0 = mbsc0 | 0x2c;
592 pci_write_config8(NB, MBSC + 0, mbsc0);
593 pci_write_config8(NB, MBSC + 1, mbsc1);
594 pci_write_config8(NB, MBSC + 2, 0x00);
595 pci_write_config8(NB, MBSC + 3, mbsc3);
596 pci_write_config8(NB, MBSC + 4, mbsc4);
597 pci_write_config8(NB, MBFS + 0, mbfs0);
598 pci_write_config8(NB, MBFS + 1, 0xff);
599 pci_write_config8(NB, MBFS + 2, mbfs2);
602 /*-----------------------------------------------------------------------------
603 DIMM-independant configuration functions.
604 -----------------------------------------------------------------------------*/
606 static void spd_enable_refresh(void)
611 reg = pci_read_config8(NB, DRAMC);
613 for (i = 0; i < DIMM_SOCKETS; i++) {
614 value = spd_read_byte(DIMM_SPD_BASE + i, SPD_REFRESH);
617 reg = (reg & 0xf8) | refresh_rate_map[(value & 0x7f)];
619 PRINT_DEBUG(" Enabling refresh (DRAMC = 0x");
620 PRINT_DEBUG_HEX8(reg);
621 PRINT_DEBUG(") for DIMM ");
626 pci_write_config8(NB, DRAMC, reg);
629 /*-----------------------------------------------------------------------------
631 -----------------------------------------------------------------------------*/
633 static void sdram_set_registers(void)
638 PRINT_DEBUG("Northbridge prior to SDRAM init:\n");
641 max = ARRAY_SIZE(register_values);
643 /* Set registers as specified in the register_values[] array. */
644 for (i = 0; i < max; i += 3) {
645 reg = pci_read_config8(NB, register_values[i]);
646 reg &= register_values[i + 1];
647 reg |= register_values[i + 2] & ~(register_values[i + 1]);
648 pci_write_config8(NB, register_values[i], reg);
650 PRINT_DEBUG(" Set register 0x");
651 PRINT_DEBUG_HEX8(register_values[i]);
652 PRINT_DEBUG(" to 0x");
653 PRINT_DEBUG_HEX8(reg);
664 static struct dimm_size spd_get_dimm_size(unsigned int device)
667 int i, module_density, dimm_banks;
669 module_density = spd_read_byte(device, SPD_DENSITY_OF_EACH_ROW_ON_MODULE);
670 dimm_banks = spd_read_byte(device, SPD_NUM_DIMM_BANKS);
672 /* Find the size of side1. */
673 /* Find the larger value. The larger value is always side1. */
674 for (i = 512; i >= 0; i >>= 1) {
675 if ((module_density & i) == i) {
681 /* Set to 0 in case it's single sided. */
684 /* Test if it's a dual-sided DIMM. */
685 if (dimm_banks > 1) {
686 /* Test if there's a second value. If so it's asymmetrical. */
687 if (module_density != i) {
689 * Find second value, picking up where we left off.
690 * i >>= 1 done initially to make sure we don't get
691 * the same value again.
693 for (i >>= 1; i >= 0; i >>= 1) {
694 if (module_density == (sz.side1 | i)) {
699 /* If not, it's symmetrical. */
706 * SPD byte 31 is the memory size divided by 4 so we
707 * need to muliply by 4 to get the total size.
712 /* It is possible to partially use larger then supported
713 * modules by setting them to a supported size.
716 PRINT_DEBUG("Side1 was 0x");
717 PRINT_DEBUG_HEX16(sz.side1);
718 PRINT_DEBUG(" but only 128MB will be used.\n");
722 PRINT_DEBUG("Side2 was 0x");
723 PRINT_DEBUG_HEX16(sz.side2);
724 PRINT_DEBUG(" but only 128MB will be used.\n");
732 * Sets DRAM attributes one DIMM at a time, based on SPD data.
733 * Northbridge settings that are set: NBXCFG[31:24], DRB0-DRB7, RPS, DRAMC.
735 static void set_dram_row_attributes(void)
737 int i, dra, drb, col, width, value, rps, edosd, ecc, nbxecc;
738 u8 bpr; /* Top 8 bits of PGPOL */
746 for (i = 0; i < DIMM_SOCKETS; i++) {
748 device = DIMM_SPD_BASE + i;
751 /* First check if a DIMM is actually present. */
752 value = spd_read_byte(device, SPD_MEMORY_TYPE);
753 /* This is 440BX! We do EDO too! */
754 if (value == SPD_MEMORY_TYPE_EDO
755 || value == SPD_MEMORY_TYPE_SDRAM) {
757 PRINT_DEBUG("Found ");
758 if (value == SPD_MEMORY_TYPE_EDO) {
760 } else if (value == SPD_MEMORY_TYPE_SDRAM) {
763 PRINT_DEBUG("DIMM in slot ");
768 print_err("Mixing EDO/SDRAM unsupported!\n");
772 /* "DRA" is our RPS for the two rows on this DIMM. */
776 col = spd_read_byte(device, SPD_NUM_COLUMNS);
779 * Is this an ECC DIMM? Actually will be a 2 if so.
780 * TODO: Other register than NBXCFG also needs this
783 ecc = spd_read_byte(device, SPD_DIMM_CONFIG_TYPE);
786 width = spd_read_byte(device, SPD_MODULE_DATA_WIDTH_LSB);
788 /* Exclude error checking data width from page size calculations */
790 value = spd_read_byte(device,
791 SPD_ERROR_CHECKING_SDRAM_WIDTH);
794 /* Clear top 2 bits to help set up NBXCFG. */
797 /* Without ECC, top 2 bits should be 11. */
801 /* Calculate page size in bits. */
802 value = ((1 << col) * width);
807 /* Number of banks of DIMM (single or double sided). */
808 value = spd_read_byte(device, SPD_NUM_DIMM_BANKS);
810 /* Once we have dra, col is done and can be reused.
811 * So it's reused for number of banks.
813 col = spd_read_byte(device, SPD_NUM_BANKS_PER_SDRAM);
817 * Second bank of 1-bank DIMMs "doesn't have
818 * ECC" - or anything.
823 } else if (dra == 4) {
825 } else if (dra == 8) {
827 } else if (dra >= 16) {
828 /* Page sizes larger than supported are
829 * set to 8KB to use module partially.
831 PRINT_DEBUG("Page size forced to 8KB.\n");
837 * Sets a flag in PGPOL[BPR] if this DIMM has
842 } else if (value == 2) {
845 } else if (dra == 4) {
846 dra = 0x05; /* 4KB */
847 } else if (dra == 8) {
848 dra = 0x0a; /* 8KB */
849 } else if (dra >= 16) {
851 PRINT_DEBUG("Page size forced to 8KB.\n");
852 dra = 0x0a; /* 8KB */
860 print_err("# of banks of DIMM unsupported!\n");
864 print_err("Page size not supported\n");
869 * 440BX supports asymmetrical dual-sided DIMMs,
870 * but can't handle DIMMs smaller than 8MB per
873 struct dimm_size sz = spd_get_dimm_size(device);
874 if ((sz.side1 < 8)) {
875 print_err("DIMMs smaller than 8MB per side\n"
876 "are not supported on this NB.\n");
880 /* Divide size by 8 to set up the DRB registers. */
881 drb += (sz.side1 / 8);
884 * Build the DRB for the next row in MSB so it gets
885 * placed in DRB[n+1] where it belongs when written
889 drb |= (drb + (sz.side2 / 8)) << 8;
892 PRINT_DEBUG("No DIMM found in slot ");
897 /* If there's no DIMM in the slot, set dra to 0x00. */
900 /* Still have to propagate DRB over. */
905 pci_write_config16(NB, DRB + (2 * i), drb);
907 PRINT_DEBUG("DRB has been set to 0x");
908 PRINT_DEBUG_HEX16(drb);
912 /* Brings the upper DRB back down to be base for
913 * DRB calculations for the next two rows.
917 rps |= (dra & 0x0f) << (i * 4);
918 nbxecc = (nbxecc >> 2) | (ecc & 0xc0);
921 /* Set paging policy register. */
922 pci_write_config8(NB, PGPOL + 1, bpr);
923 PRINT_DEBUG("PGPOL[BPR] has been set to 0x");
924 PRINT_DEBUG_HEX8(bpr);
927 /* Set DRAM row page size register. */
928 pci_write_config16(NB, RPS, rps);
929 PRINT_DEBUG("RPS has been set to 0x");
930 PRINT_DEBUG_HEX16(rps);
934 pci_write_config8(NB, NBXCFG + 3, nbxecc);
935 PRINT_DEBUG("NBXECC[31:24] has been set to 0x");
936 PRINT_DEBUG_HEX8(nbxecc);
939 /* Set DRAMC[4:3] to proper memory type (EDO/SDRAM).
940 * TODO: Registered SDRAM support.
945 } else if (edosd & 0x04) {
950 /* edosd is now in the form needed for DRAMC[4:3]. */
951 value = pci_read_config8(NB, DRAMC) & 0xe7;
953 pci_write_config8(NB, DRAMC, value);
954 PRINT_DEBUG("DRAMC has been set to 0x");
955 PRINT_DEBUG_HEX8(value);
959 static void sdram_set_spd_registers(void)
961 /* Setup DRAM row boundary registers and other attributes. */
962 set_dram_row_attributes();
964 /* Setup DRAM buffer strength. */
965 set_dram_buffer_strength();
967 /* TODO: Set PMCR? */
968 // pci_write_config8(NB, PMCR, 0x14);
969 pci_write_config8(NB, PMCR, 0x10);
971 /* TODO: This is for EDO memory only. */
972 pci_write_config8(NB, DRAMT, 0x03);
975 static void sdram_enable(void)
979 /* 0. Wait until power/voltages and clocks are stable (200us). */
982 /* 1. Apply NOP. Wait 200 clock cycles (200us should do). */
983 PRINT_DEBUG("RAM Enable 1: Apply NOP\n");
984 do_ram_command(RAM_COMMAND_NOP);
987 /* 2. Precharge all. Wait tRP. */
988 PRINT_DEBUG("RAM Enable 2: Precharge all\n");
989 do_ram_command(RAM_COMMAND_PRECHARGE);
992 /* 3. Perform 8 refresh cycles. Wait tRC each time. */
993 PRINT_DEBUG("RAM Enable 3: CBR\n");
994 for (i = 0; i < 8; i++) {
995 do_ram_command(RAM_COMMAND_CBR);
999 /* 4. Mode register set. Wait two memory cycles. */
1000 PRINT_DEBUG("RAM Enable 4: Mode register set\n");
1001 do_ram_command(RAM_COMMAND_MRS);
1004 /* 5. Normal operation. */
1005 PRINT_DEBUG("RAM Enable 5: Normal operation\n");
1006 do_ram_command(RAM_COMMAND_NORMAL);
1009 /* 6. Finally enable refresh. */
1010 PRINT_DEBUG("RAM Enable 6: Enable refresh\n");
1011 // pci_write_config8(NB, PMCR, 0x10);
1012 spd_enable_refresh();
1015 PRINT_DEBUG("Northbridge following SDRAM init:\n");