Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003-2006 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2004 |
| 6 | * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com. |
| 7 | * |
| 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 | |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 31 | #include "mt48lc8m32b2-6-7.h" |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 32 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 35 | extern flash_info_t flash_info[]; /* FLASH chips info */ |
| 36 | |
Stefan Roese | 896391f | 2006-03-01 17:00:49 +0100 | [diff] [blame] | 37 | ulong flash_get_size (ulong base, int banknum); |
| 38 | |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 39 | #ifndef CFG_RAMBOOT |
| 40 | static void sdram_start (int hi_addr) |
| 41 | { |
| 42 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 43 | |
| 44 | /* unlock mode register */ |
| 45 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit; |
| 46 | __asm__ volatile ("sync"); |
| 47 | |
| 48 | /* precharge all banks */ |
| 49 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
| 50 | __asm__ volatile ("sync"); |
| 51 | |
| 52 | #if SDRAM_DDR |
| 53 | /* set mode register: extended mode */ |
| 54 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE; |
| 55 | __asm__ volatile ("sync"); |
| 56 | |
| 57 | /* set mode register: reset DLL */ |
| 58 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000; |
| 59 | __asm__ volatile ("sync"); |
| 60 | #endif |
| 61 | |
| 62 | /* precharge all banks */ |
| 63 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
| 64 | __asm__ volatile ("sync"); |
| 65 | |
| 66 | /* auto refresh */ |
| 67 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit; |
| 68 | __asm__ volatile ("sync"); |
| 69 | |
| 70 | /* set mode register */ |
| 71 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE; |
| 72 | __asm__ volatile ("sync"); |
| 73 | |
| 74 | /* normal operation */ |
| 75 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit; |
| 76 | __asm__ volatile ("sync"); |
| 77 | } |
| 78 | #endif |
| 79 | |
| 80 | /* |
| 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. |
| 84 | */ |
| 85 | |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 86 | long int initdram (int board_type) |
| 87 | { |
| 88 | ulong dramsize = 0; |
| 89 | ulong dramsize2 = 0; |
| 90 | #ifndef CFG_RAMBOOT |
| 91 | ulong test1, test2; |
| 92 | |
| 93 | /* setup SDRAM chip selects */ |
| 94 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */ |
| 95 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */ |
| 96 | __asm__ volatile ("sync"); |
| 97 | |
| 98 | /* setup config registers */ |
| 99 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1; |
| 100 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2; |
| 101 | __asm__ volatile ("sync"); |
| 102 | |
| 103 | #if SDRAM_DDR |
| 104 | /* set tap delay */ |
| 105 | *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY; |
| 106 | __asm__ volatile ("sync"); |
| 107 | #endif |
| 108 | |
| 109 | /* find RAM size using SDRAM CS0 only */ |
| 110 | sdram_start(0); |
| 111 | test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000); |
| 112 | sdram_start(1); |
| 113 | test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000); |
| 114 | if (test1 > test2) { |
| 115 | sdram_start(0); |
| 116 | dramsize = test1; |
| 117 | } else { |
| 118 | dramsize = test2; |
| 119 | } |
| 120 | |
| 121 | /* memory smaller than 1MB is impossible */ |
| 122 | if (dramsize < (1 << 20)) { |
| 123 | dramsize = 0; |
| 124 | } |
| 125 | |
| 126 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 127 | if (dramsize > 0) { |
| 128 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1; |
| 129 | } else { |
| 130 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */ |
| 131 | } |
| 132 | |
| 133 | /* let SDRAM CS1 start right after CS0 */ |
| 134 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */ |
| 135 | |
| 136 | /* find RAM size using SDRAM CS1 only */ |
| 137 | if (!dramsize) |
| 138 | sdram_start(0); |
| 139 | test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000); |
| 140 | if (!dramsize) { |
| 141 | sdram_start(1); |
| 142 | test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000); |
| 143 | } |
| 144 | if (test1 > test2) { |
| 145 | sdram_start(0); |
| 146 | dramsize2 = test1; |
| 147 | } else { |
| 148 | dramsize2 = test2; |
| 149 | } |
| 150 | |
| 151 | /* memory smaller than 1MB is impossible */ |
| 152 | if (dramsize2 < (1 << 20)) { |
| 153 | dramsize2 = 0; |
| 154 | } |
| 155 | |
| 156 | /* set SDRAM CS1 size according to the amount of RAM found */ |
| 157 | if (dramsize2 > 0) { |
| 158 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize |
| 159 | | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1); |
| 160 | } else { |
| 161 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */ |
| 162 | } |
| 163 | |
| 164 | #else /* CFG_RAMBOOT */ |
| 165 | |
| 166 | /* retrieve size of memory connected to SDRAM CS0 */ |
| 167 | dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF; |
| 168 | if (dramsize >= 0x13) { |
| 169 | dramsize = (1 << (dramsize - 0x13)) << 20; |
| 170 | } else { |
| 171 | dramsize = 0; |
| 172 | } |
| 173 | |
| 174 | /* retrieve size of memory connected to SDRAM CS1 */ |
| 175 | dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF; |
| 176 | if (dramsize2 >= 0x13) { |
| 177 | dramsize2 = (1 << (dramsize2 - 0x13)) << 20; |
| 178 | } else { |
| 179 | dramsize2 = 0; |
| 180 | } |
| 181 | |
| 182 | #endif /* CFG_RAMBOOT */ |
| 183 | |
| 184 | return dramsize + dramsize2; |
| 185 | } |
| 186 | |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 187 | int checkboard (void) |
| 188 | { |
Wolfgang Denk | ce87cf9 | 2006-02-24 01:42:40 +0100 | [diff] [blame] | 189 | puts ("Board: MCC200\n"); |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 193 | int misc_init_r (void) |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 194 | { |
| 195 | /* |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 196 | * Adjust flash start and offset to detected values |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 197 | */ |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 198 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 199 | gd->bd->bi_flashoffset = 0; |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 200 | |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 201 | /* |
| 202 | * Check if boot FLASH isn't max size |
| 203 | */ |
| 204 | if (gd->bd->bi_flashsize < (0 - CFG_FLASH_BASE)) { |
| 205 | /* adjust mapping */ |
| 206 | *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START = |
| 207 | START_REG(gd->bd->bi_flashstart); |
| 208 | *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP = |
| 209 | STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize); |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 210 | |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 211 | /* |
| 212 | * Re-check to get correct base address |
| 213 | */ |
| 214 | flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1); |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 215 | |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 216 | /* |
| 217 | * Re-do flash protection upon new addresses |
| 218 | */ |
| 219 | flash_protect (FLAG_PROTECT_CLEAR, |
| 220 | gd->bd->bi_flashstart, 0xffffffff, |
| 221 | &flash_info[CFG_MAX_FLASH_BANKS - 1]); |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 222 | |
Stefan Roese | 254a3d0 | 2006-02-28 15:33:28 +0100 | [diff] [blame] | 223 | /* Monitor protection ON by default */ |
| 224 | flash_protect (FLAG_PROTECT_SET, |
| 225 | CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1, |
| 226 | &flash_info[CFG_MAX_FLASH_BANKS - 1]); |
| 227 | |
| 228 | /* Environment protection ON by default */ |
| 229 | flash_protect (FLAG_PROTECT_SET, |
| 230 | CFG_ENV_ADDR, |
| 231 | CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1, |
| 232 | &flash_info[CFG_MAX_FLASH_BANKS - 1]); |
| 233 | |
| 234 | /* Redundant environment protection ON by default */ |
| 235 | flash_protect (FLAG_PROTECT_SET, |
| 236 | CFG_ENV_ADDR_REDUND, |
| 237 | CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1, |
| 238 | &flash_info[CFG_MAX_FLASH_BANKS - 1]); |
| 239 | } |
| 240 | |
Wolfgang Denk | 934d842 | 2006-04-06 15:03:42 +0200 | [diff] [blame] | 241 | if (gd->bd->bi_flashsize > (32 << 20)) { |
| 242 | /* Unprotect the upper bank of the Flash */ |
| 243 | *(volatile int*)MPC5XXX_CS0_CFG |= (1 << 6); |
| 244 | flash_protect (FLAG_PROTECT_CLEAR, |
Wolfgang Denk | a9f0cd6 | 2006-06-09 21:19:21 +0200 | [diff] [blame^] | 245 | flash_info[0].start[0] + flash_info[0].size / 2, |
Wolfgang Denk | 934d842 | 2006-04-06 15:03:42 +0200 | [diff] [blame] | 246 | (flash_info[0].start[0] + flash_info[0].size) / 2 - 1, |
| 247 | &flash_info[0]); |
| 248 | *(volatile int*)MPC5XXX_CS0_CFG &= ~(1 << 6); |
| 249 | } |
| 250 | |
Wolfgang Denk | 07ad17c | 2006-02-22 00:43:16 +0100 | [diff] [blame] | 251 | return (0); |
| 252 | } |
| 253 | |
| 254 | #ifdef CONFIG_PCI |
| 255 | static struct pci_controller hose; |
| 256 | |
| 257 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 258 | |
| 259 | void pci_init_board(void) |
| 260 | { |
| 261 | pci_mpc5xxx_init(&hose); |
| 262 | } |
| 263 | #endif |
| 264 | |
| 265 | #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) |
| 266 | |
| 267 | void init_ide_reset (void) |
| 268 | { |
| 269 | debug ("init_ide_reset\n"); |
| 270 | |
| 271 | } |
| 272 | |
| 273 | void ide_set_reset (int idereset) |
| 274 | { |
| 275 | debug ("ide_reset(%d)\n", idereset); |
| 276 | |
| 277 | } |
| 278 | #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */ |
| 279 | |
| 280 | #if (CONFIG_COMMANDS & CFG_CMD_DOC) |
| 281 | extern void doc_probe (ulong physadr); |
| 282 | void doc_init (void) |
| 283 | { |
| 284 | doc_probe (CFG_DOC_BASE); |
| 285 | } |
| 286 | #endif |