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-2016 Freescale Semiconductor, Inc. |
| 4 | * Copyright 2017-2018 NXP Semiconductor |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 8 | #include <fsl_ddr_sdram.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 10 | #include <asm/bitops.h> |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 11 | |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 12 | #include <fsl_ddr.h> |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 13 | |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 14 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
Kim Phillips | 82f576f | 2012-10-29 13:34:37 +0000 | [diff] [blame] | 15 | static unsigned int |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 16 | compute_cas_latency(const unsigned int ctrl_num, |
| 17 | const dimm_params_t *dimm_params, |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 18 | common_timing_params_t *outpdimm, |
| 19 | unsigned int number_of_dimms) |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 20 | { |
| 21 | unsigned int i; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 22 | unsigned int common_caslat; |
| 23 | unsigned int caslat_actual; |
| 24 | unsigned int retry = 16; |
York Sun | fc63b28 | 2015-03-19 09:30:27 -0700 | [diff] [blame] | 25 | unsigned int tmp = ~0; |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 26 | const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 27 | #ifdef CONFIG_SYS_FSL_DDR3 |
| 28 | const unsigned int taamax = 20000; |
| 29 | #else |
| 30 | const unsigned int taamax = 18000; |
| 31 | #endif |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 32 | |
| 33 | /* compute the common CAS latency supported between slots */ |
York Sun | fc63b28 | 2015-03-19 09:30:27 -0700 | [diff] [blame] | 34 | for (i = 0; i < number_of_dimms; i++) { |
York Sun | fa3ede5 | 2012-08-17 08:22:41 +0000 | [diff] [blame] | 35 | if (dimm_params[i].n_ranks) |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 36 | tmp &= dimm_params[i].caslat_x; |
York Sun | fa3ede5 | 2012-08-17 08:22:41 +0000 | [diff] [blame] | 37 | } |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 38 | common_caslat = tmp; |
| 39 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 40 | /* validate if the memory clk is in the range of dimms */ |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 41 | if (mclk_ps < outpdimm->tckmin_x_ps) { |
York Sun | c04da04 | 2011-05-06 07:14:14 +0800 | [diff] [blame] | 42 | printf("DDR clock (MCLK cycle %u ps) is faster than " |
| 43 | "the slowest DIMM(s) (tCKmin %u ps) can support.\n", |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 44 | mclk_ps, outpdimm->tckmin_x_ps); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 45 | } |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 46 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 47 | if (mclk_ps > outpdimm->tckmax_ps) { |
| 48 | printf("DDR clock (MCLK cycle %u ps) is slower than DIMM(s) (tCKmax %u ps) can support.\n", |
| 49 | mclk_ps, outpdimm->tckmax_ps); |
| 50 | } |
| 51 | #endif |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 52 | /* determine the acutal cas latency */ |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 53 | caslat_actual = (outpdimm->taamin_ps + mclk_ps - 1) / mclk_ps; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 54 | /* check if the dimms support the CAS latency */ |
| 55 | while (!(common_caslat & (1 << caslat_actual)) && retry > 0) { |
| 56 | caslat_actual++; |
| 57 | retry--; |
| 58 | } |
| 59 | /* once the caculation of caslat_actual is completed |
| 60 | * we must verify that this CAS latency value does not |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 61 | * exceed tAAmax, which is 20 ns for all DDR3 speed grades, |
| 62 | * 18ns for all DDR4 speed grades. |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 63 | */ |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 64 | if (caslat_actual * mclk_ps > taamax) { |
Alexander Merkle | 0137e60 | 2016-03-17 15:44:47 +0100 | [diff] [blame] | 65 | printf("The chosen cas latency %d is too large\n", |
| 66 | caslat_actual); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 67 | } |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 68 | outpdimm->lowest_common_spd_caslat = caslat_actual; |
| 69 | debug("lowest_common_spd_caslat is 0x%x\n", caslat_actual); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 73 | #else /* for DDR1 and DDR2 */ |
| 74 | static unsigned int |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 75 | compute_cas_latency(const unsigned int ctrl_num, |
| 76 | const dimm_params_t *dimm_params, |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 77 | common_timing_params_t *outpdimm, |
| 78 | unsigned int number_of_dimms) |
| 79 | { |
| 80 | int i; |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 81 | const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 82 | unsigned int lowest_good_caslat; |
| 83 | unsigned int not_ok; |
| 84 | unsigned int temp1, temp2; |
| 85 | |
| 86 | debug("using mclk_ps = %u\n", mclk_ps); |
| 87 | if (mclk_ps > outpdimm->tckmax_ps) { |
| 88 | printf("Warning: DDR clock (%u ps) is slower than DIMM(s) (tCKmax %u ps)\n", |
| 89 | mclk_ps, outpdimm->tckmax_ps); |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Compute a CAS latency suitable for all DIMMs |
| 94 | * |
| 95 | * Strategy for SPD-defined latencies: compute only |
| 96 | * CAS latency defined by all DIMMs. |
| 97 | */ |
| 98 | |
| 99 | /* |
| 100 | * Step 1: find CAS latency common to all DIMMs using bitwise |
| 101 | * operation. |
| 102 | */ |
| 103 | temp1 = 0xFF; |
| 104 | for (i = 0; i < number_of_dimms; i++) { |
| 105 | if (dimm_params[i].n_ranks) { |
| 106 | temp2 = 0; |
| 107 | temp2 |= 1 << dimm_params[i].caslat_x; |
| 108 | temp2 |= 1 << dimm_params[i].caslat_x_minus_1; |
| 109 | temp2 |= 1 << dimm_params[i].caslat_x_minus_2; |
| 110 | /* |
| 111 | * If there was no entry for X-2 (X-1) in |
| 112 | * the SPD, then caslat_x_minus_2 |
| 113 | * (caslat_x_minus_1) contains either 255 or |
| 114 | * 0xFFFFFFFF because that's what the glorious |
| 115 | * __ilog2 function returns for an input of 0. |
| 116 | * On 32-bit PowerPC, left shift counts with bit |
| 117 | * 26 set (that the value of 255 or 0xFFFFFFFF |
| 118 | * will have), cause the destination register to |
| 119 | * be 0. That is why this works. |
| 120 | */ |
| 121 | temp1 &= temp2; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Step 2: check each common CAS latency against tCK of each |
| 127 | * DIMM's SPD. |
| 128 | */ |
| 129 | lowest_good_caslat = 0; |
| 130 | temp2 = 0; |
| 131 | while (temp1) { |
| 132 | not_ok = 0; |
| 133 | temp2 = __ilog2(temp1); |
| 134 | debug("checking common caslat = %u\n", temp2); |
| 135 | |
| 136 | /* Check if this CAS latency will work on all DIMMs at tCK. */ |
| 137 | for (i = 0; i < number_of_dimms; i++) { |
| 138 | if (!dimm_params[i].n_ranks) |
| 139 | continue; |
| 140 | |
| 141 | if (dimm_params[i].caslat_x == temp2) { |
| 142 | if (mclk_ps >= dimm_params[i].tckmin_x_ps) { |
| 143 | debug("CL = %u ok on DIMM %u at tCK=%u ps with tCKmin_X_ps of %u\n", |
| 144 | temp2, i, mclk_ps, |
| 145 | dimm_params[i].tckmin_x_ps); |
| 146 | continue; |
| 147 | } else { |
| 148 | not_ok++; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (dimm_params[i].caslat_x_minus_1 == temp2) { |
| 153 | unsigned int tckmin_x_minus_1_ps |
| 154 | = dimm_params[i].tckmin_x_minus_1_ps; |
| 155 | if (mclk_ps >= tckmin_x_minus_1_ps) { |
| 156 | debug("CL = %u ok on DIMM %u at tCK=%u ps with tckmin_x_minus_1_ps of %u\n", |
| 157 | temp2, i, mclk_ps, |
| 158 | tckmin_x_minus_1_ps); |
| 159 | continue; |
| 160 | } else { |
| 161 | not_ok++; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (dimm_params[i].caslat_x_minus_2 == temp2) { |
| 166 | unsigned int tckmin_x_minus_2_ps |
| 167 | = dimm_params[i].tckmin_x_minus_2_ps; |
| 168 | if (mclk_ps >= tckmin_x_minus_2_ps) { |
| 169 | debug("CL = %u ok on DIMM %u at tCK=%u ps with tckmin_x_minus_2_ps of %u\n", |
| 170 | temp2, i, mclk_ps, |
| 171 | tckmin_x_minus_2_ps); |
| 172 | continue; |
| 173 | } else { |
| 174 | not_ok++; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if (!not_ok) |
| 180 | lowest_good_caslat = temp2; |
| 181 | |
| 182 | temp1 &= ~(1 << temp2); |
| 183 | } |
| 184 | |
| 185 | debug("lowest common SPD-defined CAS latency = %u\n", |
| 186 | lowest_good_caslat); |
| 187 | outpdimm->lowest_common_spd_caslat = lowest_good_caslat; |
| 188 | |
| 189 | |
| 190 | /* |
| 191 | * Compute a common 'de-rated' CAS latency. |
| 192 | * |
| 193 | * The strategy here is to find the *highest* dereated cas latency |
| 194 | * with the assumption that all of the DIMMs will support a dereated |
| 195 | * CAS latency higher than or equal to their lowest dereated value. |
| 196 | */ |
| 197 | temp1 = 0; |
| 198 | for (i = 0; i < number_of_dimms; i++) |
| 199 | temp1 = max(temp1, dimm_params[i].caslat_lowest_derated); |
| 200 | |
| 201 | outpdimm->highest_common_derated_caslat = temp1; |
| 202 | debug("highest common dereated CAS latency = %u\n", temp1); |
| 203 | |
| 204 | return 0; |
| 205 | } |
Kim Phillips | 82f576f | 2012-10-29 13:34:37 +0000 | [diff] [blame] | 206 | #endif |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 207 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 208 | /* |
| 209 | * compute_lowest_common_dimm_parameters() |
| 210 | * |
| 211 | * Determine the worst-case DIMM timing parameters from the set of DIMMs |
| 212 | * whose parameters have been computed into the array pointed to |
| 213 | * by dimm_params. |
| 214 | */ |
| 215 | unsigned int |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 216 | compute_lowest_common_dimm_parameters(const unsigned int ctrl_num, |
| 217 | const dimm_params_t *dimm_params, |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 218 | common_timing_params_t *outpdimm, |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 219 | const unsigned int number_of_dimms) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 220 | { |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 221 | unsigned int i, j; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 222 | |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 223 | unsigned int tckmin_x_ps = 0; |
| 224 | unsigned int tckmax_ps = 0xFFFFFFFF; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 225 | unsigned int trcd_ps = 0; |
| 226 | unsigned int trp_ps = 0; |
| 227 | unsigned int tras_ps = 0; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 228 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
| 229 | unsigned int taamin_ps = 0; |
| 230 | #endif |
| 231 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 232 | unsigned int twr_ps = 15000; |
| 233 | unsigned int trfc1_ps = 0; |
| 234 | unsigned int trfc2_ps = 0; |
| 235 | unsigned int trfc4_ps = 0; |
| 236 | unsigned int trrds_ps = 0; |
| 237 | unsigned int trrdl_ps = 0; |
| 238 | unsigned int tccdl_ps = 0; |
York Sun | 6db4fdd | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 239 | unsigned int trfc_slr_ps = 0; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 240 | #else |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 241 | unsigned int twr_ps = 0; |
| 242 | unsigned int twtr_ps = 0; |
| 243 | unsigned int trfc_ps = 0; |
| 244 | unsigned int trrd_ps = 0; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 245 | unsigned int trtp_ps = 0; |
| 246 | #endif |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 247 | unsigned int trc_ps = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 248 | unsigned int refresh_rate_ps = 0; |
Valentin Longchamp | 0b81093 | 2013-10-18 11:47:20 +0200 | [diff] [blame] | 249 | unsigned int extended_op_srt = 1; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 250 | #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2) |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 251 | unsigned int tis_ps = 0; |
| 252 | unsigned int tih_ps = 0; |
| 253 | unsigned int tds_ps = 0; |
| 254 | unsigned int tdh_ps = 0; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 255 | unsigned int tdqsq_max_ps = 0; |
| 256 | unsigned int tqhs_ps = 0; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 257 | #endif |
York Sun | d56624f | 2011-01-10 12:02:56 +0000 | [diff] [blame] | 258 | unsigned int temp1, temp2; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 259 | unsigned int additive_latency = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 260 | |
| 261 | temp1 = 0; |
| 262 | for (i = 0; i < number_of_dimms; i++) { |
| 263 | /* |
| 264 | * If there are no ranks on this DIMM, |
| 265 | * it probably doesn't exist, so skip it. |
| 266 | */ |
| 267 | if (dimm_params[i].n_ranks == 0) { |
| 268 | temp1++; |
| 269 | continue; |
| 270 | } |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 271 | if (dimm_params[i].n_ranks == 4 && i != 0) { |
| 272 | printf("Found Quad-rank DIMM in wrong bank, ignored." |
| 273 | " Software may not run as expected.\n"); |
| 274 | temp1++; |
| 275 | continue; |
| 276 | } |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * check if quad-rank DIMM is plugged if |
| 280 | * CONFIG_CHIP_SELECT_QUAD_CAPABLE is not defined |
| 281 | * Only the board with proper design is capable |
| 282 | */ |
| 283 | #ifndef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 284 | if (dimm_params[i].n_ranks == 4 && \ |
| 285 | CONFIG_CHIP_SELECTS_PER_CTRL/CONFIG_DIMM_SLOTS_PER_CTLR < 4) { |
| 286 | printf("Found Quad-rank DIMM, not able to support."); |
| 287 | temp1++; |
| 288 | continue; |
| 289 | } |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 290 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 291 | /* |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 292 | * Find minimum tckmax_ps to find fastest slow speed, |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 293 | * i.e., this is the slowest the whole system can go. |
| 294 | */ |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 295 | tckmax_ps = min(tckmax_ps, |
| 296 | (unsigned int)dimm_params[i].tckmax_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 297 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 298 | taamin_ps = max(taamin_ps, |
| 299 | (unsigned int)dimm_params[i].taa_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 300 | #endif |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 301 | tckmin_x_ps = max(tckmin_x_ps, |
| 302 | (unsigned int)dimm_params[i].tckmin_x_ps); |
| 303 | trcd_ps = max(trcd_ps, (unsigned int)dimm_params[i].trcd_ps); |
| 304 | trp_ps = max(trp_ps, (unsigned int)dimm_params[i].trp_ps); |
| 305 | tras_ps = max(tras_ps, (unsigned int)dimm_params[i].tras_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 306 | #ifdef CONFIG_SYS_FSL_DDR4 |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 307 | trfc1_ps = max(trfc1_ps, |
| 308 | (unsigned int)dimm_params[i].trfc1_ps); |
| 309 | trfc2_ps = max(trfc2_ps, |
| 310 | (unsigned int)dimm_params[i].trfc2_ps); |
| 311 | trfc4_ps = max(trfc4_ps, |
| 312 | (unsigned int)dimm_params[i].trfc4_ps); |
| 313 | trrds_ps = max(trrds_ps, |
| 314 | (unsigned int)dimm_params[i].trrds_ps); |
| 315 | trrdl_ps = max(trrdl_ps, |
| 316 | (unsigned int)dimm_params[i].trrdl_ps); |
| 317 | tccdl_ps = max(tccdl_ps, |
| 318 | (unsigned int)dimm_params[i].tccdl_ps); |
York Sun | 6db4fdd | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 319 | trfc_slr_ps = max(trfc_slr_ps, |
| 320 | (unsigned int)dimm_params[i].trfc_slr_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 321 | #else |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 322 | twr_ps = max(twr_ps, (unsigned int)dimm_params[i].twr_ps); |
| 323 | twtr_ps = max(twtr_ps, (unsigned int)dimm_params[i].twtr_ps); |
| 324 | trfc_ps = max(trfc_ps, (unsigned int)dimm_params[i].trfc_ps); |
| 325 | trrd_ps = max(trrd_ps, (unsigned int)dimm_params[i].trrd_ps); |
| 326 | trtp_ps = max(trtp_ps, (unsigned int)dimm_params[i].trtp_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 327 | #endif |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 328 | trc_ps = max(trc_ps, (unsigned int)dimm_params[i].trc_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 329 | #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 330 | tis_ps = max(tis_ps, (unsigned int)dimm_params[i].tis_ps); |
| 331 | tih_ps = max(tih_ps, (unsigned int)dimm_params[i].tih_ps); |
| 332 | tds_ps = max(tds_ps, (unsigned int)dimm_params[i].tds_ps); |
| 333 | tdh_ps = max(tdh_ps, (unsigned int)dimm_params[i].tdh_ps); |
| 334 | tqhs_ps = max(tqhs_ps, (unsigned int)dimm_params[i].tqhs_ps); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 335 | /* |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 336 | * Find maximum tdqsq_max_ps to find slowest. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 337 | * |
| 338 | * FIXME: is finding the slowest value the correct |
| 339 | * strategy for this parameter? |
| 340 | */ |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 341 | tdqsq_max_ps = max(tdqsq_max_ps, |
| 342 | (unsigned int)dimm_params[i].tdqsq_max_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 343 | #endif |
| 344 | refresh_rate_ps = max(refresh_rate_ps, |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 345 | (unsigned int)dimm_params[i].refresh_rate_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 346 | /* extended_op_srt is either 0 or 1, 0 having priority */ |
| 347 | extended_op_srt = min(extended_op_srt, |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 348 | (unsigned int)dimm_params[i].extended_op_srt); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | outpdimm->ndimms_present = number_of_dimms - temp1; |
| 352 | |
| 353 | if (temp1 == number_of_dimms) { |
| 354 | debug("no dimms this memory controller\n"); |
| 355 | return 0; |
| 356 | } |
| 357 | |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 358 | outpdimm->tckmin_x_ps = tckmin_x_ps; |
| 359 | outpdimm->tckmax_ps = tckmax_ps; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 360 | #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4) |
| 361 | outpdimm->taamin_ps = taamin_ps; |
| 362 | #endif |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 363 | outpdimm->trcd_ps = trcd_ps; |
| 364 | outpdimm->trp_ps = trp_ps; |
| 365 | outpdimm->tras_ps = tras_ps; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 366 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 367 | outpdimm->trfc1_ps = trfc1_ps; |
| 368 | outpdimm->trfc2_ps = trfc2_ps; |
| 369 | outpdimm->trfc4_ps = trfc4_ps; |
| 370 | outpdimm->trrds_ps = trrds_ps; |
| 371 | outpdimm->trrdl_ps = trrdl_ps; |
| 372 | outpdimm->tccdl_ps = tccdl_ps; |
York Sun | 6db4fdd | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 373 | outpdimm->trfc_slr_ps = trfc_slr_ps; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 374 | #else |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 375 | outpdimm->twtr_ps = twtr_ps; |
| 376 | outpdimm->trfc_ps = trfc_ps; |
| 377 | outpdimm->trrd_ps = trrd_ps; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 378 | outpdimm->trtp_ps = trtp_ps; |
| 379 | #endif |
| 380 | outpdimm->twr_ps = twr_ps; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 381 | outpdimm->trc_ps = trc_ps; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 382 | outpdimm->refresh_rate_ps = refresh_rate_ps; |
Valentin Longchamp | 0b81093 | 2013-10-18 11:47:20 +0200 | [diff] [blame] | 383 | outpdimm->extended_op_srt = extended_op_srt; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 384 | #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2) |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 385 | outpdimm->tis_ps = tis_ps; |
| 386 | outpdimm->tih_ps = tih_ps; |
| 387 | outpdimm->tds_ps = tds_ps; |
| 388 | outpdimm->tdh_ps = tdh_ps; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 389 | outpdimm->tdqsq_max_ps = tdqsq_max_ps; |
| 390 | outpdimm->tqhs_ps = tqhs_ps; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 391 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 392 | |
| 393 | /* Determine common burst length for all DIMMs. */ |
| 394 | temp1 = 0xff; |
| 395 | for (i = 0; i < number_of_dimms; i++) { |
| 396 | if (dimm_params[i].n_ranks) { |
| 397 | temp1 &= dimm_params[i].burst_lengths_bitmask; |
| 398 | } |
| 399 | } |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 400 | outpdimm->all_dimms_burst_lengths_bitmask = temp1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 401 | |
| 402 | /* Determine if all DIMMs registered buffered. */ |
| 403 | temp1 = temp2 = 0; |
| 404 | for (i = 0; i < number_of_dimms; i++) { |
| 405 | if (dimm_params[i].n_ranks) { |
York Sun | b06fcb5 | 2011-02-04 13:58:00 -0800 | [diff] [blame] | 406 | if (dimm_params[i].registered_dimm) { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 407 | temp1 = 1; |
Ying Zhang | 9ff7026 | 2013-08-16 15:16:11 +0800 | [diff] [blame] | 408 | #ifndef CONFIG_SPL_BUILD |
York Sun | b06fcb5 | 2011-02-04 13:58:00 -0800 | [diff] [blame] | 409 | printf("Detected RDIMM %s\n", |
| 410 | dimm_params[i].mpart); |
Ying Zhang | 9ff7026 | 2013-08-16 15:16:11 +0800 | [diff] [blame] | 411 | #endif |
York Sun | b06fcb5 | 2011-02-04 13:58:00 -0800 | [diff] [blame] | 412 | } else { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 413 | temp2 = 1; |
Ying Zhang | 9ff7026 | 2013-08-16 15:16:11 +0800 | [diff] [blame] | 414 | #ifndef CONFIG_SPL_BUILD |
York Sun | b06fcb5 | 2011-02-04 13:58:00 -0800 | [diff] [blame] | 415 | printf("Detected UDIMM %s\n", |
| 416 | dimm_params[i].mpart); |
Ying Zhang | 9ff7026 | 2013-08-16 15:16:11 +0800 | [diff] [blame] | 417 | #endif |
York Sun | b06fcb5 | 2011-02-04 13:58:00 -0800 | [diff] [blame] | 418 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 422 | outpdimm->all_dimms_registered = 0; |
| 423 | outpdimm->all_dimms_unbuffered = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 424 | if (temp1 && !temp2) { |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 425 | outpdimm->all_dimms_registered = 1; |
York Sun | d56624f | 2011-01-10 12:02:56 +0000 | [diff] [blame] | 426 | } else if (!temp1 && temp2) { |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 427 | outpdimm->all_dimms_unbuffered = 1; |
York Sun | d56624f | 2011-01-10 12:02:56 +0000 | [diff] [blame] | 428 | } else { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 429 | printf("ERROR: Mix of registered buffered and unbuffered " |
| 430 | "DIMMs detected!\n"); |
| 431 | } |
| 432 | |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 433 | temp1 = 0; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 434 | if (outpdimm->all_dimms_registered) |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 435 | for (j = 0; j < 16; j++) { |
| 436 | outpdimm->rcw[j] = dimm_params[0].rcw[j]; |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 437 | for (i = 1; i < number_of_dimms; i++) { |
| 438 | if (!dimm_params[i].n_ranks) |
| 439 | continue; |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 440 | if (dimm_params[i].rcw[j] != dimm_params[0].rcw[j]) { |
York Sun | d56624f | 2011-01-10 12:02:56 +0000 | [diff] [blame] | 441 | temp1 = 1; |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 442 | break; |
| 443 | } |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 444 | } |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | if (temp1 != 0) |
| 448 | printf("ERROR: Mix different RDIMM detected!\n"); |
| 449 | |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 450 | /* calculate cas latency for all DDR types */ |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 451 | if (compute_cas_latency(ctrl_num, dimm_params, |
| 452 | outpdimm, number_of_dimms)) |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 453 | return 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 454 | |
| 455 | /* Determine if all DIMMs ECC capable. */ |
| 456 | temp1 = 1; |
| 457 | for (i = 0; i < number_of_dimms; i++) { |
York Sun | fbe6595 | 2011-03-17 11:18:10 -0700 | [diff] [blame] | 458 | if (dimm_params[i].n_ranks && |
| 459 | !(dimm_params[i].edc_config & EDC_ECC)) { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 460 | temp1 = 0; |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | if (temp1) { |
| 465 | debug("all DIMMs ECC capable\n"); |
| 466 | } else { |
| 467 | debug("Warning: not all DIMMs ECC capable, cant enable ECC\n"); |
| 468 | } |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 469 | outpdimm->all_dimms_ecc_capable = temp1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 470 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 471 | /* |
| 472 | * Compute additive latency. |
| 473 | * |
| 474 | * For DDR1, additive latency should be 0. |
| 475 | * |
| 476 | * For DDR2, with ODT enabled, use "a value" less than ACTTORW, |
| 477 | * which comes from Trcd, and also note that: |
| 478 | * add_lat + caslat must be >= 4 |
| 479 | * |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 480 | * For DDR3, we use the AL=0 |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 481 | * |
| 482 | * When to use additive latency for DDR2: |
| 483 | * |
| 484 | * I. Because you are using CL=3 and need to do ODT on writes and |
| 485 | * want functionality. |
| 486 | * 1. Are you going to use ODT? (Does your board not have |
| 487 | * additional termination circuitry for DQ, DQS, DQS_, |
| 488 | * DM, RDQS, RDQS_ for x4/x8 configs?) |
| 489 | * 2. If so, is your lowest supported CL going to be 3? |
| 490 | * 3. If so, then you must set AL=1 because |
| 491 | * |
| 492 | * WL >= 3 for ODT on writes |
| 493 | * RL = AL + CL |
| 494 | * WL = RL - 1 |
| 495 | * -> |
| 496 | * WL = AL + CL - 1 |
| 497 | * AL + CL - 1 >= 3 |
| 498 | * AL + CL >= 4 |
| 499 | * QED |
| 500 | * |
| 501 | * RL >= 3 for ODT on reads |
| 502 | * RL = AL + CL |
| 503 | * |
| 504 | * Since CL aren't usually less than 2, AL=0 is a minimum, |
| 505 | * so the WL-derived AL should be the -- FIXME? |
| 506 | * |
| 507 | * II. Because you are using auto-precharge globally and want to |
| 508 | * use additive latency (posted CAS) to get more bandwidth. |
| 509 | * 1. Are you going to use auto-precharge mode globally? |
| 510 | * |
| 511 | * Use addtivie latency and compute AL to be 1 cycle less than |
| 512 | * tRCD, i.e. the READ or WRITE command is in the cycle |
| 513 | * immediately following the ACTIVATE command.. |
| 514 | * |
| 515 | * III. Because you feel like it or want to do some sort of |
| 516 | * degraded-performance experiment. |
| 517 | * 1. Do you just want to use additive latency because you feel |
| 518 | * like it? |
| 519 | * |
| 520 | * Validation: AL is less than tRCD, and within the other |
| 521 | * read-to-precharge constraints. |
| 522 | */ |
| 523 | |
| 524 | additive_latency = 0; |
| 525 | |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 526 | #if defined(CONFIG_SYS_FSL_DDR2) |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 527 | if ((outpdimm->lowest_common_spd_caslat < 4) && |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 528 | (picos_to_mclk(ctrl_num, trcd_ps) > |
| 529 | outpdimm->lowest_common_spd_caslat)) { |
| 530 | additive_latency = picos_to_mclk(ctrl_num, trcd_ps) - |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 531 | outpdimm->lowest_common_spd_caslat; |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 532 | if (mclk_to_picos(ctrl_num, additive_latency) > trcd_ps) { |
| 533 | additive_latency = picos_to_mclk(ctrl_num, trcd_ps); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 534 | debug("setting additive_latency to %u because it was " |
| 535 | " greater than tRCD_ps\n", additive_latency); |
| 536 | } |
| 537 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 538 | #endif |
| 539 | |
| 540 | /* |
| 541 | * Validate additive latency |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 542 | * |
| 543 | * AL <= tRCD(min) |
| 544 | */ |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 545 | if (mclk_to_picos(ctrl_num, additive_latency) > trcd_ps) { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 546 | printf("Error: invalid additive latency exceeds tRCD(min).\n"); |
| 547 | return 1; |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * RL = CL + AL; RL >= 3 for ODT_RD_CFG to be enabled |
| 552 | * WL = RL - 1; WL >= 3 for ODT_WL_CFG to be enabled |
| 553 | * ADD_LAT (the register) must be set to a value less |
| 554 | * than ACTTORW if WL = 1, then AL must be set to 1 |
| 555 | * RD_TO_PRE (the register) must be set to a minimum |
| 556 | * tRTP + AL if AL is nonzero |
| 557 | */ |
| 558 | |
| 559 | /* |
| 560 | * Additive latency will be applied only if the memctl option to |
| 561 | * use it. |
| 562 | */ |
| 563 | outpdimm->additive_latency = additive_latency; |
| 564 | |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 565 | debug("tCKmin_ps = %u\n", outpdimm->tckmin_x_ps); |
| 566 | debug("trcd_ps = %u\n", outpdimm->trcd_ps); |
| 567 | debug("trp_ps = %u\n", outpdimm->trp_ps); |
| 568 | debug("tras_ps = %u\n", outpdimm->tras_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 569 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 570 | debug("trfc1_ps = %u\n", trfc1_ps); |
| 571 | debug("trfc2_ps = %u\n", trfc2_ps); |
| 572 | debug("trfc4_ps = %u\n", trfc4_ps); |
| 573 | debug("trrds_ps = %u\n", trrds_ps); |
| 574 | debug("trrdl_ps = %u\n", trrdl_ps); |
| 575 | debug("tccdl_ps = %u\n", tccdl_ps); |
York Sun | 6db4fdd | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 576 | debug("trfc_slr_ps = %u\n", trfc_slr_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 577 | #else |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 578 | debug("twtr_ps = %u\n", outpdimm->twtr_ps); |
| 579 | debug("trfc_ps = %u\n", outpdimm->trfc_ps); |
| 580 | debug("trrd_ps = %u\n", outpdimm->trrd_ps); |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 581 | #endif |
| 582 | debug("twr_ps = %u\n", outpdimm->twr_ps); |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 583 | debug("trc_ps = %u\n", outpdimm->trc_ps); |
York Sun | cd077cf | 2012-08-17 08:22:40 +0000 | [diff] [blame] | 584 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 585 | return 0; |
| 586 | } |