Sergei Poselenov | 9dea381 | 2010-09-09 23:03:31 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 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 | * (C) Copyright 2010 |
| 9 | * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com. |
| 10 | * |
| 11 | * See file CREDITS for list of people who contributed to this |
| 12 | * project. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <mpc5xxx.h> |
| 32 | #include <pci.h> |
| 33 | #include <asm/processor.h> |
| 34 | #include <asm/io.h> |
| 35 | #include <libfdt.h> |
| 36 | #include <netdev.h> |
| 37 | |
| 38 | #include "mt46v32m16.h" |
| 39 | |
| 40 | #ifndef CONFIG_SYS_RAMBOOT |
| 41 | static void sdram_start (int hi_addr) |
| 42 | { |
| 43 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 44 | long control = SDRAM_CONTROL | hi_addr_bit; |
| 45 | |
| 46 | /* unlock mode register */ |
| 47 | out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000); |
| 48 | __asm__ volatile ("sync"); |
| 49 | |
| 50 | /* precharge all banks */ |
| 51 | out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002); |
| 52 | __asm__ volatile ("sync"); |
| 53 | |
| 54 | #if SDRAM_DDR |
| 55 | /* set mode register: extended mode */ |
| 56 | out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_EMODE); |
| 57 | __asm__ volatile ("sync"); |
| 58 | |
| 59 | /* set mode register: reset DLL */ |
| 60 | out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE | 0x04000000); |
| 61 | __asm__ volatile ("sync"); |
| 62 | #endif |
| 63 | |
| 64 | /* precharge all banks */ |
| 65 | out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002); |
| 66 | __asm__ volatile ("sync"); |
| 67 | |
| 68 | /* auto refresh */ |
| 69 | out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004); |
| 70 | __asm__ volatile ("sync"); |
| 71 | |
| 72 | /* set mode register */ |
| 73 | out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE); |
| 74 | __asm__ volatile ("sync"); |
| 75 | |
| 76 | /* normal operation */ |
| 77 | out_be32((void *)MPC5XXX_SDRAM_CTRL, control); |
| 78 | __asm__ volatile ("sync"); |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | /* |
| 83 | * ATTENTION: Although partially referenced initdram does NOT make real use |
| 84 | * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE |
| 85 | * is something else than 0x00000000. |
| 86 | */ |
| 87 | |
| 88 | phys_size_t initdram (int board_type) |
| 89 | { |
| 90 | ulong dramsize = 0; |
| 91 | uint svr, pvr; |
| 92 | |
| 93 | #ifndef CONFIG_SYS_RAMBOOT |
| 94 | ulong test1, test2; |
| 95 | |
| 96 | /* setup SDRAM chip selects */ |
| 97 | out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); /* 2GB at 0x0 */ |
| 98 | out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */ |
| 99 | __asm__ volatile ("sync"); |
| 100 | |
| 101 | /* setup config registers */ |
| 102 | out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1); |
| 103 | out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2); |
| 104 | __asm__ volatile ("sync"); |
| 105 | |
| 106 | #if SDRAM_DDR |
| 107 | /* set tap delay */ |
| 108 | out_be32((void *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY); |
| 109 | __asm__ volatile ("sync"); |
| 110 | #endif |
| 111 | |
| 112 | /* find RAM size using SDRAM CS0 only */ |
| 113 | sdram_start(0); |
| 114 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
| 115 | sdram_start(1); |
| 116 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
| 117 | if (test1 > test2) { |
| 118 | sdram_start(0); |
| 119 | dramsize = test1; |
| 120 | } else { |
| 121 | dramsize = test2; |
| 122 | } |
| 123 | |
| 124 | /* memory smaller than 1MB is impossible */ |
| 125 | if (dramsize < (1 << 20)) { |
| 126 | dramsize = 0; |
| 127 | } |
| 128 | |
| 129 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 130 | if (dramsize > 0) { |
| 131 | out_be32((void *)MPC5XXX_SDRAM_CS0CFG, |
| 132 | 0x13 + __builtin_ffs(dramsize >> 20) - 1); |
| 133 | } else { |
| 134 | out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */ |
| 135 | } |
| 136 | |
| 137 | #else /* CONFIG_SYS_RAMBOOT */ |
| 138 | |
| 139 | /* retrieve size of memory connected to SDRAM CS0 */ |
| 140 | dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF; |
| 141 | if (dramsize >= 0x13) { |
| 142 | dramsize = (1 << (dramsize - 0x13)) << 20; |
| 143 | } else { |
| 144 | dramsize = 0; |
| 145 | } |
| 146 | |
| 147 | #endif /* CONFIG_SYS_RAMBOOT */ |
| 148 | |
| 149 | /* |
| 150 | * On MPC5200B we need to set the special configuration delay in the |
| 151 | * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM |
| 152 | * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190: |
| 153 | * |
| 154 | * "The SDelay should be written to a value of 0x00000004. It is |
| 155 | * required to account for changes caused by normal wafer processing |
| 156 | * parameters." |
| 157 | */ |
| 158 | svr = get_svr(); |
| 159 | pvr = get_pvr(); |
| 160 | if ((SVR_MJREV(svr) >= 2) && |
| 161 | (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) { |
| 162 | |
| 163 | out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04); |
| 164 | __asm__ volatile ("sync"); |
| 165 | } |
| 166 | |
| 167 | return dramsize; |
| 168 | } |
| 169 | |
| 170 | int checkboard (void) |
| 171 | { |
| 172 | puts ("Board: A4M072\n"); |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | #ifdef CONFIG_PCI |
| 177 | static struct pci_controller hose; |
| 178 | |
| 179 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 180 | |
| 181 | void pci_init_board(void) |
| 182 | { |
| 183 | pci_mpc5xxx_init(&hose); |
| 184 | } |
| 185 | #endif |
| 186 | |
| 187 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 188 | void |
| 189 | ft_board_setup(void *blob, bd_t *bd) |
| 190 | { |
| 191 | ft_cpu_setup(blob, bd); |
| 192 | } |
| 193 | #endif |
| 194 | |
| 195 | int board_eth_init(bd_t *bis) |
| 196 | { |
| 197 | int rv, num_if = 0; |
| 198 | |
| 199 | /* Initialize TSECs first */ |
| 200 | if ((rv = cpu_eth_init(bis)) >= 0) |
| 201 | num_if += rv; |
| 202 | else |
| 203 | printf("ERROR: failed to initialize FEC.\n"); |
| 204 | |
| 205 | if ((rv = pci_eth_init(bis)) >= 0) |
| 206 | num_if += rv; |
| 207 | else |
| 208 | printf("ERROR: failed to initialize PCI Ethernet.\n"); |
| 209 | |
| 210 | return num_if; |
| 211 | } |
| 212 | /* |
| 213 | * Miscellaneous late-boot configurations |
| 214 | * |
| 215 | * Initialize EEPROM write-protect GPIO pin. |
| 216 | */ |
| 217 | int misc_init_r(void) |
| 218 | { |
| 219 | #if defined(CONFIG_SYS_EEPROM_WREN) |
| 220 | /* Enable GPIO pin */ |
| 221 | setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, CONFIG_SYS_EEPROM_WP); |
| 222 | /* Set direction, output */ |
| 223 | setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, CONFIG_SYS_EEPROM_WP); |
| 224 | /* De-assert write enable */ |
| 225 | setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP); |
| 226 | #endif |
| 227 | return 0; |
| 228 | } |
| 229 | #if defined(CONFIG_SYS_EEPROM_WREN) |
| 230 | /* Input: <dev_addr> I2C address of EEPROM device to enable. |
| 231 | * <state> -1: deliver current state |
| 232 | * 0: disable write |
| 233 | * 1: enable write |
| 234 | * Returns: -1: wrong device address |
| 235 | * 0: dis-/en- able done |
| 236 | * 0/1: current state if <state> was -1. |
| 237 | */ |
| 238 | int eeprom_write_enable (unsigned dev_addr, int state) |
| 239 | { |
| 240 | if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) { |
| 241 | return -1; |
| 242 | } else { |
| 243 | switch (state) { |
| 244 | case 1: |
| 245 | /* Enable write access */ |
| 246 | clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP); |
| 247 | state = 0; |
| 248 | break; |
| 249 | case 0: |
| 250 | /* Disable write access */ |
| 251 | setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP); |
| 252 | state = 0; |
| 253 | break; |
| 254 | default: |
| 255 | /* Read current status back. */ |
| 256 | state = (0 == (in_be32((void *)MPC5XXX_WU_GPIO_DATA_O) & |
| 257 | CONFIG_SYS_EEPROM_WP)); |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | return state; |
| 262 | } |
| 263 | #endif |