2 * (C) Copyright 2003-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@freescale.com.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #ifndef CONFIG_SYS_RAMBOOT
33 static void mpc5xxx_sdram_start (sdram_conf_t *sdram_conf, int hi_addr)
35 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
37 /* unlock mode register */
38 *(vu_long *)MPC5XXX_SDRAM_CTRL = sdram_conf->control | 0x80000000 | hi_addr_bit;
39 __asm__ volatile ("sync");
41 /* precharge all banks */
42 *(vu_long *)MPC5XXX_SDRAM_CTRL = sdram_conf->control | 0x80000002 | hi_addr_bit;
43 __asm__ volatile ("sync");
45 if (sdram_conf->ddr) {
46 /* set mode register: extended mode */
47 *(vu_long *)MPC5XXX_SDRAM_MODE = sdram_conf->emode;
48 __asm__ volatile ("sync");
50 /* set mode register: reset DLL */
51 *(vu_long *)MPC5XXX_SDRAM_MODE = sdram_conf->mode | 0x04000000;
52 __asm__ volatile ("sync");
55 /* precharge all banks */
56 *(vu_long *)MPC5XXX_SDRAM_CTRL = sdram_conf->control | 0x80000002 | hi_addr_bit;
57 __asm__ volatile ("sync");
60 *(vu_long *)MPC5XXX_SDRAM_CTRL = sdram_conf->control | 0x80000004 | hi_addr_bit;
61 __asm__ volatile ("sync");
63 /* set mode register */
64 *(vu_long *)MPC5XXX_SDRAM_MODE = sdram_conf->mode;
65 __asm__ volatile ("sync");
67 /* normal operation */
68 *(vu_long *)MPC5XXX_SDRAM_CTRL = sdram_conf->control | hi_addr_bit;
69 __asm__ volatile ("sync");
74 * ATTENTION: Although partially referenced initdram does NOT make real use
75 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
76 * is something else than 0x00000000.
79 long int mpc5xxx_sdram_init (sdram_conf_t *sdram_conf)
83 #ifndef CONFIG_SYS_RAMBOOT
86 /* setup SDRAM chip selects */
87 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
88 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
89 __asm__ volatile ("sync");
91 /* setup config registers */
92 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = sdram_conf->config1;
93 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = sdram_conf->config2;
94 __asm__ volatile ("sync");
96 if (sdram_conf->ddr) {
98 *(vu_long *)MPC5XXX_CDM_PORCFG = sdram_conf->tapdelay;
99 __asm__ volatile ("sync");
102 /* find RAM size using SDRAM CS0 only */
103 mpc5xxx_sdram_start(sdram_conf, 0);
104 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
105 mpc5xxx_sdram_start(sdram_conf, 1);
106 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
108 mpc5xxx_sdram_start(sdram_conf, 0);
114 /* memory smaller than 1MB is impossible */
115 if (dramsize < (1 << 20)) {
119 /* set SDRAM CS0 size according to the amount of RAM found */
121 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
123 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
126 /* let SDRAM CS1 start right after CS0 */
127 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
129 /* find RAM size using SDRAM CS1 only */
130 mpc5xxx_sdram_start(sdram_conf, 0);
131 test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
132 mpc5xxx_sdram_start(sdram_conf, 1);
133 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
135 mpc5xxx_sdram_start(sdram_conf, 0);
141 /* memory smaller than 1MB is impossible */
142 if (dramsize2 < (1 << 20)) {
146 /* set SDRAM CS1 size according to the amount of RAM found */
148 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
149 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
151 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
154 #else /* CONFIG_SYS_RAMBOOT */
156 /* retrieve size of memory connected to SDRAM CS0 */
157 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
158 if (dramsize >= 0x13) {
159 dramsize = (1 << (dramsize - 0x13)) << 20;
164 /* retrieve size of memory connected to SDRAM CS1 */
165 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
166 if (dramsize2 >= 0x13) {
167 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
172 #endif /* CONFIG_SYS_RAMBOOT */
174 return dramsize + dramsize2;