ddr.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. * Copyright (C) 2014 Gateworks Corporation
  3. * Author: Tim Harvey <tharvey@gateworks.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <linux/types.h>
  9. #include <asm/arch/mx6-ddr.h>
  10. #include <asm/arch/sys_proto.h>
  11. #include <asm/io.h>
  12. #include <asm/types.h>
  13. #if defined(CONFIG_MX6QDL) || defined(CONFIG_MX6Q) || defined(CONFIG_MX6D)
  14. /* Configure MX6DQ mmdc iomux */
  15. void mx6dq_dram_iocfg(unsigned width,
  16. const struct mx6dq_iomux_ddr_regs *ddr,
  17. const struct mx6dq_iomux_grp_regs *grp)
  18. {
  19. volatile struct mx6dq_iomux_ddr_regs *mx6_ddr_iomux;
  20. volatile struct mx6dq_iomux_grp_regs *mx6_grp_iomux;
  21. mx6_ddr_iomux = (struct mx6dq_iomux_ddr_regs *)MX6DQ_IOM_DDR_BASE;
  22. mx6_grp_iomux = (struct mx6dq_iomux_grp_regs *)MX6DQ_IOM_GRP_BASE;
  23. /* DDR IO Type */
  24. mx6_grp_iomux->grp_ddr_type = grp->grp_ddr_type;
  25. mx6_grp_iomux->grp_ddrpke = grp->grp_ddrpke;
  26. /* Clock */
  27. mx6_ddr_iomux->dram_sdclk_0 = ddr->dram_sdclk_0;
  28. mx6_ddr_iomux->dram_sdclk_1 = ddr->dram_sdclk_1;
  29. /* Address */
  30. mx6_ddr_iomux->dram_cas = ddr->dram_cas;
  31. mx6_ddr_iomux->dram_ras = ddr->dram_ras;
  32. mx6_grp_iomux->grp_addds = grp->grp_addds;
  33. /* Control */
  34. mx6_ddr_iomux->dram_reset = ddr->dram_reset;
  35. mx6_ddr_iomux->dram_sdcke0 = ddr->dram_sdcke0;
  36. mx6_ddr_iomux->dram_sdcke1 = ddr->dram_sdcke1;
  37. mx6_ddr_iomux->dram_sdba2 = ddr->dram_sdba2;
  38. mx6_ddr_iomux->dram_sdodt0 = ddr->dram_sdodt0;
  39. mx6_ddr_iomux->dram_sdodt1 = ddr->dram_sdodt1;
  40. mx6_grp_iomux->grp_ctlds = grp->grp_ctlds;
  41. /* Data Strobes */
  42. mx6_grp_iomux->grp_ddrmode_ctl = grp->grp_ddrmode_ctl;
  43. mx6_ddr_iomux->dram_sdqs0 = ddr->dram_sdqs0;
  44. mx6_ddr_iomux->dram_sdqs1 = ddr->dram_sdqs1;
  45. if (width >= 32) {
  46. mx6_ddr_iomux->dram_sdqs2 = ddr->dram_sdqs2;
  47. mx6_ddr_iomux->dram_sdqs3 = ddr->dram_sdqs3;
  48. }
  49. if (width >= 64) {
  50. mx6_ddr_iomux->dram_sdqs4 = ddr->dram_sdqs4;
  51. mx6_ddr_iomux->dram_sdqs5 = ddr->dram_sdqs5;
  52. mx6_ddr_iomux->dram_sdqs6 = ddr->dram_sdqs6;
  53. mx6_ddr_iomux->dram_sdqs7 = ddr->dram_sdqs7;
  54. }
  55. /* Data */
  56. mx6_grp_iomux->grp_ddrmode = grp->grp_ddrmode;
  57. mx6_grp_iomux->grp_b0ds = grp->grp_b0ds;
  58. mx6_grp_iomux->grp_b1ds = grp->grp_b1ds;
  59. if (width >= 32) {
  60. mx6_grp_iomux->grp_b2ds = grp->grp_b2ds;
  61. mx6_grp_iomux->grp_b3ds = grp->grp_b3ds;
  62. }
  63. if (width >= 64) {
  64. mx6_grp_iomux->grp_b4ds = grp->grp_b4ds;
  65. mx6_grp_iomux->grp_b5ds = grp->grp_b5ds;
  66. mx6_grp_iomux->grp_b6ds = grp->grp_b6ds;
  67. mx6_grp_iomux->grp_b7ds = grp->grp_b7ds;
  68. }
  69. mx6_ddr_iomux->dram_dqm0 = ddr->dram_dqm0;
  70. mx6_ddr_iomux->dram_dqm1 = ddr->dram_dqm1;
  71. if (width >= 32) {
  72. mx6_ddr_iomux->dram_dqm2 = ddr->dram_dqm2;
  73. mx6_ddr_iomux->dram_dqm3 = ddr->dram_dqm3;
  74. }
  75. if (width >= 64) {
  76. mx6_ddr_iomux->dram_dqm4 = ddr->dram_dqm4;
  77. mx6_ddr_iomux->dram_dqm5 = ddr->dram_dqm5;
  78. mx6_ddr_iomux->dram_dqm6 = ddr->dram_dqm6;
  79. mx6_ddr_iomux->dram_dqm7 = ddr->dram_dqm7;
  80. }
  81. }
  82. #endif
  83. #if defined(CONFIG_MX6QDL) || defined(CONFIG_MX6DL) || defined(CONFIG_MX6S)
  84. /* Configure MX6SDL mmdc iomux */
  85. void mx6sdl_dram_iocfg(unsigned width,
  86. const struct mx6sdl_iomux_ddr_regs *ddr,
  87. const struct mx6sdl_iomux_grp_regs *grp)
  88. {
  89. volatile struct mx6sdl_iomux_ddr_regs *mx6_ddr_iomux;
  90. volatile struct mx6sdl_iomux_grp_regs *mx6_grp_iomux;
  91. mx6_ddr_iomux = (struct mx6sdl_iomux_ddr_regs *)MX6SDL_IOM_DDR_BASE;
  92. mx6_grp_iomux = (struct mx6sdl_iomux_grp_regs *)MX6SDL_IOM_GRP_BASE;
  93. /* DDR IO Type */
  94. mx6_grp_iomux->grp_ddr_type = grp->grp_ddr_type;
  95. mx6_grp_iomux->grp_ddrpke = grp->grp_ddrpke;
  96. /* Clock */
  97. mx6_ddr_iomux->dram_sdclk_0 = ddr->dram_sdclk_0;
  98. mx6_ddr_iomux->dram_sdclk_1 = ddr->dram_sdclk_1;
  99. /* Address */
  100. mx6_ddr_iomux->dram_cas = ddr->dram_cas;
  101. mx6_ddr_iomux->dram_ras = ddr->dram_ras;
  102. mx6_grp_iomux->grp_addds = grp->grp_addds;
  103. /* Control */
  104. mx6_ddr_iomux->dram_reset = ddr->dram_reset;
  105. mx6_ddr_iomux->dram_sdcke0 = ddr->dram_sdcke0;
  106. mx6_ddr_iomux->dram_sdcke1 = ddr->dram_sdcke1;
  107. mx6_ddr_iomux->dram_sdba2 = ddr->dram_sdba2;
  108. mx6_ddr_iomux->dram_sdodt0 = ddr->dram_sdodt0;
  109. mx6_ddr_iomux->dram_sdodt1 = ddr->dram_sdodt1;
  110. mx6_grp_iomux->grp_ctlds = grp->grp_ctlds;
  111. /* Data Strobes */
  112. mx6_grp_iomux->grp_ddrmode_ctl = grp->grp_ddrmode_ctl;
  113. mx6_ddr_iomux->dram_sdqs0 = ddr->dram_sdqs0;
  114. mx6_ddr_iomux->dram_sdqs1 = ddr->dram_sdqs1;
  115. if (width >= 32) {
  116. mx6_ddr_iomux->dram_sdqs2 = ddr->dram_sdqs2;
  117. mx6_ddr_iomux->dram_sdqs3 = ddr->dram_sdqs3;
  118. }
  119. if (width >= 64) {
  120. mx6_ddr_iomux->dram_sdqs4 = ddr->dram_sdqs4;
  121. mx6_ddr_iomux->dram_sdqs5 = ddr->dram_sdqs5;
  122. mx6_ddr_iomux->dram_sdqs6 = ddr->dram_sdqs6;
  123. mx6_ddr_iomux->dram_sdqs7 = ddr->dram_sdqs7;
  124. }
  125. /* Data */
  126. mx6_grp_iomux->grp_ddrmode = grp->grp_ddrmode;
  127. mx6_grp_iomux->grp_b0ds = grp->grp_b0ds;
  128. mx6_grp_iomux->grp_b1ds = grp->grp_b1ds;
  129. if (width >= 32) {
  130. mx6_grp_iomux->grp_b2ds = grp->grp_b2ds;
  131. mx6_grp_iomux->grp_b3ds = grp->grp_b3ds;
  132. }
  133. if (width >= 64) {
  134. mx6_grp_iomux->grp_b4ds = grp->grp_b4ds;
  135. mx6_grp_iomux->grp_b5ds = grp->grp_b5ds;
  136. mx6_grp_iomux->grp_b6ds = grp->grp_b6ds;
  137. mx6_grp_iomux->grp_b7ds = grp->grp_b7ds;
  138. }
  139. mx6_ddr_iomux->dram_dqm0 = ddr->dram_dqm0;
  140. mx6_ddr_iomux->dram_dqm1 = ddr->dram_dqm1;
  141. if (width >= 32) {
  142. mx6_ddr_iomux->dram_dqm2 = ddr->dram_dqm2;
  143. mx6_ddr_iomux->dram_dqm3 = ddr->dram_dqm3;
  144. }
  145. if (width >= 64) {
  146. mx6_ddr_iomux->dram_dqm4 = ddr->dram_dqm4;
  147. mx6_ddr_iomux->dram_dqm5 = ddr->dram_dqm5;
  148. mx6_ddr_iomux->dram_dqm6 = ddr->dram_dqm6;
  149. mx6_ddr_iomux->dram_dqm7 = ddr->dram_dqm7;
  150. }
  151. }
  152. #endif
  153. /*
  154. * Configure mx6 mmdc registers based on:
  155. * - board-specific memory configuration
  156. * - board-specific calibration data
  157. * - ddr3 chip details
  158. *
  159. * The various calculations here are derived from the Freescale
  160. * i.Mx6DQSDL DDR3 Script Aid spreadsheet (DOC-94917) designed to generate MMDC
  161. * configuration registers based on memory system and memory chip parameters.
  162. *
  163. * The defaults here are those which were specified in the spreadsheet.
  164. * For details on each register, refer to the IMX6DQRM and/or IMX6SDLRM
  165. * section titled MMDC initialization
  166. */
  167. #define MR(val, ba, cmd, cs1) \
  168. ((val << 16) | (1 << 15) | (cmd << 4) | (cs1 << 3) | ba)
  169. void mx6_dram_cfg(const struct mx6_ddr_sysinfo *i,
  170. const struct mx6_mmdc_calibration *c,
  171. const struct mx6_ddr3_cfg *m)
  172. {
  173. volatile struct mmdc_p_regs *mmdc0;
  174. volatile struct mmdc_p_regs *mmdc1;
  175. u32 reg;
  176. u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd;
  177. u8 todtlon, taxpd, tanpd, tcwl, txp, tfaw, tcl;
  178. u8 todt_idle_off = 0x4; /* from DDR3 Script Aid spreadsheet */
  179. u16 trcd, trc, tras, twr, tmrd, trtp, trp, twtr, trfc, txs, txpr;
  180. u16 CS0_END;
  181. u16 tdllk = 0x1ff; /* DLL locking time: 512 cycles (JEDEC DDR3) */
  182. int clkper; /* clock period in picoseconds */
  183. int clock; /* clock freq in mHz */
  184. int cs;
  185. mmdc0 = (struct mmdc_p_regs *)MMDC_P0_BASE_ADDR;
  186. mmdc1 = (struct mmdc_p_regs *)MMDC_P1_BASE_ADDR;
  187. /* MX6D/MX6Q: 1066 MHz memory clock, clkper = 1.894ns = 1894ps */
  188. if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) {
  189. clock = 528;
  190. tcwl = 4;
  191. }
  192. /* MX6S/MX6DL: 800 MHz memory clock, clkper = 2.5ns = 2500ps */
  193. else {
  194. clock = 400;
  195. tcwl = 3;
  196. }
  197. clkper = (1000*1000)/clock; /* ps */
  198. todtlon = tcwl;
  199. taxpd = tcwl;
  200. tanpd = tcwl;
  201. tcwl = tcwl;
  202. switch (m->density) {
  203. case 1: /* 1Gb per chip */
  204. trfc = DIV_ROUND_UP(110000, clkper) - 1;
  205. txs = DIV_ROUND_UP(120000, clkper) - 1;
  206. break;
  207. case 2: /* 2Gb per chip */
  208. trfc = DIV_ROUND_UP(160000, clkper) - 1;
  209. txs = DIV_ROUND_UP(170000, clkper) - 1;
  210. break;
  211. case 4: /* 4Gb per chip */
  212. trfc = DIV_ROUND_UP(260000, clkper) - 1;
  213. txs = DIV_ROUND_UP(270000, clkper) - 1;
  214. break;
  215. case 8: /* 8Gb per chip */
  216. trfc = DIV_ROUND_UP(350000, clkper) - 1;
  217. txs = DIV_ROUND_UP(360000, clkper) - 1;
  218. break;
  219. default:
  220. /* invalid density */
  221. printf("invalid chip density\n");
  222. hang();
  223. break;
  224. }
  225. txpr = txs;
  226. switch (m->mem_speed) {
  227. case 800:
  228. txp = DIV_ROUND_UP(MAX(3*clkper, 7500), clkper) - 1;
  229. tcke = DIV_ROUND_UP(MAX(3*clkper, 7500), clkper) - 1;
  230. if (m->pagesz == 1) {
  231. tfaw = DIV_ROUND_UP(40000, clkper) - 1;
  232. trrd = DIV_ROUND_UP(MAX(4*clkper, 10000), clkper) - 1;
  233. } else {
  234. tfaw = DIV_ROUND_UP(50000, clkper) - 1;
  235. trrd = DIV_ROUND_UP(MAX(4*clkper, 10000), clkper) - 1;
  236. }
  237. break;
  238. case 1066:
  239. txp = DIV_ROUND_UP(MAX(3*clkper, 7500), clkper) - 1;
  240. tcke = DIV_ROUND_UP(MAX(3*clkper, 5625), clkper) - 1;
  241. if (m->pagesz == 1) {
  242. tfaw = DIV_ROUND_UP(37500, clkper) - 1;
  243. trrd = DIV_ROUND_UP(MAX(4*clkper, 7500), clkper) - 1;
  244. } else {
  245. tfaw = DIV_ROUND_UP(50000, clkper) - 1;
  246. trrd = DIV_ROUND_UP(MAX(4*clkper, 10000), clkper) - 1;
  247. }
  248. break;
  249. case 1333:
  250. txp = DIV_ROUND_UP(MAX(3*clkper, 6000), clkper) - 1;
  251. tcke = DIV_ROUND_UP(MAX(3*clkper, 5625), clkper) - 1;
  252. if (m->pagesz == 1) {
  253. tfaw = DIV_ROUND_UP(30000, clkper) - 1;
  254. trrd = DIV_ROUND_UP(MAX(4*clkper, 6000), clkper) - 1;
  255. } else {
  256. tfaw = DIV_ROUND_UP(45000, clkper) - 1;
  257. trrd = DIV_ROUND_UP(MAX(4*clkper, 7500), clkper) - 1;
  258. }
  259. break;
  260. case 1600:
  261. txp = DIV_ROUND_UP(MAX(3*clkper, 6000), clkper) - 1;
  262. tcke = DIV_ROUND_UP(MAX(3*clkper, 5000), clkper) - 1;
  263. if (m->pagesz == 1) {
  264. tfaw = DIV_ROUND_UP(30000, clkper) - 1;
  265. trrd = DIV_ROUND_UP(MAX(4*clkper, 6000), clkper) - 1;
  266. } else {
  267. tfaw = DIV_ROUND_UP(40000, clkper) - 1;
  268. trrd = DIV_ROUND_UP(MAX(4*clkper, 7500), clkper) - 1;
  269. }
  270. break;
  271. default:
  272. printf("invalid memory speed\n");
  273. hang();
  274. break;
  275. }
  276. txpdll = DIV_ROUND_UP(MAX(10*clkper, 24000), clkper) - 1;
  277. tcl = DIV_ROUND_UP(m->trcd, clkper/10) - 3;
  278. tcksre = DIV_ROUND_UP(MAX(5*clkper, 10000), clkper);
  279. tcksrx = tcksre;
  280. taonpd = DIV_ROUND_UP(2000, clkper) - 1;
  281. taofpd = taonpd;
  282. trp = DIV_ROUND_UP(m->trcd, clkper/10) - 1;
  283. trcd = trp;
  284. trc = DIV_ROUND_UP(m->trcmin, clkper/10) - 1;
  285. tras = DIV_ROUND_UP(m->trasmin, clkper/10) - 1;
  286. twr = DIV_ROUND_UP(15000, clkper) - 1;
  287. tmrd = DIV_ROUND_UP(MAX(12*clkper, 15000), clkper) - 1;
  288. twtr = ROUND(MAX(4*clkper, 7500)/clkper, 1) - 1;
  289. trtp = twtr;
  290. CS0_END = ((4*i->cs_density) <= 120) ? (4*i->cs_density)+7 : 127;
  291. debug("density:%d Gb (%d Gb per chip)\n", i->cs_density, m->density);
  292. debug("clock: %dMHz (%d ps)\n", clock, clkper);
  293. debug("memspd:%d\n", m->mem_speed);
  294. debug("tcke=%d\n", tcke);
  295. debug("tcksrx=%d\n", tcksrx);
  296. debug("tcksre=%d\n", tcksre);
  297. debug("taofpd=%d\n", taofpd);
  298. debug("taonpd=%d\n", taonpd);
  299. debug("todtlon=%d\n", todtlon);
  300. debug("tanpd=%d\n", tanpd);
  301. debug("taxpd=%d\n", taxpd);
  302. debug("trfc=%d\n", trfc);
  303. debug("txs=%d\n", txs);
  304. debug("txp=%d\n", txp);
  305. debug("txpdll=%d\n", txpdll);
  306. debug("tfaw=%d\n", tfaw);
  307. debug("tcl=%d\n", tcl);
  308. debug("trcd=%d\n", trcd);
  309. debug("trp=%d\n", trp);
  310. debug("trc=%d\n", trc);
  311. debug("tras=%d\n", tras);
  312. debug("twr=%d\n", twr);
  313. debug("tmrd=%d\n", tmrd);
  314. debug("tcwl=%d\n", tcwl);
  315. debug("tdllk=%d\n", tdllk);
  316. debug("trtp=%d\n", trtp);
  317. debug("twtr=%d\n", twtr);
  318. debug("trrd=%d\n", trrd);
  319. debug("txpr=%d\n", txpr);
  320. debug("CS0_END=%d\n", CS0_END);
  321. debug("ncs=%d\n", i->ncs);
  322. debug("Rtt_wr=%d\n", i->rtt_wr);
  323. debug("Rtt_nom=%d\n", i->rtt_nom);
  324. debug("SRT=%d\n", m->SRT);
  325. debug("tcl=%d\n", tcl);
  326. debug("twr=%d\n", twr);
  327. /*
  328. * board-specific configuration:
  329. * These values are determined empirically and vary per board layout
  330. * see:
  331. * appnote, ddr3 spreadsheet
  332. */
  333. mmdc0->mpwldectrl0 = c->p0_mpwldectrl0;
  334. mmdc0->mpwldectrl1 = c->p0_mpwldectrl1;
  335. mmdc0->mpdgctrl0 = c->p0_mpdgctrl0;
  336. mmdc0->mpdgctrl1 = c->p0_mpdgctrl1;
  337. mmdc0->mprddlctl = c->p0_mprddlctl;
  338. mmdc0->mpwrdlctl = c->p0_mpwrdlctl;
  339. if (i->dsize > 1) {
  340. mmdc1->mpwldectrl0 = c->p1_mpwldectrl0;
  341. mmdc1->mpwldectrl1 = c->p1_mpwldectrl1;
  342. mmdc1->mpdgctrl0 = c->p1_mpdgctrl0;
  343. mmdc1->mpdgctrl1 = c->p1_mpdgctrl1;
  344. mmdc1->mprddlctl = c->p1_mprddlctl;
  345. mmdc1->mpwrdlctl = c->p1_mpwrdlctl;
  346. }
  347. /* Read data DQ Byte0-3 delay */
  348. mmdc0->mprddqby0dl = (u32)0x33333333;
  349. mmdc0->mprddqby1dl = (u32)0x33333333;
  350. if (i->dsize > 0) {
  351. mmdc0->mprddqby2dl = (u32)0x33333333;
  352. mmdc0->mprddqby3dl = (u32)0x33333333;
  353. }
  354. if (i->dsize > 1) {
  355. mmdc1->mprddqby0dl = (u32)0x33333333;
  356. mmdc1->mprddqby1dl = (u32)0x33333333;
  357. mmdc1->mprddqby2dl = (u32)0x33333333;
  358. mmdc1->mprddqby3dl = (u32)0x33333333;
  359. }
  360. /* MMDC Termination: rtt_nom:2 RZQ/2(120ohm), rtt_nom:1 RZQ/4(60ohm) */
  361. reg = (i->rtt_nom == 2) ? 0x00011117 : 0x00022227;
  362. mmdc0->mpodtctrl = reg;
  363. if (i->dsize > 1)
  364. mmdc1->mpodtctrl = reg;
  365. /* complete calibration */
  366. reg = (1 << 11); /* Force measurement on delay-lines */
  367. mmdc0->mpmur0 = reg;
  368. if (i->dsize > 1)
  369. mmdc1->mpmur0 = reg;
  370. /* Step 1: configuration request */
  371. mmdc0->mdscr = (u32)(1 << 15); /* config request */
  372. /* Step 2: Timing configuration */
  373. reg = (trfc << 24) | (txs << 16) | (txp << 13) | (txpdll << 9) |
  374. (tfaw << 4) | tcl;
  375. mmdc0->mdcfg0 = reg;
  376. reg = (trcd << 29) | (trp << 26) | (trc << 21) | (tras << 16) |
  377. (1 << 15) | /* trpa */
  378. (twr << 9) | (tmrd << 5) | tcwl;
  379. mmdc0->mdcfg1 = reg;
  380. reg = (tdllk << 16) | (trtp << 6) | (twtr << 3) | trrd;
  381. mmdc0->mdcfg2 = reg;
  382. reg = (taofpd << 27) | (taonpd << 24) | (tanpd << 20) | (taxpd << 16) |
  383. (todtlon << 12) | (todt_idle_off << 4);
  384. mmdc0->mdotc = reg;
  385. mmdc0->mdasp = CS0_END; /* CS addressing */
  386. /* Step 3: Configure DDR type */
  387. reg = (i->cs1_mirror << 19) | (i->walat << 16) | (i->bi_on << 12) |
  388. (i->mif3_mode << 9) | (i->ralat << 6);
  389. mmdc0->mdmisc = reg;
  390. /* Step 4: Configure delay while leaving reset */
  391. reg = (txpr << 16) | (i->sde_to_rst << 8) | (i->rst_to_cke << 0);
  392. mmdc0->mdor = reg;
  393. /* Step 5: Configure DDR physical parameters (density and burst len) */
  394. reg = (m->rowaddr - 11) << 24 | /* ROW */
  395. (m->coladdr - 9) << 20 | /* COL */
  396. (1 << 19) | /* Burst Length = 8 for DDR3 */
  397. (i->dsize << 16); /* DDR data bus size */
  398. mmdc0->mdctl = reg;
  399. /* Step 6: Perform ZQ calibration */
  400. reg = (u32)0xa1390001; /* one-time HW ZQ calib */
  401. mmdc0->mpzqhwctrl = reg;
  402. if (i->dsize > 1)
  403. mmdc1->mpzqhwctrl = reg;
  404. /* Step 7: Enable MMDC with desired chip select */
  405. reg = mmdc0->mdctl |
  406. (1 << 31) | /* SDE_0 for CS0 */
  407. ((i->ncs == 2) ? 1 : 0) << 30; /* SDE_1 for CS1 */
  408. mmdc0->mdctl = reg;
  409. /* Step 8: Write Mode Registers to Init DDR3 devices */
  410. for (cs = 0; cs < i->ncs; cs++) {
  411. /* MR2 */
  412. reg = (i->rtt_wr & 3) << 9 | (m->SRT & 1) << 7 |
  413. ((tcwl - 3) & 3) << 3;
  414. mmdc0->mdscr = (u32)MR(reg, 2, 3, cs);
  415. /* MR3 */
  416. mmdc0->mdscr = (u32)MR(0, 3, 3, cs);
  417. /* MR1 */
  418. reg = ((i->rtt_nom & 1) ? 1 : 0) << 2 |
  419. ((i->rtt_nom & 2) ? 1 : 0) << 6;
  420. mmdc0->mdscr = (u32)MR(reg, 1, 3, cs);
  421. reg = ((tcl - 1) << 4) | /* CAS */
  422. (1 << 8) | /* DLL Reset */
  423. ((twr - 3) << 9); /* Write Recovery */
  424. /* MR0 */
  425. mmdc0->mdscr = (u32)MR(reg, 0, 3, cs);
  426. /* ZQ calibration */
  427. reg = (1 << 10);
  428. mmdc0->mdscr = (u32)MR(reg, 0, 4, cs);
  429. }
  430. /* Step 10: Power down control and self-refresh */
  431. reg = (tcke & 0x7) << 16 |
  432. 5 << 12 | /* PWDT_1: 256 cycles */
  433. 5 << 8 | /* PWDT_0: 256 cycles */
  434. 1 << 6 | /* BOTH_CS_PD */
  435. (tcksrx & 0x7) << 3 |
  436. (tcksre & 0x7);
  437. mmdc0->mdpdc = reg;
  438. mmdc0->mapsr = (u32)0x00011006; /* ADOPT power down enabled */
  439. /* Step 11: Configure ZQ calibration: one-time and periodic 1ms */
  440. mmdc0->mpzqhwctrl = (u32)0xa1390003;
  441. if (i->dsize > 1)
  442. mmdc1->mpzqhwctrl = (u32)0xa1390003;
  443. /* Step 12: Configure and activate periodic refresh */
  444. reg = (1 << 14) | /* REF_SEL: Periodic refresh cycles of 32kHz */
  445. (7 << 11); /* REFR: Refresh Rate - 8 refreshes */
  446. mmdc0->mdref = reg;
  447. /* Step 13: Deassert config request - init complete */
  448. mmdc0->mdscr = (u32)0x00000000;
  449. /* wait for auto-ZQ calibration to complete */
  450. mdelay(1);
  451. }