Merge branch 'master' of git://git.denx.de/u-boot-mpc85xx
[oweals/u-boot.git] / arch / arm / cpu / armv7 / omap3 / sdrc.c
index 2719bb53a7cc343a2e677493d682fbf27905aeee..0dd1955431dc89787a9c70289e328fae483881ce 100644 (file)
@@ -8,6 +8,9 @@
  * Copyright (C) 2004-2010
  * Texas Instruments Incorporated - http://www.ti.com/
  *
+ * Copyright (C) 2011
+ * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
+ *
  * Author :
  *     Vaibhav Hiremath <hvaibhav@ti.com>
  *
@@ -37,6 +40,7 @@
 #include <asm/arch/mem.h>
 #include <asm/arch/sys_proto.h>
 
+DECLARE_GLOBAL_DATA_PTR;
 extern omap3_sysinfo sysinfo;
 
 static struct sdrc *sdrc_base = (struct sdrc *)OMAP34XX_SDRC_BASE;
@@ -99,7 +103,7 @@ u32 get_sdr_cs_offset(u32 cs)
                return 0;
 
        offset = readl(&sdrc_base->cs_cfg);
-       offset = (offset & 15) << 27 | (offset & 0x30) >> 17;
+       offset = (offset & 15) << 27 | (offset & 0x30) << 17;
 
        return offset;
 }
@@ -132,13 +136,40 @@ void do_sdrc_init(u32 cs, u32 early)
                sdelay(0x20000);
        }
 
+/* As long as V_MCFG and V_RFR_CTRL is not defined for all OMAP3 boards we need
+ * to prevent this to be build in non-SPL build */
+#ifdef CONFIG_SPL_BUILD
+       /* If we use a SPL there is no x-loader nor config header so we have
+        * to do the job ourselfs
+        */
+       if (cs == CS0) {
+               sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
+
+               /* General SDRC config */
+               writel(V_MCFG, &sdrc_base->cs[cs].mcfg);
+               writel(V_RFR_CTRL, &sdrc_base->cs[cs].rfr_ctrl);
+
+               /* AC timings */
+               writel(V_ACTIMA_165, &sdrc_actim_base0->ctrla);
+               writel(V_ACTIMB_165, &sdrc_actim_base0->ctrlb);
+
+               /* Initialize */
+               writel(CMD_NOP, &sdrc_base->cs[cs].manual);
+               writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
+               writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
+               writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
+
+               writel(V_MR, &sdrc_base->cs[cs].mr);
+       }
+#endif
+
        /*
         * SDRC timings are set up by x-load or config header
         * We don't need to redo them here.
         * Older x-loads configure only CS0
         * configure CS1 to handle this ommission
         */
-       if (cs) {
+       if (cs == CS1) {
                sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
                sdrc_actim_base1 = (struct sdrc_actim *)SDRC_ACTIM_CTRL1_BASE;
                writel(readl(&sdrc_base->cs[CS0].mcfg),
@@ -149,6 +180,13 @@ void do_sdrc_init(u32 cs, u32 early)
                        &sdrc_actim_base1->ctrla);
                writel(readl(&sdrc_actim_base0->ctrlb),
                        &sdrc_actim_base1->ctrlb);
+
+               writel(CMD_NOP, &sdrc_base->cs[cs].manual);
+               writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
+               writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
+               writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
+               writel(readl(&sdrc_base->cs[CS0].mr),
+                       &sdrc_base->cs[CS1].mr);
        }
 
        /*
@@ -163,36 +201,8 @@ void do_sdrc_init(u32 cs, u32 early)
  * dram_init -
  *  - Sets uboots idea of sdram size
  */
-#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
-int dram_init(void)
-{
-       DECLARE_GLOBAL_DATA_PTR;
-       unsigned int size0 = 0, size1 = 0;
-
-       size0 = get_sdr_cs_size(CS0);
-       /*
-        * If a second bank of DDR is attached to CS1 this is
-        * where it can be started.  Early init code will init
-        * memory on CS0.
-        */
-       if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED)) {
-               do_sdrc_init(CS1, NOT_EARLY);
-               make_cs1_contiguous();
-
-               size1 = get_sdr_cs_size(CS1);
-       }
-
-       gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
-       gd->bd->bi_dram[0].size = size0;
-       gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
-       gd->bd->bi_dram[1].size = size1;
-
-       return 0;
-}
-#else
 int dram_init(void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        unsigned int size0 = 0, size1 = 0;
 
        size0 = get_sdr_cs_size(CS0);
@@ -214,7 +224,6 @@ int dram_init(void)
 
 void dram_init_banksize (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        unsigned int size0 = 0, size1 = 0;
 
        size0 = get_sdr_cs_size(CS0);
@@ -225,7 +234,6 @@ void dram_init_banksize (void)
        gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
        gd->bd->bi_dram[1].size = size1;
 }
-#endif
 
 /*
  * mem_init -