3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/addrspace.h>
27 #include <asm/inca-ip.h>
30 static ulong max_sdram_size(void)
32 /* The only supported SDRAM data width is 16bit.
36 /* The only supported number of SDRAM banks is 4.
40 ulong cfgpb0 = *INCA_IP_SDRAM_MC_CFGPB0;
41 int cols = cfgpb0 & 0xF;
42 int rows = (cfgpb0 & 0xF0) >> 4;
43 ulong size = (1 << (rows + cols)) * CFG_DW * CFG_NB;
49 * Check memory range for valid RAM. A simple memory test determines
50 * the actually available RAM size between addresses `base' and
51 * `base + maxsize'. Some (not all) hardware errors are detected:
52 * - short between address lines
53 * - short between data lines
56 static long int dram_size(long int *base, long int maxsize)
58 volatile long int *addr;
60 ulong save[32]; /* to make test non-destructive */
63 for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
64 addr = base + cnt; /* pointer arith! */
70 /* write 0 to base address */
75 /* check at base address */
76 if ((val = *addr) != 0) {
81 for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
82 addr = base + cnt; /* pointer arith! */
88 return (cnt * sizeof (long));
94 long int initdram(int board_type)
96 int rows, cols, best_val = *INCA_IP_SDRAM_MC_CFGPB0;
97 ulong size, max_size = 0;
100 asm volatile ("move %0, $25" : "=r" (our_address) :);
102 /* Can't probe for RAM size unless we are running from Flash.
104 if (PHYSADDR(our_address) < PHYSADDR(PHYS_FLASH_1))
106 return max_sdram_size();
109 for (cols = 0x8; cols <= 0xC; cols++)
111 for (rows = 0xB; rows <= 0xD; rows++)
113 *INCA_IP_SDRAM_MC_CFGPB0 = (0x14 << 8) |
115 size = dram_size((ulong *)CFG_SDRAM_BASE,
120 best_val = *INCA_IP_SDRAM_MC_CFGPB0;
126 *INCA_IP_SDRAM_MC_CFGPB0 = best_val;