emif-common.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  1. /*
  2. * EMIF programming
  3. *
  4. * (C) Copyright 2010
  5. * Texas Instruments, <www.ti.com>
  6. *
  7. * Aneesh V <aneesh@ti.com>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <asm/emif.h>
  13. #include <asm/arch/clock.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/omap_common.h>
  16. #include <asm/omap_sec_common.h>
  17. #include <asm/utils.h>
  18. #include <linux/compiler.h>
  19. #include <asm/ti-common/ti-edma3.h>
  20. static int emif1_enabled = -1, emif2_enabled = -1;
  21. void set_lpmode_selfrefresh(u32 base)
  22. {
  23. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  24. u32 reg;
  25. reg = readl(&emif->emif_pwr_mgmt_ctrl);
  26. reg &= ~EMIF_REG_LP_MODE_MASK;
  27. reg |= LP_MODE_SELF_REFRESH << EMIF_REG_LP_MODE_SHIFT;
  28. reg &= ~EMIF_REG_SR_TIM_MASK;
  29. writel(reg, &emif->emif_pwr_mgmt_ctrl);
  30. /* dummy read for the new SR_TIM to be loaded */
  31. readl(&emif->emif_pwr_mgmt_ctrl);
  32. }
  33. void force_emif_self_refresh()
  34. {
  35. set_lpmode_selfrefresh(EMIF1_BASE);
  36. if (!is_dra72x())
  37. set_lpmode_selfrefresh(EMIF2_BASE);
  38. }
  39. inline u32 emif_num(u32 base)
  40. {
  41. if (base == EMIF1_BASE)
  42. return 1;
  43. else if (base == EMIF2_BASE)
  44. return 2;
  45. else
  46. return 0;
  47. }
  48. static inline u32 get_mr(u32 base, u32 cs, u32 mr_addr)
  49. {
  50. u32 mr;
  51. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  52. mr_addr |= cs << EMIF_REG_CS_SHIFT;
  53. writel(mr_addr, &emif->emif_lpddr2_mode_reg_cfg);
  54. if (omap_revision() == OMAP4430_ES2_0)
  55. mr = readl(&emif->emif_lpddr2_mode_reg_data_es2);
  56. else
  57. mr = readl(&emif->emif_lpddr2_mode_reg_data);
  58. debug("get_mr: EMIF%d cs %d mr %08x val 0x%x\n", emif_num(base),
  59. cs, mr_addr, mr);
  60. if (((mr & 0x0000ff00) >> 8) == (mr & 0xff) &&
  61. ((mr & 0x00ff0000) >> 16) == (mr & 0xff) &&
  62. ((mr & 0xff000000) >> 24) == (mr & 0xff))
  63. return mr & 0xff;
  64. else
  65. return mr;
  66. }
  67. static inline void set_mr(u32 base, u32 cs, u32 mr_addr, u32 mr_val)
  68. {
  69. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  70. mr_addr |= cs << EMIF_REG_CS_SHIFT;
  71. writel(mr_addr, &emif->emif_lpddr2_mode_reg_cfg);
  72. writel(mr_val, &emif->emif_lpddr2_mode_reg_data);
  73. }
  74. void emif_reset_phy(u32 base)
  75. {
  76. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  77. u32 iodft;
  78. iodft = readl(&emif->emif_iodft_tlgc);
  79. iodft |= EMIF_REG_RESET_PHY_MASK;
  80. writel(iodft, &emif->emif_iodft_tlgc);
  81. }
  82. static void do_lpddr2_init(u32 base, u32 cs)
  83. {
  84. u32 mr_addr;
  85. const struct lpddr2_mr_regs *mr_regs;
  86. get_lpddr2_mr_regs(&mr_regs);
  87. /* Wait till device auto initialization is complete */
  88. while (get_mr(base, cs, LPDDR2_MR0) & LPDDR2_MR0_DAI_MASK)
  89. ;
  90. set_mr(base, cs, LPDDR2_MR10, mr_regs->mr10);
  91. /*
  92. * tZQINIT = 1 us
  93. * Enough loops assuming a maximum of 2GHz
  94. */
  95. sdelay(2000);
  96. set_mr(base, cs, LPDDR2_MR1, mr_regs->mr1);
  97. set_mr(base, cs, LPDDR2_MR16, mr_regs->mr16);
  98. /*
  99. * Enable refresh along with writing MR2
  100. * Encoding of RL in MR2 is (RL - 2)
  101. */
  102. mr_addr = LPDDR2_MR2 | EMIF_REG_REFRESH_EN_MASK;
  103. set_mr(base, cs, mr_addr, mr_regs->mr2);
  104. if (mr_regs->mr3 > 0)
  105. set_mr(base, cs, LPDDR2_MR3, mr_regs->mr3);
  106. }
  107. static void lpddr2_init(u32 base, const struct emif_regs *regs)
  108. {
  109. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  110. /* Not NVM */
  111. clrbits_le32(&emif->emif_lpddr2_nvm_config, EMIF_REG_CS1NVMEN_MASK);
  112. /*
  113. * Keep REG_INITREF_DIS = 1 to prevent re-initialization of SDRAM
  114. * when EMIF_SDRAM_CONFIG register is written
  115. */
  116. setbits_le32(&emif->emif_sdram_ref_ctrl, EMIF_REG_INITREF_DIS_MASK);
  117. /*
  118. * Set the SDRAM_CONFIG and PHY_CTRL for the
  119. * un-locked frequency & default RL
  120. */
  121. writel(regs->sdram_config_init, &emif->emif_sdram_config);
  122. writel(regs->emif_ddr_phy_ctlr_1_init, &emif->emif_ddr_phy_ctrl_1);
  123. do_ext_phy_settings(base, regs);
  124. do_lpddr2_init(base, CS0);
  125. if (regs->sdram_config & EMIF_REG_EBANK_MASK)
  126. do_lpddr2_init(base, CS1);
  127. writel(regs->sdram_config, &emif->emif_sdram_config);
  128. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1);
  129. /* Enable refresh now */
  130. clrbits_le32(&emif->emif_sdram_ref_ctrl, EMIF_REG_INITREF_DIS_MASK);
  131. }
  132. __weak void do_ext_phy_settings(u32 base, const struct emif_regs *regs)
  133. {
  134. }
  135. void emif_update_timings(u32 base, const struct emif_regs *regs)
  136. {
  137. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  138. if (!is_dra7xx())
  139. writel(regs->ref_ctrl, &emif->emif_sdram_ref_ctrl_shdw);
  140. else
  141. writel(regs->ref_ctrl_final, &emif->emif_sdram_ref_ctrl_shdw);
  142. writel(regs->sdram_tim1, &emif->emif_sdram_tim_1_shdw);
  143. writel(regs->sdram_tim2, &emif->emif_sdram_tim_2_shdw);
  144. writel(regs->sdram_tim3, &emif->emif_sdram_tim_3_shdw);
  145. if (omap_revision() == OMAP4430_ES1_0) {
  146. /* ES1 bug EMIF should be in force idle during freq_update */
  147. writel(0, &emif->emif_pwr_mgmt_ctrl);
  148. } else {
  149. writel(EMIF_PWR_MGMT_CTRL, &emif->emif_pwr_mgmt_ctrl);
  150. writel(EMIF_PWR_MGMT_CTRL_SHDW, &emif->emif_pwr_mgmt_ctrl_shdw);
  151. }
  152. writel(regs->read_idle_ctrl, &emif->emif_read_idlectrl_shdw);
  153. writel(regs->zq_config, &emif->emif_zq_config);
  154. writel(regs->temp_alert_config, &emif->emif_temp_alert_config);
  155. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1_shdw);
  156. if ((omap_revision() >= OMAP5430_ES1_0) || is_dra7xx()) {
  157. writel(EMIF_L3_CONFIG_VAL_SYS_10_MPU_5_LL_0,
  158. &emif->emif_l3_config);
  159. } else if (omap_revision() >= OMAP4460_ES1_0) {
  160. writel(EMIF_L3_CONFIG_VAL_SYS_10_MPU_3_LL_0,
  161. &emif->emif_l3_config);
  162. } else {
  163. writel(EMIF_L3_CONFIG_VAL_SYS_10_LL_0,
  164. &emif->emif_l3_config);
  165. }
  166. }
  167. #ifndef CONFIG_OMAP44XX
  168. static void omap5_ddr3_leveling(u32 base, const struct emif_regs *regs)
  169. {
  170. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  171. /* keep sdram in self-refresh */
  172. writel(((LP_MODE_SELF_REFRESH << EMIF_REG_LP_MODE_SHIFT)
  173. & EMIF_REG_LP_MODE_MASK), &emif->emif_pwr_mgmt_ctrl);
  174. __udelay(130);
  175. /*
  176. * Set invert_clkout (if activated)--DDR_PHYCTRL_1
  177. * Invert clock adds an additional half cycle delay on the
  178. * command interface. The additional half cycle, is usually
  179. * meant to enable leveling in the situation that DQS is later
  180. * than CK on the board.It also helps provide some additional
  181. * margin for leveling.
  182. */
  183. writel(regs->emif_ddr_phy_ctlr_1,
  184. &emif->emif_ddr_phy_ctrl_1);
  185. writel(regs->emif_ddr_phy_ctlr_1,
  186. &emif->emif_ddr_phy_ctrl_1_shdw);
  187. __udelay(130);
  188. writel(((LP_MODE_DISABLE << EMIF_REG_LP_MODE_SHIFT)
  189. & EMIF_REG_LP_MODE_MASK), &emif->emif_pwr_mgmt_ctrl);
  190. /* Launch Full leveling */
  191. writel(DDR3_FULL_LVL, &emif->emif_rd_wr_lvl_ctl);
  192. /* Wait till full leveling is complete */
  193. readl(&emif->emif_rd_wr_lvl_ctl);
  194. __udelay(130);
  195. /* Read data eye leveling no of samples */
  196. config_data_eye_leveling_samples(base);
  197. /*
  198. * Launch 8 incremental WR_LVL- to compensate for
  199. * PHY limitation.
  200. */
  201. writel(0x2 << EMIF_REG_WRLVLINC_INT_SHIFT,
  202. &emif->emif_rd_wr_lvl_ctl);
  203. __udelay(130);
  204. /* Launch Incremental leveling */
  205. writel(DDR3_INC_LVL, &emif->emif_rd_wr_lvl_ctl);
  206. __udelay(130);
  207. }
  208. static void update_hwleveling_output(u32 base, const struct emif_regs *regs)
  209. {
  210. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  211. u32 *emif_ext_phy_ctrl_reg, *emif_phy_status;
  212. u32 reg, i, phy;
  213. emif_phy_status = (u32 *)&emif->emif_ddr_phy_status[6];
  214. phy = readl(&emif->emif_ddr_phy_ctrl_1);
  215. /* Update PHY_REG_RDDQS_RATIO */
  216. emif_ext_phy_ctrl_reg = (u32 *)&emif->emif_ddr_ext_phy_ctrl_7;
  217. if (!(phy & EMIF_DDR_PHY_CTRL_1_RDLVL_MASK_MASK))
  218. for (i = 0; i < PHY_RDDQS_RATIO_REGS; i++) {
  219. reg = readl(emif_phy_status++);
  220. writel(reg, emif_ext_phy_ctrl_reg++);
  221. writel(reg, emif_ext_phy_ctrl_reg++);
  222. }
  223. /* Update PHY_REG_FIFO_WE_SLAVE_RATIO */
  224. emif_ext_phy_ctrl_reg = (u32 *)&emif->emif_ddr_ext_phy_ctrl_2;
  225. emif_phy_status = (u32 *)&emif->emif_ddr_phy_status[11];
  226. if (!(phy & EMIF_DDR_PHY_CTRL_1_RDLVLGATE_MASK_MASK))
  227. for (i = 0; i < PHY_FIFO_WE_SLAVE_RATIO_REGS; i++) {
  228. reg = readl(emif_phy_status++);
  229. writel(reg, emif_ext_phy_ctrl_reg++);
  230. writel(reg, emif_ext_phy_ctrl_reg++);
  231. }
  232. /* Update PHY_REG_WR_DQ/DQS_SLAVE_RATIO */
  233. emif_ext_phy_ctrl_reg = (u32 *)&emif->emif_ddr_ext_phy_ctrl_12;
  234. emif_phy_status = (u32 *)&emif->emif_ddr_phy_status[16];
  235. if (!(phy & EMIF_DDR_PHY_CTRL_1_WRLVL_MASK_MASK))
  236. for (i = 0; i < PHY_REG_WR_DQ_SLAVE_RATIO_REGS; i++) {
  237. reg = readl(emif_phy_status++);
  238. writel(reg, emif_ext_phy_ctrl_reg++);
  239. writel(reg, emif_ext_phy_ctrl_reg++);
  240. }
  241. /* Disable Leveling */
  242. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1);
  243. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1_shdw);
  244. writel(0x0, &emif->emif_rd_wr_lvl_rmp_ctl);
  245. }
  246. static void dra7_ddr3_leveling(u32 base, const struct emif_regs *regs)
  247. {
  248. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  249. /* Clear Error Status */
  250. clrsetbits_le32(&emif->emif_ddr_ext_phy_ctrl_36,
  251. EMIF_REG_PHY_FIFO_WE_IN_MISALINED_CLR,
  252. EMIF_REG_PHY_FIFO_WE_IN_MISALINED_CLR);
  253. clrsetbits_le32(&emif->emif_ddr_ext_phy_ctrl_36_shdw,
  254. EMIF_REG_PHY_FIFO_WE_IN_MISALINED_CLR,
  255. EMIF_REG_PHY_FIFO_WE_IN_MISALINED_CLR);
  256. /* Disable refreshed before leveling */
  257. clrsetbits_le32(&emif->emif_sdram_ref_ctrl, EMIF_REG_INITREF_DIS_MASK,
  258. EMIF_REG_INITREF_DIS_MASK);
  259. /* Start Full leveling */
  260. writel(DDR3_FULL_LVL, &emif->emif_rd_wr_lvl_ctl);
  261. __udelay(300);
  262. /* Check for leveling timeout */
  263. if (readl(&emif->emif_status) & EMIF_REG_LEVELING_TO_MASK) {
  264. printf("Leveling timeout on EMIF%d\n", emif_num(base));
  265. return;
  266. }
  267. /* Enable refreshes after leveling */
  268. clrbits_le32(&emif->emif_sdram_ref_ctrl, EMIF_REG_INITREF_DIS_MASK);
  269. debug("HW leveling success\n");
  270. /*
  271. * Update slave ratios in EXT_PHY_CTRLx registers
  272. * as per HW leveling output
  273. */
  274. update_hwleveling_output(base, regs);
  275. }
  276. static void dra7_reset_ddr_data(u32 base, u32 size)
  277. {
  278. #if defined(CONFIG_TI_EDMA3) && !defined(CONFIG_DMA)
  279. enable_edma3_clocks();
  280. edma3_fill(EDMA3_BASE, 1, (void *)base, 0, size);
  281. disable_edma3_clocks();
  282. #else
  283. memset((void *)base, 0, size);
  284. #endif
  285. }
  286. static void dra7_enable_ecc(u32 base, const struct emif_regs *regs)
  287. {
  288. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  289. u32 rgn, size;
  290. /* ECC available only on dra76x EMIF1 */
  291. if ((base != EMIF1_BASE) || !is_dra76x())
  292. return;
  293. if (regs->emif_ecc_ctrl_reg & EMIF_ECC_CTRL_REG_ECC_EN_MASK) {
  294. writel(regs->emif_ecc_address_range_1,
  295. &emif->emif_ecc_address_range_1);
  296. writel(regs->emif_ecc_address_range_2,
  297. &emif->emif_ecc_address_range_2);
  298. writel(regs->emif_ecc_ctrl_reg, &emif->emif_ecc_ctrl_reg);
  299. /* Set region1 memory with 0 */
  300. rgn = ((regs->emif_ecc_address_range_1 &
  301. EMIF_ECC_REG_ECC_START_ADDR_MASK) << 16) +
  302. CONFIG_SYS_SDRAM_BASE;
  303. size = (regs->emif_ecc_address_range_1 &
  304. EMIF_ECC_REG_ECC_END_ADDR_MASK) + 0x10000;
  305. if (regs->emif_ecc_ctrl_reg &
  306. EMIF_ECC_REG_ECC_ADDR_RGN_1_EN_MASK)
  307. dra7_reset_ddr_data(rgn, size);
  308. /* Set region2 memory with 0 */
  309. rgn = ((regs->emif_ecc_address_range_2 &
  310. EMIF_ECC_REG_ECC_START_ADDR_MASK) << 16) +
  311. CONFIG_SYS_SDRAM_BASE;
  312. size = (regs->emif_ecc_address_range_2 &
  313. EMIF_ECC_REG_ECC_END_ADDR_MASK) + 0x10000;
  314. if (regs->emif_ecc_ctrl_reg &
  315. EMIF_ECC_REG_ECC_ADDR_RGN_2_EN_MASK)
  316. dra7_reset_ddr_data(rgn, size);
  317. #ifdef CONFIG_DRA7XX
  318. /* Clear the status flags and other history */
  319. writel(readl(&emif->emif_1b_ecc_err_cnt),
  320. &emif->emif_1b_ecc_err_cnt);
  321. writel(0xffffffff, &emif->emif_1b_ecc_err_dist_1);
  322. writel(0x1, &emif->emif_2b_ecc_err_addr_log);
  323. writel(EMIF_INT_WR_ECC_ERR_SYS_MASK |
  324. EMIF_INT_TWOBIT_ECC_ERR_SYS_MASK |
  325. EMIF_INT_ONEBIT_ECC_ERR_SYS_MASK,
  326. &emif->emif_irqstatus_sys);
  327. #endif
  328. }
  329. }
  330. static void dra7_ddr3_init(u32 base, const struct emif_regs *regs)
  331. {
  332. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  333. if (warm_reset()) {
  334. emif_reset_phy(base);
  335. writel(0x0, &emif->emif_pwr_mgmt_ctrl);
  336. }
  337. do_ext_phy_settings(base, regs);
  338. writel(regs->ref_ctrl | EMIF_REG_INITREF_DIS_MASK,
  339. &emif->emif_sdram_ref_ctrl);
  340. /* Update timing registers */
  341. writel(regs->sdram_tim1, &emif->emif_sdram_tim_1);
  342. writel(regs->sdram_tim2, &emif->emif_sdram_tim_2);
  343. writel(regs->sdram_tim3, &emif->emif_sdram_tim_3);
  344. writel(EMIF_L3_CONFIG_VAL_SYS_10_MPU_5_LL_0, &emif->emif_l3_config);
  345. writel(regs->read_idle_ctrl, &emif->emif_read_idlectrl);
  346. writel(regs->zq_config, &emif->emif_zq_config);
  347. writel(regs->temp_alert_config, &emif->emif_temp_alert_config);
  348. writel(regs->emif_rd_wr_lvl_rmp_ctl, &emif->emif_rd_wr_lvl_rmp_ctl);
  349. writel(regs->emif_rd_wr_lvl_ctl, &emif->emif_rd_wr_lvl_ctl);
  350. writel(regs->emif_ddr_phy_ctlr_1_init, &emif->emif_ddr_phy_ctrl_1);
  351. writel(regs->emif_rd_wr_exec_thresh, &emif->emif_rd_wr_exec_thresh);
  352. writel(regs->ref_ctrl, &emif->emif_sdram_ref_ctrl);
  353. writel(regs->sdram_config2, &emif->emif_lpddr2_nvm_config);
  354. writel(regs->sdram_config_init, &emif->emif_sdram_config);
  355. __udelay(1000);
  356. writel(regs->ref_ctrl_final, &emif->emif_sdram_ref_ctrl);
  357. if (regs->emif_rd_wr_lvl_rmp_ctl & EMIF_REG_RDWRLVL_EN_MASK) {
  358. /*
  359. * Perform Dummy ECC setup just to allow hardware
  360. * leveling of ECC memories
  361. */
  362. if (is_dra76x() && (base == EMIF1_BASE) &&
  363. (regs->emif_ecc_ctrl_reg & EMIF_ECC_CTRL_REG_ECC_EN_MASK)) {
  364. writel(0, &emif->emif_ecc_address_range_1);
  365. writel(0, &emif->emif_ecc_address_range_2);
  366. writel(EMIF_ECC_CTRL_REG_ECC_EN_MASK |
  367. EMIF_ECC_CTRL_REG_ECC_ADDR_RGN_PROT_MASK,
  368. &emif->emif_ecc_ctrl_reg);
  369. }
  370. dra7_ddr3_leveling(base, regs);
  371. /* Disable ECC */
  372. if (is_dra76x())
  373. writel(0, &emif->emif_ecc_ctrl_reg);
  374. }
  375. /* Enable ECC as necessary */
  376. dra7_enable_ecc(base, regs);
  377. }
  378. static void omap5_ddr3_init(u32 base, const struct emif_regs *regs)
  379. {
  380. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  381. writel(regs->ref_ctrl, &emif->emif_sdram_ref_ctrl);
  382. writel(regs->sdram_config_init, &emif->emif_sdram_config);
  383. /*
  384. * Set SDRAM_CONFIG and PHY control registers to locked frequency
  385. * and RL =7. As the default values of the Mode Registers are not
  386. * defined, contents of mode Registers must be fully initialized.
  387. * H/W takes care of this initialization
  388. */
  389. writel(regs->emif_ddr_phy_ctlr_1_init, &emif->emif_ddr_phy_ctrl_1);
  390. /* Update timing registers */
  391. writel(regs->sdram_tim1, &emif->emif_sdram_tim_1);
  392. writel(regs->sdram_tim2, &emif->emif_sdram_tim_2);
  393. writel(regs->sdram_tim3, &emif->emif_sdram_tim_3);
  394. writel(regs->read_idle_ctrl, &emif->emif_read_idlectrl);
  395. writel(regs->sdram_config2, &emif->emif_lpddr2_nvm_config);
  396. writel(regs->sdram_config_init, &emif->emif_sdram_config);
  397. do_ext_phy_settings(base, regs);
  398. writel(regs->emif_rd_wr_lvl_rmp_ctl, &emif->emif_rd_wr_lvl_rmp_ctl);
  399. omap5_ddr3_leveling(base, regs);
  400. }
  401. static void ddr3_init(u32 base, const struct emif_regs *regs)
  402. {
  403. if (is_omap54xx())
  404. omap5_ddr3_init(base, regs);
  405. else
  406. dra7_ddr3_init(base, regs);
  407. }
  408. #endif
  409. #ifndef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  410. #define print_timing_reg(reg) debug(#reg" - 0x%08x\n", (reg))
  411. /*
  412. * Organization and refresh requirements for LPDDR2 devices of different
  413. * types and densities. Derived from JESD209-2 section 2.4
  414. */
  415. const struct lpddr2_addressing addressing_table[] = {
  416. /* Banks tREFIx10 rowx32,rowx16 colx32,colx16 density */
  417. {BANKS4, T_REFI_15_6, {ROW_12, ROW_12}, {COL_7, COL_8} },/*64M */
  418. {BANKS4, T_REFI_15_6, {ROW_12, ROW_12}, {COL_8, COL_9} },/*128M */
  419. {BANKS4, T_REFI_7_8, {ROW_13, ROW_13}, {COL_8, COL_9} },/*256M */
  420. {BANKS4, T_REFI_7_8, {ROW_13, ROW_13}, {COL_9, COL_10} },/*512M */
  421. {BANKS8, T_REFI_7_8, {ROW_13, ROW_13}, {COL_9, COL_10} },/*1GS4 */
  422. {BANKS8, T_REFI_3_9, {ROW_14, ROW_14}, {COL_9, COL_10} },/*2GS4 */
  423. {BANKS8, T_REFI_3_9, {ROW_14, ROW_14}, {COL_10, COL_11} },/*4G */
  424. {BANKS8, T_REFI_3_9, {ROW_15, ROW_15}, {COL_10, COL_11} },/*8G */
  425. {BANKS4, T_REFI_7_8, {ROW_14, ROW_14}, {COL_9, COL_10} },/*1GS2 */
  426. {BANKS4, T_REFI_3_9, {ROW_15, ROW_15}, {COL_9, COL_10} },/*2GS2 */
  427. };
  428. static const u32 lpddr2_density_2_size_in_mbytes[] = {
  429. 8, /* 64Mb */
  430. 16, /* 128Mb */
  431. 32, /* 256Mb */
  432. 64, /* 512Mb */
  433. 128, /* 1Gb */
  434. 256, /* 2Gb */
  435. 512, /* 4Gb */
  436. 1024, /* 8Gb */
  437. 2048, /* 16Gb */
  438. 4096 /* 32Gb */
  439. };
  440. /*
  441. * Calculate the period of DDR clock from frequency value and set the
  442. * denominator and numerator in global variables for easy access later
  443. */
  444. static void set_ddr_clk_period(u32 freq)
  445. {
  446. /*
  447. * period = 1/freq
  448. * period_in_ns = 10^9/freq
  449. */
  450. *T_num = 1000000000;
  451. *T_den = freq;
  452. cancel_out(T_num, T_den, 200);
  453. }
  454. /*
  455. * Convert time in nano seconds to number of cycles of DDR clock
  456. */
  457. static inline u32 ns_2_cycles(u32 ns)
  458. {
  459. return ((ns * (*T_den)) + (*T_num) - 1) / (*T_num);
  460. }
  461. /*
  462. * ns_2_cycles with the difference that the time passed is 2 times the actual
  463. * value(to avoid fractions). The cycles returned is for the original value of
  464. * the timing parameter
  465. */
  466. static inline u32 ns_x2_2_cycles(u32 ns)
  467. {
  468. return ((ns * (*T_den)) + (*T_num) * 2 - 1) / ((*T_num) * 2);
  469. }
  470. /*
  471. * Find addressing table index based on the device's type(S2 or S4) and
  472. * density
  473. */
  474. s8 addressing_table_index(u8 type, u8 density, u8 width)
  475. {
  476. u8 index;
  477. if ((density > LPDDR2_DENSITY_8Gb) || (width == LPDDR2_IO_WIDTH_8))
  478. return -1;
  479. /*
  480. * Look at the way ADDR_TABLE_INDEX* values have been defined
  481. * in emif.h compared to LPDDR2_DENSITY_* values
  482. * The table is layed out in the increasing order of density
  483. * (ignoring type). The exceptions 1GS2 and 2GS2 have been placed
  484. * at the end
  485. */
  486. if ((type == LPDDR2_TYPE_S2) && (density == LPDDR2_DENSITY_1Gb))
  487. index = ADDR_TABLE_INDEX1GS2;
  488. else if ((type == LPDDR2_TYPE_S2) && (density == LPDDR2_DENSITY_2Gb))
  489. index = ADDR_TABLE_INDEX2GS2;
  490. else
  491. index = density;
  492. debug("emif: addressing table index %d\n", index);
  493. return index;
  494. }
  495. /*
  496. * Find the the right timing table from the array of timing
  497. * tables of the device using DDR clock frequency
  498. */
  499. static const struct lpddr2_ac_timings *get_timings_table(const struct
  500. lpddr2_ac_timings const *const *device_timings,
  501. u32 freq)
  502. {
  503. u32 i, temp, freq_nearest;
  504. const struct lpddr2_ac_timings *timings = 0;
  505. emif_assert(freq <= MAX_LPDDR2_FREQ);
  506. emif_assert(device_timings);
  507. /*
  508. * Start with the maximum allowed frequency - that is always safe
  509. */
  510. freq_nearest = MAX_LPDDR2_FREQ;
  511. /*
  512. * Find the timings table that has the max frequency value:
  513. * i. Above or equal to the DDR frequency - safe
  514. * ii. The lowest that satisfies condition (i) - optimal
  515. */
  516. for (i = 0; (i < MAX_NUM_SPEEDBINS) && device_timings[i]; i++) {
  517. temp = device_timings[i]->max_freq;
  518. if ((temp >= freq) && (temp <= freq_nearest)) {
  519. freq_nearest = temp;
  520. timings = device_timings[i];
  521. }
  522. }
  523. debug("emif: timings table: %d\n", freq_nearest);
  524. return timings;
  525. }
  526. /*
  527. * Finds the value of emif_sdram_config_reg
  528. * All parameters are programmed based on the device on CS0.
  529. * If there is a device on CS1, it will be same as that on CS0 or
  530. * it will be NVM. We don't support NVM yet.
  531. * If cs1_device pointer is NULL it is assumed that there is no device
  532. * on CS1
  533. */
  534. static u32 get_sdram_config_reg(const struct lpddr2_device_details *cs0_device,
  535. const struct lpddr2_device_details *cs1_device,
  536. const struct lpddr2_addressing *addressing,
  537. u8 RL)
  538. {
  539. u32 config_reg = 0;
  540. config_reg |= (cs0_device->type + 4) << EMIF_REG_SDRAM_TYPE_SHIFT;
  541. config_reg |= EMIF_INTERLEAVING_POLICY_MAX_INTERLEAVING <<
  542. EMIF_REG_IBANK_POS_SHIFT;
  543. config_reg |= cs0_device->io_width << EMIF_REG_NARROW_MODE_SHIFT;
  544. config_reg |= RL << EMIF_REG_CL_SHIFT;
  545. config_reg |= addressing->row_sz[cs0_device->io_width] <<
  546. EMIF_REG_ROWSIZE_SHIFT;
  547. config_reg |= addressing->num_banks << EMIF_REG_IBANK_SHIFT;
  548. config_reg |= (cs1_device ? EBANK_CS1_EN : EBANK_CS1_DIS) <<
  549. EMIF_REG_EBANK_SHIFT;
  550. config_reg |= addressing->col_sz[cs0_device->io_width] <<
  551. EMIF_REG_PAGESIZE_SHIFT;
  552. return config_reg;
  553. }
  554. static u32 get_sdram_ref_ctrl(u32 freq,
  555. const struct lpddr2_addressing *addressing)
  556. {
  557. u32 ref_ctrl = 0, val = 0, freq_khz;
  558. freq_khz = freq / 1000;
  559. /*
  560. * refresh rate to be set is 'tREFI * freq in MHz
  561. * division by 10000 to account for khz and x10 in t_REFI_us_x10
  562. */
  563. val = addressing->t_REFI_us_x10 * freq_khz / 10000;
  564. ref_ctrl |= val << EMIF_REG_REFRESH_RATE_SHIFT;
  565. return ref_ctrl;
  566. }
  567. static u32 get_sdram_tim_1_reg(const struct lpddr2_ac_timings *timings,
  568. const struct lpddr2_min_tck *min_tck,
  569. const struct lpddr2_addressing *addressing)
  570. {
  571. u32 tim1 = 0, val = 0;
  572. val = max(min_tck->tWTR, ns_x2_2_cycles(timings->tWTRx2)) - 1;
  573. tim1 |= val << EMIF_REG_T_WTR_SHIFT;
  574. if (addressing->num_banks == BANKS8)
  575. val = (timings->tFAW * (*T_den) + 4 * (*T_num) - 1) /
  576. (4 * (*T_num)) - 1;
  577. else
  578. val = max(min_tck->tRRD, ns_2_cycles(timings->tRRD)) - 1;
  579. tim1 |= val << EMIF_REG_T_RRD_SHIFT;
  580. val = ns_2_cycles(timings->tRASmin + timings->tRPab) - 1;
  581. tim1 |= val << EMIF_REG_T_RC_SHIFT;
  582. val = max(min_tck->tRAS_MIN, ns_2_cycles(timings->tRASmin)) - 1;
  583. tim1 |= val << EMIF_REG_T_RAS_SHIFT;
  584. val = max(min_tck->tWR, ns_2_cycles(timings->tWR)) - 1;
  585. tim1 |= val << EMIF_REG_T_WR_SHIFT;
  586. val = max(min_tck->tRCD, ns_2_cycles(timings->tRCD)) - 1;
  587. tim1 |= val << EMIF_REG_T_RCD_SHIFT;
  588. val = max(min_tck->tRP_AB, ns_2_cycles(timings->tRPab)) - 1;
  589. tim1 |= val << EMIF_REG_T_RP_SHIFT;
  590. return tim1;
  591. }
  592. static u32 get_sdram_tim_2_reg(const struct lpddr2_ac_timings *timings,
  593. const struct lpddr2_min_tck *min_tck)
  594. {
  595. u32 tim2 = 0, val = 0;
  596. val = max(min_tck->tCKE, timings->tCKE) - 1;
  597. tim2 |= val << EMIF_REG_T_CKE_SHIFT;
  598. val = max(min_tck->tRTP, ns_x2_2_cycles(timings->tRTPx2)) - 1;
  599. tim2 |= val << EMIF_REG_T_RTP_SHIFT;
  600. /*
  601. * tXSRD = tRFCab + 10 ns. XSRD and XSNR should have the
  602. * same value
  603. */
  604. val = ns_2_cycles(timings->tXSR) - 1;
  605. tim2 |= val << EMIF_REG_T_XSRD_SHIFT;
  606. tim2 |= val << EMIF_REG_T_XSNR_SHIFT;
  607. val = max(min_tck->tXP, ns_x2_2_cycles(timings->tXPx2)) - 1;
  608. tim2 |= val << EMIF_REG_T_XP_SHIFT;
  609. return tim2;
  610. }
  611. static u32 get_sdram_tim_3_reg(const struct lpddr2_ac_timings *timings,
  612. const struct lpddr2_min_tck *min_tck,
  613. const struct lpddr2_addressing *addressing)
  614. {
  615. u32 tim3 = 0, val = 0;
  616. val = min(timings->tRASmax * 10 / addressing->t_REFI_us_x10 - 1, 0xF);
  617. tim3 |= val << EMIF_REG_T_RAS_MAX_SHIFT;
  618. val = ns_2_cycles(timings->tRFCab) - 1;
  619. tim3 |= val << EMIF_REG_T_RFC_SHIFT;
  620. val = ns_x2_2_cycles(timings->tDQSCKMAXx2) - 1;
  621. tim3 |= val << EMIF_REG_T_TDQSCKMAX_SHIFT;
  622. val = ns_2_cycles(timings->tZQCS) - 1;
  623. tim3 |= val << EMIF_REG_ZQ_ZQCS_SHIFT;
  624. val = max(min_tck->tCKESR, ns_2_cycles(timings->tCKESR)) - 1;
  625. tim3 |= val << EMIF_REG_T_CKESR_SHIFT;
  626. return tim3;
  627. }
  628. static u32 get_zq_config_reg(const struct lpddr2_device_details *cs1_device,
  629. const struct lpddr2_addressing *addressing,
  630. u8 volt_ramp)
  631. {
  632. u32 zq = 0, val = 0;
  633. if (volt_ramp)
  634. val =
  635. EMIF_ZQCS_INTERVAL_DVFS_IN_US * 10 /
  636. addressing->t_REFI_us_x10;
  637. else
  638. val =
  639. EMIF_ZQCS_INTERVAL_NORMAL_IN_US * 10 /
  640. addressing->t_REFI_us_x10;
  641. zq |= val << EMIF_REG_ZQ_REFINTERVAL_SHIFT;
  642. zq |= (REG_ZQ_ZQCL_MULT - 1) << EMIF_REG_ZQ_ZQCL_MULT_SHIFT;
  643. zq |= (REG_ZQ_ZQINIT_MULT - 1) << EMIF_REG_ZQ_ZQINIT_MULT_SHIFT;
  644. zq |= REG_ZQ_SFEXITEN_ENABLE << EMIF_REG_ZQ_SFEXITEN_SHIFT;
  645. /*
  646. * Assuming that two chipselects have a single calibration resistor
  647. * If there are indeed two calibration resistors, then this flag should
  648. * be enabled to take advantage of dual calibration feature.
  649. * This data should ideally come from board files. But considering
  650. * that none of the boards today have calibration resistors per CS,
  651. * it would be an unnecessary overhead.
  652. */
  653. zq |= REG_ZQ_DUALCALEN_DISABLE << EMIF_REG_ZQ_DUALCALEN_SHIFT;
  654. zq |= REG_ZQ_CS0EN_ENABLE << EMIF_REG_ZQ_CS0EN_SHIFT;
  655. zq |= (cs1_device ? 1 : 0) << EMIF_REG_ZQ_CS1EN_SHIFT;
  656. return zq;
  657. }
  658. static u32 get_temp_alert_config(const struct lpddr2_device_details *cs1_device,
  659. const struct lpddr2_addressing *addressing,
  660. u8 is_derated)
  661. {
  662. u32 alert = 0, interval;
  663. interval =
  664. TEMP_ALERT_POLL_INTERVAL_MS * 10000 / addressing->t_REFI_us_x10;
  665. if (is_derated)
  666. interval *= 4;
  667. alert |= interval << EMIF_REG_TA_REFINTERVAL_SHIFT;
  668. alert |= TEMP_ALERT_CONFIG_DEVCT_1 << EMIF_REG_TA_DEVCNT_SHIFT;
  669. alert |= TEMP_ALERT_CONFIG_DEVWDT_32 << EMIF_REG_TA_DEVWDT_SHIFT;
  670. alert |= 1 << EMIF_REG_TA_SFEXITEN_SHIFT;
  671. alert |= 1 << EMIF_REG_TA_CS0EN_SHIFT;
  672. alert |= (cs1_device ? 1 : 0) << EMIF_REG_TA_CS1EN_SHIFT;
  673. return alert;
  674. }
  675. static u32 get_read_idle_ctrl_reg(u8 volt_ramp)
  676. {
  677. u32 idle = 0, val = 0;
  678. if (volt_ramp)
  679. val = ns_2_cycles(READ_IDLE_INTERVAL_DVFS) / 64 - 1;
  680. else
  681. /*Maximum value in normal conditions - suggested by hw team */
  682. val = 0x1FF;
  683. idle |= val << EMIF_REG_READ_IDLE_INTERVAL_SHIFT;
  684. idle |= EMIF_REG_READ_IDLE_LEN_VAL << EMIF_REG_READ_IDLE_LEN_SHIFT;
  685. return idle;
  686. }
  687. static u32 get_ddr_phy_ctrl_1(u32 freq, u8 RL)
  688. {
  689. u32 phy = 0, val = 0;
  690. phy |= (RL + 2) << EMIF_REG_READ_LATENCY_SHIFT;
  691. if (freq <= 100000000)
  692. val = EMIF_DLL_SLAVE_DLY_CTRL_100_MHZ_AND_LESS;
  693. else if (freq <= 200000000)
  694. val = EMIF_DLL_SLAVE_DLY_CTRL_200_MHZ;
  695. else
  696. val = EMIF_DLL_SLAVE_DLY_CTRL_400_MHZ;
  697. phy |= val << EMIF_REG_DLL_SLAVE_DLY_CTRL_SHIFT;
  698. /* Other fields are constant magic values. Hardcode them together */
  699. phy |= EMIF_DDR_PHY_CTRL_1_BASE_VAL <<
  700. EMIF_EMIF_DDR_PHY_CTRL_1_BASE_VAL_SHIFT;
  701. return phy;
  702. }
  703. static u32 get_emif_mem_size(u32 base)
  704. {
  705. u32 size_mbytes = 0, temp;
  706. struct emif_device_details dev_details;
  707. struct lpddr2_device_details cs0_dev_details, cs1_dev_details;
  708. u32 emif_nr = emif_num(base);
  709. emif_reset_phy(base);
  710. dev_details.cs0_device_details = emif_get_device_details(emif_nr, CS0,
  711. &cs0_dev_details);
  712. dev_details.cs1_device_details = emif_get_device_details(emif_nr, CS1,
  713. &cs1_dev_details);
  714. emif_reset_phy(base);
  715. if (dev_details.cs0_device_details) {
  716. temp = dev_details.cs0_device_details->density;
  717. size_mbytes += lpddr2_density_2_size_in_mbytes[temp];
  718. }
  719. if (dev_details.cs1_device_details) {
  720. temp = dev_details.cs1_device_details->density;
  721. size_mbytes += lpddr2_density_2_size_in_mbytes[temp];
  722. }
  723. /* convert to bytes */
  724. return size_mbytes << 20;
  725. }
  726. /* Gets the encoding corresponding to a given DMM section size */
  727. u32 get_dmm_section_size_map(u32 section_size)
  728. {
  729. /*
  730. * Section size mapping:
  731. * 0x0: 16-MiB section
  732. * 0x1: 32-MiB section
  733. * 0x2: 64-MiB section
  734. * 0x3: 128-MiB section
  735. * 0x4: 256-MiB section
  736. * 0x5: 512-MiB section
  737. * 0x6: 1-GiB section
  738. * 0x7: 2-GiB section
  739. */
  740. section_size >>= 24; /* divide by 16 MB */
  741. return log_2_n_round_down(section_size);
  742. }
  743. static void emif_calculate_regs(
  744. const struct emif_device_details *emif_dev_details,
  745. u32 freq, struct emif_regs *regs)
  746. {
  747. u32 temp, sys_freq;
  748. const struct lpddr2_addressing *addressing;
  749. const struct lpddr2_ac_timings *timings;
  750. const struct lpddr2_min_tck *min_tck;
  751. const struct lpddr2_device_details *cs0_dev_details =
  752. emif_dev_details->cs0_device_details;
  753. const struct lpddr2_device_details *cs1_dev_details =
  754. emif_dev_details->cs1_device_details;
  755. const struct lpddr2_device_timings *cs0_dev_timings =
  756. emif_dev_details->cs0_device_timings;
  757. emif_assert(emif_dev_details);
  758. emif_assert(regs);
  759. /*
  760. * You can not have a device on CS1 without one on CS0
  761. * So configuring EMIF without a device on CS0 doesn't
  762. * make sense
  763. */
  764. emif_assert(cs0_dev_details);
  765. emif_assert(cs0_dev_details->type != LPDDR2_TYPE_NVM);
  766. /*
  767. * If there is a device on CS1 it should be same type as CS0
  768. * (or NVM. But NVM is not supported in this driver yet)
  769. */
  770. emif_assert((cs1_dev_details == NULL) ||
  771. (cs1_dev_details->type == LPDDR2_TYPE_NVM) ||
  772. (cs0_dev_details->type == cs1_dev_details->type));
  773. emif_assert(freq <= MAX_LPDDR2_FREQ);
  774. set_ddr_clk_period(freq);
  775. /*
  776. * The device on CS0 is used for all timing calculations
  777. * There is only one set of registers for timings per EMIF. So, if the
  778. * second CS(CS1) has a device, it should have the same timings as the
  779. * device on CS0
  780. */
  781. timings = get_timings_table(cs0_dev_timings->ac_timings, freq);
  782. emif_assert(timings);
  783. min_tck = cs0_dev_timings->min_tck;
  784. temp = addressing_table_index(cs0_dev_details->type,
  785. cs0_dev_details->density,
  786. cs0_dev_details->io_width);
  787. emif_assert((temp >= 0));
  788. addressing = &(addressing_table[temp]);
  789. emif_assert(addressing);
  790. sys_freq = get_sys_clk_freq();
  791. regs->sdram_config_init = get_sdram_config_reg(cs0_dev_details,
  792. cs1_dev_details,
  793. addressing, RL_BOOT);
  794. regs->sdram_config = get_sdram_config_reg(cs0_dev_details,
  795. cs1_dev_details,
  796. addressing, RL_FINAL);
  797. regs->ref_ctrl = get_sdram_ref_ctrl(freq, addressing);
  798. regs->sdram_tim1 = get_sdram_tim_1_reg(timings, min_tck, addressing);
  799. regs->sdram_tim2 = get_sdram_tim_2_reg(timings, min_tck);
  800. regs->sdram_tim3 = get_sdram_tim_3_reg(timings, min_tck, addressing);
  801. regs->read_idle_ctrl = get_read_idle_ctrl_reg(LPDDR2_VOLTAGE_STABLE);
  802. regs->temp_alert_config =
  803. get_temp_alert_config(cs1_dev_details, addressing, 0);
  804. regs->zq_config = get_zq_config_reg(cs1_dev_details, addressing,
  805. LPDDR2_VOLTAGE_STABLE);
  806. regs->emif_ddr_phy_ctlr_1_init =
  807. get_ddr_phy_ctrl_1(sys_freq / 2, RL_BOOT);
  808. regs->emif_ddr_phy_ctlr_1 =
  809. get_ddr_phy_ctrl_1(freq, RL_FINAL);
  810. regs->freq = freq;
  811. print_timing_reg(regs->sdram_config_init);
  812. print_timing_reg(regs->sdram_config);
  813. print_timing_reg(regs->ref_ctrl);
  814. print_timing_reg(regs->sdram_tim1);
  815. print_timing_reg(regs->sdram_tim2);
  816. print_timing_reg(regs->sdram_tim3);
  817. print_timing_reg(regs->read_idle_ctrl);
  818. print_timing_reg(regs->temp_alert_config);
  819. print_timing_reg(regs->zq_config);
  820. print_timing_reg(regs->emif_ddr_phy_ctlr_1);
  821. print_timing_reg(regs->emif_ddr_phy_ctlr_1_init);
  822. }
  823. #endif /* CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS */
  824. #ifdef CONFIG_SYS_AUTOMATIC_SDRAM_DETECTION
  825. const char *get_lpddr2_type(u8 type_id)
  826. {
  827. switch (type_id) {
  828. case LPDDR2_TYPE_S4:
  829. return "LPDDR2-S4";
  830. case LPDDR2_TYPE_S2:
  831. return "LPDDR2-S2";
  832. default:
  833. return NULL;
  834. }
  835. }
  836. const char *get_lpddr2_io_width(u8 width_id)
  837. {
  838. switch (width_id) {
  839. case LPDDR2_IO_WIDTH_8:
  840. return "x8";
  841. case LPDDR2_IO_WIDTH_16:
  842. return "x16";
  843. case LPDDR2_IO_WIDTH_32:
  844. return "x32";
  845. default:
  846. return NULL;
  847. }
  848. }
  849. const char *get_lpddr2_manufacturer(u32 manufacturer)
  850. {
  851. switch (manufacturer) {
  852. case LPDDR2_MANUFACTURER_SAMSUNG:
  853. return "Samsung";
  854. case LPDDR2_MANUFACTURER_QIMONDA:
  855. return "Qimonda";
  856. case LPDDR2_MANUFACTURER_ELPIDA:
  857. return "Elpida";
  858. case LPDDR2_MANUFACTURER_ETRON:
  859. return "Etron";
  860. case LPDDR2_MANUFACTURER_NANYA:
  861. return "Nanya";
  862. case LPDDR2_MANUFACTURER_HYNIX:
  863. return "Hynix";
  864. case LPDDR2_MANUFACTURER_MOSEL:
  865. return "Mosel";
  866. case LPDDR2_MANUFACTURER_WINBOND:
  867. return "Winbond";
  868. case LPDDR2_MANUFACTURER_ESMT:
  869. return "ESMT";
  870. case LPDDR2_MANUFACTURER_SPANSION:
  871. return "Spansion";
  872. case LPDDR2_MANUFACTURER_SST:
  873. return "SST";
  874. case LPDDR2_MANUFACTURER_ZMOS:
  875. return "ZMOS";
  876. case LPDDR2_MANUFACTURER_INTEL:
  877. return "Intel";
  878. case LPDDR2_MANUFACTURER_NUMONYX:
  879. return "Numonyx";
  880. case LPDDR2_MANUFACTURER_MICRON:
  881. return "Micron";
  882. default:
  883. return NULL;
  884. }
  885. }
  886. static void display_sdram_details(u32 emif_nr, u32 cs,
  887. struct lpddr2_device_details *device)
  888. {
  889. const char *mfg_str;
  890. const char *type_str;
  891. char density_str[10];
  892. u32 density;
  893. debug("EMIF%d CS%d\t", emif_nr, cs);
  894. if (!device) {
  895. debug("None\n");
  896. return;
  897. }
  898. mfg_str = get_lpddr2_manufacturer(device->manufacturer);
  899. type_str = get_lpddr2_type(device->type);
  900. density = lpddr2_density_2_size_in_mbytes[device->density];
  901. if ((density / 1024 * 1024) == density) {
  902. density /= 1024;
  903. sprintf(density_str, "%d GB", density);
  904. } else
  905. sprintf(density_str, "%d MB", density);
  906. if (mfg_str && type_str)
  907. debug("%s\t\t%s\t%s\n", mfg_str, type_str, density_str);
  908. }
  909. static u8 is_lpddr2_sdram_present(u32 base, u32 cs,
  910. struct lpddr2_device_details *lpddr2_device)
  911. {
  912. u32 mr = 0, temp;
  913. mr = get_mr(base, cs, LPDDR2_MR0);
  914. if (mr > 0xFF) {
  915. /* Mode register value bigger than 8 bit */
  916. return 0;
  917. }
  918. temp = (mr & LPDDR2_MR0_DI_MASK) >> LPDDR2_MR0_DI_SHIFT;
  919. if (temp) {
  920. /* Not SDRAM */
  921. return 0;
  922. }
  923. temp = (mr & LPDDR2_MR0_DNVI_MASK) >> LPDDR2_MR0_DNVI_SHIFT;
  924. if (temp) {
  925. /* DNV supported - But DNV is only supported for NVM */
  926. return 0;
  927. }
  928. mr = get_mr(base, cs, LPDDR2_MR4);
  929. if (mr > 0xFF) {
  930. /* Mode register value bigger than 8 bit */
  931. return 0;
  932. }
  933. mr = get_mr(base, cs, LPDDR2_MR5);
  934. if (mr > 0xFF) {
  935. /* Mode register value bigger than 8 bit */
  936. return 0;
  937. }
  938. if (!get_lpddr2_manufacturer(mr)) {
  939. /* Manufacturer not identified */
  940. return 0;
  941. }
  942. lpddr2_device->manufacturer = mr;
  943. mr = get_mr(base, cs, LPDDR2_MR6);
  944. if (mr >= 0xFF) {
  945. /* Mode register value bigger than 8 bit */
  946. return 0;
  947. }
  948. mr = get_mr(base, cs, LPDDR2_MR7);
  949. if (mr >= 0xFF) {
  950. /* Mode register value bigger than 8 bit */
  951. return 0;
  952. }
  953. mr = get_mr(base, cs, LPDDR2_MR8);
  954. if (mr >= 0xFF) {
  955. /* Mode register value bigger than 8 bit */
  956. return 0;
  957. }
  958. temp = (mr & MR8_TYPE_MASK) >> MR8_TYPE_SHIFT;
  959. if (!get_lpddr2_type(temp)) {
  960. /* Not SDRAM */
  961. return 0;
  962. }
  963. lpddr2_device->type = temp;
  964. temp = (mr & MR8_DENSITY_MASK) >> MR8_DENSITY_SHIFT;
  965. if (temp > LPDDR2_DENSITY_32Gb) {
  966. /* Density not supported */
  967. return 0;
  968. }
  969. lpddr2_device->density = temp;
  970. temp = (mr & MR8_IO_WIDTH_MASK) >> MR8_IO_WIDTH_SHIFT;
  971. if (!get_lpddr2_io_width(temp)) {
  972. /* IO width unsupported value */
  973. return 0;
  974. }
  975. lpddr2_device->io_width = temp;
  976. /*
  977. * If all the above tests pass we should
  978. * have a device on this chip-select
  979. */
  980. return 1;
  981. }
  982. struct lpddr2_device_details *emif_get_device_details(u32 emif_nr, u8 cs,
  983. struct lpddr2_device_details *lpddr2_dev_details)
  984. {
  985. u32 phy;
  986. u32 base = (emif_nr == 1) ? EMIF1_BASE : EMIF2_BASE;
  987. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  988. if (!lpddr2_dev_details)
  989. return NULL;
  990. /* Do the minimum init for mode register accesses */
  991. if (!(running_from_sdram() || warm_reset())) {
  992. phy = get_ddr_phy_ctrl_1(get_sys_clk_freq() / 2, RL_BOOT);
  993. writel(phy, &emif->emif_ddr_phy_ctrl_1);
  994. }
  995. if (!(is_lpddr2_sdram_present(base, cs, lpddr2_dev_details)))
  996. return NULL;
  997. display_sdram_details(emif_num(base), cs, lpddr2_dev_details);
  998. return lpddr2_dev_details;
  999. }
  1000. #endif /* CONFIG_SYS_AUTOMATIC_SDRAM_DETECTION */
  1001. static void do_sdram_init(u32 base)
  1002. {
  1003. const struct emif_regs *regs;
  1004. u32 in_sdram, emif_nr;
  1005. debug(">>do_sdram_init() %x\n", base);
  1006. in_sdram = running_from_sdram();
  1007. emif_nr = (base == EMIF1_BASE) ? 1 : 2;
  1008. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  1009. emif_get_reg_dump(emif_nr, &regs);
  1010. if (!regs) {
  1011. debug("EMIF: reg dump not provided\n");
  1012. return;
  1013. }
  1014. #else
  1015. /*
  1016. * The user has not provided the register values. We need to
  1017. * calculate it based on the timings and the DDR frequency
  1018. */
  1019. struct emif_device_details dev_details;
  1020. struct emif_regs calculated_regs;
  1021. /*
  1022. * Get device details:
  1023. * - Discovered if CONFIG_SYS_AUTOMATIC_SDRAM_DETECTION is set
  1024. * - Obtained from user otherwise
  1025. */
  1026. struct lpddr2_device_details cs0_dev_details, cs1_dev_details;
  1027. emif_reset_phy(base);
  1028. dev_details.cs0_device_details = emif_get_device_details(emif_nr, CS0,
  1029. &cs0_dev_details);
  1030. dev_details.cs1_device_details = emif_get_device_details(emif_nr, CS1,
  1031. &cs1_dev_details);
  1032. emif_reset_phy(base);
  1033. /* Return if no devices on this EMIF */
  1034. if (!dev_details.cs0_device_details &&
  1035. !dev_details.cs1_device_details) {
  1036. return;
  1037. }
  1038. /*
  1039. * Get device timings:
  1040. * - Default timings specified by JESD209-2 if
  1041. * CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS is set
  1042. * - Obtained from user otherwise
  1043. */
  1044. emif_get_device_timings(emif_nr, &dev_details.cs0_device_timings,
  1045. &dev_details.cs1_device_timings);
  1046. /* Calculate the register values */
  1047. emif_calculate_regs(&dev_details, omap_ddr_clk(), &calculated_regs);
  1048. regs = &calculated_regs;
  1049. #endif /* CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS */
  1050. /*
  1051. * Initializing the DDR device can not happen from SDRAM.
  1052. * Changing the timing registers in EMIF can happen(going from one
  1053. * OPP to another)
  1054. */
  1055. if (!in_sdram && (!warm_reset() || is_dra7xx())) {
  1056. if (emif_sdram_type(regs->sdram_config) ==
  1057. EMIF_SDRAM_TYPE_LPDDR2)
  1058. lpddr2_init(base, regs);
  1059. #ifndef CONFIG_OMAP44XX
  1060. else
  1061. ddr3_init(base, regs);
  1062. #endif
  1063. }
  1064. #ifdef CONFIG_OMAP54X
  1065. if (warm_reset() && (emif_sdram_type(regs->sdram_config) ==
  1066. EMIF_SDRAM_TYPE_DDR3) && !is_dra7xx()) {
  1067. set_lpmode_selfrefresh(base);
  1068. emif_reset_phy(base);
  1069. omap5_ddr3_leveling(base, regs);
  1070. }
  1071. #endif
  1072. /* Write to the shadow registers */
  1073. emif_update_timings(base, regs);
  1074. debug("<<do_sdram_init() %x\n", base);
  1075. }
  1076. void emif_post_init_config(u32 base)
  1077. {
  1078. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  1079. u32 omap_rev = omap_revision();
  1080. /* reset phy on ES2.0 */
  1081. if (omap_rev == OMAP4430_ES2_0)
  1082. emif_reset_phy(base);
  1083. /* Put EMIF back in smart idle on ES1.0 */
  1084. if (omap_rev == OMAP4430_ES1_0)
  1085. writel(0x80000000, &emif->emif_pwr_mgmt_ctrl);
  1086. }
  1087. void dmm_init(u32 base)
  1088. {
  1089. const struct dmm_lisa_map_regs *lisa_map_regs;
  1090. u32 i, section, valid;
  1091. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  1092. emif_get_dmm_regs(&lisa_map_regs);
  1093. #else
  1094. u32 emif1_size, emif2_size, mapped_size, section_map = 0;
  1095. u32 section_cnt, sys_addr;
  1096. struct dmm_lisa_map_regs lis_map_regs_calculated = {0};
  1097. mapped_size = 0;
  1098. section_cnt = 3;
  1099. sys_addr = CONFIG_SYS_SDRAM_BASE;
  1100. emif1_size = get_emif_mem_size(EMIF1_BASE);
  1101. emif2_size = get_emif_mem_size(EMIF2_BASE);
  1102. debug("emif1_size 0x%x emif2_size 0x%x\n", emif1_size, emif2_size);
  1103. if (!emif1_size && !emif2_size)
  1104. return;
  1105. /* symmetric interleaved section */
  1106. if (emif1_size && emif2_size) {
  1107. mapped_size = min(emif1_size, emif2_size);
  1108. section_map = DMM_LISA_MAP_INTERLEAVED_BASE_VAL;
  1109. section_map |= 0 << EMIF_SDRC_ADDR_SHIFT;
  1110. /* only MSB */
  1111. section_map |= (sys_addr >> 24) <<
  1112. EMIF_SYS_ADDR_SHIFT;
  1113. section_map |= get_dmm_section_size_map(mapped_size * 2)
  1114. << EMIF_SYS_SIZE_SHIFT;
  1115. lis_map_regs_calculated.dmm_lisa_map_3 = section_map;
  1116. emif1_size -= mapped_size;
  1117. emif2_size -= mapped_size;
  1118. sys_addr += (mapped_size * 2);
  1119. section_cnt--;
  1120. }
  1121. /*
  1122. * Single EMIF section(we can have a maximum of 1 single EMIF
  1123. * section- either EMIF1 or EMIF2 or none, but not both)
  1124. */
  1125. if (emif1_size) {
  1126. section_map = DMM_LISA_MAP_EMIF1_ONLY_BASE_VAL;
  1127. section_map |= get_dmm_section_size_map(emif1_size)
  1128. << EMIF_SYS_SIZE_SHIFT;
  1129. /* only MSB */
  1130. section_map |= (mapped_size >> 24) <<
  1131. EMIF_SDRC_ADDR_SHIFT;
  1132. /* only MSB */
  1133. section_map |= (sys_addr >> 24) << EMIF_SYS_ADDR_SHIFT;
  1134. section_cnt--;
  1135. }
  1136. if (emif2_size) {
  1137. section_map = DMM_LISA_MAP_EMIF2_ONLY_BASE_VAL;
  1138. section_map |= get_dmm_section_size_map(emif2_size) <<
  1139. EMIF_SYS_SIZE_SHIFT;
  1140. /* only MSB */
  1141. section_map |= mapped_size >> 24 << EMIF_SDRC_ADDR_SHIFT;
  1142. /* only MSB */
  1143. section_map |= sys_addr >> 24 << EMIF_SYS_ADDR_SHIFT;
  1144. section_cnt--;
  1145. }
  1146. if (section_cnt == 2) {
  1147. /* Only 1 section - either symmetric or single EMIF */
  1148. lis_map_regs_calculated.dmm_lisa_map_3 = section_map;
  1149. lis_map_regs_calculated.dmm_lisa_map_2 = 0;
  1150. lis_map_regs_calculated.dmm_lisa_map_1 = 0;
  1151. } else {
  1152. /* 2 sections - 1 symmetric, 1 single EMIF */
  1153. lis_map_regs_calculated.dmm_lisa_map_2 = section_map;
  1154. lis_map_regs_calculated.dmm_lisa_map_1 = 0;
  1155. }
  1156. /* TRAP for invalid TILER mappings in section 0 */
  1157. lis_map_regs_calculated.dmm_lisa_map_0 = DMM_LISA_MAP_0_INVAL_ADDR_TRAP;
  1158. if (omap_revision() >= OMAP4460_ES1_0)
  1159. lis_map_regs_calculated.is_ma_present = 1;
  1160. lisa_map_regs = &lis_map_regs_calculated;
  1161. #endif
  1162. struct dmm_lisa_map_regs *hw_lisa_map_regs =
  1163. (struct dmm_lisa_map_regs *)base;
  1164. writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
  1165. writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
  1166. writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
  1167. writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
  1168. writel(lisa_map_regs->dmm_lisa_map_3,
  1169. &hw_lisa_map_regs->dmm_lisa_map_3);
  1170. writel(lisa_map_regs->dmm_lisa_map_2,
  1171. &hw_lisa_map_regs->dmm_lisa_map_2);
  1172. writel(lisa_map_regs->dmm_lisa_map_1,
  1173. &hw_lisa_map_regs->dmm_lisa_map_1);
  1174. writel(lisa_map_regs->dmm_lisa_map_0,
  1175. &hw_lisa_map_regs->dmm_lisa_map_0);
  1176. if (lisa_map_regs->is_ma_present) {
  1177. hw_lisa_map_regs =
  1178. (struct dmm_lisa_map_regs *)MA_BASE;
  1179. writel(lisa_map_regs->dmm_lisa_map_3,
  1180. &hw_lisa_map_regs->dmm_lisa_map_3);
  1181. writel(lisa_map_regs->dmm_lisa_map_2,
  1182. &hw_lisa_map_regs->dmm_lisa_map_2);
  1183. writel(lisa_map_regs->dmm_lisa_map_1,
  1184. &hw_lisa_map_regs->dmm_lisa_map_1);
  1185. writel(lisa_map_regs->dmm_lisa_map_0,
  1186. &hw_lisa_map_regs->dmm_lisa_map_0);
  1187. setbits_le32(MA_PRIORITY, MA_HIMEM_INTERLEAVE_UN_MASK);
  1188. }
  1189. /*
  1190. * EMIF should be configured only when
  1191. * memory is mapped on it. Using emif1_enabled
  1192. * and emif2_enabled variables for this.
  1193. */
  1194. emif1_enabled = 0;
  1195. emif2_enabled = 0;
  1196. for (i = 0; i < 4; i++) {
  1197. section = __raw_readl(DMM_BASE + i*4);
  1198. valid = (section & EMIF_SDRC_MAP_MASK) >>
  1199. (EMIF_SDRC_MAP_SHIFT);
  1200. if (valid == 3) {
  1201. emif1_enabled = 1;
  1202. emif2_enabled = 1;
  1203. break;
  1204. }
  1205. if (valid == 1)
  1206. emif1_enabled = 1;
  1207. if (valid == 2)
  1208. emif2_enabled = 1;
  1209. }
  1210. }
  1211. static void do_bug0039_workaround(u32 base)
  1212. {
  1213. u32 val, i, clkctrl;
  1214. struct emif_reg_struct *emif_base = (struct emif_reg_struct *)base;
  1215. const struct read_write_regs *bug_00339_regs;
  1216. u32 iterations;
  1217. u32 *phy_status_base = &emif_base->emif_ddr_phy_status[0];
  1218. u32 *phy_ctrl_base = &emif_base->emif_ddr_ext_phy_ctrl_1;
  1219. if (is_dra7xx())
  1220. phy_status_base++;
  1221. bug_00339_regs = get_bug_regs(&iterations);
  1222. /* Put EMIF in to idle */
  1223. clkctrl = __raw_readl((*prcm)->cm_memif_clkstctrl);
  1224. __raw_writel(0x0, (*prcm)->cm_memif_clkstctrl);
  1225. /* Copy the phy status registers in to phy ctrl shadow registers */
  1226. for (i = 0; i < iterations; i++) {
  1227. val = __raw_readl(phy_status_base +
  1228. bug_00339_regs[i].read_reg - 1);
  1229. __raw_writel(val, phy_ctrl_base +
  1230. ((bug_00339_regs[i].write_reg - 1) << 1));
  1231. __raw_writel(val, phy_ctrl_base +
  1232. (bug_00339_regs[i].write_reg << 1) - 1);
  1233. }
  1234. /* Disable leveling */
  1235. writel(0x0, &emif_base->emif_rd_wr_lvl_rmp_ctl);
  1236. __raw_writel(clkctrl, (*prcm)->cm_memif_clkstctrl);
  1237. }
  1238. /*
  1239. * SDRAM initialization:
  1240. * SDRAM initialization has two parts:
  1241. * 1. Configuring the SDRAM device
  1242. * 2. Update the AC timings related parameters in the EMIF module
  1243. * (1) should be done only once and should not be done while we are
  1244. * running from SDRAM.
  1245. * (2) can and should be done more than once if OPP changes.
  1246. * Particularly, this may be needed when we boot without SPL and
  1247. * and using Configuration Header(CH). ROM code supports only at 50% OPP
  1248. * at boot (low power boot). So u-boot has to switch to OPP100 and update
  1249. * the frequency. So,
  1250. * Doing (1) and (2) makes sense - first time initialization
  1251. * Doing (2) and not (1) makes sense - OPP change (when using CH)
  1252. * Doing (1) and not (2) doen't make sense
  1253. * See do_sdram_init() for the details
  1254. */
  1255. void sdram_init(void)
  1256. {
  1257. u32 in_sdram, size_prog, size_detect;
  1258. struct emif_reg_struct *emif = (struct emif_reg_struct *)EMIF1_BASE;
  1259. u32 sdram_type = emif_sdram_type(emif->emif_sdram_config);
  1260. debug(">>sdram_init()\n");
  1261. if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
  1262. return;
  1263. in_sdram = running_from_sdram();
  1264. debug("in_sdram = %d\n", in_sdram);
  1265. if (!in_sdram) {
  1266. if ((sdram_type == EMIF_SDRAM_TYPE_LPDDR2) && !warm_reset())
  1267. bypass_dpll((*prcm)->cm_clkmode_dpll_core);
  1268. else if (sdram_type == EMIF_SDRAM_TYPE_DDR3)
  1269. writel(CM_DLL_CTRL_NO_OVERRIDE, (*prcm)->cm_dll_ctrl);
  1270. }
  1271. if (!in_sdram)
  1272. dmm_init(DMM_BASE);
  1273. if (emif1_enabled)
  1274. do_sdram_init(EMIF1_BASE);
  1275. if (emif2_enabled)
  1276. do_sdram_init(EMIF2_BASE);
  1277. if (!(in_sdram || warm_reset())) {
  1278. if (emif1_enabled)
  1279. emif_post_init_config(EMIF1_BASE);
  1280. if (emif2_enabled)
  1281. emif_post_init_config(EMIF2_BASE);
  1282. }
  1283. /* for the shadow registers to take effect */
  1284. if (sdram_type == EMIF_SDRAM_TYPE_LPDDR2)
  1285. freq_update_core();
  1286. /* Do some testing after the init */
  1287. if (!in_sdram) {
  1288. size_prog = omap_sdram_size();
  1289. size_prog = log_2_n_round_down(size_prog);
  1290. size_prog = (1 << size_prog);
  1291. size_detect = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
  1292. size_prog);
  1293. /* Compare with the size programmed */
  1294. if (size_detect != size_prog) {
  1295. printf("SDRAM: identified size not same as expected"
  1296. " size identified: %x expected: %x\n",
  1297. size_detect,
  1298. size_prog);
  1299. } else
  1300. debug("get_ram_size() successful");
  1301. }
  1302. #if defined(CONFIG_TI_SECURE_DEVICE)
  1303. /*
  1304. * On HS devices, do static EMIF firewall configuration
  1305. * but only do it if not already running in SDRAM
  1306. */
  1307. if (!in_sdram)
  1308. if (0 != secure_emif_reserve())
  1309. hang();
  1310. /* On HS devices, ensure static EMIF firewall APIs are locked */
  1311. if (0 != secure_emif_firewall_lock())
  1312. hang();
  1313. #endif
  1314. if (sdram_type == EMIF_SDRAM_TYPE_DDR3 &&
  1315. (!in_sdram && !warm_reset()) && (!is_dra7xx())) {
  1316. if (emif1_enabled)
  1317. do_bug0039_workaround(EMIF1_BASE);
  1318. if (emif2_enabled)
  1319. do_bug0039_workaround(EMIF2_BASE);
  1320. }
  1321. debug("<<sdram_init()\n");
  1322. }