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