Move C labels to start-of-line
[coreboot.git] / src / northbridge / intel / i945 / raminit.c
index 3084072389e8bb7ffa23c84155f883b15cf96dad..a4512d7ba80743c5d5561fb4d5cffe955399b513 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <cpu/x86/mem.h>
+#include <console/console.h>
 #include <cpu/x86/mtrr.h>
 #include <cpu/x86/cache.h>
+#include <pc80/mc146818rtc.h>
 #include <spd.h>
+#include <string.h>
+#include <arch/romcc_io.h>
 #include "raminit.h"
 #include "i945.h"
+#include <cbmem.h>
 
-#define DEBUG_RAM_SETUP
+struct cbmem_entry *get_cbmem_toc(void)
+{
+       return (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE);
+}
 
 /* Debugging macros. */
-#if defined(DEBUG_RAM_SETUP)
-#define PRINTK_DEBUG(x...)     printk_debug(x)
+#if CONFIG_DEBUG_RAM_SETUP
+#define PRINTK_DEBUG(x...)     printk(BIOS_DEBUG, x)
 #else
 #define PRINTK_DEBUG(x...)
 #endif
 #define RAM_EMRS_2                     (0x1 << 21)
 #define RAM_EMRS_3                     (0x2 << 21)
 
-static void do_ram_command(u32 command)
+static int get_dimm_spd_address(struct sys_info *sysinfo, int device)
+{
+       if (sysinfo->spd_addresses)
+               return sysinfo->spd_addresses[device];
+       else
+               return DIMM0 + device;
+
+}
+
+static inline int spd_read_byte(unsigned device, unsigned address)
+{
+       return smbus_read_byte(device, address);
+}
+
+static __attribute__((noinline)) void do_ram_command(u32 command)
 {
        u32 reg32;
 
@@ -64,6 +85,8 @@ static void do_ram_command(u32 command)
        MCHBAR32(DCC) = reg32;  /* This is the actual magic */
 
        PRINTK_DEBUG("...done\n");
+
+       udelay(1);
 }
 
 static void ram_read32(u32 offset)
@@ -73,29 +96,68 @@ static void ram_read32(u32 offset)
        read32(offset);
 }
 
-#ifdef DEBUG_RAM_SETUP
-static void sdram_dump_mchbar_registers(void)
+#if CONFIG_DEBUG_RAM_SETUP
+void sdram_dump_mchbar_registers(void)
 {
        int i;
-       printk_debug("Dumping MCHBAR Registers\n");
+       printk(BIOS_DEBUG, "Dumping MCHBAR Registers\n");
 
        for (i=0; i<0xfff; i+=4) {
                if (MCHBAR32(i) == 0)
                        continue;
-               printk_debug("0x%04x: 0x%08x\n", i, MCHBAR32(i));
+               printk(BIOS_DEBUG, "0x%04x: 0x%08x\n", i, MCHBAR32(i));
        }
 }
 #endif
 
+static int memclk(void)
+{
+       int offset = 0;
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
+       offset++;
+#endif
+       switch (((MCHBAR32(CLKCFG) >> 4) & 7) - offset) {
+       case 1: return 400;
+       case 2: return 533;
+       case 3: return 667;
+       default: printk(BIOS_DEBUG, "memclk: unknown register value %x\n", ((MCHBAR32(CLKCFG) >> 4) & 7) - offset);
+       }
+       return -1;
+}
+
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
+static u16 fsbclk(void)
+{
+       switch (MCHBAR32(CLKCFG) & 7) {
+       case 0: return 400;
+       case 1: return 533;
+       case 3: return 667;
+       default: printk(BIOS_DEBUG, "fsbclk: unknown register value %x\n", MCHBAR32(CLKCFG) & 7);
+       }
+       return 0xffff;
+}
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
+static u16 fsbclk(void)
+{
+       switch (MCHBAR32(CLKCFG) & 7) {
+       case 0: return 1066;
+       case 1: return 533;
+       case 2: return 800;
+       default: printk(BIOS_DEBUG, "fsbclk: unknown register value %x\n", MCHBAR32(CLKCFG) & 7);
+       }
+       return 0xffff;
+}
+#endif
+
 static int sdram_capabilities_max_supported_memory_frequency(void)
 {
        u32 reg32;
 
-#ifdef MAXIMUM_SUPPORTED_FREQUENCY
-       return MAXIMUM_SUPPORTED_FREQUENCY;
+#if CONFIG_MAXIMUM_SUPPORTED_FREQUENCY
+       return CONFIG_MAXIMUM_SUPPORTED_FREQUENCY;
 #endif
 
-       reg32 = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xe4);
+       reg32 = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xe4); /* CAPID0 + 4 */
        reg32 &= (7 << 0);
 
        switch (reg32) {
@@ -119,7 +181,7 @@ static int sdram_capabilities_interleave(void)
 {
        u32 reg32;
 
-       reg32 = pci_read_config8(PCI_DEV(0, 0x00,0), 0xe4);
+       reg32 = pci_read_config32(PCI_DEV(0, 0x00,0), 0xe4); /* CAPID0 + 4 */
        reg32 >>= 25;
        reg32 &= 1;
 
@@ -135,7 +197,7 @@ static int sdram_capabilities_dual_channel(void)
 {
        u32 reg32;
 
-       reg32 = pci_read_config8(PCI_DEV(0, 0x00,0), 0xe4);
+       reg32 = pci_read_config32(PCI_DEV(0, 0x00,0), 0xe4); /* CAPID0 + 4 */
        reg32 >>= 24;
        reg32 &= 1;
 
@@ -162,15 +224,18 @@ static int sdram_capabilities_two_dimms_per_channel(void)
        return (reg8 != 0);
 }
 
+// TODO check if we ever need this function
+#if 0
 static int sdram_capabilities_MEM4G_disable(void)
 {
        u8 reg8;
 
-       reg8 = pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe5);
+       reg8 = pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe5); /* CAPID0 + 5 */
        reg8 &= (1 << 0);
 
        return (reg8 != 0);
 }
+#endif
 
 #define GFX_FREQUENCY_CAP_166MHZ       0x04
 #define GFX_FREQUENCY_CAP_200MHZ       0x03
@@ -188,7 +253,7 @@ static int sdram_capabilities_core_frequencies(void)
        return (reg8);
 }
 
-static void sdram_detect_errors(void)
+static void sdram_detect_errors(struct sys_info *sysinfo)
 {
        u8 reg8;
        u8 do_reset = 0;
@@ -197,14 +262,15 @@ static void sdram_detect_errors(void)
 
        if (reg8 & ((1<<7)|(1<<2))) {
                if (reg8 & (1<<2)) {
-                       printk_debug("SLP S4# Assertion Width Violation.\n");
-
+                       printk(BIOS_DEBUG, "SLP S4# Assertion Width Violation.\n");
+                       /* Write back clears bit 2 */
                        pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8);
+                       do_reset = 1;
 
                }
 
                if (reg8 & (1<<7)) {
-                       printk_debug("DRAM initialization was interrupted.\n");
+                       printk(BIOS_DEBUG, "DRAM initialization was interrupted.\n");
                        reg8 &= ~(1<<7);
                        pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8);
                        do_reset = 1;
@@ -216,10 +282,10 @@ static void sdram_detect_errors(void)
                pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
 
                if (do_reset) {
-                       printk_debug("Reset required.\n");
+                       printk(BIOS_DEBUG, "Reset required.\n");
                        outb(0x00, 0xcf9);
                        outb(0x0e, 0xcf9);
-                       for (;;) ; /* Wait for reset! */
+                       for (;;) asm("hlt"); /* Wait for reset! */
                }
        }
 
@@ -228,6 +294,29 @@ static void sdram_detect_errors(void)
        reg8 |= (1<<7);
        pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8);
 
+       /* clear self refresh status if check is disabled or not a resume */
+       if (!CONFIG_CHECK_SLFRCS_ON_RESUME || sysinfo->boot_path != 2) {
+               MCHBAR8(0xf14) |= 3;
+       } else {
+               /* Validate self refresh config */
+               if (((sysinfo->dimm[0] != SYSINFO_DIMM_NOT_POPULATED) ||
+                    (sysinfo->dimm[1] != SYSINFO_DIMM_NOT_POPULATED)) &&
+                   !(MCHBAR8(0xf14) & (1<<0))) {
+                       do_reset = 1;
+               }
+               if (((sysinfo->dimm[2] != SYSINFO_DIMM_NOT_POPULATED) ||
+                    (sysinfo->dimm[3] != SYSINFO_DIMM_NOT_POPULATED)) &&
+                   !(MCHBAR8(0xf14) & (1<<1))) {
+                       do_reset = 1;
+               }
+       }
+
+       if (do_reset) {
+               printk(BIOS_DEBUG, "Reset required.\n");
+               outb(0x00, 0xcf9);
+               outb(0x0e, 0xcf9);
+               for (;;) asm("hlt"); /* Wait for reset! */
+       }
 }
 
 /**
@@ -249,23 +338,22 @@ static void sdram_get_dram_configuration(struct sys_info *sysinfo)
        /**
         * i945 supports two DIMMs, in two configurations:
         *
-        * - single channel with two dimms
-        * - dual channel with one dimm per channel
+        * - single channel with two DIMMs
+        * - dual channel with one DIMM per channel
         *
-        * In practice dual channel mainboards have their spd at 0x50, 0x52
-        * whereas single channel configurations have their spd at 0x50/x51
+        * In practice dual channel mainboards have their SPD at 0x50/0x52
+        * whereas single channel configurations have their SPD at 0x50/0x51.
         *
         * The capability register knows a lot about the channel configuration
-        * but for now we stick with the information we gather from the SPD
-        * ROMs
+        * but for now we stick with the information we gather via SPD.
         */
 
        if (sdram_capabilities_dual_channel()) {
                sysinfo->dual_channel = 1;
-               printk_debug("This mainboard supports Dual Channel Operation.\n");
+               printk(BIOS_DEBUG, "This mainboard supports Dual Channel Operation.\n");
        } else {
                sysinfo->dual_channel = 0;
-               printk_debug("This mainboard supports only Single Channel Operation.\n");
+               printk(BIOS_DEBUG, "This mainboard supports only Single Channel Operation.\n");
        }
 
        /**
@@ -288,7 +376,8 @@ static void sdram_get_dram_configuration(struct sys_info *sysinfo)
         */
 
        for (i=0; i<(2 * DIMM_SOCKETS); i++) {
-               u8 reg8, device = DIMM_SPD_BASE + i;
+               int device = get_dimm_spd_address(sysinfo, i);
+               u8 reg8;
 
                /* Initialize the socket information with a sane value */
                sysinfo->dimm[i] = SYSINFO_DIMM_NOT_POPULATED;
@@ -301,10 +390,10 @@ static void sdram_get_dram_configuration(struct sys_info *sysinfo)
                if (!sdram_capabilities_two_dimms_per_channel() && (i& 1))
                        continue;
 
-               printk_debug("DDR II Channel %d Socket %d: ", (i >> 1), (i & 1));
+               printk(BIOS_DEBUG, "DDR II Channel %d Socket %d: ", (i >> 1), (i & 1));
 
                if (spd_read_byte(device, SPD_MEMORY_TYPE) != SPD_MEMORY_TYPE_SDRAM_DDR2) {
-                       printk_debug("N/A\n");
+                       printk(BIOS_DEBUG, "N/A\n");
                        continue;
                }
 
@@ -322,29 +411,29 @@ static void sdram_get_dram_configuration(struct sys_info *sysinfo)
                case 0x08:
                        switch (spd_read_byte(device, SPD_NUM_DIMM_BANKS) & 0x0f) {
                        case 1:
-                               printk_debug("x8DDS\n");
+                               printk(BIOS_DEBUG, "x8DDS\n");
                                sysinfo->dimm[i] = SYSINFO_DIMM_X8DDS;
                                break;
                        case 0:
-                               printk_debug("x8DS\n");
+                               printk(BIOS_DEBUG, "x8DS\n");
                                sysinfo->dimm[i] = SYSINFO_DIMM_X8DS;
                                break;
                        default:
-                               printk_debug ("Unsupported.\n");
+                               printk(BIOS_DEBUG, "Unsupported.\n");
                        }
                        break;
                case 0x10:
                        switch (spd_read_byte(device, SPD_NUM_DIMM_BANKS) & 0x0f) {
                        case 1:
-                               printk_debug("x16DS\n");
+                               printk(BIOS_DEBUG, "x16DS\n");
                                sysinfo->dimm[i] = SYSINFO_DIMM_X16DS;
                                break;
                        case 0:
-                               printk_debug("x16SS\n");
+                               printk(BIOS_DEBUG, "x16SS\n");
                                sysinfo->dimm[i] = SYSINFO_DIMM_X16SS;
                                break;
                        default:
-                               printk_debug ("Unsupported.\n");
+                               printk(BIOS_DEBUG, "Unsupported.\n");
                        }
                        break;
                default:
@@ -358,12 +447,8 @@ static void sdram_get_dram_configuration(struct sys_info *sysinfo)
                die("No memory installed.\n");
        }
 
-       /* The chipset might be able to do this. What the heck, legacy bios
-        * just beeps when a single DIMM is in the Channel 1 socket. So let's
-        * not bother until someone needs this enough to cope with it.
-        */
        if (!(dimm_mask & ((1 << DIMM_SOCKETS) - 1))) {
-               printk_err("Channel 0 has no memory populated. This setup is not usable. Please move the DIMM.\n");
+               printk(BIOS_INFO, "Channel 0 has no memory populated.\n");
        }
 }
 
@@ -383,7 +468,7 @@ static void sdram_verify_package_type(struct sys_info * sysinfo)
                        continue;
 
                /* Is the current DIMM a stacked DIMM? */
-               if (spd_read_byte(DIMM_SPD_BASE + i, SPD_NUM_DIMM_BANKS) & (1 << 4))
+               if (spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_NUM_DIMM_BANKS) & (1 << 4))
                        sysinfo->package = 1;
        }
 }
@@ -400,7 +485,8 @@ static u8 sdram_possible_cas_latencies(struct sys_info * sysinfo)
 
        for (i=0; i<2*DIMM_SOCKETS; i++) {
                if (sysinfo->dimm[i] != SYSINFO_DIMM_NOT_POPULATED)
-                       cas_mask &= spd_read_byte(DIMM_SPD_BASE + i, SPD_ACCEPTABLE_CAS_LATENCIES);
+                       cas_mask &= spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                                 SPD_ACCEPTABLE_CAS_LATENCIES);
        }
 
        if(!cas_mask) {
@@ -414,7 +500,7 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
 {
        int i, j, idx;
        int lowest_common_cas = 0;
-       int max_ram_speed;
+       int max_ram_speed = 0;
 
        const u8 ddr2_speeds_table[] = {
                0x50, 0x60,     /* DDR2 400: tCLK = 5.0ns  tAC = 0.6ns  */
@@ -434,6 +520,9 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
        case 667: max_ram_speed = 2; break;
        }
 
+       if (fsbclk() == 533)
+               max_ram_speed = 1;
+
        sysinfo->memory_frequency = 0;
        sysinfo->cas = 0;
 
@@ -451,6 +540,7 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
 
                PRINTK_DEBUG("Probing Speed %d\n", j);
                for (i=0; i<2*DIMM_SOCKETS; i++) {
+                       int device = get_dimm_spd_address(sysinfo, i);
                        int current_cas_mask;
 
                        PRINTK_DEBUG("  DIMM: %d\n", i);
@@ -458,7 +548,7 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
                                continue;
                        }
 
-                       current_cas_mask = spd_read_byte(DIMM_SPD_BASE + i, SPD_ACCEPTABLE_CAS_LATENCIES);
+                       current_cas_mask = spd_read_byte(device, SPD_ACCEPTABLE_CAS_LATENCIES);
 
                        while (current_cas_mask) {
                                int highest_supported_cas = 0, current_cas = 0;
@@ -469,6 +559,8 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
                                        highest_supported_cas = 4;
                                } else if (current_cas_mask & SPD_CAS_LATENCY_DDR2_3) {
                                        highest_supported_cas = 3;
+                               } else {
+                                       die("Invalid max. CAS.\n");
                                }
                                if (current_cas_mask & SPD_CAS_LATENCY_DDR2_3) {
                                        current_cas = 3;
@@ -476,15 +568,17 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
                                        current_cas = 4;
                                } else if (current_cas_mask & SPD_CAS_LATENCY_DDR2_5) {
                                        current_cas = 5;
+                               } else {
+                                       die("Invalid CAS.\n");
                                }
 
                                idx = highest_supported_cas - current_cas;
                                PRINTK_DEBUG("idx=%d, ", idx);
-                               PRINTK_DEBUG("tCLK=%x, ", spd_read_byte(DIMM_SPD_BASE + i, spd_lookup_table[2*idx]));
-                               PRINTK_DEBUG("tAC=%x", spd_read_byte(DIMM_SPD_BASE + i, spd_lookup_table[(2*idx)+1]));
+                               PRINTK_DEBUG("tCLK=%x, ", spd_read_byte(device, spd_lookup_table[2*idx]));
+                               PRINTK_DEBUG("tAC=%x", spd_read_byte(device, spd_lookup_table[(2*idx)+1]));
 
-                               if (spd_read_byte(DIMM_SPD_BASE + i, spd_lookup_table[2*idx]) <= ddr2_speeds_table[2*j] &&
-                                               spd_read_byte(DIMM_SPD_BASE + i, spd_lookup_table[(2*idx)+1]) <= ddr2_speeds_table[(2*j)+1]) {
+                               if (spd_read_byte(device, spd_lookup_table[2*idx]) <= ddr2_speeds_table[2*j] &&
+                                               spd_read_byte(device, spd_lookup_table[(2*idx)+1]) <= ddr2_speeds_table[(2*j)+1]) {
                                        PRINTK_DEBUG(":    OK\n");
                                        break;
                                }
@@ -519,7 +613,7 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
        }
 
        if (sysinfo->memory_frequency && sysinfo->cas) {
-               printk_debug("Memory will be driven at %dMHz with CAS=%d clocks\n",
+               printk(BIOS_DEBUG, "Memory will be driven at %dMHz with CAS=%d clocks\n",
                                sysinfo->memory_frequency, sysinfo->cas);
        } else {
                die("Could not find common memory frequency and CAS\n");
@@ -548,7 +642,7 @@ static void sdram_detect_smallest_tRAS(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM_SPD_BASE + i, SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY);
                if (!reg8) {
                        die("Invalid tRAS value.\n");
                }
@@ -562,7 +656,7 @@ static void sdram_detect_smallest_tRAS(struct sys_info * sysinfo)
                die("DDR-II Module does not support this frequency (tRAS error)\n");
        }
 
-       printk_debug("tRAS = %d cycles\n", tRAS_cycles);
+       printk(BIOS_DEBUG, "tRAS = %d cycles\n", tRAS_cycles);
        sysinfo->tras = tRAS_cycles;
 }
 
@@ -588,7 +682,7 @@ static void sdram_detect_smallest_tRP(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM_SPD_BASE + i, SPD_MIN_ROW_PRECHARGE_TIME);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_MIN_ROW_PRECHARGE_TIME);
                if (!reg8) {
                        die("Invalid tRP value.\n");
                }
@@ -603,7 +697,7 @@ static void sdram_detect_smallest_tRP(struct sys_info * sysinfo)
                die("DDR-II Module does not support this frequency (tRP error)\n");
        }
 
-       printk_debug("tRP = %d cycles\n", tRP_cycles);
+       printk(BIOS_DEBUG, "tRP = %d cycles\n", tRP_cycles);
        sysinfo->trp = tRP_cycles;
 }
 
@@ -629,7 +723,7 @@ static void sdram_detect_smallest_tRCD(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM_SPD_BASE + i, SPD_MIN_RAS_TO_CAS_DELAY);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_MIN_RAS_TO_CAS_DELAY);
                if (!reg8) {
                        die("Invalid tRCD value.\n");
                }
@@ -643,7 +737,7 @@ static void sdram_detect_smallest_tRCD(struct sys_info * sysinfo)
                die("DDR-II Module does not support this frequency (tRCD error)\n");
        }
 
-       printk_debug("tRCD = %d cycles\n", tRCD_cycles);
+       printk(BIOS_DEBUG, "tRCD = %d cycles\n", tRCD_cycles);
        sysinfo->trcd = tRCD_cycles;
 }
 
@@ -669,7 +763,7 @@ static void sdram_detect_smallest_tWR(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM_SPD_BASE + i, SPD_WRITE_RECOVERY_TIME);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_WRITE_RECOVERY_TIME);
                if (!reg8) {
                        die("Invalid tWR value.\n");
                }
@@ -683,7 +777,7 @@ static void sdram_detect_smallest_tWR(struct sys_info * sysinfo)
                die("DDR-II Module does not support this frequency (tWR error)\n");
        }
 
-       printk_debug("tWR = %d cycles\n", tWR_cycles);
+       printk(BIOS_DEBUG, "tWR = %d cycles\n", tWR_cycles);
        sysinfo->twr = tWR_cycles;
 }
 
@@ -719,7 +813,7 @@ static void sdram_detect_smallest_tRFC(struct sys_info * sysinfo)
                        /* Can this happen? Go back to 127.5ns just to be sure
                         * we don't run out of the array. This may be wrong
                         */
-                       printk_debug("DIMM %d is 1Gb x16.. Please report.\n", i);
+                       printk(BIOS_DEBUG, "DIMM %d is 1Gb x16.. Please report.\n", i);
                        reg8 = 3;
                }
 
@@ -735,7 +829,7 @@ static void sdram_detect_smallest_tRFC(struct sys_info * sysinfo)
        }
 
        sysinfo->trfc = tRFC_cycles[index];
-       printk_debug("tRFC = %d cycles\n", tRFC_cycles[index]);
+       printk(BIOS_DEBUG, "tRFC = %d cycles\n", tRFC_cycles[index]);
 }
 
 static void sdram_detect_smallest_refresh(struct sys_info * sysinfo)
@@ -750,7 +844,8 @@ static void sdram_detect_smallest_refresh(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               refresh = spd_read_byte(DIMM_SPD_BASE + i, SPD_REFRESH) & ~(1 << 7);
+               refresh = spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                       SPD_REFRESH) & ~(1 << 7);
 
                /* 15.6us */
                if (!refresh)
@@ -767,7 +862,7 @@ static void sdram_detect_smallest_refresh(struct sys_info * sysinfo)
 
                die("DDR-II module has unsupported refresh value\n");
        }
-       printk_debug("Refresh: %s\n", sysinfo->refresh?"7.8us":"15.6us");
+       printk(BIOS_DEBUG, "Refresh: %s\n", sysinfo->refresh?"7.8us":"15.6us");
 }
 
 static void sdram_verify_burst_length(struct sys_info * sysinfo)
@@ -778,7 +873,8 @@ static void sdram_verify_burst_length(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               if (!(spd_read_byte(DIMM_SPD_BASE + i, SPD_SUPPORTED_BURST_LENGTHS) & SPD_BURST_LENGTH_8))
+               if (!(spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                   SPD_SUPPORTED_BURST_LENGTHS) & SPD_BURST_LENGTH_8))
                        die("Only DDR-II RAM with burst length 8 is supported by this chipset.\n");
        }
 }
@@ -827,201 +923,290 @@ static void sdram_write_slew_rates(u32 offset, const u32 *slew_rate_table)
                MCHBAR32(offset+(i*4)) = slew_rate_table[i];
 }
 
-static void sdram_rcomp_buffer_strength_and_slew(struct sys_info *sysinfo)
-{
-       static const u32 dq2030[] = {
-               0x08070706, 0x0a090908, 0x0d0c0b0a, 0x12100f0e,
-               0x1a181614, 0x22201e1c, 0x2a282624, 0x3934302d,
-               0x0a090908, 0x0c0b0b0a, 0x0e0d0d0c, 0x1211100f,
-               0x19171513, 0x211f1d1b, 0x2d292623, 0x3f393531
-       };
+static const u32 dq2030[] = {
+       0x08070706, 0x0a090908, 0x0d0c0b0a, 0x12100f0e,
+       0x1a181614, 0x22201e1c, 0x2a282624, 0x3934302d,
+       0x0a090908, 0x0c0b0b0a, 0x0e0d0d0c, 0x1211100f,
+       0x19171513, 0x211f1d1b, 0x2d292623, 0x3f393531
+};
 
-       static const u32 dq2330[] = {
-               0x08070706, 0x0a090908, 0x0d0c0b0a, 0x12100f0e,
-               0x1a181614, 0x22201e1c, 0x2a282624, 0x3934302d,
-               0x0a090908, 0x0c0b0b0a, 0x0e0d0d0c, 0x1211100f,
-               0x19171513, 0x211f1d1b, 0x2d292623, 0x3f393531
-       };
+static const u32 dq2330[] = {
+       0x08070706, 0x0a090908, 0x0d0c0b0a, 0x12100f0e,
+       0x1a181614, 0x22201e1c, 0x2a282624, 0x3934302d,
+       0x0a090908, 0x0c0b0b0a, 0x0e0d0d0c, 0x1211100f,
+       0x19171513, 0x211f1d1b, 0x2d292623, 0x3f393531
+};
 
-       static const u32 cmd2710[] = {
-               0x07060605, 0x0f0d0b09, 0x19171411, 0x1f1f1d1b,
-               0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f,
-               0x1110100f, 0x0f0d0b09, 0x19171411, 0x1f1f1d1b,
-               0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f
-       };
+static const u32 cmd2710[] = {
+       0x07060605, 0x0f0d0b09, 0x19171411, 0x1f1f1d1b,
+       0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f,
+       0x1110100f, 0x0f0d0b09, 0x19171411, 0x1f1f1d1b,
+       0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f
+};
 
-       static const u32 cmd3210[] = {
-               0x0f0d0b0a, 0x17151311, 0x1f1d1b19, 0x1f1f1f1f,
-               0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f,
-               0x18171615, 0x1f1f1c1a, 0x1f1f1f1f, 0x1f1f1f1f,
-               0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f
-       };
+static const u32 cmd3210[] = {
+       0x0f0d0b0a, 0x17151311, 0x1f1d1b19, 0x1f1f1f1f,
+       0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f,
+       0x18171615, 0x1f1f1c1a, 0x1f1f1f1f, 0x1f1f1f1f,
+       0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f, 0x1f1f1f1f
+};
 
-       static const u32 clk2030[] = {
-               0x0e0d0d0c, 0x100f0f0e, 0x100f0e0d, 0x15131211,
-               0x1d1b1917, 0x2523211f, 0x2a282927, 0x32302e2c,
-               0x17161514, 0x1b1a1918, 0x1f1e1d1c, 0x23222120,
-               0x27262524, 0x2d2b2928, 0x3533312f, 0x3d3b3937
-       };
+static const u32 clk2030[] = {
+       0x0e0d0d0c, 0x100f0f0e, 0x100f0e0d, 0x15131211,
+       0x1d1b1917, 0x2523211f, 0x2a282927, 0x32302e2c,
+       0x17161514, 0x1b1a1918, 0x1f1e1d1c, 0x23222120,
+       0x27262524, 0x2d2b2928, 0x3533312f, 0x3d3b3937
+};
 
-       static const u32 ctl3215[] = {
-               0x01010000, 0x03020101, 0x07060504, 0x0b0a0908,
-               0x100f0e0d, 0x14131211, 0x18171615, 0x1c1b1a19,
-               0x05040403, 0x07060605, 0x0a090807, 0x0f0d0c0b,
-               0x14131211, 0x18171615, 0x1c1b1a19, 0x201f1e1d
-       };
+static const u32 ctl3215[] = {
+       0x01010000, 0x03020101, 0x07060504, 0x0b0a0908,
+       0x100f0e0d, 0x14131211, 0x18171615, 0x1c1b1a19,
+       0x05040403, 0x07060605, 0x0a090807, 0x0f0d0c0b,
+       0x14131211, 0x18171615, 0x1c1b1a19, 0x201f1e1d
+};
 
-       static const u32 ctl3220[] = {
-               0x05040403, 0x07060505, 0x0e0c0a08, 0x1a171411,
-               0x2825221f, 0x35322f2b, 0x3e3e3b38, 0x3e3e3e3e,
-               0x09080807, 0x0b0a0a09, 0x0f0d0c0b, 0x1b171311,
-               0x2825221f, 0x35322f2b, 0x3e3e3b38, 0x3e3e3e3e
-       };
+static const u32 ctl3220[] = {
+       0x05040403, 0x07060505, 0x0e0c0a08, 0x1a171411,
+       0x2825221f, 0x35322f2b, 0x3e3e3b38, 0x3e3e3e3e,
+       0x09080807, 0x0b0a0a09, 0x0f0d0c0b, 0x1b171311,
+       0x2825221f, 0x35322f2b, 0x3e3e3b38, 0x3e3e3e3e
+};
 
-       static const u32 nc[] = {
-               0x00000000, 0x00000000, 0x00000000, 0x00000000,
-               0x00000000, 0x00000000, 0x00000000, 0x00000000,
-               0x00000000, 0x00000000, 0x00000000, 0x00000000,
-               0x00000000, 0x00000000, 0x00000000, 0x00000000
-       };
+static const u32 nc[] = {
+       0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000
+};
 
-       static const u32 const * const dual_channel_slew_group_lookup[] = {
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd2710,
-               dq2030, cmd3210, nc,      ctl3215, nc,      clk2030, nc,     nc,
-
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, nc,      clk2030, nc,      dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, nc,      clk2030, nc,      dq2030, cmd2710,
-               dq2030, cmd3210, ctl3215, nc,      clk2030, nc,      nc,     nc,
-
-               dq2030, cmd3210, nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               dq2030, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd2710,
-               dq2030, cmd3210, nc,      ctl3215, nc,      clk2030, nc,     nc,
-
-               dq2030, cmd2710, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd2710, ctl3215, nc,      clk2030, nc,      dq2030, cmd3210,
-               dq2030, cmd2710, ctl3215, ctl3215, clk2030, clk2030, dq2030, cmd3210,
-               dq2030, cmd2710, ctl3215, nc,      clk2030, nc,      dq2030, cmd2710,
-               dq2030, cmd2710, ctl3215, nc,      clk2030, nc,      nc,     nc,
-
-               nc,     nc,      nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               nc,     nc,      ctl3215, nc,      clk2030, nc,      dq2030, cmd3210,
-               nc,     nc,      nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               nc,     nc,      ctl3215, nc,      clk2030, clk2030, dq2030, cmd2710
-       };
+enum {
+       DQ2030,
+       DQ2330,
+       CMD2710,
+       CMD3210,
+       CLK2030,
+       CTL3215,
+       CTL3220,
+       NC,
+};
 
-       static const u32 const * const single_channel_slew_group_lookup[] = {
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, nc,      ctl3215, nc,      clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, nc,      ctl3215, nc,      clk2030, nc,     nc,
-
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, nc,      clk2030, nc,      dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, nc,      clk2030, nc,      dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, nc,      clk2030, nc,      nc,     nc,
-
-               dq2330, cmd3210, nc,      ctl3215, nc,      clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, nc,      ctl3215, nc,      clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, nc,      ctl3215, nc,      clk2030, nc,     nc,
-
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, nc,      clk2030, nc,      dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, ctl3215, clk2030, clk2030, dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, nc,      clk2030, nc,      dq2330, cmd3210,
-               dq2330, cmd3210, ctl3215, nc,      clk2030, nc,      nc,     nc,
-
-               dq2330, nc,      nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               dq2330, nc,      ctl3215, nc,      clk2030, nc,      dq2030, cmd3210,
-               dq2330, nc,      nc,      ctl3215, nc,      clk2030, dq2030, cmd3210,
-               dq2330, nc,      ctl3215, nc,      clk2030, clk2030, dq2030, cmd3210
-       };
+static const u8 dual_channel_slew_group_lookup[] = {
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD2710,
+       DQ2030, CMD3210, NC,      CTL3215, NC,      CLK2030, NC,     NC,
+
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, NC,      CLK2030, NC,      DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, NC,      CLK2030, NC,      DQ2030, CMD2710,
+       DQ2030, CMD3210, CTL3215, NC,      CLK2030, NC,      NC,     NC,
+
+       DQ2030, CMD3210, NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD2710,
+       DQ2030, CMD3210, NC,      CTL3215, NC,      CLK2030, NC,     NC,
+
+       DQ2030, CMD2710, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD2710, CTL3215, NC,      CLK2030, NC,      DQ2030, CMD3210,
+       DQ2030, CMD2710, CTL3215, CTL3215, CLK2030, CLK2030, DQ2030, CMD3210,
+       DQ2030, CMD2710, CTL3215, NC,      CLK2030, NC,      DQ2030, CMD2710,
+       DQ2030, CMD2710, CTL3215, NC,      CLK2030, NC,      NC,     NC,
+
+       NC,     NC,      NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       NC,     NC,      CTL3215, NC,      CLK2030, NC,      DQ2030, CMD3210,
+       NC,     NC,      NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       NC,     NC,      CTL3215, NC,      CLK2030, CLK2030, DQ2030, CMD2710
+};
 
-       /* Strength multiplier tables */
-       static const u8 dual_channel_strength_multiplier[] = {
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x22,
-               0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x00, 0x44, 0x00, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x00, 0x44, 0x00, 0x44, 0x22,
-               0x44, 0x11, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
-               0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
-               0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x22,
-               0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
-               0x44, 0x22, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x22, 0x11, 0x00, 0x44, 0x00, 0x44, 0x11,
-               0x44, 0x22, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
-               0x44, 0x22, 0x11, 0x00, 0x44, 0x00, 0x44, 0x22,
-               0x44, 0x22, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
-               0x00, 0x00, 0x11, 0x00, 0x44, 0x00, 0x44, 0x11,
-               0x00, 0x00, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
-               0x00, 0x00, 0x11, 0x00, 0x44, 0x44, 0x44, 0x22
-       };
+static const u8 single_channel_slew_group_lookup[] = {
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, NC,      CTL3215, NC,      CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, NC,      CTL3215, NC,      CLK2030, NC,     NC,
+
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, NC,      CLK2030, NC,      DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, NC,      CLK2030, NC,      DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, NC,      CLK2030, NC,      NC,     NC,
+
+       DQ2330, CMD3210, NC,      CTL3215, NC,      CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, NC,      CTL3215, NC,      CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, NC,      CTL3215, NC,      CLK2030, NC,     NC,
+
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, NC,      CLK2030, NC,      DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, CTL3215, CLK2030, CLK2030, DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, NC,      CLK2030, NC,      DQ2330, CMD3210,
+       DQ2330, CMD3210, CTL3215, NC,      CLK2030, NC,      NC,     NC,
+
+       DQ2330, NC,      NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       DQ2330, NC,      CTL3215, NC,      CLK2030, NC,      DQ2030, CMD3210,
+       DQ2330, NC,      NC,      CTL3215, NC,      CLK2030, DQ2030, CMD3210,
+       DQ2330, NC,      CTL3215, NC,      CLK2030, CLK2030, DQ2030, CMD3210
+};
 
-       static const u8 single_channel_strength_multiplier[] = {
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
-               0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
-               0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
-               0x33, 0x00, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
-               0x33, 0x00, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
-               0x33, 0x00, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
-               0x33, 0x00, 0x11, 0x00, 0x44, 0x44, 0x33, 0x11
-       };
+static const u32 *slew_group_lookup(int dual_channel, int index)
+{
+       const u8 *slew_group;
+       /* Dual Channel needs different tables. */
+       if (dual_channel)
+               slew_group   = dual_channel_slew_group_lookup;
+       else
+               slew_group   = single_channel_slew_group_lookup;
 
+       switch (slew_group[index]) {
+       case DQ2030:    return dq2030;
+       case DQ2330:    return dq2330;
+       case CMD2710:   return cmd2710;
+       case CMD3210:   return cmd3210;
+       case CLK2030:   return clk2030;
+       case CTL3215:   return ctl3215;
+       case CTL3220:   return ctl3220;
+       case NC:        return nc;
+       }
+
+       return nc;
+}
+
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
+/* Strength multiplier tables */
+static const u8 dual_channel_strength_multiplier[] = {
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x00, 0x44, 0x00, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x00, 0x44, 0x00, 0x44, 0x22,
+       0x44, 0x11, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
+       0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
+       0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
+       0x44, 0x22, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x22, 0x11, 0x00, 0x44, 0x00, 0x44, 0x11,
+       0x44, 0x22, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
+       0x44, 0x22, 0x11, 0x00, 0x44, 0x00, 0x44, 0x22,
+       0x44, 0x22, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
+       0x00, 0x00, 0x11, 0x00, 0x44, 0x00, 0x44, 0x11,
+       0x00, 0x00, 0x00, 0x11, 0x00, 0x44, 0x44, 0x11,
+       0x00, 0x00, 0x11, 0x00, 0x44, 0x44, 0x44, 0x22
+};
+
+static const u8 single_channel_strength_multiplier[] = {
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
+       0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x00, 0x11, 0x00, 0x44, 0x00, 0x00,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x11, 0x44, 0x44, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
+       0x33, 0x11, 0x11, 0x00, 0x44, 0x00, 0x00, 0x00,
+       0x33, 0x00, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
+       0x33, 0x00, 0x11, 0x00, 0x44, 0x00, 0x33, 0x11,
+       0x33, 0x00, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
+       0x33, 0x00, 0x11, 0x00, 0x44, 0x44, 0x33, 0x11
+};
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
+static const u8 dual_channel_strength_multiplier[] = {
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x33,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x33,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x33,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x33,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
+       0x44, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x33
+};
+
+static const u8 single_channel_strength_multiplier[] = {
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x44, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x55, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x44, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x55, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x44, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x88, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x44, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x55, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x55, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x88, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x55, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x88, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00,
+       0x44, 0x33, 0x00, 0x00, 0x44, 0x44, 0x44, 0x00
+};
+#endif
+
+static void sdram_rcomp_buffer_strength_and_slew(struct sys_info *sysinfo)
+{
        const u8 * strength_multiplier;
-       const u32* const * slew_group_lookup;
-       int idx;
+       int idx, dual_channel;
 
        /* Set Strength Multipliers */
 
        /* Dual Channel needs different tables. */
        if (sdram_capabilities_dual_channel()) {
-               printk_debug("Programming Dual Channel RCOMP\n");
+               printk(BIOS_DEBUG, "Programming Dual Channel RCOMP\n");
                strength_multiplier = dual_channel_strength_multiplier;
-               slew_group_lookup   = dual_channel_slew_group_lookup;
+               dual_channel = 1;
                idx = 5 * sysinfo->dimm[0] +  sysinfo->dimm[2];
        } else {
-               printk_debug("Programming Single Channel RCOMP\n");
+               printk(BIOS_DEBUG, "Programming Single Channel RCOMP\n");
                strength_multiplier = single_channel_strength_multiplier;
-               slew_group_lookup   = single_channel_slew_group_lookup;
+               dual_channel = 0;
                idx = 5 * sysinfo->dimm[0] + sysinfo->dimm[1];
        }
 
-       printk_debug("Table Index: %d\n", idx);
+       printk(BIOS_DEBUG, "Table Index: %d\n", idx);
 
        MCHBAR8(G1SC) = strength_multiplier[idx * 8 + 0];
        MCHBAR8(G2SC) = strength_multiplier[idx * 8 + 1];
@@ -1033,22 +1218,22 @@ static void sdram_rcomp_buffer_strength_and_slew(struct sys_info *sysinfo)
        MCHBAR8(G8SC) = strength_multiplier[idx * 8 + 7];
 
        /* Channel 0 */
-       sdram_write_slew_rates(G1SRPUT, slew_group_lookup[idx * 8 + 0]);
-       sdram_write_slew_rates(G2SRPUT, slew_group_lookup[idx * 8 + 1]);
-       if ((slew_group_lookup[idx * 8 + 2] != nc) && (sysinfo->package == SYSINFO_PACKAGE_STACKED)) {
+       sdram_write_slew_rates(G1SRPUT, slew_group_lookup(dual_channel, idx * 8 + 0));
+       sdram_write_slew_rates(G2SRPUT, slew_group_lookup(dual_channel, idx * 8 + 1));
+       if ((slew_group_lookup(dual_channel, idx * 8 + 2) != nc) && (sysinfo->package == SYSINFO_PACKAGE_STACKED)) {
 
                sdram_write_slew_rates(G3SRPUT, ctl3220);
        } else {
-               sdram_write_slew_rates(G3SRPUT, slew_group_lookup[idx * 8 + 2]);
+               sdram_write_slew_rates(G3SRPUT, slew_group_lookup(dual_channel, idx * 8 + 2));
        }
-       sdram_write_slew_rates(G4SRPUT, slew_group_lookup[idx * 8 + 3]);
-       sdram_write_slew_rates(G5SRPUT, slew_group_lookup[idx * 8 + 4]);
-       sdram_write_slew_rates(G6SRPUT, slew_group_lookup[idx * 8 + 5]);
+       sdram_write_slew_rates(G4SRPUT, slew_group_lookup(dual_channel, idx * 8 + 3));
+       sdram_write_slew_rates(G5SRPUT, slew_group_lookup(dual_channel, idx * 8 + 4));
+       sdram_write_slew_rates(G6SRPUT, slew_group_lookup(dual_channel, idx * 8 + 5));
 
        /* Channel 1 */
        if (sysinfo->dual_channel) {
-               sdram_write_slew_rates(G7SRPUT, slew_group_lookup[idx * 8 + 6]);
-               sdram_write_slew_rates(G8SRPUT, slew_group_lookup[idx * 8 + 7]);
+               sdram_write_slew_rates(G7SRPUT, slew_group_lookup(dual_channel, idx * 8 + 6));
+               sdram_write_slew_rates(G8SRPUT, slew_group_lookup(dual_channel, idx * 8 + 7));
        } else {
                sdram_write_slew_rates(G7SRPUT, nc);
                sdram_write_slew_rates(G8SRPUT, nc);
@@ -1070,7 +1255,7 @@ static void sdram_program_dll_timings(struct sys_info *sysinfo)
        u32 chan0dll = 0, chan1dll = 0;
        int i;
 
-       printk_debug ("Programming DLL Timings... \n");
+       printk(BIOS_DEBUG, "Programming DLL Timings... \n");
 
        MCHBAR16(DQSMT) &= ~( (3 << 12) | (1 << 10) | ( 0xf << 0) );
        MCHBAR16(DQSMT) |= (1 << 13) | (0xc << 0);
@@ -1110,6 +1295,7 @@ static void sdram_force_rcomp(void)
 
        reg8 = i945_silicon_revision();
        if ((reg8 == 0 && (MCHBAR32(DCC) & (3 << 0)) == 0) || (reg8 == 1)) {
+
                reg32 = MCHBAR32(GBRCOMPCTL);
                reg32 |= (3 << 5);
                MCHBAR32(GBRCOMPCTL) = reg32;
@@ -1121,7 +1307,7 @@ static void sdram_initialize_system_memory_io(struct sys_info *sysinfo)
        u8 reg8;
        u32 reg32;
 
-       printk_debug ("Initializing System Memory IO... \n");
+       printk(BIOS_DEBUG, "Initializing System Memory IO... \n");
        /* Enable Data Half Clock Pushout */
        reg8 = MCHBAR8(C0HCTC);
        reg8 &= ~0x1f;
@@ -1163,7 +1349,7 @@ static void sdram_enable_system_memory_io(struct sys_info *sysinfo)
 {
        u32 reg32;
 
-       printk_debug ("Enabling System Memory IO... \n");
+       printk(BIOS_DEBUG, "Enabling System Memory IO... \n");
 
        reg32 = MCHBAR32(RCVENMT);
        reg32 &= ~(0x3f << 6);
@@ -1180,7 +1366,7 @@ static void sdram_enable_system_memory_io(struct sys_info *sysinfo)
        reg32 |= (1 << 6) | (1 << 4);
        MCHBAR32(DRTST) = reg32;
 
-       asm volatile ("nop; nop;");
+       asm volatile ("nop; nop;" ::: "memory");
 
        reg32 = MCHBAR32(DRTST);
 
@@ -1220,12 +1406,13 @@ struct dimm_size {
        unsigned long side2;
 };
 
-static struct dimm_size sdram_get_dimm_size(u16 device)
+static struct dimm_size sdram_get_dimm_size(struct sys_info *sysinfo, u16 dimmno)
 {
        /* Calculate the log base 2 size of a DIMM in bits */
        struct dimm_size sz;
-       int value, low, rows, columns;
+       int value, low, rows, columns, device;
 
+       device = get_dimm_spd_address(sysinfo, dimmno);
        sz.side1 = 0;
        sz.side2 = 0;
 
@@ -1273,7 +1460,7 @@ static struct dimm_size sdram_get_dimm_size(u16 device)
        /* Don't die here, I have not come across any of these to test what
         * actually happens.
         */
-       printk_err("Assymetric DIMMs are not supported by this chipset\n");
+       printk(BIOS_ERR, "Assymetric DIMMs are not supported by this chipset\n");
 
        sz.side2 -= (rows & 0x0f);              /* Subtract out rows on side 1 */
        sz.side2 += ((rows >> 4) & 0x0f);       /* Add in rows on side 2 */
@@ -1291,7 +1478,7 @@ static struct dimm_size sdram_get_dimm_size(u16 device)
         */
        sz.side1 = 0;
        sz.side2 = 0;
- out:
+out:
        return sz;
 }
 
@@ -1308,16 +1495,17 @@ static void sdram_detect_dimm_size(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               sz = sdram_get_dimm_size(DIMM_SPD_BASE + i);
+               sz = sdram_get_dimm_size(sysinfo, i);
 
-               sysinfo->banks[i] = spd_read_byte(DIMM_SPD_BASE + i, SPD_NUM_BANKS_PER_SDRAM);  /* banks */
+               sysinfo->banks[i] = spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                                 SPD_NUM_BANKS_PER_SDRAM);     /* banks */
 
                if (sz.side1 < 30)
                        die("DDR-II rank size smaller than 128MB is not supported.\n");
 
                sysinfo->banksize[i * 2] = 1 << (sz.side1 - 28);
 
-               printk_debug("DIMM %d side 0 = %d MB\n", i, sysinfo->banksize[i * 2] * 32 );
+               printk(BIOS_DEBUG, "DIMM %d side 0 = %d MB\n", i, sysinfo->banksize[i * 2] * 32 );
 
                if (!sz.side2)
                        continue;
@@ -1328,7 +1516,7 @@ static void sdram_detect_dimm_size(struct sys_info * sysinfo)
 
                sysinfo->banksize[(i * 2) + 1] = 1 << (sz.side2 - 28);
 
-               printk_debug("DIMM %d side 1 = %d MB\n", i, sysinfo->banksize[(i * 2) + 1] * 32);
+               printk(BIOS_DEBUG, "DIMM %d side 1 = %d MB\n", i, sysinfo->banksize[(i * 2) + 1] * 32);
        }
 }
 
@@ -1337,7 +1525,7 @@ static int sdram_program_row_boundaries(struct sys_info *sysinfo)
        int i;
        int cum0, cum1, tolud, tom;
 
-       printk_debug ("Setting RAM size... \n");
+       printk(BIOS_DEBUG, "Setting RAM size... \n");
 
        cum0 = 0;
        for(i = 0; i < 2 * DIMM_SOCKETS; i++) {
@@ -1352,10 +1540,12 @@ static int sdram_program_row_boundaries(struct sys_info *sysinfo)
        if (sysinfo->interleaved)
                cum1 = 0;
 
+#if 0
        /* Exception: Channel 1 is not populated. C1DRB stays zero */
        if (sysinfo->dimm[2] == SYSINFO_DIMM_NOT_POPULATED &&
                        sysinfo->dimm[3] == SYSINFO_DIMM_NOT_POPULATED)
                cum1 = 0;
+#endif
 
        for(i = 0; i < 2 * DIMM_SOCKETS; i++) {
                cum1 += sysinfo->banksize[i + 4];
@@ -1377,9 +1567,9 @@ static int sdram_program_row_boundaries(struct sys_info *sysinfo)
 
        pci_write_config8(PCI_DEV(0,0,0), TOLUD, tolud);
 
-       printk_debug("C0DRB = 0x%08x\n", MCHBAR32(C0DRB0));
-       printk_debug("C1DRB = 0x%08x\n", MCHBAR32(C1DRB0));
-       printk_debug("TOLUD = 0x%04x\n", pci_read_config8(PCI_DEV(0,0,0), TOLUD));
+       printk(BIOS_DEBUG, "C0DRB = 0x%08x\n", MCHBAR32(C0DRB0));
+       printk(BIOS_DEBUG, "C1DRB = 0x%08x\n", MCHBAR32(C1DRB0));
+       printk(BIOS_DEBUG, "TOLUD = 0x%04x\n", pci_read_config8(PCI_DEV(0,0,0), TOLUD));
 
        pci_write_config16(PCI_DEV(0,0,0), TOM, tom);
 
@@ -1391,7 +1581,7 @@ static int sdram_set_row_attributes(struct sys_info *sysinfo)
        int i, value;
        u16 dra0=0, dra1=0, dra = 0;
 
-       printk_debug ("Setting row attributes... \n");
+       printk(BIOS_DEBUG, "Setting row attributes... \n");
        for(i=0; i < 2 * DIMM_SOCKETS; i++) {
                u16 device;
                u8 columnsrows;
@@ -1400,7 +1590,7 @@ static int sdram_set_row_attributes(struct sys_info *sysinfo)
                        continue;
                }
 
-               device = DIMM_SPD_BASE + i;
+               device = get_dimm_spd_address(sysinfo, i);
 
                value = spd_read_byte(device, SPD_NUM_ROWS);    /* rows */
                columnsrows = (value & 0x0f);
@@ -1431,8 +1621,8 @@ static int sdram_set_row_attributes(struct sys_info *sysinfo)
        MCHBAR16(C0DRA0) = dra0;
        MCHBAR16(C1DRA0) = dra1;
 
-       printk_debug("C0DRA = 0x%04x\n", dra0);
-       printk_debug("C1DRA = 0x%04x\n", dra1);
+       printk(BIOS_DEBUG, "C0DRA = 0x%04x\n", dra0);
+       printk(BIOS_DEBUG, "C1DRA = 0x%04x\n", dra1);
 
        return 0;
 }
@@ -1457,7 +1647,7 @@ static void sdram_set_bank_architecture(struct sys_info *sysinfo)
                if (sysinfo->banks[i] != 8)
                        continue;
 
-               printk_spew("DIMM%d has 8 banks.\n");
+               printk(BIOS_SPEW, "DIMM%d has 8 banks.\n", i);
 
                if (i & 1)
                        MCHBAR16(off32) |= 0x50;
@@ -1722,7 +1912,7 @@ static void sdram_set_channel_mode(struct sys_info *sysinfo)
 {
        u32 reg32;
 
-       printk_debug("Setting mode of operation for memory channels...");
+       printk(BIOS_DEBUG, "Setting mode of operation for memory channels...");
 
        if (sdram_capabilities_interleave() &&
                    ( ( sysinfo->banksize[0] + sysinfo->banksize[1] +
@@ -1740,23 +1930,24 @@ static void sdram_set_channel_mode(struct sys_info *sysinfo)
 
        if(sysinfo->interleaved) {
                /* Dual Channel Interleaved */
-               printk_debug("Dual Channel Interleaved.\n");
+               printk(BIOS_DEBUG, "Dual Channel Interleaved.\n");
                reg32 |= (1 << 1);
        } else if (sysinfo->dimm[0] == SYSINFO_DIMM_NOT_POPULATED &&
                        sysinfo->dimm[1] == SYSINFO_DIMM_NOT_POPULATED) {
                /* Channel 1 only */
-               printk_debug("Single Channel 1 only.\n");
+               printk(BIOS_DEBUG, "Single Channel 1 only.\n");
                reg32 |= (1 << 2);
        } else if (sdram_capabilities_dual_channel() && sysinfo->dimm[2] !=
                        SYSINFO_DIMM_NOT_POPULATED) {
                /* Dual Channel Assymetric */
-               printk_debug("Dual Channel Assymetric.\n");
+               printk(BIOS_DEBUG, "Dual Channel Assymetric.\n");
                reg32 |= (1 << 0);
        } else {
                /* All bits 0 means Single Channel 0 operation */
-               printk_debug("Single Channel 0 only.\n");
+               printk(BIOS_DEBUG, "Single Channel 0 only.\n");
        }
 
+       /* Now disable channel XORing */
        reg32 |= (1 << 10);
 
        MCHBAR32(DCC) = reg32;
@@ -1770,12 +1961,9 @@ static void sdram_program_pll_settings(struct sys_info *sysinfo)
 
        MCHBAR32(PLLMON) = 0x80800000;
 
-       switch (MCHBAR32(CLKCFG) & 0x7) {
-       case 0: sysinfo->fsb_frequency = 400; break;    /* FSB400 */
-       case 1: sysinfo->fsb_frequency = 533; break;    /* FSB533 */
-       case 3: sysinfo->fsb_frequency = 667; break;    /* FSB667 */
-       default: die("Unsupported FSB speed");
-       }
+       sysinfo->fsb_frequency = fsbclk();
+       if (sysinfo->fsb_frequency == 0xffff)
+               die("Unsupported FSB speed");
 
        /* Program CPCTL according to FSB speed */
        /* Only write the lower byte */
@@ -1807,14 +1995,14 @@ static void sdram_program_graphics_frequency(struct sys_info *sysinfo)
 #define VOLTAGE_1_05   0x00
 #define VOLTAGE_1_50   0x01
 
-       printk_debug ("Setting Graphics Frequency... \n");
+       printk(BIOS_DEBUG, "Setting Graphics Frequency... \n");
 
-       printk_debug("FSB: %d MHz ", sysinfo->fsb_frequency);
+       printk(BIOS_DEBUG, "FSB: %d MHz ", sysinfo->fsb_frequency);
 
        voltage = VOLTAGE_1_05;
        if (MCHBAR32(DFT_STRAP1) & (1 << 20))
                voltage = VOLTAGE_1_50;
-       printk_debug("Voltage: %s ", (voltage==VOLTAGE_1_05)?"1.05V":"1.5V");
+       printk(BIOS_DEBUG, "Voltage: %s ", (voltage==VOLTAGE_1_05)?"1.05V":"1.5V");
 
        /* Gate graphics hardware for frequency change */
        reg8 = pci_read_config16(PCI_DEV(0,2,0), GCFC + 1);
@@ -1830,7 +2018,7 @@ static void sdram_program_graphics_frequency(struct sys_info *sysinfo)
                if (voltage == VOLTAGE_1_05)
                        freq = CRCLK_250MHz;
                else
-                       freq = CRCLK_400MHz;
+                       freq = CRCLK_400MHz; /* 1.5V requires 400MHz */
                break;
        case GFX_FREQUENCY_CAP_250MHZ: freq = CRCLK_250MHz; break;
        case GFX_FREQUENCY_CAP_200MHZ: freq = CRCLK_200MHz; break;
@@ -1844,12 +2032,12 @@ static void sdram_program_graphics_frequency(struct sys_info *sysinfo)
                        freq = CRCLK_166MHz;
        }
 
-       printk_debug("Render: ");
+       printk(BIOS_DEBUG, "Render: ");
        switch (freq) {
-       case CRCLK_166MHz: printk_debug("166Mhz"); break;
-       case CRCLK_200MHz: printk_debug("200Mhz"); break;
-       case CRCLK_250MHz: printk_debug("250Mhz"); break;
-       case CRCLK_400MHz: printk_debug("400Mhz"); break;
+       case CRCLK_166MHz: printk(BIOS_DEBUG, "166Mhz"); break;
+       case CRCLK_200MHz: printk(BIOS_DEBUG, "200Mhz"); break;
+       case CRCLK_250MHz: printk(BIOS_DEBUG, "250Mhz"); break;
+       case CRCLK_400MHz: printk(BIOS_DEBUG, "400Mhz"); break;
        }
 
        if (i945_silicon_revision() == 0) {
@@ -1894,10 +2082,10 @@ static void sdram_program_graphics_frequency(struct sys_info *sysinfo)
 
        if (voltage == VOLTAGE_1_05) {
                reg8 |= CDCLK_200MHz;
-               printk_debug(" Display: 200MHz\n");
+               printk(BIOS_DEBUG, " Display: 200MHz\n");
        } else {
                reg8 |= CDCLK_320MHz;
-               printk_debug(" Display: 320MHz\n");
+               printk(BIOS_DEBUG, " Display: 320MHz\n");
        }
        pci_write_config8(PCI_DEV(0,2,0), GCFC, reg8);
 
@@ -1919,21 +2107,21 @@ static void sdram_program_memory_frequency(struct sys_info *sysinfo)
        u32 clkcfg;
        u8 reg8;
 
-       printk_debug ("Setting Memory Frequency... ");
+       printk(BIOS_DEBUG, "Setting Memory Frequency... ");
 
        clkcfg = MCHBAR32(CLKCFG);
 
-       printk_debug("CLKCFG=0x%08x, ", clkcfg);
+       printk(BIOS_DEBUG, "CLKCFG=0x%08x, ", clkcfg);
 
        clkcfg &= ~( (1 << 12) | (1 << 7) | ( 7 << 4) );
 
        if (sysinfo->mvco4x) {
-               printk_debug("MVCO 4x, ");
+               printk(BIOS_DEBUG, "MVCO 4x, ");
                clkcfg &= ~(1 << 12);
        }
 
        if (sysinfo->clkcfg_bit7) {
-               printk_debug("second VCO, ");
+               printk(BIOS_DEBUG, "second VCO, ");
 
                clkcfg |= (1 << 7);
        }
@@ -1946,7 +2134,7 @@ static void sdram_program_memory_frequency(struct sys_info *sysinfo)
        }
 
        if (MCHBAR32(CLKCFG) == clkcfg) {
-               printk_debug ("ok (unchanged)\n");
+               printk(BIOS_DEBUG, "ok (unchanged)\n");
                return;
        }
 
@@ -1966,7 +2154,7 @@ vco_update:
        clkcfg |= (1 << 10);
        MCHBAR32(CLKCFG) = clkcfg;
 
-       __asm__ __volatile__ (
+       asm volatile (
                "       movl $0x100, %%ecx\n"
                "delay_update:\n"
                "       nop\n"
@@ -1976,7 +2164,7 @@ vco_update:
                "       loop delay_update\n"
                : /* No outputs */
                : /* No inputs */
-               : "%ecx"
+               : "%ecx", "memory"
                );
 
        clkcfg &= ~(1 << 10);
@@ -1987,58 +2175,131 @@ cache_code:
        goto vco_update;
 out:
 
-       printk_debug("CLKCFG=0x%08x, ", MCHBAR32(CLKCFG));
-       printk_debug ("ok\n");
+       printk(BIOS_DEBUG, "CLKCFG=0x%08x, ", MCHBAR32(CLKCFG));
+       printk(BIOS_DEBUG, "ok\n");
 }
 
 static void sdram_program_clock_crossing(void)
 {
-       u32 reg32;
        int idx = 0;
 
        /**
         * We add the indices according to our clocks from CLKCFG.
         */
-
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
        static const u32 data_clock_crossing[] = {
                0x00100401, 0x00000000, /* DDR400 FSB400 */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
 
                0x08040120, 0x00000000, /* DDR400 FSB533 */
                0x00100401, 0x00000000, /* DDR533 FSB533 */
+               0x00010402, 0x00000000, /* DDR667 FSB533 - fake values */
 
                0x04020120, 0x00000010, /* DDR400 FSB667 */
                0x10040280, 0x00000040, /* DDR533 FSB667 */
-               0x00100401, 0x00000000  /* DDR667 FSB667 */
+               0x00100401, 0x00000000, /* DDR667 FSB667 */
+
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
        };
 
        static const u32 command_clock_crossing[] = {
                0x04020208, 0x00000000, /* DDR400 FSB400 */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
 
                0x00060108, 0x00000000, /* DDR400 FSB533 */
                0x04020108, 0x00000000, /* DDR533 FSB533 */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
 
                0x00040318, 0x00000000, /* DDR400 FSB667 */
                0x04020118, 0x00000000, /* DDR533 FSB667 */
-               0x02010804, 0x00000000  /* DDR667 FSB667 */
+               0x02010804, 0x00000000, /* DDR667 FSB667 */
+
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+       };
+
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
+       /* i945 G/P */
+       static const u32 data_clock_crossing[] = {
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+
+               0x10080201, 0x00000000, /* DDR400 FSB533 */
+               0x00100401, 0x00000000, /* DDR533 FSB533 */
+               0x00010402, 0x00000000, /* DDR667 FSB533 - fake values */
+
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+
+               0x04020108, 0x00000000, /* DDR400 FSB800 */
+               0x00020108, 0x00000000, /* DDR533 FSB800 */
+               0x00080201, 0x00000000, /* DDR667 FSB800 */
+
+               0x00010402, 0x00000000, /* DDR400 FSB1066 */
+               0x04020108, 0x00000000, /* DDR533 FSB1066 */
+               0x08040110, 0x00000000, /* DDR667 FSB1066 */
        };
 
-       printk_debug("Programming Clock Crossing...");
-       reg32 = MCHBAR32(CLKCFG);
+       static const u32 command_clock_crossing[] = {
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+
+               0x00010800, 0x00000402, /* DDR400 FSB533 */
+               0x01000400, 0x00000200, /* DDR533 FSB533 */
+               0x00020904, 0x00000000, /* DDR667 FSB533 - fake values */
+
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+               0xffffffff, 0xffffffff, /*  nonexistant  */
+
+               0x02010804, 0x00000000, /* DDR400 FSB800 */
+               0x00010402, 0x00000000, /* DDR533 FSB800 */
+               0x04020180, 0x00000008, /* DDR667 FSB800 */
 
-       printk_debug("MEM=");
-       switch ((reg32 >> 4) & 7) {
-       case 2: printk_debug("400"); idx += 0; break;
-       case 3: printk_debug("533"); idx += 2; break;
-       case 4: printk_debug("667"); idx += 4; break;
-       default: printk_debug("RSVD\n"); return;
+               0x00020904, 0x00000000, /* DDR400 FSB1066 */
+               0x02010804, 0x00000000, /* DDR533 FSB1066 */
+               0x180601c0, 0x00000020, /* DDR667 FSB1066 */
+       };
+#endif
+
+       printk(BIOS_DEBUG, "Programming Clock Crossing...");
+
+       printk(BIOS_DEBUG, "MEM=");
+       switch (memclk()) {
+       case 400:       printk(BIOS_DEBUG, "400"); idx += 0; break;
+       case 533:       printk(BIOS_DEBUG, "533"); idx += 2; break;
+       case 667:       printk(BIOS_DEBUG, "667"); idx += 4; break;
+       default: printk(BIOS_DEBUG, "RSVD %x", memclk()); return;
        }
 
-       printk_debug(" FSB=");
-       switch (reg32 & 7) {
-       case 0: printk_debug("400\n"); idx += 0; break;
-       case 1: printk_debug("533"); idx += 2; break;
-       case 3: printk_debug("667"); idx += 6; break;
-       default: printk_debug("RSVD\n"); return;
+       printk(BIOS_DEBUG, " FSB=");
+       switch (fsbclk()) {
+       case 400:       printk(BIOS_DEBUG, "400"); idx += 0; break;
+       case 533:       printk(BIOS_DEBUG, "533"); idx += 6; break;
+       case 667:       printk(BIOS_DEBUG, "667"); idx += 12; break;
+       case 800:       printk(BIOS_DEBUG, "800"); idx += 18; break;
+       case 1066:      printk(BIOS_DEBUG, "1066"); idx += 24; break;
+       default: printk(BIOS_DEBUG, "RSVD %x\n", fsbclk()); return;
+       }
+
+       if (command_clock_crossing[idx]==0xffffffff) {
+               printk(BIOS_DEBUG, "Invalid MEM/FSB combination!\n");
        }
 
        MCHBAR32(CCCFT + 0) = command_clock_crossing[idx];
@@ -2049,7 +2310,7 @@ static void sdram_program_clock_crossing(void)
        MCHBAR32(C1DCCFT + 0) = data_clock_crossing[idx];
        MCHBAR32(C1DCCFT + 4) = data_clock_crossing[idx + 1];
 
-       printk_debug("... ok\n");
+       printk(BIOS_DEBUG, "... ok\n");
 }
 
 static void sdram_disable_fast_dispatch(void)
@@ -2189,7 +2450,7 @@ static void sdram_post_jedec_initialization(struct sys_info *sysinfo)
        if (sysinfo->interleaved) {
 
                reg32 = MCHBAR32(DCC);
-#if CHANNEL_XOR_RANDOMIZATION
+#if CONFIG_CHANNEL_XOR_RANDOMIZATION
                reg32 &= ~(1 << 10);
                reg32 |= (1 << 9);
 #else
@@ -2361,10 +2622,10 @@ static void sdram_power_management(struct sys_info *sysinfo)
        reg8 |= (1 << 2);
        pci_write_config8(PCI_DEV(0, 0x2, 0), 0xc1, reg8);
 
-#if C2_SELF_REFRESH_DISABLE
+#ifdef C2_SELF_REFRESH_DISABLE
 
        if (integrated_graphics) {
-               printk_debug("C2 self-refresh with IGD\n");
+               printk(BIOS_DEBUG, "C2 self-refresh with IGD\n");
                MCHBAR16(MIPMC4) = 0x0468;
                MCHBAR16(MIPMC5) = 0x046c;
                MCHBAR16(MIPMC6) = 0x046c;
@@ -2411,6 +2672,7 @@ static void sdram_thermal_management(void)
         * 0x30/0x32.
         */
 
+       /* TODO This is not implemented yet. Volunteers? */
 }
 
 static void sdram_save_receive_enable(void)
@@ -2442,7 +2704,7 @@ static void sdram_save_receive_enable(void)
        values[3] |= (reg32 >> (24 - 4)) & 0xf0;
 
        /* coreboot only uses bytes 0 - 127 for its CMOS values so far
-        * so we grad bytes 128 - 131 to save the receive enable values
+        * so we grab bytes 128 - 131 to save the receive enable values
         */
 
        for (i=0; i<4; i++)
@@ -2481,6 +2743,9 @@ static void sdram_program_receive_enable(struct sys_info *sysinfo)
 {
        MCHBAR32(REPC) |= (1 << 0);
 
+       /* enable upper CMOS */
+       RCBA32(0x3400) = (1 << 2);
+
        /* Program Receive Enable Timings */
        if (sysinfo->boot_path == BOOT_PATH_RESUME) {
                sdram_recover_receive_enable();
@@ -2520,7 +2785,7 @@ static void sdram_on_die_termination(struct sys_info *sysinfo)
 
        if ( !(sysinfo->dimm[0] != SYSINFO_DIMM_NOT_POPULATED &&
                        sysinfo->dimm[1] != SYSINFO_DIMM_NOT_POPULATED) ) {
-               printk_debug("one dimm per channel config.. \n");
+               printk(BIOS_DEBUG, "one dimm per channel config.. \n");
 
                reg32 = MCHBAR32(C0ODT);
                reg32 &= ~(7 << 28);
@@ -2557,27 +2822,28 @@ static void sdram_enable_memory_clocks(struct sys_info *sysinfo)
 {
        u8 clocks[2] = { 0, 0 };
 
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
+#define CLOCKS_WIDTH 2
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
+#define CLOCKS_WIDTH 3
+#endif
        if (sysinfo->dimm[0] != SYSINFO_DIMM_NOT_POPULATED)
-               clocks[0] |= (1 << 0) | (1 << 1);
+               clocks[0] |= (1 << CLOCKS_WIDTH)-1;
 
        if (sysinfo->dimm[1] != SYSINFO_DIMM_NOT_POPULATED)
-               clocks[0] |= (1 << 2) | (1 << 3);
+               clocks[0] |= ((1 << CLOCKS_WIDTH)-1) << CLOCKS_WIDTH;
 
        if (sysinfo->dimm[2] != SYSINFO_DIMM_NOT_POPULATED)
-               clocks[1] |= (1 << 0) | (1 << 1);
+               clocks[1] |= (1 << CLOCKS_WIDTH)-1;
 
        if (sysinfo->dimm[3] != SYSINFO_DIMM_NOT_POPULATED)
-               clocks[1] |= (1 << 2) | (1 << 3);
+               clocks[1] |= ((1 << CLOCKS_WIDTH)-1) << CLOCKS_WIDTH;
 
-#ifdef OVERRIDE_CLOCK_DISABLE
+#if CONFIG_OVERRIDE_CLOCK_DISABLE
        /* Usually system firmware turns off system memory clock signals
         * to unused SO-DIMM slots to reduce EMI and power consumption.
         * However, the Kontron 986LCD-M does not like unused clock
         * signals to be disabled.
-        * If other similar mainboard occur, it would make sense to make
-        * this an entry in the sysinfo structure, and pre-initialize that
-        * structure in the mainboard's auto.c main() function.
-        * For now an #ifdef will do.
         */
 
        clocks[0] = 0xf; /* force all clock gate pairs to enable */
@@ -2618,7 +2884,7 @@ static void sdram_jedec_enable(struct sys_info *sysinfo)
                        continue;
                }
 
-               printk_debug("jedec enable sequence: bank %d\n", i);
+               printk(BIOS_DEBUG, "jedec enable sequence: bank %d\n", i);
                switch (i) {
                case 0:
                        /* Start at address 0 */
@@ -2631,7 +2897,7 @@ static void sdram_jedec_enable(struct sys_info *sysinfo)
                        }
                default:
                        if (nonzero != -1) {
-                               printk_debug("bankaddr from bank size of rank %d\n", nonzero);
+                               printk(BIOS_DEBUG, "bankaddr from bank size of rank %d\n", nonzero);
                                bankaddr += sysinfo->banksize[nonzero] <<
                                        (sysinfo->interleaved ? 26 : 25);
                                break;
@@ -2789,22 +3055,24 @@ static void sdram_setup_processor_side(void)
 /**
  * @param boot_path: 0 = normal, 1 = reset, 2 = resume from s3
  */
-void sdram_initialize(int boot_path)
+void sdram_initialize(int boot_path, const u8 *spd_addresses)
 {
        struct sys_info sysinfo;
        u8 reg8, cas_mask;
 
-       sdram_detect_errors();
-
-       printk_debug ("Setting up RAM controller.\n");
+       printk(BIOS_DEBUG, "Setting up RAM controller.\n");
 
        memset(&sysinfo, 0, sizeof(sysinfo));
 
        sysinfo.boot_path = boot_path;
+       sysinfo.spd_addresses = spd_addresses;
 
        /* Look at the type of DIMMs and verify all DIMMs are x8 or x16 width */
        sdram_get_dram_configuration(&sysinfo);
 
+       /* If error, do cold boot */
+       sdram_detect_errors(&sysinfo);
+
        /* Check whether we have stacked DIMMs */
        sdram_verify_package_type(&sysinfo);
 
@@ -2904,9 +3172,7 @@ void sdram_initialize(int boot_path)
        sdram_thermal_management();
 
        /* Normal Operations */
-       if (boot_path == BOOT_PATH_NORMAL) {
-               sdram_init_complete();
-       }
+       sdram_init_complete();
 
        /* Program Receive Enable Timings */
        sdram_program_receive_enable(&sysinfo);
@@ -2919,8 +3185,40 @@ void sdram_initialize(int boot_path)
        reg8 &= ~(1 << 7);
        pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8);
 
-       printk_debug("RAM initialization finished.\n");
+       printk(BIOS_DEBUG, "RAM initialization finished.\n");
 
        sdram_setup_processor_side();
 }
 
+unsigned long get_top_of_ram(void)
+{
+       u32 tom;
+
+       if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & ((1 << 4) | (1 << 3))) {
+               /* IGD enabled, get top of Memory from BSM register */
+               tom = pci_read_config32(PCI_DEV(0,2,0), 0x5c);
+       } else {
+               tom = (pci_read_config8(PCI_DEV(0,0,0), TOLUD) & 0xf7) << 24;
+       }
+
+       /* if TSEG enabled subtract size */
+       switch(pci_read_config8(PCI_DEV(0, 0, 0), ESMRAM)) {
+       case 0x01:
+               /* 1MB TSEG */
+               tom -= 0x10000;
+               break;
+       case 0x03:
+               /* 2MB TSEG */
+               tom -= 0x20000;
+               break;
+       case 0x05:
+               /* 8MB TSEG */
+               tom -= 0x80000;
+               break;
+       default:
+               /* TSEG either disabled or invalid */
+               break;
+       }
+       return (unsigned long) tom;
+}
+