mv_ddr_spd.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) Marvell International Ltd. and its affiliates
  4. */
  5. #ifndef _MV_DDR_SPD_H
  6. #define _MV_DDR_SPD_H
  7. #include "mv_ddr_topology.h"
  8. /*
  9. * Based on JEDEC Standard No. 21-C, 4.1.2.L-4:
  10. * Serial Presence Detect (SPD) for DDR4 SDRAM Modules
  11. */
  12. /* block 0: base configuration and dram parameters */
  13. #define MV_DDR_SPD_DATA_BLOCK0_SIZE 128
  14. /* block 1: module specific parameters sub-block */
  15. #define MV_DDR_SPD_DATA_BLOCK1M_SIZE 64
  16. /* block 1: hybrid memory parameters sub-block */
  17. #define MV_DDR_SPD_DATA_BLOCK1H_SIZE 64
  18. /* block 2: extended function parameter block */
  19. #define MV_DDR_SPD_DATA_BLOCK2E_SIZE 64
  20. /* block 2: manufacturing information */
  21. #define MV_DDR_SPD_DATA_BLOCK2M_SIZE 64
  22. /* block 3: end user programmable */
  23. #define MV_DDR_SPD_DATA_BLOCK3_SIZE 128
  24. #define MV_DDR_SPD_DEV_TYPE_DDR4 0xc
  25. #define MV_DDR_SPD_MODULE_TYPE_UDIMM 0x2
  26. #define MV_DDR_SPD_MODULE_TYPE_SO_DIMM 0x3
  27. #define MV_DDR_SPD_MODULE_TYPE_MINI_UDIMM 0x6
  28. #define MV_DDR_SPD_MODULE_TYPE_72BIT_SO_UDIMM 0x9
  29. #define MV_DDR_SPD_MODULE_TYPE_16BIT_SO_DIMM 0xc
  30. #define MV_DDR_SPD_MODULE_TYPE_32BIT_SO_DIMM 0xd
  31. /*
  32. * TODO: For now, the struct contains block 0 & block 1 with module specific
  33. * parameters for unbuffered memory module types only.
  34. */
  35. union mv_ddr_spd_data {
  36. unsigned char all_bytes[MV_DDR_SPD_DATA_BLOCK0_SIZE +
  37. MV_DDR_SPD_DATA_BLOCK1M_SIZE];
  38. struct {
  39. /* block 0 */
  40. union { /* num of bytes used/num of bytes in spd device/crc coverage */
  41. unsigned char all_bits;
  42. struct {
  43. unsigned char spd_bytes_used:4,
  44. spd_bytes_total:3,
  45. reserved:1;
  46. } bit_fields;
  47. } byte_0;
  48. union { /* spd revision */
  49. unsigned char all_bits;
  50. struct {
  51. unsigned char addtions_level:4,
  52. encoding_level:4;
  53. } bit_fields;
  54. } byte_1;
  55. unsigned char byte_2; /* key_byte/dram device type */
  56. union { /* key byte/module type */
  57. unsigned char all_bits;
  58. struct {
  59. unsigned char module_type:4,
  60. hybrid_media:3,
  61. hybrid:1;
  62. } bit_fields;
  63. } byte_3;
  64. union { /* sdram density & banks */
  65. unsigned char all_bits;
  66. struct {
  67. unsigned char die_capacity:4,
  68. bank_address:2,
  69. bank_group:2;
  70. } bit_fields;
  71. } byte_4;
  72. union { /* sdram addressing */
  73. unsigned char all_bits;
  74. struct {
  75. unsigned char col_address:3,
  76. row_address:3,
  77. reserved:2;
  78. } bit_fields;
  79. } byte_5;
  80. union { /* sdram package type */
  81. unsigned char all_bits;
  82. struct {
  83. unsigned char signal_loading:2,
  84. reserved:2,
  85. die_count:3,
  86. sdram_package_type:1;
  87. } bit_fields;
  88. } byte_6;
  89. union { /* sdram optional features */
  90. unsigned char all_bits;
  91. struct {
  92. unsigned char mac:4, /* max activate count */
  93. t_maw:2, /* max activate window */
  94. reserved:2; /* all 0s */
  95. } bit_fields;
  96. } byte_7;
  97. unsigned char byte_8; /* sdram thermal & refresh options; reserved; 0x00 */
  98. union { /* other sdram optional features */
  99. unsigned char all_bits;
  100. struct {
  101. unsigned char reserved:5, /* all 0s */
  102. soft_ppr:1,
  103. ppr:2; /* post package repair */
  104. } bit_fields;
  105. } byte_9;
  106. union { /* secondary sdram package type */
  107. unsigned char all_bits;
  108. struct {
  109. unsigned char signal_loading:2,
  110. density_ratio:2, /* dram density ratio */
  111. die_count:3,
  112. sdram_package_type:1;
  113. } bit_fields;
  114. } byte_10;
  115. union { /* module nominal voltage, vdd */
  116. unsigned char all_bits;
  117. struct {
  118. unsigned char operable:1,
  119. endurant:1,
  120. reserved:5; /* all 0s */
  121. } bit_fields;
  122. } byte_11;
  123. union { /* module organization*/
  124. unsigned char all_bits;
  125. struct {
  126. unsigned char device_width:3,
  127. dimm_pkg_ranks_num:3, /* package ranks per dimm number */
  128. rank_mix:1,
  129. reserved:1; /* 0 */
  130. } bit_fields;
  131. } byte_12;
  132. union { /* module memory bus width */
  133. unsigned char all_bits;
  134. struct {
  135. unsigned char primary_bus_width:3, /* in bits */
  136. bus_width_ext:2, /* in bits */
  137. reserved:3; /* all 0s */
  138. } bit_fields;
  139. } byte_13;
  140. union { /* module thernal sensor */
  141. unsigned char all_bits;
  142. struct {
  143. unsigned char reserved:7,
  144. thermal_sensor:1;
  145. } bit_fields;
  146. } byte_14;
  147. union { /* extended module type */
  148. unsigned char all_bits;
  149. struct {
  150. unsigned char ext_base_module_type:4,
  151. reserved:4; /* all 0s */
  152. } bit_fields;
  153. } byte_15;
  154. unsigned char byte_16; /* reserved; 0x00 */
  155. union { /* timebases */
  156. unsigned char all_bits;
  157. struct {
  158. unsigned char ftb:2, /* fine timebase */
  159. mtb:2, /* medium timebase */
  160. reserved:4; /* all 0s */
  161. } bit_fields;
  162. } byte_17;
  163. unsigned char byte_18; /* sdram min cycle time (t ck avg min), mtb */
  164. unsigned char byte_19; /* sdram max cycle time (t ck avg max), mtb */
  165. unsigned char byte_20; /* cas latencies supported, first byte */
  166. unsigned char byte_21; /* cas latencies supported, second byte */
  167. unsigned char byte_22; /* cas latencies supported, third byte */
  168. unsigned char byte_23; /* cas latencies supported, fourth byte */
  169. unsigned char byte_24; /* min cas latency time (t aa min), mtb */
  170. unsigned char byte_25; /* min ras to cas delay time (t rcd min), mtb */
  171. unsigned char byte_26; /* min row precharge delay time (t rp min), mtb */
  172. union { /* upper nibbles for t ras min & t rc min */
  173. unsigned char all_bits;
  174. struct {
  175. unsigned char t_ras_min_msn:4, /* t ras min most significant nibble */
  176. t_rc_min_msn:4; /* t rc min most significant nibble */
  177. } bit_fields;
  178. } byte_27;
  179. unsigned char byte_28; /* min active to precharge delay time (t ras min), l-s-byte, mtb */
  180. unsigned char byte_29; /* min active to active/refresh delay time (t rc min), l-s-byte, mtb */
  181. unsigned char byte_30; /* min refresh recovery delay time (t rfc1 min), l-s-byte, mtb */
  182. unsigned char byte_31; /* min refresh recovery delay time (t rfc1 min), m-s-byte, mtb */
  183. unsigned char byte_32; /* min refresh recovery delay time (t rfc2 min), l-s-byte, mtb */
  184. unsigned char byte_33; /* min refresh recovery delay time (t rfc2 min), m-s-byte, mtb */
  185. unsigned char byte_34; /* min refresh recovery delay time (t rfc4 min), l-s-byte, mtb */
  186. unsigned char byte_35; /* min refresh recovery delay time (t rfc4 min), m-s-byte, mtb */
  187. union { /* upper nibble for t faw */
  188. unsigned char all_bits;
  189. struct {
  190. unsigned char t_faw_min_msn:4, /* t faw min most significant nibble */
  191. reserved:4;
  192. } bit_fields;
  193. } byte_36;
  194. unsigned char byte_37; /* min four activate window delay time (t faw min), l-s-byte, mtb */
  195. /* byte 38: min activate to activate delay time (t rrd_s min), diff bank group, mtb */
  196. unsigned char byte_38;
  197. /* byte 39: min activate to activate delay time (t rrd_l min), same bank group, mtb */
  198. unsigned char byte_39;
  199. unsigned char byte_40; /* min cas to cas delay time (t ccd_l min), same bank group, mtb */
  200. union { /* upper nibble for t wr min */
  201. unsigned char all_bits;
  202. struct {
  203. unsigned char t_wr_min_msn:4, /* t wr min most significant nibble */
  204. reserved:4;
  205. } bit_fields;
  206. } byte_41;
  207. unsigned char byte_42; /* min write recovery time (t wr min) */
  208. union { /* upper nibbles for t wtr min */
  209. unsigned char all_bits;
  210. struct {
  211. unsigned char t_wtr_s_min_msn:4, /* t wtr s min most significant nibble */
  212. t_wtr_l_min_msn:4; /* t wtr l min most significant nibble */
  213. } bit_fields;
  214. } byte_43;
  215. unsigned char byte_44; /* min write to read time (t wtr s min), diff bank group, mtb */
  216. unsigned char byte_45; /* min write to read time (t wtr l min), same bank group, mtb */
  217. unsigned char bytes_46_59[14]; /* reserved; all 0s */
  218. unsigned char bytes_60_77[18]; /* TODO: connector to sdram bit mapping */
  219. unsigned char bytes_78_116[39]; /* reserved; all 0s */
  220. /* fine offset for min cas to cas delay time (t ccd_l min), same bank group, ftb */
  221. unsigned char byte_117;
  222. /* fine offset for min activate to activate delay time (t rrd_l min), same bank group, ftb */
  223. unsigned char byte_118;
  224. /* fine offset for min activate to activate delay time (t rrd_s min), diff bank group, ftb */
  225. unsigned char byte_119;
  226. /* fine offset for min active to active/refresh delay time (t rc min), ftb */
  227. unsigned char byte_120;
  228. unsigned char byte_121; /* fine offset for min row precharge delay time (t rp min), ftb */
  229. unsigned char byte_122; /* fine offset for min ras to cas delay time (t rcd min), ftb */
  230. unsigned char byte_123; /* fine offset for min cas latency time (t aa min), ftb */
  231. unsigned char byte_124; /* fine offset for sdram max cycle time (t ck avg max), ftb */
  232. unsigned char byte_125; /* fine offset for sdram min cycle time (t ck avg min), ftb */
  233. unsigned char byte_126; /* crc for base configuration section, l-s-byte */
  234. unsigned char byte_127; /* crc for base configuration section, m-s-byte */
  235. /*
  236. * block 1: module specific parameters for unbuffered memory module types only
  237. */
  238. union { /* (unbuffered) raw card extension, module nominal height */
  239. unsigned char all_bits;
  240. struct {
  241. unsigned char nom_height_max:5, /* in mm */
  242. raw_cad_ext:3;
  243. } bit_fields;
  244. } byte_128;
  245. union { /* (unbuffered) module maximum thickness */
  246. unsigned char all_bits;
  247. struct {
  248. unsigned char front_thickness_max:4, /* in mm */
  249. back_thickness_max:4; /* in mm */
  250. } bit_fields;
  251. } byte_129;
  252. union { /* (unbuffered) reference raw card used */
  253. unsigned char all_bits;
  254. struct {
  255. unsigned char ref_raw_card:5,
  256. ref_raw_card_rev:2,
  257. ref_raw_card_ext:1;
  258. } bit_fields;
  259. } byte_130;
  260. union { /* (unbuffered) address mapping from edge connector to dram */
  261. unsigned char all_bits;
  262. struct {
  263. unsigned char rank_1_mapping:1,
  264. reserved:7;
  265. } bit_fields;
  266. } byte_131;
  267. unsigned char bytes_132_191[60]; /* reserved; all 0s */
  268. } byte_fields;
  269. };
  270. int mv_ddr_spd_timing_calc(union mv_ddr_spd_data *spd_data, unsigned int timing_data[]);
  271. enum mv_ddr_dev_width mv_ddr_spd_dev_width_get(union mv_ddr_spd_data *spd_data);
  272. enum mv_ddr_die_capacity mv_ddr_spd_die_capacity_get(union mv_ddr_spd_data *spd_data);
  273. unsigned char mv_ddr_spd_mem_mirror_get(union mv_ddr_spd_data *spd_data);
  274. unsigned char mv_ddr_spd_cs_bit_mask_get(union mv_ddr_spd_data *spd_data);
  275. unsigned char mv_ddr_spd_dev_type_get(union mv_ddr_spd_data *spd_data);
  276. unsigned char mv_ddr_spd_module_type_get(union mv_ddr_spd_data *spd_data);
  277. int mv_ddr_spd_supported_cls_calc(union mv_ddr_spd_data *spd_data);
  278. unsigned int mv_ddr_spd_supported_cl_get(unsigned int cl);
  279. enum mv_ddr_pkg_rank mv_ddr_spd_pri_bus_width_get(union mv_ddr_spd_data *spd_data);
  280. enum mv_ddr_pkg_rank mv_ddr_spd_bus_width_ext_get(union mv_ddr_spd_data *spd_data);
  281. #endif /* _MV_DDR_SPD_H */