#include <asm/io.h>
 #include <asm/mmu.h>
 #include <asm/fsl_law.h>
+#include <asm/fsl_lbc.h>
 #include <post.h>
 #include <asm/processor.h>
 #include <asm/fsl_ddr_sdram.h>
        print_lbc_regs();
 }
 
+/* Common ddr init for non-corenet fsl 85xx platforms */
+#ifndef CONFIG_FSL_CORENET
+phys_size_t initdram(int board_type)
+{
+       phys_size_t dram_size = 0;
+
+#if defined(CONFIG_DDR_DLL)
+       {
+               ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+               unsigned int x = 10;
+               unsigned int i;
+
+               /*
+                * Work around to stabilize DDR DLL
+                */
+               out_be32(&gur->ddrdllcr, 0x81000000);
+               asm("sync;isync;msync");
+               udelay(200);
+               while (in_be32(&gur->ddrdllcr) != 0x81000100) {
+                       setbits_be32(&gur->devdisr, 0x00010000);
+                       for (i = 0; i < x; i++)
+                               ;
+                       clrbits_be32(&gur->devdisr, 0x00010000);
+                       x++;
+               }
+       }
+#endif
+
+#if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
+       dram_size = fsl_ddr_sdram();
+#else
+       dram_size = fixed_sdram();
+#endif
+       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
+       dram_size *= 0x100000;
+
+#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
+       /*
+        * Initialize and enable DDR ECC.
+        */
+       ddr_enable_ecc(dram_size);
+#endif
+
+       /* Some boards also have sdram on the lbc */
+       sdram_init();
+
+       puts("DDR: ");
+       return dram_size;
+}
+#endif
+
 #if CONFIG_POST & CONFIG_SYS_POST_MEMORY
 
 /* Board-specific functions defined in each board's ddr.c */
 
 #include <common.h>
 #include <asm/fsl_lbc.h>
 
+#ifdef CONFIG_MPC85xx
+/* Boards should provide their own version of this if they use lbc sdram */
+void __sdram_init(void)
+{
+       /* Do nothing */
+}
+void sdram_init(void) __attribute__((weak, alias("__sdram_init")));
+#endif
+
+
 void print_lbc_regs(void)
 {
        int i;
 
 
 extern phys_size_t fsl_ddr_sdram(void);
 
+/*
+ * The 85xx boards have a common prototype for fixed_sdram so put the
+ * declaration here.
+ */
+#ifdef CONFIG_MPC85xx
+extern phys_size_t fixed_sdram(void);
+#endif
+
+#if defined(CONFIG_DDR_ECC)
+extern void ddr_enable_ecc(unsigned int dram_size);
+#endif
+
+
 typedef struct fixed_ddr_parm{
        int min_freq;
        int max_freq;
 
 #include <config.h>
 #include <common.h>
 
+#ifdef CONFIG_MPC85xx
+void sdram_init(void);
+#endif
+
 /* BR - Base Registers
  */
 #define BR0                            0x5000          /* Register offset to immr */
 
 
 #include "../common/sgmii_riser.h"
 
-phys_size_t fixed_sdram(void);
-
 int board_early_init_f (void)
 {
 #ifdef CONFIG_MMC
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       phys_size_t dram_size = 0;
-
-       puts("Initializing....");
-
-#ifdef CONFIG_SPD_EEPROM
-       dram_size = fsl_ddr_sdram();
-#else
-       dram_size = fixed_sdram();
-#endif
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 #if !defined(CONFIG_SPD_EEPROM)
 /*
  * Fixed sdram init -- doesn't use serial presence detect.
 
 #endif
 
 void local_bus_init(void);
-void sdram_init(void);
-long int fixed_sdram(void);
 
 int checkboard (void)
 {
        return 0;
 }
 
-
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-           volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-           uint temp_ddrdll = 0;
-
-           /*
-            * Work around to stabilize DDR DLL
-            */
-           temp_ddrdll = gur->ddrdllcr;
-           gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
-           asm("sync;isync;msync");
-       }
-#endif
-
-#ifdef CONFIG_SPD_EEPROM
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-
-       dram_size *= 0x100000;
-#else
-       dram_size = fixed_sdram();
-#endif
-
-#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
-       /*
-        * Initialize and enable DDR ECC.
-        */
-       ddr_enable_ecc(dram_size);
-#endif
-
-       /*
-        * Initialize SDRAM.
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
-
 /*
  * Initialize Local Bus
  */
 /*************************************************************************
  *  fixed sdram init -- doesn't use serial presence detect.
  ************************************************************************/
-long int fixed_sdram (void)
+phys_size_t fixed_sdram(void)
 {
   #ifndef CONFIG_SYS_RAMBOOT
        volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
 
        SET_TLB_ENTRY(1, CONFIG_SYS_BCSR, CONFIG_SYS_BCSR,
                      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                      0, 7, BOOKE_PAGESZ_16K, 1),
-
-#if !defined(CONFIG_SPD_EEPROM)
-       /*
-        * TLB 8, 9:    128M    DDR
-        * 0x00000000   64M     DDR System memory
-        * 0x04000000   64M     DDR System memory
-        * Without SPD EEPROM configured DDR, this must be setup manually.
-        * Make sure the TLB count at the top of this table is correct.
-        * Likely it needs to be increased by two for these entries.
-        */
-#error("Update the number of table entries in tlb1_entry")
-       SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
-                     MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 8, BOOKE_PAGESZ_64M, 1),
-
-       SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE + 0x4000000, CONFIG_SYS_DDR_SDRAM_BASE + 0x4000000,
-                     MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 9, BOOKE_PAGESZ_64M, 1),
-#endif
 };
 
 int num_tlb_entries = ARRAY_SIZE(tlb_table);
 
 #endif
 
 void local_bus_init(void);
-void sdram_init(void);
 
 /*
  * I/O Port configuration table
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               /*
-                * Work around to stabilize DDR DLL MSYNC_IN.
-                * Errata DDR9 seems to have been fixed.
-                * This is now the workaround for Errata DDR11:
-                *    Override DLL = 1, Course Adj = 1, Tap Select = 0
-                */
-
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-
-               gur->ddrdllcr = 0x81000000;
-               asm("sync;isync;msync");
-               udelay(200);
-       }
-#endif
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
-       /*
-        * Initialize and enable DDR ECC.
-        */
-       ddr_enable_ecc(dram_size);
-#endif
-       /*
-        * SDRAM Initialization
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 /*
  * Initialize Local Bus
  */
 
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-       dram_size = fsl_ddr_sdram();
-
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-
-       dram_size *= 0x100000;
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 #ifdef CONFIG_PCI1
 static struct pci_controller pci1_hose;
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
 void local_bus_init(void);
-void sdram_init(void);
 
 int checkboard (void)
 {
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               /*
-                * Work around to stabilize DDR DLL MSYNC_IN.
-                * Errata DDR9 seems to have been fixed.
-                * This is now the workaround for Errata DDR11:
-                *    Override DLL = 1, Course Adj = 1, Tap Select = 0
-                */
-
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-
-               gur->ddrdllcr = 0x81000000;
-               asm("sync;isync;msync");
-               udelay(200);
-       }
-#endif
-
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       /*
-        * SDRAM Initialization
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 /*
  * Initialize Local Bus
  */
 
 #endif
 
 void local_bus_init(void);
-void sdram_init(void);
 
 /*
  * I/O Port configuration table
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               /*
-                * Work around to stabilize DDR DLL MSYNC_IN.
-                * Errata DDR9 seems to have been fixed.
-                * This is now the workaround for Errata DDR11:
-                *    Override DLL = 1, Course Adj = 1, Tap Select = 0
-                */
-
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-
-               gur->ddrdllcr = 0x81000000;
-               asm("sync;isync;msync");
-               udelay(200);
-       }
-#endif
-
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
-       /*
-        * Initialize and enable DDR ECC.
-        */
-       ddr_enable_ecc(dram_size);
-#endif
-
-       /*
-        * SDRAM Initialization
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 /*
  * Initialize Local Bus
  */
 
 
 
 void local_bus_init(void);
-void sdram_init(void);
-long int fixed_sdram(void);
 
 
 /*
        return 0;
 }
 
-
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-           volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-           uint temp_ddrdll = 0;
-
-           /*
-            * Work around to stabilize DDR DLL
-            */
-           temp_ddrdll = gur->ddrdllcr;
-           gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
-           asm("sync;isync;msync");
-       }
-#endif
-
-#ifdef CONFIG_SPD_EEPROM
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-
-       dram_size *= 0x100000;
-#else
-       dram_size = fixed_sdram();
-#endif
-
-#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
-       /*
-        * Initialize and enable DDR ECC.
-        */
-       ddr_enable_ecc(dram_size);
-#endif
-
-       /*
-        * Initialize SDRAM.
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
-
 /*
  * Initialize Local Bus
  */
 /*************************************************************************
  *  fixed sdram init -- doesn't use serial presence detect.
  ************************************************************************/
-long int fixed_sdram (void)
+phys_size_t fixed_sdram(void)
 {
   #ifndef CONFIG_SYS_RAMBOOT
        volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
 
        SET_TLB_ENTRY(1, CONFIG_SYS_BCSR, CONFIG_SYS_BCSR,
                      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                      0, 7, BOOKE_PAGESZ_16K, 1),
-
-#if !defined(CONFIG_SPD_EEPROM)
-       /*
-        * TLB 8, 9:    128M    DDR
-        * 0x00000000   64M     DDR System memory
-        * 0x04000000   64M     DDR System memory
-        * Without SPD EEPROM configured DDR, this must be setup manually.
-        * Make sure the TLB count at the top of this table is correct.
-        * Likely it needs to be increased by two for these entries.
-        */
-#error("Update the number of table entries in tlb1_entry")
-       SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
-                     MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 8, BOOKE_PAGESZ_64M, 1),
-
-       SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE + 0x4000000, CONFIG_SYS_DDR_SDRAM_BASE + 0x4000000,
-                     MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 9, BOOKE_PAGESZ_64M, 1),
-#endif
 };
 
 int num_tlb_entries = ARRAY_SIZE(tlb_table);
 
 };
 
 void local_bus_init(void);
-void sdram_init(void);
 
 int board_early_init_f (void)
 {
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               /*
-                * Work around to stabilize DDR DLL MSYNC_IN.
-                * Errata DDR9 seems to have been fixed.
-                * This is now the workaround for Errata DDR11:
-                *    Override DLL = 1, Course Adj = 1, Tap Select = 0
-                */
-
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-
-               gur->ddrdllcr = 0x81000000;
-               asm("sync;isync;msync");
-               udelay(200);
-       }
-#endif
-
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       /*
-        * SDRAM Initialization
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 /*
  * Initialize Local Bus
  */
 
 #include "../common/pq-mds-pib.h"
 #endif
 
-phys_size_t fixed_sdram(void);
-
 const qe_iop_conf_t qe_iop_conf_tab[] = {
        /* QE_MUX_MDC */
        {2,  31, 1, 0, 1}, /* QE_MUX_MDC               */
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       /*
-        * Work around to stabilize DDR DLL MSYNC_IN.
-        * Errata DDR9 seems to have been fixed.
-        * This is now the workaround for Errata DDR11:
-        *    Override DLL = 1, Course Adj = 1, Tap Select = 0
-        */
-       volatile ccsr_gur_t *gur =
-                       (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-
-       out_be32(&gur->ddrdllcr, 0x81000000);
-       udelay(200);
-#endif
-
-#ifdef CONFIG_SPD_EEPROM
-       dram_size = fsl_ddr_sdram();
-#else
-       dram_size = fixed_sdram();
-#endif
-
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 #if !defined(CONFIG_SPD_EEPROM)
 phys_size_t fixed_sdram(void)
 {
 
 
 #include "../common/sgmii_riser.h"
 
-long int fixed_sdram(void);
-
 int checkboard (void)
 {
        u8 vboot;
        return 0;
 }
 
-phys_size_t initdram(int board_type)
-{
-       phys_size_t dram_size = 0;
-
-       puts("Initializing....");
-
-#ifdef CONFIG_SPD_EEPROM
-       dram_size = fsl_ddr_sdram();
-#else
-       dram_size = fixed_sdram();
-#endif
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       puts("    DDR: ");
-       return dram_size;
-}
 
 #if !defined(CONFIG_SPD_EEPROM)
 /*
 
        return 0;
 }
 
-phys_size_t initdram(int board_type)
-{
-       phys_size_t dram_size = 0;
-
-       puts("Initializing....\n");
-
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000) * 0x100000;
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 #define CONFIG_TFP410_I2C_ADDR 0x38
 
 /* Masks for the SSI_TDM and AUDCLK bits of the ngPIXIS BRDCFG1 register. */
 
 
        fsl_ddr_set_memctl_regs(&ddr_cfg_regs, 0);
 
+       set_ddr_laws(0, ddr_size, LAW_TRGT_IF_DDR_1);
        return ddr_size;
 }
-
-phys_size_t initdram(int board_type)
-{
-       phys_size_t dram_size = 0;
-
-       dram_size = fixed_sdram();
-       set_ddr_laws(0, dram_size, LAW_TRGT_IF_DDR_1);
-
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       puts("DDR: ");
-       return dram_size;
-}
 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-phys_size_t fixed_sdram(void);
-
 int checkboard(void)
 {
        u8 sw;
        return 0;
 }
 
-phys_size_t initdram(int board_type)
-{
-       phys_size_t dram_size = 0;
-
-       puts("Initializing....");
-
-#ifdef CONFIG_DDR_SPD
-       dram_size = fsl_ddr_sdram();
-#else
-       dram_size = fixed_sdram();
-
-       if (set_ddr_laws(CONFIG_SYS_DDR_SDRAM_BASE,
-                        dram_size,
-                        LAW_TRGT_IF_DDR) < 0) {
-               printf("ERROR setting Local Access Windows for DDR\n");
-               return 0;
-       };
-#endif
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 #if !defined(CONFIG_DDR_SPD)
 /*
  * Fixed sdram init -- doesn't use serial presence detect.
        udelay(500);
 #endif
 
+       if (set_ddr_laws(CONFIG_SYS_DDR_SDRAM_BASE,
+                        CONFIG_SYS_SDRAM_SIZE * 1024 * 1024,
+                        LAW_TRGT_IF_DDR) < 0) {
+               printf("ERROR setting Local Access Windows for DDR\n");
+               return 0;
+       };
+
        return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
 }
 
 
 DECLARE_GLOBAL_DATA_PTR;
 
 void local_bus_init(void);
-void sdram_init(void);
-long int fixed_sdram (void);
 
 int board_early_init_f (void)
 {
        return 0;
 }
 
-phys_size_t
-initdram(int board_type)
-{
-       long dram_size = 0;
-
-       puts("Initializing\n");
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               /*
-                * Work around to stabilize DDR DLL MSYNC_IN.
-                * Errata DDR9 seems to have been fixed.
-                * This is now the workaround for Errata DDR11:
-                *    Override DLL = 1, Course Adj = 1, Tap Select = 0
-                */
-
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-
-               out_be32(&gur->ddrdllcr, 0x81000000);
-               asm("sync;isync;msync");
-               udelay(200);
-       }
-#endif
-
-#if defined(CONFIG_SPD_EEPROM)
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-#else
-       dram_size = fixed_sdram ();
-#endif
-
-       /*
-        * SDRAM Initialization
-        */
-       sdram_init();
-
-       puts("    DDR: ");
-       return dram_size;
-}
-
 /*
  * Initialize Local Bus
  */
  *  fixed_sdram init -- doesn't use serial presence detect.
  *  assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  ************************************************************************/
-long int fixed_sdram (void)
+phys_size_t fixed_sdram(void)
 {
        volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
 
 
                      0, 1, BOOKE_PAGESZ_1G, 1),
 
        /*
-        * TLB 2:       256M Cacheable, non-guarded
-        * 0x0          256M DDR SDRAM
-        */
-#if !defined(CONFIG_SPD_EEPROM)
-       SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
-                     MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 2, BOOKE_PAGESZ_256M, 1),
-#endif
-
-       /*
-        * TLB 3:       64M     Non-cacheable, guarded
+        * TLB 2:       64M     Non-cacheable, guarded
         * 0xe0000000   1M      CCSRBAR
         * 0xe2000000   8M      PCI1 IO
         * 0xe2800000   8M      PCIe IO
         */
        SET_TLB_ENTRY(1, CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS,
                      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
-                     0, 3, BOOKE_PAGESZ_64M, 1),
+                     0, 2, BOOKE_PAGESZ_64M, 1),
 
        /*
-        * TLB 4:       64M     Cacheable, non-guarded
+        * TLB 3:       64M     Cacheable, non-guarded
         * 0xf0000000   64M     LBC SDRAM First half
         */
        SET_TLB_ENTRY(1, CONFIG_SYS_LBC_SDRAM_BASE, CONFIG_SYS_LBC_SDRAM_BASE,
                      MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 4, BOOKE_PAGESZ_64M, 1),
+                     0, 3, BOOKE_PAGESZ_64M, 1),
 
        /*
-        * TLB 5:       64M     Cacheable, non-guarded
+        * TLB 4:       64M     Cacheable, non-guarded
         * 0xf4000000   64M     LBC SDRAM Second half
         */
        SET_TLB_ENTRY(1, CONFIG_SYS_LBC_SDRAM_BASE + 0x4000000,
                      CONFIG_SYS_LBC_SDRAM_BASE + 0x4000000,
                      MAS3_SX|MAS3_SW|MAS3_SR, 0,
-                     0, 5, BOOKE_PAGESZ_64M, 1),
+                     0, 4, BOOKE_PAGESZ_64M, 1),
 
        /*
-        * TLB 6:       16M     Cacheable, non-guarded
+        * TLB 5:       16M     Cacheable, non-guarded
         * 0xf8000000   1M      7-segment LED display
         * 0xf8100000   1M      User switches
         * 0xf8300000   1M      Board revision
         */
        SET_TLB_ENTRY(1, CONFIG_SYS_EPLD_BASE, CONFIG_SYS_EPLD_BASE,
                      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
-                     0, 6, BOOKE_PAGESZ_16M, 1),
+                     0, 5, BOOKE_PAGESZ_16M, 1),
 
        /*
-        * TLB 7:       4M      Non-cacheable, guarded
+        * TLB 6:       4M      Non-cacheable, guarded
         * 0xfb800000   4M      1st 4MB block of 64MB user FLASH
         */
        SET_TLB_ENTRY(1, CONFIG_SYS_ALT_FLASH, CONFIG_SYS_ALT_FLASH,
                      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
-                     0, 7, BOOKE_PAGESZ_4M, 1),
+                     0, 6, BOOKE_PAGESZ_4M, 1),
 
        /*
-        * TLB 8:       4M      Non-cacheable, guarded
+        * TLB 7:       4M      Non-cacheable, guarded
         * 0xfbc00000   4M      2nd 4MB block of 64MB user FLASH
         */
        SET_TLB_ENTRY(1, CONFIG_SYS_ALT_FLASH + 0x400000,
                      CONFIG_SYS_ALT_FLASH + 0x400000,
                      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
-                     0, 8, BOOKE_PAGESZ_4M, 1),
+                     0, 7, BOOKE_PAGESZ_4M, 1),
 
 };
 
 
 #include <libfdt.h>
 #include <fdt_support.h>
 
-long int fixed_sdram (void);
-
 /*
  * I/O Port configuration table
  *
 }
 
 
-phys_size_t initdram (int board_type)
-{
-       long dram_size = 0;
-
-#if 0
-#if !defined(CONFIG_RAM_AS_FLASH)
-       volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
-       sys_info_t sysinfo;
-       uint temp_lbcdll = 0;
-#endif
-#endif /* 0 */
-#if !defined(CONFIG_RAM_AS_FLASH) || defined(CONFIG_DDR_DLL)
-       volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-#endif
-#if defined(CONFIG_DDR_DLL)
-       uint temp_ddrdll = 0;
-
-       /* Work around to stabilize DDR DLL */
-       temp_ddrdll = gur->ddrdllcr;
-       gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
-       asm("sync;isync;msync");
-#endif
-
-#if defined(CONFIG_SPD_EEPROM)
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-#else
-       dram_size = fixed_sdram ();
-#endif
-
-#if 0
-#if !defined(CONFIG_RAM_AS_FLASH) /* LocalBus SDRAM is not emulating flash */
-       get_sys_info(&sysinfo);
-       /* if localbus freq is less than 66MHz,we use bypass mode,otherwise use DLL */
-       if(sysinfo.freqSystemBus/(CONFIG_SYS_LBC_LCRR & 0x0f) < 66000000) {
-               lbc->lcrr = (CONFIG_SYS_LBC_LCRR & 0x0fffffff)| 0x80000000;
-       } else {
-#if defined(CONFIG_MPC85xx_REV1) /* need change CLKDIV before enable DLL */
-               lbc->lcrr = 0x10000004; /* default CLKDIV is 8, change it to 4 temporarily */
-#endif
-               lbc->lcrr = CONFIG_SYS_LBC_LCRR & 0x7fffffff;
-               udelay(200);
-               temp_lbcdll = gur->lbcdllcr;
-               gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16 ) | 0x80000000;
-               asm("sync;isync;msync");
-       }
-       set_lbc_or(2, CONFIG_SYS_OR2_PRELIM); /* 64MB SDRAM */
-       set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
-       lbc->lbcr = CONFIG_SYS_LBC_LBCR;
-       lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
-       asm("sync");
-       (unsigned int) * (ulong *)0 = 0x000000ff;
-       lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
-       asm("sync");
-       (unsigned int) * (ulong *)0 = 0x000000ff;
-       lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
-       asm("sync");
-       (unsigned int) * (ulong *)0 = 0x000000ff;
-       lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
-       asm("sync");
-       (unsigned int) * (ulong *)0 = 0x000000ff;
-       lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
-       asm("sync");
-       lbc->lsrt = CONFIG_SYS_LBC_LSRT;
-       asm("sync");
-       lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
-       asm("sync");
-#endif
-#endif
-
-#if defined(CONFIG_DDR_ECC)
-       {
-               /* Initialize all of memory for ECC, then
-                * enable errors */
-               volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
-
-               dma_meminit(CONFIG_MEM_INIT_VALUE, dram_size);
-
-               /* Enable errors for ECC */
-               ddr->err_disable = 0x00000000;
-               asm("sync;isync;msync");
-       }
-#endif
-
-       return dram_size;
-}
-
-
 #if defined(CONFIG_SYS_DRAM_TEST)
 int testdram (void)
 {
 /*************************************************************************
  *  fixed sdram init -- doesn't use serial presence detect.
  ************************************************************************/
-long int fixed_sdram (void)
+phys_size_t fixed_sdram(void)
 {
 
 #define CONFIG_SYS_DDR_CONTROL 0xc2000000
 
  *       so this should be extended for other future boards
  *       using this routine!
  */
-long int fixed_sdram(void)
+phys_size_t fixed_sdram(void)
 {
        volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
 
 }
 #endif
 
-phys_size_t initdram (int board_type)
-{
-       long dram_size = 0;
-#if defined(CONFIG_SPD_EEPROM)
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-#else
-       dram_size = fixed_sdram();
-#endif
-       return dram_size;
-}
-
 #if defined(CONFIG_SYS_DRAM_TEST)
 int testdram (void)
 {
 
 #include <spd_sdram.h>
 #include <miiphy.h>
 
-long int fixed_sdram (void);
-
 /*
  * I/O Port configuration table
  *
        next_led_update += (get_tbclk() / 4);
 }
 
-phys_size_t
-initdram (int board_type)
-{
-       long dram_size = 0;
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-               uint temp_ddrdll = 0;
-
-               /* Work around to stabilize DDR DLL */
-               temp_ddrdll = gur->ddrdllcr;
-               gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
-               asm("sync;isync;msync");
-       }
-#endif
-
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-#if defined(CONFIG_DDR_ECC)
-       /* Initialize and enable DDR ECC.
-       */
-       ddr_enable_ecc(dram_size);
-#endif
-
-       return dram_size;
-}
-
 
 #if defined(CONFIG_SYS_DRAM_TEST)
 int testdram (void)
 
 #include <miiphy.h>
 #include <netdev.h>
 
-long int fixed_sdram (void);
-
 /*
  * I/O Port configuration table
  *
        next_led_update += (get_tbclk() / 4);
 }
 
-phys_size_t
-initdram (int board_type)
-{
-       long dram_size = 0;
-
-#if defined(CONFIG_DDR_DLL)
-       {
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-               uint temp_ddrdll = 0;
-
-               /* Work around to stabilize DDR DLL */
-               temp_ddrdll = gur->ddrdllcr;
-               gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
-               asm("sync;isync;msync");
-       }
-#endif
-
-       dram_size = fsl_ddr_sdram();
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-
-#if defined(CONFIG_DDR_ECC)
-       /* Initialize and enable DDR ECC.
-       */
-       ddr_enable_ecc(dram_size);
-#endif
-
-       return dram_size;
-}
-
-
 #if defined(CONFIG_SYS_DRAM_TEST)
 int testdram (void)
 {
 
        return (i < N_DDR_CS_CONF) ? ddr_cs_conf[i].size : 0;
 }
 
-phys_size_t initdram (int board_type)
-{
-       phys_size_t dram_size = 0;
-
-#if defined(CONFIG_DDR_DLL)
-       /*
-        * This DLL-Override only used on TQM8540 and TQM8560
-        */
-       {
-               volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-               int i, x;
-
-               x = 10;
-
-               /*
-                * Work around to stabilize DDR DLL
-                */
-               gur->ddrdllcr = 0x81000000;
-               asm ("sync; isync; msync");
-               udelay (200);
-               while (gur->ddrdllcr != 0x81000100) {
-                       gur->devdisr = gur->devdisr | 0x00010000;
-                       asm ("sync; isync; msync");
-                       for (i = 0; i < x; i++)
-                               ;
-                       gur->devdisr = gur->devdisr & 0xfff7ffff;
-                       asm ("sync; isync; msync");
-                       x++;
-               }
-       }
-#endif
-
-       dram_size = fixed_sdram();
-
-       return dram_size;
-}
-
 #if defined(CONFIG_SYS_DRAM_TEST)
 int testdram (void)
 {
 
        SET_TLB_ENTRY (1, CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS,
                       MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
                       0, 6, BOOKE_PAGESZ_64M, 1),
-
-#if defined(CONFIG_TQM8548_AG) || defined (CONFIG_TQM8548_BE)
-       /*
-        * TLB 7+8:       2G     DDR, cache enabled
-        * 0x00000000     2G     DDR System memory
-        * Without SPD EEPROM configured DDR, this must be setup manually.
-        */
-       SET_TLB_ENTRY (1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
-                      MAS3_SX | MAS3_SW | MAS3_SR, 0,
-                      0, 7, BOOKE_PAGESZ_1G, 1),
-
-       SET_TLB_ENTRY (1, CONFIG_SYS_DDR_SDRAM_BASE + 0x40000000,
-                      CONFIG_SYS_DDR_SDRAM_BASE + 0x40000000,
-                      MAS3_SX | MAS3_SW | MAS3_SR, 0,
-                      0, 8, BOOKE_PAGESZ_1G, 1),
-#else
-       /*
-        * TLB 7+8:     512M     DDR, cache disabled (needed for memory test)
-        * 0x00000000   512M     DDR System memory
-        * Without SPD EEPROM configured DDR, this must be setup manually.
-        */
-       SET_TLB_ENTRY (1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
-                      MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
-                      0, 7, BOOKE_PAGESZ_256M, 1),
-
-       SET_TLB_ENTRY (1, CONFIG_SYS_DDR_SDRAM_BASE + 0x10000000,
-                      CONFIG_SYS_DDR_SDRAM_BASE + 0x10000000,
-                      MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
-                      0, 8, BOOKE_PAGESZ_256M, 1),
-#endif
 #ifdef CONFIG_PCIE1
        /*
         * TLB 9:        16M    Non-cacheable, guarded
        SET_TLB_ENTRY (1, CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS,
                       MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
                       0, 7, BOOKE_PAGESZ_64M, 1),
-
-       /*
-        * TLB 8+9:     512M     DDR, cache disabled (needed for memory test)
-        * 0x00000000   512M     DDR System memory
-        * Without SPD EEPROM configured DDR, this must be setup manually.
-        * Make sure the TLB count at the top of this table is correct.
-        * Likely it needs to be increased by two for these entries.
-        */
-       SET_TLB_ENTRY (1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
-                      MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
-                      0, 8, BOOKE_PAGESZ_256M, 1),
-
-       SET_TLB_ENTRY (1, CONFIG_SYS_DDR_SDRAM_BASE + 0x10000000,
-                      CONFIG_SYS_DDR_SDRAM_BASE + 0x10000000,
-                      MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
-                      0, 9, BOOKE_PAGESZ_256M, 1),
-
 #ifdef CONFIG_PCIE1
        /*
         * TLB 10:       16M    Non-cacheable, guarded
 
 COBJS-$(CONFIG_MPC8572)                += fsl_8xxx_clk.o
 COBJS-$(CONFIG_MPC86xx)                += fsl_8xxx_clk.o
 COBJS-$(CONFIG_P2020)          += fsl_8xxx_clk.o
-COBJS-$(CONFIG_FSL_DDR2)       += fsl_8xxx_ddr.o
-COBJS-$(CONFIG_FSL_DDR3)       += fsl_8xxx_ddr.o
 COBJS-$(CONFIG_MPC85xx)                += fsl_8xxx_misc.o board.o
 COBJS-$(CONFIG_MPC86xx)                += fsl_8xxx_misc.o board.o
 COBJS-$(CONFIG_NAND_ACTL)      += actl_nand.o
 
+++ /dev/null
-/*
- * Copyright 2008 Extreme Engineering Solutions, Inc.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-#include <asm/fsl_ddr_sdram.h>
-#include <asm/mmu.h>
-
-#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
-extern void ddr_enable_ecc(unsigned int dram_size);
-#endif
-
-phys_size_t initdram(int board_type)
-{
-       phys_size_t dram_size = fsl_ddr_sdram();
-
-#ifdef CONFIG_MPC85xx
-       dram_size = setup_ddr_tlbs(dram_size / 0x100000);
-       dram_size *= 0x100000;
-#endif
-
-#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
-       /* Initialize and enable DDR ECC */
-       ddr_enable_ecc(dram_size);
-#endif
-
-       return dram_size;
-}
 
 
 #include <common.h>
 #include <asm/processor.h>
+#include <asm/fsl_ddr_sdram.h>
 #include <asm/mmu.h>
 #include <asm/io.h>
 #include <fdt_support.h>
        return 0;
 }
 
+phys_size_t initdram(int board_type)
+{
+       phys_size_t dram_size = fsl_ddr_sdram();
+
+#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
+       /* Initialize and enable DDR ECC */
+       ddr_enable_ecc(dram_size);
+#endif
+
+       return dram_size;
+}
+
 #if defined(CONFIG_OF_BOARD_SETUP)
 void ft_board_setup(void *blob, bd_t *bd)
 {
 
  * DDR Setup
  */
 #define CONFIG_SYS_DDR_SDRAM_BASE      0x00000000      /* DDR is system memory */
+#if defined(CONFIG_TQM_BIGFLASH) || \
+       (!defined(CONFIG_TQM8548_AG) && !defined(CONFIG_TQM8548_BE))
+#define CONFIG_SYS_PPC_DDR_WIMGE (MAS2_I | MAS2_G)
+#endif
 #define CONFIG_SYS_SDRAM_BASE          CONFIG_SYS_DDR_SDRAM_BASE
 #ifdef CONFIG_TQM8548_AG
 #define CONFIG_VERY_BIG_RAM