wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003-2004 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 5 | * (C) Copyright 2004 |
| 6 | * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com. |
| 7 | * |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <mpc5xxx.h> |
| 29 | #include <pci.h> |
| 30 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 31 | #if defined(CONFIG_MPC5200_DDR) |
| 32 | #include "mt46v16m16-75.h" |
| 33 | #else |
| 34 | #include "mt48lc16m16a2-75.h" |
| 35 | #endif |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 36 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 37 | #ifndef CFG_RAMBOOT |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 38 | static void sdram_start (int hi_addr) |
| 39 | { |
| 40 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 41 | |
| 42 | /* unlock mode register */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 43 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit; |
| 44 | __asm__ volatile ("sync"); |
| 45 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 46 | /* precharge all banks */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 47 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
| 48 | __asm__ volatile ("sync"); |
| 49 | |
| 50 | #if SDRAM_DDR |
| 51 | /* set mode register: extended mode */ |
| 52 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE; |
| 53 | __asm__ volatile ("sync"); |
| 54 | |
| 55 | /* set mode register: reset DLL */ |
| 56 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000; |
| 57 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 58 | #endif |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 59 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 60 | /* precharge all banks */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 61 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
| 62 | __asm__ volatile ("sync"); |
| 63 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 64 | /* auto refresh */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 65 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit; |
| 66 | __asm__ volatile ("sync"); |
| 67 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 68 | /* set mode register */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 69 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE; |
| 70 | __asm__ volatile ("sync"); |
| 71 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 72 | /* normal operation */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 73 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit; |
| 74 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 75 | } |
| 76 | #endif |
| 77 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 78 | /* |
| 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. |
| 82 | */ |
| 83 | |
| 84 | #if defined(CONFIG_MPC5200) |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 85 | long int initdram (int board_type) |
| 86 | { |
| 87 | ulong dramsize = 0; |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 88 | ulong dramsize2 = 0; |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 89 | #ifndef CFG_RAMBOOT |
| 90 | ulong test1, test2; |
| 91 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 92 | /* setup SDRAM chip selects */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 93 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */ |
| 94 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 95 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 96 | |
| 97 | /* setup config registers */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 98 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1; |
| 99 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2; |
| 100 | __asm__ volatile ("sync"); |
| 101 | |
| 102 | #if SDRAM_DDR |
| 103 | /* set tap delay */ |
| 104 | *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY; |
| 105 | __asm__ volatile ("sync"); |
| 106 | #endif |
| 107 | |
| 108 | /* find RAM size using SDRAM CS0 only */ |
| 109 | sdram_start(0); |
| 110 | test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000); |
| 111 | sdram_start(1); |
| 112 | test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000); |
| 113 | if (test1 > test2) { |
| 114 | sdram_start(0); |
| 115 | dramsize = test1; |
| 116 | } else { |
| 117 | dramsize = test2; |
| 118 | } |
| 119 | |
| 120 | /* memory smaller than 1MB is impossible */ |
| 121 | if (dramsize < (1 << 20)) { |
| 122 | dramsize = 0; |
| 123 | } |
| 124 | |
| 125 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 126 | if (dramsize > 0) { |
| 127 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1; |
| 128 | } else { |
| 129 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */ |
| 130 | } |
| 131 | |
| 132 | /* let SDRAM CS1 start right after CS0 */ |
| 133 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */ |
| 134 | |
| 135 | /* find RAM size using SDRAM CS1 only */ |
| 136 | sdram_start(0); |
| 137 | test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000); |
| 138 | sdram_start(1); |
| 139 | test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000); |
| 140 | if (test1 > test2) { |
| 141 | sdram_start(0); |
| 142 | dramsize2 = test1; |
| 143 | } else { |
| 144 | dramsize2 = test2; |
| 145 | } |
| 146 | |
| 147 | /* memory smaller than 1MB is impossible */ |
| 148 | if (dramsize2 < (1 << 20)) { |
| 149 | dramsize2 = 0; |
| 150 | } |
| 151 | |
| 152 | /* set SDRAM CS1 size according to the amount of RAM found */ |
| 153 | if (dramsize2 > 0) { |
| 154 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize |
| 155 | | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1); |
| 156 | } else { |
| 157 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */ |
| 158 | } |
| 159 | |
| 160 | #else /* CFG_RAMBOOT */ |
| 161 | |
| 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; |
| 166 | } else { |
| 167 | dramsize = 0; |
| 168 | } |
| 169 | |
| 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; |
| 174 | } else { |
| 175 | dramsize2 = 0; |
| 176 | } |
| 177 | |
| 178 | #endif /* CFG_RAMBOOT */ |
| 179 | |
| 180 | return dramsize + dramsize2; |
| 181 | } |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 182 | |
| 183 | #elif defined(CONFIG_MGT5100) |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 184 | |
| 185 | long int initdram (int board_type) |
| 186 | { |
| 187 | ulong dramsize = 0; |
| 188 | #ifndef CFG_RAMBOOT |
| 189 | ulong test1, test2; |
| 190 | |
| 191 | /* setup and enable SDRAM chip selects */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 192 | *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000; |
| 193 | *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */ |
| 194 | *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 195 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 196 | |
| 197 | /* setup config registers */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 198 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1; |
| 199 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2; |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 200 | |
| 201 | /* address select register */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 202 | *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL; |
| 203 | __asm__ volatile ("sync"); |
| 204 | |
| 205 | /* find RAM size */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 206 | sdram_start(0); |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 207 | test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 208 | sdram_start(1); |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 209 | test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 210 | if (test1 > test2) { |
| 211 | sdram_start(0); |
| 212 | dramsize = test1; |
| 213 | } else { |
| 214 | dramsize = test2; |
| 215 | } |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 216 | |
| 217 | /* set SDRAM end address according to size */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 218 | *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 219 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 220 | #else /* CFG_RAMBOOT */ |
| 221 | |
| 222 | /* Retrieve amount of SDRAM available */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 223 | dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15); |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 224 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 225 | #endif /* CFG_RAMBOOT */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 226 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 227 | return dramsize; |
| 228 | } |
| 229 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 230 | #else |
| 231 | #error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined |
| 232 | #endif |
| 233 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 234 | int checkboard (void) |
| 235 | { |
| 236 | #if defined(CONFIG_MPC5200) |
| 237 | puts ("Board: MicroSys PM520 \n"); |
| 238 | #elif defined(CONFIG_MGT5100) |
| 239 | puts ("Board: MicroSys PM510 \n"); |
| 240 | #endif |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | void flash_preinit(void) |
| 245 | { |
| 246 | /* |
| 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. |
| 251 | */ |
| 252 | #if defined(CONFIG_MGT5100) |
| 253 | *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */ |
| 254 | *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */ |
| 255 | #endif |
| 256 | *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */ |
| 257 | } |
| 258 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 259 | void flash_afterinit(ulong start, ulong size) |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 260 | { |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 261 | #if defined(CONFIG_BOOT_ROM) |
| 262 | /* adjust mapping */ |
| 263 | *(vu_long *)MPC5XXX_CS1_START = |
| 264 | START_REG(start); |
| 265 | *(vu_long *)MPC5XXX_CS1_STOP = |
| 266 | STOP_REG(start, size); |
| 267 | #else |
| 268 | /* adjust mapping */ |
| 269 | *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START = |
| 270 | START_REG(start); |
| 271 | *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP = |
| 272 | STOP_REG(start, size); |
| 273 | #endif |
| 274 | } |
| 275 | |
| 276 | |
| 277 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
| 278 | |
| 279 | int misc_init_r (void) |
| 280 | { |
| 281 | DECLARE_GLOBAL_DATA_PTR; |
| 282 | /* adjust flash start */ |
| 283 | gd->bd->bi_flashstart = flash_info[0].start[0]; |
| 284 | return (0); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | #ifdef CONFIG_PCI |
| 288 | static struct pci_controller hose; |
| 289 | |
| 290 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 291 | |
| 292 | void pci_init_board(void) |
| 293 | { |
| 294 | pci_mpc5xxx_init(&hose); |
| 295 | } |
| 296 | #endif |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 297 | |
| 298 | #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) |
| 299 | |
| 300 | void init_ide_reset (void) |
| 301 | { |
| 302 | debug ("init_ide_reset\n"); |
| 303 | |
| 304 | } |
| 305 | |
| 306 | void ide_set_reset (int idereset) |
| 307 | { |
| 308 | debug ("ide_reset(%d)\n", idereset); |
| 309 | |
| 310 | } |
| 311 | #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */ |
| 312 | |
| 313 | #if (CONFIG_COMMANDS & CFG_CMD_DOC) |
| 314 | extern void doc_probe (ulong physadr); |
| 315 | void doc_init (void) |
| 316 | { |
| 317 | doc_probe (CFG_DOC_BASE); |
| 318 | } |
| 319 | #endif |