dram_spec_timing.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DRAM_SPEC_TIMING_H
  7. #define DRAM_SPEC_TIMING_H
  8. #include <stdint.h>
  9. enum ddr3_speed_rate {
  10. /* 5-5-5 */
  11. DDR3_800D = 0,
  12. /* 6-6-6 */
  13. DDR3_800E = 1,
  14. /* 6-6-6 */
  15. DDR3_1066E = 2,
  16. /* 7-7-7 */
  17. DDR3_1066F = 3,
  18. /* 8-8-8 */
  19. DDR3_1066G = 4,
  20. /* 7-7-7 */
  21. DDR3_1333F = 5,
  22. /* 8-8-8 */
  23. DDR3_1333G = 6,
  24. /* 9-9-9 */
  25. DDR3_1333H = 7,
  26. /* 10-10-10 */
  27. DDR3_1333J = 8,
  28. /* 8-8-8 */
  29. DDR3_1600G = 9,
  30. /* 9-9-9 */
  31. DDR3_1600H = 10,
  32. /* 10-10-10 */
  33. DDR3_1600J = 11,
  34. /* 11-11-11 */
  35. DDR3_1600K = 12,
  36. /* 10-10-10 */
  37. DDR3_1866J = 13,
  38. /* 11-11-11 */
  39. DDR3_1866K = 14,
  40. /* 12-12-12 */
  41. DDR3_1866L = 15,
  42. /* 13-13-13 */
  43. DDR3_1866M = 16,
  44. /* 11-11-11 */
  45. DDR3_2133K = 17,
  46. /* 12-12-12 */
  47. DDR3_2133L = 18,
  48. /* 13-13-13 */
  49. DDR3_2133M = 19,
  50. /* 14-14-14 */
  51. DDR3_2133N = 20,
  52. DDR3_DEFAULT = 21,
  53. };
  54. #define max(a, b) (((a) > (b)) ? (a) : (b))
  55. #define range(mi, val, ma) (((ma) > (val)) ? (max(mi, val)) : (ma))
  56. struct dram_timing_t {
  57. /* unit MHz */
  58. uint32_t mhz;
  59. /* some timing unit is us */
  60. uint32_t tinit1;
  61. uint32_t tinit2;
  62. uint32_t tinit3;
  63. uint32_t tinit4;
  64. uint32_t tinit5;
  65. /* reset low, DDR3:200us */
  66. uint32_t trstl;
  67. /* reset high to CKE high, DDR3:500us */
  68. uint32_t trsth;
  69. uint32_t trefi;
  70. /* base */
  71. uint32_t trcd;
  72. /* trp per bank */
  73. uint32_t trppb;
  74. /* trp all bank */
  75. uint32_t trp;
  76. uint32_t twr;
  77. uint32_t tdal;
  78. uint32_t trtp;
  79. uint32_t trc;
  80. uint32_t trrd;
  81. uint32_t tccd;
  82. uint32_t twtr;
  83. uint32_t trtw;
  84. uint32_t tras_max;
  85. uint32_t tras_min;
  86. uint32_t tfaw;
  87. uint32_t trfc;
  88. uint32_t tdqsck;
  89. uint32_t tdqsck_max;
  90. /* pd or sr */
  91. uint32_t txsr;
  92. uint32_t txsnr;
  93. uint32_t txp;
  94. uint32_t txpdll;
  95. uint32_t tdllk;
  96. uint32_t tcke;
  97. uint32_t tckesr;
  98. uint32_t tcksre;
  99. uint32_t tcksrx;
  100. uint32_t tdpd;
  101. /* mode register timing */
  102. uint32_t tmod;
  103. uint32_t tmrd;
  104. uint32_t tmrr;
  105. uint32_t tmrri;
  106. /* ODT */
  107. uint32_t todton;
  108. /* ZQ */
  109. uint32_t tzqinit;
  110. uint32_t tzqcs;
  111. uint32_t tzqoper;
  112. uint32_t tzqreset;
  113. /* Write Leveling */
  114. uint32_t twlmrd;
  115. uint32_t twlo;
  116. uint32_t twldqsen;
  117. /* CA Training */
  118. uint32_t tcackel;
  119. uint32_t tcaent;
  120. uint32_t tcamrd;
  121. uint32_t tcackeh;
  122. uint32_t tcaext;
  123. uint32_t tadr;
  124. uint32_t tmrz;
  125. uint32_t tcacd;
  126. /* mode register */
  127. uint32_t mr[4];
  128. uint32_t mr11;
  129. /* lpddr4 spec */
  130. uint32_t mr12;
  131. uint32_t mr13;
  132. uint32_t mr14;
  133. uint32_t mr16;
  134. uint32_t mr17;
  135. uint32_t mr20;
  136. uint32_t mr22;
  137. uint32_t tccdmw;
  138. uint32_t tppd;
  139. uint32_t tescke;
  140. uint32_t tsr;
  141. uint32_t tcmdcke;
  142. uint32_t tcscke;
  143. uint32_t tckelcs;
  144. uint32_t tcsckeh;
  145. uint32_t tckehcs;
  146. uint32_t tmrwckel;
  147. uint32_t tzqcal;
  148. uint32_t tzqlat;
  149. uint32_t tzqcke;
  150. uint32_t tvref_long;
  151. uint32_t tvref_short;
  152. uint32_t tvrcg_enable;
  153. uint32_t tvrcg_disable;
  154. uint32_t tfc_long;
  155. uint32_t tckfspe;
  156. uint32_t tckfspx;
  157. uint32_t tckehcmd;
  158. uint32_t tckelcmd;
  159. uint32_t tckelpd;
  160. uint32_t tckckel;
  161. /* other */
  162. uint32_t al;
  163. uint32_t cl;
  164. uint32_t cwl;
  165. uint32_t bl;
  166. };
  167. struct dram_info_t {
  168. /* speed_rate only used when DDR3 */
  169. enum ddr3_speed_rate speed_rate;
  170. /* 1: use CS0, 2: use CS0 and CS1 */
  171. uint32_t cs_cnt;
  172. /* give the max per-die capability on each rank/cs */
  173. uint32_t per_die_capability[2];
  174. };
  175. struct timing_related_config {
  176. struct dram_info_t dram_info[2];
  177. uint32_t dram_type;
  178. /* MHz */
  179. uint32_t freq;
  180. uint32_t ch_cnt;
  181. uint32_t bl;
  182. /* 1:auto precharge, 0:never auto precharge */
  183. uint32_t ap;
  184. /*
  185. * 1:dll bypass, 0:dll normal
  186. * dram and controller dll bypass at the same time
  187. */
  188. uint32_t dllbp;
  189. /* 1:odt enable, 0:odt disable */
  190. uint32_t odt;
  191. /* 1:enable, 0:disabe */
  192. uint32_t rdbi;
  193. uint32_t wdbi;
  194. /* dram driver strength */
  195. uint32_t dramds;
  196. /* dram ODT, if odt=0, this parameter invalid */
  197. uint32_t dramodt;
  198. /*
  199. * ca ODT, if odt=0, this parameter invalid
  200. * it only used by LPDDR4
  201. */
  202. uint32_t caodt;
  203. };
  204. /* mr0 for ddr3 */
  205. #define DDR3_BL8 (0)
  206. #define DDR3_BC4_8 (1)
  207. #define DDR3_BC4 (2)
  208. #define DDR3_CL(n) (((((n) - 4) & 0x7) << 4)\
  209. | ((((n) - 4) & 0x8) >> 1))
  210. #define DDR3_WR(n) (((n) & 0x7) << 9)
  211. #define DDR3_DLL_RESET (1 << 8)
  212. #define DDR3_DLL_DERESET (0 << 8)
  213. /* mr1 for ddr3 */
  214. #define DDR3_DLL_ENABLE (0)
  215. #define DDR3_DLL_DISABLE (1)
  216. #define DDR3_MR1_AL(n) (((n) & 0x3) << 3)
  217. #define DDR3_DS_40 (0)
  218. #define DDR3_DS_34 (1 << 1)
  219. #define DDR3_RTT_NOM_DIS (0)
  220. #define DDR3_RTT_NOM_60 (1 << 2)
  221. #define DDR3_RTT_NOM_120 (1 << 6)
  222. #define DDR3_RTT_NOM_40 ((1 << 2) | (1 << 6))
  223. #define DDR3_TDQS (1 << 11)
  224. /* mr2 for ddr3 */
  225. #define DDR3_MR2_CWL(n) ((((n) - 5) & 0x7) << 3)
  226. #define DDR3_RTT_WR_DIS (0)
  227. #define DDR3_RTT_WR_60 (1 << 9)
  228. #define DDR3_RTT_WR_120 (2 << 9)
  229. /*
  230. * MR0 (Device Information)
  231. * 0:DAI complete, 1:DAI still in progress
  232. */
  233. #define LPDDR2_DAI (0x1)
  234. /* 0:S2 or S4 SDRAM, 1:NVM */
  235. #define LPDDR2_DI (0x1 << 1)
  236. /* 0:DNV not supported, 1:DNV supported */
  237. #define LPDDR2_DNVI (0x1 << 2)
  238. #define LPDDR2_RZQI (0x3 << 3)
  239. /*
  240. * 00:RZQ self test not supported,
  241. * 01:ZQ-pin may connect to VDDCA or float
  242. * 10:ZQ-pin may short to GND.
  243. * 11:ZQ-pin self test completed, no error condition detected.
  244. */
  245. /* MR1 (Device Feature) */
  246. #define LPDDR2_BL4 (0x2)
  247. #define LPDDR2_BL8 (0x3)
  248. #define LPDDR2_BL16 (0x4)
  249. #define LPDDR2_N_WR(n) (((n) - 2) << 5)
  250. /* MR2 (Device Feature 2) */
  251. #define LPDDR2_RL3_WL1 (0x1)
  252. #define LPDDR2_RL4_WL2 (0x2)
  253. #define LPDDR2_RL5_WL2 (0x3)
  254. #define LPDDR2_RL6_WL3 (0x4)
  255. #define LPDDR2_RL7_WL4 (0x5)
  256. #define LPDDR2_RL8_WL4 (0x6)
  257. /* MR3 (IO Configuration 1) */
  258. #define LPDDR2_DS_34 (0x1)
  259. #define LPDDR2_DS_40 (0x2)
  260. #define LPDDR2_DS_48 (0x3)
  261. #define LPDDR2_DS_60 (0x4)
  262. #define LPDDR2_DS_80 (0x6)
  263. /* optional */
  264. #define LPDDR2_DS_120 (0x7)
  265. /* MR4 (Device Temperature) */
  266. #define LPDDR2_TREF_MASK (0x7)
  267. #define LPDDR2_4_TREF (0x1)
  268. #define LPDDR2_2_TREF (0x2)
  269. #define LPDDR2_1_TREF (0x3)
  270. #define LPDDR2_025_TREF (0x5)
  271. #define LPDDR2_025_TREF_DERATE (0x6)
  272. #define LPDDR2_TUF (0x1 << 7)
  273. /* MR8 (Basic configuration 4) */
  274. #define LPDDR2_S4 (0x0)
  275. #define LPDDR2_S2 (0x1)
  276. #define LPDDR2_N (0x2)
  277. /* Unit:MB */
  278. #define LPDDR2_DENSITY(mr8) (8 << (((mr8) >> 2) & 0xf))
  279. #define LPDDR2_IO_WIDTH(mr8) (32 >> (((mr8) >> 6) & 0x3))
  280. /* MR10 (Calibration) */
  281. #define LPDDR2_ZQINIT (0xff)
  282. #define LPDDR2_ZQCL (0xab)
  283. #define LPDDR2_ZQCS (0x56)
  284. #define LPDDR2_ZQRESET (0xc3)
  285. /* MR16 (PASR Bank Mask), S2 SDRAM Only */
  286. #define LPDDR2_PASR_FULL (0x0)
  287. #define LPDDR2_PASR_1_2 (0x1)
  288. #define LPDDR2_PASR_1_4 (0x2)
  289. #define LPDDR2_PASR_1_8 (0x3)
  290. /*
  291. * MR0 (Device Information)
  292. * 0:DAI complete,
  293. * 1:DAI still in progress
  294. */
  295. #define LPDDR3_DAI (0x1)
  296. /*
  297. * 00:RZQ self test not supported,
  298. * 01:ZQ-pin may connect to VDDCA or float
  299. * 10:ZQ-pin may short to GND.
  300. * 11:ZQ-pin self test completed, no error condition detected.
  301. */
  302. #define LPDDR3_RZQI (0x3 << 3)
  303. /*
  304. * 0:DRAM does not support WL(Set B),
  305. * 1:DRAM support WL(Set B)
  306. */
  307. #define LPDDR3_WL_SUPOT (1 << 6)
  308. /*
  309. * 0:DRAM does not support RL=3,nWR=3,WL=1;
  310. * 1:DRAM supports RL=3,nWR=3,WL=1 for frequencies <=166
  311. */
  312. #define LPDDR3_RL3_SUPOT (1 << 7)
  313. /* MR1 (Device Feature) */
  314. #define LPDDR3_BL8 (0x3)
  315. #define LPDDR3_N_WR(n) ((n) << 5)
  316. /* MR2 (Device Feature 2), WL Set A,default */
  317. /* <=166MHz,optional*/
  318. #define LPDDR3_RL3_WL1 (0x1)
  319. /* <=400MHz*/
  320. #define LPDDR3_RL6_WL3 (0x4)
  321. /* <=533MHz*/
  322. #define LPDDR3_RL8_WL4 (0x6)
  323. /* <=600MHz*/
  324. #define LPDDR3_RL9_WL5 (0x7)
  325. /* <=667MHz,default*/
  326. #define LPDDR3_RL10_WL6 (0x8)
  327. /* <=733MHz*/
  328. #define LPDDR3_RL11_WL6 (0x9)
  329. /* <=800MHz*/
  330. #define LPDDR3_RL12_WL6 (0xa)
  331. /* <=933MHz*/
  332. #define LPDDR3_RL14_WL8 (0xc)
  333. /* <=1066MHz*/
  334. #define LPDDR3_RL16_WL8 (0xe)
  335. /* WL Set B, optional */
  336. /* <=667MHz,default*/
  337. #define LPDDR3_RL10_WL8 (0x8)
  338. /* <=733MHz*/
  339. #define LPDDR3_RL11_WL9 (0x9)
  340. /* <=800MHz*/
  341. #define LPDDR3_RL12_WL9 (0xa)
  342. /* <=933MHz*/
  343. #define LPDDR3_RL14_WL11 (0xc)
  344. /* <=1066MHz*/
  345. #define LPDDR3_RL16_WL13 (0xe)
  346. /* 1:enable nWR programming > 9(default)*/
  347. #define LPDDR3_N_WRE (1 << 4)
  348. /* 1:Select WL Set B*/
  349. #define LPDDR3_WL_S (1 << 6)
  350. /* 1:enable*/
  351. #define LPDDR3_WR_LEVEL (1 << 7)
  352. /* MR3 (IO Configuration 1) */
  353. #define LPDDR3_DS_34 (0x1)
  354. #define LPDDR3_DS_40 (0x2)
  355. #define LPDDR3_DS_48 (0x3)
  356. #define LPDDR3_DS_60 (0x4)
  357. #define LPDDR3_DS_80 (0x6)
  358. #define LPDDR3_DS_34D_40U (0x9)
  359. #define LPDDR3_DS_40D_48U (0xa)
  360. #define LPDDR3_DS_34D_48U (0xb)
  361. /* MR4 (Device Temperature) */
  362. #define LPDDR3_TREF_MASK (0x7)
  363. /* SDRAM Low temperature operating limit exceeded */
  364. #define LPDDR3_LT_EXED (0x0)
  365. #define LPDDR3_4_TREF (0x1)
  366. #define LPDDR3_2_TREF (0x2)
  367. #define LPDDR3_1_TREF (0x3)
  368. #define LPDDR3_05_TREF (0x4)
  369. #define LPDDR3_025_TREF (0x5)
  370. #define LPDDR3_025_TREF_DERATE (0x6)
  371. /* SDRAM High temperature operating limit exceeded */
  372. #define LPDDR3_HT_EXED (0x7)
  373. /* 1:value has changed since last read of MR4 */
  374. #define LPDDR3_TUF (0x1 << 7)
  375. /* MR8 (Basic configuration 4) */
  376. #define LPDDR3_S8 (0x3)
  377. #define LPDDR3_DENSITY(mr8) (8 << (((mr8) >> 2) & 0xf))
  378. #define LPDDR3_IO_WIDTH(mr8) (32 >> (((mr8) >> 6) & 0x3))
  379. /* MR10 (Calibration) */
  380. #define LPDDR3_ZQINIT (0xff)
  381. #define LPDDR3_ZQCL (0xab)
  382. #define LPDDR3_ZQCS (0x56)
  383. #define LPDDR3_ZQRESET (0xc3)
  384. /* MR11 (ODT Control) */
  385. #define LPDDR3_ODT_60 (1)
  386. #define LPDDR3_ODT_120 (2)
  387. #define LPDDR3_ODT_240 (3)
  388. #define LPDDR3_ODT_DIS (0)
  389. /* MR2 (Device Feature 2) */
  390. /* RL & nRTP for DBI-RD Disabled */
  391. #define LPDDR4_RL6_NRTP8 (0x0)
  392. #define LPDDR4_RL10_NRTP8 (0x1)
  393. #define LPDDR4_RL14_NRTP8 (0x2)
  394. #define LPDDR4_RL20_NRTP8 (0x3)
  395. #define LPDDR4_RL24_NRTP10 (0x4)
  396. #define LPDDR4_RL28_NRTP12 (0x5)
  397. #define LPDDR4_RL32_NRTP14 (0x6)
  398. #define LPDDR4_RL36_NRTP16 (0x7)
  399. /* RL & nRTP for DBI-RD Disabled */
  400. #define LPDDR4_RL12_NRTP8 (0x1)
  401. #define LPDDR4_RL16_NRTP8 (0x2)
  402. #define LPDDR4_RL22_NRTP8 (0x3)
  403. #define LPDDR4_RL28_NRTP10 (0x4)
  404. #define LPDDR4_RL32_NRTP12 (0x5)
  405. #define LPDDR4_RL36_NRTP14 (0x6)
  406. #define LPDDR4_RL40_NRTP16 (0x7)
  407. /* WL Set A,default */
  408. #define LPDDR4_A_WL4 (0x0)
  409. #define LPDDR4_A_WL6 (0x1)
  410. #define LPDDR4_A_WL8 (0x2)
  411. #define LPDDR4_A_WL10 (0x3)
  412. #define LPDDR4_A_WL12 (0x4)
  413. #define LPDDR4_A_WL14 (0x5)
  414. #define LPDDR4_A_WL16 (0x6)
  415. #define LPDDR4_A_WL18 (0x7)
  416. /* WL Set B, optional */
  417. #define LPDDR4_B_WL4 (0x0 << 3)
  418. #define LPDDR4_B_WL8 (0x1 << 3)
  419. #define LPDDR4_B_WL12 (0x2 << 3)
  420. #define LPDDR4_B_WL18 (0x3 << 3)
  421. #define LPDDR4_B_WL22 (0x4 << 3)
  422. #define LPDDR4_B_WL26 (0x5 << 3)
  423. #define LPDDR4_B_WL30 (0x6 << 3)
  424. #define LPDDR4_B_WL34 (0x7 << 3)
  425. /* 1:Select WL Set B*/
  426. #define LPDDR4_WL_B (1 << 6)
  427. /* 1:enable*/
  428. #define LPDDR4_WR_LEVEL (1 << 7)
  429. /* MR3 */
  430. #define LPDDR4_VDDQ_2_5 (0)
  431. #define LPDDR4_VDDQ_3 (1)
  432. #define LPDDR4_WRPST_0_5_TCK (0 << 1)
  433. #define LPDDR4_WRPST_1_5_TCK (1 << 1)
  434. #define LPDDR4_PPR_EN (1 << 2)
  435. /* PDDS */
  436. #define LPDDR4_PDDS_240 (0x1 << 3)
  437. #define LPDDR4_PDDS_120 (0x2 << 3)
  438. #define LPDDR4_PDDS_80 (0x3 << 3)
  439. #define LPDDR4_PDDS_60 (0x4 << 3)
  440. #define LPDDR4_PDDS_48 (0x5 << 3)
  441. #define LPDDR4_PDDS_40 (0x6 << 3)
  442. #define LPDDR4_DBI_RD_EN (1 << 6)
  443. #define LPDDR4_DBI_WR_EN (1 << 7)
  444. /* MR11 (ODT Control) */
  445. #define LPDDR4_DQODT_240 (1)
  446. #define LPDDR4_DQODT_120 (2)
  447. #define LPDDR4_DQODT_80 (3)
  448. #define LPDDR4_DQODT_60 (4)
  449. #define LPDDR4_DQODT_48 (5)
  450. #define LPDDR4_DQODT_40 (6)
  451. #define LPDDR4_DQODT_DIS (0)
  452. #define LPDDR4_CAODT_240 (1 << 4)
  453. #define LPDDR4_CAODT_120 (2 << 4)
  454. #define LPDDR4_CAODT_80 (3 << 4)
  455. #define LPDDR4_CAODT_60 (4 << 4)
  456. #define LPDDR4_CAODT_48 (5 << 4)
  457. #define LPDDR4_CAODT_40 (6 << 4)
  458. #define LPDDR4_CAODT_DIS (0 << 4)
  459. /*
  460. * Description: depend on input parameter "timing_config",
  461. * and calculate correspond "dram_type"
  462. * spec timing to "pdram_timing"
  463. * parameters:
  464. * input: timing_config
  465. * output: pdram_timing
  466. * NOTE: MR ODT is set, need to disable by controller
  467. */
  468. void dram_get_parameter(struct timing_related_config *timing_config,
  469. struct dram_timing_t *pdram_timing);
  470. #endif /* DRAM_SPEC_TIMING_H */