Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 2 | * Copyright 2008, 2010-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 3 | * |
Dave Liu | 22c9de0 | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the Free |
| 6 | * Software Foundation; either version 2 of the License, or (at your option) |
| 7 | * any later version. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Kumar Gala | 79e4e64 | 2010-07-14 10:04:21 -0500 | [diff] [blame] | 11 | #include <hwconfig.h> |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 12 | #include <asm/fsl_ddr_sdram.h> |
| 13 | |
| 14 | #include "ddr.h" |
| 15 | |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 16 | /* |
| 17 | * Use our own stack based buffer before relocation to allow accessing longer |
| 18 | * hwconfig strings that might be in the environment before we've relocated. |
| 19 | * This is pretty fragile on both the use of stack and if the buffer is big |
| 20 | * enough. However we will get a warning from getenv_f for the later. |
| 21 | */ |
| 22 | #define HWCONFIG_BUFFER_SIZE 128 |
| 23 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 24 | /* Board-specific functions defined in each board's ddr.c */ |
| 25 | extern void fsl_ddr_board_options(memctl_options_t *popts, |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 26 | dimm_params_t *pdimm, |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 27 | unsigned int ctrl_num); |
| 28 | |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 29 | typedef struct { |
| 30 | unsigned int odt_rd_cfg; |
| 31 | unsigned int odt_wr_cfg; |
| 32 | unsigned int odt_rtt_norm; |
| 33 | unsigned int odt_rtt_wr; |
| 34 | } dynamic_odt_t; |
| 35 | |
| 36 | static const dynamic_odt_t single_Q[4] = { |
| 37 | { /* cs0 */ |
| 38 | FSL_DDR_ODT_NEVER, |
| 39 | FSL_DDR_ODT_CS_AND_OTHER_DIMM, |
| 40 | DDR3_RTT_20_OHM, |
| 41 | DDR3_RTT_120_OHM |
| 42 | }, |
| 43 | { /* cs1 */ |
| 44 | FSL_DDR_ODT_NEVER, |
| 45 | FSL_DDR_ODT_NEVER, /* tied high */ |
| 46 | DDR3_RTT_OFF, |
| 47 | DDR3_RTT_120_OHM |
| 48 | }, |
| 49 | { /* cs2 */ |
| 50 | FSL_DDR_ODT_NEVER, |
| 51 | FSL_DDR_ODT_CS_AND_OTHER_DIMM, |
| 52 | DDR3_RTT_20_OHM, |
| 53 | DDR3_RTT_120_OHM |
| 54 | }, |
| 55 | { /* cs3 */ |
| 56 | FSL_DDR_ODT_NEVER, |
| 57 | FSL_DDR_ODT_NEVER, /* tied high */ |
| 58 | DDR3_RTT_OFF, |
| 59 | DDR3_RTT_120_OHM |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | static const dynamic_odt_t single_D[4] = { |
| 64 | { /* cs0 */ |
| 65 | FSL_DDR_ODT_NEVER, |
| 66 | FSL_DDR_ODT_ALL, |
| 67 | DDR3_RTT_40_OHM, |
| 68 | DDR3_RTT_OFF |
| 69 | }, |
| 70 | { /* cs1 */ |
| 71 | FSL_DDR_ODT_NEVER, |
| 72 | FSL_DDR_ODT_NEVER, |
| 73 | DDR3_RTT_OFF, |
| 74 | DDR3_RTT_OFF |
| 75 | }, |
| 76 | {0, 0, 0, 0}, |
| 77 | {0, 0, 0, 0} |
| 78 | }; |
| 79 | |
| 80 | static const dynamic_odt_t single_S[4] = { |
| 81 | { /* cs0 */ |
| 82 | FSL_DDR_ODT_NEVER, |
| 83 | FSL_DDR_ODT_ALL, |
| 84 | DDR3_RTT_40_OHM, |
| 85 | DDR3_RTT_OFF |
| 86 | }, |
| 87 | {0, 0, 0, 0}, |
| 88 | {0, 0, 0, 0}, |
| 89 | {0, 0, 0, 0}, |
| 90 | }; |
| 91 | |
| 92 | static const dynamic_odt_t dual_DD[4] = { |
| 93 | { /* cs0 */ |
| 94 | FSL_DDR_ODT_NEVER, |
| 95 | FSL_DDR_ODT_SAME_DIMM, |
| 96 | DDR3_RTT_120_OHM, |
| 97 | DDR3_RTT_OFF |
| 98 | }, |
| 99 | { /* cs1 */ |
| 100 | FSL_DDR_ODT_OTHER_DIMM, |
| 101 | FSL_DDR_ODT_OTHER_DIMM, |
| 102 | DDR3_RTT_30_OHM, |
| 103 | DDR3_RTT_OFF |
| 104 | }, |
| 105 | { /* cs2 */ |
| 106 | FSL_DDR_ODT_NEVER, |
| 107 | FSL_DDR_ODT_SAME_DIMM, |
| 108 | DDR3_RTT_120_OHM, |
| 109 | DDR3_RTT_OFF |
| 110 | }, |
| 111 | { /* cs3 */ |
| 112 | FSL_DDR_ODT_OTHER_DIMM, |
| 113 | FSL_DDR_ODT_OTHER_DIMM, |
| 114 | DDR3_RTT_30_OHM, |
| 115 | DDR3_RTT_OFF |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | static const dynamic_odt_t dual_DS[4] = { |
| 120 | { /* cs0 */ |
| 121 | FSL_DDR_ODT_NEVER, |
| 122 | FSL_DDR_ODT_SAME_DIMM, |
| 123 | DDR3_RTT_120_OHM, |
| 124 | DDR3_RTT_OFF |
| 125 | }, |
| 126 | { /* cs1 */ |
| 127 | FSL_DDR_ODT_OTHER_DIMM, |
| 128 | FSL_DDR_ODT_OTHER_DIMM, |
| 129 | DDR3_RTT_30_OHM, |
| 130 | DDR3_RTT_OFF |
| 131 | }, |
| 132 | { /* cs2 */ |
| 133 | FSL_DDR_ODT_OTHER_DIMM, |
| 134 | FSL_DDR_ODT_ALL, |
| 135 | DDR3_RTT_20_OHM, |
| 136 | DDR3_RTT_120_OHM |
| 137 | }, |
| 138 | {0, 0, 0, 0} |
| 139 | }; |
| 140 | static const dynamic_odt_t dual_SD[4] = { |
| 141 | { /* cs0 */ |
| 142 | FSL_DDR_ODT_OTHER_DIMM, |
| 143 | FSL_DDR_ODT_ALL, |
| 144 | DDR3_RTT_20_OHM, |
| 145 | DDR3_RTT_120_OHM |
| 146 | }, |
| 147 | {0, 0, 0, 0}, |
| 148 | { /* cs2 */ |
| 149 | FSL_DDR_ODT_NEVER, |
| 150 | FSL_DDR_ODT_SAME_DIMM, |
| 151 | DDR3_RTT_120_OHM, |
| 152 | DDR3_RTT_OFF |
| 153 | }, |
| 154 | { /* cs3 */ |
| 155 | FSL_DDR_ODT_OTHER_DIMM, |
| 156 | FSL_DDR_ODT_OTHER_DIMM, |
| 157 | DDR3_RTT_20_OHM, |
| 158 | DDR3_RTT_OFF |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | static const dynamic_odt_t dual_SS[4] = { |
| 163 | { /* cs0 */ |
| 164 | FSL_DDR_ODT_OTHER_DIMM, |
| 165 | FSL_DDR_ODT_ALL, |
| 166 | DDR3_RTT_30_OHM, |
| 167 | DDR3_RTT_120_OHM |
| 168 | }, |
| 169 | {0, 0, 0, 0}, |
| 170 | { /* cs2 */ |
| 171 | FSL_DDR_ODT_OTHER_DIMM, |
| 172 | FSL_DDR_ODT_ALL, |
| 173 | DDR3_RTT_30_OHM, |
| 174 | DDR3_RTT_120_OHM |
| 175 | }, |
| 176 | {0, 0, 0, 0} |
| 177 | }; |
| 178 | |
| 179 | static const dynamic_odt_t dual_D0[4] = { |
| 180 | { /* cs0 */ |
| 181 | FSL_DDR_ODT_NEVER, |
| 182 | FSL_DDR_ODT_SAME_DIMM, |
| 183 | DDR3_RTT_40_OHM, |
| 184 | DDR3_RTT_OFF |
| 185 | }, |
| 186 | { /* cs1 */ |
| 187 | FSL_DDR_ODT_NEVER, |
| 188 | FSL_DDR_ODT_NEVER, |
| 189 | DDR3_RTT_OFF, |
| 190 | DDR3_RTT_OFF |
| 191 | }, |
| 192 | {0, 0, 0, 0}, |
| 193 | {0, 0, 0, 0} |
| 194 | }; |
| 195 | |
| 196 | static const dynamic_odt_t dual_0D[4] = { |
| 197 | {0, 0, 0, 0}, |
| 198 | {0, 0, 0, 0}, |
| 199 | { /* cs2 */ |
| 200 | FSL_DDR_ODT_NEVER, |
| 201 | FSL_DDR_ODT_SAME_DIMM, |
| 202 | DDR3_RTT_40_OHM, |
| 203 | DDR3_RTT_OFF |
| 204 | }, |
| 205 | { /* cs3 */ |
| 206 | FSL_DDR_ODT_NEVER, |
| 207 | FSL_DDR_ODT_NEVER, |
| 208 | DDR3_RTT_OFF, |
| 209 | DDR3_RTT_OFF |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | static const dynamic_odt_t dual_S0[4] = { |
| 214 | { /* cs0 */ |
| 215 | FSL_DDR_ODT_NEVER, |
| 216 | FSL_DDR_ODT_CS, |
| 217 | DDR3_RTT_40_OHM, |
| 218 | DDR3_RTT_OFF |
| 219 | }, |
| 220 | {0, 0, 0, 0}, |
| 221 | {0, 0, 0, 0}, |
| 222 | {0, 0, 0, 0} |
| 223 | |
| 224 | }; |
| 225 | |
| 226 | static const dynamic_odt_t dual_0S[4] = { |
| 227 | {0, 0, 0, 0}, |
| 228 | {0, 0, 0, 0}, |
| 229 | { /* cs2 */ |
| 230 | FSL_DDR_ODT_NEVER, |
| 231 | FSL_DDR_ODT_CS, |
| 232 | DDR3_RTT_40_OHM, |
| 233 | DDR3_RTT_OFF |
| 234 | }, |
| 235 | {0, 0, 0, 0} |
| 236 | |
| 237 | }; |
| 238 | |
| 239 | static const dynamic_odt_t odt_unknown[4] = { |
| 240 | { /* cs0 */ |
| 241 | FSL_DDR_ODT_NEVER, |
| 242 | FSL_DDR_ODT_CS, |
| 243 | DDR3_RTT_120_OHM, |
| 244 | DDR3_RTT_OFF |
| 245 | }, |
| 246 | { /* cs1 */ |
| 247 | FSL_DDR_ODT_NEVER, |
| 248 | FSL_DDR_ODT_CS, |
| 249 | DDR3_RTT_120_OHM, |
| 250 | DDR3_RTT_OFF |
| 251 | }, |
| 252 | { /* cs2 */ |
| 253 | FSL_DDR_ODT_NEVER, |
| 254 | FSL_DDR_ODT_CS, |
| 255 | DDR3_RTT_120_OHM, |
| 256 | DDR3_RTT_OFF |
| 257 | }, |
| 258 | { /* cs3 */ |
| 259 | FSL_DDR_ODT_NEVER, |
| 260 | FSL_DDR_ODT_CS, |
| 261 | DDR3_RTT_120_OHM, |
| 262 | DDR3_RTT_OFF |
| 263 | } |
| 264 | }; |
| 265 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 266 | unsigned int populate_memctl_options(int all_DIMMs_registered, |
| 267 | memctl_options_t *popts, |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 268 | dimm_params_t *pdimm, |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 269 | unsigned int ctrl_num) |
| 270 | { |
| 271 | unsigned int i; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 272 | char buffer[HWCONFIG_BUFFER_SIZE]; |
| 273 | char *buf = NULL; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 274 | const dynamic_odt_t *pdodt = odt_unknown; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * Extract hwconfig from environment since we have not properly setup |
| 278 | * the environment but need it for ddr config params |
| 279 | */ |
| 280 | if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0) |
| 281 | buf = buffer; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 282 | |
| 283 | /* Chip select options. */ |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 284 | if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) { |
| 285 | switch (pdimm[0].n_ranks) { |
| 286 | case 1: |
| 287 | pdodt = single_S; |
| 288 | break; |
| 289 | case 2: |
| 290 | pdodt = single_D; |
| 291 | break; |
| 292 | case 4: |
| 293 | pdodt = single_Q; |
| 294 | break; |
| 295 | } |
| 296 | } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) { |
| 297 | switch (pdimm[0].n_ranks) { |
| 298 | case 2: |
| 299 | switch (pdimm[1].n_ranks) { |
| 300 | case 2: |
| 301 | pdodt = dual_DD; |
| 302 | break; |
| 303 | case 1: |
| 304 | pdodt = dual_DS; |
| 305 | break; |
| 306 | case 0: |
| 307 | pdodt = dual_D0; |
| 308 | break; |
| 309 | } |
| 310 | break; |
| 311 | case 1: |
| 312 | switch (pdimm[1].n_ranks) { |
| 313 | case 2: |
| 314 | pdodt = dual_SD; |
| 315 | break; |
| 316 | case 1: |
| 317 | pdodt = dual_SS; |
| 318 | break; |
| 319 | case 0: |
| 320 | pdodt = dual_S0; |
| 321 | break; |
| 322 | } |
| 323 | break; |
| 324 | case 0: |
| 325 | switch (pdimm[1].n_ranks) { |
| 326 | case 2: |
| 327 | pdodt = dual_0D; |
| 328 | break; |
| 329 | case 1: |
| 330 | pdodt = dual_0S; |
| 331 | break; |
| 332 | } |
| 333 | break; |
| 334 | } |
| 335 | } |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 336 | |
| 337 | /* Pick chip-select local options. */ |
| 338 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 339 | #if defined(CONFIG_FSL_DDR3) |
| 340 | popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg; |
| 341 | popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg; |
| 342 | popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm; |
| 343 | popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr; |
| 344 | #else |
| 345 | popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER; |
| 346 | popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS; |
| 347 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 348 | popts->cs_local_opts[i].auto_precharge = 0; |
| 349 | } |
| 350 | |
| 351 | /* Pick interleaving mode. */ |
| 352 | |
| 353 | /* |
| 354 | * 0 = no interleaving |
| 355 | * 1 = interleaving between 2 controllers |
| 356 | */ |
| 357 | popts->memctl_interleaving = 0; |
| 358 | |
| 359 | /* |
| 360 | * 0 = cacheline |
| 361 | * 1 = page |
| 362 | * 2 = (logical) bank |
| 363 | * 3 = superbank (only if CS interleaving is enabled) |
| 364 | */ |
| 365 | popts->memctl_interleaving_mode = 0; |
| 366 | |
| 367 | /* |
| 368 | * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl |
| 369 | * 1: page: bit to the left of the column bits selects the memctl |
| 370 | * 2: bank: bit to the left of the bank bits selects the memctl |
| 371 | * 3: superbank: bit to the left of the chip select selects the memctl |
| 372 | * |
| 373 | * NOTE: ba_intlv (rank interleaving) is independent of memory |
| 374 | * controller interleaving; it is only within a memory controller. |
| 375 | * Must use superbank interleaving if rank interleaving is used and |
| 376 | * memory controller interleaving is enabled. |
| 377 | */ |
| 378 | |
| 379 | /* |
| 380 | * 0 = no |
| 381 | * 0x40 = CS0,CS1 |
| 382 | * 0x20 = CS2,CS3 |
| 383 | * 0x60 = CS0,CS1 + CS2,CS3 |
| 384 | * 0x04 = CS0,CS1,CS2,CS3 |
| 385 | */ |
| 386 | popts->ba_intlv_ctl = 0; |
| 387 | |
| 388 | /* Memory Organization Parameters */ |
| 389 | popts->registered_dimm_en = all_DIMMs_registered; |
| 390 | |
| 391 | /* Operational Mode Paramters */ |
| 392 | |
| 393 | /* Pick ECC modes */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 394 | popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */ |
York Sun | 47df8f0 | 2011-01-10 12:02:57 +0000 | [diff] [blame] | 395 | #ifdef CONFIG_DDR_ECC |
| 396 | if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) { |
| 397 | if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf)) |
| 398 | popts->ECC_mode = 1; |
| 399 | } else |
| 400 | popts->ECC_mode = 1; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 401 | #endif |
| 402 | popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */ |
| 403 | |
| 404 | /* |
| 405 | * Choose DQS config |
| 406 | * 0 for DDR1 |
| 407 | * 1 for DDR2 |
| 408 | */ |
| 409 | #if defined(CONFIG_FSL_DDR1) |
| 410 | popts->DQS_config = 0; |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 411 | #elif defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3) |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 412 | popts->DQS_config = 1; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 413 | #endif |
| 414 | |
| 415 | /* Choose self-refresh during sleep. */ |
| 416 | popts->self_refresh_in_sleep = 1; |
| 417 | |
| 418 | /* Choose dynamic power management mode. */ |
| 419 | popts->dynamic_power = 0; |
| 420 | |
| 421 | /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */ |
| 422 | popts->data_bus_width = 0; |
| 423 | |
| 424 | /* Choose burst length. */ |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 425 | #if defined(CONFIG_FSL_DDR3) |
Dave Liu | 22c9de0 | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 426 | #if defined(CONFIG_E500MC) |
| 427 | popts->OTF_burst_chop_en = 0; /* on-the-fly burst chop disable */ |
| 428 | popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */ |
| 429 | #else |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 430 | popts->OTF_burst_chop_en = 1; /* on-the-fly burst chop */ |
| 431 | popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */ |
Dave Liu | 22c9de0 | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 432 | #endif |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 433 | #else |
| 434 | popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */ |
| 435 | #endif |
| 436 | |
| 437 | /* Choose ddr controller address mirror mode */ |
| 438 | #if defined(CONFIG_FSL_DDR3) |
| 439 | popts->mirrored_dimm = pdimm[0].mirrored_dimm; |
| 440 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 441 | |
| 442 | /* Global Timing Parameters. */ |
| 443 | debug("mclk_ps = %u ps\n", get_memory_clk_period_ps()); |
| 444 | |
| 445 | /* Pick a caslat override. */ |
| 446 | popts->cas_latency_override = 0; |
| 447 | popts->cas_latency_override_value = 3; |
| 448 | if (popts->cas_latency_override) { |
| 449 | debug("using caslat override value = %u\n", |
| 450 | popts->cas_latency_override_value); |
| 451 | } |
| 452 | |
| 453 | /* Decide whether to use the computed derated latency */ |
| 454 | popts->use_derated_caslat = 0; |
| 455 | |
| 456 | /* Choose an additive latency. */ |
| 457 | popts->additive_latency_override = 0; |
| 458 | popts->additive_latency_override_value = 3; |
| 459 | if (popts->additive_latency_override) { |
| 460 | debug("using additive latency override value = %u\n", |
| 461 | popts->additive_latency_override_value); |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * 2T_EN setting |
| 466 | * |
| 467 | * Factors to consider for 2T_EN: |
| 468 | * - number of DIMMs installed |
| 469 | * - number of components, number of active ranks |
| 470 | * - how much time you want to spend playing around |
| 471 | */ |
Dave Liu | b4983e1 | 2008-11-21 16:31:43 +0800 | [diff] [blame] | 472 | popts->twoT_en = 0; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 473 | popts->threeT_en = 0; |
| 474 | |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 475 | /* for RDIMM, address parity enable */ |
| 476 | popts->ap_en = 1; |
| 477 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 478 | /* |
| 479 | * BSTTOPRE precharge interval |
| 480 | * |
| 481 | * Set this to 0 for global auto precharge |
| 482 | * |
| 483 | * FIXME: Should this be configured in picoseconds? |
| 484 | * Why it should be in ps: better understanding of this |
| 485 | * relative to actual DRAM timing parameters such as tRAS. |
| 486 | * e.g. tRAS(min) = 40 ns |
| 487 | */ |
| 488 | popts->bstopre = 0x100; |
| 489 | |
| 490 | /* Minimum CKE pulse width -- tCKE(MIN) */ |
| 491 | popts->tCKE_clock_pulse_width_ps |
| 492 | = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR); |
| 493 | |
| 494 | /* |
| 495 | * Window for four activates -- tFAW |
| 496 | * |
| 497 | * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only |
| 498 | * FIXME: varies depending upon number of column addresses or data |
| 499 | * FIXME: width, was considering looking at pdimm->primary_sdram_width |
| 500 | */ |
| 501 | #if defined(CONFIG_FSL_DDR1) |
| 502 | popts->tFAW_window_four_activates_ps = mclk_to_picos(1); |
| 503 | |
| 504 | #elif defined(CONFIG_FSL_DDR2) |
| 505 | /* |
| 506 | * x4/x8; some datasheets have 35000 |
| 507 | * x16 wide columns only? Use 50000? |
| 508 | */ |
| 509 | popts->tFAW_window_four_activates_ps = 37500; |
| 510 | |
| 511 | #elif defined(CONFIG_FSL_DDR3) |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 512 | popts->tFAW_window_four_activates_ps = pdimm[0].tFAW_ps; |
| 513 | #endif |
| 514 | popts->zq_en = 0; |
| 515 | popts->wrlvl_en = 0; |
| 516 | #if defined(CONFIG_FSL_DDR3) |
| 517 | /* |
| 518 | * due to ddr3 dimm is fly-by topology |
| 519 | * we suggest to enable write leveling to |
| 520 | * meet the tQDSS under different loading. |
| 521 | */ |
| 522 | popts->wrlvl_en = 1; |
york | 5fb8a8a | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 523 | popts->zq_en = 1; |
Dave Liu | bdc9f7b | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 524 | popts->wrlvl_override = 0; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 525 | #endif |
| 526 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 527 | /* |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 528 | * Check interleaving configuration from environment. |
| 529 | * Please refer to doc/README.fsl-ddr for the detail. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 530 | * |
| 531 | * If memory controller interleaving is enabled, then the data |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 532 | * bus widths must be programmed identically for all memory controllers. |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 533 | * |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 534 | * XXX: Attempt to set all controllers to the same chip select |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 535 | * interleaving mode. It will do a best effort to get the |
| 536 | * requested ranks interleaved together such that the result |
| 537 | * should be a subset of the requested configuration. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 538 | */ |
Kumar Gala | 1542fbd | 2009-02-06 09:56:34 -0600 | [diff] [blame] | 539 | #if (CONFIG_NUM_DDR_CONTROLLERS > 1) |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 540 | if (hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf)) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 541 | if (pdimm[0].n_ranks == 0) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 542 | printf("There is no rank on CS0 for controller %d. Because only" |
| 543 | " rank on CS0 and ranks chip-select interleaved with CS0" |
Ed Swarthout | 7008d26 | 2008-10-29 09:21:44 -0500 | [diff] [blame] | 544 | " are controller interleaved, force non memory " |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 545 | "controller interleaving\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 546 | popts->memctl_interleaving = 0; |
| 547 | } else { |
| 548 | popts->memctl_interleaving = 1; |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 549 | /* |
| 550 | * test null first. if CONFIG_HWCONFIG is not defined |
| 551 | * hwconfig_arg_cmp returns non-zero |
| 552 | */ |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 553 | if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv", |
| 554 | "null", buf)) { |
Kumar Gala | 79e4e64 | 2010-07-14 10:04:21 -0500 | [diff] [blame] | 555 | popts->memctl_interleaving = 0; |
| 556 | debug("memory controller interleaving disabled.\n"); |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 557 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 558 | "ctlr_intlv", |
| 559 | "cacheline", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 560 | popts->memctl_interleaving_mode = |
| 561 | FSL_DDR_CACHE_LINE_INTERLEAVING; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 562 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv", |
| 563 | "page", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 564 | popts->memctl_interleaving_mode = |
| 565 | FSL_DDR_PAGE_INTERLEAVING; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 566 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv", |
| 567 | "bank", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 568 | popts->memctl_interleaving_mode = |
| 569 | FSL_DDR_BANK_INTERLEAVING; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 570 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv", |
| 571 | "superbank", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 572 | popts->memctl_interleaving_mode = |
| 573 | FSL_DDR_SUPERBANK_INTERLEAVING; |
Kumar Gala | 79e4e64 | 2010-07-14 10:04:21 -0500 | [diff] [blame] | 574 | else { |
| 575 | popts->memctl_interleaving = 0; |
| 576 | printf("hwconfig has unrecognized parameter for ctlr_intlv.\n"); |
| 577 | } |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 578 | } |
| 579 | } |
Dave Liu | 3ad95de | 2009-11-12 07:26:37 +0800 | [diff] [blame] | 580 | #endif |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 581 | if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) && |
Dave Liu | 3ad95de | 2009-11-12 07:26:37 +0800 | [diff] [blame] | 582 | (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) { |
Kumar Gala | 79e4e64 | 2010-07-14 10:04:21 -0500 | [diff] [blame] | 583 | /* test null first. if CONFIG_HWCONFIG is not defined, |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 584 | * hwconfig_subarg_cmp_f returns non-zero */ |
| 585 | if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 586 | "null", buf)) |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 587 | debug("bank interleaving disabled.\n"); |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 588 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 589 | "cs0_cs1", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 590 | popts->ba_intlv_ctl = FSL_DDR_CS0_CS1; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 591 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 592 | "cs2_cs3", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 593 | popts->ba_intlv_ctl = FSL_DDR_CS2_CS3; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 594 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 595 | "cs0_cs1_and_cs2_cs3", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 596 | popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 597 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 598 | "cs0_cs1_cs2_cs3", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 599 | popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3; |
| 600 | else |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 601 | printf("hwconfig has unrecognized parameter for bank_intlv.\n"); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 602 | switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) { |
| 603 | case FSL_DDR_CS0_CS1_CS2_CS3: |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 604 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 605 | if (pdimm[0].n_ranks < 4) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 606 | popts->ba_intlv_ctl = 0; |
| 607 | printf("Not enough bank(chip-select) for " |
| 608 | "CS0+CS1+CS2+CS3 on controller %d, " |
| 609 | "force non-interleaving!\n", ctrl_num); |
| 610 | } |
| 611 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 612 | if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 613 | popts->ba_intlv_ctl = 0; |
| 614 | printf("Not enough bank(chip-select) for " |
| 615 | "CS0+CS1+CS2+CS3 on controller %d, " |
| 616 | "force non-interleaving!\n", ctrl_num); |
| 617 | } |
| 618 | if (pdimm[0].capacity != pdimm[1].capacity) { |
| 619 | popts->ba_intlv_ctl = 0; |
| 620 | printf("Not identical DIMM size for " |
| 621 | "CS0+CS1+CS2+CS3 on controller %d, " |
| 622 | "force non-interleaving!\n", ctrl_num); |
| 623 | } |
| 624 | #endif |
| 625 | break; |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 626 | case FSL_DDR_CS0_CS1: |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 627 | if (pdimm[0].n_ranks < 2) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 628 | popts->ba_intlv_ctl = 0; |
Ed Swarthout | 7008d26 | 2008-10-29 09:21:44 -0500 | [diff] [blame] | 629 | printf("Not enough bank(chip-select) for " |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 630 | "CS0+CS1 on controller %d, " |
| 631 | "force non-interleaving!\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 632 | } |
| 633 | break; |
| 634 | case FSL_DDR_CS2_CS3: |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 635 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 636 | if (pdimm[0].n_ranks < 4) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 637 | popts->ba_intlv_ctl = 0; |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 638 | printf("Not enough bank(chip-select) for CS2+CS3 " |
| 639 | "on controller %d, force non-interleaving!\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 640 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 641 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 642 | if (pdimm[1].n_ranks < 2) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 643 | popts->ba_intlv_ctl = 0; |
| 644 | printf("Not enough bank(chip-select) for CS2+CS3 " |
| 645 | "on controller %d, force non-interleaving!\n", ctrl_num); |
| 646 | } |
| 647 | #endif |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 648 | break; |
| 649 | case FSL_DDR_CS0_CS1_AND_CS2_CS3: |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 650 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 651 | if (pdimm[0].n_ranks < 4) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 652 | popts->ba_intlv_ctl = 0; |
| 653 | printf("Not enough bank(CS) for CS0+CS1 and " |
| 654 | "CS2+CS3 on controller %d, " |
| 655 | "force non-interleaving!\n", ctrl_num); |
| 656 | } |
| 657 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 658 | if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 659 | popts->ba_intlv_ctl = 0; |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 660 | printf("Not enough bank(CS) for CS0+CS1 and " |
| 661 | "CS2+CS3 on controller %d, " |
| 662 | "force non-interleaving!\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 663 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 664 | #endif |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 665 | break; |
| 666 | default: |
| 667 | popts->ba_intlv_ctl = 0; |
| 668 | break; |
| 669 | } |
| 670 | } |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 671 | |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 672 | if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) { |
| 673 | if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf)) |
york | 7fd101c | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 674 | popts->addr_hash = 0; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 675 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", |
| 676 | "true", buf)) |
york | 7fd101c | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 677 | popts->addr_hash = 1; |
| 678 | } |
| 679 | |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 680 | if (pdimm[0].n_ranks == 4) |
| 681 | popts->quad_rank_present = 1; |
| 682 | |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 683 | fsl_ddr_board_options(popts, pdimm, ctrl_num); |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 684 | |
| 685 | return 0; |
| 686 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 687 | |
| 688 | void check_interleaving_options(fsl_ddr_info_t *pinfo) |
| 689 | { |
| 690 | int i, j, check_n_ranks, intlv_fixed = 0; |
| 691 | unsigned long long check_rank_density; |
| 692 | /* |
| 693 | * Check if all controllers are configured for memory |
| 694 | * controller interleaving. Identical dimms are recommended. At least |
| 695 | * the size should be checked. |
| 696 | */ |
| 697 | j = 0; |
| 698 | check_n_ranks = pinfo->dimm_params[0][0].n_ranks; |
| 699 | check_rank_density = pinfo->dimm_params[0][0].rank_density; |
| 700 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) { |
| 701 | if ((pinfo->memctl_opts[i].memctl_interleaving) && \ |
| 702 | (check_rank_density == pinfo->dimm_params[i][0].rank_density) && \ |
| 703 | (check_n_ranks == pinfo->dimm_params[i][0].n_ranks)) { |
| 704 | j++; |
| 705 | } |
| 706 | } |
| 707 | if (j != CONFIG_NUM_DDR_CONTROLLERS) { |
| 708 | for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) |
| 709 | if (pinfo->memctl_opts[i].memctl_interleaving) { |
| 710 | pinfo->memctl_opts[i].memctl_interleaving = 0; |
| 711 | intlv_fixed = 1; |
| 712 | } |
| 713 | if (intlv_fixed) |
| 714 | printf("Not all DIMMs are identical in size. " |
| 715 | "Memory controller interleaving disabled.\n"); |
| 716 | } |
| 717 | } |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 718 | |
| 719 | int fsl_use_spd(void) |
| 720 | { |
| 721 | int use_spd = 0; |
| 722 | |
| 723 | #ifdef CONFIG_DDR_SPD |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 724 | char buffer[HWCONFIG_BUFFER_SIZE]; |
| 725 | char *buf = NULL; |
| 726 | |
| 727 | /* |
| 728 | * Extract hwconfig from environment since we have not properly setup |
| 729 | * the environment but need it for ddr config params |
| 730 | */ |
| 731 | if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0) |
| 732 | buf = buffer; |
| 733 | |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 734 | /* if hwconfig is not enabled, or "sdram" is not defined, use spd */ |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 735 | if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) { |
| 736 | if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf)) |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 737 | use_spd = 1; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 738 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", |
| 739 | "fixed", buf)) |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 740 | use_spd = 0; |
| 741 | else |
| 742 | use_spd = 1; |
| 743 | } else |
| 744 | use_spd = 1; |
| 745 | #endif |
| 746 | |
| 747 | return use_spd; |
| 748 | } |