]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - board/esd/pmc440/sdram.c
drivers, block: remove sil680 driver
[people/ms/u-boot.git] / board / esd / pmc440 / sdram.c
index 197857ad097381dfe125e09a2ed3c340b3f7e0e0..c379e7723d5f1449c1824773cedfa5b376b2cbde 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * (C) Copyright 2009
+ * Matthias Fuchs, esd gmbh, matthias.fuchs@esd.eu
+ *
  * (C) Copyright 2006
  * Sylvie Gohl,             AMCC/IBM, gohl.sylvie@fr.ibm.com
  * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
@@ -9,20 +12,7 @@
  * (C) Copyright 2006-2007
  * Stefan Roese, DENX Software Engineering, sr@denx.de.
  *
- * 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+
  */
 
 /* define DEBUG for debug output */
 #include <common.h>
 #include <asm/processor.h>
 #include <asm/io.h>
-#include <ppc440.h>
+#include <asm/mmu.h>
+#include <asm/ppc440.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 extern int denali_wait_for_dlllock(void);
 extern void denali_core_search_data_eye(void);
 
+struct sdram_conf_s {
+       ulong size;
+       int rows;
+       int banks;
+};
 
-#if defined(CONFIG_NAND_SPL)
-/* Using cpu/ppc4xx/speed.c to calculate the bus frequency is too big
- * for the 4k NAND boot image so define bus_frequency to 133MHz here
- * which is save for the refresh counter setup.
- */
-#define get_bus_freq(val)      133000000
-#endif
+struct sdram_conf_s sdram_conf[] = {
+       {(1024 << 20), 14, 8}, /* 1GByte: 4x2GBit, 14x10, 8 banks */
+       {(512 << 20),  13, 8}, /* 512MByte: 4x1GBit, 13x10, 8 banks */
+       {(256 << 20),  13, 4}, /* 256MByte: 4x512MBit, 13x10, 4 banks */
+};
 
-/*************************************************************************
- *
- * initdram -- 440EPx's DDR controller is a DENALI Core
- *
- ************************************************************************/
-phys_size_t initdram (int board_type)
+/*
+ * dram_init -- 440EPx's DDR controller is a DENALI Core
+ */
+int initdram_by_rb(int rows, int banks)
 {
-#if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
-#if !defined(CONFIG_NAND_SPL)
        ulong speed = get_bus_freq(0);
-#else
-       ulong speed = 133333333;        /* 133MHz is on the safe side   */
-#endif
 
        mtsdram(DDR0_02, 0x00000000);
 
@@ -70,7 +59,7 @@ phys_size_t initdram (int board_type)
        mtsdram(DDR0_07, 0x000D0100);
        mtsdram(DDR0_08, 0x02430001);
        mtsdram(DDR0_09, 0x00011D5F);
-       mtsdram(DDR0_10, 0x00000300);
+       mtsdram(DDR0_10, 0x00000100);
        mtsdram(DDR0_11, 0x0027C800);
        mtsdram(DDR0_12, 0x00000003);
        mtsdram(DDR0_14, 0x00000000);
@@ -89,21 +78,25 @@ phys_size_t initdram (int board_type)
        mtsdram(DDR0_27, 0x0000682B);
        mtsdram(DDR0_28, 0x00000000);
        mtsdram(DDR0_31, 0x00000000);
-       mtsdram(DDR0_42, 0x01000006);
-       mtsdram(DDR0_43, 0x030A0200);
+
+       mtsdram(DDR0_42,
+               DDR0_42_ADDR_PINS_DECODE(14 - rows) |
+               0x00000006);
+       mtsdram(DDR0_43,
+               DDR0_43_EIGHT_BANK_MODE_ENCODE(8 == banks ? 1 : 0) |
+               0x030A0200);
+
        mtsdram(DDR0_44, 0x00000003);
        mtsdram(DDR0_02, 0x00000001);
 
        denali_wait_for_dlllock();
-#endif /* #ifndef CONFIG_NAND_U_BOOT */
 
 #ifdef CONFIG_DDR_DATA_EYE
-       /* -----------------------------------------------------------+
+       /*
         * Perform data eye search if requested.
-        * ----------------------------------------------------------*/
+        */
        denali_core_search_data_eye();
 #endif
-
        /*
         * Clear possible errors resulting from data-eye-search.
         * If not done, then we could get an interrupt later on when
@@ -111,5 +104,37 @@ phys_size_t initdram (int board_type)
         */
        set_mcsr(get_mcsr());
 
-       return (CONFIG_SYS_MBYTES_SDRAM << 20);
+       return 0;
+}
+
+int dram_init(void)
+{
+       phys_size_t size;
+       int n;
+
+       /* go through supported memory configurations */
+       for (n = 0; n < ARRAY_SIZE(sdram_conf); n++) {
+               size = sdram_conf[n].size;
+
+               /* program TLB entries */
+               program_tlb(0, CONFIG_SYS_SDRAM_BASE, size,
+                           TLB_WORD2_I_ENABLE);
+
+               /*
+                * setup denali core
+                */
+               initdram_by_rb(sdram_conf[n].rows,
+                              sdram_conf[n].banks);
+
+               /* check for suitable configuration */
+               if (get_ram_size(CONFIG_SYS_SDRAM_BASE, size) == size) {
+                       gd->ram_size = size;
+                       return 0;
+               }
+
+               /* delete TLB entries */
+               remove_tlb(CONFIG_SYS_SDRAM_BASE, size);
+       }
+
+       return -ENXIO;
 }