wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc. |
| 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 | /* sdram_init.c - automatic memory sizing */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <74xx_7xx.h> |
| 28 | #include <galileo/memory.h> |
| 29 | #include <galileo/pci.h> |
| 30 | #include <galileo/gt64260R.h> |
| 31 | #include <net.h> |
Wolfgang Denk | b191c70 | 2011-11-09 09:28:59 +0000 | [diff] [blame] | 32 | #include <linux/compiler.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | |
| 34 | #include "eth.h" |
| 35 | #include "mpsc.h" |
| 36 | #include "i2c.h" |
| 37 | #include "64260.h" |
| 38 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | /* #define DEBUG */ |
| 42 | #define MAP_PCI |
| 43 | |
| 44 | #ifdef DEBUG |
| 45 | #define DP(x) x |
| 46 | #else |
| 47 | #define DP(x) |
| 48 | #endif |
| 49 | |
| 50 | #define GB (1 << 30) |
| 51 | |
| 52 | /* structure to store the relevant information about an sdram bank */ |
| 53 | typedef struct sdram_info { |
| 54 | uchar drb_size; |
| 55 | uchar registered, ecc; |
| 56 | uchar tpar; |
| 57 | uchar tras_clocks; |
| 58 | uchar burst_len; |
| 59 | uchar banks, slot; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 60 | int size; /* detected size, not from I2C but from dram_size() */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 61 | } sdram_info_t; |
| 62 | |
| 63 | #ifdef DEBUG |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 64 | void dump_dimm_info (struct sdram_info *d) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 66 | static const char *ecc_legend[] = { "", " Parity", " ECC" }; |
| 67 | |
| 68 | printf ("dimm%s %sDRAM: %dMibytes:\n", |
| 69 | ecc_legend[d->ecc], |
| 70 | d->registered ? "R" : "", (d->size >> 20)); |
| 71 | printf (" drb=%d tpar=%d tras=%d burstlen=%d banks=%d slot=%d\n", |
| 72 | d->drb_size, d->tpar, d->tras_clocks, d->burst_len, |
| 73 | d->banks, d->slot); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | } |
| 75 | #endif |
| 76 | |
| 77 | static int |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 78 | memory_map_bank (unsigned int bankNo, |
| 79 | unsigned int bankBase, unsigned int bankLength) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 80 | { |
| 81 | #ifdef DEBUG |
| 82 | if (bankLength > 0) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 83 | printf ("mapping bank %d at %08x - %08x\n", |
| 84 | bankNo, bankBase, bankBase + bankLength - 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | } else { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 86 | printf ("unmapping bank %d\n", bankNo); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 87 | } |
| 88 | #endif |
| 89 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 90 | memoryMapBank (bankNo, bankBase, bankLength); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | #ifdef MAP_PCI |
| 96 | static int |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 97 | memory_map_bank_pci (unsigned int bankNo, |
| 98 | unsigned int bankBase, unsigned int bankLength) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | { |
| 100 | PCI_HOST host; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 101 | |
| 102 | for (host = PCI_HOST0; host <= PCI_HOST1; host++) { |
| 103 | const int features = |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 104 | PREFETCH_ENABLE | |
| 105 | DELAYED_READ_ENABLE | |
| 106 | AGGRESSIVE_PREFETCH | |
| 107 | READ_LINE_AGGRESSIVE_PREFETCH | |
| 108 | READ_MULTI_AGGRESSIVE_PREFETCH | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 109 | MAX_BURST_4 | PCI_NO_SWAP; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 111 | pciMapMemoryBank (host, bankNo, bankBase, bankLength); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 113 | pciSetRegionSnoopMode (host, bankNo, PCI_SNOOP_WB, bankBase, |
| 114 | bankLength); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 115 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 116 | pciSetRegionFeatures (host, bankNo, features, bankBase, |
| 117 | bankLength); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | } |
| 119 | return 0; |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | /* ------------------------------------------------------------------------- */ |
| 124 | |
| 125 | /* much of this code is based on (or is) the code in the pip405 port */ |
| 126 | /* thanks go to the authors of said port - Josh */ |
| 127 | |
| 128 | |
| 129 | /* |
| 130 | * translate ns.ns/10 coding of SPD timing values |
| 131 | * into 10 ps unit values |
| 132 | */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 133 | static inline unsigned short NS10to10PS (unsigned char spd_byte) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | { |
| 135 | unsigned short ns, ns10; |
| 136 | |
| 137 | /* isolate upper nibble */ |
| 138 | ns = (spd_byte >> 4) & 0x0F; |
| 139 | /* isolate lower nibble */ |
| 140 | ns10 = (spd_byte & 0x0F); |
| 141 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 142 | return (ns * 100 + ns10 * 10); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* |
| 146 | * translate ns coding of SPD timing values |
| 147 | * into 10 ps unit values |
| 148 | */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 149 | static inline unsigned short NSto10PS (unsigned char spd_byte) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 150 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 151 | return (spd_byte * 100); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | #ifdef CONFIG_ZUMA_V2 |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 155 | static int check_dimm (uchar slot, sdram_info_t * info) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 157 | /* assume 2 dimms, 2 banks each 256M - we dont have an |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | * dimm i2c so rely on the detection routines later */ |
| 159 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 160 | memset (info, 0, sizeof (*info)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 161 | |
| 162 | info->slot = slot; |
| 163 | info->banks = 2; /* Detect later */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 164 | info->registered = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | info->drb_size = 32; /* 16 - 256MBit, 32 - 512MBit |
| 166 | but doesn't matter, both do same |
| 167 | thing in setup_sdram() */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 168 | info->tpar = 3; |
| 169 | info->tras_clocks = 5; |
| 170 | info->burst_len = 4; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 171 | #ifdef CONFIG_ECC |
| 172 | info->ecc = 0; /* Detect later */ |
| 173 | #endif /* CONFIG_ECC */ |
| 174 | return 0; |
| 175 | } |
| 176 | |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 177 | #elif defined(CONFIG_P3G4) |
| 178 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 179 | static int check_dimm (uchar slot, sdram_info_t * info) |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 180 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 181 | memset (info, 0, sizeof (*info)); |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 182 | |
| 183 | if (slot) |
| 184 | return 0; |
| 185 | |
| 186 | info->slot = slot; |
| 187 | info->banks = 1; |
| 188 | info->registered = 0; |
| 189 | info->drb_size = 4; |
| 190 | info->tpar = 3; |
| 191 | info->tras_clocks = 6; |
| 192 | info->burst_len = 4; |
| 193 | #ifdef CONFIG_ECC |
| 194 | info->ecc = 2; |
| 195 | #endif |
| 196 | return 0; |
| 197 | } |
| 198 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 199 | #else /* ! CONFIG_ZUMA_V2 && ! CONFIG_P3G4 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 200 | |
| 201 | /* This code reads the SPD chip on the sdram and populates |
| 202 | * the array which is passed in with the relevant information */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 203 | static int check_dimm (uchar slot, sdram_info_t * info) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 204 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 205 | uchar addr = slot == 0 ? DIMM0_I2C_ADDR : DIMM1_I2C_ADDR; |
| 206 | int ret; |
| 207 | uchar rows, cols, sdram_banks, supp_cal, width, cal_val; |
| 208 | ulong tmemclk; |
| 209 | uchar trp_clocks, trcd_clocks; |
| 210 | uchar data[128]; |
| 211 | |
| 212 | get_clocks (); |
| 213 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 214 | tmemclk = 1000000000 / (gd->bus_clk / 100); /* in 10 ps units */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 215 | |
| 216 | #ifdef CONFIG_EVB64260_750CX |
| 217 | if (0 != slot) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 218 | printf ("check_dimm: The EVB-64260-750CX only has 1 DIMM,"); |
| 219 | printf (" called with slot=%d insetad!\n", slot); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | #endif |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 223 | DP (puts ("before i2c read\n")); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 224 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 225 | ret = i2c_read (addr, 0, 128, data, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 226 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 227 | DP (puts ("after i2c read\n")); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 228 | |
| 229 | /* zero all the values */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 230 | memset (info, 0, sizeof (*info)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 231 | |
| 232 | if (ret) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 233 | DP (printf ("No DIMM in slot %d [err = %x]\n", slot, ret)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /* first, do some sanity checks */ |
| 238 | if (data[2] != 0x4) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 239 | printf ("Not SDRAM in slot %d\n", slot); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | /* get various information */ |
| 244 | rows = data[3]; |
| 245 | cols = data[4]; |
| 246 | info->banks = data[5]; |
| 247 | sdram_banks = data[17]; |
| 248 | width = data[13] & 0x7f; |
| 249 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 250 | DP (printf |
| 251 | ("sdram_banks: %d, banks: %d\n", sdram_banks, info->banks)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 252 | |
| 253 | /* check if the memory is registered */ |
| 254 | if (data[21] & (BIT1 | BIT4)) |
| 255 | info->registered = 1; |
| 256 | |
| 257 | #ifdef CONFIG_ECC |
| 258 | /* check for ECC/parity [0 = none, 1 = parity, 2 = ecc] */ |
| 259 | info->ecc = (data[11] & 2) >> 1; |
| 260 | #endif |
| 261 | |
| 262 | /* bit 1 is CL2, bit 2 is CL3 */ |
| 263 | supp_cal = (data[18] & 0x6) >> 1; |
| 264 | |
| 265 | /* compute the relevant clock values */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 266 | trp_clocks = (NSto10PS (data[27]) + (tmemclk - 1)) / tmemclk; |
| 267 | trcd_clocks = (NSto10PS (data[29]) + (tmemclk - 1)) / tmemclk; |
| 268 | info->tras_clocks = (NSto10PS (data[30]) + (tmemclk - 1)) / tmemclk; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 270 | DP (printf ("trp = %d\ntrcd_clocks = %d\ntras_clocks = %d\n", |
| 271 | trp_clocks, trcd_clocks, info->tras_clocks)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 272 | |
| 273 | /* try a CAS latency of 3 first... */ |
| 274 | cal_val = 0; |
| 275 | if (supp_cal & 3) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 276 | if (NS10to10PS (data[9]) <= tmemclk) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 277 | cal_val = 3; |
| 278 | } |
| 279 | |
| 280 | /* then 2... */ |
| 281 | if (supp_cal & 2) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 282 | if (NS10to10PS (data[23]) <= tmemclk) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 283 | cal_val = 2; |
| 284 | } |
| 285 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 286 | DP (printf ("cal_val = %d\n", cal_val)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 287 | |
| 288 | /* bummer, did't work... */ |
| 289 | if (cal_val == 0) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 290 | DP (printf ("Couldn't find a good CAS latency\n")); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | /* get the largest delay -- these values need to all be the same |
| 295 | * see Res#6 */ |
| 296 | info->tpar = cal_val; |
| 297 | if (trp_clocks > info->tpar) |
| 298 | info->tpar = trp_clocks; |
| 299 | if (trcd_clocks > info->tpar) |
| 300 | info->tpar = trcd_clocks; |
| 301 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 302 | DP (printf ("tpar set to: %d\n", info->tpar)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 303 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 304 | #ifdef CONFIG_SYS_BROKEN_CL2 |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 305 | if (info->tpar == 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 306 | info->tpar = 3; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 307 | DP (printf ("tpar fixed-up to: %d\n", info->tpar)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 308 | } |
| 309 | #endif |
| 310 | /* compute the module DRB size */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 311 | info->drb_size = |
| 312 | (((1 << (rows + cols)) * sdram_banks) * width) / _16M; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 313 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 314 | DP (printf ("drb_size set to: %d\n", info->drb_size)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 315 | |
| 316 | /* find the burst len */ |
| 317 | info->burst_len = data[16] & 0xf; |
| 318 | if ((info->burst_len & 8) == 8) { |
| 319 | info->burst_len = 1; |
| 320 | } else if ((info->burst_len & 4) == 4) { |
| 321 | info->burst_len = 0; |
| 322 | } else { |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | info->slot = slot; |
| 327 | return 0; |
| 328 | } |
| 329 | #endif /* ! CONFIG_ZUMA_V2 */ |
| 330 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 331 | static int setup_sdram_common (sdram_info_t info[2]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 332 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 333 | ulong tmp; |
Wolfgang Denk | b191c70 | 2011-11-09 09:28:59 +0000 | [diff] [blame] | 334 | int tpar = 2, tras_clocks = 5, registered = 1; |
| 335 | __maybe_unused int ecc = 2; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 336 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 337 | if (!info[0].banks && !info[1].banks) |
| 338 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 339 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 340 | if (info[0].banks) { |
| 341 | if (info[0].tpar > tpar) |
| 342 | tpar = info[0].tpar; |
| 343 | if (info[0].tras_clocks > tras_clocks) |
| 344 | tras_clocks = info[0].tras_clocks; |
| 345 | if (!info[0].registered) |
| 346 | registered = 0; |
wdenk | 3f85ce2 | 2004-02-23 16:11:30 +0000 | [diff] [blame] | 347 | if (info[0].ecc != 2) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 348 | ecc = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 349 | } |
| 350 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 351 | if (info[1].banks) { |
| 352 | if (info[1].tpar > tpar) |
| 353 | tpar = info[1].tpar; |
| 354 | if (info[1].tras_clocks > tras_clocks) |
| 355 | tras_clocks = info[1].tras_clocks; |
| 356 | if (!info[1].registered) |
| 357 | registered = 0; |
| 358 | if (info[1].ecc != 2) |
| 359 | ecc = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /* SDRAM configuration */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 363 | tmp = GTREGREAD (SDRAM_CONFIGURATION); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 364 | |
| 365 | /* Turn on physical interleave if both DIMMs |
| 366 | * have even numbers of banks. */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 367 | if ((info[0].banks == 0 || info[0].banks == 2) && |
| 368 | (info[1].banks == 0 || info[1].banks == 2)) { |
| 369 | /* physical interleave on */ |
| 370 | tmp &= ~(1 << 15); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 371 | } else { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 372 | /* physical interleave off */ |
| 373 | tmp |= (1 << 15); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | tmp |= (registered << 17); |
| 377 | |
| 378 | /* Use buffer 1 to return read data to the CPU |
| 379 | * See Res #12 */ |
| 380 | tmp |= (1 << 26); |
| 381 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 382 | GT_REG_WRITE (SDRAM_CONFIGURATION, tmp); |
| 383 | DP (printf ("SDRAM config: %08x\n", GTREGREAD (SDRAM_CONFIGURATION))); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 384 | |
| 385 | /* SDRAM timing */ |
| 386 | tmp = (((tpar == 3) ? 2 : 1) | |
| 387 | (((tpar == 3) ? 2 : 1) << 2) | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 388 | (((tpar == 3) ? 2 : 1) << 4) | (tras_clocks << 8)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 389 | |
| 390 | #ifdef CONFIG_ECC |
| 391 | /* Setup ECC */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 392 | if (ecc == 2) |
| 393 | tmp |= 1 << 13; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 394 | #endif /* CONFIG_ECC */ |
| 395 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 396 | GT_REG_WRITE (SDRAM_TIMING, tmp); |
| 397 | DP (printf ("SDRAM timing: %08x (%d,%d,%d,%d)\n", |
| 398 | GTREGREAD (SDRAM_TIMING), tpar, tpar, tpar, tras_clocks)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 399 | |
| 400 | /* SDRAM address decode register */ |
| 401 | /* program this with the default value */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 402 | GT_REG_WRITE (SDRAM_ADDRESS_DECODE, 0x2); |
| 403 | DP (printf ("SDRAM decode: %08x\n", |
| 404 | GTREGREAD (SDRAM_ADDRESS_DECODE))); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | /* sets up the GT properly with information passed in */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 410 | static int setup_sdram (sdram_info_t * info) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 411 | { |
Wolfgang Denk | b191c70 | 2011-11-09 09:28:59 +0000 | [diff] [blame] | 412 | ulong tmp; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 413 | ulong *addr = 0; |
Wolfgang Denk | b191c70 | 2011-11-09 09:28:59 +0000 | [diff] [blame] | 414 | __maybe_unused ulong check; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | int i; |
| 416 | |
| 417 | /* sanity checking */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 418 | if (!info->banks) |
| 419 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | |
| 421 | /* ---------------------------- */ |
| 422 | /* Program the GT with the discovered data */ |
| 423 | |
| 424 | /* bank parameters */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 425 | tmp = (0xf << 16); /* leave all virt bank pages open */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 426 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 427 | DP (printf ("drb_size: %d\n", info->drb_size)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 428 | switch (info->drb_size) { |
| 429 | case 1: |
| 430 | tmp |= (1 << 14); |
| 431 | break; |
| 432 | case 4: |
| 433 | case 8: |
| 434 | tmp |= (2 << 14); |
| 435 | break; |
| 436 | case 16: |
| 437 | case 32: |
| 438 | tmp |= (3 << 14); |
| 439 | break; |
| 440 | default: |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 441 | printf ("Error in dram size calculation\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 442 | return 1; |
| 443 | } |
| 444 | |
| 445 | /* SDRAM bank parameters */ |
| 446 | /* the param registers for slot 1 (banks 2+3) are offset by 0x8 */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 447 | GT_REG_WRITE (SDRAM_BANK0PARAMETERS + (info->slot * 0x8), tmp); |
| 448 | GT_REG_WRITE (SDRAM_BANK1PARAMETERS + (info->slot * 0x8), tmp); |
| 449 | DP (printf |
| 450 | ("SDRAM bankparam slot %d (bank %d+%d): %08lx\n", info->slot, |
| 451 | info->slot * 2, (info->slot * 2) + 1, tmp)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | |
| 453 | /* set the SDRAM configuration for each bank */ |
| 454 | for (i = info->slot * 2; i < ((info->slot * 2) + info->banks); i++) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 455 | DP (printf ("*** Running a MRS cycle for bank %d ***\n", i)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 456 | |
| 457 | /* map the bank */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 458 | memory_map_bank (i, 0, GB / 4); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 459 | |
| 460 | /* set SDRAM mode */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 461 | GT_REG_WRITE (SDRAM_OPERATION_MODE, 0x3); |
| 462 | check = GTREGREAD (SDRAM_OPERATION_MODE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 463 | |
| 464 | /* dummy write */ |
| 465 | *addr = 0; |
| 466 | |
| 467 | /* wait for the command to complete */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 468 | while ((GTREGREAD (SDRAM_OPERATION_MODE) & (1 << 31)) == 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 469 | |
| 470 | /* switch back to normal operation mode */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 471 | GT_REG_WRITE (SDRAM_OPERATION_MODE, 0); |
| 472 | check = GTREGREAD (SDRAM_OPERATION_MODE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 473 | |
| 474 | /* unmap the bank */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 475 | memory_map_bank (i, 0, 0); |
| 476 | DP (printf ("*** MRS cycle for bank %d done ***\n", i)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | * Check memory range for valid RAM. A simple memory test determines |
| 484 | * the actually available RAM size between addresses `base' and |
| 485 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 486 | * - short between address lines |
| 487 | * - short between data lines |
| 488 | */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 489 | static long int dram_size (long int *base, long int maxsize) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 490 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 491 | volatile long int *addr, *b = base; |
| 492 | long int cnt, val, save1, save2; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 493 | |
| 494 | #define STARTVAL (1<<20) /* start test at 1M */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 495 | for (cnt = STARTVAL / sizeof (long); cnt < maxsize / sizeof (long); |
| 496 | cnt <<= 1) { |
| 497 | addr = base + cnt; /* pointer arith! */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 498 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 499 | save1 = *addr; /* save contents of addr */ |
| 500 | save2 = *b; /* save contents of base */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 501 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 502 | *addr = cnt; /* write cnt to addr */ |
| 503 | *b = 0; /* put null at base */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 504 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 505 | /* check at base address */ |
| 506 | if ((*b) != 0) { |
| 507 | *addr = save1; /* restore *addr */ |
| 508 | *b = save2; /* restore *b */ |
| 509 | return (0); |
| 510 | } |
| 511 | val = *addr; /* read *addr */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 512 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 513 | *addr = save1; |
| 514 | *b = save2; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 515 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 516 | if (val != cnt) { |
| 517 | /* fix boundary condition.. STARTVAL means zero */ |
| 518 | if (cnt == STARTVAL / sizeof (long)) |
| 519 | cnt = 0; |
| 520 | return (cnt * sizeof (long)); |
| 521 | } |
| 522 | } |
| 523 | return maxsize; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /* ------------------------------------------------------------------------- */ |
| 527 | |
| 528 | /* U-Boot interface function to SDRAM init - this is where all the |
| 529 | * controlling logic happens */ |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 530 | phys_size_t initdram (int board_type) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 531 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 532 | ulong checkbank[4] = {[0 ... 3] = 0 }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 533 | int bank_no; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 534 | ulong total; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 535 | int nhr; |
| 536 | sdram_info_t dimm_info[2]; |
| 537 | |
| 538 | |
| 539 | /* first, use the SPD to get info about the SDRAM */ |
| 540 | |
| 541 | /* check the NHR bit and skip mem init if it's already done */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 542 | nhr = get_hid0 () & (1 << 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 543 | |
| 544 | if (nhr) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 545 | printf ("Skipping SDRAM setup due to NHR bit being set\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 546 | } else { |
| 547 | /* DIMM0 */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 548 | check_dimm (0, &dimm_info[0]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 549 | |
| 550 | /* DIMM1 */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 551 | #ifndef CONFIG_EVB64260_750CX /* EVB64260_750CX has only 1 DIMM */ |
| 552 | check_dimm (1, &dimm_info[1]); |
| 553 | #else /* CONFIG_EVB64260_750CX */ |
| 554 | memset (&dimm_info[1], 0, sizeof (sdram_info_t)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 555 | #endif |
| 556 | |
| 557 | /* unmap all banks */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 558 | memory_map_bank (0, 0, 0); |
| 559 | memory_map_bank (1, 0, 0); |
| 560 | memory_map_bank (2, 0, 0); |
| 561 | memory_map_bank (3, 0, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 562 | |
| 563 | /* Now, program the GT with the correct values */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 564 | if (setup_sdram_common (dimm_info)) { |
| 565 | printf ("Setup common failed.\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 566 | } |
| 567 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 568 | if (setup_sdram (&dimm_info[0])) { |
| 569 | printf ("Setup for DIMM1 failed.\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 570 | } |
| 571 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 572 | if (setup_sdram (&dimm_info[1])) { |
| 573 | printf ("Setup for DIMM2 failed.\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* set the NHR bit */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 577 | set_hid0 (get_hid0 () | (1 << 16)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 578 | } |
| 579 | /* next, size the SDRAM banks */ |
| 580 | |
| 581 | total = 0; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 582 | if (dimm_info[0].banks > 0) |
| 583 | checkbank[0] = 1; |
| 584 | if (dimm_info[0].banks > 1) |
| 585 | checkbank[1] = 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 586 | if (dimm_info[0].banks > 2) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 587 | printf ("Error, SPD claims DIMM1 has >2 banks\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 588 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 589 | if (dimm_info[1].banks > 0) |
| 590 | checkbank[2] = 1; |
| 591 | if (dimm_info[1].banks > 1) |
| 592 | checkbank[3] = 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 593 | if (dimm_info[1].banks > 2) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 594 | printf ("Error, SPD claims DIMM2 has >2 banks\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 595 | |
| 596 | /* Generic dram sizer: works even if we don't have i2c DIMMs, |
| 597 | * as long as the timing settings are more or less correct */ |
| 598 | |
| 599 | /* |
| 600 | * pass 1: size all the banks, using first bat (0-256M) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 601 | * limitation: we only support 256M per bank due to |
| 602 | * us only having 1 BAT for all DRAM |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 603 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 604 | for (bank_no = 0; bank_no < CONFIG_SYS_DRAM_BANKS; bank_no++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 605 | /* skip over banks that are not populated */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 606 | if (!checkbank[bank_no]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 607 | continue; |
| 608 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 609 | DP (printf ("checking bank %d\n", bank_no)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 610 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 611 | memory_map_bank (bank_no, 0, GB / 4); |
| 612 | checkbank[bank_no] = dram_size (NULL, GB / 4); |
| 613 | memory_map_bank (bank_no, 0, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 614 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 615 | DP (printf ("bank %d %08lx\n", bank_no, checkbank[bank_no])); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
| 619 | * pass 2: contiguously map each bank into physical address |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 620 | * space. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 621 | */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 622 | dimm_info[0].banks = dimm_info[1].banks = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 623 | for (bank_no = 0; bank_no < CONFIG_SYS_DRAM_BANKS; bank_no++) { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 624 | if (!checkbank[bank_no]) |
| 625 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 626 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 627 | dimm_info[bank_no / 2].banks++; |
| 628 | dimm_info[bank_no / 2].size += checkbank[bank_no]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 629 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 630 | memory_map_bank (bank_no, total, checkbank[bank_no]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 631 | #ifdef MAP_PCI |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 632 | memory_map_bank_pci (bank_no, total, checkbank[bank_no]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 633 | #endif |
| 634 | total += checkbank[bank_no]; |
| 635 | } |
| 636 | |
| 637 | #ifdef CONFIG_ECC |
| 638 | #ifdef CONFIG_ZUMA_V2 |
| 639 | /* |
| 640 | * We always enable ECC when bank 2 and 3 are unpopulated |
| 641 | * If we 2 or 3 are populated, we CAN'T support ECC. |
| 642 | * (Zuma boards only support ECC in banks 0 and 1; assume that |
| 643 | * in that configuration, ECC chips are mounted, even for stacked |
| 644 | * chips) |
| 645 | */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 646 | if (checkbank[2] == 0 && checkbank[3] == 0) { |
| 647 | dimm_info[0].ecc = 2; |
| 648 | GT_REG_WRITE (SDRAM_TIMING, |
| 649 | GTREGREAD (SDRAM_TIMING) | (1 << 13)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 650 | /* TODO: do we have to run MRS cycles again? */ |
| 651 | } |
| 652 | #endif /* CONFIG_ZUMA_V2 */ |
| 653 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 654 | if (GTREGREAD (SDRAM_TIMING) & (1 << 13)) { |
| 655 | puts ("[ECC] "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 656 | } |
| 657 | #endif /* CONFIG_ECC */ |
| 658 | |
| 659 | #ifdef DEBUG |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 660 | dump_dimm_info (&dimm_info[0]); |
| 661 | dump_dimm_info (&dimm_info[1]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 662 | #endif |
| 663 | /* TODO: return at MOST 256M? */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 664 | /* return total > GB/4 ? GB/4 : total; */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 665 | return total; |
| 666 | } |