Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [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> |
Heiko Schocher | 50219e6 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 29 | #include <net.h> |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 30 | #include <asm/processor.h> |
| 31 | |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 32 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | #ifndef CONFIG_SYS_RAMBOOT |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 34 | static void sdram_start(int hi_addr) |
| 35 | { |
| 36 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 37 | |
| 38 | /* unlock mode register */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 39 | *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 40 | __asm__ volatile ("sync"); |
| 41 | |
| 42 | /* precharge all banks */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 43 | *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 44 | __asm__ volatile ("sync"); |
| 45 | |
| 46 | #if SDRAM_DDR |
| 47 | /* set mode register: extended mode */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 48 | *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 49 | __asm__ volatile ("sync"); |
| 50 | |
| 51 | /* set mode register: reset DLL */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 52 | *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 53 | __asm__ volatile ("sync"); |
| 54 | #endif /* SDRAM_DDR */ |
| 55 | |
| 56 | /* precharge all banks */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 57 | *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 58 | __asm__ volatile ("sync"); |
| 59 | |
| 60 | /* auto refresh */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 61 | *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 62 | __asm__ volatile ("sync"); |
| 63 | |
| 64 | /* set mode register */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 65 | *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 66 | __asm__ volatile ("sync"); |
| 67 | |
| 68 | /* normal operation */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 69 | *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 70 | __asm__ volatile ("sync"); |
| 71 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | #endif /* !CONFIG_SYS_RAMBOOT */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 73 | |
| 74 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 75 | phys_size_t initdram(int board_type) |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 76 | { |
| 77 | ulong dramsize = 0; |
| 78 | ulong dramsize2 = 0; |
| 79 | uint svr, pvr; |
| 80 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | #ifndef CONFIG_SYS_RAMBOOT |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 82 | ulong test1, test2; |
| 83 | |
| 84 | /* setup SDRAM chip selects */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 85 | *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */ |
| 86 | *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 87 | __asm__ volatile ("sync"); |
| 88 | |
| 89 | /* setup config registers */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 90 | *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1; |
| 91 | *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 92 | __asm__ volatile ("sync"); |
| 93 | |
| 94 | #if SDRAM_DDR |
| 95 | /* set tap delay */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 96 | *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 97 | __asm__ volatile ("sync"); |
| 98 | #endif /* SDRAM_DDR */ |
| 99 | |
| 100 | /* find RAM size using SDRAM CS0 only */ |
| 101 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 103 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 105 | if (test1 > test2) { |
| 106 | sdram_start(0); |
| 107 | dramsize = test1; |
| 108 | } else |
| 109 | dramsize = test2; |
| 110 | |
| 111 | /* memory smaller than 1MB is impossible */ |
| 112 | if (dramsize < (1 << 20)) |
| 113 | dramsize = 0; |
| 114 | |
| 115 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 116 | if (dramsize > 0) |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 117 | *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 118 | else |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 119 | *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 120 | |
| 121 | /* let SDRAM CS1 start right after CS0 */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 122 | *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 123 | |
| 124 | /* find RAM size using SDRAM CS1 only */ |
| 125 | if (!dramsize) |
| 126 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 127 | test2 = test1 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000); |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 128 | if (!dramsize) { |
| 129 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 130 | test2 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000); |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 131 | } |
| 132 | if (test1 > test2) { |
| 133 | sdram_start(0); |
| 134 | dramsize2 = test1; |
| 135 | } else |
| 136 | dramsize2 = test2; |
| 137 | |
| 138 | /* memory smaller than 1MB is impossible */ |
| 139 | if (dramsize2 < (1 << 20)) |
| 140 | dramsize2 = 0; |
| 141 | |
| 142 | /* set SDRAM CS1 size according to the amount of RAM found */ |
| 143 | if (dramsize2 > 0) |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 144 | *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 145 | | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1); |
| 146 | else |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 147 | *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 148 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 149 | #else /* CONFIG_SYS_RAMBOOT */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 150 | |
| 151 | /* retrieve size of memory connected to SDRAM CS0 */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 152 | dramsize = *(vu_long *) MPC5XXX_SDRAM_CS0CFG & 0xFF; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 153 | if (dramsize >= 0x13) |
| 154 | dramsize = (1 << (dramsize - 0x13)) << 20; |
| 155 | else |
| 156 | dramsize = 0; |
| 157 | |
| 158 | /* retrieve size of memory connected to SDRAM CS1 */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 159 | dramsize2 = *(vu_long *) MPC5XXX_SDRAM_CS1CFG & 0xFF; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 160 | if (dramsize2 >= 0x13) |
| 161 | dramsize2 = (1 << (dramsize2 - 0x13)) << 20; |
| 162 | else |
| 163 | dramsize2 = 0; |
| 164 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 165 | #endif /* CONFIG_SYS_RAMBOOT */ |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * On MPC5200B we need to set the special configuration delay in the |
| 169 | * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM |
| 170 | * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190: |
| 171 | * |
| 172 | * "The SDelay should be written to a value of 0x00000004. It is |
| 173 | * required to account for changes caused by normal wafer processing |
| 174 | * parameters." |
| 175 | */ |
| 176 | svr = get_svr(); |
| 177 | pvr = get_pvr(); |
| 178 | if ((SVR_MJREV(svr) >= 2) && |
| 179 | (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) { |
| 180 | |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 181 | *(vu_long *) MPC5XXX_SDRAM_SDELAY = 0x04; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 182 | __asm__ volatile ("sync"); |
| 183 | } |
| 184 | |
| 185 | return dramsize + dramsize2; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | int checkboard (void) |
| 190 | { |
| 191 | puts("Board: MarelV38B\n"); |
| 192 | return 0; |
| 193 | } |
| 194 | |
Bartlomiej Sieka | 37e6664 | 2006-12-28 19:08:21 +0100 | [diff] [blame] | 195 | int board_early_init_f(void) |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 196 | { |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 197 | #ifdef CONFIG_HW_WATCHDOG |
| 198 | /* |
| 199 | * Enable and configure the direction (output) of PSC3_9 - watchdog |
| 200 | * reset input. Refer to 7.3.2.2.[1,3,4] of the MPC5200B User's |
| 201 | * Manual. |
| 202 | */ |
| 203 | *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9; |
| 204 | *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9; |
| 205 | #endif /* CONFIG_HW_WATCHDOG */ |
Bartlomiej Sieka | 37e6664 | 2006-12-28 19:08:21 +0100 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | int board_early_init_r(void) |
| 210 | { |
| 211 | /* |
| 212 | * Now, when we are in RAM, enable flash write access for the |
| 213 | * detection process. Note that CS_BOOT cannot be cleared when |
| 214 | * executing in flash. |
| 215 | */ |
| 216 | *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * Enable GPIO_WKUP_7 to "read the status of the actual power |
| 220 | * situation". Default direction is input, so no need to set it |
| 221 | * explicitly. |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 222 | */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 223 | *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WKUP_7; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Mike Frysinger | 13e9bb9 | 2009-02-16 18:03:14 -0500 | [diff] [blame] | 227 | extern void board_get_enetaddr(uchar *enetaddr); |
| 228 | int misc_init_r(void) |
| 229 | { |
| 230 | uchar enetaddr[6]; |
| 231 | |
| 232 | if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { |
| 233 | board_get_enetaddr(enetaddr); |
Heiko Schocher | 50219e6 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 234 | eth_setenv_enetaddr("ethaddr", enetaddr); |
Mike Frysinger | 13e9bb9 | 2009-02-16 18:03:14 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | return 0; |
| 238 | } |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 239 | |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 240 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 241 | void init_ide_reset(void) |
| 242 | { |
| 243 | debug("init_ide_reset\n"); |
| 244 | |
| 245 | /* Configure PSC1_4 as GPIO output for ATA reset */ |
| 246 | *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4; |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 247 | *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 248 | /* Deassert reset */ |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 249 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | |
| 253 | void ide_set_reset(int idereset) |
| 254 | { |
| 255 | debug("ide_reset(%d)\n", idereset); |
| 256 | |
| 257 | if (idereset) { |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 258 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 259 | /* Make a delay. MPC5200 spec says 25 usec min */ |
| 260 | udelay(500000); |
| 261 | } else |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 262 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 263 | } |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 264 | #endif |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 265 | |
| 266 | |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 267 | #ifdef CONFIG_HW_WATCHDOG |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 268 | void hw_watchdog_reset(void) |
| 269 | { |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 270 | /* |
| 271 | * MarelV38B has a TPS3705 watchdog. Spec says that to kick the dog |
| 272 | * we need a positive or negative transition on WDI i.e., our PSC3_9. |
| 273 | */ |
| 274 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O ^= GPIO_PSC3_9; |
Bartlomiej Sieka | 2dfa3d2 | 2006-10-13 21:09:09 +0200 | [diff] [blame] | 275 | } |
Bartlomiej Sieka | 252eede | 2006-11-01 02:04:38 +0100 | [diff] [blame] | 276 | #endif /* CONFIG_HW_WATCHDOG */ |