wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net |
| 4 | * |
| 5 | * (C) Copyright 2001-2002 |
| 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 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 <malloc.h> |
| 29 | #include <mpc8xx.h> |
| 30 | |
| 31 | /* ------------------------------------------------------------------------- */ |
| 32 | |
| 33 | static long int dram_size (long int, long int *, long int); |
| 34 | |
| 35 | /* ------------------------------------------------------------------------- */ |
| 36 | |
| 37 | #define _NOT_USED_ 0xFFFFFFFF |
| 38 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 39 | const uint sdram_table[] = { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 40 | #if (MPC8XX_SPEED <= 50000000L) |
| 41 | /* |
| 42 | * Single Read. (Offset 0 in UPMA RAM) |
| 43 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 44 | 0x0F07EC04, 0x01BBD804, 0x1FF7F440, 0xFFFFFC07, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 45 | 0xFFFFFFFF, |
| 46 | |
| 47 | /* |
| 48 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 49 | * |
| 50 | * This is no UPM entry point. The following definition uses |
| 51 | * the remaining space to establish an initialization |
| 52 | * sequence, which is executed by a RUN command. |
| 53 | * |
| 54 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 55 | 0x1FE7F434, 0xEFABE834, 0x1FA7D435, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * Burst Read. (Offset 8 in UPMA RAM) |
| 59 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 60 | 0x0F07EC04, 0x10EFDC04, 0xF0AFFC00, 0xF0AFFC00, |
| 61 | 0xF1AFFC00, 0xFFAFFC40, 0xFFAFFC07, 0xFFFFFFFF, |
| 62 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 63 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Single Write. (Offset 18 in UPMA RAM) |
| 67 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 68 | 0x0E07E804, 0x01BBD000, 0x1FF7F447, 0xFFFFFFFF, |
| 69 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Burst Write. (Offset 20 in UPMA RAM) |
| 73 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 74 | 0x0E07E800, 0x10EFD400, 0xF0AFFC00, 0xF0AFFC00, |
| 75 | 0xF1AFFC47, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 76 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 77 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Refresh (Offset 30 in UPMA RAM) |
| 81 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 82 | 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC84, 0xFFFFFC07, |
| 83 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 84 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * Exception. (Offset 3c in UPMA RAM) |
| 88 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 89 | 0x7FFFFC07, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 90 | #else |
| 91 | |
| 92 | /* |
| 93 | * Single Read. (Offset 0 in UPMA RAM) |
| 94 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 95 | 0x1F07FC04, 0xEEAFEC04, 0x11AFDC04, 0xEFBBF800, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 96 | 0x1FF7F447, |
| 97 | |
| 98 | /* |
| 99 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 100 | * |
| 101 | * This is no UPM entry point. The following definition uses |
| 102 | * the remaining space to establish an initialization |
| 103 | * sequence, which is executed by a RUN command. |
| 104 | * |
| 105 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 106 | 0x1FF7F434, 0xEFEBE834, 0x1FB7D435, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Burst Read. (Offset 8 in UPMA RAM) |
| 110 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 111 | 0x1F07FC04, 0xEEAFEC04, 0x10AFDC04, 0xF0AFFC00, |
| 112 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBBF800, 0x1FF7F447, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 113 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 114 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 115 | |
| 116 | /* |
| 117 | * Single Write. (Offset 18 in UPMA RAM) |
| 118 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 119 | 0x1F07FC04, 0xEEAFE800, 0x01BBD004, 0x1FF7F447, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 120 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 121 | |
| 122 | /* |
| 123 | * Burst Write. (Offset 20 in UPMA RAM) |
| 124 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 125 | 0x1F07FC04, 0xEEAFE800, 0x10AFD400, 0xF0AFFC00, |
| 126 | 0xF0AFFC00, 0xE1BBF804, 0x1FF7F447, _NOT_USED_, |
| 127 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 128 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 129 | |
| 130 | /* |
| 131 | * Refresh (Offset 30 in UPMA RAM) |
| 132 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 133 | 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 134 | 0xFFFFFC84, 0xFFFFFC07, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 135 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 136 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 137 | |
| 138 | /* |
| 139 | * Exception. (Offset 3c in UPMA RAM) |
| 140 | */ |
| 141 | 0x7FFFFC07, /* last */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 142 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 143 | #endif |
| 144 | }; |
| 145 | |
| 146 | /* ------------------------------------------------------------------------- */ |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | * Check Board Identity: |
| 151 | * |
| 152 | */ |
| 153 | |
| 154 | int checkboard (void) |
| 155 | { |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 156 | printf ("Board: Nexus NX823"); |
| 157 | return (0); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* ------------------------------------------------------------------------- */ |
| 161 | |
| 162 | long int initdram (int board_type) |
| 163 | { |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 164 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 165 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 166 | long int size_b0, size_b1, size8, size9; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 167 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 168 | upmconfig (UPMA, (uint *) sdram_table, |
| 169 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 170 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 171 | /* |
| 172 | * Up to 2 Banks of 64Mbit x 2 devices |
| 173 | * Initial builds only have 1 |
| 174 | */ |
| 175 | memctl->memc_mptpr = CFG_MPTPR_1BK_4K; |
| 176 | memctl->memc_mar = 0x00000088; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 177 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 178 | /* |
| 179 | * Map controller SDRAM bank 0 |
| 180 | */ |
| 181 | memctl->memc_or1 = CFG_OR1_PRELIM; |
| 182 | memctl->memc_br1 = CFG_BR1_PRELIM; |
| 183 | memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */ |
| 184 | udelay (200); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 185 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 186 | /* |
| 187 | * Map controller SDRAM bank 1 |
| 188 | */ |
| 189 | memctl->memc_or2 = CFG_OR2_PRELIM; |
| 190 | memctl->memc_br2 = CFG_BR2_PRELIM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 191 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 192 | /* |
| 193 | * Perform SDRAM initializsation sequence |
| 194 | */ |
| 195 | memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */ |
| 196 | udelay (1); |
| 197 | memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - execute twice */ |
| 198 | udelay (1); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 199 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 200 | memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */ |
| 201 | udelay (1); |
| 202 | memctl->memc_mcr = 0x80004230; /* SDRAM bank 1 - execute twice */ |
| 203 | udelay (1); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 204 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 205 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
| 206 | udelay (1000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 207 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 208 | /* |
| 209 | * Preliminary prescaler for refresh (depends on number of |
| 210 | * banks): This value is selected for four cycles every 62.4 us |
| 211 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 212 | * bank. It will be adjusted after memory sizing. |
| 213 | */ |
| 214 | memctl->memc_mptpr = CFG_MPTPR_2BK_8K; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 215 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 216 | memctl->memc_mar = 0x00000088; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 217 | |
| 218 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 219 | /* |
| 220 | * Check Bank 0 Memory Size for re-configuration |
| 221 | * |
| 222 | * try 8 column mode |
| 223 | */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 224 | size8 = dram_size (CFG_MAMR_8COL, (long *) SDRAM_BASE1_PRELIM, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 225 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 226 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 227 | udelay (1000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 228 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 229 | /* |
| 230 | * try 9 column mode |
| 231 | */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 232 | size9 = dram_size (CFG_MAMR_9COL, (long *) SDRAM_BASE1_PRELIM, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 233 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 234 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 235 | if (size8 < size9) { /* leave configuration at 9 columns */ |
| 236 | size_b0 = size9; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 237 | /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 238 | } else { /* back to 8 columns */ |
| 239 | size_b0 = size8; |
| 240 | memctl->memc_mamr = CFG_MAMR_8COL; |
| 241 | udelay (500); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 242 | /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 243 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Check Bank 1 Memory Size |
| 247 | * use current column settings |
| 248 | * [9 column SDRAM may also be used in 8 column mode, |
| 249 | * but then only half the real size will be used.] |
| 250 | */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 251 | size_b1 = dram_size (memctl->memc_mamr, (long *) SDRAM_BASE2_PRELIM, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 252 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 253 | /* debug ("SDRAM Bank 1: %ld MB\n", size8 >> 20); */ |
| 254 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 255 | udelay (1000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 256 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 257 | /* |
| 258 | * Adjust refresh rate depending on SDRAM type, both banks |
| 259 | * For types > 128 MBit leave it at the current (fast) rate |
| 260 | */ |
| 261 | if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) { |
| 262 | /* reduce to 15.6 us (62.4 us / quad) */ |
| 263 | memctl->memc_mptpr = CFG_MPTPR_2BK_4K; |
| 264 | udelay (1000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 265 | } |
| 266 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 267 | /* |
| 268 | * Final mapping: map bigger bank first |
| 269 | */ |
| 270 | if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 271 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 272 | memctl->memc_or2 = |
| 273 | ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM; |
| 274 | memctl->memc_br2 = |
| 275 | (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 276 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 277 | if (size_b0 > 0) { |
| 278 | /* |
| 279 | * Position Bank 0 immediately above Bank 1 |
| 280 | */ |
| 281 | memctl->memc_or1 = |
| 282 | ((-size_b0) & 0xFFFF0000) | |
| 283 | CFG_OR_TIMING_SDRAM; |
| 284 | memctl->memc_br1 = |
| 285 | ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | |
| 286 | BR_V) |
| 287 | + size_b1; |
| 288 | } else { |
| 289 | unsigned long reg; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 290 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 291 | /* |
| 292 | * No bank 0 |
| 293 | * |
| 294 | * invalidate bank |
| 295 | */ |
| 296 | memctl->memc_br1 = 0; |
| 297 | |
| 298 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 299 | reg = memctl->memc_mptpr; |
| 300 | reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */ |
| 301 | memctl->memc_mptpr = reg; |
| 302 | } |
| 303 | |
| 304 | } else { /* SDRAM Bank 0 is bigger - map first */ |
| 305 | |
| 306 | memctl->memc_or1 = |
| 307 | ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM; |
| 308 | memctl->memc_br1 = |
| 309 | (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
| 310 | |
| 311 | if (size_b1 > 0) { |
| 312 | /* |
| 313 | * Position Bank 1 immediately above Bank 0 |
| 314 | */ |
| 315 | memctl->memc_or2 = |
| 316 | ((-size_b1) & 0xFFFF0000) | |
| 317 | CFG_OR_TIMING_SDRAM; |
| 318 | memctl->memc_br2 = |
| 319 | ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | |
| 320 | BR_V) |
| 321 | + size_b0; |
| 322 | } else { |
| 323 | unsigned long reg; |
| 324 | |
| 325 | /* |
| 326 | * No bank 1 |
| 327 | * |
| 328 | * invalidate bank |
| 329 | */ |
| 330 | memctl->memc_br2 = 0; |
| 331 | |
| 332 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 333 | reg = memctl->memc_mptpr; |
| 334 | reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */ |
| 335 | memctl->memc_mptpr = reg; |
| 336 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 337 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 338 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 339 | udelay (10000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 340 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 341 | return (size_b0 + size_b1); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* ------------------------------------------------------------------------- */ |
| 345 | |
| 346 | /* |
| 347 | * Check memory range for valid RAM. A simple memory test determines |
| 348 | * the actually available RAM size between addresses `base' and |
| 349 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 350 | * - short between address lines |
| 351 | * - short between data lines |
| 352 | */ |
| 353 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 354 | static long int dram_size (long int mamr_value, long int *base, |
| 355 | long int maxsize) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 356 | { |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 357 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 358 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 359 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 360 | memctl->memc_mamr = mamr_value; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 361 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 362 | return (get_ram_size (base, maxsize)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | u_long *my_sernum; |
| 366 | |
| 367 | int misc_init_r (void) |
| 368 | { |
| 369 | DECLARE_GLOBAL_DATA_PTR; |
| 370 | |
| 371 | char tmp[50]; |
| 372 | u_char *e = gd->bd->bi_enetaddr; |
| 373 | |
| 374 | /* save serial numbre from flash (uniquely programmed) */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 375 | my_sernum = malloc (8); |
| 376 | memcpy (my_sernum, gd->bd->bi_sernum, 8); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 377 | |
| 378 | /* save env variables according to sernum */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 379 | sprintf (tmp, "%08lx%08lx", my_sernum[0], my_sernum[1]); |
| 380 | setenv ("serial#", tmp); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 381 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 382 | sprintf (tmp, "%02x:%02x:%02x:%02x:%02x:%02x", e[0], e[1], e[2], e[3], |
| 383 | e[4], e[5]); |
| 384 | setenv ("ethaddr", tmp); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 385 | return (0); |
| 386 | } |
| 387 | |
| 388 | void load_sernum_ethaddr (void) |
| 389 | { |
| 390 | DECLARE_GLOBAL_DATA_PTR; |
| 391 | |
| 392 | int i; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 393 | bd_t *bd = gd->bd; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 394 | |
| 395 | for (i = 0; i < 8; i++) { |
| 396 | bd->bi_sernum[i] = *(u_char *) (CFG_FLASH_SN_BASE + i); |
| 397 | } |
| 398 | bd->bi_enetaddr[0] = 0x10; |
| 399 | bd->bi_enetaddr[1] = 0x20; |
| 400 | bd->bi_enetaddr[2] = 0x30; |
| 401 | bd->bi_enetaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2]; |
| 402 | bd->bi_enetaddr[4] = bd->bi_sernum[5]; |
| 403 | bd->bi_enetaddr[5] = bd->bi_sernum[6]; |
| 404 | } |