emif-common.c 44 KB

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