ddr3_dimm_params.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * Copyright 2008-2009 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 i;
  85. if (spd->mem_type) {
  86. if (spd->mem_type != SPD_MEMTYPE_DDR3) {
  87. printf("DIMM %u: is not a DDR3 SPD.\n", dimm_number);
  88. return 1;
  89. }
  90. } else {
  91. memset(pdimm, 0, sizeof(dimm_params_t));
  92. return 1;
  93. }
  94. retval = ddr3_spd_check(spd);
  95. if (retval) {
  96. printf("DIMM %u: failed checksum\n", dimm_number);
  97. return 2;
  98. }
  99. /*
  100. * The part name in ASCII in the SPD EEPROM is not null terminated.
  101. * Guarantee null termination here by presetting all bytes to 0
  102. * and copying the part name in ASCII from the SPD onto it
  103. */
  104. memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
  105. if ((spd->info_size_crc & 0xF) > 1)
  106. memcpy(pdimm->mpart, spd->mpart, sizeof(pdimm->mpart) - 1);
  107. /* DIMM organization parameters */
  108. pdimm->n_ranks = ((spd->organization >> 3) & 0x7) + 1;
  109. pdimm->rank_density = compute_ranksize(spd);
  110. pdimm->capacity = pdimm->n_ranks * pdimm->rank_density;
  111. pdimm->primary_sdram_width = 1 << (3 + (spd->bus_width & 0x7));
  112. if ((spd->bus_width >> 3) & 0x3)
  113. pdimm->ec_sdram_width = 8;
  114. else
  115. pdimm->ec_sdram_width = 0;
  116. pdimm->data_width = pdimm->primary_sdram_width
  117. + pdimm->ec_sdram_width;
  118. /* These are the types defined by the JEDEC DDR3 SPD spec */
  119. pdimm->mirrored_dimm = 0;
  120. pdimm->registered_dimm = 0;
  121. switch (spd->module_type & DDR3_SPD_MODULETYPE_MASK) {
  122. case DDR3_SPD_MODULETYPE_RDIMM:
  123. case DDR3_SPD_MODULETYPE_MINI_RDIMM:
  124. case DDR3_SPD_MODULETYPE_72B_SO_RDIMM:
  125. /* Registered/buffered DIMMs */
  126. pdimm->registered_dimm = 1;
  127. for (i = 0; i < 16; i += 2) {
  128. u8 rcw = spd->mod_section.registered.rcw[i/2];
  129. pdimm->rcw[i] = (rcw >> 0) & 0x0F;
  130. pdimm->rcw[i+1] = (rcw >> 4) & 0x0F;
  131. }
  132. break;
  133. case DDR3_SPD_MODULETYPE_UDIMM:
  134. case DDR3_SPD_MODULETYPE_SO_DIMM:
  135. case DDR3_SPD_MODULETYPE_MICRO_DIMM:
  136. case DDR3_SPD_MODULETYPE_MINI_UDIMM:
  137. case DDR3_SPD_MODULETYPE_MINI_CDIMM:
  138. case DDR3_SPD_MODULETYPE_72B_SO_UDIMM:
  139. case DDR3_SPD_MODULETYPE_72B_SO_CDIMM:
  140. case DDR3_SPD_MODULETYPE_LRDIMM:
  141. case DDR3_SPD_MODULETYPE_16B_SO_DIMM:
  142. case DDR3_SPD_MODULETYPE_32B_SO_DIMM:
  143. /* Unbuffered DIMMs */
  144. if (spd->mod_section.unbuffered.addr_mapping & 0x1)
  145. pdimm->mirrored_dimm = 1;
  146. break;
  147. default:
  148. printf("unknown module_type 0x%02X\n", spd->module_type);
  149. return 1;
  150. }
  151. /* SDRAM device parameters */
  152. pdimm->n_row_addr = ((spd->addressing >> 3) & 0x7) + 12;
  153. pdimm->n_col_addr = (spd->addressing & 0x7) + 9;
  154. pdimm->n_banks_per_sdram_device = 8 << ((spd->density_banks >> 4) & 0x7);
  155. /*
  156. * The SPD spec has not the ECC bit,
  157. * We consider the DIMM as ECC capability
  158. * when the extension bus exist
  159. */
  160. if (pdimm->ec_sdram_width)
  161. pdimm->edc_config = 0x02;
  162. else
  163. pdimm->edc_config = 0x00;
  164. /*
  165. * The SPD spec has not the burst length byte
  166. * but DDR3 spec has nature BL8 and BC4,
  167. * BL8 -bit3, BC4 -bit2
  168. */
  169. pdimm->burst_lengths_bitmask = 0x0c;
  170. pdimm->row_density = __ilog2(pdimm->rank_density);
  171. /* MTB - medium timebase
  172. * The unit in the SPD spec is ns,
  173. * We convert it to ps.
  174. * eg: MTB = 0.125ns (125ps)
  175. */
  176. mtb_ps = (spd->mtb_dividend * 1000) /spd->mtb_divisor;
  177. pdimm->mtb_ps = mtb_ps;
  178. /*
  179. * sdram minimum cycle time
  180. * we assume the MTB is 0.125ns
  181. * eg:
  182. * tCK_min=15 MTB (1.875ns) ->DDR3-1066
  183. * =12 MTB (1.5ns) ->DDR3-1333
  184. * =10 MTB (1.25ns) ->DDR3-1600
  185. */
  186. pdimm->tCKmin_X_ps = spd->tCK_min * mtb_ps;
  187. /*
  188. * CAS latency supported
  189. * bit4 - CL4
  190. * bit5 - CL5
  191. * bit18 - CL18
  192. */
  193. pdimm->caslat_X = ((spd->caslat_msb << 8) | spd->caslat_lsb) << 4;
  194. /*
  195. * min CAS latency time
  196. * eg: tAA_min =
  197. * DDR3-800D 100 MTB (12.5ns)
  198. * DDR3-1066F 105 MTB (13.125ns)
  199. * DDR3-1333H 108 MTB (13.5ns)
  200. * DDR3-1600H 90 MTB (11.25ns)
  201. */
  202. pdimm->tAA_ps = spd->tAA_min * mtb_ps;
  203. /*
  204. * min write recovery time
  205. * eg:
  206. * tWR_min = 120 MTB (15ns) -> all speed grades.
  207. */
  208. pdimm->tWR_ps = spd->tWR_min * mtb_ps;
  209. /*
  210. * min RAS to CAS delay time
  211. * eg: tRCD_min =
  212. * DDR3-800 100 MTB (12.5ns)
  213. * DDR3-1066F 105 MTB (13.125ns)
  214. * DDR3-1333H 108 MTB (13.5ns)
  215. * DDR3-1600H 90 MTB (11.25)
  216. */
  217. pdimm->tRCD_ps = spd->tRCD_min * mtb_ps;
  218. /*
  219. * min row active to row active delay time
  220. * eg: tRRD_min =
  221. * DDR3-800(1KB page) 80 MTB (10ns)
  222. * DDR3-1333(1KB page) 48 MTB (6ns)
  223. */
  224. pdimm->tRRD_ps = spd->tRRD_min * mtb_ps;
  225. /*
  226. * min row precharge delay time
  227. * eg: tRP_min =
  228. * DDR3-800D 100 MTB (12.5ns)
  229. * DDR3-1066F 105 MTB (13.125ns)
  230. * DDR3-1333H 108 MTB (13.5ns)
  231. * DDR3-1600H 90 MTB (11.25ns)
  232. */
  233. pdimm->tRP_ps = spd->tRP_min * mtb_ps;
  234. /* min active to precharge delay time
  235. * eg: tRAS_min =
  236. * DDR3-800D 300 MTB (37.5ns)
  237. * DDR3-1066F 300 MTB (37.5ns)
  238. * DDR3-1333H 288 MTB (36ns)
  239. * DDR3-1600H 280 MTB (35ns)
  240. */
  241. pdimm->tRAS_ps = (((spd->tRAS_tRC_ext & 0xf) << 8) | spd->tRAS_min_lsb)
  242. * mtb_ps;
  243. /*
  244. * min active to actice/refresh delay time
  245. * eg: tRC_min =
  246. * DDR3-800D 400 MTB (50ns)
  247. * DDR3-1066F 405 MTB (50.625ns)
  248. * DDR3-1333H 396 MTB (49.5ns)
  249. * DDR3-1600H 370 MTB (46.25ns)
  250. */
  251. pdimm->tRC_ps = (((spd->tRAS_tRC_ext & 0xf0) << 4) | spd->tRC_min_lsb)
  252. * mtb_ps;
  253. /*
  254. * min refresh recovery delay time
  255. * eg: tRFC_min =
  256. * 512Mb 720 MTB (90ns)
  257. * 1Gb 880 MTB (110ns)
  258. * 2Gb 1280 MTB (160ns)
  259. */
  260. pdimm->tRFC_ps = ((spd->tRFC_min_msb << 8) | spd->tRFC_min_lsb)
  261. * mtb_ps;
  262. /*
  263. * min internal write to read command delay time
  264. * eg: tWTR_min = 40 MTB (7.5ns) - all speed bins.
  265. * tWRT is at least 4 mclk independent of operating freq.
  266. */
  267. pdimm->tWTR_ps = spd->tWTR_min * mtb_ps;
  268. /*
  269. * min internal read to precharge command delay time
  270. * eg: tRTP_min = 40 MTB (7.5ns) - all speed bins.
  271. * tRTP is at least 4 mclk independent of operating freq.
  272. */
  273. pdimm->tRTP_ps = spd->tRTP_min * mtb_ps;
  274. /*
  275. * Average periodic refresh interval
  276. * tREFI = 7.8 us at normal temperature range
  277. * = 3.9 us at ext temperature range
  278. */
  279. pdimm->refresh_rate_ps = 7800000;
  280. /*
  281. * min four active window delay time
  282. * eg: tFAW_min =
  283. * DDR3-800(1KB page) 320 MTB (40ns)
  284. * DDR3-1066(1KB page) 300 MTB (37.5ns)
  285. * DDR3-1333(1KB page) 240 MTB (30ns)
  286. * DDR3-1600(1KB page) 240 MTB (30ns)
  287. */
  288. pdimm->tFAW_ps = (((spd->tFAW_msb & 0xf) << 8) | spd->tFAW_min)
  289. * mtb_ps;
  290. return 0;
  291. }