mx6-ddr.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2013 Boundary Devices Inc.
  4. */
  5. #ifndef __ASM_ARCH_MX6_DDR_H__
  6. #define __ASM_ARCH_MX6_DDR_H__
  7. #ifndef CONFIG_SPL_BUILD
  8. #ifdef CONFIG_MX6Q
  9. #include "mx6q-ddr.h"
  10. #else
  11. #if defined(CONFIG_MX6DL) || defined(CONFIG_MX6S)
  12. #include "mx6dl-ddr.h"
  13. #else
  14. #ifdef CONFIG_MX6SX
  15. #include "mx6sx-ddr.h"
  16. #else
  17. #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
  18. #include "mx6ul-ddr.h"
  19. #else
  20. #ifdef CONFIG_MX6SL
  21. #include "mx6sl-ddr.h"
  22. #else
  23. #error "Please select cpu"
  24. #endif /* CONFIG_MX6SL */
  25. #endif /* CONFIG_MX6UL */
  26. #endif /* CONFIG_MX6SX */
  27. #endif /* CONFIG_MX6DL or CONFIG_MX6S */
  28. #endif /* CONFIG_MX6Q */
  29. #else
  30. enum {
  31. DDR_TYPE_DDR3,
  32. DDR_TYPE_LPDDR2,
  33. };
  34. /* MMDC P0/P1 Registers */
  35. struct mmdc_p_regs {
  36. u32 mdctl;
  37. u32 mdpdc;
  38. u32 mdotc;
  39. u32 mdcfg0;
  40. u32 mdcfg1;
  41. u32 mdcfg2;
  42. u32 mdmisc;
  43. u32 mdscr;
  44. u32 mdref;
  45. u32 res1[2];
  46. u32 mdrwd;
  47. u32 mdor;
  48. u32 mdmrr;
  49. u32 mdcfg3lp;
  50. u32 mdmr4;
  51. u32 mdasp;
  52. u32 res2[239];
  53. u32 maarcr;
  54. u32 mapsr;
  55. u32 maexidr0;
  56. u32 maexidr1;
  57. u32 madpcr0;
  58. u32 madpcr1;
  59. u32 madpsr0;
  60. u32 madpsr1;
  61. u32 madpsr2;
  62. u32 madpsr3;
  63. u32 madpsr4;
  64. u32 madpsr5;
  65. u32 masbs0;
  66. u32 masbs1;
  67. u32 res3[2];
  68. u32 magenp;
  69. u32 res4[239];
  70. u32 mpzqhwctrl;
  71. u32 mpzqswctrl;
  72. u32 mpwlgcr;
  73. u32 mpwldectrl0;
  74. u32 mpwldectrl1;
  75. u32 mpwldlst;
  76. u32 mpodtctrl;
  77. u32 mprddqby0dl;
  78. u32 mprddqby1dl;
  79. u32 mprddqby2dl;
  80. u32 mprddqby3dl;
  81. u32 mpwrdqby0dl;
  82. u32 mpwrdqby1dl;
  83. u32 mpwrdqby2dl;
  84. u32 mpwrdqby3dl;
  85. u32 mpdgctrl0;
  86. u32 mpdgctrl1;
  87. u32 mpdgdlst0;
  88. u32 mprddlctl;
  89. u32 mprddlst;
  90. u32 mpwrdlctl;
  91. u32 mpwrdlst;
  92. u32 mpsdctrl;
  93. u32 mpzqlp2ctl;
  94. u32 mprddlhwctl;
  95. u32 mpwrdlhwctl;
  96. u32 mprddlhwst0;
  97. u32 mprddlhwst1;
  98. u32 mpwrdlhwst0;
  99. u32 mpwrdlhwst1;
  100. u32 mpwlhwerr;
  101. u32 mpdghwst0;
  102. u32 mpdghwst1;
  103. u32 mpdghwst2;
  104. u32 mpdghwst3;
  105. u32 mppdcmpr1;
  106. u32 mppdcmpr2;
  107. u32 mpswdar0;
  108. u32 mpswdrdr0;
  109. u32 mpswdrdr1;
  110. u32 mpswdrdr2;
  111. u32 mpswdrdr3;
  112. u32 mpswdrdr4;
  113. u32 mpswdrdr5;
  114. u32 mpswdrdr6;
  115. u32 mpswdrdr7;
  116. u32 mpmur0;
  117. u32 mpwrcadl;
  118. u32 mpdccr;
  119. };
  120. #define MX6SL_IOM_DDR_BASE 0x020e0300
  121. struct mx6sl_iomux_ddr_regs {
  122. u32 dram_cas;
  123. u32 dram_cs0_b;
  124. u32 dram_cs1_b;
  125. u32 dram_dqm0;
  126. u32 dram_dqm1;
  127. u32 dram_dqm2;
  128. u32 dram_dqm3;
  129. u32 dram_ras;
  130. u32 dram_reset;
  131. u32 dram_sdba0;
  132. u32 dram_sdba1;
  133. u32 dram_sdba2;
  134. u32 dram_sdcke0;
  135. u32 dram_sdcke1;
  136. u32 dram_sdclk_0;
  137. u32 dram_odt0;
  138. u32 dram_odt1;
  139. u32 dram_sdqs0;
  140. u32 dram_sdqs1;
  141. u32 dram_sdqs2;
  142. u32 dram_sdqs3;
  143. u32 dram_sdwe_b;
  144. };
  145. #define MX6SL_IOM_GRP_BASE 0x020e0500
  146. struct mx6sl_iomux_grp_regs {
  147. u32 res1[43];
  148. u32 grp_addds;
  149. u32 grp_ddrmode_ctl;
  150. u32 grp_ddrpke;
  151. u32 grp_ddrpk;
  152. u32 grp_ddrhys;
  153. u32 grp_ddrmode;
  154. u32 grp_b0ds;
  155. u32 grp_ctlds;
  156. u32 grp_b1ds;
  157. u32 grp_ddr_type;
  158. u32 grp_b2ds;
  159. u32 grp_b3ds;
  160. };
  161. #define MX6UL_IOM_DDR_BASE 0x020e0200
  162. struct mx6ul_iomux_ddr_regs {
  163. u32 res1[17];
  164. u32 dram_dqm0;
  165. u32 dram_dqm1;
  166. u32 dram_ras;
  167. u32 dram_cas;
  168. u32 dram_cs0;
  169. u32 dram_cs1;
  170. u32 dram_sdwe_b;
  171. u32 dram_odt0;
  172. u32 dram_odt1;
  173. u32 dram_sdba0;
  174. u32 dram_sdba1;
  175. u32 dram_sdba2;
  176. u32 dram_sdcke0;
  177. u32 dram_sdcke1;
  178. u32 dram_sdclk_0;
  179. u32 dram_sdqs0;
  180. u32 dram_sdqs1;
  181. u32 dram_reset;
  182. };
  183. #define MX6UL_IOM_GRP_BASE 0x020e0400
  184. struct mx6ul_iomux_grp_regs {
  185. u32 res1[36];
  186. u32 grp_addds;
  187. u32 grp_ddrmode_ctl;
  188. u32 grp_b0ds;
  189. u32 grp_ddrpk;
  190. u32 grp_ctlds;
  191. u32 grp_b1ds;
  192. u32 grp_ddrhys;
  193. u32 grp_ddrpke;
  194. u32 grp_ddrmode;
  195. u32 grp_ddr_type;
  196. };
  197. #define MX6SX_IOM_DDR_BASE 0x020e0200
  198. struct mx6sx_iomux_ddr_regs {
  199. u32 res1[59];
  200. u32 dram_dqm0;
  201. u32 dram_dqm1;
  202. u32 dram_dqm2;
  203. u32 dram_dqm3;
  204. u32 dram_ras;
  205. u32 dram_cas;
  206. u32 res2[2];
  207. u32 dram_sdwe_b;
  208. u32 dram_odt0;
  209. u32 dram_odt1;
  210. u32 dram_sdba0;
  211. u32 dram_sdba1;
  212. u32 dram_sdba2;
  213. u32 dram_sdcke0;
  214. u32 dram_sdcke1;
  215. u32 dram_sdclk_0;
  216. u32 dram_sdqs0;
  217. u32 dram_sdqs1;
  218. u32 dram_sdqs2;
  219. u32 dram_sdqs3;
  220. u32 dram_reset;
  221. };
  222. #define MX6SX_IOM_GRP_BASE 0x020e0500
  223. struct mx6sx_iomux_grp_regs {
  224. u32 res1[61];
  225. u32 grp_addds;
  226. u32 grp_ddrmode_ctl;
  227. u32 grp_ddrpke;
  228. u32 grp_ddrpk;
  229. u32 grp_ddrhys;
  230. u32 grp_ddrmode;
  231. u32 grp_b0ds;
  232. u32 grp_b1ds;
  233. u32 grp_ctlds;
  234. u32 grp_ddr_type;
  235. u32 grp_b2ds;
  236. u32 grp_b3ds;
  237. };
  238. /*
  239. * MMDC iomux registers (pinctl/padctl) - (different for IMX6DQ vs IMX6SDL)
  240. */
  241. #define MX6DQ_IOM_DDR_BASE 0x020e0500
  242. struct mx6dq_iomux_ddr_regs {
  243. u32 res1[3];
  244. u32 dram_sdqs5;
  245. u32 dram_dqm5;
  246. u32 dram_dqm4;
  247. u32 dram_sdqs4;
  248. u32 dram_sdqs3;
  249. u32 dram_dqm3;
  250. u32 dram_sdqs2;
  251. u32 dram_dqm2;
  252. u32 res2[16];
  253. u32 dram_cas;
  254. u32 res3[2];
  255. u32 dram_ras;
  256. u32 dram_reset;
  257. u32 res4[2];
  258. u32 dram_sdclk_0;
  259. u32 dram_sdba2;
  260. u32 dram_sdcke0;
  261. u32 dram_sdclk_1;
  262. u32 dram_sdcke1;
  263. u32 dram_sdodt0;
  264. u32 dram_sdodt1;
  265. u32 res5;
  266. u32 dram_sdqs0;
  267. u32 dram_dqm0;
  268. u32 dram_sdqs1;
  269. u32 dram_dqm1;
  270. u32 dram_sdqs6;
  271. u32 dram_dqm6;
  272. u32 dram_sdqs7;
  273. u32 dram_dqm7;
  274. };
  275. #define MX6DQ_IOM_GRP_BASE 0x020e0700
  276. struct mx6dq_iomux_grp_regs {
  277. u32 res1[18];
  278. u32 grp_b7ds;
  279. u32 grp_addds;
  280. u32 grp_ddrmode_ctl;
  281. u32 res2;
  282. u32 grp_ddrpke;
  283. u32 res3[6];
  284. u32 grp_ddrmode;
  285. u32 res4[3];
  286. u32 grp_b0ds;
  287. u32 grp_b1ds;
  288. u32 grp_ctlds;
  289. u32 res5;
  290. u32 grp_b2ds;
  291. u32 grp_ddr_type;
  292. u32 grp_b3ds;
  293. u32 grp_b4ds;
  294. u32 grp_b5ds;
  295. u32 grp_b6ds;
  296. };
  297. #define MX6SDL_IOM_DDR_BASE 0x020e0400
  298. struct mx6sdl_iomux_ddr_regs {
  299. u32 res1[25];
  300. u32 dram_cas;
  301. u32 res2[2];
  302. u32 dram_dqm0;
  303. u32 dram_dqm1;
  304. u32 dram_dqm2;
  305. u32 dram_dqm3;
  306. u32 dram_dqm4;
  307. u32 dram_dqm5;
  308. u32 dram_dqm6;
  309. u32 dram_dqm7;
  310. u32 dram_ras;
  311. u32 dram_reset;
  312. u32 res3[2];
  313. u32 dram_sdba2;
  314. u32 dram_sdcke0;
  315. u32 dram_sdcke1;
  316. u32 dram_sdclk_0;
  317. u32 dram_sdclk_1;
  318. u32 dram_sdodt0;
  319. u32 dram_sdodt1;
  320. u32 dram_sdqs0;
  321. u32 dram_sdqs1;
  322. u32 dram_sdqs2;
  323. u32 dram_sdqs3;
  324. u32 dram_sdqs4;
  325. u32 dram_sdqs5;
  326. u32 dram_sdqs6;
  327. u32 dram_sdqs7;
  328. };
  329. #define MX6SDL_IOM_GRP_BASE 0x020e0700
  330. struct mx6sdl_iomux_grp_regs {
  331. u32 res1[18];
  332. u32 grp_b7ds;
  333. u32 grp_addds;
  334. u32 grp_ddrmode_ctl;
  335. u32 grp_ddrpke;
  336. u32 res2[2];
  337. u32 grp_ddrmode;
  338. u32 grp_b0ds;
  339. u32 res3;
  340. u32 grp_ctlds;
  341. u32 grp_b1ds;
  342. u32 grp_ddr_type;
  343. u32 grp_b2ds;
  344. u32 grp_b3ds;
  345. u32 grp_b4ds;
  346. u32 grp_b5ds;
  347. u32 res4;
  348. u32 grp_b6ds;
  349. };
  350. /* Device Information: Varies per DDR3 part number and speed grade */
  351. struct mx6_ddr3_cfg {
  352. u16 mem_speed; /* ie 1600 for DDR3-1600 (800,1066,1333,1600) */
  353. u8 density; /* chip density (Gb) (1,2,4,8) */
  354. u8 width; /* bus width (bits) (4,8,16) */
  355. u8 banks; /* number of banks */
  356. u8 rowaddr; /* row address bits (11-16)*/
  357. u8 coladdr; /* col address bits (9-12) */
  358. u8 pagesz; /* page size (K) (1-2) */
  359. u16 trcd; /* tRCD=tRP=CL (ns*100) */
  360. u16 trcmin; /* tRC min (ns*100) */
  361. u16 trasmin; /* tRAS min (ns*100) */
  362. u8 SRT; /* self-refresh temperature: 0=normal, 1=extended */
  363. };
  364. /* Device Information: Varies per LPDDR2 part number and speed grade */
  365. struct mx6_lpddr2_cfg {
  366. u16 mem_speed; /* ie 800 for LPDDR2-800 */
  367. u8 density; /* chip density (Gb) (1,2,4,8) */
  368. u8 width; /* bus width (bits) (4,8,16) */
  369. u8 banks; /* number of banks */
  370. u8 rowaddr; /* row address bits (11-16)*/
  371. u8 coladdr; /* col address bits (9-12) */
  372. u16 trcd_lp;
  373. u16 trppb_lp;
  374. u16 trpab_lp;
  375. u16 trcmin; /* tRC min (ns*100) */
  376. u16 trasmin; /* tRAS min (ns*100) */
  377. };
  378. /* System Information: Varies per board design, layout, and term choices */
  379. struct mx6_ddr_sysinfo {
  380. u8 dsize; /* size of bus (in dwords: 0=16bit,1=32bit,2=64bit) */
  381. u8 cs_density; /* density per chip select (Gb) */
  382. u8 ncs; /* number chip selects used (1|2) */
  383. char cs1_mirror;/* enable address mirror (0|1) */
  384. char bi_on; /* Bank interleaving enable */
  385. u8 rtt_nom; /* Rtt_Nom (DDR3_RTT_*) */
  386. u8 rtt_wr; /* Rtt_Wr (DDR3_RTT_*) */
  387. u8 ralat; /* Read Additional Latency (0-7) */
  388. u8 walat; /* Write Additional Latency (0-3) */
  389. u8 mif3_mode; /* Command prediction working mode */
  390. u8 rst_to_cke; /* Time from SDE enable to CKE rise */
  391. u8 sde_to_rst; /* Time from SDE enable until DDR reset# is high */
  392. u8 pd_fast_exit;/* enable precharge powerdown fast-exit */
  393. u8 ddr_type; /* DDR type: DDR3(0) or LPDDR2(1) */
  394. u8 refsel; /* REF_SEL field of register MDREF */
  395. u8 refr; /* REFR field of register MDREF */
  396. };
  397. /*
  398. * Board specific calibration:
  399. * This includes write leveling calibration values as well as DQS gating
  400. * and read/write delays. These values are board/layout/device specific.
  401. * Freescale recommends using the i.MX6 DDR Stress Test Tool V1.0.2
  402. * (DOC-96412) to determine these values over a range of boards and
  403. * temperatures.
  404. */
  405. struct mx6_mmdc_calibration {
  406. /* write leveling calibration */
  407. u32 p0_mpwldectrl0;
  408. u32 p0_mpwldectrl1;
  409. u32 p1_mpwldectrl0;
  410. u32 p1_mpwldectrl1;
  411. /* read DQS gating */
  412. u32 p0_mpdgctrl0;
  413. u32 p0_mpdgctrl1;
  414. u32 p1_mpdgctrl0;
  415. u32 p1_mpdgctrl1;
  416. /* read delay */
  417. u32 p0_mprddlctl;
  418. u32 p1_mprddlctl;
  419. /* write delay */
  420. u32 p0_mpwrdlctl;
  421. u32 p1_mpwrdlctl;
  422. /* lpddr2 zq hw calibration */
  423. u32 mpzqlp2ctl;
  424. };
  425. /* configure iomux (pinctl/padctl) */
  426. void mx6dq_dram_iocfg(unsigned width,
  427. const struct mx6dq_iomux_ddr_regs *,
  428. const struct mx6dq_iomux_grp_regs *);
  429. void mx6sdl_dram_iocfg(unsigned width,
  430. const struct mx6sdl_iomux_ddr_regs *,
  431. const struct mx6sdl_iomux_grp_regs *);
  432. void mx6sx_dram_iocfg(unsigned width,
  433. const struct mx6sx_iomux_ddr_regs *,
  434. const struct mx6sx_iomux_grp_regs *);
  435. void mx6ul_dram_iocfg(unsigned width,
  436. const struct mx6ul_iomux_ddr_regs *,
  437. const struct mx6ul_iomux_grp_regs *);
  438. void mx6sl_dram_iocfg(unsigned width,
  439. const struct mx6sl_iomux_ddr_regs *,
  440. const struct mx6sl_iomux_grp_regs *);
  441. #if defined(CONFIG_MX6_DDRCAL)
  442. int mmdc_do_write_level_calibration(struct mx6_ddr_sysinfo const *sysinfo);
  443. int mmdc_do_dqs_calibration(struct mx6_ddr_sysinfo const *sysinfo);
  444. void mmdc_read_calibration(struct mx6_ddr_sysinfo const *sysinfo,
  445. struct mx6_mmdc_calibration *calib);
  446. #endif
  447. /* configure mx6 mmdc registers */
  448. void mx6_dram_cfg(const struct mx6_ddr_sysinfo *,
  449. const struct mx6_mmdc_calibration *,
  450. const void *);
  451. #endif /* CONFIG_SPL_BUILD */
  452. #define MX6_MMDC_P0_MDCTL 0x021b0000
  453. #define MX6_MMDC_P0_MDPDC 0x021b0004
  454. #define MX6_MMDC_P0_MDOTC 0x021b0008
  455. #define MX6_MMDC_P0_MDCFG0 0x021b000c
  456. #define MX6_MMDC_P0_MDCFG1 0x021b0010
  457. #define MX6_MMDC_P0_MDCFG2 0x021b0014
  458. #define MX6_MMDC_P0_MDMISC 0x021b0018
  459. #define MX6_MMDC_P0_MDSCR 0x021b001c
  460. #define MX6_MMDC_P0_MDREF 0x021b0020
  461. #define MX6_MMDC_P0_MDRWD 0x021b002c
  462. #define MX6_MMDC_P0_MDOR 0x021b0030
  463. #define MX6_MMDC_P0_MDASP 0x021b0040
  464. #define MX6_MMDC_P0_MAPSR 0x021b0404
  465. #define MX6_MMDC_P0_MPZQHWCTRL 0x021b0800
  466. #define MX6_MMDC_P0_MPWLDECTRL0 0x021b080c
  467. #define MX6_MMDC_P0_MPWLDECTRL1 0x021b0810
  468. #define MX6_MMDC_P0_MPODTCTRL 0x021b0818
  469. #define MX6_MMDC_P0_MPRDDQBY0DL 0x021b081c
  470. #define MX6_MMDC_P0_MPRDDQBY1DL 0x021b0820
  471. #define MX6_MMDC_P0_MPRDDQBY2DL 0x021b0824
  472. #define MX6_MMDC_P0_MPRDDQBY3DL 0x021b0828
  473. #define MX6_MMDC_P0_MPDGCTRL0 0x021b083c
  474. #define MX6_MMDC_P0_MPDGCTRL1 0x021b0840
  475. #define MX6_MMDC_P0_MPRDDLCTL 0x021b0848
  476. #define MX6_MMDC_P0_MPWRDLCTL 0x021b0850
  477. #define MX6_MMDC_P0_MPZQLP2CTL 0x021b085C
  478. #define MX6_MMDC_P0_MPMUR0 0x021b08b8
  479. #define MX6_MMDC_P1_MDCTL 0x021b4000
  480. #define MX6_MMDC_P1_MDPDC 0x021b4004
  481. #define MX6_MMDC_P1_MDOTC 0x021b4008
  482. #define MX6_MMDC_P1_MDCFG0 0x021b400c
  483. #define MX6_MMDC_P1_MDCFG1 0x021b4010
  484. #define MX6_MMDC_P1_MDCFG2 0x021b4014
  485. #define MX6_MMDC_P1_MDMISC 0x021b4018
  486. #define MX6_MMDC_P1_MDSCR 0x021b401c
  487. #define MX6_MMDC_P1_MDREF 0x021b4020
  488. #define MX6_MMDC_P1_MDRWD 0x021b402c
  489. #define MX6_MMDC_P1_MDOR 0x021b4030
  490. #define MX6_MMDC_P1_MDASP 0x021b4040
  491. #define MX6_MMDC_P1_MAPSR 0x021b4404
  492. #define MX6_MMDC_P1_MPZQHWCTRL 0x021b4800
  493. #define MX6_MMDC_P1_MPWLDECTRL0 0x021b480c
  494. #define MX6_MMDC_P1_MPWLDECTRL1 0x021b4810
  495. #define MX6_MMDC_P1_MPODTCTRL 0x021b4818
  496. #define MX6_MMDC_P1_MPRDDQBY0DL 0x021b481c
  497. #define MX6_MMDC_P1_MPRDDQBY1DL 0x021b4820
  498. #define MX6_MMDC_P1_MPRDDQBY2DL 0x021b4824
  499. #define MX6_MMDC_P1_MPRDDQBY3DL 0x021b4828
  500. #define MX6_MMDC_P1_MPDGCTRL0 0x021b483c
  501. #define MX6_MMDC_P1_MPDGCTRL1 0x021b4840
  502. #define MX6_MMDC_P1_MPRDDLCTL 0x021b4848
  503. #define MX6_MMDC_P1_MPWRDLCTL 0x021b4850
  504. #define MX6_MMDC_P1_MPZQLP2CTL 0x021b485C
  505. #define MX6_MMDC_P1_MPMUR0 0x021b48b8
  506. #endif /*__ASM_ARCH_MX6_DDR_H__ */