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> |
Ben Warren | f2c1acb | 2008-08-31 10:03:22 -0700 | [diff] [blame] | 30 | #include <netdev.h> |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 31 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 32 | #if defined(CONFIG_MPC5200_DDR) |
| 33 | #include "mt46v16m16-75.h" |
| 34 | #else |
| 35 | #include "mt48lc16m16a2-75.h" |
| 36 | #endif |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 37 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 40 | #ifndef CONFIG_SYS_RAMBOOT |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 41 | static void sdram_start (int hi_addr) |
| 42 | { |
| 43 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 44 | |
| 45 | /* unlock mode register */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 46 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit; |
| 47 | __asm__ volatile ("sync"); |
| 48 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 49 | /* precharge all banks */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 50 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
| 51 | __asm__ volatile ("sync"); |
| 52 | |
| 53 | #if SDRAM_DDR |
| 54 | /* set mode register: extended mode */ |
| 55 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE; |
| 56 | __asm__ volatile ("sync"); |
| 57 | |
| 58 | /* set mode register: reset DLL */ |
| 59 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000; |
| 60 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 61 | #endif |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 62 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 63 | /* precharge all banks */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 64 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
| 65 | __asm__ volatile ("sync"); |
| 66 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 67 | /* auto refresh */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 68 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit; |
| 69 | __asm__ volatile ("sync"); |
| 70 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 71 | /* set mode register */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 72 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE; |
| 73 | __asm__ volatile ("sync"); |
| 74 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 75 | /* normal operation */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 76 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit; |
| 77 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 78 | } |
| 79 | #endif |
| 80 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 81 | /* |
| 82 | * ATTENTION: Although partially referenced initdram does NOT make real use |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 84 | * is something else than 0x00000000. |
| 85 | */ |
| 86 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 87 | phys_size_t initdram (int board_type) |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 88 | { |
| 89 | ulong dramsize = 0; |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 90 | ulong dramsize2 = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | #ifndef CONFIG_SYS_RAMBOOT |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 92 | ulong test1, test2; |
| 93 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 94 | /* setup SDRAM chip selects */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 95 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */ |
| 96 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 97 | __asm__ volatile ("sync"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 98 | |
| 99 | /* setup config registers */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 100 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1; |
| 101 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2; |
| 102 | __asm__ volatile ("sync"); |
| 103 | |
| 104 | #if SDRAM_DDR |
| 105 | /* set tap delay */ |
| 106 | *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY; |
| 107 | __asm__ volatile ("sync"); |
| 108 | #endif |
| 109 | |
| 110 | /* find RAM size using SDRAM CS0 only */ |
| 111 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 112 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 113 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 114 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 115 | if (test1 > test2) { |
| 116 | sdram_start(0); |
| 117 | dramsize = test1; |
| 118 | } else { |
| 119 | dramsize = test2; |
| 120 | } |
| 121 | |
| 122 | /* memory smaller than 1MB is impossible */ |
| 123 | if (dramsize < (1 << 20)) { |
| 124 | dramsize = 0; |
| 125 | } |
| 126 | |
| 127 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 128 | if (dramsize > 0) { |
| 129 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1; |
| 130 | } else { |
| 131 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */ |
| 132 | } |
| 133 | |
| 134 | /* let SDRAM CS1 start right after CS0 */ |
| 135 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */ |
| 136 | |
| 137 | /* find RAM size using SDRAM CS1 only */ |
wdenk | e84ec90 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 138 | if (!dramsize) |
wdenk | faaa602 | 2005-04-21 21:10:22 +0000 | [diff] [blame] | 139 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000); |
wdenk | faaa602 | 2005-04-21 21:10:22 +0000 | [diff] [blame] | 141 | if (!dramsize) { |
| 142 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 143 | test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000); |
wdenk | faaa602 | 2005-04-21 21:10:22 +0000 | [diff] [blame] | 144 | } |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 145 | if (test1 > test2) { |
| 146 | sdram_start(0); |
| 147 | dramsize2 = test1; |
| 148 | } else { |
| 149 | dramsize2 = test2; |
| 150 | } |
| 151 | |
| 152 | /* memory smaller than 1MB is impossible */ |
| 153 | if (dramsize2 < (1 << 20)) { |
| 154 | dramsize2 = 0; |
| 155 | } |
| 156 | |
| 157 | /* set SDRAM CS1 size according to the amount of RAM found */ |
| 158 | if (dramsize2 > 0) { |
| 159 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize |
| 160 | | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1); |
| 161 | } else { |
| 162 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */ |
| 163 | } |
| 164 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 165 | #else /* CONFIG_SYS_RAMBOOT */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 166 | |
| 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; |
| 171 | } else { |
| 172 | dramsize = 0; |
| 173 | } |
| 174 | |
| 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; |
| 179 | } else { |
| 180 | dramsize2 = 0; |
| 181 | } |
| 182 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 183 | #endif /* CONFIG_SYS_RAMBOOT */ |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 184 | |
| 185 | return dramsize + dramsize2; |
| 186 | } |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 187 | |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 188 | int checkboard (void) |
| 189 | { |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 190 | puts ("Board: MicroSys PM520 \n"); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | void flash_preinit(void) |
| 195 | { |
| 196 | /* |
| 197 | * Now, when we are in RAM, enable flash write |
| 198 | * access for detection process. |
| 199 | * Note that CS_BOOT cannot be cleared when |
| 200 | * executing in flash. |
| 201 | */ |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 202 | *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */ |
| 203 | } |
| 204 | |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 205 | void flash_afterinit(ulong start, ulong size) |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 206 | { |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 207 | #if defined(CONFIG_BOOT_ROM) |
| 208 | /* adjust mapping */ |
| 209 | *(vu_long *)MPC5XXX_CS1_START = |
| 210 | START_REG(start); |
| 211 | *(vu_long *)MPC5XXX_CS1_STOP = |
| 212 | STOP_REG(start, size); |
| 213 | #else |
| 214 | /* adjust mapping */ |
| 215 | *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START = |
| 216 | START_REG(start); |
| 217 | *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP = |
| 218 | STOP_REG(start, size); |
| 219 | #endif |
| 220 | } |
| 221 | |
| 222 | |
| 223 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
| 224 | |
| 225 | int misc_init_r (void) |
| 226 | { |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 227 | /* adjust flash start */ |
| 228 | gd->bd->bi_flashstart = flash_info[0].start[0]; |
| 229 | return (0); |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | #ifdef CONFIG_PCI |
| 233 | static struct pci_controller hose; |
| 234 | |
| 235 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 236 | |
| 237 | void pci_init_board(void) |
| 238 | { |
| 239 | pci_mpc5xxx_init(&hose); |
| 240 | } |
| 241 | #endif |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 242 | |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 243 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 244 | |
| 245 | void init_ide_reset (void) |
| 246 | { |
| 247 | debug ("init_ide_reset\n"); |
| 248 | |
| 249 | } |
| 250 | |
| 251 | void ide_set_reset (int idereset) |
| 252 | { |
| 253 | debug ("ide_reset(%d)\n", idereset); |
| 254 | |
| 255 | } |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 256 | #endif |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 257 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 258 | #if defined(CONFIG_CMD_DOC) |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 259 | void doc_init (void) |
| 260 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 261 | doc_probe (CONFIG_SYS_DOC_BASE); |
wdenk | 9e930b6 | 2004-06-19 21:19:10 +0000 | [diff] [blame] | 262 | } |
| 263 | #endif |
Ben Warren | f2c1acb | 2008-08-31 10:03:22 -0700 | [diff] [blame] | 264 | |
| 265 | int board_eth_init(bd_t *bis) |
| 266 | { |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 267 | cpu_eth_init(bis); /* Built in FEC comes first */ |
Ben Warren | f2c1acb | 2008-08-31 10:03:22 -0700 | [diff] [blame] | 268 | return pci_eth_init(bis); |
| 269 | } |