Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 2 | * Copyright 2008-2012 Freescale Semiconductor, Inc. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * Version 2 as published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Generic driver for Freescale DDR/DDR2/DDR3 memory controller. |
| 11 | * Based on code from spd_sdram.c |
| 12 | * Author: James Yang [at freescale.com] |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 16 | #include <i2c.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 17 | #include <fsl_ddr_sdram.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 18 | #include <fsl_ddr.h> |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 19 | |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 20 | #ifdef CONFIG_PPC |
| 21 | #include <asm/fsl_law.h> |
| 22 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 23 | void fsl_ddr_set_lawbar( |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 24 | const common_timing_params_t *memctl_common_params, |
| 25 | unsigned int memctl_interleaved, |
| 26 | unsigned int ctrl_num); |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 27 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 28 | |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 29 | void fsl_ddr_set_intl3r(const unsigned int granule_size); |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 30 | #if defined(SPD_EEPROM_ADDRESS) || \ |
| 31 | defined(SPD_EEPROM_ADDRESS1) || defined(SPD_EEPROM_ADDRESS2) || \ |
| 32 | defined(SPD_EEPROM_ADDRESS3) || defined(SPD_EEPROM_ADDRESS4) |
| 33 | #if (CONFIG_NUM_DDR_CONTROLLERS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
| 34 | u8 spd_i2c_addr[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR] = { |
| 35 | [0][0] = SPD_EEPROM_ADDRESS, |
| 36 | }; |
York Sun | 92b46ac | 2011-08-26 11:32:41 -0700 | [diff] [blame] | 37 | #elif (CONFIG_NUM_DDR_CONTROLLERS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 38 | u8 spd_i2c_addr[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR] = { |
| 39 | [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */ |
York Sun | 92b46ac | 2011-08-26 11:32:41 -0700 | [diff] [blame] | 40 | [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */ |
| 41 | }; |
| 42 | #elif (CONFIG_NUM_DDR_CONTROLLERS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
| 43 | u8 spd_i2c_addr[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR] = { |
| 44 | [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */ |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 45 | [1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */ |
| 46 | }; |
York Sun | 92b46ac | 2011-08-26 11:32:41 -0700 | [diff] [blame] | 47 | #elif (CONFIG_NUM_DDR_CONTROLLERS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 48 | u8 spd_i2c_addr[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR] = { |
| 49 | [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */ |
| 50 | [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */ |
| 51 | [1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */ |
| 52 | [1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */ |
| 53 | }; |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 54 | #elif (CONFIG_NUM_DDR_CONTROLLERS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
| 55 | u8 spd_i2c_addr[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR] = { |
| 56 | [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */ |
| 57 | [1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */ |
| 58 | [2][0] = SPD_EEPROM_ADDRESS3, /* controller 3 */ |
| 59 | }; |
| 60 | #elif (CONFIG_NUM_DDR_CONTROLLERS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
| 61 | u8 spd_i2c_addr[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR] = { |
| 62 | [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */ |
| 63 | [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */ |
| 64 | [1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */ |
| 65 | [1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */ |
| 66 | [2][0] = SPD_EEPROM_ADDRESS5, /* controller 3 */ |
| 67 | [2][1] = SPD_EEPROM_ADDRESS6, /* controller 3 */ |
| 68 | }; |
| 69 | |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | static void __get_spd(generic_spd_eeprom_t *spd, u8 i2c_address) |
| 73 | { |
Valentin Longchamp | 993967a | 2013-10-18 11:47:19 +0200 | [diff] [blame] | 74 | int ret; |
| 75 | |
| 76 | i2c_set_bus_num(CONFIG_SYS_SPD_BUS_NUM); |
| 77 | |
| 78 | ret = i2c_read(i2c_address, 0, 1, (uchar *)spd, |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 79 | sizeof(generic_spd_eeprom_t)); |
| 80 | |
| 81 | if (ret) { |
York Sun | 9b9372f | 2012-10-08 07:44:28 +0000 | [diff] [blame] | 82 | if (i2c_address == |
| 83 | #ifdef SPD_EEPROM_ADDRESS |
| 84 | SPD_EEPROM_ADDRESS |
| 85 | #elif defined(SPD_EEPROM_ADDRESS1) |
| 86 | SPD_EEPROM_ADDRESS1 |
| 87 | #endif |
| 88 | ) { |
| 89 | printf("DDR: failed to read SPD from address %u\n", |
| 90 | i2c_address); |
| 91 | } else { |
| 92 | debug("DDR: failed to read SPD from address %u\n", |
| 93 | i2c_address); |
| 94 | } |
Kumar Gala | c68e86c | 2011-01-31 22:18:47 -0600 | [diff] [blame] | 95 | memset(spd, 0, sizeof(generic_spd_eeprom_t)); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | __attribute__((weak, alias("__get_spd"))) |
| 100 | void get_spd(generic_spd_eeprom_t *spd, u8 i2c_address); |
| 101 | |
| 102 | void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd, |
| 103 | unsigned int ctrl_num) |
| 104 | { |
| 105 | unsigned int i; |
| 106 | unsigned int i2c_address = 0; |
| 107 | |
| 108 | if (ctrl_num >= CONFIG_NUM_DDR_CONTROLLERS) { |
| 109 | printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) { |
| 114 | i2c_address = spd_i2c_addr[ctrl_num][i]; |
| 115 | get_spd(&(ctrl_dimms_spd[i]), i2c_address); |
| 116 | } |
| 117 | } |
| 118 | #else |
| 119 | void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd, |
| 120 | unsigned int ctrl_num) |
| 121 | { |
| 122 | } |
| 123 | #endif /* SPD_EEPROM_ADDRESSx */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * ASSUMPTIONS: |
| 127 | * - Same number of CONFIG_DIMM_SLOTS_PER_CTLR on each controller |
| 128 | * - Same memory data bus width on all controllers |
| 129 | * |
| 130 | * NOTES: |
| 131 | * |
| 132 | * The memory controller and associated documentation use confusing |
| 133 | * terminology when referring to the orgranization of DRAM. |
| 134 | * |
| 135 | * Here is a terminology translation table: |
| 136 | * |
| 137 | * memory controller/documention |industry |this code |signals |
| 138 | * -------------------------------|-----------|-----------|----------------- |
Wolfgang Denk | 9dbbd7b | 2008-09-13 02:23:05 +0200 | [diff] [blame] | 139 | * physical bank/bank |rank |rank |chip select (CS) |
| 140 | * logical bank/sub-bank |bank |bank |bank address (BA) |
| 141 | * page/row |row |page |row address |
| 142 | * ??? |column |column |column address |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 143 | * |
| 144 | * The naming confusion is further exacerbated by the descriptions of the |
| 145 | * memory controller interleaving feature, where accesses are interleaved |
| 146 | * _BETWEEN_ two seperate memory controllers. This is configured only in |
| 147 | * CS0_CONFIG[INTLV_CTL] of each memory controller. |
| 148 | * |
| 149 | * memory controller documentation | number of chip selects |
Wolfgang Denk | 9dbbd7b | 2008-09-13 02:23:05 +0200 | [diff] [blame] | 150 | * | per memory controller supported |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 151 | * --------------------------------|----------------------------------------- |
Wolfgang Denk | 9dbbd7b | 2008-09-13 02:23:05 +0200 | [diff] [blame] | 152 | * cache line interleaving | 1 (CS0 only) |
| 153 | * page interleaving | 1 (CS0 only) |
| 154 | * bank interleaving | 1 (CS0 only) |
| 155 | * superbank interleraving | depends on bank (chip select) |
| 156 | * | interleraving [rank interleaving] |
| 157 | * | mode used on every memory controller |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 158 | * |
| 159 | * Even further confusing is the existence of the interleaving feature |
| 160 | * _WITHIN_ each memory controller. The feature is referred to in |
| 161 | * documentation as chip select interleaving or bank interleaving, |
| 162 | * although it is configured in the DDR_SDRAM_CFG field. |
| 163 | * |
Wolfgang Denk | 9dbbd7b | 2008-09-13 02:23:05 +0200 | [diff] [blame] | 164 | * Name of field | documentation name | this code |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 165 | * -----------------------------|-----------------------|------------------ |
Wolfgang Denk | 9dbbd7b | 2008-09-13 02:23:05 +0200 | [diff] [blame] | 166 | * DDR_SDRAM_CFG[BA_INTLV_CTL] | Bank (chip select) | rank interleaving |
| 167 | * | interleaving |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 168 | */ |
| 169 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 170 | const char *step_string_tbl[] = { |
| 171 | "STEP_GET_SPD", |
| 172 | "STEP_COMPUTE_DIMM_PARMS", |
| 173 | "STEP_COMPUTE_COMMON_PARMS", |
| 174 | "STEP_GATHER_OPTS", |
| 175 | "STEP_ASSIGN_ADDRESSES", |
| 176 | "STEP_COMPUTE_REGS", |
| 177 | "STEP_PROGRAM_REGS", |
| 178 | "STEP_ALL" |
| 179 | }; |
| 180 | |
| 181 | const char * step_to_string(unsigned int step) { |
| 182 | |
| 183 | unsigned int s = __ilog2(step); |
| 184 | |
| 185 | if ((1 << s) != step) |
| 186 | return step_string_tbl[7]; |
| 187 | |
| 188 | return step_string_tbl[s]; |
| 189 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 190 | |
York Sun | 01a8258 | 2013-03-25 07:39:35 +0000 | [diff] [blame] | 191 | static unsigned long long __step_assign_addresses(fsl_ddr_info_t *pinfo, |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 192 | unsigned int dbw_cap_adj[]) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 193 | { |
| 194 | int i, j; |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 195 | unsigned long long total_mem, current_mem_base, total_ctlr_mem; |
| 196 | unsigned long long rank_density, ctlr_density = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * If a reduced data width is requested, but the SPD |
| 200 | * specifies a physically wider device, adjust the |
| 201 | * computed dimm capacities accordingly before |
| 202 | * assigning addresses. |
| 203 | */ |
| 204 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 205 | unsigned int found = 0; |
| 206 | |
| 207 | switch (pinfo->memctl_opts[i].data_bus_width) { |
| 208 | case 2: |
| 209 | /* 16-bit */ |
York Sun | dd803dd | 2011-05-27 07:25:51 +0800 | [diff] [blame] | 210 | for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) { |
| 211 | unsigned int dw; |
| 212 | if (!pinfo->dimm_params[i][j].n_ranks) |
| 213 | continue; |
| 214 | dw = pinfo->dimm_params[i][j].primary_sdram_width; |
| 215 | if ((dw == 72 || dw == 64)) { |
| 216 | dbw_cap_adj[i] = 2; |
| 217 | break; |
| 218 | } else if ((dw == 40 || dw == 32)) { |
| 219 | dbw_cap_adj[i] = 1; |
| 220 | break; |
| 221 | } |
| 222 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 223 | break; |
| 224 | |
| 225 | case 1: |
| 226 | /* 32-bit */ |
| 227 | for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) { |
| 228 | unsigned int dw; |
| 229 | dw = pinfo->dimm_params[i][j].data_width; |
| 230 | if (pinfo->dimm_params[i][j].n_ranks |
| 231 | && (dw == 72 || dw == 64)) { |
| 232 | /* |
| 233 | * FIXME: can't really do it |
| 234 | * like this because this just |
| 235 | * further reduces the memory |
| 236 | */ |
| 237 | found = 1; |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | if (found) { |
| 242 | dbw_cap_adj[i] = 1; |
| 243 | } |
| 244 | break; |
| 245 | |
| 246 | case 0: |
| 247 | /* 64-bit */ |
| 248 | break; |
| 249 | |
| 250 | default: |
| 251 | printf("unexpected data bus width " |
| 252 | "specified controller %u\n", i); |
| 253 | return 1; |
| 254 | } |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 255 | debug("dbw_cap_adj[%d]=%d\n", i, dbw_cap_adj[i]); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 256 | } |
| 257 | |
York Sun | 6446f1e | 2013-10-28 16:36:02 -0700 | [diff] [blame^] | 258 | current_mem_base = CONFIG_SYS_DDR_SDRAM_BASE; |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 259 | total_mem = 0; |
| 260 | if (pinfo->memctl_opts[0].memctl_interleaving) { |
| 261 | rank_density = pinfo->dimm_params[0][0].rank_density >> |
| 262 | dbw_cap_adj[0]; |
| 263 | switch (pinfo->memctl_opts[0].ba_intlv_ctl & |
| 264 | FSL_DDR_CS0_CS1_CS2_CS3) { |
| 265 | case FSL_DDR_CS0_CS1_CS2_CS3: |
| 266 | ctlr_density = 4 * rank_density; |
| 267 | break; |
| 268 | case FSL_DDR_CS0_CS1: |
| 269 | case FSL_DDR_CS0_CS1_AND_CS2_CS3: |
| 270 | ctlr_density = 2 * rank_density; |
| 271 | break; |
| 272 | case FSL_DDR_CS2_CS3: |
| 273 | default: |
| 274 | ctlr_density = rank_density; |
| 275 | break; |
| 276 | } |
| 277 | debug("rank density is 0x%llx, ctlr density is 0x%llx\n", |
| 278 | rank_density, ctlr_density); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 279 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 280 | if (pinfo->memctl_opts[i].memctl_interleaving) { |
| 281 | switch (pinfo->memctl_opts[i].memctl_interleaving_mode) { |
| 282 | case FSL_DDR_CACHE_LINE_INTERLEAVING: |
| 283 | case FSL_DDR_PAGE_INTERLEAVING: |
| 284 | case FSL_DDR_BANK_INTERLEAVING: |
| 285 | case FSL_DDR_SUPERBANK_INTERLEAVING: |
| 286 | total_ctlr_mem = 2 * ctlr_density; |
| 287 | break; |
| 288 | case FSL_DDR_3WAY_1KB_INTERLEAVING: |
| 289 | case FSL_DDR_3WAY_4KB_INTERLEAVING: |
| 290 | case FSL_DDR_3WAY_8KB_INTERLEAVING: |
| 291 | total_ctlr_mem = 3 * ctlr_density; |
| 292 | break; |
| 293 | case FSL_DDR_4WAY_1KB_INTERLEAVING: |
| 294 | case FSL_DDR_4WAY_4KB_INTERLEAVING: |
| 295 | case FSL_DDR_4WAY_8KB_INTERLEAVING: |
| 296 | total_ctlr_mem = 4 * ctlr_density; |
| 297 | break; |
| 298 | default: |
| 299 | panic("Unknown interleaving mode"); |
| 300 | } |
| 301 | pinfo->common_timing_params[i].base_address = |
| 302 | current_mem_base; |
| 303 | pinfo->common_timing_params[i].total_mem = |
| 304 | total_ctlr_mem; |
| 305 | total_mem = current_mem_base + total_ctlr_mem; |
| 306 | debug("ctrl %d base 0x%llx\n", i, current_mem_base); |
| 307 | debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem); |
| 308 | } else { |
| 309 | /* when 3rd controller not interleaved */ |
| 310 | current_mem_base = total_mem; |
| 311 | total_ctlr_mem = 0; |
| 312 | pinfo->common_timing_params[i].base_address = |
| 313 | current_mem_base; |
| 314 | for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) { |
| 315 | unsigned long long cap = |
| 316 | pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i]; |
| 317 | pinfo->dimm_params[i][j].base_address = |
| 318 | current_mem_base; |
| 319 | debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base); |
| 320 | current_mem_base += cap; |
| 321 | total_ctlr_mem += cap; |
| 322 | } |
| 323 | debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem); |
| 324 | pinfo->common_timing_params[i].total_mem = |
| 325 | total_ctlr_mem; |
| 326 | total_mem += total_ctlr_mem; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | } else { |
| 330 | /* |
| 331 | * Simple linear assignment if memory |
| 332 | * controllers are not interleaved. |
| 333 | */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 334 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 335 | total_ctlr_mem = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 336 | pinfo->common_timing_params[i].base_address = |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 337 | current_mem_base; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 338 | for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) { |
| 339 | /* Compute DIMM base addresses. */ |
| 340 | unsigned long long cap = |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 341 | pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i]; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 342 | pinfo->dimm_params[i][j].base_address = |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 343 | current_mem_base; |
| 344 | debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base); |
| 345 | current_mem_base += cap; |
| 346 | total_ctlr_mem += cap; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 347 | } |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 348 | debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 349 | pinfo->common_timing_params[i].total_mem = |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 350 | total_ctlr_mem; |
| 351 | total_mem += total_ctlr_mem; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 352 | } |
| 353 | } |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 354 | debug("Total mem by %s is 0x%llx\n", __func__, total_mem); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 355 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 356 | return total_mem; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 357 | } |
| 358 | |
York Sun | 01a8258 | 2013-03-25 07:39:35 +0000 | [diff] [blame] | 359 | /* Use weak function to allow board file to override the address assignment */ |
| 360 | __attribute__((weak, alias("__step_assign_addresses"))) |
| 361 | unsigned long long step_assign_addresses(fsl_ddr_info_t *pinfo, |
| 362 | unsigned int dbw_cap_adj[]); |
| 363 | |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 364 | unsigned long long |
Haiying Wang | 80ad401 | 2010-12-01 10:35:31 -0500 | [diff] [blame] | 365 | fsl_ddr_compute(fsl_ddr_info_t *pinfo, unsigned int start_step, |
| 366 | unsigned int size_only) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 367 | { |
| 368 | unsigned int i, j; |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 369 | unsigned long long total_mem = 0; |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 370 | int assert_reset; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 371 | |
| 372 | fsl_ddr_cfg_regs_t *ddr_reg = pinfo->fsl_ddr_config_reg; |
| 373 | common_timing_params_t *timing_params = pinfo->common_timing_params; |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 374 | assert_reset = board_need_mem_reset(); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 375 | |
| 376 | /* data bus width capacity adjust shift amount */ |
| 377 | unsigned int dbw_capacity_adjust[CONFIG_NUM_DDR_CONTROLLERS]; |
| 378 | |
| 379 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 380 | dbw_capacity_adjust[i] = 0; |
| 381 | } |
| 382 | |
| 383 | debug("starting at step %u (%s)\n", |
| 384 | start_step, step_to_string(start_step)); |
| 385 | |
| 386 | switch (start_step) { |
| 387 | case STEP_GET_SPD: |
York Sun | e73cc04 | 2011-06-07 09:42:16 +0800 | [diff] [blame] | 388 | #if defined(CONFIG_DDR_SPD) || defined(CONFIG_SPD_EEPROM) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 389 | /* STEP 1: Gather all DIMM SPD data */ |
| 390 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 391 | fsl_ddr_get_spd(pinfo->spd_installed_dimms[i], i); |
| 392 | } |
| 393 | |
| 394 | case STEP_COMPUTE_DIMM_PARMS: |
| 395 | /* STEP 2: Compute DIMM parameters from SPD data */ |
| 396 | |
| 397 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 398 | for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) { |
| 399 | unsigned int retval; |
| 400 | generic_spd_eeprom_t *spd = |
| 401 | &(pinfo->spd_installed_dimms[i][j]); |
| 402 | dimm_params_t *pdimm = |
Wolfgang Denk | 9dbbd7b | 2008-09-13 02:23:05 +0200 | [diff] [blame] | 403 | &(pinfo->dimm_params[i][j]); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 404 | |
| 405 | retval = compute_dimm_parameters(spd, pdimm, i); |
York Sun | 09d8aa8 | 2011-06-07 09:42:17 +0800 | [diff] [blame] | 406 | #ifdef CONFIG_SYS_DDR_RAW_TIMING |
York Sun | 11dd884 | 2012-08-17 08:22:42 +0000 | [diff] [blame] | 407 | if (!i && !j && retval) { |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 408 | printf("SPD error on controller %d! " |
| 409 | "Trying fallback to raw timing " |
| 410 | "calculation\n", i); |
York Sun | 09d8aa8 | 2011-06-07 09:42:17 +0800 | [diff] [blame] | 411 | fsl_ddr_get_dimm_params(pdimm, i, j); |
| 412 | } |
| 413 | #else |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 414 | if (retval == 2) { |
| 415 | printf("Error: compute_dimm_parameters" |
| 416 | " non-zero returned FATAL value " |
| 417 | "for memctl=%u dimm=%u\n", i, j); |
| 418 | return 0; |
| 419 | } |
York Sun | 09d8aa8 | 2011-06-07 09:42:17 +0800 | [diff] [blame] | 420 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 421 | if (retval) { |
| 422 | debug("Warning: compute_dimm_parameters" |
| 423 | " non-zero return value for memctl=%u " |
| 424 | "dimm=%u\n", i, j); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Shaohui Xie | 2400904 | 2012-06-28 23:36:38 +0000 | [diff] [blame] | 429 | #elif defined(CONFIG_SYS_DDR_RAW_TIMING) |
York Sun | e73cc04 | 2011-06-07 09:42:16 +0800 | [diff] [blame] | 430 | case STEP_COMPUTE_DIMM_PARMS: |
| 431 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 432 | for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) { |
| 433 | dimm_params_t *pdimm = |
| 434 | &(pinfo->dimm_params[i][j]); |
| 435 | fsl_ddr_get_dimm_params(pdimm, i, j); |
| 436 | } |
| 437 | } |
| 438 | debug("Filling dimm parameters from board specific file\n"); |
| 439 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 440 | case STEP_COMPUTE_COMMON_PARMS: |
| 441 | /* |
| 442 | * STEP 3: Compute a common set of timing parameters |
| 443 | * suitable for all of the DIMMs on each memory controller |
| 444 | */ |
| 445 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 446 | debug("Computing lowest common DIMM" |
| 447 | " parameters for memctl=%u\n", i); |
| 448 | compute_lowest_common_dimm_parameters( |
| 449 | pinfo->dimm_params[i], |
| 450 | &timing_params[i], |
| 451 | CONFIG_DIMM_SLOTS_PER_CTLR); |
| 452 | } |
| 453 | |
| 454 | case STEP_GATHER_OPTS: |
| 455 | /* STEP 4: Gather configuration requirements from user */ |
| 456 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 457 | debug("Reloading memory controller " |
| 458 | "configuration options for memctl=%u\n", i); |
| 459 | /* |
| 460 | * This "reloads" the memory controller options |
| 461 | * to defaults. If the user "edits" an option, |
| 462 | * next_step points to the step after this, |
| 463 | * which is currently STEP_ASSIGN_ADDRESSES. |
| 464 | */ |
| 465 | populate_memctl_options( |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 466 | timing_params[i].all_dimms_registered, |
Haiying Wang | fa44036 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 467 | &pinfo->memctl_opts[i], |
| 468 | pinfo->dimm_params[i], i); |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 469 | /* |
| 470 | * For RDIMMs, JEDEC spec requires clocks to be stable |
| 471 | * before reset signal is deasserted. For the boards |
| 472 | * using fixed parameters, this function should be |
| 473 | * be called from board init file. |
| 474 | */ |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 475 | if (timing_params[i].all_dimms_registered) |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 476 | assert_reset = 1; |
| 477 | } |
| 478 | if (assert_reset) { |
| 479 | debug("Asserting mem reset\n"); |
| 480 | board_assert_mem_reset(); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 481 | } |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 482 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 483 | case STEP_ASSIGN_ADDRESSES: |
| 484 | /* STEP 5: Assign addresses to chip selects */ |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 485 | check_interleaving_options(pinfo); |
| 486 | total_mem = step_assign_addresses(pinfo, dbw_capacity_adjust); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 487 | |
| 488 | case STEP_COMPUTE_REGS: |
| 489 | /* STEP 6: compute controller register values */ |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 490 | debug("FSL Memory ctrl register computation\n"); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 491 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 492 | if (timing_params[i].ndimms_present == 0) { |
| 493 | memset(&ddr_reg[i], 0, |
| 494 | sizeof(fsl_ddr_cfg_regs_t)); |
| 495 | continue; |
| 496 | } |
| 497 | |
| 498 | compute_fsl_memctl_config_regs( |
| 499 | &pinfo->memctl_opts[i], |
| 500 | &ddr_reg[i], &timing_params[i], |
| 501 | pinfo->dimm_params[i], |
Haiying Wang | 80ad401 | 2010-12-01 10:35:31 -0500 | [diff] [blame] | 502 | dbw_capacity_adjust[i], |
| 503 | size_only); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | default: |
| 507 | break; |
| 508 | } |
| 509 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 510 | { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 511 | /* |
| 512 | * Compute the amount of memory available just by |
| 513 | * looking for the highest valid CSn_BNDS value. |
| 514 | * This allows us to also experiment with using |
| 515 | * only CS0 when using dual-rank DIMMs. |
| 516 | */ |
| 517 | unsigned int max_end = 0; |
| 518 | |
| 519 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 520 | for (j = 0; j < CONFIG_CHIP_SELECTS_PER_CTRL; j++) { |
| 521 | fsl_ddr_cfg_regs_t *reg = &ddr_reg[i]; |
| 522 | if (reg->cs[j].config & 0x80000000) { |
| 523 | unsigned int end; |
York Sun | c21a739 | 2013-06-25 11:37:45 -0700 | [diff] [blame] | 524 | /* |
| 525 | * 0xfffffff is a special value we put |
| 526 | * for unused bnds |
| 527 | */ |
| 528 | if (reg->cs[j].bnds == 0xffffffff) |
| 529 | continue; |
| 530 | end = reg->cs[j].bnds & 0xffff; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 531 | if (end > max_end) { |
| 532 | max_end = end; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
York Sun | 6446f1e | 2013-10-28 16:36:02 -0700 | [diff] [blame^] | 538 | total_mem = 1 + (((unsigned long long)max_end << 24ULL) | |
| 539 | 0xFFFFFFULL) - CONFIG_SYS_DDR_SDRAM_BASE; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | return total_mem; |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * fsl_ddr_sdram() -- this is the main function to be called by |
| 547 | * initdram() in the board file. |
| 548 | * |
| 549 | * It returns amount of memory configured in bytes. |
| 550 | */ |
| 551 | phys_size_t fsl_ddr_sdram(void) |
| 552 | { |
| 553 | unsigned int i; |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 554 | #ifdef CONFIG_PPC |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 555 | unsigned int law_memctl = LAW_TRGT_IF_DDR_1; |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 556 | #endif |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 557 | unsigned long long total_memory; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 558 | fsl_ddr_info_t info; |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 559 | int deassert_reset; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 560 | |
| 561 | /* Reset info structure. */ |
| 562 | memset(&info, 0, sizeof(fsl_ddr_info_t)); |
| 563 | |
| 564 | /* Compute it once normally. */ |
York Sun | bd495cf | 2011-09-16 13:21:35 -0700 | [diff] [blame] | 565 | #ifdef CONFIG_FSL_DDR_INTERACTIVE |
James Yang | 4379438 | 2013-01-07 14:01:03 +0000 | [diff] [blame] | 566 | if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */ |
| 567 | total_memory = fsl_ddr_interactive(&info, 0); |
| 568 | } else if (fsl_ddr_interactive_env_var_exists()) { |
| 569 | total_memory = fsl_ddr_interactive(&info, 1); |
York Sun | 5025a8d | 2013-01-04 08:13:59 +0000 | [diff] [blame] | 570 | } else |
York Sun | bd495cf | 2011-09-16 13:21:35 -0700 | [diff] [blame] | 571 | #endif |
| 572 | total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 0); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 573 | |
York Sun | 016095d | 2012-10-08 07:44:24 +0000 | [diff] [blame] | 574 | /* setup 3-way interleaving before enabling DDRC */ |
York Sun | fcb60e8 | 2013-03-25 07:33:20 +0000 | [diff] [blame] | 575 | if (info.memctl_opts[0].memctl_interleaving) { |
| 576 | switch (info.memctl_opts[0].memctl_interleaving_mode) { |
| 577 | case FSL_DDR_3WAY_1KB_INTERLEAVING: |
| 578 | case FSL_DDR_3WAY_4KB_INTERLEAVING: |
| 579 | case FSL_DDR_3WAY_8KB_INTERLEAVING: |
| 580 | fsl_ddr_set_intl3r( |
| 581 | info.memctl_opts[0].memctl_interleaving_mode); |
| 582 | break; |
| 583 | default: |
| 584 | break; |
| 585 | } |
York Sun | 016095d | 2012-10-08 07:44:24 +0000 | [diff] [blame] | 586 | } |
| 587 | |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 588 | /* |
| 589 | * Program configuration registers. |
| 590 | * JEDEC specs requires clocks to be stable before deasserting reset |
| 591 | * for RDIMMs. Clocks start after chip select is enabled and clock |
| 592 | * control register is set. During step 1, all controllers have their |
| 593 | * registers set but not enabled. Step 2 proceeds after deasserting |
| 594 | * reset through board FPGA or GPIO. |
| 595 | * For non-registered DIMMs, initialization can go through but it is |
| 596 | * also OK to follow the same flow. |
| 597 | */ |
| 598 | deassert_reset = board_need_mem_reset(); |
| 599 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 600 | if (info.common_timing_params[i].all_dimms_registered) |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 601 | deassert_reset = 1; |
| 602 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 603 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 604 | debug("Programming controller %u\n", i); |
| 605 | if (info.common_timing_params[i].ndimms_present == 0) { |
| 606 | debug("No dimms present on controller %u; " |
| 607 | "skipping programming\n", i); |
| 608 | continue; |
| 609 | } |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 610 | /* |
| 611 | * The following call with step = 1 returns before enabling |
| 612 | * the controller. It has to finish with step = 2 later. |
| 613 | */ |
| 614 | fsl_ddr_set_memctl_regs(&(info.fsl_ddr_config_reg[i]), i, |
| 615 | deassert_reset ? 1 : 0); |
| 616 | } |
| 617 | if (deassert_reset) { |
| 618 | /* Use board FPGA or GPIO to deassert reset signal */ |
| 619 | debug("Deasserting mem reset\n"); |
| 620 | board_deassert_mem_reset(); |
| 621 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 622 | /* Call with step = 2 to continue initialization */ |
| 623 | fsl_ddr_set_memctl_regs(&(info.fsl_ddr_config_reg[i]), |
| 624 | i, 2); |
| 625 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 626 | } |
| 627 | |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 628 | #ifdef CONFIG_PPC |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 629 | /* program LAWs */ |
| 630 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 631 | if (info.memctl_opts[i].memctl_interleaving) { |
| 632 | switch (info.memctl_opts[i].memctl_interleaving_mode) { |
| 633 | case FSL_DDR_CACHE_LINE_INTERLEAVING: |
| 634 | case FSL_DDR_PAGE_INTERLEAVING: |
| 635 | case FSL_DDR_BANK_INTERLEAVING: |
| 636 | case FSL_DDR_SUPERBANK_INTERLEAVING: |
| 637 | if (i == 0) { |
| 638 | law_memctl = LAW_TRGT_IF_DDR_INTRLV; |
| 639 | fsl_ddr_set_lawbar(&info.common_timing_params[i], |
| 640 | law_memctl, i); |
| 641 | } else if (i == 2) { |
| 642 | law_memctl = LAW_TRGT_IF_DDR_INTLV_34; |
| 643 | fsl_ddr_set_lawbar(&info.common_timing_params[i], |
| 644 | law_memctl, i); |
| 645 | } |
| 646 | break; |
| 647 | case FSL_DDR_3WAY_1KB_INTERLEAVING: |
| 648 | case FSL_DDR_3WAY_4KB_INTERLEAVING: |
| 649 | case FSL_DDR_3WAY_8KB_INTERLEAVING: |
| 650 | law_memctl = LAW_TRGT_IF_DDR_INTLV_123; |
| 651 | if (i == 0) { |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 652 | fsl_ddr_set_lawbar(&info.common_timing_params[i], |
| 653 | law_memctl, i); |
| 654 | } |
| 655 | break; |
| 656 | case FSL_DDR_4WAY_1KB_INTERLEAVING: |
| 657 | case FSL_DDR_4WAY_4KB_INTERLEAVING: |
| 658 | case FSL_DDR_4WAY_8KB_INTERLEAVING: |
| 659 | law_memctl = LAW_TRGT_IF_DDR_INTLV_1234; |
| 660 | if (i == 0) |
| 661 | fsl_ddr_set_lawbar(&info.common_timing_params[i], |
| 662 | law_memctl, i); |
| 663 | /* place holder for future 4-way interleaving */ |
| 664 | break; |
| 665 | default: |
| 666 | break; |
| 667 | } |
| 668 | } else { |
| 669 | switch (i) { |
| 670 | case 0: |
| 671 | law_memctl = LAW_TRGT_IF_DDR_1; |
| 672 | break; |
| 673 | case 1: |
| 674 | law_memctl = LAW_TRGT_IF_DDR_2; |
| 675 | break; |
| 676 | case 2: |
| 677 | law_memctl = LAW_TRGT_IF_DDR_3; |
| 678 | break; |
| 679 | case 3: |
| 680 | law_memctl = LAW_TRGT_IF_DDR_4; |
| 681 | break; |
| 682 | default: |
| 683 | break; |
| 684 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 685 | fsl_ddr_set_lawbar(&info.common_timing_params[i], |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 686 | law_memctl, i); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 687 | } |
| 688 | } |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 689 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 690 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 691 | debug("total_memory by %s = %llu\n", __func__, total_memory); |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 692 | |
| 693 | #if !defined(CONFIG_PHYS_64BIT) |
| 694 | /* Check for 4G or more. Bad. */ |
| 695 | if (total_memory >= (1ull << 32)) { |
Shruti Kanetkar | 3adfb91 | 2013-08-15 11:25:37 -0500 | [diff] [blame] | 696 | puts("Detected "); |
| 697 | print_size(total_memory, " of memory\n"); |
Becky Bruce | 2d8ecac | 2010-12-17 17:17:59 -0600 | [diff] [blame] | 698 | printf(" This U-Boot only supports < 4G of DDR\n"); |
| 699 | printf(" You could rebuild it with CONFIG_PHYS_64BIT\n"); |
| 700 | printf(" "); /* re-align to match init_func_ram print */ |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 701 | total_memory = CONFIG_MAX_MEM_MAPPED; |
| 702 | } |
| 703 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 704 | |
| 705 | return total_memory; |
| 706 | } |
Haiying Wang | 80ad401 | 2010-12-01 10:35:31 -0500 | [diff] [blame] | 707 | |
| 708 | /* |
| 709 | * fsl_ddr_sdram_size() - This function only returns the size of the total |
| 710 | * memory without setting ddr control registers. |
| 711 | */ |
| 712 | phys_size_t |
| 713 | fsl_ddr_sdram_size(void) |
| 714 | { |
| 715 | fsl_ddr_info_t info; |
| 716 | unsigned long long total_memory = 0; |
| 717 | |
| 718 | memset(&info, 0 , sizeof(fsl_ddr_info_t)); |
| 719 | |
| 720 | /* Compute it once normally. */ |
| 721 | total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 1); |
| 722 | |
| 723 | return total_memory; |
| 724 | } |