Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 2 | * Copyright 2008, 2010-2014 Freescale Semiconductor, Inc. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Kumar Gala | 79e4e64 | 2010-07-14 10:04:21 -0500 | [diff] [blame] | 8 | #include <hwconfig.h> |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 9 | #include <fsl_ddr_sdram.h> |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 10 | |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 11 | #include <fsl_ddr.h> |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 12 | |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 13 | /* |
| 14 | * Use our own stack based buffer before relocation to allow accessing longer |
| 15 | * hwconfig strings that might be in the environment before we've relocated. |
| 16 | * This is pretty fragile on both the use of stack and if the buffer is big |
| 17 | * enough. However we will get a warning from getenv_f for the later. |
| 18 | */ |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 19 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 20 | /* Board-specific functions defined in each board's ddr.c */ |
| 21 | extern void fsl_ddr_board_options(memctl_options_t *popts, |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 22 | dimm_params_t *pdimm, |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 23 | unsigned int ctrl_num); |
| 24 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 25 | struct dynamic_odt { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 26 | unsigned int odt_rd_cfg; |
| 27 | unsigned int odt_wr_cfg; |
| 28 | unsigned int odt_rtt_norm; |
| 29 | unsigned int odt_rtt_wr; |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 30 | }; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 31 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 32 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 33 | static const struct dynamic_odt single_Q[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 34 | { /* cs0 */ |
| 35 | FSL_DDR_ODT_NEVER, |
| 36 | FSL_DDR_ODT_CS_AND_OTHER_DIMM, |
| 37 | DDR3_RTT_20_OHM, |
| 38 | DDR3_RTT_120_OHM |
| 39 | }, |
| 40 | { /* cs1 */ |
| 41 | FSL_DDR_ODT_NEVER, |
| 42 | FSL_DDR_ODT_NEVER, /* tied high */ |
| 43 | DDR3_RTT_OFF, |
| 44 | DDR3_RTT_120_OHM |
| 45 | }, |
| 46 | { /* cs2 */ |
| 47 | FSL_DDR_ODT_NEVER, |
| 48 | FSL_DDR_ODT_CS_AND_OTHER_DIMM, |
| 49 | DDR3_RTT_20_OHM, |
| 50 | DDR3_RTT_120_OHM |
| 51 | }, |
| 52 | { /* cs3 */ |
| 53 | FSL_DDR_ODT_NEVER, |
| 54 | FSL_DDR_ODT_NEVER, /* tied high */ |
| 55 | DDR3_RTT_OFF, |
| 56 | DDR3_RTT_120_OHM |
| 57 | } |
| 58 | }; |
| 59 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 60 | static const struct dynamic_odt single_D[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 61 | { /* cs0 */ |
| 62 | FSL_DDR_ODT_NEVER, |
| 63 | FSL_DDR_ODT_ALL, |
| 64 | DDR3_RTT_40_OHM, |
| 65 | DDR3_RTT_OFF |
| 66 | }, |
| 67 | { /* cs1 */ |
| 68 | FSL_DDR_ODT_NEVER, |
| 69 | FSL_DDR_ODT_NEVER, |
| 70 | DDR3_RTT_OFF, |
| 71 | DDR3_RTT_OFF |
| 72 | }, |
| 73 | {0, 0, 0, 0}, |
| 74 | {0, 0, 0, 0} |
| 75 | }; |
| 76 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 77 | static const struct dynamic_odt single_S[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 78 | { /* cs0 */ |
| 79 | FSL_DDR_ODT_NEVER, |
| 80 | FSL_DDR_ODT_ALL, |
| 81 | DDR3_RTT_40_OHM, |
| 82 | DDR3_RTT_OFF |
| 83 | }, |
| 84 | {0, 0, 0, 0}, |
| 85 | {0, 0, 0, 0}, |
| 86 | {0, 0, 0, 0}, |
| 87 | }; |
| 88 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 89 | static const struct dynamic_odt dual_DD[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 90 | { /* cs0 */ |
| 91 | FSL_DDR_ODT_NEVER, |
| 92 | FSL_DDR_ODT_SAME_DIMM, |
| 93 | DDR3_RTT_120_OHM, |
| 94 | DDR3_RTT_OFF |
| 95 | }, |
| 96 | { /* cs1 */ |
| 97 | FSL_DDR_ODT_OTHER_DIMM, |
| 98 | FSL_DDR_ODT_OTHER_DIMM, |
| 99 | DDR3_RTT_30_OHM, |
| 100 | DDR3_RTT_OFF |
| 101 | }, |
| 102 | { /* cs2 */ |
| 103 | FSL_DDR_ODT_NEVER, |
| 104 | FSL_DDR_ODT_SAME_DIMM, |
| 105 | DDR3_RTT_120_OHM, |
| 106 | DDR3_RTT_OFF |
| 107 | }, |
| 108 | { /* cs3 */ |
| 109 | FSL_DDR_ODT_OTHER_DIMM, |
| 110 | FSL_DDR_ODT_OTHER_DIMM, |
| 111 | DDR3_RTT_30_OHM, |
| 112 | DDR3_RTT_OFF |
| 113 | } |
| 114 | }; |
| 115 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 116 | static const struct dynamic_odt dual_DS[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 117 | { /* cs0 */ |
| 118 | FSL_DDR_ODT_NEVER, |
| 119 | FSL_DDR_ODT_SAME_DIMM, |
| 120 | DDR3_RTT_120_OHM, |
| 121 | DDR3_RTT_OFF |
| 122 | }, |
| 123 | { /* cs1 */ |
| 124 | FSL_DDR_ODT_OTHER_DIMM, |
| 125 | FSL_DDR_ODT_OTHER_DIMM, |
| 126 | DDR3_RTT_30_OHM, |
| 127 | DDR3_RTT_OFF |
| 128 | }, |
| 129 | { /* cs2 */ |
| 130 | FSL_DDR_ODT_OTHER_DIMM, |
| 131 | FSL_DDR_ODT_ALL, |
| 132 | DDR3_RTT_20_OHM, |
| 133 | DDR3_RTT_120_OHM |
| 134 | }, |
| 135 | {0, 0, 0, 0} |
| 136 | }; |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 137 | static const struct dynamic_odt dual_SD[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 138 | { /* cs0 */ |
| 139 | FSL_DDR_ODT_OTHER_DIMM, |
| 140 | FSL_DDR_ODT_ALL, |
| 141 | DDR3_RTT_20_OHM, |
| 142 | DDR3_RTT_120_OHM |
| 143 | }, |
| 144 | {0, 0, 0, 0}, |
| 145 | { /* cs2 */ |
| 146 | FSL_DDR_ODT_NEVER, |
| 147 | FSL_DDR_ODT_SAME_DIMM, |
| 148 | DDR3_RTT_120_OHM, |
| 149 | DDR3_RTT_OFF |
| 150 | }, |
| 151 | { /* cs3 */ |
| 152 | FSL_DDR_ODT_OTHER_DIMM, |
| 153 | FSL_DDR_ODT_OTHER_DIMM, |
| 154 | DDR3_RTT_20_OHM, |
| 155 | DDR3_RTT_OFF |
| 156 | } |
| 157 | }; |
| 158 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 159 | static const struct dynamic_odt dual_SS[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 160 | { /* cs0 */ |
| 161 | FSL_DDR_ODT_OTHER_DIMM, |
| 162 | FSL_DDR_ODT_ALL, |
| 163 | DDR3_RTT_30_OHM, |
| 164 | DDR3_RTT_120_OHM |
| 165 | }, |
| 166 | {0, 0, 0, 0}, |
| 167 | { /* cs2 */ |
| 168 | FSL_DDR_ODT_OTHER_DIMM, |
| 169 | FSL_DDR_ODT_ALL, |
| 170 | DDR3_RTT_30_OHM, |
| 171 | DDR3_RTT_120_OHM |
| 172 | }, |
| 173 | {0, 0, 0, 0} |
| 174 | }; |
| 175 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 176 | static const struct dynamic_odt dual_D0[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 177 | { /* cs0 */ |
| 178 | FSL_DDR_ODT_NEVER, |
| 179 | FSL_DDR_ODT_SAME_DIMM, |
| 180 | DDR3_RTT_40_OHM, |
| 181 | DDR3_RTT_OFF |
| 182 | }, |
| 183 | { /* cs1 */ |
| 184 | FSL_DDR_ODT_NEVER, |
| 185 | FSL_DDR_ODT_NEVER, |
| 186 | DDR3_RTT_OFF, |
| 187 | DDR3_RTT_OFF |
| 188 | }, |
| 189 | {0, 0, 0, 0}, |
| 190 | {0, 0, 0, 0} |
| 191 | }; |
| 192 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 193 | static const struct dynamic_odt dual_0D[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 194 | {0, 0, 0, 0}, |
| 195 | {0, 0, 0, 0}, |
| 196 | { /* cs2 */ |
| 197 | FSL_DDR_ODT_NEVER, |
| 198 | FSL_DDR_ODT_SAME_DIMM, |
| 199 | DDR3_RTT_40_OHM, |
| 200 | DDR3_RTT_OFF |
| 201 | }, |
| 202 | { /* cs3 */ |
| 203 | FSL_DDR_ODT_NEVER, |
| 204 | FSL_DDR_ODT_NEVER, |
| 205 | DDR3_RTT_OFF, |
| 206 | DDR3_RTT_OFF |
| 207 | } |
| 208 | }; |
| 209 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 210 | static const struct dynamic_odt dual_S0[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 211 | { /* cs0 */ |
| 212 | FSL_DDR_ODT_NEVER, |
| 213 | FSL_DDR_ODT_CS, |
| 214 | DDR3_RTT_40_OHM, |
| 215 | DDR3_RTT_OFF |
| 216 | }, |
| 217 | {0, 0, 0, 0}, |
| 218 | {0, 0, 0, 0}, |
| 219 | {0, 0, 0, 0} |
| 220 | |
| 221 | }; |
| 222 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 223 | static const struct dynamic_odt dual_0S[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 224 | {0, 0, 0, 0}, |
| 225 | {0, 0, 0, 0}, |
| 226 | { /* cs2 */ |
| 227 | FSL_DDR_ODT_NEVER, |
| 228 | FSL_DDR_ODT_CS, |
| 229 | DDR3_RTT_40_OHM, |
| 230 | DDR3_RTT_OFF |
| 231 | }, |
| 232 | {0, 0, 0, 0} |
| 233 | |
| 234 | }; |
| 235 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 236 | static const struct dynamic_odt odt_unknown[4] = { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 237 | { /* cs0 */ |
| 238 | FSL_DDR_ODT_NEVER, |
| 239 | FSL_DDR_ODT_CS, |
| 240 | DDR3_RTT_120_OHM, |
| 241 | DDR3_RTT_OFF |
| 242 | }, |
| 243 | { /* cs1 */ |
| 244 | FSL_DDR_ODT_NEVER, |
| 245 | FSL_DDR_ODT_CS, |
| 246 | DDR3_RTT_120_OHM, |
| 247 | DDR3_RTT_OFF |
| 248 | }, |
| 249 | { /* cs2 */ |
| 250 | FSL_DDR_ODT_NEVER, |
| 251 | FSL_DDR_ODT_CS, |
| 252 | DDR3_RTT_120_OHM, |
| 253 | DDR3_RTT_OFF |
| 254 | }, |
| 255 | { /* cs3 */ |
| 256 | FSL_DDR_ODT_NEVER, |
| 257 | FSL_DDR_ODT_CS, |
| 258 | DDR3_RTT_120_OHM, |
| 259 | DDR3_RTT_OFF |
| 260 | } |
| 261 | }; |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 262 | #else /* CONFIG_SYS_FSL_DDR3 || CONFIG_SYS_FSL_DDR4 */ |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 263 | static const struct dynamic_odt single_Q[4] = { |
| 264 | {0, 0, 0, 0}, |
| 265 | {0, 0, 0, 0}, |
| 266 | {0, 0, 0, 0}, |
| 267 | {0, 0, 0, 0} |
| 268 | }; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 269 | |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 270 | static const struct dynamic_odt single_D[4] = { |
| 271 | { /* cs0 */ |
| 272 | FSL_DDR_ODT_NEVER, |
| 273 | FSL_DDR_ODT_ALL, |
| 274 | DDR2_RTT_150_OHM, |
| 275 | DDR2_RTT_OFF |
| 276 | }, |
| 277 | { /* cs1 */ |
| 278 | FSL_DDR_ODT_NEVER, |
| 279 | FSL_DDR_ODT_NEVER, |
| 280 | DDR2_RTT_OFF, |
| 281 | DDR2_RTT_OFF |
| 282 | }, |
| 283 | {0, 0, 0, 0}, |
| 284 | {0, 0, 0, 0} |
| 285 | }; |
| 286 | |
| 287 | static const struct dynamic_odt single_S[4] = { |
| 288 | { /* cs0 */ |
| 289 | FSL_DDR_ODT_NEVER, |
| 290 | FSL_DDR_ODT_ALL, |
| 291 | DDR2_RTT_150_OHM, |
| 292 | DDR2_RTT_OFF |
| 293 | }, |
| 294 | {0, 0, 0, 0}, |
| 295 | {0, 0, 0, 0}, |
| 296 | {0, 0, 0, 0}, |
| 297 | }; |
| 298 | |
| 299 | static const struct dynamic_odt dual_DD[4] = { |
| 300 | { /* cs0 */ |
| 301 | FSL_DDR_ODT_OTHER_DIMM, |
| 302 | FSL_DDR_ODT_OTHER_DIMM, |
| 303 | DDR2_RTT_75_OHM, |
| 304 | DDR2_RTT_OFF |
| 305 | }, |
| 306 | { /* cs1 */ |
| 307 | FSL_DDR_ODT_NEVER, |
| 308 | FSL_DDR_ODT_NEVER, |
| 309 | DDR2_RTT_OFF, |
| 310 | DDR2_RTT_OFF |
| 311 | }, |
| 312 | { /* cs2 */ |
| 313 | FSL_DDR_ODT_OTHER_DIMM, |
| 314 | FSL_DDR_ODT_OTHER_DIMM, |
| 315 | DDR2_RTT_75_OHM, |
| 316 | DDR2_RTT_OFF |
| 317 | }, |
| 318 | { /* cs3 */ |
| 319 | FSL_DDR_ODT_NEVER, |
| 320 | FSL_DDR_ODT_NEVER, |
| 321 | DDR2_RTT_OFF, |
| 322 | DDR2_RTT_OFF |
| 323 | } |
| 324 | }; |
| 325 | |
| 326 | static const struct dynamic_odt dual_DS[4] = { |
| 327 | { /* cs0 */ |
| 328 | FSL_DDR_ODT_OTHER_DIMM, |
| 329 | FSL_DDR_ODT_OTHER_DIMM, |
| 330 | DDR2_RTT_75_OHM, |
| 331 | DDR2_RTT_OFF |
| 332 | }, |
| 333 | { /* cs1 */ |
| 334 | FSL_DDR_ODT_NEVER, |
| 335 | FSL_DDR_ODT_NEVER, |
| 336 | DDR2_RTT_OFF, |
| 337 | DDR2_RTT_OFF |
| 338 | }, |
| 339 | { /* cs2 */ |
| 340 | FSL_DDR_ODT_OTHER_DIMM, |
| 341 | FSL_DDR_ODT_OTHER_DIMM, |
| 342 | DDR2_RTT_75_OHM, |
| 343 | DDR2_RTT_OFF |
| 344 | }, |
| 345 | {0, 0, 0, 0} |
| 346 | }; |
| 347 | |
| 348 | static const struct dynamic_odt dual_SD[4] = { |
| 349 | { /* cs0 */ |
| 350 | FSL_DDR_ODT_OTHER_DIMM, |
| 351 | FSL_DDR_ODT_OTHER_DIMM, |
| 352 | DDR2_RTT_75_OHM, |
| 353 | DDR2_RTT_OFF |
| 354 | }, |
| 355 | {0, 0, 0, 0}, |
| 356 | { /* cs2 */ |
| 357 | FSL_DDR_ODT_OTHER_DIMM, |
| 358 | FSL_DDR_ODT_OTHER_DIMM, |
| 359 | DDR2_RTT_75_OHM, |
| 360 | DDR2_RTT_OFF |
| 361 | }, |
| 362 | { /* cs3 */ |
| 363 | FSL_DDR_ODT_NEVER, |
| 364 | FSL_DDR_ODT_NEVER, |
| 365 | DDR2_RTT_OFF, |
| 366 | DDR2_RTT_OFF |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | static const struct dynamic_odt dual_SS[4] = { |
| 371 | { /* cs0 */ |
| 372 | FSL_DDR_ODT_OTHER_DIMM, |
| 373 | FSL_DDR_ODT_OTHER_DIMM, |
| 374 | DDR2_RTT_75_OHM, |
| 375 | DDR2_RTT_OFF |
| 376 | }, |
| 377 | {0, 0, 0, 0}, |
| 378 | { /* cs2 */ |
| 379 | FSL_DDR_ODT_OTHER_DIMM, |
| 380 | FSL_DDR_ODT_OTHER_DIMM, |
| 381 | DDR2_RTT_75_OHM, |
| 382 | DDR2_RTT_OFF |
| 383 | }, |
| 384 | {0, 0, 0, 0} |
| 385 | }; |
| 386 | |
| 387 | static const struct dynamic_odt dual_D0[4] = { |
| 388 | { /* cs0 */ |
| 389 | FSL_DDR_ODT_NEVER, |
| 390 | FSL_DDR_ODT_ALL, |
| 391 | DDR2_RTT_150_OHM, |
| 392 | DDR2_RTT_OFF |
| 393 | }, |
| 394 | { /* cs1 */ |
| 395 | FSL_DDR_ODT_NEVER, |
| 396 | FSL_DDR_ODT_NEVER, |
| 397 | DDR2_RTT_OFF, |
| 398 | DDR2_RTT_OFF |
| 399 | }, |
| 400 | {0, 0, 0, 0}, |
| 401 | {0, 0, 0, 0} |
| 402 | }; |
| 403 | |
| 404 | static const struct dynamic_odt dual_0D[4] = { |
| 405 | {0, 0, 0, 0}, |
| 406 | {0, 0, 0, 0}, |
| 407 | { /* cs2 */ |
| 408 | FSL_DDR_ODT_NEVER, |
| 409 | FSL_DDR_ODT_ALL, |
| 410 | DDR2_RTT_150_OHM, |
| 411 | DDR2_RTT_OFF |
| 412 | }, |
| 413 | { /* cs3 */ |
| 414 | FSL_DDR_ODT_NEVER, |
| 415 | FSL_DDR_ODT_NEVER, |
| 416 | DDR2_RTT_OFF, |
| 417 | DDR2_RTT_OFF |
| 418 | } |
| 419 | }; |
| 420 | |
| 421 | static const struct dynamic_odt dual_S0[4] = { |
| 422 | { /* cs0 */ |
| 423 | FSL_DDR_ODT_NEVER, |
| 424 | FSL_DDR_ODT_CS, |
| 425 | DDR2_RTT_150_OHM, |
| 426 | DDR2_RTT_OFF |
| 427 | }, |
| 428 | {0, 0, 0, 0}, |
| 429 | {0, 0, 0, 0}, |
| 430 | {0, 0, 0, 0} |
| 431 | |
| 432 | }; |
| 433 | |
| 434 | static const struct dynamic_odt dual_0S[4] = { |
| 435 | {0, 0, 0, 0}, |
| 436 | {0, 0, 0, 0}, |
| 437 | { /* cs2 */ |
| 438 | FSL_DDR_ODT_NEVER, |
| 439 | FSL_DDR_ODT_CS, |
| 440 | DDR2_RTT_150_OHM, |
| 441 | DDR2_RTT_OFF |
| 442 | }, |
| 443 | {0, 0, 0, 0} |
| 444 | |
| 445 | }; |
| 446 | |
| 447 | static const struct dynamic_odt odt_unknown[4] = { |
| 448 | { /* cs0 */ |
| 449 | FSL_DDR_ODT_NEVER, |
| 450 | FSL_DDR_ODT_CS, |
| 451 | DDR2_RTT_75_OHM, |
| 452 | DDR2_RTT_OFF |
| 453 | }, |
| 454 | { /* cs1 */ |
| 455 | FSL_DDR_ODT_NEVER, |
| 456 | FSL_DDR_ODT_NEVER, |
| 457 | DDR2_RTT_OFF, |
| 458 | DDR2_RTT_OFF |
| 459 | }, |
| 460 | { /* cs2 */ |
| 461 | FSL_DDR_ODT_NEVER, |
| 462 | FSL_DDR_ODT_CS, |
| 463 | DDR2_RTT_75_OHM, |
| 464 | DDR2_RTT_OFF |
| 465 | }, |
| 466 | { /* cs3 */ |
| 467 | FSL_DDR_ODT_NEVER, |
| 468 | FSL_DDR_ODT_NEVER, |
| 469 | DDR2_RTT_OFF, |
| 470 | DDR2_RTT_OFF |
| 471 | } |
| 472 | }; |
| 473 | #endif |
York Sun | 89b7809 | 2012-10-08 07:44:27 +0000 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * Automatically seleect bank interleaving mode based on DIMMs |
| 477 | * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null. |
| 478 | * This function only deal with one or two slots per controller. |
| 479 | */ |
| 480 | static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm) |
| 481 | { |
| 482 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
| 483 | if (pdimm[0].n_ranks == 4) |
| 484 | return FSL_DDR_CS0_CS1_CS2_CS3; |
| 485 | else if (pdimm[0].n_ranks == 2) |
| 486 | return FSL_DDR_CS0_CS1; |
| 487 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
| 488 | #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE |
| 489 | if (pdimm[0].n_ranks == 4) |
| 490 | return FSL_DDR_CS0_CS1_CS2_CS3; |
| 491 | #endif |
| 492 | if (pdimm[0].n_ranks == 2) { |
| 493 | if (pdimm[1].n_ranks == 2) |
| 494 | return FSL_DDR_CS0_CS1_CS2_CS3; |
| 495 | else |
| 496 | return FSL_DDR_CS0_CS1; |
| 497 | } |
| 498 | #endif |
| 499 | return 0; |
| 500 | } |
| 501 | |
York Sun | 5684842 | 2015-07-23 14:04:48 -0700 | [diff] [blame] | 502 | unsigned int populate_memctl_options(const common_timing_params_t *common_dimm, |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 503 | memctl_options_t *popts, |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 504 | dimm_params_t *pdimm, |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 505 | unsigned int ctrl_num) |
| 506 | { |
| 507 | unsigned int i; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 508 | char buffer[HWCONFIG_BUFFER_SIZE]; |
| 509 | char *buf = NULL; |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 510 | #if defined(CONFIG_SYS_FSL_DDR3) || \ |
| 511 | defined(CONFIG_SYS_FSL_DDR2) || \ |
| 512 | defined(CONFIG_SYS_FSL_DDR4) |
York Sun | 4e57382 | 2011-08-26 11:32:43 -0700 | [diff] [blame] | 513 | const struct dynamic_odt *pdodt = odt_unknown; |
Kumar Gala | 667bc17 | 2011-11-09 10:05:21 -0600 | [diff] [blame] | 514 | #endif |
York Sun | cda1de2 | 2011-08-24 09:40:26 -0700 | [diff] [blame] | 515 | ulong ddr_freq; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 516 | |
| 517 | /* |
| 518 | * Extract hwconfig from environment since we have not properly setup |
| 519 | * the environment but need it for ddr config params |
| 520 | */ |
| 521 | if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0) |
| 522 | buf = buffer; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 523 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 524 | #if defined(CONFIG_SYS_FSL_DDR3) || \ |
| 525 | defined(CONFIG_SYS_FSL_DDR2) || \ |
| 526 | defined(CONFIG_SYS_FSL_DDR4) |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 527 | /* Chip select options. */ |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 528 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
| 529 | switch (pdimm[0].n_ranks) { |
| 530 | case 1: |
| 531 | pdodt = single_S; |
| 532 | break; |
| 533 | case 2: |
| 534 | pdodt = single_D; |
| 535 | break; |
| 536 | case 4: |
| 537 | pdodt = single_Q; |
| 538 | break; |
| 539 | } |
| 540 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
| 541 | switch (pdimm[0].n_ranks) { |
York Sun | 123922b | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 542 | #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 543 | case 4: |
| 544 | pdodt = single_Q; |
| 545 | if (pdimm[1].n_ranks) |
| 546 | printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n"); |
| 547 | break; |
York Sun | 123922b | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 548 | #endif |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 549 | case 2: |
| 550 | switch (pdimm[1].n_ranks) { |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 551 | case 2: |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 552 | pdodt = dual_DD; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 553 | break; |
| 554 | case 1: |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 555 | pdodt = dual_DS; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 556 | break; |
| 557 | case 0: |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 558 | pdodt = dual_D0; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 559 | break; |
| 560 | } |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 561 | break; |
| 562 | case 1: |
| 563 | switch (pdimm[1].n_ranks) { |
| 564 | case 2: |
| 565 | pdodt = dual_SD; |
| 566 | break; |
| 567 | case 1: |
| 568 | pdodt = dual_SS; |
| 569 | break; |
| 570 | case 0: |
| 571 | pdodt = dual_S0; |
| 572 | break; |
| 573 | } |
| 574 | break; |
| 575 | case 0: |
| 576 | switch (pdimm[1].n_ranks) { |
| 577 | case 2: |
| 578 | pdodt = dual_0D; |
| 579 | break; |
| 580 | case 1: |
| 581 | pdodt = dual_0S; |
| 582 | break; |
| 583 | } |
| 584 | break; |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 585 | } |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 586 | #endif /* CONFIG_DIMM_SLOTS_PER_CTLR */ |
| 587 | #endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 588 | |
| 589 | /* Pick chip-select local options. */ |
| 590 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 591 | #if defined(CONFIG_SYS_FSL_DDR3) || \ |
| 592 | defined(CONFIG_SYS_FSL_DDR2) || \ |
| 593 | defined(CONFIG_SYS_FSL_DDR4) |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 594 | popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg; |
| 595 | popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg; |
| 596 | popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm; |
| 597 | popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr; |
| 598 | #else |
| 599 | popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER; |
| 600 | popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS; |
| 601 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 602 | popts->cs_local_opts[i].auto_precharge = 0; |
| 603 | } |
| 604 | |
| 605 | /* Pick interleaving mode. */ |
| 606 | |
| 607 | /* |
| 608 | * 0 = no interleaving |
| 609 | * 1 = interleaving between 2 controllers |
| 610 | */ |
| 611 | popts->memctl_interleaving = 0; |
| 612 | |
| 613 | /* |
| 614 | * 0 = cacheline |
| 615 | * 1 = page |
| 616 | * 2 = (logical) bank |
| 617 | * 3 = superbank (only if CS interleaving is enabled) |
| 618 | */ |
| 619 | popts->memctl_interleaving_mode = 0; |
| 620 | |
| 621 | /* |
| 622 | * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl |
| 623 | * 1: page: bit to the left of the column bits selects the memctl |
| 624 | * 2: bank: bit to the left of the bank bits selects the memctl |
| 625 | * 3: superbank: bit to the left of the chip select selects the memctl |
| 626 | * |
| 627 | * NOTE: ba_intlv (rank interleaving) is independent of memory |
| 628 | * controller interleaving; it is only within a memory controller. |
| 629 | * Must use superbank interleaving if rank interleaving is used and |
| 630 | * memory controller interleaving is enabled. |
| 631 | */ |
| 632 | |
| 633 | /* |
| 634 | * 0 = no |
| 635 | * 0x40 = CS0,CS1 |
| 636 | * 0x20 = CS2,CS3 |
| 637 | * 0x60 = CS0,CS1 + CS2,CS3 |
| 638 | * 0x04 = CS0,CS1,CS2,CS3 |
| 639 | */ |
| 640 | popts->ba_intlv_ctl = 0; |
| 641 | |
| 642 | /* Memory Organization Parameters */ |
York Sun | 5684842 | 2015-07-23 14:04:48 -0700 | [diff] [blame] | 643 | popts->registered_dimm_en = common_dimm->all_dimms_registered; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 644 | |
| 645 | /* Operational Mode Paramters */ |
| 646 | |
| 647 | /* Pick ECC modes */ |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 648 | popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */ |
York Sun | 47df8f0 | 2011-01-10 12:02:57 +0000 | [diff] [blame] | 649 | #ifdef CONFIG_DDR_ECC |
| 650 | if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) { |
| 651 | if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf)) |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 652 | popts->ecc_mode = 1; |
York Sun | 47df8f0 | 2011-01-10 12:02:57 +0000 | [diff] [blame] | 653 | } else |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 654 | popts->ecc_mode = 1; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 655 | #endif |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 656 | popts->ecc_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 657 | |
| 658 | /* |
| 659 | * Choose DQS config |
| 660 | * 0 for DDR1 |
| 661 | * 1 for DDR2 |
| 662 | */ |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 663 | #if defined(CONFIG_SYS_FSL_DDR1) |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 664 | popts->dqs_config = 0; |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 665 | #elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3) |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 666 | popts->dqs_config = 1; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 667 | #endif |
| 668 | |
| 669 | /* Choose self-refresh during sleep. */ |
| 670 | popts->self_refresh_in_sleep = 1; |
| 671 | |
| 672 | /* Choose dynamic power management mode. */ |
| 673 | popts->dynamic_power = 0; |
| 674 | |
York Sun | e090aa7 | 2011-05-27 07:25:48 +0800 | [diff] [blame] | 675 | /* |
| 676 | * check first dimm for primary sdram width |
| 677 | * presuming all dimms are similar |
| 678 | * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit |
| 679 | */ |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 680 | #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2) |
York Sun | 4c99cb9 | 2011-06-27 13:35:25 -0700 | [diff] [blame] | 681 | if (pdimm[0].n_ranks != 0) { |
| 682 | if ((pdimm[0].data_width >= 64) && \ |
| 683 | (pdimm[0].data_width <= 72)) |
| 684 | popts->data_bus_width = 0; |
| 685 | else if ((pdimm[0].data_width >= 32) || \ |
| 686 | (pdimm[0].data_width <= 40)) |
| 687 | popts->data_bus_width = 1; |
| 688 | else { |
| 689 | panic("Error: data width %u is invalid!\n", |
| 690 | pdimm[0].data_width); |
| 691 | } |
| 692 | } |
| 693 | #else |
| 694 | if (pdimm[0].n_ranks != 0) { |
| 695 | if (pdimm[0].primary_sdram_width == 64) |
| 696 | popts->data_bus_width = 0; |
| 697 | else if (pdimm[0].primary_sdram_width == 32) |
| 698 | popts->data_bus_width = 1; |
| 699 | else if (pdimm[0].primary_sdram_width == 16) |
| 700 | popts->data_bus_width = 2; |
| 701 | else { |
| 702 | panic("Error: primary sdram width %u is invalid!\n", |
| 703 | pdimm[0].primary_sdram_width); |
| 704 | } |
| 705 | } |
| 706 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 707 | |
York Sun | b61e061 | 2013-06-25 11:37:47 -0700 | [diff] [blame] | 708 | popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0; |
| 709 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 710 | /* Choose burst length. */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 711 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
Dave Liu | 22c9de0 | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 712 | #if defined(CONFIG_E500MC) |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 713 | popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */ |
Dave Liu | 22c9de0 | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 714 | popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */ |
| 715 | #else |
York Sun | 51d498f | 2011-05-27 07:25:51 +0800 | [diff] [blame] | 716 | if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) { |
| 717 | /* 32-bit or 16-bit bus */ |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 718 | popts->otf_burst_chop_en = 0; |
York Sun | e090aa7 | 2011-05-27 07:25:48 +0800 | [diff] [blame] | 719 | popts->burst_length = DDR_BL8; |
| 720 | } else { |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 721 | popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */ |
York Sun | e090aa7 | 2011-05-27 07:25:48 +0800 | [diff] [blame] | 722 | popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */ |
| 723 | } |
Dave Liu | 22c9de0 | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 724 | #endif |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 725 | #else |
| 726 | popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */ |
| 727 | #endif |
| 728 | |
| 729 | /* Choose ddr controller address mirror mode */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 730 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
York Sun | 6b95be2 | 2015-03-19 09:30:27 -0700 | [diff] [blame] | 731 | for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) { |
| 732 | if (pdimm[i].n_ranks) { |
| 733 | popts->mirrored_dimm = pdimm[i].mirrored_dimm; |
| 734 | break; |
| 735 | } |
| 736 | } |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 737 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 738 | |
| 739 | /* Global Timing Parameters. */ |
York Sun | 03e664d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 740 | debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num)); |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 741 | |
| 742 | /* Pick a caslat override. */ |
| 743 | popts->cas_latency_override = 0; |
| 744 | popts->cas_latency_override_value = 3; |
| 745 | if (popts->cas_latency_override) { |
| 746 | debug("using caslat override value = %u\n", |
| 747 | popts->cas_latency_override_value); |
| 748 | } |
| 749 | |
| 750 | /* Decide whether to use the computed derated latency */ |
| 751 | popts->use_derated_caslat = 0; |
| 752 | |
| 753 | /* Choose an additive latency. */ |
| 754 | popts->additive_latency_override = 0; |
| 755 | popts->additive_latency_override_value = 3; |
| 756 | if (popts->additive_latency_override) { |
| 757 | debug("using additive latency override value = %u\n", |
| 758 | popts->additive_latency_override_value); |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * 2T_EN setting |
| 763 | * |
| 764 | * Factors to consider for 2T_EN: |
| 765 | * - number of DIMMs installed |
| 766 | * - number of components, number of active ranks |
| 767 | * - how much time you want to spend playing around |
| 768 | */ |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 769 | popts->twot_en = 0; |
| 770 | popts->threet_en = 0; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 771 | |
York Sun | e1fd16b | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 772 | /* for RDIMM, address parity enable */ |
| 773 | popts->ap_en = 1; |
| 774 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 775 | /* |
| 776 | * BSTTOPRE precharge interval |
| 777 | * |
| 778 | * Set this to 0 for global auto precharge |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 779 | * The value of 0x100 has been used for DDR1, DDR2, DDR3. |
| 780 | * It is not wrong. Any value should be OK. The performance depends on |
York Sun | 5684842 | 2015-07-23 14:04:48 -0700 | [diff] [blame] | 781 | * applications. There is no one good value for all. One way to set |
| 782 | * is to use 1/4 of refint value. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 783 | */ |
York Sun | 5684842 | 2015-07-23 14:04:48 -0700 | [diff] [blame] | 784 | popts->bstopre = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps) |
| 785 | >> 2; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 786 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 787 | /* |
| 788 | * Window for four activates -- tFAW |
| 789 | * |
| 790 | * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only |
| 791 | * FIXME: varies depending upon number of column addresses or data |
| 792 | * FIXME: width, was considering looking at pdimm->primary_sdram_width |
| 793 | */ |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 794 | #if defined(CONFIG_SYS_FSL_DDR1) |
York Sun | 03e664d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 795 | popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1); |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 796 | |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 797 | #elif defined(CONFIG_SYS_FSL_DDR2) |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 798 | /* |
| 799 | * x4/x8; some datasheets have 35000 |
| 800 | * x16 wide columns only? Use 50000? |
| 801 | */ |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 802 | popts->tfaw_window_four_activates_ps = 37500; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 803 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 804 | #else |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 805 | popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps; |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 806 | #endif |
| 807 | popts->zq_en = 0; |
| 808 | popts->wrlvl_en = 0; |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 809 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 810 | /* |
| 811 | * due to ddr3 dimm is fly-by topology |
| 812 | * we suggest to enable write leveling to |
| 813 | * meet the tQDSS under different loading. |
| 814 | */ |
| 815 | popts->wrlvl_en = 1; |
york | 5fb8a8a | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 816 | popts->zq_en = 1; |
Dave Liu | bdc9f7b | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 817 | popts->wrlvl_override = 0; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 818 | #endif |
| 819 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 820 | /* |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 821 | * Check interleaving configuration from environment. |
| 822 | * Please refer to doc/README.fsl-ddr for the detail. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 823 | * |
| 824 | * If memory controller interleaving is enabled, then the data |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 825 | * bus widths must be programmed identically for all memory controllers. |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 826 | * |
York Sun | 6b1e125 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 827 | * Attempt to set all controllers to the same chip select |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 828 | * interleaving mode. It will do a best effort to get the |
| 829 | * requested ranks interleaved together such that the result |
| 830 | * should be a subset of the requested configuration. |
York Sun | 6b1e125 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 831 | * |
| 832 | * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving |
| 833 | * with 256 Byte is enabled. |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 834 | */ |
Kumar Gala | 1542fbd | 2009-02-06 09:56:34 -0600 | [diff] [blame] | 835 | #if (CONFIG_NUM_DDR_CONTROLLERS > 1) |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 836 | if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf)) |
York Sun | 6b1e125 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 837 | #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B |
| 838 | ; |
| 839 | #else |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 840 | goto done; |
York Sun | 6b1e125 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 841 | #endif |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 842 | if (pdimm[0].n_ranks == 0) { |
| 843 | printf("There is no rank on CS0 for controller %d.\n", ctrl_num); |
| 844 | popts->memctl_interleaving = 0; |
| 845 | goto done; |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 846 | } |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 847 | popts->memctl_interleaving = 1; |
York Sun | 6b1e125 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 848 | #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B |
| 849 | popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING; |
| 850 | popts->memctl_interleaving = 1; |
| 851 | debug("256 Byte interleaving\n"); |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 852 | #else |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 853 | /* |
| 854 | * test null first. if CONFIG_HWCONFIG is not defined |
| 855 | * hwconfig_arg_cmp returns non-zero |
| 856 | */ |
| 857 | if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv", |
| 858 | "null", buf)) { |
| 859 | popts->memctl_interleaving = 0; |
| 860 | debug("memory controller interleaving disabled.\n"); |
| 861 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 862 | "ctlr_intlv", |
| 863 | "cacheline", buf)) { |
| 864 | popts->memctl_interleaving_mode = |
| 865 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 866 | 0 : FSL_DDR_CACHE_LINE_INTERLEAVING; |
| 867 | popts->memctl_interleaving = |
| 868 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 869 | 0 : 1; |
| 870 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 871 | "ctlr_intlv", |
| 872 | "page", buf)) { |
| 873 | popts->memctl_interleaving_mode = |
| 874 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 875 | 0 : FSL_DDR_PAGE_INTERLEAVING; |
| 876 | popts->memctl_interleaving = |
| 877 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 878 | 0 : 1; |
| 879 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 880 | "ctlr_intlv", |
| 881 | "bank", buf)) { |
| 882 | popts->memctl_interleaving_mode = |
| 883 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 884 | 0 : FSL_DDR_BANK_INTERLEAVING; |
| 885 | popts->memctl_interleaving = |
| 886 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 887 | 0 : 1; |
| 888 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 889 | "ctlr_intlv", |
| 890 | "superbank", buf)) { |
| 891 | popts->memctl_interleaving_mode = |
| 892 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 893 | 0 : FSL_DDR_SUPERBANK_INTERLEAVING; |
| 894 | popts->memctl_interleaving = |
| 895 | ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ? |
| 896 | 0 : 1; |
| 897 | #if (CONFIG_NUM_DDR_CONTROLLERS == 3) |
| 898 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 899 | "ctlr_intlv", |
| 900 | "3way_1KB", buf)) { |
| 901 | popts->memctl_interleaving_mode = |
| 902 | FSL_DDR_3WAY_1KB_INTERLEAVING; |
| 903 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 904 | "ctlr_intlv", |
| 905 | "3way_4KB", buf)) { |
| 906 | popts->memctl_interleaving_mode = |
| 907 | FSL_DDR_3WAY_4KB_INTERLEAVING; |
| 908 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 909 | "ctlr_intlv", |
| 910 | "3way_8KB", buf)) { |
| 911 | popts->memctl_interleaving_mode = |
| 912 | FSL_DDR_3WAY_8KB_INTERLEAVING; |
| 913 | #elif (CONFIG_NUM_DDR_CONTROLLERS == 4) |
| 914 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 915 | "ctlr_intlv", |
| 916 | "4way_1KB", buf)) { |
| 917 | popts->memctl_interleaving_mode = |
| 918 | FSL_DDR_4WAY_1KB_INTERLEAVING; |
| 919 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 920 | "ctlr_intlv", |
| 921 | "4way_4KB", buf)) { |
| 922 | popts->memctl_interleaving_mode = |
| 923 | FSL_DDR_4WAY_4KB_INTERLEAVING; |
| 924 | } else if (hwconfig_subarg_cmp_f("fsl_ddr", |
| 925 | "ctlr_intlv", |
| 926 | "4way_8KB", buf)) { |
| 927 | popts->memctl_interleaving_mode = |
| 928 | FSL_DDR_4WAY_8KB_INTERLEAVING; |
| 929 | #endif |
| 930 | } else { |
| 931 | popts->memctl_interleaving = 0; |
| 932 | printf("hwconfig has unrecognized parameter for ctlr_intlv.\n"); |
| 933 | } |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 934 | #endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */ |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 935 | done: |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 936 | #endif /* CONFIG_NUM_DDR_CONTROLLERS > 1 */ |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 937 | if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) && |
Dave Liu | 3ad95de | 2009-11-12 07:26:37 +0800 | [diff] [blame] | 938 | (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) { |
Kumar Gala | 79e4e64 | 2010-07-14 10:04:21 -0500 | [diff] [blame] | 939 | /* test null first. if CONFIG_HWCONFIG is not defined, |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 940 | * hwconfig_subarg_cmp_f returns non-zero */ |
| 941 | if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 942 | "null", buf)) |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 943 | debug("bank interleaving disabled.\n"); |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 944 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 945 | "cs0_cs1", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 946 | popts->ba_intlv_ctl = FSL_DDR_CS0_CS1; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 947 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 948 | "cs2_cs3", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 949 | popts->ba_intlv_ctl = FSL_DDR_CS2_CS3; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 950 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 951 | "cs0_cs1_and_cs2_cs3", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 952 | popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 953 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 954 | "cs0_cs1_cs2_cs3", buf)) |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 955 | popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3; |
York Sun | 89b7809 | 2012-10-08 07:44:27 +0000 | [diff] [blame] | 956 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv", |
| 957 | "auto", buf)) |
| 958 | popts->ba_intlv_ctl = auto_bank_intlv(pdimm); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 959 | else |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 960 | printf("hwconfig has unrecognized parameter for bank_intlv.\n"); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 961 | switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) { |
| 962 | case FSL_DDR_CS0_CS1_CS2_CS3: |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 963 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 964 | if (pdimm[0].n_ranks < 4) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 965 | popts->ba_intlv_ctl = 0; |
| 966 | printf("Not enough bank(chip-select) for " |
| 967 | "CS0+CS1+CS2+CS3 on controller %d, " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 968 | "interleaving disabled!\n", ctrl_num); |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 969 | } |
| 970 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
York Sun | 123922b | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 971 | #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE |
| 972 | if (pdimm[0].n_ranks == 4) |
| 973 | break; |
| 974 | #endif |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 975 | if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 976 | popts->ba_intlv_ctl = 0; |
| 977 | printf("Not enough bank(chip-select) for " |
| 978 | "CS0+CS1+CS2+CS3 on controller %d, " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 979 | "interleaving disabled!\n", ctrl_num); |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 980 | } |
| 981 | if (pdimm[0].capacity != pdimm[1].capacity) { |
| 982 | popts->ba_intlv_ctl = 0; |
| 983 | printf("Not identical DIMM size for " |
| 984 | "CS0+CS1+CS2+CS3 on controller %d, " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 985 | "interleaving disabled!\n", ctrl_num); |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 986 | } |
| 987 | #endif |
| 988 | break; |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 989 | case FSL_DDR_CS0_CS1: |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 990 | if (pdimm[0].n_ranks < 2) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 991 | popts->ba_intlv_ctl = 0; |
Ed Swarthout | 7008d26 | 2008-10-29 09:21:44 -0500 | [diff] [blame] | 992 | printf("Not enough bank(chip-select) for " |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 993 | "CS0+CS1 on controller %d, " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 994 | "interleaving disabled!\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 995 | } |
| 996 | break; |
| 997 | case FSL_DDR_CS2_CS3: |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 998 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 999 | if (pdimm[0].n_ranks < 4) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 1000 | popts->ba_intlv_ctl = 0; |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1001 | printf("Not enough bank(chip-select) for CS2+CS3 " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1002 | "on controller %d, interleaving disabled!\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 1003 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1004 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 1005 | if (pdimm[1].n_ranks < 2) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1006 | popts->ba_intlv_ctl = 0; |
| 1007 | printf("Not enough bank(chip-select) for CS2+CS3 " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1008 | "on controller %d, interleaving disabled!\n", ctrl_num); |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1009 | } |
| 1010 | #endif |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 1011 | break; |
| 1012 | case FSL_DDR_CS0_CS1_AND_CS2_CS3: |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1013 | #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 1014 | if (pdimm[0].n_ranks < 4) { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1015 | popts->ba_intlv_ctl = 0; |
| 1016 | printf("Not enough bank(CS) for CS0+CS1 and " |
| 1017 | "CS2+CS3 on controller %d, " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1018 | "interleaving disabled!\n", ctrl_num); |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1019 | } |
| 1020 | #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2) |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 1021 | if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) { |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 1022 | popts->ba_intlv_ctl = 0; |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1023 | printf("Not enough bank(CS) for CS0+CS1 and " |
| 1024 | "CS2+CS3 on controller %d, " |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1025 | "interleaving disabled!\n", ctrl_num); |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 1026 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1027 | #endif |
Haiying Wang | c9ffd83 | 2008-10-03 12:37:10 -0400 | [diff] [blame] | 1028 | break; |
| 1029 | default: |
| 1030 | popts->ba_intlv_ctl = 0; |
| 1031 | break; |
| 1032 | } |
| 1033 | } |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1034 | |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 1035 | if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) { |
| 1036 | if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf)) |
york | 7fd101c | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 1037 | popts->addr_hash = 0; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 1038 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", |
| 1039 | "true", buf)) |
york | 7fd101c | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 1040 | popts->addr_hash = 1; |
| 1041 | } |
| 1042 | |
york | 5800e7a | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 1043 | if (pdimm[0].n_ranks == 4) |
| 1044 | popts->quad_rank_present = 1; |
| 1045 | |
York Sun | 03e664d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 1046 | ddr_freq = get_ddr_freq(ctrl_num) / 1000000; |
York Sun | cda1de2 | 2011-08-24 09:40:26 -0700 | [diff] [blame] | 1047 | if (popts->registered_dimm_en) { |
| 1048 | popts->rcw_override = 1; |
| 1049 | popts->rcw_1 = 0x000a5a00; |
| 1050 | if (ddr_freq <= 800) |
| 1051 | popts->rcw_2 = 0x00000000; |
| 1052 | else if (ddr_freq <= 1066) |
| 1053 | popts->rcw_2 = 0x00100000; |
| 1054 | else if (ddr_freq <= 1333) |
| 1055 | popts->rcw_2 = 0x00200000; |
| 1056 | else |
| 1057 | popts->rcw_2 = 0x00300000; |
| 1058 | } |
| 1059 | |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 1060 | fsl_ddr_board_options(popts, pdimm, ctrl_num); |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1061 | |
| 1062 | return 0; |
| 1063 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1064 | |
| 1065 | void check_interleaving_options(fsl_ddr_info_t *pinfo) |
| 1066 | { |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1067 | int i, j, k, check_n_ranks, intlv_invalid = 0; |
| 1068 | unsigned int check_intlv, check_n_row_addr, check_n_col_addr; |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1069 | unsigned long long check_rank_density; |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1070 | struct dimm_params_s *dimm; |
York Sun | 1d71efb | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 1071 | int first_ctrl = pinfo->first_ctrl; |
| 1072 | int last_ctrl = first_ctrl + pinfo->num_ctrls - 1; |
| 1073 | |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1074 | /* |
| 1075 | * Check if all controllers are configured for memory |
| 1076 | * controller interleaving. Identical dimms are recommended. At least |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1077 | * the size, row and col address should be checked. |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1078 | */ |
| 1079 | j = 0; |
York Sun | 1d71efb | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 1080 | check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks; |
| 1081 | check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density; |
| 1082 | check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr; |
| 1083 | check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr; |
| 1084 | check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode; |
| 1085 | for (i = first_ctrl; i <= last_ctrl; i++) { |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1086 | dimm = &pinfo->dimm_params[i][0]; |
| 1087 | if (!pinfo->memctl_opts[i].memctl_interleaving) { |
| 1088 | continue; |
| 1089 | } else if (((check_rank_density != dimm->rank_density) || |
| 1090 | (check_n_ranks != dimm->n_ranks) || |
| 1091 | (check_n_row_addr != dimm->n_row_addr) || |
| 1092 | (check_n_col_addr != dimm->n_col_addr) || |
| 1093 | (check_intlv != |
| 1094 | pinfo->memctl_opts[i].memctl_interleaving_mode))){ |
| 1095 | intlv_invalid = 1; |
| 1096 | break; |
| 1097 | } else { |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1098 | j++; |
| 1099 | } |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1100 | |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1101 | } |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1102 | if (intlv_invalid) { |
York Sun | 1d71efb | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 1103 | for (i = first_ctrl; i <= last_ctrl; i++) |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1104 | pinfo->memctl_opts[i].memctl_interleaving = 0; |
| 1105 | printf("Not all DIMMs are identical. " |
| 1106 | "Memory controller interleaving disabled.\n"); |
| 1107 | } else { |
| 1108 | switch (check_intlv) { |
York Sun | 6b1e125 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 1109 | case FSL_DDR_256B_INTERLEAVING: |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1110 | case FSL_DDR_CACHE_LINE_INTERLEAVING: |
| 1111 | case FSL_DDR_PAGE_INTERLEAVING: |
| 1112 | case FSL_DDR_BANK_INTERLEAVING: |
| 1113 | case FSL_DDR_SUPERBANK_INTERLEAVING: |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 1114 | #if (3 == CONFIG_NUM_DDR_CONTROLLERS) |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1115 | k = 2; |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 1116 | #else |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1117 | k = CONFIG_NUM_DDR_CONTROLLERS; |
York Sun | 349689b | 2014-04-01 14:20:49 -0700 | [diff] [blame] | 1118 | #endif |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | case FSL_DDR_3WAY_1KB_INTERLEAVING: |
| 1121 | case FSL_DDR_3WAY_4KB_INTERLEAVING: |
| 1122 | case FSL_DDR_3WAY_8KB_INTERLEAVING: |
| 1123 | case FSL_DDR_4WAY_1KB_INTERLEAVING: |
| 1124 | case FSL_DDR_4WAY_4KB_INTERLEAVING: |
| 1125 | case FSL_DDR_4WAY_8KB_INTERLEAVING: |
| 1126 | default: |
| 1127 | k = CONFIG_NUM_DDR_CONTROLLERS; |
| 1128 | break; |
| 1129 | } |
| 1130 | debug("%d of %d controllers are interleaving.\n", j, k); |
York Sun | 89b7809 | 2012-10-08 07:44:27 +0000 | [diff] [blame] | 1131 | if (j && (j != k)) { |
York Sun | 1d71efb | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 1132 | for (i = first_ctrl; i <= last_ctrl; i++) |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1133 | pinfo->memctl_opts[i].memctl_interleaving = 0; |
York Sun | 1d71efb | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 1134 | if ((last_ctrl - first_ctrl) > 1) |
| 1135 | puts("Not all controllers have compatible interleaving mode. All disabled.\n"); |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1136 | } |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1137 | } |
York Sun | a4c6650 | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 1138 | debug("Checking interleaving options completed\n"); |
york | 076bff8 | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1139 | } |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 1140 | |
| 1141 | int fsl_use_spd(void) |
| 1142 | { |
| 1143 | int use_spd = 0; |
| 1144 | |
| 1145 | #ifdef CONFIG_DDR_SPD |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 1146 | char buffer[HWCONFIG_BUFFER_SIZE]; |
| 1147 | char *buf = NULL; |
| 1148 | |
| 1149 | /* |
| 1150 | * Extract hwconfig from environment since we have not properly setup |
| 1151 | * the environment but need it for ddr config params |
| 1152 | */ |
| 1153 | if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0) |
| 1154 | buf = buffer; |
| 1155 | |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 1156 | /* if hwconfig is not enabled, or "sdram" is not defined, use spd */ |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 1157 | if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) { |
| 1158 | if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf)) |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 1159 | use_spd = 1; |
Kumar Gala | dd50af2 | 2011-01-09 11:37:00 -0600 | [diff] [blame] | 1160 | else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", |
| 1161 | "fixed", buf)) |
Kumar Gala | 3dbd5d7 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 1162 | use_spd = 0; |
| 1163 | else |
| 1164 | use_spd = 1; |
| 1165 | } else |
| 1166 | use_spd = 1; |
| 1167 | #endif |
| 1168 | |
| 1169 | return use_spd; |
| 1170 | } |