]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - arch/arm/cpu/armv7/omap3/sdrc.c
sunxi: add sun7i cpu, board and start of day support
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / omap3 / sdrc.c
index 66ce33f785124a3584e8408a0d1f86f682c48849..7a291318ab0722e67b6a4c1624c9de260a9e5855 100644 (file)
  *      Shashi Ranjan <shashiranjanmca05@gmail.com>
  *      Manikandan Pillai <mani.pillai@ti.com>
  *
- * 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
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -102,21 +89,64 @@ 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 & 0x300) << 17;
 
        return offset;
 }
 
+/*
+ * write_sdrc_timings -
+ *  - Takes CS and associated timings and initalize SDRAM
+ *  - Test CS to make sure it's OK for use
+ */
+static void write_sdrc_timings(u32 cs, struct sdrc_actim *sdrc_actim_base,
+                       struct board_sdrc_timings *timings)
+{
+       /* Setup timings we got from the board. */
+       writel(timings->mcfg, &sdrc_base->cs[cs].mcfg);
+       writel(timings->ctrla, &sdrc_actim_base->ctrla);
+       writel(timings->ctrlb, &sdrc_actim_base->ctrlb);
+       writel(timings->rfr_ctrl, &sdrc_base->cs[cs].rfr_ctrl);
+       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(timings->mr, &sdrc_base->cs[cs].mr);
+
+       /*
+        * Test ram in this bank
+        * Disable if bad or not present
+        */
+       if (!mem_ok(cs))
+               writel(0, &sdrc_base->cs[cs].mcfg);
+}
+
 /*
  * do_sdrc_init -
- *  - Initialize the SDRAM for use.
- *  - code called once in C-Stack only context for CS0 and a possible 2nd
- *    time depending on memory configuration from stack+global context
+ *  - Code called once in C-Stack only context for CS0 and with early being
+ *    true and a possible 2nd time depending on memory configuration from
+ *    stack+global context.
  */
 void do_sdrc_init(u32 cs, u32 early)
 {
        struct sdrc_actim *sdrc_actim_base0, *sdrc_actim_base1;
+       struct board_sdrc_timings timings;
+
+       sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
+       sdrc_actim_base1 = (struct sdrc_actim *)SDRC_ACTIM_CTRL1_BASE;
 
+       /*
+        * When called in the early context this may be SPL and we will
+        * need to set all of the timings.  This ends up being board
+        * specific so we call a helper function to take care of this
+        * for us.  Otherwise, to be safe, we need to copy the settings
+        * from the first bank to the second.  We will setup CS0,
+        * then set cs_cfg to the appropriate value then try and
+        * setup CS1.
+        */
+#ifdef CONFIG_SPL_BUILD
+       get_board_mem_timings(&timings);
+#endif
        if (early) {
                /* reset sdrc controller */
                writel(SOFTRESET, &sdrc_base->sysconfig);
@@ -127,73 +157,34 @@ void do_sdrc_init(u32 cs, u32 early)
                /* setup sdrc to ball mux */
                writel(SDRC_SHARING, &sdrc_base->sharing);
 
-               /* Disable Power Down of CKE cuz of 1 CKE on combo part */
+               /* Disable Power Down of CKE because of 1 CKE on combo part */
                writel(WAKEUPPROC | SRFRONRESET | PAGEPOLICY_HIGH,
                                &sdrc_base->power);
 
                writel(ENADLL | DLLPHASE_90, &sdrc_base->dlla_ctrl);
                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);
+               write_sdrc_timings(CS0, sdrc_actim_base0, &timings);
+               make_cs1_contiguous();
+               write_sdrc_timings(CS1, sdrc_actim_base1, &timings);
+#endif
 
-               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 we aren't using SPL we have been loaded by some
+        * other means which may not have correctly initialized
+        * both CS0 and CS1 (such as some older versions of x-loader)
+        * so we may be asked now to setup CS1.
         */
        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),
-                       &sdrc_base->cs[CS1].mcfg);
-               writel(readl(&sdrc_base->cs[CS0].rfr_ctrl),
-                       &sdrc_base->cs[CS1].rfr_ctrl);
-               writel(readl(&sdrc_actim_base0->ctrla),
-                       &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);
+               timings.mcfg = readl(&sdrc_base->cs[CS0].mcfg),
+               timings.rfr_ctrl = readl(&sdrc_base->cs[CS0].rfr_ctrl);
+               timings.ctrla = readl(&sdrc_actim_base0->ctrla);
+               timings.ctrlb = readl(&sdrc_actim_base0->ctrlb);
+               timings.mr = readl(&sdrc_base->cs[CS0].mr);
+               write_sdrc_timings(cs, sdrc_actim_base1, &timings);
        }
-
-       /*
-        * Test ram in this bank
-        * Disable if bad or not present
-        */
-       if (!mem_ok(cs))
-               writel(0, &sdrc_base->cs[cs].mcfg);
 }
 
 /*