wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <commproc.h> |
| 10 | #include <mpc8xx.h> |
| 11 | |
| 12 | /* ------------------------------------------------------------------------- */ |
| 13 | |
| 14 | static long int dram_size (long int, long int *, long int); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 15 | unsigned long ip860_get_dram_size(void); |
| 16 | unsigned long ip860_get_clk_freq (void); |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 17 | /* ------------------------------------------------------------------------- */ |
| 18 | |
| 19 | #define _NOT_USED_ 0xFFFFFFFF |
| 20 | |
| 21 | const uint sdram_table[] = { |
| 22 | /* |
| 23 | * Single Read. (Offset 0 in UPMA RAM) |
| 24 | */ |
| 25 | 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00, |
| 26 | 0x1ff77c47, /* last */ |
| 27 | /* |
| 28 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 29 | * |
| 30 | * This is no UPM entry point. The following definition uses |
| 31 | * the remaining space to establish an initialization |
| 32 | * sequence, which is executed by a RUN command. |
| 33 | * |
| 34 | */ |
| 35 | 0x1ff77c34, 0xefeabc34, 0x1fb57c35, /* last */ |
| 36 | /* |
| 37 | * Burst Read. (Offset 8 in UPMA RAM) |
| 38 | */ |
| 39 | 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00, |
| 40 | 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, /* last */ |
| 41 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 42 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 43 | /* |
| 44 | * Single Write. (Offset 18 in UPMA RAM) |
| 45 | */ |
| 46 | 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, /* last */ |
| 47 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 48 | /* |
| 49 | * Burst Write. (Offset 20 in UPMA RAM) |
| 50 | */ |
| 51 | 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00, |
| 52 | 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, /* last */ |
| 53 | _NOT_USED_, |
| 54 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 55 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 56 | /* |
| 57 | * Refresh (Offset 30 in UPMA RAM) |
| 58 | */ |
| 59 | 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 60 | 0xfffffc84, 0xfffffc07, /* last */ |
| 61 | _NOT_USED_, _NOT_USED_, |
| 62 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 63 | /* |
| 64 | * Exception. (Offset 3c in UPMA RAM) |
| 65 | */ |
| 66 | 0x7ffffc07, /* last */ |
| 67 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 68 | }; |
| 69 | |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 70 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 71 | /* ------------------------------------------------------------------------- */ |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 72 | int board_early_init_f(void) |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 73 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 74 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 75 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 76 | |
| 77 | /* init BCSR chipselect line for ip860_get_clk_freq() and ip860_get_dram_size() */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | memctl->memc_or4 = CONFIG_SYS_OR4; |
| 79 | memctl->memc_br4 = CONFIG_SYS_BR4; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /* ------------------------------------------------------------------------- */ |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * Check Board Identity: |
| 89 | * |
| 90 | * Test ID string (IP860...) |
| 91 | */ |
| 92 | |
| 93 | int checkboard (void) |
| 94 | { |
| 95 | unsigned char *s, *e; |
| 96 | unsigned char buf[64]; |
| 97 | int i; |
| 98 | |
| 99 | puts ("Board: "); |
| 100 | |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 101 | i = getenv_f("serial#", (char *)buf, sizeof (buf)); |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 102 | s = (i > 0) ? buf : NULL; |
| 103 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 104 | if (!s || strncmp ((char *)s, "IP860", 5)) { |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 105 | puts ("### No HW ID - assuming IP860"); |
| 106 | } else { |
| 107 | for (e = s; *e; ++e) { |
| 108 | if (*e == ' ') |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | for (; s < e; ++s) { |
| 113 | putc (*s); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | putc ('\n'); |
| 118 | |
| 119 | return (0); |
| 120 | } |
| 121 | |
| 122 | /* ------------------------------------------------------------------------- */ |
| 123 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 124 | phys_size_t initdram (int board_type) |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 125 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 126 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 127 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 128 | long int size; |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 129 | ulong refresh_val; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 130 | |
| 131 | upmconfig (UPMA, (uint *) sdram_table, |
| 132 | sizeof (sdram_table) / sizeof (uint)); |
| 133 | |
| 134 | /* |
| 135 | * Preliminary prescaler for refresh |
| 136 | */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 137 | if (ip860_get_clk_freq() == 50000000) |
| 138 | { |
| 139 | memctl->memc_mptpr = 0x0400; |
| 140 | refresh_val = 0xC3000000; |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | memctl->memc_mptpr = 0x0200; |
| 145 | refresh_val = 0x9C000000; |
| 146 | } |
| 147 | |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 148 | |
| 149 | memctl->memc_mar = 0x00000088; |
| 150 | |
| 151 | /* |
| 152 | * Map controller banks 2 to the SDRAM address |
| 153 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | memctl->memc_or2 = CONFIG_SYS_OR2; |
| 155 | memctl->memc_br2 = CONFIG_SYS_BR2; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 156 | |
| 157 | /* IP860 boards have only one bank SDRAM */ |
| 158 | |
| 159 | |
| 160 | udelay (200); |
| 161 | |
| 162 | /* perform SDRAM initializsation sequence */ |
| 163 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 164 | memctl->memc_mamr = 0x00804114 | refresh_val; |
| 165 | memctl->memc_mcr = 0x80004105; /* run precharge pattern from loc 5 */ |
| 166 | udelay(1); |
| 167 | memctl->memc_mamr = 0x00804118 | refresh_val; |
| 168 | memctl->memc_mcr = 0x80004130; /* run refresh pattern 8 times */ |
| 169 | |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 170 | |
| 171 | udelay (1000); |
| 172 | |
| 173 | /* |
| 174 | * Check SDRAM Memory Size |
| 175 | */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 176 | if (ip860_get_dram_size() == 16) |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 177 | size = dram_size (refresh_val | 0x00804114, SDRAM_BASE, SDRAM_MAX_SIZE); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 178 | else |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 179 | size = dram_size (refresh_val | 0x00906114, SDRAM_BASE, SDRAM_MAX_SIZE); |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 180 | |
| 181 | udelay (1000); |
| 182 | |
| 183 | memctl->memc_or2 = ((-size) & 0xFFFF0000) | SDRAM_TIMING; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 184 | memctl->memc_br2 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 185 | |
| 186 | udelay (10000); |
| 187 | |
| 188 | /* |
| 189 | * Also, map other memory to correct position |
| 190 | */ |
| 191 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 192 | #if (defined(CONFIG_SYS_OR1) && defined(CONFIG_SYS_BR1_PRELIM)) |
| 193 | memctl->memc_or1 = CONFIG_SYS_OR1; |
| 194 | memctl->memc_br1 = CONFIG_SYS_BR1; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 197 | #if defined(CONFIG_SYS_OR3) && defined(CONFIG_SYS_BR3) |
| 198 | memctl->memc_or3 = CONFIG_SYS_OR3; |
| 199 | memctl->memc_br3 = CONFIG_SYS_BR3; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 200 | #endif |
| 201 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 202 | #if defined(CONFIG_SYS_OR4) && defined(CONFIG_SYS_BR4) |
| 203 | memctl->memc_or4 = CONFIG_SYS_OR4; |
| 204 | memctl->memc_br4 = CONFIG_SYS_BR4; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 205 | #endif |
| 206 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 207 | #if defined(CONFIG_SYS_OR5) && defined(CONFIG_SYS_BR5) |
| 208 | memctl->memc_or5 = CONFIG_SYS_OR5; |
| 209 | memctl->memc_br5 = CONFIG_SYS_BR5; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 210 | #endif |
| 211 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 212 | #if defined(CONFIG_SYS_OR6) && defined(CONFIG_SYS_BR6) |
| 213 | memctl->memc_or6 = CONFIG_SYS_OR6; |
| 214 | memctl->memc_br6 = CONFIG_SYS_BR6; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 215 | #endif |
| 216 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 217 | #if defined(CONFIG_SYS_OR7) && defined(CONFIG_SYS_BR7) |
| 218 | memctl->memc_or7 = CONFIG_SYS_OR7; |
| 219 | memctl->memc_br7 = CONFIG_SYS_BR7; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 220 | #endif |
| 221 | |
| 222 | return (size); |
| 223 | } |
| 224 | |
| 225 | /* ------------------------------------------------------------------------- */ |
| 226 | |
| 227 | /* |
| 228 | * Check memory range for valid RAM. A simple memory test determines |
| 229 | * the actually available RAM size between addresses `base' and |
| 230 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 231 | * - short between address lines |
| 232 | * - short between data lines |
| 233 | */ |
| 234 | |
| 235 | static long int dram_size (long int mamr_value, long int *base, |
| 236 | long int maxsize) |
| 237 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 238 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 239 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 240 | |
| 241 | memctl->memc_mamr = mamr_value; |
| 242 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 243 | return (get_ram_size(base, maxsize)); |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* ------------------------------------------------------------------------- */ |
| 247 | |
| 248 | void reset_phy (void) |
| 249 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 250 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 16f2170 | 2002-08-26 21:58:50 +0000 | [diff] [blame] | 251 | ulong mask = PB_ENET_RESET | PB_ENET_JABD; |
| 252 | ulong reg; |
| 253 | |
| 254 | /* Make sure PHY is not in low-power mode */ |
| 255 | immr->im_cpm.cp_pbpar &= ~(mask); /* GPIO */ |
| 256 | immr->im_cpm.cp_pbodr &= ~(mask); /* active output */ |
| 257 | |
| 258 | /* Set JABD low (no JABber Disable), |
| 259 | * and RESET high (Reset PHY) |
| 260 | */ |
| 261 | reg = immr->im_cpm.cp_pbdat; |
| 262 | reg = (reg & ~PB_ENET_JABD) | PB_ENET_RESET; |
| 263 | immr->im_cpm.cp_pbdat = reg; |
| 264 | |
| 265 | /* now drive outputs */ |
| 266 | immr->im_cpm.cp_pbdir |= mask; /* output */ |
| 267 | udelay (1000); |
| 268 | /* |
| 269 | * Release RESET signal |
| 270 | */ |
| 271 | immr->im_cpm.cp_pbdat &= ~(PB_ENET_RESET); |
| 272 | udelay (1000); |
| 273 | } |
| 274 | |
| 275 | /* ------------------------------------------------------------------------- */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 276 | |
| 277 | unsigned long ip860_get_clk_freq(void) |
| 278 | { |
| 279 | volatile ip860_bcsr_t *bcsr = (ip860_bcsr_t *)BCSR_BASE; |
| 280 | ulong temp; |
| 281 | uchar sysclk; |
| 282 | |
| 283 | if ((bcsr->bd_status & 0x80) == 0x80) /* bd_rev valid ? */ |
| 284 | sysclk = (bcsr->bd_rev & 0x18) >> 3; |
| 285 | else |
| 286 | sysclk = 0x00; |
| 287 | |
| 288 | switch (sysclk) |
| 289 | { |
| 290 | case 0x00: |
| 291 | temp = 50000000; |
| 292 | break; |
| 293 | |
| 294 | case 0x01: |
| 295 | temp = 80000000; |
| 296 | break; |
| 297 | |
| 298 | default: |
| 299 | temp = 50000000; |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | return (temp); |
| 304 | |
| 305 | } |
| 306 | |
| 307 | |
| 308 | /* ------------------------------------------------------------------------- */ |
| 309 | |
| 310 | unsigned long ip860_get_dram_size(void) |
| 311 | { |
| 312 | volatile ip860_bcsr_t *bcsr = (ip860_bcsr_t *)BCSR_BASE; |
| 313 | ulong temp; |
| 314 | uchar dram_size; |
| 315 | |
| 316 | if ((bcsr->bd_status & 0x80) == 0x80) /* bd_rev valid ? */ |
| 317 | dram_size = (bcsr->bd_rev & 0xE0) >> 5; |
| 318 | else |
| 319 | dram_size = 0x00; /* default is 16 MB */ |
| 320 | |
| 321 | switch (dram_size) |
| 322 | { |
| 323 | case 0x00: |
| 324 | temp = 16; |
| 325 | break; |
| 326 | |
| 327 | case 0x01: |
| 328 | temp = 32; |
| 329 | break; |
| 330 | |
| 331 | default: |
| 332 | temp = 16; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | return (temp); |
| 337 | |
| 338 | } |
| 339 | |
| 340 | /* ------------------------------------------------------------------------- */ |