2 * (C) Copyright 2003-2004
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"
37 DECLARE_GLOBAL_DATA_PTR;
40 static void sdram_start (int hi_addr)
42 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
44 /* unlock mode register */
45 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
46 __asm__ volatile ("sync");
48 /* precharge all banks */
49 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
50 __asm__ volatile ("sync");
53 /* set mode register: extended mode */
54 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
55 __asm__ volatile ("sync");
57 /* set mode register: reset DLL */
58 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
59 __asm__ volatile ("sync");
62 /* precharge all banks */
63 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
64 __asm__ volatile ("sync");
67 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
68 __asm__ volatile ("sync");
70 /* set mode register */
71 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
72 __asm__ volatile ("sync");
74 /* normal operation */
75 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
76 __asm__ volatile ("sync");
81 * ATTENTION: Although partially referenced initdram does NOT make real use
82 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
83 * is something else than 0x00000000.
86 #if defined(CONFIG_MPC5200)
87 long int initdram (int board_type)
94 /* setup SDRAM chip selects */
95 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
96 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
97 __asm__ volatile ("sync");
99 /* setup config registers */
100 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
101 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
102 __asm__ volatile ("sync");
106 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
107 __asm__ volatile ("sync");
110 /* find RAM size using SDRAM CS0 only */
112 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
114 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
122 /* memory smaller than 1MB is impossible */
123 if (dramsize < (1 << 20)) {
127 /* set SDRAM CS0 size according to the amount of RAM found */
129 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
131 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
134 /* let SDRAM CS1 start right after CS0 */
135 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
137 /* find RAM size using SDRAM CS1 only */
140 test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
143 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
152 /* memory smaller than 1MB is impossible */
153 if (dramsize2 < (1 << 20)) {
157 /* set SDRAM CS1 size according to the amount of RAM found */
159 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
160 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
162 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
165 #else /* CFG_RAMBOOT */
167 /* retrieve size of memory connected to SDRAM CS0 */
168 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
169 if (dramsize >= 0x13) {
170 dramsize = (1 << (dramsize - 0x13)) << 20;
175 /* retrieve size of memory connected to SDRAM CS1 */
176 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
177 if (dramsize2 >= 0x13) {
178 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
183 #endif /* CFG_RAMBOOT */
185 return dramsize + dramsize2;
188 #elif defined(CONFIG_MGT5100)
190 long int initdram (int board_type)
196 /* setup and enable SDRAM chip selects */
197 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
198 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
199 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
200 __asm__ volatile ("sync");
202 /* setup config registers */
203 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
204 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
206 /* address select register */
207 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
208 __asm__ volatile ("sync");
212 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
214 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
222 /* set SDRAM end address according to size */
223 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
225 #else /* CFG_RAMBOOT */
227 /* Retrieve amount of SDRAM available */
228 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
230 #endif /* CFG_RAMBOOT */
236 #error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
239 int checkboard (void)
241 #if defined(CONFIG_MPC5200)
242 puts ("Board: MicroSys PM520 \n");
243 #elif defined(CONFIG_MGT5100)
244 puts ("Board: MicroSys PM510 \n");
249 void flash_preinit(void)
252 * Now, when we are in RAM, enable flash write
253 * access for detection process.
254 * Note that CS_BOOT cannot be cleared when
255 * executing in flash.
257 #if defined(CONFIG_MGT5100)
258 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
259 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
261 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
264 void flash_afterinit(ulong start, ulong size)
266 #if defined(CONFIG_BOOT_ROM)
268 *(vu_long *)MPC5XXX_CS1_START =
270 *(vu_long *)MPC5XXX_CS1_STOP =
271 STOP_REG(start, size);
274 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
276 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
277 STOP_REG(start, size);
282 extern flash_info_t flash_info[]; /* info for FLASH chips */
284 int misc_init_r (void)
286 /* adjust flash start */
287 gd->bd->bi_flashstart = flash_info[0].start[0];
292 static struct pci_controller hose;
294 extern void pci_mpc5xxx_init(struct pci_controller *);
296 void pci_init_board(void)
298 pci_mpc5xxx_init(&hose);
302 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
304 void init_ide_reset (void)
306 debug ("init_ide_reset\n");
310 void ide_set_reset (int idereset)
312 debug ("ide_reset(%d)\n", idereset);
315 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
317 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
318 extern void doc_probe (ulong physadr);
321 doc_probe (CFG_DOC_BASE);