3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.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,
31 #if defined(CONFIG_MPC5200_DDR)
32 #include "mt46v16m16-75.h"
34 #include "mt48lc16m16a2-75.h"
38 static void sdram_start (int hi_addr)
40 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
42 /* unlock mode register */
43 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
44 __asm__ volatile ("sync");
46 /* precharge all banks */
47 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
48 __asm__ volatile ("sync");
51 /* set mode register: extended mode */
52 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
53 __asm__ volatile ("sync");
55 /* set mode register: reset DLL */
56 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
57 __asm__ volatile ("sync");
60 /* precharge all banks */
61 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
62 __asm__ volatile ("sync");
65 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
66 __asm__ volatile ("sync");
68 /* set mode register */
69 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
70 __asm__ volatile ("sync");
72 /* normal operation */
73 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
74 __asm__ volatile ("sync");
79 * ATTENTION: Although partially referenced initdram does NOT make real use
80 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
81 * is something else than 0x00000000.
84 #if defined(CONFIG_MPC5200)
85 long int initdram (int board_type)
92 /* setup SDRAM chip selects */
93 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
94 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
95 __asm__ volatile ("sync");
97 /* setup config registers */
98 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
99 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
100 __asm__ volatile ("sync");
104 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
105 __asm__ volatile ("sync");
108 /* find RAM size using SDRAM CS0 only */
110 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
112 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
120 /* memory smaller than 1MB is impossible */
121 if (dramsize < (1 << 20)) {
125 /* set SDRAM CS0 size according to the amount of RAM found */
127 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
129 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
132 /* let SDRAM CS1 start right after CS0 */
133 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
135 /* find RAM size using SDRAM CS1 only */
137 test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
139 test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
147 /* memory smaller than 1MB is impossible */
148 if (dramsize2 < (1 << 20)) {
152 /* set SDRAM CS1 size according to the amount of RAM found */
154 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
155 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
157 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
160 #else /* CFG_RAMBOOT */
162 /* retrieve size of memory connected to SDRAM CS0 */
163 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
164 if (dramsize >= 0x13) {
165 dramsize = (1 << (dramsize - 0x13)) << 20;
170 /* retrieve size of memory connected to SDRAM CS1 */
171 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
172 if (dramsize2 >= 0x13) {
173 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
178 #endif /* CFG_RAMBOOT */
180 return dramsize + dramsize2;
183 #elif defined(CONFIG_MGT5100)
185 long int initdram (int board_type)
191 /* setup and enable SDRAM chip selects */
192 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
193 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
194 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
195 __asm__ volatile ("sync");
197 /* setup config registers */
198 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
199 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
201 /* address select register */
202 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
203 __asm__ volatile ("sync");
207 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
209 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
217 /* set SDRAM end address according to size */
218 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
220 #else /* CFG_RAMBOOT */
222 /* Retrieve amount of SDRAM available */
223 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
225 #endif /* CFG_RAMBOOT */
231 #error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
234 int checkboard (void)
236 #if defined(CONFIG_MPC5200)
237 puts ("Board: Motorola MPC5200 (IceCube)\n");
238 #elif defined(CONFIG_MGT5100)
239 puts ("Board: Motorola MGT5100 (IceCube)\n");
244 void flash_preinit(void)
247 * Now, when we are in RAM, enable flash write
248 * access for detection process.
249 * Note that CS_BOOT cannot be cleared when
250 * executing in flash.
252 #if defined(CONFIG_MGT5100)
253 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
254 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
256 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
259 void flash_afterinit(ulong size)
261 if (size == 0x800000) { /* adjust mapping */
262 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
263 START_REG(CFG_BOOTCS_START | size);
264 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
265 STOP_REG(CFG_BOOTCS_START | size, size);
270 static struct pci_controller hose;
272 extern void pci_mpc5xxx_init(struct pci_controller *);
274 void pci_init_board(void)
276 pci_mpc5xxx_init(&hose);
280 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
282 #define GPIO_PSC1_4 0x01000000UL
284 void init_ide_reset (void)
286 debug ("init_ide_reset\n");
288 /* Configure PSC1_4 as GPIO output for ATA reset */
289 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
290 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
292 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
295 void ide_set_reset (int idereset)
297 debug ("ide_reset(%d)\n", idereset);
300 *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
301 /* Make a delay. MPC5200 spec says 25 usec min */
304 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
307 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */