1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <common.h>
15#include <asm/fsl_ddr_sdram.h>
16
17#include "ddr.h"
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55static unsigned long long
56compute_ranksize(const ddr3_spd_eeprom_t *spd)
57{
58 unsigned long long bsize;
59
60 int nbit_sdram_cap_bsize = 0;
61 int nbit_primary_bus_width = 0;
62 int nbit_sdram_width = 0;
63
64 if ((spd->density_banks & 0xf) < 7)
65 nbit_sdram_cap_bsize = (spd->density_banks & 0xf) + 28;
66 if ((spd->bus_width & 0x7) < 4)
67 nbit_primary_bus_width = (spd->bus_width & 0x7) + 3;
68 if ((spd->organization & 0x7) < 4)
69 nbit_sdram_width = (spd->organization & 0x7) + 2;
70
71 bsize = 1ULL << (nbit_sdram_cap_bsize - 3
72 + nbit_primary_bus_width - nbit_sdram_width);
73
74 debug("DDR: DDR III rank density = 0x%16llx\n", bsize);
75
76 return bsize;
77}
78
79
80
81
82
83
84
85
86unsigned int
87ddr_compute_dimm_parameters(const ddr3_spd_eeprom_t *spd,
88 dimm_params_t *pdimm,
89 unsigned int dimm_number)
90{
91 unsigned int retval;
92 unsigned int mtb_ps;
93 int i;
94
95 if (spd->mem_type) {
96 if (spd->mem_type != SPD_MEMTYPE_DDR3) {
97 printf("DIMM %u: is not a DDR3 SPD.\n", dimm_number);
98 return 1;
99 }
100 } else {
101 memset(pdimm, 0, sizeof(dimm_params_t));
102 return 1;
103 }
104
105 retval = ddr3_spd_check(spd);
106 if (retval) {
107 printf("DIMM %u: failed checksum\n", dimm_number);
108 return 2;
109 }
110
111
112
113
114
115
116 memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
117 if ((spd->info_size_crc & 0xF) > 1)
118 memcpy(pdimm->mpart, spd->mpart, sizeof(pdimm->mpart) - 1);
119
120
121 pdimm->n_ranks = ((spd->organization >> 3) & 0x7) + 1;
122 pdimm->rank_density = compute_ranksize(spd);
123 pdimm->capacity = pdimm->n_ranks * pdimm->rank_density;
124 pdimm->primary_sdram_width = 1 << (3 + (spd->bus_width & 0x7));
125 if ((spd->bus_width >> 3) & 0x3)
126 pdimm->ec_sdram_width = 8;
127 else
128 pdimm->ec_sdram_width = 0;
129 pdimm->data_width = pdimm->primary_sdram_width
130 + pdimm->ec_sdram_width;
131
132
133 pdimm->mirrored_dimm = 0;
134 pdimm->registered_dimm = 0;
135 switch (spd->module_type & DDR3_SPD_MODULETYPE_MASK) {
136 case DDR3_SPD_MODULETYPE_RDIMM:
137 case DDR3_SPD_MODULETYPE_MINI_RDIMM:
138 case DDR3_SPD_MODULETYPE_72B_SO_RDIMM:
139
140 pdimm->registered_dimm = 1;
141 for (i = 0; i < 16; i += 2) {
142 u8 rcw = spd->mod_section.registered.rcw[i/2];
143 pdimm->rcw[i] = (rcw >> 0) & 0x0F;
144 pdimm->rcw[i+1] = (rcw >> 4) & 0x0F;
145 }
146 break;
147
148 case DDR3_SPD_MODULETYPE_UDIMM:
149 case DDR3_SPD_MODULETYPE_SO_DIMM:
150 case DDR3_SPD_MODULETYPE_MICRO_DIMM:
151 case DDR3_SPD_MODULETYPE_MINI_UDIMM:
152 case DDR3_SPD_MODULETYPE_MINI_CDIMM:
153 case DDR3_SPD_MODULETYPE_72B_SO_UDIMM:
154 case DDR3_SPD_MODULETYPE_72B_SO_CDIMM:
155 case DDR3_SPD_MODULETYPE_LRDIMM:
156 case DDR3_SPD_MODULETYPE_16B_SO_DIMM:
157 case DDR3_SPD_MODULETYPE_32B_SO_DIMM:
158
159 if (spd->mod_section.unbuffered.addr_mapping & 0x1)
160 pdimm->mirrored_dimm = 1;
161 break;
162
163 default:
164 printf("unknown module_type 0x%02X\n", spd->module_type);
165 return 1;
166 }
167
168
169 pdimm->n_row_addr = ((spd->addressing >> 3) & 0x7) + 12;
170 pdimm->n_col_addr = (spd->addressing & 0x7) + 9;
171 pdimm->n_banks_per_sdram_device = 8 << ((spd->density_banks >> 4) & 0x7);
172
173
174
175
176
177
178 if (pdimm->ec_sdram_width)
179 pdimm->edc_config = 0x02;
180 else
181 pdimm->edc_config = 0x00;
182
183
184
185
186
187
188 pdimm->burst_lengths_bitmask = 0x0c;
189 pdimm->row_density = __ilog2(pdimm->rank_density);
190
191
192
193
194
195
196 mtb_ps = (spd->mtb_dividend * 1000) /spd->mtb_divisor;
197 pdimm->mtb_ps = mtb_ps;
198
199
200
201
202
203
204
205
206
207 pdimm->tCKmin_X_ps = spd->tCK_min * mtb_ps;
208
209
210
211
212
213
214
215 pdimm->caslat_X = ((spd->caslat_msb << 8) | spd->caslat_lsb) << 4;
216
217
218
219
220
221
222
223
224
225 pdimm->tAA_ps = spd->tAA_min * mtb_ps;
226
227
228
229
230
231
232 pdimm->tWR_ps = spd->tWR_min * mtb_ps;
233
234
235
236
237
238
239
240
241
242 pdimm->tRCD_ps = spd->tRCD_min * mtb_ps;
243
244
245
246
247
248
249
250 pdimm->tRRD_ps = spd->tRRD_min * mtb_ps;
251
252
253
254
255
256
257
258
259
260 pdimm->tRP_ps = spd->tRP_min * mtb_ps;
261
262
263
264
265
266
267
268
269 pdimm->tRAS_ps = (((spd->tRAS_tRC_ext & 0xf) << 8) | spd->tRAS_min_lsb)
270 * mtb_ps;
271
272
273
274
275
276
277
278
279 pdimm->tRC_ps = (((spd->tRAS_tRC_ext & 0xf0) << 4) | spd->tRC_min_lsb)
280 * mtb_ps;
281
282
283
284
285
286
287
288 pdimm->tRFC_ps = ((spd->tRFC_min_msb << 8) | spd->tRFC_min_lsb)
289 * mtb_ps;
290
291
292
293
294
295 pdimm->tWTR_ps = spd->tWTR_min * mtb_ps;
296
297
298
299
300
301
302 pdimm->tRTP_ps = spd->tRTP_min * mtb_ps;
303
304
305
306
307
308
309 pdimm->refresh_rate_ps = 7800000;
310
311
312
313
314
315
316
317
318
319 pdimm->tFAW_ps = (((spd->tFAW_msb & 0xf) << 8) | spd->tFAW_min)
320 * mtb_ps;
321
322 return 0;
323}
324