sdram.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Timing and Organization details of the ddr device parts used in OMAP5
  4. * EVM
  5. *
  6. * (C) Copyright 2010
  7. * Texas Instruments, <www.ti.com>
  8. *
  9. * Aneesh V <aneesh@ti.com>
  10. * Sricharan R <r.sricharan@ti.com>
  11. */
  12. #include <asm/emif.h>
  13. #include <asm/arch/sys_proto.h>
  14. /*
  15. * This file provides details of the LPDDR2 SDRAM parts used on OMAP5
  16. * EVM. Since the parts used and geometry are identical for
  17. * evm for a given OMAP5 revision, this information is kept
  18. * here instead of being in board directory. However the key functions
  19. * exported are weakly linked so that they can be over-ridden in the board
  20. * directory if there is a OMAP5 board in the future that uses a different
  21. * memory device or geometry.
  22. *
  23. * For any new board with different memory devices over-ride one or more
  24. * of the following functions as per the CONFIG flags you intend to enable:
  25. * - emif_get_reg_dump()
  26. * - emif_get_dmm_regs()
  27. * - emif_get_device_details()
  28. * - emif_get_device_timings()
  29. */
  30. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  31. const struct emif_regs emif_regs_532_mhz_2cs = {
  32. .sdram_config_init = 0x80800EBA,
  33. .sdram_config = 0x808022BA,
  34. .ref_ctrl = 0x0000081A,
  35. .sdram_tim1 = 0x772F6873,
  36. .sdram_tim2 = 0x304a129a,
  37. .sdram_tim3 = 0x02f7e45f,
  38. .read_idle_ctrl = 0x00050000,
  39. .zq_config = 0x000b3215,
  40. .temp_alert_config = 0x08000a05,
  41. .emif_ddr_phy_ctlr_1_init = 0x0E28420d,
  42. .emif_ddr_phy_ctlr_1 = 0x0E28420d,
  43. .emif_ddr_ext_phy_ctrl_1 = 0x04020080,
  44. .emif_ddr_ext_phy_ctrl_2 = 0x28C518A3,
  45. .emif_ddr_ext_phy_ctrl_3 = 0x518A3146,
  46. .emif_ddr_ext_phy_ctrl_4 = 0x0014628C,
  47. .emif_ddr_ext_phy_ctrl_5 = 0x04010040
  48. };
  49. const struct emif_regs emif_regs_532_mhz_2cs_es2 = {
  50. .sdram_config_init = 0x80800EBA,
  51. .sdram_config = 0x808022BA,
  52. .ref_ctrl = 0x0000081A,
  53. .sdram_tim1 = 0x772F6873,
  54. .sdram_tim2 = 0x304a129a,
  55. .sdram_tim3 = 0x02f7e45f,
  56. .read_idle_ctrl = 0x00050000,
  57. .zq_config = 0x100b3215,
  58. .temp_alert_config = 0x08000a05,
  59. .emif_ddr_phy_ctlr_1_init = 0x0E30400d,
  60. .emif_ddr_phy_ctlr_1 = 0x0E30400d,
  61. .emif_ddr_ext_phy_ctrl_1 = 0x04020080,
  62. .emif_ddr_ext_phy_ctrl_2 = 0x28C518A3,
  63. .emif_ddr_ext_phy_ctrl_3 = 0x518A3146,
  64. .emif_ddr_ext_phy_ctrl_4 = 0x0014628C,
  65. .emif_ddr_ext_phy_ctrl_5 = 0xC330CC33,
  66. };
  67. const struct emif_regs emif_regs_266_mhz_2cs = {
  68. .sdram_config_init = 0x80800EBA,
  69. .sdram_config = 0x808022BA,
  70. .ref_ctrl = 0x0000040D,
  71. .sdram_tim1 = 0x2A86B419,
  72. .sdram_tim2 = 0x1025094A,
  73. .sdram_tim3 = 0x026BA22F,
  74. .read_idle_ctrl = 0x00050000,
  75. .zq_config = 0x000b3215,
  76. .temp_alert_config = 0x08000a05,
  77. .emif_ddr_phy_ctlr_1_init = 0x0E28420d,
  78. .emif_ddr_phy_ctlr_1 = 0x0E28420d,
  79. .emif_ddr_ext_phy_ctrl_1 = 0x04020080,
  80. .emif_ddr_ext_phy_ctrl_2 = 0x0A414829,
  81. .emif_ddr_ext_phy_ctrl_3 = 0x14829052,
  82. .emif_ddr_ext_phy_ctrl_4 = 0x000520A4,
  83. .emif_ddr_ext_phy_ctrl_5 = 0x04010040
  84. };
  85. const struct emif_regs emif_regs_ddr3_532_mhz_1cs = {
  86. .sdram_config_init = 0x61851B32,
  87. .sdram_config = 0x61851B32,
  88. .sdram_config2 = 0x0,
  89. .ref_ctrl = 0x00001035,
  90. .sdram_tim1 = 0xCCCF36B3,
  91. .sdram_tim2 = 0x308F7FDA,
  92. .sdram_tim3 = 0x027F88A8,
  93. .read_idle_ctrl = 0x00050000,
  94. .zq_config = 0x0007190B,
  95. .temp_alert_config = 0x00000000,
  96. .emif_ddr_phy_ctlr_1_init = 0x0020420A,
  97. .emif_ddr_phy_ctlr_1 = 0x0024420A,
  98. .emif_ddr_ext_phy_ctrl_1 = 0x04040100,
  99. .emif_ddr_ext_phy_ctrl_2 = 0x00000000,
  100. .emif_ddr_ext_phy_ctrl_3 = 0x00000000,
  101. .emif_ddr_ext_phy_ctrl_4 = 0x00000000,
  102. .emif_ddr_ext_phy_ctrl_5 = 0x04010040,
  103. .emif_rd_wr_lvl_rmp_win = 0x00000000,
  104. .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
  105. .emif_rd_wr_lvl_ctl = 0x00000000,
  106. .emif_rd_wr_exec_thresh = 0x00000305
  107. };
  108. const struct emif_regs emif_regs_ddr3_532_mhz_1cs_es2 = {
  109. .sdram_config_init = 0x61851B32,
  110. .sdram_config = 0x61851B32,
  111. .sdram_config2 = 0x0,
  112. .ref_ctrl = 0x00001035,
  113. .sdram_tim1 = 0xCCCF36B3,
  114. .sdram_tim2 = 0x308F7FDA,
  115. .sdram_tim3 = 0x027F88A8,
  116. .read_idle_ctrl = 0x00050000,
  117. .zq_config = 0x1007190B,
  118. .temp_alert_config = 0x00000000,
  119. .emif_ddr_phy_ctlr_1_init = 0x0030400A,
  120. .emif_ddr_phy_ctlr_1 = 0x0034400A,
  121. .emif_ddr_ext_phy_ctrl_1 = 0x04040100,
  122. .emif_ddr_ext_phy_ctrl_2 = 0x00000000,
  123. .emif_ddr_ext_phy_ctrl_3 = 0x00000000,
  124. .emif_ddr_ext_phy_ctrl_4 = 0x00000000,
  125. .emif_ddr_ext_phy_ctrl_5 = 0x4350D435,
  126. .emif_rd_wr_lvl_rmp_win = 0x00000000,
  127. .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
  128. .emif_rd_wr_lvl_ctl = 0x00000000,
  129. .emif_rd_wr_exec_thresh = 0x40000305
  130. };
  131. const struct dmm_lisa_map_regs lisa_map_4G_x_2_x_2 = {
  132. .dmm_lisa_map_0 = 0x0,
  133. .dmm_lisa_map_1 = 0x0,
  134. .dmm_lisa_map_2 = 0x80740300,
  135. .dmm_lisa_map_3 = 0xFF020100,
  136. .is_ma_present = 0x1
  137. };
  138. static void emif_get_reg_dump_sdp(u32 emif_nr, const struct emif_regs **regs)
  139. {
  140. switch (omap_revision()) {
  141. case OMAP5430_ES1_0:
  142. *regs = &emif_regs_532_mhz_2cs;
  143. break;
  144. case OMAP5432_ES1_0:
  145. *regs = &emif_regs_ddr3_532_mhz_1cs;
  146. break;
  147. case OMAP5430_ES2_0:
  148. *regs = &emif_regs_532_mhz_2cs_es2;
  149. break;
  150. case OMAP5432_ES2_0:
  151. default:
  152. *regs = &emif_regs_ddr3_532_mhz_1cs_es2;
  153. break;
  154. }
  155. }
  156. void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
  157. __attribute__((weak, alias("emif_get_reg_dump_sdp")));
  158. static void emif_get_dmm_regs_sdp(const struct dmm_lisa_map_regs
  159. **dmm_lisa_regs)
  160. {
  161. switch (omap_revision()) {
  162. case OMAP5430_ES1_0:
  163. case OMAP5430_ES2_0:
  164. case OMAP5432_ES1_0:
  165. case OMAP5432_ES2_0:
  166. default:
  167. *dmm_lisa_regs = &lisa_map_4G_x_2_x_2;
  168. break;
  169. }
  170. }
  171. void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
  172. __attribute__((weak, alias("emif_get_dmm_regs_sdp")));
  173. #else
  174. static const struct lpddr2_device_details dev_4G_S4_details = {
  175. .type = LPDDR2_TYPE_S4,
  176. .density = LPDDR2_DENSITY_4Gb,
  177. .io_width = LPDDR2_IO_WIDTH_32,
  178. .manufacturer = LPDDR2_MANUFACTURER_SAMSUNG
  179. };
  180. static void emif_get_device_details_sdp(u32 emif_nr,
  181. struct lpddr2_device_details *cs0_device_details,
  182. struct lpddr2_device_details *cs1_device_details)
  183. {
  184. /* EMIF1 & EMIF2 have identical configuration */
  185. *cs0_device_details = dev_4G_S4_details;
  186. *cs1_device_details = dev_4G_S4_details;
  187. }
  188. void emif_get_device_details(u32 emif_nr,
  189. struct lpddr2_device_details *cs0_device_details,
  190. struct lpddr2_device_details *cs1_device_details)
  191. __attribute__((weak, alias("emif_get_device_details_sdp")));
  192. #endif /* CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS */
  193. const u32 ext_phy_ctrl_const_base[] = {
  194. 0x01004010,
  195. 0x00001004,
  196. 0x04010040,
  197. 0x01004010,
  198. 0x00001004,
  199. 0x00000000,
  200. 0x00000000,
  201. 0x00000000,
  202. 0x80080080,
  203. 0x00800800,
  204. 0x08102040,
  205. 0x00000001,
  206. 0x540A8150,
  207. 0xA81502a0,
  208. 0x002A0540,
  209. 0x00000000,
  210. 0x00000000,
  211. 0x00000000,
  212. 0x00000077,
  213. 0x0
  214. };
  215. const u32 ddr3_ext_phy_ctrl_const_base_es1[] = {
  216. 0x01004010,
  217. 0x00001004,
  218. 0x04010040,
  219. 0x01004010,
  220. 0x00001004,
  221. 0x00000000,
  222. 0x00000000,
  223. 0x00000000,
  224. 0x80080080,
  225. 0x00800800,
  226. 0x08102040,
  227. 0x00000002,
  228. 0x0,
  229. 0x0,
  230. 0x0,
  231. 0x00000000,
  232. 0x00000000,
  233. 0x00000000,
  234. 0x00000057,
  235. 0x0
  236. };
  237. const u32 ddr3_ext_phy_ctrl_const_base_es2[] = {
  238. 0x50D4350D,
  239. 0x00000D43,
  240. 0x04010040,
  241. 0x01004010,
  242. 0x00001004,
  243. 0x00000000,
  244. 0x00000000,
  245. 0x00000000,
  246. 0x80080080,
  247. 0x00800800,
  248. 0x08102040,
  249. 0x00000002,
  250. 0x00000000,
  251. 0x00000000,
  252. 0x00000000,
  253. 0x00000000,
  254. 0x00000000,
  255. 0x00000000,
  256. 0x00000057,
  257. 0x0
  258. };
  259. /* Ext phy ctrl 1-35 regs */
  260. const u32
  261. dra_ddr3_ext_phy_ctrl_const_base_es1_emif1[] = {
  262. 0x10040100,
  263. 0x00910091,
  264. 0x00950095,
  265. 0x009B009B,
  266. 0x009E009E,
  267. 0x00980098,
  268. 0x00340034,
  269. 0x00350035,
  270. 0x00340034,
  271. 0x00310031,
  272. 0x00340034,
  273. 0x007F007F,
  274. 0x007F007F,
  275. 0x007F007F,
  276. 0x007F007F,
  277. 0x007F007F,
  278. 0x00480048,
  279. 0x004A004A,
  280. 0x00520052,
  281. 0x00550055,
  282. 0x00500050,
  283. 0x00000000,
  284. 0x00600020,
  285. 0x40011080,
  286. 0x08102040,
  287. 0x0,
  288. 0x0,
  289. 0x0,
  290. 0x0,
  291. 0x0,
  292. 0x0,
  293. 0x0,
  294. 0x0,
  295. 0x0,
  296. 0x0
  297. };
  298. /* Ext phy ctrl 1-35 regs */
  299. const u32
  300. dra_ddr3_ext_phy_ctrl_const_base_es1_emif2[] = {
  301. 0x10040100,
  302. 0x00910091,
  303. 0x00950095,
  304. 0x009B009B,
  305. 0x009E009E,
  306. 0x00980098,
  307. 0x00330033,
  308. 0x00330033,
  309. 0x002F002F,
  310. 0x00320032,
  311. 0x00310031,
  312. 0x007F007F,
  313. 0x007F007F,
  314. 0x007F007F,
  315. 0x007F007F,
  316. 0x007F007F,
  317. 0x00520052,
  318. 0x00520052,
  319. 0x00470047,
  320. 0x00490049,
  321. 0x00500050,
  322. 0x00000000,
  323. 0x00600020,
  324. 0x40011080,
  325. 0x08102040,
  326. 0x0,
  327. 0x0,
  328. 0x0,
  329. 0x0,
  330. 0x0,
  331. 0x0,
  332. 0x0,
  333. 0x0,
  334. 0x0,
  335. 0x0
  336. };
  337. /* Ext phy ctrl 1-35 regs */
  338. const u32
  339. dra_ddr3_ext_phy_ctrl_const_base_666MHz[] = {
  340. 0x10040100,
  341. 0x00A400A4,
  342. 0x00A900A9,
  343. 0x00B000B0,
  344. 0x00B000B0,
  345. 0x00A400A4,
  346. 0x00390039,
  347. 0x00320032,
  348. 0x00320032,
  349. 0x00320032,
  350. 0x00440044,
  351. 0x00550055,
  352. 0x00550055,
  353. 0x00550055,
  354. 0x00550055,
  355. 0x007F007F,
  356. 0x004D004D,
  357. 0x00430043,
  358. 0x00560056,
  359. 0x00540054,
  360. 0x00600060,
  361. 0x0,
  362. 0x00600020,
  363. 0x40010080,
  364. 0x08102040,
  365. 0x0,
  366. 0x0,
  367. 0x0,
  368. 0x0,
  369. 0x0,
  370. 0x0,
  371. 0x0,
  372. 0x0,
  373. 0x0,
  374. 0x0
  375. };
  376. const u32 dra_ddr3_ext_phy_ctrl_const_base_666MHz_es2[] = {
  377. 0x04040100,
  378. 0x006B009F,
  379. 0x006B00A2,
  380. 0x006B00A8,
  381. 0x006B00A8,
  382. 0x006B00B2,
  383. 0x002F002F,
  384. 0x002F002F,
  385. 0x002F002F,
  386. 0x002F002F,
  387. 0x002F002F,
  388. 0x00600073,
  389. 0x00600071,
  390. 0x0060007C,
  391. 0x0060007E,
  392. 0x00600084,
  393. 0x00400053,
  394. 0x00400051,
  395. 0x0040005C,
  396. 0x0040005E,
  397. 0x00400064,
  398. 0x00800080,
  399. 0x00800080,
  400. 0x40010080,
  401. 0x08102040,
  402. 0x005B008F,
  403. 0x005B0092,
  404. 0x005B0098,
  405. 0x005B0098,
  406. 0x005B00A2,
  407. 0x00300043,
  408. 0x00300041,
  409. 0x0030004C,
  410. 0x0030004E,
  411. 0x00300054,
  412. 0x00000077
  413. };
  414. const struct lpddr2_mr_regs mr_regs = {
  415. .mr1 = MR1_BL_8_BT_SEQ_WRAP_EN_NWR_8,
  416. .mr2 = 0x6,
  417. .mr3 = 0x1,
  418. .mr10 = MR10_ZQ_ZQINIT,
  419. .mr16 = MR16_REF_FULL_ARRAY
  420. };
  421. void __weak emif_get_ext_phy_ctrl_const_regs(u32 emif_nr,
  422. const u32 **regs,
  423. u32 *size)
  424. {
  425. switch (omap_revision()) {
  426. case OMAP5430_ES1_0:
  427. case OMAP5430_ES2_0:
  428. *regs = ext_phy_ctrl_const_base;
  429. *size = ARRAY_SIZE(ext_phy_ctrl_const_base);
  430. break;
  431. case OMAP5432_ES1_0:
  432. *regs = ddr3_ext_phy_ctrl_const_base_es1;
  433. *size = ARRAY_SIZE(ddr3_ext_phy_ctrl_const_base_es1);
  434. break;
  435. case OMAP5432_ES2_0:
  436. *regs = ddr3_ext_phy_ctrl_const_base_es2;
  437. *size = ARRAY_SIZE(ddr3_ext_phy_ctrl_const_base_es2);
  438. break;
  439. case DRA752_ES1_0:
  440. case DRA752_ES1_1:
  441. case DRA752_ES2_0:
  442. if (emif_nr == 1) {
  443. *regs = dra_ddr3_ext_phy_ctrl_const_base_es1_emif1;
  444. *size =
  445. ARRAY_SIZE(dra_ddr3_ext_phy_ctrl_const_base_es1_emif1);
  446. } else {
  447. *regs = dra_ddr3_ext_phy_ctrl_const_base_es1_emif2;
  448. *size =
  449. ARRAY_SIZE(dra_ddr3_ext_phy_ctrl_const_base_es1_emif2);
  450. }
  451. break;
  452. case DRA722_ES1_0:
  453. *regs = dra_ddr3_ext_phy_ctrl_const_base_666MHz;
  454. *size = ARRAY_SIZE(dra_ddr3_ext_phy_ctrl_const_base_666MHz);
  455. break;
  456. case DRA762_ES1_0:
  457. case DRA762_ABZ_ES1_0:
  458. case DRA762_ACD_ES1_0:
  459. case DRA722_ES2_0:
  460. case DRA722_ES2_1:
  461. *regs = dra_ddr3_ext_phy_ctrl_const_base_666MHz_es2;
  462. *size = ARRAY_SIZE(dra_ddr3_ext_phy_ctrl_const_base_666MHz_es2);
  463. break;
  464. default:
  465. *regs = ddr3_ext_phy_ctrl_const_base_es2;
  466. *size = ARRAY_SIZE(ddr3_ext_phy_ctrl_const_base_es2);
  467. }
  468. }
  469. void get_lpddr2_mr_regs(const struct lpddr2_mr_regs **regs)
  470. {
  471. *regs = &mr_regs;
  472. }
  473. static void do_ext_phy_settings_omap5(u32 base, const struct emif_regs *regs)
  474. {
  475. u32 *ext_phy_ctrl_base = 0;
  476. u32 *emif_ext_phy_ctrl_base = 0;
  477. u32 emif_nr;
  478. const u32 *ext_phy_ctrl_const_regs;
  479. u32 i = 0;
  480. u32 size;
  481. emif_nr = (base == EMIF1_BASE) ? 1 : 2;
  482. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  483. ext_phy_ctrl_base = (u32 *) &(regs->emif_ddr_ext_phy_ctrl_1);
  484. emif_ext_phy_ctrl_base = (u32 *) &(emif->emif_ddr_ext_phy_ctrl_1);
  485. /* Configure external phy control timing registers */
  486. for (i = 0; i < EMIF_EXT_PHY_CTRL_TIMING_REG; i++) {
  487. writel(*ext_phy_ctrl_base, emif_ext_phy_ctrl_base++);
  488. /* Update shadow registers */
  489. writel(*ext_phy_ctrl_base++, emif_ext_phy_ctrl_base++);
  490. }
  491. /*
  492. * external phy 6-24 registers do not change with
  493. * ddr frequency
  494. */
  495. emif_get_ext_phy_ctrl_const_regs(emif_nr,
  496. &ext_phy_ctrl_const_regs, &size);
  497. for (i = 0; i < size; i++) {
  498. writel(ext_phy_ctrl_const_regs[i],
  499. emif_ext_phy_ctrl_base++);
  500. /* Update shadow registers */
  501. writel(ext_phy_ctrl_const_regs[i],
  502. emif_ext_phy_ctrl_base++);
  503. }
  504. }
  505. static void do_ext_phy_settings_dra7(u32 base, const struct emif_regs *regs)
  506. {
  507. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  508. u32 *emif_ext_phy_ctrl_base = 0;
  509. u32 emif_nr;
  510. const u32 *ext_phy_ctrl_const_regs;
  511. u32 i, hw_leveling, size, phy;
  512. emif_nr = (base == EMIF1_BASE) ? 1 : 2;
  513. hw_leveling = regs->emif_rd_wr_lvl_rmp_ctl >> EMIF_REG_RDWRLVL_EN_SHIFT;
  514. phy = regs->emif_ddr_phy_ctlr_1_init;
  515. emif_ext_phy_ctrl_base = (u32 *)&(emif->emif_ddr_ext_phy_ctrl_1);
  516. emif_get_ext_phy_ctrl_const_regs(emif_nr,
  517. &ext_phy_ctrl_const_regs, &size);
  518. writel(ext_phy_ctrl_const_regs[0], &emif_ext_phy_ctrl_base[0]);
  519. writel(ext_phy_ctrl_const_regs[0], &emif_ext_phy_ctrl_base[1]);
  520. /*
  521. * Copy the predefined PHY register values
  522. * if leveling is disabled.
  523. */
  524. if (phy & EMIF_DDR_PHY_CTRL_1_RDLVLGATE_MASK_MASK)
  525. for (i = 1; i < 6; i++) {
  526. writel(ext_phy_ctrl_const_regs[i],
  527. &emif_ext_phy_ctrl_base[i * 2]);
  528. writel(ext_phy_ctrl_const_regs[i],
  529. &emif_ext_phy_ctrl_base[i * 2 + 1]);
  530. }
  531. if (phy & EMIF_DDR_PHY_CTRL_1_RDLVL_MASK_MASK)
  532. for (i = 6; i < 11; i++) {
  533. writel(ext_phy_ctrl_const_regs[i],
  534. &emif_ext_phy_ctrl_base[i * 2]);
  535. writel(ext_phy_ctrl_const_regs[i],
  536. &emif_ext_phy_ctrl_base[i * 2 + 1]);
  537. }
  538. if (phy & EMIF_DDR_PHY_CTRL_1_WRLVL_MASK_MASK)
  539. for (i = 11; i < 25; i++) {
  540. writel(ext_phy_ctrl_const_regs[i],
  541. &emif_ext_phy_ctrl_base[i * 2]);
  542. writel(ext_phy_ctrl_const_regs[i],
  543. &emif_ext_phy_ctrl_base[i * 2 + 1]);
  544. }
  545. if (hw_leveling) {
  546. /*
  547. * Write the init value for HW levling to occur
  548. */
  549. for (i = 21; i < 35; i++) {
  550. writel(ext_phy_ctrl_const_regs[i],
  551. &emif_ext_phy_ctrl_base[i * 2]);
  552. writel(ext_phy_ctrl_const_regs[i],
  553. &emif_ext_phy_ctrl_base[i * 2 + 1]);
  554. }
  555. }
  556. }
  557. void do_ext_phy_settings(u32 base, const struct emif_regs *regs)
  558. {
  559. if (is_omap54xx())
  560. do_ext_phy_settings_omap5(base, regs);
  561. else
  562. do_ext_phy_settings_dra7(base, regs);
  563. }
  564. #ifndef CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS
  565. static const struct lpddr2_ac_timings timings_jedec_532_mhz = {
  566. .max_freq = 532000000,
  567. .RL = 8,
  568. .tRPab = 21,
  569. .tRCD = 18,
  570. .tWR = 15,
  571. .tRASmin = 42,
  572. .tRRD = 10,
  573. .tWTRx2 = 15,
  574. .tXSR = 140,
  575. .tXPx2 = 15,
  576. .tRFCab = 130,
  577. .tRTPx2 = 15,
  578. .tCKE = 3,
  579. .tCKESR = 15,
  580. .tZQCS = 90,
  581. .tZQCL = 360,
  582. .tZQINIT = 1000,
  583. .tDQSCKMAXx2 = 11,
  584. .tRASmax = 70,
  585. .tFAW = 50
  586. };
  587. static const struct lpddr2_min_tck min_tck = {
  588. .tRL = 3,
  589. .tRP_AB = 3,
  590. .tRCD = 3,
  591. .tWR = 3,
  592. .tRAS_MIN = 3,
  593. .tRRD = 2,
  594. .tWTR = 2,
  595. .tXP = 2,
  596. .tRTP = 2,
  597. .tCKE = 3,
  598. .tCKESR = 3,
  599. .tFAW = 8
  600. };
  601. static const struct lpddr2_ac_timings *ac_timings[MAX_NUM_SPEEDBINS] = {
  602. &timings_jedec_532_mhz
  603. };
  604. static const struct lpddr2_device_timings dev_4G_S4_timings = {
  605. .ac_timings = ac_timings,
  606. .min_tck = &min_tck,
  607. };
  608. /*
  609. * List of status registers to be controlled back to control registers
  610. * after initial leveling
  611. * readreg, writereg
  612. */
  613. const struct read_write_regs omap5_bug_00339_regs[] = {
  614. { 8, 5 },
  615. { 9, 6 },
  616. { 10, 7 },
  617. { 14, 8 },
  618. { 15, 9 },
  619. { 16, 10 },
  620. { 11, 2 },
  621. { 12, 3 },
  622. { 13, 4 },
  623. { 17, 11 },
  624. { 18, 12 },
  625. { 19, 13 },
  626. };
  627. const struct read_write_regs dra_bug_00339_regs[] = {
  628. { 7, 7 },
  629. { 8, 8 },
  630. { 9, 9 },
  631. { 10, 10 },
  632. { 11, 11 },
  633. { 12, 2 },
  634. { 13, 3 },
  635. { 14, 4 },
  636. { 15, 5 },
  637. { 16, 6 },
  638. { 17, 12 },
  639. { 18, 13 },
  640. { 19, 14 },
  641. { 20, 15 },
  642. { 21, 16 },
  643. { 22, 17 },
  644. { 23, 18 },
  645. { 24, 19 },
  646. { 25, 20 },
  647. { 26, 21}
  648. };
  649. const struct read_write_regs *get_bug_regs(u32 *iterations)
  650. {
  651. const struct read_write_regs *bug_00339_regs_ptr = NULL;
  652. switch (omap_revision()) {
  653. case OMAP5430_ES1_0:
  654. case OMAP5430_ES2_0:
  655. case OMAP5432_ES1_0:
  656. case OMAP5432_ES2_0:
  657. bug_00339_regs_ptr = omap5_bug_00339_regs;
  658. *iterations = sizeof(omap5_bug_00339_regs)/
  659. sizeof(omap5_bug_00339_regs[0]);
  660. break;
  661. case DRA762_ABZ_ES1_0:
  662. case DRA762_ACD_ES1_0:
  663. case DRA762_ES1_0:
  664. case DRA752_ES1_0:
  665. case DRA752_ES1_1:
  666. case DRA752_ES2_0:
  667. case DRA722_ES1_0:
  668. case DRA722_ES2_0:
  669. case DRA722_ES2_1:
  670. bug_00339_regs_ptr = dra_bug_00339_regs;
  671. *iterations = sizeof(dra_bug_00339_regs)/
  672. sizeof(dra_bug_00339_regs[0]);
  673. break;
  674. default:
  675. printf("\n Error: UnKnown SOC");
  676. }
  677. return bug_00339_regs_ptr;
  678. }
  679. void emif_get_device_timings_sdp(u32 emif_nr,
  680. const struct lpddr2_device_timings **cs0_device_timings,
  681. const struct lpddr2_device_timings **cs1_device_timings)
  682. {
  683. /* Identical devices on EMIF1 & EMIF2 */
  684. *cs0_device_timings = &dev_4G_S4_timings;
  685. *cs1_device_timings = &dev_4G_S4_timings;
  686. }
  687. void emif_get_device_timings(u32 emif_nr,
  688. const struct lpddr2_device_timings **cs0_device_timings,
  689. const struct lpddr2_device_timings **cs1_device_timings)
  690. __attribute__((weak, alias("emif_get_device_timings_sdp")));
  691. #endif /* CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS */