ddr3_dimm_params.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * Copyright 2008-2012 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. *
  5. * calculate the organization and timing parameter
  6. * from ddr3 spd, please refer to the spec
  7. * JEDEC standard No.21-C 4_01_02_11R18.pdf
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * Version 2 as published by the Free Software Foundation.
  12. */
  13. #include <common.h>
  14. #include <asm/fsl_ddr_sdram.h>
  15. #include "ddr.h"
  16. /*
  17. * Calculate the Density of each Physical Rank.
  18. * Returned size is in bytes.
  19. *
  20. * each rank size =
  21. * sdram capacity(bit) / 8 * primary bus width / sdram width
  22. *
  23. * where: sdram capacity = spd byte4[3:0]
  24. * primary bus width = spd byte8[2:0]
  25. * sdram width = spd byte7[2:0]
  26. *
  27. * SPD byte4 - sdram density and banks
  28. * bit[3:0] size(bit) size(byte)
  29. * 0000 256Mb 32MB
  30. * 0001 512Mb 64MB
  31. * 0010 1Gb 128MB
  32. * 0011 2Gb 256MB
  33. * 0100 4Gb 512MB
  34. * 0101 8Gb 1GB
  35. * 0110 16Gb 2GB
  36. *
  37. * SPD byte8 - module memory bus width
  38. * bit[2:0] primary bus width
  39. * 000 8bits
  40. * 001 16bits
  41. * 010 32bits
  42. * 011 64bits
  43. *
  44. * SPD byte7 - module organiztion
  45. * bit[2:0] sdram device width
  46. * 000 4bits
  47. * 001 8bits
  48. * 010 16bits
  49. * 011 32bits
  50. *
  51. */
  52. static unsigned long long
  53. compute_ranksize(const ddr3_spd_eeprom_t *spd)
  54. {
  55. unsigned long long bsize;
  56. int nbit_sdram_cap_bsize = 0;
  57. int nbit_primary_bus_width = 0;
  58. int nbit_sdram_width = 0;
  59. if ((spd->density_banks & 0xf) < 7)
  60. nbit_sdram_cap_bsize = (spd->density_banks & 0xf) + 28;
  61. if ((spd->bus_width & 0x7) < 4)
  62. nbit_primary_bus_width = (spd->bus_width & 0x7) + 3;
  63. if ((spd->organization & 0x7) < 4)
  64. nbit_sdram_width = (spd->organization & 0x7) + 2;
  65. bsize = 1ULL << (nbit_sdram_cap_bsize - 3
  66. + nbit_primary_bus_width - nbit_sdram_width);
  67. debug("DDR: DDR III rank density = 0x%16llx\n", bsize);
  68. return bsize;
  69. }
  70. /*
  71. * ddr_compute_dimm_parameters for DDR3 SPD
  72. *
  73. * Compute DIMM parameters based upon the SPD information in spd.
  74. * Writes the results to the dimm_params_t structure pointed by pdimm.
  75. *
  76. */
  77. unsigned int
  78. ddr_compute_dimm_parameters(const ddr3_spd_eeprom_t *spd,
  79. dimm_params_t *pdimm,
  80. unsigned int dimm_number)
  81. {
  82. unsigned int retval;
  83. unsigned int mtb_ps;
  84. int ftb_10th_ps;
  85. int i;
  86. if (spd->mem_type) {
  87. if (spd->mem_type != SPD_MEMTYPE_DDR3) {
  88. printf("DIMM %u: is not a DDR3 SPD.\n", dimm_number);
  89. return 1;
  90. }
  91. } else {
  92. memset(pdimm, 0, sizeof(dimm_params_t));
  93. return 1;
  94. }
  95. retval = ddr3_spd_check(spd);
  96. if (retval) {
  97. printf("DIMM %u: failed checksum\n", dimm_number);
  98. return 2;
  99. }
  100. /*
  101. * The part name in ASCII in the SPD EEPROM is not null terminated.
  102. * Guarantee null termination here by presetting all bytes to 0
  103. * and copying the part name in ASCII from the SPD onto it
  104. */
  105. memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
  106. if ((spd->info_size_crc & 0xF) > 1)
  107. memcpy(pdimm->mpart, spd->mpart, sizeof(pdimm->mpart) - 1);
  108. /* DIMM organization parameters */
  109. pdimm->n_ranks = ((spd->organization >> 3) & 0x7) + 1;
  110. pdimm->rank_density = compute_ranksize(spd);
  111. pdimm->capacity = pdimm->n_ranks * pdimm->rank_density;
  112. pdimm->primary_sdram_width = 1 << (3 + (spd->bus_width & 0x7));
  113. if ((spd->bus_width >> 3) & 0x3)
  114. pdimm->ec_sdram_width = 8;
  115. else
  116. pdimm->ec_sdram_width = 0;
  117. pdimm->data_width = pdimm->primary_sdram_width
  118. + pdimm->ec_sdram_width;
  119. pdimm->device_width = 1 << ((spd->organization & 0x7) + 2);
  120. /* These are the types defined by the JEDEC DDR3 SPD spec */
  121. pdimm->mirrored_dimm = 0;
  122. pdimm->registered_dimm = 0;
  123. switch (spd->module_type & DDR3_SPD_MODULETYPE_MASK) {
  124. case DDR3_SPD_MODULETYPE_RDIMM:
  125. case DDR3_SPD_MODULETYPE_MINI_RDIMM:
  126. case DDR3_SPD_MODULETYPE_72B_SO_RDIMM:
  127. /* Registered/buffered DIMMs */
  128. pdimm->registered_dimm = 1;
  129. for (i = 0; i < 16; i += 2) {
  130. u8 rcw = spd->mod_section.registered.rcw[i/2];
  131. pdimm->rcw[i] = (rcw >> 0) & 0x0F;
  132. pdimm->rcw[i+1] = (rcw >> 4) & 0x0F;
  133. }
  134. break;
  135. case DDR3_SPD_MODULETYPE_UDIMM:
  136. case DDR3_SPD_MODULETYPE_SO_DIMM:
  137. case DDR3_SPD_MODULETYPE_MICRO_DIMM:
  138. case DDR3_SPD_MODULETYPE_MINI_UDIMM:
  139. case DDR3_SPD_MODULETYPE_MINI_CDIMM:
  140. case DDR3_SPD_MODULETYPE_72B_SO_UDIMM:
  141. case DDR3_SPD_MODULETYPE_72B_SO_CDIMM:
  142. case DDR3_SPD_MODULETYPE_LRDIMM:
  143. case DDR3_SPD_MODULETYPE_16B_SO_DIMM:
  144. case DDR3_SPD_MODULETYPE_32B_SO_DIMM:
  145. /* Unbuffered DIMMs */
  146. if (spd->mod_section.unbuffered.addr_mapping & 0x1)
  147. pdimm->mirrored_dimm = 1;
  148. break;
  149. default:
  150. printf("unknown module_type 0x%02X\n", spd->module_type);
  151. return 1;
  152. }
  153. /* SDRAM device parameters */
  154. pdimm->n_row_addr = ((spd->addressing >> 3) & 0x7) + 12;
  155. pdimm->n_col_addr = (spd->addressing & 0x7) + 9;
  156. pdimm->n_banks_per_sdram_device = 8 << ((spd->density_banks >> 4) & 0x7);
  157. /*
  158. * The SPD spec has not the ECC bit,
  159. * We consider the DIMM as ECC capability
  160. * when the extension bus exist
  161. */
  162. if (pdimm->ec_sdram_width)
  163. pdimm->edc_config = 0x02;
  164. else
  165. pdimm->edc_config = 0x00;
  166. /*
  167. * The SPD spec has not the burst length byte
  168. * but DDR3 spec has nature BL8 and BC4,
  169. * BL8 -bit3, BC4 -bit2
  170. */
  171. pdimm->burst_lengths_bitmask = 0x0c;
  172. pdimm->row_density = __ilog2(pdimm->rank_density);
  173. /* MTB - medium timebase
  174. * The unit in the SPD spec is ns,
  175. * We convert it to ps.
  176. * eg: MTB = 0.125ns (125ps)
  177. */
  178. mtb_ps = (spd->mtb_dividend * 1000) /spd->mtb_divisor;
  179. pdimm->mtb_ps = mtb_ps;
  180. /*
  181. * FTB - fine timebase
  182. * use 1/10th of ps as our unit to avoid floating point
  183. * eg, 10 for 1ps, 25 for 2.5ps, 50 for 5ps
  184. */
  185. ftb_10th_ps =
  186. ((spd->ftb_div & 0xf0) >> 4) * 10 / (spd->ftb_div & 0x0f);
  187. pdimm->ftb_10th_ps = ftb_10th_ps;
  188. /*
  189. * sdram minimum cycle time
  190. * we assume the MTB is 0.125ns
  191. * eg:
  192. * tck_min=15 MTB (1.875ns) ->DDR3-1066
  193. * =12 MTB (1.5ns) ->DDR3-1333
  194. * =10 MTB (1.25ns) ->DDR3-1600
  195. */
  196. pdimm->tckmin_x_ps = spd->tck_min * mtb_ps +
  197. (spd->fine_tck_min * ftb_10th_ps) / 10;
  198. /*
  199. * CAS latency supported
  200. * bit4 - CL4
  201. * bit5 - CL5
  202. * bit18 - CL18
  203. */
  204. pdimm->caslat_x = ((spd->caslat_msb << 8) | spd->caslat_lsb) << 4;
  205. /*
  206. * min CAS latency time
  207. * eg: taa_min =
  208. * DDR3-800D 100 MTB (12.5ns)
  209. * DDR3-1066F 105 MTB (13.125ns)
  210. * DDR3-1333H 108 MTB (13.5ns)
  211. * DDR3-1600H 90 MTB (11.25ns)
  212. */
  213. pdimm->taa_ps = spd->taa_min * mtb_ps +
  214. (spd->fine_taa_min * ftb_10th_ps) / 10;
  215. /*
  216. * min write recovery time
  217. * eg:
  218. * twr_min = 120 MTB (15ns) -> all speed grades.
  219. */
  220. pdimm->twr_ps = spd->twr_min * mtb_ps;
  221. /*
  222. * min RAS to CAS delay time
  223. * eg: trcd_min =
  224. * DDR3-800 100 MTB (12.5ns)
  225. * DDR3-1066F 105 MTB (13.125ns)
  226. * DDR3-1333H 108 MTB (13.5ns)
  227. * DDR3-1600H 90 MTB (11.25)
  228. */
  229. pdimm->trcd_ps = spd->trcd_min * mtb_ps +
  230. (spd->fine_trcd_min * ftb_10th_ps) / 10;
  231. /*
  232. * min row active to row active delay time
  233. * eg: trrd_min =
  234. * DDR3-800(1KB page) 80 MTB (10ns)
  235. * DDR3-1333(1KB page) 48 MTB (6ns)
  236. */
  237. pdimm->trrd_ps = spd->trrd_min * mtb_ps;
  238. /*
  239. * min row precharge delay time
  240. * eg: trp_min =
  241. * DDR3-800D 100 MTB (12.5ns)
  242. * DDR3-1066F 105 MTB (13.125ns)
  243. * DDR3-1333H 108 MTB (13.5ns)
  244. * DDR3-1600H 90 MTB (11.25ns)
  245. */
  246. pdimm->trp_ps = spd->trp_min * mtb_ps +
  247. (spd->fine_trp_min * ftb_10th_ps) / 10;
  248. /* min active to precharge delay time
  249. * eg: tRAS_min =
  250. * DDR3-800D 300 MTB (37.5ns)
  251. * DDR3-1066F 300 MTB (37.5ns)
  252. * DDR3-1333H 288 MTB (36ns)
  253. * DDR3-1600H 280 MTB (35ns)
  254. */
  255. pdimm->tras_ps = (((spd->tras_trc_ext & 0xf) << 8) | spd->tras_min_lsb)
  256. * mtb_ps;
  257. /*
  258. * min active to actice/refresh delay time
  259. * eg: tRC_min =
  260. * DDR3-800D 400 MTB (50ns)
  261. * DDR3-1066F 405 MTB (50.625ns)
  262. * DDR3-1333H 396 MTB (49.5ns)
  263. * DDR3-1600H 370 MTB (46.25ns)
  264. */
  265. pdimm->trc_ps = (((spd->tras_trc_ext & 0xf0) << 4) | spd->trc_min_lsb)
  266. * mtb_ps + (spd->fine_trc_min * ftb_10th_ps) / 10;
  267. /*
  268. * min refresh recovery delay time
  269. * eg: tRFC_min =
  270. * 512Mb 720 MTB (90ns)
  271. * 1Gb 880 MTB (110ns)
  272. * 2Gb 1280 MTB (160ns)
  273. */
  274. pdimm->trfc_ps = ((spd->trfc_min_msb << 8) | spd->trfc_min_lsb)
  275. * mtb_ps;
  276. /*
  277. * min internal write to read command delay time
  278. * eg: twtr_min = 40 MTB (7.5ns) - all speed bins.
  279. * tWRT is at least 4 mclk independent of operating freq.
  280. */
  281. pdimm->twtr_ps = spd->twtr_min * mtb_ps;
  282. /*
  283. * min internal read to precharge command delay time
  284. * eg: trtp_min = 40 MTB (7.5ns) - all speed bins.
  285. * tRTP is at least 4 mclk independent of operating freq.
  286. */
  287. pdimm->trtp_ps = spd->trtp_min * mtb_ps;
  288. /*
  289. * Average periodic refresh interval
  290. * tREFI = 7.8 us at normal temperature range
  291. * = 3.9 us at ext temperature range
  292. */
  293. pdimm->refresh_rate_ps = 7800000;
  294. /*
  295. * min four active window delay time
  296. * eg: tfaw_min =
  297. * DDR3-800(1KB page) 320 MTB (40ns)
  298. * DDR3-1066(1KB page) 300 MTB (37.5ns)
  299. * DDR3-1333(1KB page) 240 MTB (30ns)
  300. * DDR3-1600(1KB page) 240 MTB (30ns)
  301. */
  302. pdimm->tfaw_ps = (((spd->tfaw_msb & 0xf) << 8) | spd->tfaw_min)
  303. * mtb_ps;
  304. return 0;
  305. }