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,
28 /* ------------------------------------------------------------------------- */
30 static long int dram_size (long int, long int *, long int);
32 /* ------------------------------------------------------------------------- */
34 #define _NOT_USED_ 0xFFFFCC25
36 const uint sdram_table[] =
39 * Single Read. (Offset 00h in UPMA RAM)
41 0x0F03CC04, 0x00ACCC24, 0x1FF74C20, _NOT_USED_,
42 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
45 * Burst Read. (Offset 08h in UPMA RAM)
47 0x0F03CC04, 0x00ACCC24, 0x00FFCC20, 0x00FFCC20,
48 0x01FFCC20, 0x1FF74C20, _NOT_USED_, _NOT_USED_,
49 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
50 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
53 * Single Write. (Offset 18h in UPMA RAM)
55 0x0F03CC02, 0x00AC0C24, 0x1FF74C25, _NOT_USED_,
56 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
59 * Burst Write. (Offset 20h in UPMA RAM)
61 0x0F03CC00, 0x00AC0C20, 0x00FFFC20, 0x00FFFC22,
62 0x01FFFC24, 0x1FF74C25, _NOT_USED_, _NOT_USED_,
63 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
64 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
67 * Refresh. (Offset 30h in UPMA RAM)
68 * (Initialization code at 0x36)
70 0x0FF0CC24, 0xFFFFCC24, _NOT_USED_, _NOT_USED_,
71 _NOT_USED_, _NOT_USED_, 0xEFFB8C34, 0x0FF74C34,
72 0x0FFACCB4, 0x0FF5CC34, 0x0FFCC34, 0x0FFFCCB4,
75 * Exception. (Offset 3Ch in UPMA RAM)
77 0x0FEA8C34, 0x1FB54C34, 0xFFFFCC34, _NOT_USED_
80 /* ------------------------------------------------------------------------- */
84 * Check Board Identity:
89 puts ("Board: RMU\n") ;
93 /* ------------------------------------------------------------------------- */
95 long int initdram (int board_type)
97 volatile immap_t *immap = (immap_t *)CFG_IMMR;
98 volatile memctl8xx_t *memctl = &immap->im_memctl;
101 upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
103 /* Refresh clock prescalar */
104 memctl->memc_mptpr = CFG_MPTPR ;
106 memctl->memc_mar = 0x00000088;
108 /* Map controller banks 1 to the SDRAM bank */
109 memctl->memc_or1 = CFG_OR1_PRELIM;
110 memctl->memc_br1 = CFG_BR1_PRELIM;
112 memctl->memc_mamr = CFG_MAMR_9COL & (~(MAMR_PTAE)); /* no refresh yet */
116 /* perform SDRAM initializsation sequence */
118 memctl->memc_mcr = 0x80002136 ; /* SDRAM bank 0 */
121 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
125 /* Check Bank 0 Memory Size,
129 size9 = dram_size (CFG_MAMR_9COL, (ulong *)SDRAM_BASE_PRELIM, SDRAM_MAX_SIZE) ;
135 memctl->memc_or1 = ((-size9) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
141 /* ------------------------------------------------------------------------- */
144 * Check memory range for valid RAM. A simple memory test determines
145 * the actually available RAM size between addresses `base' and
146 * `base + maxsize'. Some (not all) hardware errors are detected:
147 * - short between address lines
148 * - short between data lines
151 static long int dram_size (long int mamr_value, long int *base, long int maxsize)
153 volatile immap_t *immap = (immap_t *)CFG_IMMR;
154 volatile memctl8xx_t *memctl = &immap->im_memctl;
155 volatile long int *addr;
157 ulong save[32]; /* to make test non-destructive */
160 memctl->memc_mamr = mamr_value;
162 for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
163 addr = base + cnt; /* pointer arith! */
169 /* write 0 to base address */
174 /* check at base address */
175 if ((val = *addr) != 0) {
180 for (cnt = 1; cnt <= maxsize/sizeof(long); cnt <<= 1) {
181 addr = base + cnt; /* pointer arith! */
187 return (cnt * sizeof(long));