2 * (C) Copyright 2003-2006
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 /* Two MT48LC8M32B2 for 32 MB */
32 /* #include "mt48lc8m32b2-6-7.h" */
34 /* One MT48LC16M32S2 for 64 MB */
35 /* #include "mt48lc16m32s2-75.h" */
36 #if defined (CONFIG_MCC200_SDRAM)
37 #include "mt48lc16m16a2-75.h"
39 #include "mt46v16m16-75.h"
42 DECLARE_GLOBAL_DATA_PTR;
44 extern flash_info_t flash_info[]; /* FLASH chips info */
46 ulong flash_get_size (ulong base, int banknum);
49 static void sdram_start (int hi_addr)
51 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
53 /* unlock mode register */
54 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
55 __asm__ volatile ("sync");
57 /* precharge all banks */
58 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
59 __asm__ volatile ("sync");
62 /* set mode register: extended mode */
63 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
64 __asm__ volatile ("sync");
66 /* set mode register: reset DLL */
67 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
68 __asm__ volatile ("sync");
71 /* precharge all banks */
72 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
73 __asm__ volatile ("sync");
76 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
77 __asm__ volatile ("sync");
79 /* set mode register */
80 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
81 __asm__ volatile ("sync");
83 /* normal operation */
84 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
85 __asm__ volatile ("sync");
92 * ATTENTION: Although partially referenced initdram does NOT make real use
93 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
94 * is something else than 0x00000000.
97 long int initdram (int board_type)
104 /* setup SDRAM chip selects */
105 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
106 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
107 __asm__ volatile ("sync");
109 /* setup config registers */
110 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
111 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
112 __asm__ volatile ("sync");
116 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
117 __asm__ volatile ("sync");
120 /* find RAM size using SDRAM CS0 only */
122 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
124 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
132 /* memory smaller than 1MB is impossible */
133 if (dramsize < (1 << 20)) {
137 /* set SDRAM CS0 size according to the amount of RAM found */
139 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
141 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
144 /* let SDRAM CS1 start right after CS0 */
145 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
147 /* find RAM size using SDRAM CS1 only */
150 test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
153 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
162 /* memory smaller than 1MB is impossible */
163 if (dramsize2 < (1 << 20)) {
167 /* set SDRAM CS1 size according to the amount of RAM found */
169 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
170 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
172 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
175 #else /* CFG_RAMBOOT */
177 /* retrieve size of memory connected to SDRAM CS0 */
178 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
179 if (dramsize >= 0x13) {
180 dramsize = (1 << (dramsize - 0x13)) << 20;
185 /* retrieve size of memory connected to SDRAM CS1 */
186 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
187 if (dramsize2 >= 0x13) {
188 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
193 #endif /* CFG_RAMBOOT */
195 return dramsize + dramsize2;
198 int checkboard (void)
200 puts ("Board: MCC200\n");
204 int misc_init_r (void)
206 ulong flash_sup_end, snum;
209 * Adjust flash start and offset to detected values
211 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
212 gd->bd->bi_flashoffset = 0;
215 * Check if boot FLASH isn't max size
217 if (gd->bd->bi_flashsize < (0 - CFG_FLASH_BASE)) {
219 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
220 START_REG(gd->bd->bi_flashstart);
221 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
222 STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize);
225 * Re-check to get correct base address
227 flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
230 * Re-do flash protection upon new addresses
232 flash_protect (FLAG_PROTECT_CLEAR,
233 gd->bd->bi_flashstart, 0xffffffff,
234 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
236 /* Monitor protection ON by default */
237 flash_protect (FLAG_PROTECT_SET,
238 CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1,
239 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
241 /* Environment protection ON by default */
242 flash_protect (FLAG_PROTECT_SET,
244 CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
245 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
247 /* Redundant environment protection ON by default */
248 flash_protect (FLAG_PROTECT_SET,
250 CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
251 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
254 if (gd->bd->bi_flashsize > (32 << 20)) {
255 /* Unprotect the upper bank of the Flash */
256 *(volatile int*)MPC5XXX_CS0_CFG |= (1 << 6);
257 flash_protect (FLAG_PROTECT_CLEAR,
258 flash_info[0].start[0] + flash_info[0].size / 2,
259 (flash_info[0].start[0] - 1) + flash_info[0].size,
261 *(volatile int*)MPC5XXX_CS0_CFG &= ~(1 << 6);
262 printf ("Warning: Only 32 of 64 MB of Flash are accessible from U-Boot\n");
263 flash_info[0].size = 32 << 20;
264 for (snum = 0, flash_sup_end = gd->bd->bi_flashstart + (32<<20);
265 flash_info[0].start[snum] < flash_sup_end;
267 flash_info[0].sector_count = snum;
274 static struct pci_controller hose;
276 extern void pci_mpc5xxx_init(struct pci_controller *);
278 void pci_init_board(void)
280 pci_mpc5xxx_init(&hose);
284 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
286 void init_ide_reset (void)
288 debug ("init_ide_reset\n");
292 void ide_set_reset (int idereset)
294 debug ("ide_reset(%d)\n", idereset);
297 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
299 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
300 extern void doc_probe (ulong physadr);
303 doc_probe (CFG_DOC_BASE);