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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <commproc.h> |
| 26 | #include <mpc8xx.h> |
| 27 | |
| 28 | /* ------------------------------------------------------------------------- */ |
| 29 | |
| 30 | static long int dram_size (long int, long int *, long int); |
| 31 | |
| 32 | /* ------------------------------------------------------------------------- */ |
| 33 | |
| 34 | #define _NOT_USED_ 0xFFFFFFFF |
| 35 | |
| 36 | const uint sdram_table[] = { |
| 37 | /* |
| 38 | * Single Read. (Offset 0 in UPMA RAM) |
| 39 | */ |
| 40 | 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00, |
| 41 | 0x1ff77c47, /* last */ |
| 42 | /* |
| 43 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 44 | * |
| 45 | * This is no UPM entry point. The following definition uses |
| 46 | * the remaining space to establish an initialization |
| 47 | * sequence, which is executed by a RUN command. |
| 48 | * |
| 49 | */ |
| 50 | 0x1ff77c34, 0xefeabc34, 0x1fb57c35, /* last */ |
| 51 | /* |
| 52 | * Burst Read. (Offset 8 in UPMA RAM) |
| 53 | */ |
| 54 | 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00, |
| 55 | 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, /* last */ |
| 56 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 57 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 58 | /* |
| 59 | * Single Write. (Offset 18 in UPMA RAM) |
| 60 | */ |
| 61 | 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, /* last */ |
| 62 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 63 | /* |
| 64 | * Burst Write. (Offset 20 in UPMA RAM) |
| 65 | */ |
| 66 | 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00, |
| 67 | 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, /* last */ |
| 68 | _NOT_USED_, |
| 69 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 70 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 71 | /* |
| 72 | * Refresh (Offset 30 in UPMA RAM) |
| 73 | */ |
| 74 | 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 75 | 0xfffffc84, 0xfffffc07, /* last */ |
| 76 | _NOT_USED_, _NOT_USED_, |
| 77 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 78 | /* |
| 79 | * Exception. (Offset 3c in UPMA RAM) |
| 80 | */ |
| 81 | 0x7ffffc07, /* last */ |
| 82 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 83 | }; |
| 84 | |
| 85 | /* ------------------------------------------------------------------------- */ |
| 86 | |
| 87 | |
| 88 | /* |
| 89 | * Check Board Identity: |
| 90 | * |
| 91 | * Test ID string (IP860...) |
| 92 | */ |
| 93 | |
| 94 | int checkboard (void) |
| 95 | { |
| 96 | unsigned char *s, *e; |
| 97 | unsigned char buf[64]; |
| 98 | int i; |
| 99 | |
| 100 | puts ("Board: "); |
| 101 | |
| 102 | i = getenv_r ("serial#", buf, sizeof (buf)); |
| 103 | s = (i > 0) ? buf : NULL; |
| 104 | |
| 105 | if (!s || strncmp (s, "IP860", 5)) { |
| 106 | puts ("### No HW ID - assuming IP860"); |
| 107 | } else { |
| 108 | for (e = s; *e; ++e) { |
| 109 | if (*e == ' ') |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | for (; s < e; ++s) { |
| 114 | putc (*s); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | putc ('\n'); |
| 119 | |
| 120 | return (0); |
| 121 | } |
| 122 | |
| 123 | /* ------------------------------------------------------------------------- */ |
| 124 | |
| 125 | long int initdram (int board_type) |
| 126 | { |
| 127 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 128 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 129 | long int size; |
| 130 | |
| 131 | upmconfig (UPMA, (uint *) sdram_table, |
| 132 | sizeof (sdram_table) / sizeof (uint)); |
| 133 | |
| 134 | /* |
| 135 | * Preliminary prescaler for refresh |
| 136 | */ |
| 137 | memctl->memc_mptpr = 0x0400; |
| 138 | |
| 139 | memctl->memc_mar = 0x00000088; |
| 140 | |
| 141 | /* |
| 142 | * Map controller banks 2 to the SDRAM address |
| 143 | */ |
| 144 | memctl->memc_or2 = CFG_OR2; |
| 145 | memctl->memc_br2 = CFG_BR2; |
| 146 | |
| 147 | /* IP860 boards have only one bank SDRAM */ |
| 148 | |
| 149 | |
| 150 | udelay (200); |
| 151 | |
| 152 | /* perform SDRAM initializsation sequence */ |
| 153 | |
| 154 | memctl->memc_mamr = 0xC3804114; |
| 155 | memctl->memc_mcr = 0x80004105; /* run precharge pattern from loc 5 */ |
| 156 | udelay (1); |
| 157 | memctl->memc_mamr = 0xC3804118; |
| 158 | memctl->memc_mcr = 0x80004130; /* run refresh pattern 8 times */ |
| 159 | |
| 160 | udelay (1000); |
| 161 | |
| 162 | /* |
| 163 | * Check SDRAM Memory Size |
| 164 | */ |
| 165 | size = dram_size (CFG_MAMR, (ulong *) SDRAM_BASE, SDRAM_MAX_SIZE); |
| 166 | |
| 167 | udelay (1000); |
| 168 | |
| 169 | memctl->memc_or2 = ((-size) & 0xFFFF0000) | SDRAM_TIMING; |
| 170 | memctl->memc_br2 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
| 171 | |
| 172 | udelay (10000); |
| 173 | |
| 174 | /* |
| 175 | * Also, map other memory to correct position |
| 176 | */ |
| 177 | |
| 178 | #if (defined(CFG_OR1) && defined(CFG_BR1_PRELIM)) |
| 179 | memctl->memc_or1 = CFG_OR1; |
| 180 | memctl->memc_br1 = CFG_BR1; |
| 181 | #endif |
| 182 | |
| 183 | #if defined(CFG_OR3) && defined(CFG_BR3) |
| 184 | memctl->memc_or3 = CFG_OR3; |
| 185 | memctl->memc_br3 = CFG_BR3; |
| 186 | #endif |
| 187 | |
| 188 | #if defined(CFG_OR4) && defined(CFG_BR4) |
| 189 | memctl->memc_or4 = CFG_OR4; |
| 190 | memctl->memc_br4 = CFG_BR4; |
| 191 | #endif |
| 192 | |
| 193 | #if defined(CFG_OR5) && defined(CFG_BR5) |
| 194 | memctl->memc_or5 = CFG_OR5; |
| 195 | memctl->memc_br5 = CFG_BR5; |
| 196 | #endif |
| 197 | |
| 198 | #if defined(CFG_OR6) && defined(CFG_BR6) |
| 199 | memctl->memc_or6 = CFG_OR6; |
| 200 | memctl->memc_br6 = CFG_BR6; |
| 201 | #endif |
| 202 | |
| 203 | #if defined(CFG_OR7) && defined(CFG_BR7) |
| 204 | memctl->memc_or7 = CFG_OR7; |
| 205 | memctl->memc_br7 = CFG_BR7; |
| 206 | #endif |
| 207 | |
| 208 | return (size); |
| 209 | } |
| 210 | |
| 211 | /* ------------------------------------------------------------------------- */ |
| 212 | |
| 213 | /* |
| 214 | * Check memory range for valid RAM. A simple memory test determines |
| 215 | * the actually available RAM size between addresses `base' and |
| 216 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 217 | * - short between address lines |
| 218 | * - short between data lines |
| 219 | */ |
| 220 | |
| 221 | static long int dram_size (long int mamr_value, long int *base, |
| 222 | long int maxsize) |
| 223 | { |
| 224 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 225 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 226 | volatile long int *addr; |
| 227 | ulong cnt, val; |
| 228 | ulong save[32]; /* to make test non-destructive */ |
| 229 | unsigned char i = 0; |
| 230 | |
| 231 | memctl->memc_mamr = mamr_value; |
| 232 | |
| 233 | for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) { |
| 234 | addr = base + cnt; /* pointer arith! */ |
| 235 | |
| 236 | save[i++] = *addr; |
| 237 | *addr = ~cnt; |
| 238 | } |
| 239 | |
| 240 | /* write 0 to base address */ |
| 241 | addr = base; |
| 242 | save[i] = *addr; |
| 243 | *addr = 0; |
| 244 | |
| 245 | /* check at base address */ |
| 246 | if ((val = *addr) != 0) { |
| 247 | *addr = save[i]; |
| 248 | return (0); |
| 249 | } |
| 250 | |
| 251 | for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) { |
| 252 | addr = base + cnt; /* pointer arith! */ |
| 253 | |
| 254 | val = *addr; |
| 255 | *addr = save[--i]; |
| 256 | |
| 257 | if (val != (~cnt)) { |
| 258 | return (cnt * sizeof (long)); |
| 259 | } |
| 260 | } |
| 261 | return (maxsize); |
| 262 | } |
| 263 | |
| 264 | /* ------------------------------------------------------------------------- */ |
| 265 | |
| 266 | void reset_phy (void) |
| 267 | { |
| 268 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 269 | ulong mask = PB_ENET_RESET | PB_ENET_JABD; |
| 270 | ulong reg; |
| 271 | |
| 272 | /* Make sure PHY is not in low-power mode */ |
| 273 | immr->im_cpm.cp_pbpar &= ~(mask); /* GPIO */ |
| 274 | immr->im_cpm.cp_pbodr &= ~(mask); /* active output */ |
| 275 | |
| 276 | /* Set JABD low (no JABber Disable), |
| 277 | * and RESET high (Reset PHY) |
| 278 | */ |
| 279 | reg = immr->im_cpm.cp_pbdat; |
| 280 | reg = (reg & ~PB_ENET_JABD) | PB_ENET_RESET; |
| 281 | immr->im_cpm.cp_pbdat = reg; |
| 282 | |
| 283 | /* now drive outputs */ |
| 284 | immr->im_cpm.cp_pbdir |= mask; /* output */ |
| 285 | udelay (1000); |
| 286 | /* |
| 287 | * Release RESET signal |
| 288 | */ |
| 289 | immr->im_cpm.cp_pbdat &= ~(PB_ENET_RESET); |
| 290 | udelay (1000); |
| 291 | } |
| 292 | |
| 293 | /* ------------------------------------------------------------------------- */ |