dram_spec_timing.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. /*
  2. * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include <lib/utils.h>
  9. #include <dram.h>
  10. #include "dram_spec_timing.h"
  11. static const uint8_t ddr3_cl_cwl[][7] = {
  12. /*
  13. * speed 0~330 331 ~ 400 401 ~ 533 534~666 667~800 801~933 934~1066
  14. * tCK>3 2.5~3 1.875~2.5 1.5~1.875 1.25~1.5 1.07~1.25 0.938~1.07
  15. * cl<<4, cwl cl<<4, cwl cl<<4, cwl
  16. */
  17. /* DDR3_800D (5-5-5) */
  18. {((5 << 4) | 5), ((5 << 4) | 5), 0, 0, 0, 0, 0},
  19. /* DDR3_800E (6-6-6) */
  20. {((5 << 4) | 5), ((6 << 4) | 5), 0, 0, 0, 0, 0},
  21. /* DDR3_1066E (6-6-6) */
  22. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), 0, 0, 0, 0},
  23. /* DDR3_1066F (7-7-7) */
  24. {((5 << 4) | 5), ((6 << 4) | 5), ((7 << 4) | 6), 0, 0, 0, 0},
  25. /* DDR3_1066G (8-8-8) */
  26. {((5 << 4) | 5), ((6 << 4) | 5), ((8 << 4) | 6), 0, 0, 0, 0},
  27. /* DDR3_1333F (7-7-7) */
  28. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), ((7 << 4) | 7),
  29. 0, 0, 0},
  30. /* DDR3_1333G (8-8-8) */
  31. {((5 << 4) | 5), ((5 << 4) | 5), ((7 << 4) | 6), ((8 << 4) | 7),
  32. 0, 0, 0},
  33. /* DDR3_1333H (9-9-9) */
  34. {((5 << 4) | 5), ((6 << 4) | 5), ((8 << 4) | 6), ((9 << 4) | 7),
  35. 0, 0, 0},
  36. /* DDR3_1333J (10-10-10) */
  37. {((5 << 4) | 5), ((6 << 4) | 5), ((8 << 4) | 6), ((10 << 4) | 7),
  38. 0, 0, 0},
  39. /* DDR3_1600G (8-8-8) */
  40. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), ((7 << 4) | 7),
  41. ((8 << 4) | 8), 0, 0},
  42. /* DDR3_1600H (9-9-9) */
  43. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), ((8 << 4) | 7),
  44. ((9 << 4) | 8), 0, 0},
  45. /* DDR3_1600J (10-10-10) */
  46. {((5 << 4) | 5), ((5 << 4) | 5), ((7 << 4) | 6), ((9 << 4) | 7),
  47. ((10 << 4) | 8), 0, 0},
  48. /* DDR3_1600K (11-11-11) */
  49. {((5 << 4) | 5), ((6 << 4) | 5), ((8 << 4) | 6), ((10 << 4) | 7),
  50. ((11 << 4) | 8), 0, 0},
  51. /* DDR3_1866J (10-10-10) */
  52. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), ((8 << 4) | 7),
  53. ((9 << 4) | 8), ((11 << 4) | 9), 0},
  54. /* DDR3_1866K (11-11-11) */
  55. {((5 << 4) | 5), ((5 << 4) | 5), ((7 << 4) | 6), ((8 << 4) | 7),
  56. ((10 << 4) | 8), ((11 << 4) | 9), 0},
  57. /* DDR3_1866L (12-12-12) */
  58. {((6 << 4) | 5), ((6 << 4) | 5), ((7 << 4) | 6), ((9 << 4) | 7),
  59. ((11 << 4) | 8), ((12 << 4) | 9), 0},
  60. /* DDR3_1866M (13-13-13) */
  61. {((6 << 4) | 5), ((6 << 4) | 5), ((8 << 4) | 6), ((10 << 4) | 7),
  62. ((11 << 4) | 8), ((13 << 4) | 9), 0},
  63. /* DDR3_2133K (11-11-11) */
  64. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), ((7 << 4) | 7),
  65. ((9 << 4) | 8), ((10 << 4) | 9), ((11 << 4) | 10)},
  66. /* DDR3_2133L (12-12-12) */
  67. {((5 << 4) | 5), ((5 << 4) | 5), ((6 << 4) | 6), ((8 << 4) | 7),
  68. ((9 << 4) | 8), ((11 << 4) | 9), ((12 << 4) | 10)},
  69. /* DDR3_2133M (13-13-13) */
  70. {((5 << 4) | 5), ((5 << 4) | 5), ((7 << 4) | 6), ((9 << 4) | 7),
  71. ((10 << 4) | 8), ((12 << 4) | 9), ((13 << 4) | 10)},
  72. /* DDR3_2133N (14-14-14) */
  73. {((6 << 4) | 5), ((6 << 4) | 5), ((7 << 4) | 6), ((9 << 4) | 7),
  74. ((11 << 4) | 8), ((13 << 4) | 9), ((14 << 4) | 10)},
  75. /* DDR3_DEFAULT */
  76. {((6 << 4) | 5), ((6 << 4) | 5), ((8 << 4) | 6), ((10 << 4) | 7),
  77. ((11 << 4) | 8), ((13 << 4) | 9), ((14 << 4) | 10)}
  78. };
  79. static const uint16_t ddr3_trc_tfaw[] = {
  80. /* tRC tFAW */
  81. ((50 << 8) | 50), /* DDR3_800D (5-5-5) */
  82. ((53 << 8) | 50), /* DDR3_800E (6-6-6) */
  83. ((49 << 8) | 50), /* DDR3_1066E (6-6-6) */
  84. ((51 << 8) | 50), /* DDR3_1066F (7-7-7) */
  85. ((53 << 8) | 50), /* DDR3_1066G (8-8-8) */
  86. ((47 << 8) | 45), /* DDR3_1333F (7-7-7) */
  87. ((48 << 8) | 45), /* DDR3_1333G (8-8-8) */
  88. ((50 << 8) | 45), /* DDR3_1333H (9-9-9) */
  89. ((51 << 8) | 45), /* DDR3_1333J (10-10-10) */
  90. ((45 << 8) | 40), /* DDR3_1600G (8-8-8) */
  91. ((47 << 8) | 40), /* DDR3_1600H (9-9-9)*/
  92. ((48 << 8) | 40), /* DDR3_1600J (10-10-10) */
  93. ((49 << 8) | 40), /* DDR3_1600K (11-11-11) */
  94. ((45 << 8) | 35), /* DDR3_1866J (10-10-10) */
  95. ((46 << 8) | 35), /* DDR3_1866K (11-11-11) */
  96. ((47 << 8) | 35), /* DDR3_1866L (12-12-12) */
  97. ((48 << 8) | 35), /* DDR3_1866M (13-13-13) */
  98. ((44 << 8) | 35), /* DDR3_2133K (11-11-11) */
  99. ((45 << 8) | 35), /* DDR3_2133L (12-12-12) */
  100. ((46 << 8) | 35), /* DDR3_2133M (13-13-13) */
  101. ((47 << 8) | 35), /* DDR3_2133N (14-14-14) */
  102. ((53 << 8) | 50) /* DDR3_DEFAULT */
  103. };
  104. static uint32_t get_max_speed_rate(struct timing_related_config *timing_config)
  105. {
  106. if (timing_config->ch_cnt > 1)
  107. return max(timing_config->dram_info[0].speed_rate,
  108. timing_config->dram_info[1].speed_rate);
  109. else
  110. return timing_config->dram_info[0].speed_rate;
  111. }
  112. static uint32_t
  113. get_max_die_capability(struct timing_related_config *timing_config)
  114. {
  115. uint32_t die_cap = 0;
  116. uint32_t cs, ch;
  117. for (ch = 0; ch < timing_config->ch_cnt; ch++) {
  118. for (cs = 0; cs < timing_config->dram_info[ch].cs_cnt; cs++) {
  119. die_cap = max(die_cap,
  120. timing_config->
  121. dram_info[ch].per_die_capability[cs]);
  122. }
  123. }
  124. return die_cap;
  125. }
  126. /* tRSTL, 100ns */
  127. #define DDR3_TRSTL (100)
  128. /* trsth, 500us */
  129. #define DDR3_TRSTH (500000)
  130. /* trefi, 7.8us */
  131. #define DDR3_TREFI_7_8_US (7800)
  132. /* tWR, 15ns */
  133. #define DDR3_TWR (15)
  134. /* tRTP, max(4 tCK,7.5ns) */
  135. #define DDR3_TRTP (7)
  136. /* tRRD = max(4nCK, 10ns) */
  137. #define DDR3_TRRD (10)
  138. /* tCK */
  139. #define DDR3_TCCD (4)
  140. /*tWTR, max(4 tCK,7.5ns)*/
  141. #define DDR3_TWTR (7)
  142. /* tCK */
  143. #define DDR3_TRTW (0)
  144. /* tRAS, 37.5ns(400MHz) 37.5ns(533MHz) */
  145. #define DDR3_TRAS (37)
  146. /* ns */
  147. #define DDR3_TRFC_512MBIT (90)
  148. /* ns */
  149. #define DDR3_TRFC_1GBIT (110)
  150. /* ns */
  151. #define DDR3_TRFC_2GBIT (160)
  152. /* ns */
  153. #define DDR3_TRFC_4GBIT (300)
  154. /* ns */
  155. #define DDR3_TRFC_8GBIT (350)
  156. /*pd and sr*/
  157. #define DDR3_TXP (7) /* tXP, max(3 tCK, 7.5ns)( < 933MHz) */
  158. #define DDR3_TXPDLL (24) /* tXPDLL, max(10 tCK, 24ns) */
  159. #define DDR3_TDLLK (512) /* tXSR, tDLLK=512 tCK */
  160. #define DDR3_TCKE_400MHZ (7) /* tCKE, max(3 tCK,7.5ns)(400MHz) */
  161. #define DDR3_TCKE_533MHZ (6) /* tCKE, max(3 tCK,5.625ns)(533MHz) */
  162. #define DDR3_TCKSRE (10) /* tCKSRX, max(5 tCK, 10ns) */
  163. /*mode register timing*/
  164. #define DDR3_TMOD (15) /* tMOD, max(12 tCK,15ns) */
  165. #define DDR3_TMRD (4) /* tMRD, 4 tCK */
  166. /* ZQ */
  167. #define DDR3_TZQINIT (640) /* tZQinit, max(512 tCK, 640ns) */
  168. #define DDR3_TZQCS (80) /* tZQCS, max(64 tCK, 80ns) */
  169. #define DDR3_TZQOPER (320) /* tZQoper, max(256 tCK, 320ns) */
  170. /* Write leveling */
  171. #define DDR3_TWLMRD (40) /* tCK */
  172. #define DDR3_TWLO (9) /* max 7.5ns */
  173. #define DDR3_TWLDQSEN (25) /* tCK */
  174. /*
  175. * Description: depend on input parameter "timing_config",
  176. * and calculate all ddr3
  177. * spec timing to "pdram_timing"
  178. * parameters:
  179. * input: timing_config
  180. * output: pdram_timing
  181. */
  182. static void ddr3_get_parameter(struct timing_related_config *timing_config,
  183. struct dram_timing_t *pdram_timing)
  184. {
  185. uint32_t nmhz = timing_config->freq;
  186. uint32_t ddr_speed_bin = get_max_speed_rate(timing_config);
  187. uint32_t ddr_capability_per_die = get_max_die_capability(timing_config);
  188. uint32_t tmp;
  189. zeromem((void *)pdram_timing, sizeof(struct dram_timing_t));
  190. pdram_timing->mhz = nmhz;
  191. pdram_timing->al = 0;
  192. pdram_timing->bl = timing_config->bl;
  193. if (nmhz <= 330)
  194. tmp = 0;
  195. else if (nmhz <= 400)
  196. tmp = 1;
  197. else if (nmhz <= 533)
  198. tmp = 2;
  199. else if (nmhz <= 666)
  200. tmp = 3;
  201. else if (nmhz <= 800)
  202. tmp = 4;
  203. else if (nmhz <= 933)
  204. tmp = 5;
  205. else
  206. tmp = 6;
  207. /* when dll bypss cl = cwl = 6 */
  208. if (nmhz < 300) {
  209. pdram_timing->cl = 6;
  210. pdram_timing->cwl = 6;
  211. } else {
  212. pdram_timing->cl = (ddr3_cl_cwl[ddr_speed_bin][tmp] >> 4) & 0xf;
  213. pdram_timing->cwl = ddr3_cl_cwl[ddr_speed_bin][tmp] & 0xf;
  214. }
  215. switch (timing_config->dramds) {
  216. case 40:
  217. tmp = DDR3_DS_40;
  218. break;
  219. case 34:
  220. default:
  221. tmp = DDR3_DS_34;
  222. break;
  223. }
  224. if (timing_config->odt)
  225. switch (timing_config->dramodt) {
  226. case 60:
  227. pdram_timing->mr[1] = tmp | DDR3_RTT_NOM_60;
  228. break;
  229. case 40:
  230. pdram_timing->mr[1] = tmp | DDR3_RTT_NOM_40;
  231. break;
  232. case 120:
  233. pdram_timing->mr[1] = tmp | DDR3_RTT_NOM_120;
  234. break;
  235. case 0:
  236. default:
  237. pdram_timing->mr[1] = tmp | DDR3_RTT_NOM_DIS;
  238. break;
  239. }
  240. else
  241. pdram_timing->mr[1] = tmp | DDR3_RTT_NOM_DIS;
  242. pdram_timing->mr[2] = DDR3_MR2_CWL(pdram_timing->cwl);
  243. pdram_timing->mr[3] = 0;
  244. pdram_timing->trstl = ((DDR3_TRSTL * nmhz + 999) / 1000);
  245. pdram_timing->trsth = ((DDR3_TRSTH * nmhz + 999) / 1000);
  246. /* tREFI, average periodic refresh interval, 7.8us */
  247. pdram_timing->trefi = ((DDR3_TREFI_7_8_US * nmhz + 999) / 1000);
  248. /* base timing */
  249. pdram_timing->trcd = pdram_timing->cl;
  250. pdram_timing->trp = pdram_timing->cl;
  251. pdram_timing->trppb = pdram_timing->cl;
  252. tmp = ((DDR3_TWR * nmhz + 999) / 1000);
  253. pdram_timing->twr = tmp;
  254. pdram_timing->tdal = tmp + pdram_timing->trp;
  255. if (tmp < 9) {
  256. tmp = tmp - 4;
  257. } else {
  258. tmp += (tmp & 0x1) ? 1 : 0;
  259. tmp = tmp >> 1;
  260. }
  261. if (pdram_timing->bl == 4)
  262. pdram_timing->mr[0] = DDR3_BC4
  263. | DDR3_CL(pdram_timing->cl)
  264. | DDR3_WR(tmp);
  265. else
  266. pdram_timing->mr[0] = DDR3_BL8
  267. | DDR3_CL(pdram_timing->cl)
  268. | DDR3_WR(tmp);
  269. tmp = ((DDR3_TRTP * nmhz + (nmhz >> 1) + 999) / 1000);
  270. pdram_timing->trtp = max(4, tmp);
  271. pdram_timing->trc =
  272. (((ddr3_trc_tfaw[ddr_speed_bin] >> 8) * nmhz + 999) / 1000);
  273. tmp = ((DDR3_TRRD * nmhz + 999) / 1000);
  274. pdram_timing->trrd = max(4, tmp);
  275. pdram_timing->tccd = DDR3_TCCD;
  276. tmp = ((DDR3_TWTR * nmhz + (nmhz >> 1) + 999) / 1000);
  277. pdram_timing->twtr = max(4, tmp);
  278. pdram_timing->trtw = DDR3_TRTW;
  279. pdram_timing->tras_max = 9 * pdram_timing->trefi;
  280. pdram_timing->tras_min = ((DDR3_TRAS * nmhz + (nmhz >> 1) + 999)
  281. / 1000);
  282. pdram_timing->tfaw =
  283. (((ddr3_trc_tfaw[ddr_speed_bin] & 0x0ff) * nmhz + 999)
  284. / 1000);
  285. /* tRFC, 90ns(512Mb),110ns(1Gb),160ns(2Gb),300ns(4Gb),350ns(8Gb) */
  286. if (ddr_capability_per_die <= 0x4000000)
  287. tmp = DDR3_TRFC_512MBIT;
  288. else if (ddr_capability_per_die <= 0x8000000)
  289. tmp = DDR3_TRFC_1GBIT;
  290. else if (ddr_capability_per_die <= 0x10000000)
  291. tmp = DDR3_TRFC_2GBIT;
  292. else if (ddr_capability_per_die <= 0x20000000)
  293. tmp = DDR3_TRFC_4GBIT;
  294. else
  295. tmp = DDR3_TRFC_8GBIT;
  296. pdram_timing->trfc = (tmp * nmhz + 999) / 1000;
  297. pdram_timing->txsnr = max(5, (((tmp + 10) * nmhz + 999) / 1000));
  298. pdram_timing->tdqsck_max = 0;
  299. /*pd and sr*/
  300. pdram_timing->txsr = DDR3_TDLLK;
  301. tmp = ((DDR3_TXP * nmhz + (nmhz >> 1) + 999) / 1000);
  302. pdram_timing->txp = max(3, tmp);
  303. tmp = ((DDR3_TXPDLL * nmhz + 999) / 1000);
  304. pdram_timing->txpdll = max(10, tmp);
  305. pdram_timing->tdllk = DDR3_TDLLK;
  306. if (nmhz >= 533)
  307. tmp = ((DDR3_TCKE_533MHZ * nmhz + 999) / 1000);
  308. else
  309. tmp = ((DDR3_TCKE_400MHZ * nmhz + (nmhz >> 1) + 999) / 1000);
  310. pdram_timing->tcke = max(3, tmp);
  311. pdram_timing->tckesr = (pdram_timing->tcke + 1);
  312. tmp = ((DDR3_TCKSRE * nmhz + 999) / 1000);
  313. pdram_timing->tcksre = max(5, tmp);
  314. pdram_timing->tcksrx = max(5, tmp);
  315. /*mode register timing*/
  316. tmp = ((DDR3_TMOD * nmhz + 999) / 1000);
  317. pdram_timing->tmod = max(12, tmp);
  318. pdram_timing->tmrd = DDR3_TMRD;
  319. pdram_timing->tmrr = 0;
  320. /*ODT*/
  321. pdram_timing->todton = pdram_timing->cwl - 2;
  322. /*ZQ*/
  323. tmp = ((DDR3_TZQINIT * nmhz + 999) / 1000);
  324. pdram_timing->tzqinit = max(512, tmp);
  325. tmp = ((DDR3_TZQCS * nmhz + 999) / 1000);
  326. pdram_timing->tzqcs = max(64, tmp);
  327. tmp = ((DDR3_TZQOPER * nmhz + 999) / 1000);
  328. pdram_timing->tzqoper = max(256, tmp);
  329. /* write leveling */
  330. pdram_timing->twlmrd = DDR3_TWLMRD;
  331. pdram_timing->twldqsen = DDR3_TWLDQSEN;
  332. pdram_timing->twlo = ((DDR3_TWLO * nmhz + (nmhz >> 1) + 999) / 1000);
  333. }
  334. #define LPDDR2_TINIT1 (100) /* ns */
  335. #define LPDDR2_TINIT2 (5) /* tCK */
  336. #define LPDDR2_TINIT3 (200000) /* 200us */
  337. #define LPDDR2_TINIT4 (1000) /* 1us */
  338. #define LPDDR2_TINIT5 (10000) /* 10us */
  339. #define LPDDR2_TRSTL (0) /* tCK */
  340. #define LPDDR2_TRSTH (500000) /* 500us */
  341. #define LPDDR2_TREFI_3_9_US (3900) /* 3.9us */
  342. #define LPDDR2_TREFI_7_8_US (7800) /* 7.8us */
  343. /* base timing */
  344. #define LPDDR2_TRCD (24) /* tRCD,15ns(Fast)18ns(Typ)24ns(Slow) */
  345. #define LPDDR2_TRP_PB (18) /* tRPpb,15ns(Fast)18ns(Typ)24ns(Slow) */
  346. #define LPDDR2_TRP_AB_8_BANK (21) /* tRPab,18ns(Fast)21ns(Typ)27ns(Slow) */
  347. #define LPDDR2_TWR (15) /* tWR, max(3tCK,15ns) */
  348. #define LPDDR2_TRTP (7) /* tRTP, max(2tCK, 7.5ns) */
  349. #define LPDDR2_TRRD (10) /* tRRD, max(2tCK,10ns) */
  350. #define LPDDR2_TCCD (2) /* tCK */
  351. #define LPDDR2_TWTR_GREAT_200MHZ (7) /* ns */
  352. #define LPDDR2_TWTR_LITTLE_200MHZ (10) /* ns */
  353. #define LPDDR2_TRTW (0) /* tCK */
  354. #define LPDDR2_TRAS_MAX (70000) /* 70us */
  355. #define LPDDR2_TRAS (42) /* tRAS, max(3tCK,42ns) */
  356. #define LPDDR2_TFAW_GREAT_200MHZ (50) /* max(8tCK,50ns) */
  357. #define LPDDR2_TFAW_LITTLE_200MHZ (60) /* max(8tCK,60ns) */
  358. #define LPDDR2_TRFC_8GBIT (210) /* ns */
  359. #define LPDDR2_TRFC_4GBIT (130) /* ns */
  360. #define LPDDR2_TDQSCK_MIN (2) /* tDQSCKmin, 2.5ns */
  361. #define LPDDR2_TDQSCK_MAX (5) /* tDQSCKmax, 5.5ns */
  362. /*pd and sr*/
  363. #define LPDDR2_TXP (7) /* tXP, max(2tCK,7.5ns) */
  364. #define LPDDR2_TXPDLL (0)
  365. #define LPDDR2_TDLLK (0) /* tCK */
  366. #define LPDDR2_TCKE (3) /* tCK */
  367. #define LPDDR2_TCKESR (15) /* tCKESR, max(3tCK,15ns) */
  368. #define LPDDR2_TCKSRE (1) /* tCK */
  369. #define LPDDR2_TCKSRX (2) /* tCK */
  370. /*mode register timing*/
  371. #define LPDDR2_TMOD (0)
  372. #define LPDDR2_TMRD (5) /* tMRD, (=tMRW), 5 tCK */
  373. #define LPDDR2_TMRR (2) /* tCK */
  374. /*ZQ*/
  375. #define LPDDR2_TZQINIT (1000) /* ns */
  376. #define LPDDR2_TZQCS (90) /* tZQCS, max(6tCK,90ns) */
  377. #define LPDDR2_TZQCL (360) /* tZQCL, max(6tCK,360ns) */
  378. #define LPDDR2_TZQRESET (50) /* ZQreset, max(3tCK,50ns) */
  379. /*
  380. * Description: depend on input parameter "timing_config",
  381. * and calculate all lpddr2
  382. * spec timing to "pdram_timing"
  383. * parameters:
  384. * input: timing_config
  385. * output: pdram_timing
  386. */
  387. static void lpddr2_get_parameter(struct timing_related_config *timing_config,
  388. struct dram_timing_t *pdram_timing)
  389. {
  390. uint32_t nmhz = timing_config->freq;
  391. uint32_t ddr_capability_per_die = get_max_die_capability(timing_config);
  392. uint32_t tmp, trp_tmp, trppb_tmp, tras_tmp, twr_tmp, bl_tmp;
  393. zeromem((void *)pdram_timing, sizeof(struct dram_timing_t));
  394. pdram_timing->mhz = nmhz;
  395. pdram_timing->al = 0;
  396. pdram_timing->bl = timing_config->bl;
  397. /* 1066 933 800 667 533 400 333
  398. * RL, 8 7 6 5 4 3 3
  399. * WL, 4 4 3 2 2 1 1
  400. */
  401. if (nmhz <= 266) {
  402. pdram_timing->cl = 4;
  403. pdram_timing->cwl = 2;
  404. pdram_timing->mr[2] = LPDDR2_RL4_WL2;
  405. } else if (nmhz <= 333) {
  406. pdram_timing->cl = 5;
  407. pdram_timing->cwl = 2;
  408. pdram_timing->mr[2] = LPDDR2_RL5_WL2;
  409. } else if (nmhz <= 400) {
  410. pdram_timing->cl = 6;
  411. pdram_timing->cwl = 3;
  412. pdram_timing->mr[2] = LPDDR2_RL6_WL3;
  413. } else if (nmhz <= 466) {
  414. pdram_timing->cl = 7;
  415. pdram_timing->cwl = 4;
  416. pdram_timing->mr[2] = LPDDR2_RL7_WL4;
  417. } else {
  418. pdram_timing->cl = 8;
  419. pdram_timing->cwl = 4;
  420. pdram_timing->mr[2] = LPDDR2_RL8_WL4;
  421. }
  422. switch (timing_config->dramds) {
  423. case 120:
  424. pdram_timing->mr[3] = LPDDR2_DS_120;
  425. break;
  426. case 80:
  427. pdram_timing->mr[3] = LPDDR2_DS_80;
  428. break;
  429. case 60:
  430. pdram_timing->mr[3] = LPDDR2_DS_60;
  431. break;
  432. case 48:
  433. pdram_timing->mr[3] = LPDDR2_DS_48;
  434. break;
  435. case 40:
  436. pdram_timing->mr[3] = LPDDR2_DS_40;
  437. break;
  438. case 34:
  439. default:
  440. pdram_timing->mr[3] = LPDDR2_DS_34;
  441. break;
  442. }
  443. pdram_timing->mr[0] = 0;
  444. pdram_timing->tinit1 = (LPDDR2_TINIT1 * nmhz + 999) / 1000;
  445. pdram_timing->tinit2 = LPDDR2_TINIT2;
  446. pdram_timing->tinit3 = (LPDDR2_TINIT3 * nmhz + 999) / 1000;
  447. pdram_timing->tinit4 = (LPDDR2_TINIT4 * nmhz + 999) / 1000;
  448. pdram_timing->tinit5 = (LPDDR2_TINIT5 * nmhz + 999) / 1000;
  449. pdram_timing->trstl = LPDDR2_TRSTL;
  450. pdram_timing->trsth = (LPDDR2_TRSTH * nmhz + 999) / 1000;
  451. /*
  452. * tREFI, average periodic refresh interval,
  453. * 15.6us(<256Mb) 7.8us(256Mb-1Gb) 3.9us(2Gb-8Gb)
  454. */
  455. if (ddr_capability_per_die >= 0x10000000)
  456. pdram_timing->trefi = (LPDDR2_TREFI_3_9_US * nmhz + 999)
  457. / 1000;
  458. else
  459. pdram_timing->trefi = (LPDDR2_TREFI_7_8_US * nmhz + 999)
  460. / 1000;
  461. /* base timing */
  462. tmp = ((LPDDR2_TRCD * nmhz + 999) / 1000);
  463. pdram_timing->trcd = max(3, tmp);
  464. /*
  465. * tRPpb, max(3tCK, 15ns(Fast) 18ns(Typ) 24ns(Slow),
  466. */
  467. trppb_tmp = ((LPDDR2_TRP_PB * nmhz + 999) / 1000);
  468. trppb_tmp = max(3, trppb_tmp);
  469. pdram_timing->trppb = trppb_tmp;
  470. /*
  471. * tRPab, max(3tCK, 4-bank:15ns(Fast) 18ns(Typ) 24ns(Slow),
  472. * 8-bank:18ns(Fast) 21ns(Typ) 27ns(Slow))
  473. */
  474. trp_tmp = ((LPDDR2_TRP_AB_8_BANK * nmhz + 999) / 1000);
  475. trp_tmp = max(3, trp_tmp);
  476. pdram_timing->trp = trp_tmp;
  477. twr_tmp = ((LPDDR2_TWR * nmhz + 999) / 1000);
  478. twr_tmp = max(3, twr_tmp);
  479. pdram_timing->twr = twr_tmp;
  480. bl_tmp = (pdram_timing->bl == 16) ? LPDDR2_BL16 :
  481. ((pdram_timing->bl == 8) ? LPDDR2_BL8 : LPDDR2_BL4);
  482. pdram_timing->mr[1] = bl_tmp | LPDDR2_N_WR(twr_tmp);
  483. tmp = ((LPDDR2_TRTP * nmhz + (nmhz >> 1) + 999) / 1000);
  484. pdram_timing->trtp = max(2, tmp);
  485. tras_tmp = ((LPDDR2_TRAS * nmhz + 999) / 1000);
  486. tras_tmp = max(3, tras_tmp);
  487. pdram_timing->tras_min = tras_tmp;
  488. pdram_timing->tras_max = ((LPDDR2_TRAS_MAX * nmhz + 999) / 1000);
  489. pdram_timing->trc = (tras_tmp + trp_tmp);
  490. tmp = ((LPDDR2_TRRD * nmhz + 999) / 1000);
  491. pdram_timing->trrd = max(2, tmp);
  492. pdram_timing->tccd = LPDDR2_TCCD;
  493. /* tWTR, max(2tCK, 7.5ns(533-266MHz) 10ns(200-166MHz)) */
  494. if (nmhz > 200)
  495. tmp = ((LPDDR2_TWTR_GREAT_200MHZ * nmhz + (nmhz >> 1) +
  496. 999) / 1000);
  497. else
  498. tmp = ((LPDDR2_TWTR_LITTLE_200MHZ * nmhz + 999) / 1000);
  499. pdram_timing->twtr = max(2, tmp);
  500. pdram_timing->trtw = LPDDR2_TRTW;
  501. if (nmhz <= 200)
  502. pdram_timing->tfaw = (LPDDR2_TFAW_LITTLE_200MHZ * nmhz + 999)
  503. / 1000;
  504. else
  505. pdram_timing->tfaw = (LPDDR2_TFAW_GREAT_200MHZ * nmhz + 999)
  506. / 1000;
  507. /* tRFC, 90ns(<=512Mb) 130ns(1Gb-4Gb) 210ns(8Gb) */
  508. if (ddr_capability_per_die >= 0x40000000) {
  509. pdram_timing->trfc =
  510. (LPDDR2_TRFC_8GBIT * nmhz + 999) / 1000;
  511. tmp = (((LPDDR2_TRFC_8GBIT + 10) * nmhz + 999) / 1000);
  512. } else {
  513. pdram_timing->trfc =
  514. (LPDDR2_TRFC_4GBIT * nmhz + 999) / 1000;
  515. tmp = (((LPDDR2_TRFC_4GBIT + 10) * nmhz + 999) / 1000);
  516. }
  517. if (tmp < 2)
  518. tmp = 2;
  519. pdram_timing->txsr = tmp;
  520. pdram_timing->txsnr = tmp;
  521. /* tdqsck use rounded down */
  522. pdram_timing->tdqsck = ((LPDDR2_TDQSCK_MIN * nmhz + (nmhz >> 1))
  523. / 1000);
  524. pdram_timing->tdqsck_max =
  525. ((LPDDR2_TDQSCK_MAX * nmhz + (nmhz >> 1) + 999)
  526. / 1000);
  527. /* pd and sr */
  528. tmp = ((LPDDR2_TXP * nmhz + (nmhz >> 1) + 999) / 1000);
  529. pdram_timing->txp = max(2, tmp);
  530. pdram_timing->txpdll = LPDDR2_TXPDLL;
  531. pdram_timing->tdllk = LPDDR2_TDLLK;
  532. pdram_timing->tcke = LPDDR2_TCKE;
  533. tmp = ((LPDDR2_TCKESR * nmhz + 999) / 1000);
  534. pdram_timing->tckesr = max(3, tmp);
  535. pdram_timing->tcksre = LPDDR2_TCKSRE;
  536. pdram_timing->tcksrx = LPDDR2_TCKSRX;
  537. /* mode register timing */
  538. pdram_timing->tmod = LPDDR2_TMOD;
  539. pdram_timing->tmrd = LPDDR2_TMRD;
  540. pdram_timing->tmrr = LPDDR2_TMRR;
  541. /* ZQ */
  542. pdram_timing->tzqinit = (LPDDR2_TZQINIT * nmhz + 999) / 1000;
  543. tmp = ((LPDDR2_TZQCS * nmhz + 999) / 1000);
  544. pdram_timing->tzqcs = max(6, tmp);
  545. tmp = ((LPDDR2_TZQCL * nmhz + 999) / 1000);
  546. pdram_timing->tzqoper = max(6, tmp);
  547. tmp = ((LPDDR2_TZQRESET * nmhz + 999) / 1000);
  548. pdram_timing->tzqreset = max(3, tmp);
  549. }
  550. #define LPDDR3_TINIT1 (100) /* ns */
  551. #define LPDDR3_TINIT2 (5) /* tCK */
  552. #define LPDDR3_TINIT3 (200000) /* 200us */
  553. #define LPDDR3_TINIT4 (1000) /* 1us */
  554. #define LPDDR3_TINIT5 (10000) /* 10us */
  555. #define LPDDR3_TRSTL (0)
  556. #define LPDDR3_TRSTH (0) /* 500us */
  557. #define LPDDR3_TREFI_3_9_US (3900) /* 3.9us */
  558. /* base timging */
  559. #define LPDDR3_TRCD (18) /* tRCD,15ns(Fast)18ns(Typ)24ns(Slow) */
  560. #define LPDDR3_TRP_PB (18) /* tRPpb, 15ns(Fast) 18ns(Typ) 24ns(Slow) */
  561. #define LPDDR3_TRP_AB (21) /* tRPab, 18ns(Fast) 21ns(Typ) 27ns(Slow) */
  562. #define LPDDR3_TWR (15) /* tWR, max(4tCK,15ns) */
  563. #define LPDDR3_TRTP (7) /* tRTP, max(4tCK, 7.5ns) */
  564. #define LPDDR3_TRRD (10) /* tRRD, max(2tCK,10ns) */
  565. #define LPDDR3_TCCD (4) /* tCK */
  566. #define LPDDR3_TWTR (7) /* tWTR, max(4tCK, 7.5ns) */
  567. #define LPDDR3_TRTW (0) /* tCK register min valid value */
  568. #define LPDDR3_TRAS_MAX (70000) /* 70us */
  569. #define LPDDR3_TRAS (42) /* tRAS, max(3tCK,42ns) */
  570. #define LPDDR3_TFAW (50) /* tFAW,max(8tCK, 50ns) */
  571. #define LPDDR3_TRFC_8GBIT (210) /* tRFC, 130ns(4Gb) 210ns(>4Gb) */
  572. #define LPDDR3_TRFC_4GBIT (130) /* ns */
  573. #define LPDDR3_TDQSCK_MIN (2) /* tDQSCKmin,2.5ns */
  574. #define LPDDR3_TDQSCK_MAX (5) /* tDQSCKmax,5.5ns */
  575. /* pd and sr */
  576. #define LPDDR3_TXP (7) /* tXP, max(3tCK,7.5ns) */
  577. #define LPDDR3_TXPDLL (0)
  578. #define LPDDR3_TCKE (7) /* tCKE, (max 7.5ns,3 tCK) */
  579. #define LPDDR3_TCKESR (15) /* tCKESR, max(3tCK,15ns) */
  580. #define LPDDR3_TCKSRE (2) /* tCKSRE=tCPDED, 2 tCK */
  581. #define LPDDR3_TCKSRX (2) /* tCKSRX, 2 tCK */
  582. /* mode register timing */
  583. #define LPDDR3_TMOD (0)
  584. #define LPDDR3_TMRD (14) /* tMRD, (=tMRW), max(14ns, 10 tCK) */
  585. #define LPDDR3_TMRR (4) /* tMRR, 4 tCK */
  586. #define LPDDR3_TMRRI LPDDR3_TRCD
  587. /* ODT */
  588. #define LPDDR3_TODTON (3) /* 3.5ns */
  589. /* ZQ */
  590. #define LPDDR3_TZQINIT (1000) /* 1us */
  591. #define LPDDR3_TZQCS (90) /* tZQCS, 90ns */
  592. #define LPDDR3_TZQCL (360) /* 360ns */
  593. #define LPDDR3_TZQRESET (50) /* ZQreset, max(3tCK,50ns) */
  594. /* write leveling */
  595. #define LPDDR3_TWLMRD (40) /* ns */
  596. #define LPDDR3_TWLO (20) /* ns */
  597. #define LPDDR3_TWLDQSEN (25) /* ns */
  598. /* CA training */
  599. #define LPDDR3_TCACKEL (10) /* tCK */
  600. #define LPDDR3_TCAENT (10) /* tCK */
  601. #define LPDDR3_TCAMRD (20) /* tCK */
  602. #define LPDDR3_TCACKEH (10) /* tCK */
  603. #define LPDDR3_TCAEXT (10) /* tCK */
  604. #define LPDDR3_TADR (20) /* ns */
  605. #define LPDDR3_TMRZ (3) /* ns */
  606. /* FSP */
  607. #define LPDDR3_TFC_LONG (250) /* ns */
  608. /*
  609. * Description: depend on input parameter "timing_config",
  610. * and calculate all lpddr3
  611. * spec timing to "pdram_timing"
  612. * parameters:
  613. * input: timing_config
  614. * output: pdram_timing
  615. */
  616. static void lpddr3_get_parameter(struct timing_related_config *timing_config,
  617. struct dram_timing_t *pdram_timing)
  618. {
  619. uint32_t nmhz = timing_config->freq;
  620. uint32_t ddr_capability_per_die = get_max_die_capability(timing_config);
  621. uint32_t tmp, trp_tmp, trppb_tmp, tras_tmp, twr_tmp, bl_tmp;
  622. zeromem((void *)pdram_timing, sizeof(struct dram_timing_t));
  623. pdram_timing->mhz = nmhz;
  624. pdram_timing->al = 0;
  625. pdram_timing->bl = timing_config->bl;
  626. /*
  627. * Only support Write Latency Set A here
  628. * 1066 933 800 733 667 600 533 400 166
  629. * RL, 16 14 12 11 10 9 8 6 3
  630. * WL, 8 8 6 6 6 5 4 3 1
  631. */
  632. if (nmhz <= 400) {
  633. pdram_timing->cl = 6;
  634. pdram_timing->cwl = 3;
  635. pdram_timing->mr[2] = LPDDR3_RL6_WL3;
  636. } else if (nmhz <= 533) {
  637. pdram_timing->cl = 8;
  638. pdram_timing->cwl = 4;
  639. pdram_timing->mr[2] = LPDDR3_RL8_WL4;
  640. } else if (nmhz <= 600) {
  641. pdram_timing->cl = 9;
  642. pdram_timing->cwl = 5;
  643. pdram_timing->mr[2] = LPDDR3_RL9_WL5;
  644. } else if (nmhz <= 667) {
  645. pdram_timing->cl = 10;
  646. pdram_timing->cwl = 6;
  647. pdram_timing->mr[2] = LPDDR3_RL10_WL6;
  648. } else if (nmhz <= 733) {
  649. pdram_timing->cl = 11;
  650. pdram_timing->cwl = 6;
  651. pdram_timing->mr[2] = LPDDR3_RL11_WL6;
  652. } else if (nmhz <= 800) {
  653. pdram_timing->cl = 12;
  654. pdram_timing->cwl = 6;
  655. pdram_timing->mr[2] = LPDDR3_RL12_WL6;
  656. } else if (nmhz <= 933) {
  657. pdram_timing->cl = 14;
  658. pdram_timing->cwl = 8;
  659. pdram_timing->mr[2] = LPDDR3_RL14_WL8;
  660. } else {
  661. pdram_timing->cl = 16;
  662. pdram_timing->cwl = 8;
  663. pdram_timing->mr[2] = LPDDR3_RL16_WL8;
  664. }
  665. switch (timing_config->dramds) {
  666. case 80:
  667. pdram_timing->mr[3] = LPDDR3_DS_80;
  668. break;
  669. case 60:
  670. pdram_timing->mr[3] = LPDDR3_DS_60;
  671. break;
  672. case 48:
  673. pdram_timing->mr[3] = LPDDR3_DS_48;
  674. break;
  675. case 40:
  676. pdram_timing->mr[3] = LPDDR3_DS_40;
  677. break;
  678. case 3440:
  679. pdram_timing->mr[3] = LPDDR3_DS_34D_40U;
  680. break;
  681. case 4048:
  682. pdram_timing->mr[3] = LPDDR3_DS_40D_48U;
  683. break;
  684. case 3448:
  685. pdram_timing->mr[3] = LPDDR3_DS_34D_48U;
  686. break;
  687. case 34:
  688. default:
  689. pdram_timing->mr[3] = LPDDR3_DS_34;
  690. break;
  691. }
  692. pdram_timing->mr[0] = 0;
  693. if (timing_config->odt)
  694. switch (timing_config->dramodt) {
  695. case 60:
  696. pdram_timing->mr11 = LPDDR3_ODT_60;
  697. break;
  698. case 120:
  699. pdram_timing->mr11 = LPDDR3_ODT_120;
  700. break;
  701. case 240:
  702. default:
  703. pdram_timing->mr11 = LPDDR3_ODT_240;
  704. break;
  705. }
  706. else
  707. pdram_timing->mr11 = LPDDR3_ODT_DIS;
  708. pdram_timing->tinit1 = (LPDDR3_TINIT1 * nmhz + 999) / 1000;
  709. pdram_timing->tinit2 = LPDDR3_TINIT2;
  710. pdram_timing->tinit3 = (LPDDR3_TINIT3 * nmhz + 999) / 1000;
  711. pdram_timing->tinit4 = (LPDDR3_TINIT4 * nmhz + 999) / 1000;
  712. pdram_timing->tinit5 = (LPDDR3_TINIT5 * nmhz + 999) / 1000;
  713. pdram_timing->trstl = LPDDR3_TRSTL;
  714. pdram_timing->trsth = (LPDDR3_TRSTH * nmhz + 999) / 1000;
  715. /* tREFI, average periodic refresh interval, 3.9us(4Gb-16Gb) */
  716. pdram_timing->trefi = (LPDDR3_TREFI_3_9_US * nmhz + 999) / 1000;
  717. /* base timing */
  718. tmp = ((LPDDR3_TRCD * nmhz + 999) / 1000);
  719. pdram_timing->trcd = max(3, tmp);
  720. trppb_tmp = ((LPDDR3_TRP_PB * nmhz + 999) / 1000);
  721. trppb_tmp = max(3, trppb_tmp);
  722. pdram_timing->trppb = trppb_tmp;
  723. trp_tmp = ((LPDDR3_TRP_AB * nmhz + 999) / 1000);
  724. trp_tmp = max(3, trp_tmp);
  725. pdram_timing->trp = trp_tmp;
  726. twr_tmp = ((LPDDR3_TWR * nmhz + 999) / 1000);
  727. twr_tmp = max(4, twr_tmp);
  728. pdram_timing->twr = twr_tmp;
  729. if (twr_tmp <= 6)
  730. twr_tmp = 6;
  731. else if (twr_tmp <= 8)
  732. twr_tmp = 8;
  733. else if (twr_tmp <= 12)
  734. twr_tmp = twr_tmp;
  735. else if (twr_tmp <= 14)
  736. twr_tmp = 14;
  737. else
  738. twr_tmp = 16;
  739. if (twr_tmp > 9)
  740. pdram_timing->mr[2] |= (1 << 4); /*enable nWR > 9*/
  741. twr_tmp = (twr_tmp > 9) ? (twr_tmp - 10) : (twr_tmp - 2);
  742. bl_tmp = LPDDR3_BL8;
  743. pdram_timing->mr[1] = bl_tmp | LPDDR3_N_WR(twr_tmp);
  744. tmp = ((LPDDR3_TRTP * nmhz + (nmhz >> 1) + 999) / 1000);
  745. pdram_timing->trtp = max(4, tmp);
  746. tras_tmp = ((LPDDR3_TRAS * nmhz + 999) / 1000);
  747. tras_tmp = max(3, tras_tmp);
  748. pdram_timing->tras_min = tras_tmp;
  749. pdram_timing->trc = (tras_tmp + trp_tmp);
  750. tmp = ((LPDDR3_TRRD * nmhz + 999) / 1000);
  751. pdram_timing->trrd = max(2, tmp);
  752. pdram_timing->tccd = LPDDR3_TCCD;
  753. tmp = ((LPDDR3_TWTR * nmhz + (nmhz >> 1) + 999) / 1000);
  754. pdram_timing->twtr = max(4, tmp);
  755. pdram_timing->trtw = ((LPDDR3_TRTW * nmhz + 999) / 1000);
  756. pdram_timing->tras_max = ((LPDDR3_TRAS_MAX * nmhz + 999) / 1000);
  757. tmp = (LPDDR3_TFAW * nmhz + 999) / 1000;
  758. pdram_timing->tfaw = max(8, tmp);
  759. if (ddr_capability_per_die > 0x20000000) {
  760. pdram_timing->trfc =
  761. (LPDDR3_TRFC_8GBIT * nmhz + 999) / 1000;
  762. tmp = (((LPDDR3_TRFC_8GBIT + 10) * nmhz + 999) / 1000);
  763. } else {
  764. pdram_timing->trfc =
  765. (LPDDR3_TRFC_4GBIT * nmhz + 999) / 1000;
  766. tmp = (((LPDDR3_TRFC_4GBIT + 10) * nmhz + 999) / 1000);
  767. }
  768. pdram_timing->txsr = max(2, tmp);
  769. pdram_timing->txsnr = max(2, tmp);
  770. /* tdqsck use rounded down */
  771. pdram_timing->tdqsck =
  772. ((LPDDR3_TDQSCK_MIN * nmhz + (nmhz >> 1))
  773. / 1000);
  774. pdram_timing->tdqsck_max =
  775. ((LPDDR3_TDQSCK_MAX * nmhz + (nmhz >> 1) + 999)
  776. / 1000);
  777. /*pd and sr*/
  778. tmp = ((LPDDR3_TXP * nmhz + (nmhz >> 1) + 999) / 1000);
  779. pdram_timing->txp = max(3, tmp);
  780. pdram_timing->txpdll = LPDDR3_TXPDLL;
  781. tmp = ((LPDDR3_TCKE * nmhz + (nmhz >> 1) + 999) / 1000);
  782. pdram_timing->tcke = max(3, tmp);
  783. tmp = ((LPDDR3_TCKESR * nmhz + 999) / 1000);
  784. pdram_timing->tckesr = max(3, tmp);
  785. pdram_timing->tcksre = LPDDR3_TCKSRE;
  786. pdram_timing->tcksrx = LPDDR3_TCKSRX;
  787. /*mode register timing*/
  788. pdram_timing->tmod = LPDDR3_TMOD;
  789. tmp = ((LPDDR3_TMRD * nmhz + 999) / 1000);
  790. pdram_timing->tmrd = max(10, tmp);
  791. pdram_timing->tmrr = LPDDR3_TMRR;
  792. tmp = ((LPDDR3_TRCD * nmhz + 999) / 1000);
  793. pdram_timing->tmrri = max(3, tmp);
  794. /* ODT */
  795. pdram_timing->todton = (LPDDR3_TODTON * nmhz + (nmhz >> 1) + 999)
  796. / 1000;
  797. /* ZQ */
  798. pdram_timing->tzqinit = (LPDDR3_TZQINIT * nmhz + 999) / 1000;
  799. pdram_timing->tzqcs =
  800. ((LPDDR3_TZQCS * nmhz + 999) / 1000);
  801. pdram_timing->tzqoper =
  802. ((LPDDR3_TZQCL * nmhz + 999) / 1000);
  803. tmp = ((LPDDR3_TZQRESET * nmhz + 999) / 1000);
  804. pdram_timing->tzqreset = max(3, tmp);
  805. /* write leveling */
  806. pdram_timing->twlmrd = (LPDDR3_TWLMRD * nmhz + 999) / 1000;
  807. pdram_timing->twlo = (LPDDR3_TWLO * nmhz + 999) / 1000;
  808. pdram_timing->twldqsen = (LPDDR3_TWLDQSEN * nmhz + 999) / 1000;
  809. /* CA training */
  810. pdram_timing->tcackel = LPDDR3_TCACKEL;
  811. pdram_timing->tcaent = LPDDR3_TCAENT;
  812. pdram_timing->tcamrd = LPDDR3_TCAMRD;
  813. pdram_timing->tcackeh = LPDDR3_TCACKEH;
  814. pdram_timing->tcaext = LPDDR3_TCAEXT;
  815. pdram_timing->tadr = (LPDDR3_TADR * nmhz + 999) / 1000;
  816. pdram_timing->tmrz = (LPDDR3_TMRZ * nmhz + 999) / 1000;
  817. pdram_timing->tcacd = pdram_timing->tadr + 2;
  818. /* FSP */
  819. pdram_timing->tfc_long = (LPDDR3_TFC_LONG * nmhz + 999) / 1000;
  820. }
  821. #define LPDDR4_TINIT1 (200000) /* 200us */
  822. #define LPDDR4_TINIT2 (10) /* 10ns */
  823. #define LPDDR4_TINIT3 (2000000) /* 2ms */
  824. #define LPDDR4_TINIT4 (5) /* tCK */
  825. #define LPDDR4_TINIT5 (2000) /* 2us */
  826. #define LPDDR4_TRSTL LPDDR4_TINIT1
  827. #define LPDDR4_TRSTH LPDDR4_TINIT3
  828. #define LPDDR4_TREFI_3_9_US (3900) /* 3.9us */
  829. /* base timging */
  830. #define LPDDR4_TRCD (18) /* tRCD, max(18ns,4tCK) */
  831. #define LPDDR4_TRP_PB (18) /* tRPpb, max(18ns, 4tCK) */
  832. #define LPDDR4_TRP_AB (21) /* tRPab, max(21ns, 4tCK) */
  833. #define LPDDR4_TRRD (10) /* tRRD, max(4tCK,10ns) */
  834. #define LPDDR4_TCCD_BL16 (8) /* tCK */
  835. #define LPDDR4_TCCD_BL32 (16) /* tCK */
  836. #define LPDDR4_TWTR (10) /* tWTR, max(8tCK, 10ns) */
  837. #define LPDDR4_TRTW (0) /* tCK register min valid value */
  838. #define LPDDR4_TRAS_MAX (70000) /* 70us */
  839. #define LPDDR4_TRAS (42) /* tRAS, max(3tCK,42ns) */
  840. #define LPDDR4_TFAW (40) /* tFAW,min 40ns) */
  841. #define LPDDR4_TRFC_12GBIT (280) /* tRFC, 280ns(>=12Gb) */
  842. #define LPDDR4_TRFC_6GBIT (180) /* 6Gb/8Gb 180ns */
  843. #define LPDDR4_TRFC_4GBIT (130) /* 4Gb 130ns */
  844. #define LPDDR4_TDQSCK_MIN (1) /* tDQSCKmin,1.5ns */
  845. #define LPDDR4_TDQSCK_MAX (3) /* tDQSCKmax,3.5ns */
  846. #define LPDDR4_TPPD (4) /* tCK */
  847. /* pd and sr */
  848. #define LPDDR4_TXP (7) /* tXP, max(5tCK,7.5ns) */
  849. #define LPDDR4_TCKE (7) /* tCKE, max(7.5ns,4 tCK) */
  850. #define LPDDR4_TESCKE (1) /* tESCKE, max(1.75ns, 3tCK) */
  851. #define LPDDR4_TSR (15) /* tSR, max(15ns, 3tCK) */
  852. #define LPDDR4_TCMDCKE (1) /* max(1.75ns, 3tCK) */
  853. #define LPDDR4_TCSCKE (1) /* 1.75ns */
  854. #define LPDDR4_TCKELCS (5) /* max(5ns, 5tCK) */
  855. #define LPDDR4_TCSCKEH (1) /* 1.75ns */
  856. #define LPDDR4_TCKEHCS (7) /* max(7.5ns, 5tCK) */
  857. #define LPDDR4_TMRWCKEL (14) /* max(14ns, 10tCK) */
  858. #define LPDDR4_TCKELCMD (7) /* max(7.5ns, 3tCK) */
  859. #define LPDDR4_TCKEHCMD (7) /* max(7.5ns, 3tCK) */
  860. #define LPDDR4_TCKELPD (7) /* max(7.5ns, 3tCK) */
  861. #define LPDDR4_TCKCKEL (7) /* max(7.5ns, 3tCK) */
  862. /* mode register timing */
  863. #define LPDDR4_TMRD (14) /* tMRD, (=tMRW), max(14ns, 10 tCK) */
  864. #define LPDDR4_TMRR (8) /* tMRR, 8 tCK */
  865. /* ODT */
  866. #define LPDDR4_TODTON (3) /* 3.5ns */
  867. /* ZQ */
  868. #define LPDDR4_TZQCAL (1000) /* 1us */
  869. #define LPDDR4_TZQLAT (30) /* tZQLAT, max(30ns,8tCK) */
  870. #define LPDDR4_TZQRESET (50) /* ZQreset, max(3tCK,50ns) */
  871. #define LPDDR4_TZQCKE (1) /* tZQCKE, max(1.75ns, 3tCK) */
  872. /* write leveling */
  873. #define LPDDR4_TWLMRD (40) /* tCK */
  874. #define LPDDR4_TWLO (20) /* ns */
  875. #define LPDDR4_TWLDQSEN (20) /* tCK */
  876. /* CA training */
  877. #define LPDDR4_TCAENT (250) /* ns */
  878. #define LPDDR4_TADR (20) /* ns */
  879. #define LPDDR4_TMRZ (1) /* 1.5ns */
  880. #define LPDDR4_TVREF_LONG (250) /* ns */
  881. #define LPDDR4_TVREF_SHORT (100) /* ns */
  882. /* VRCG */
  883. #define LPDDR4_TVRCG_ENABLE (200) /* ns */
  884. #define LPDDR4_TVRCG_DISABLE (100) /* ns */
  885. /* FSP */
  886. #define LPDDR4_TFC_LONG (250) /* ns */
  887. #define LPDDR4_TCKFSPE (7) /* max(7.5ns, 4tCK) */
  888. #define LPDDR4_TCKFSPX (7) /* max(7.5ns, 4tCK) */
  889. /*
  890. * Description: depend on input parameter "timing_config",
  891. * and calculate all lpddr4
  892. * spec timing to "pdram_timing"
  893. * parameters:
  894. * input: timing_config
  895. * output: pdram_timing
  896. */
  897. static void lpddr4_get_parameter(struct timing_related_config *timing_config,
  898. struct dram_timing_t *pdram_timing)
  899. {
  900. uint32_t nmhz = timing_config->freq;
  901. uint32_t ddr_capability_per_die = get_max_die_capability(timing_config);
  902. uint32_t tmp, trp_tmp, trppb_tmp, tras_tmp;
  903. zeromem((void *)pdram_timing, sizeof(struct dram_timing_t));
  904. pdram_timing->mhz = nmhz;
  905. pdram_timing->al = 0;
  906. pdram_timing->bl = timing_config->bl;
  907. /*
  908. * Only support Write Latency Set A here
  909. * 2133 1866 1600 1333 1066 800 533 266
  910. * RL, 36 32 28 24 20 14 10 6
  911. * WL, 18 16 14 12 10 8 6 4
  912. * nWR, 40 34 30 24 20 16 10 6
  913. * nRTP,16 14 12 10 8 8 8 8
  914. */
  915. tmp = (timing_config->bl == 32) ? 1 : 0;
  916. /*
  917. * we always use WR preamble = 2tCK
  918. * RD preamble = Static
  919. */
  920. tmp |= (1 << 2);
  921. if (nmhz <= 266) {
  922. pdram_timing->cl = 6;
  923. pdram_timing->cwl = 4;
  924. pdram_timing->twr = 6;
  925. pdram_timing->trtp = 8;
  926. pdram_timing->mr[2] = LPDDR4_RL6_NRTP8 | LPDDR4_A_WL4;
  927. } else if (nmhz <= 533) {
  928. if (timing_config->rdbi) {
  929. pdram_timing->cl = 12;
  930. pdram_timing->mr[2] = LPDDR4_RL12_NRTP8 | LPDDR4_A_WL6;
  931. } else {
  932. pdram_timing->cl = 10;
  933. pdram_timing->mr[2] = LPDDR4_RL10_NRTP8 | LPDDR4_A_WL6;
  934. }
  935. pdram_timing->cwl = 6;
  936. pdram_timing->twr = 10;
  937. pdram_timing->trtp = 8;
  938. tmp |= (1 << 4);
  939. } else if (nmhz <= 800) {
  940. if (timing_config->rdbi) {
  941. pdram_timing->cl = 16;
  942. pdram_timing->mr[2] = LPDDR4_RL16_NRTP8 | LPDDR4_A_WL8;
  943. } else {
  944. pdram_timing->cl = 14;
  945. pdram_timing->mr[2] = LPDDR4_RL14_NRTP8 | LPDDR4_A_WL8;
  946. }
  947. pdram_timing->cwl = 8;
  948. pdram_timing->twr = 16;
  949. pdram_timing->trtp = 8;
  950. tmp |= (2 << 4);
  951. } else if (nmhz <= 1066) {
  952. if (timing_config->rdbi) {
  953. pdram_timing->cl = 22;
  954. pdram_timing->mr[2] = LPDDR4_RL22_NRTP8 | LPDDR4_A_WL10;
  955. } else {
  956. pdram_timing->cl = 20;
  957. pdram_timing->mr[2] = LPDDR4_RL20_NRTP8 | LPDDR4_A_WL10;
  958. }
  959. pdram_timing->cwl = 10;
  960. pdram_timing->twr = 20;
  961. pdram_timing->trtp = 8;
  962. tmp |= (3 << 4);
  963. } else if (nmhz <= 1333) {
  964. if (timing_config->rdbi) {
  965. pdram_timing->cl = 28;
  966. pdram_timing->mr[2] = LPDDR4_RL28_NRTP10 |
  967. LPDDR4_A_WL12;
  968. } else {
  969. pdram_timing->cl = 24;
  970. pdram_timing->mr[2] = LPDDR4_RL24_NRTP10 |
  971. LPDDR4_A_WL12;
  972. }
  973. pdram_timing->cwl = 12;
  974. pdram_timing->twr = 24;
  975. pdram_timing->trtp = 10;
  976. tmp |= (4 << 4);
  977. } else if (nmhz <= 1600) {
  978. if (timing_config->rdbi) {
  979. pdram_timing->cl = 32;
  980. pdram_timing->mr[2] = LPDDR4_RL32_NRTP12 |
  981. LPDDR4_A_WL14;
  982. } else {
  983. pdram_timing->cl = 28;
  984. pdram_timing->mr[2] = LPDDR4_RL28_NRTP12 |
  985. LPDDR4_A_WL14;
  986. }
  987. pdram_timing->cwl = 14;
  988. pdram_timing->twr = 30;
  989. pdram_timing->trtp = 12;
  990. tmp |= (5 << 4);
  991. } else if (nmhz <= 1866) {
  992. if (timing_config->rdbi) {
  993. pdram_timing->cl = 36;
  994. pdram_timing->mr[2] = LPDDR4_RL36_NRTP14 |
  995. LPDDR4_A_WL16;
  996. } else {
  997. pdram_timing->cl = 32;
  998. pdram_timing->mr[2] = LPDDR4_RL32_NRTP14 |
  999. LPDDR4_A_WL16;
  1000. }
  1001. pdram_timing->cwl = 16;
  1002. pdram_timing->twr = 34;
  1003. pdram_timing->trtp = 14;
  1004. tmp |= (6 << 4);
  1005. } else {
  1006. if (timing_config->rdbi) {
  1007. pdram_timing->cl = 40;
  1008. pdram_timing->mr[2] = LPDDR4_RL40_NRTP16 |
  1009. LPDDR4_A_WL18;
  1010. } else {
  1011. pdram_timing->cl = 36;
  1012. pdram_timing->mr[2] = LPDDR4_RL36_NRTP16 |
  1013. LPDDR4_A_WL18;
  1014. }
  1015. pdram_timing->cwl = 18;
  1016. pdram_timing->twr = 40;
  1017. pdram_timing->trtp = 16;
  1018. tmp |= (7 << 4);
  1019. }
  1020. pdram_timing->mr[1] = tmp;
  1021. tmp = (timing_config->rdbi ? LPDDR4_DBI_RD_EN : 0) |
  1022. (timing_config->wdbi ? LPDDR4_DBI_WR_EN : 0);
  1023. switch (timing_config->dramds) {
  1024. case 240:
  1025. pdram_timing->mr[3] = LPDDR4_PDDS_240 | tmp;
  1026. break;
  1027. case 120:
  1028. pdram_timing->mr[3] = LPDDR4_PDDS_120 | tmp;
  1029. break;
  1030. case 80:
  1031. pdram_timing->mr[3] = LPDDR4_PDDS_80 | tmp;
  1032. break;
  1033. case 60:
  1034. pdram_timing->mr[3] = LPDDR4_PDDS_60 | tmp;
  1035. break;
  1036. case 48:
  1037. pdram_timing->mr[3] = LPDDR4_PDDS_48 | tmp;
  1038. break;
  1039. case 40:
  1040. default:
  1041. pdram_timing->mr[3] = LPDDR4_PDDS_40 | tmp;
  1042. break;
  1043. }
  1044. pdram_timing->mr[0] = 0;
  1045. if (timing_config->odt) {
  1046. switch (timing_config->dramodt) {
  1047. case 240:
  1048. tmp = LPDDR4_DQODT_240;
  1049. break;
  1050. case 120:
  1051. tmp = LPDDR4_DQODT_120;
  1052. break;
  1053. case 80:
  1054. tmp = LPDDR4_DQODT_80;
  1055. break;
  1056. case 60:
  1057. tmp = LPDDR4_DQODT_60;
  1058. break;
  1059. case 48:
  1060. tmp = LPDDR4_DQODT_48;
  1061. break;
  1062. case 40:
  1063. default:
  1064. tmp = LPDDR4_DQODT_40;
  1065. break;
  1066. }
  1067. switch (timing_config->caodt) {
  1068. case 240:
  1069. pdram_timing->mr11 = LPDDR4_CAODT_240 | tmp;
  1070. break;
  1071. case 120:
  1072. pdram_timing->mr11 = LPDDR4_CAODT_120 | tmp;
  1073. break;
  1074. case 80:
  1075. pdram_timing->mr11 = LPDDR4_CAODT_80 | tmp;
  1076. break;
  1077. case 60:
  1078. pdram_timing->mr11 = LPDDR4_CAODT_60 | tmp;
  1079. break;
  1080. case 48:
  1081. pdram_timing->mr11 = LPDDR4_CAODT_48 | tmp;
  1082. break;
  1083. case 40:
  1084. default:
  1085. pdram_timing->mr11 = LPDDR4_CAODT_40 | tmp;
  1086. break;
  1087. }
  1088. } else {
  1089. pdram_timing->mr11 = LPDDR4_CAODT_DIS | tmp;
  1090. }
  1091. pdram_timing->tinit1 = (LPDDR4_TINIT1 * nmhz + 999) / 1000;
  1092. pdram_timing->tinit2 = (LPDDR4_TINIT2 * nmhz + 999) / 1000;
  1093. pdram_timing->tinit3 = (LPDDR4_TINIT3 * nmhz + 999) / 1000;
  1094. pdram_timing->tinit4 = (LPDDR4_TINIT4 * nmhz + 999) / 1000;
  1095. pdram_timing->tinit5 = (LPDDR4_TINIT5 * nmhz + 999) / 1000;
  1096. pdram_timing->trstl = (LPDDR4_TRSTL * nmhz + 999) / 1000;
  1097. pdram_timing->trsth = (LPDDR4_TRSTH * nmhz + 999) / 1000;
  1098. /* tREFI, average periodic refresh interval, 3.9us(4Gb-16Gb) */
  1099. pdram_timing->trefi = (LPDDR4_TREFI_3_9_US * nmhz + 999) / 1000;
  1100. /* base timing */
  1101. tmp = ((LPDDR4_TRCD * nmhz + 999) / 1000);
  1102. pdram_timing->trcd = max(4, tmp);
  1103. trppb_tmp = ((LPDDR4_TRP_PB * nmhz + 999) / 1000);
  1104. trppb_tmp = max(4, trppb_tmp);
  1105. pdram_timing->trppb = trppb_tmp;
  1106. trp_tmp = ((LPDDR4_TRP_AB * nmhz + 999) / 1000);
  1107. trp_tmp = max(4, trp_tmp);
  1108. pdram_timing->trp = trp_tmp;
  1109. tras_tmp = ((LPDDR4_TRAS * nmhz + 999) / 1000);
  1110. tras_tmp = max(3, tras_tmp);
  1111. pdram_timing->tras_min = tras_tmp;
  1112. pdram_timing->trc = (tras_tmp + trp_tmp);
  1113. tmp = ((LPDDR4_TRRD * nmhz + 999) / 1000);
  1114. pdram_timing->trrd = max(4, tmp);
  1115. if (timing_config->bl == 32)
  1116. pdram_timing->tccd = LPDDR4_TCCD_BL16;
  1117. else
  1118. pdram_timing->tccd = LPDDR4_TCCD_BL32;
  1119. pdram_timing->tccdmw = 4 * pdram_timing->tccd;
  1120. tmp = ((LPDDR4_TWTR * nmhz + 999) / 1000);
  1121. pdram_timing->twtr = max(8, tmp);
  1122. pdram_timing->trtw = ((LPDDR4_TRTW * nmhz + 999) / 1000);
  1123. pdram_timing->tras_max = ((LPDDR4_TRAS_MAX * nmhz + 999) / 1000);
  1124. pdram_timing->tfaw = (LPDDR4_TFAW * nmhz + 999) / 1000;
  1125. if (ddr_capability_per_die > 0x60000000) {
  1126. /* >= 12Gb */
  1127. pdram_timing->trfc =
  1128. (LPDDR4_TRFC_12GBIT * nmhz + 999) / 1000;
  1129. tmp = (((LPDDR4_TRFC_12GBIT + 7) * nmhz + (nmhz >> 1) +
  1130. 999) / 1000);
  1131. } else if (ddr_capability_per_die > 0x30000000) {
  1132. pdram_timing->trfc =
  1133. (LPDDR4_TRFC_6GBIT * nmhz + 999) / 1000;
  1134. tmp = (((LPDDR4_TRFC_6GBIT + 7) * nmhz + (nmhz >> 1) +
  1135. 999) / 1000);
  1136. } else {
  1137. pdram_timing->trfc =
  1138. (LPDDR4_TRFC_4GBIT * nmhz + 999) / 1000;
  1139. tmp = (((LPDDR4_TRFC_4GBIT + 7) * nmhz + (nmhz >> 1) +
  1140. 999) / 1000);
  1141. }
  1142. pdram_timing->txsr = max(2, tmp);
  1143. pdram_timing->txsnr = max(2, tmp);
  1144. /* tdqsck use rounded down */
  1145. pdram_timing->tdqsck = ((LPDDR4_TDQSCK_MIN * nmhz +
  1146. (nmhz >> 1)) / 1000);
  1147. pdram_timing->tdqsck_max = ((LPDDR4_TDQSCK_MAX * nmhz +
  1148. (nmhz >> 1) + 999) / 1000);
  1149. pdram_timing->tppd = LPDDR4_TPPD;
  1150. /* pd and sr */
  1151. tmp = ((LPDDR4_TXP * nmhz + (nmhz >> 1) + 999) / 1000);
  1152. pdram_timing->txp = max(5, tmp);
  1153. tmp = ((LPDDR4_TCKE * nmhz + (nmhz >> 1) + 999) / 1000);
  1154. pdram_timing->tcke = max(4, tmp);
  1155. tmp = ((LPDDR4_TESCKE * nmhz +
  1156. ((nmhz * 3) / 4) +
  1157. 999) / 1000);
  1158. pdram_timing->tescke = max(3, tmp);
  1159. tmp = ((LPDDR4_TSR * nmhz + 999) / 1000);
  1160. pdram_timing->tsr = max(3, tmp);
  1161. tmp = ((LPDDR4_TCMDCKE * nmhz +
  1162. ((nmhz * 3) / 4) +
  1163. 999) / 1000);
  1164. pdram_timing->tcmdcke = max(3, tmp);
  1165. pdram_timing->tcscke = ((LPDDR4_TCSCKE * nmhz +
  1166. ((nmhz * 3) / 4) +
  1167. 999) / 1000);
  1168. tmp = ((LPDDR4_TCKELCS * nmhz + 999) / 1000);
  1169. pdram_timing->tckelcs = max(5, tmp);
  1170. pdram_timing->tcsckeh = ((LPDDR4_TCSCKEH * nmhz +
  1171. ((nmhz * 3) / 4) +
  1172. 999) / 1000);
  1173. tmp = ((LPDDR4_TCKEHCS * nmhz +
  1174. (nmhz >> 1) + 999) / 1000);
  1175. pdram_timing->tckehcs = max(5, tmp);
  1176. tmp = ((LPDDR4_TMRWCKEL * nmhz + 999) / 1000);
  1177. pdram_timing->tmrwckel = max(10, tmp);
  1178. tmp = ((LPDDR4_TCKELCMD * nmhz + (nmhz >> 1) +
  1179. 999) / 1000);
  1180. pdram_timing->tckelcmd = max(3, tmp);
  1181. tmp = ((LPDDR4_TCKEHCMD * nmhz + (nmhz >> 1) +
  1182. 999) / 1000);
  1183. pdram_timing->tckehcmd = max(3, tmp);
  1184. tmp = ((LPDDR4_TCKELPD * nmhz + (nmhz >> 1) +
  1185. 999) / 1000);
  1186. pdram_timing->tckelpd = max(3, tmp);
  1187. tmp = ((LPDDR4_TCKCKEL * nmhz + (nmhz >> 1) +
  1188. 999) / 1000);
  1189. pdram_timing->tckckel = max(3, tmp);
  1190. /* mode register timing */
  1191. tmp = ((LPDDR4_TMRD * nmhz + 999) / 1000);
  1192. pdram_timing->tmrd = max(10, tmp);
  1193. pdram_timing->tmrr = LPDDR4_TMRR;
  1194. pdram_timing->tmrri = pdram_timing->trcd + 3;
  1195. /* ODT */
  1196. pdram_timing->todton = (LPDDR4_TODTON * nmhz + (nmhz >> 1) + 999)
  1197. / 1000;
  1198. /* ZQ */
  1199. pdram_timing->tzqcal = (LPDDR4_TZQCAL * nmhz + 999) / 1000;
  1200. tmp = ((LPDDR4_TZQLAT * nmhz + 999) / 1000);
  1201. pdram_timing->tzqlat = max(8, tmp);
  1202. tmp = ((LPDDR4_TZQRESET * nmhz + 999) / 1000);
  1203. pdram_timing->tzqreset = max(3, tmp);
  1204. tmp = ((LPDDR4_TZQCKE * nmhz +
  1205. ((nmhz * 3) / 4) +
  1206. 999) / 1000);
  1207. pdram_timing->tzqcke = max(3, tmp);
  1208. /* write leveling */
  1209. pdram_timing->twlmrd = LPDDR4_TWLMRD;
  1210. pdram_timing->twlo = (LPDDR4_TWLO * nmhz + 999) / 1000;
  1211. pdram_timing->twldqsen = LPDDR4_TWLDQSEN;
  1212. /* CA training */
  1213. pdram_timing->tcaent = (LPDDR4_TCAENT * nmhz + 999) / 1000;
  1214. pdram_timing->tadr = (LPDDR4_TADR * nmhz + 999) / 1000;
  1215. pdram_timing->tmrz = (LPDDR4_TMRZ * nmhz + (nmhz >> 1) + 999) / 1000;
  1216. pdram_timing->tvref_long = (LPDDR4_TVREF_LONG * nmhz + 999) / 1000;
  1217. pdram_timing->tvref_short = (LPDDR4_TVREF_SHORT * nmhz + 999) / 1000;
  1218. /* VRCG */
  1219. pdram_timing->tvrcg_enable = (LPDDR4_TVRCG_ENABLE * nmhz +
  1220. 999) / 1000;
  1221. pdram_timing->tvrcg_disable = (LPDDR4_TVRCG_DISABLE * nmhz +
  1222. 999) / 1000;
  1223. /* FSP */
  1224. pdram_timing->tfc_long = (LPDDR4_TFC_LONG * nmhz + 999) / 1000;
  1225. tmp = (LPDDR4_TCKFSPE * nmhz + (nmhz >> 1) + 999) / 1000;
  1226. pdram_timing->tckfspe = max(4, tmp);
  1227. tmp = (LPDDR4_TCKFSPX * nmhz + (nmhz >> 1) + 999) / 1000;
  1228. pdram_timing->tckfspx = max(4, tmp);
  1229. }
  1230. /*
  1231. * Description: depend on input parameter "timing_config",
  1232. * and calculate correspond "dram_type"
  1233. * spec timing to "pdram_timing"
  1234. * parameters:
  1235. * input: timing_config
  1236. * output: pdram_timing
  1237. * NOTE: MR ODT is set, need to disable by controller
  1238. */
  1239. void dram_get_parameter(struct timing_related_config *timing_config,
  1240. struct dram_timing_t *pdram_timing)
  1241. {
  1242. switch (timing_config->dram_type) {
  1243. case DDR3:
  1244. ddr3_get_parameter(timing_config, pdram_timing);
  1245. break;
  1246. case LPDDR2:
  1247. lpddr2_get_parameter(timing_config, pdram_timing);
  1248. break;
  1249. case LPDDR3:
  1250. lpddr3_get_parameter(timing_config, pdram_timing);
  1251. break;
  1252. case LPDDR4:
  1253. lpddr4_get_parameter(timing_config, pdram_timing);
  1254. break;
  1255. default:
  1256. /* Do nothing in default case */
  1257. break;
  1258. }
  1259. }