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