emif-common.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. /*
  2. * EMIF programming
  3. *
  4. * (C) Copyright 2010
  5. * Texas Instruments, <www.ti.com>
  6. *
  7. * Aneesh V <aneesh@ti.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/emif.h>
  29. #include <asm/arch/clocks.h>
  30. #include <asm/arch/sys_proto.h>
  31. #include <asm/omap_common.h>
  32. #include <asm/utils.h>
  33. inline u32 emif_num(u32 base)
  34. {
  35. if (base == EMIF1_BASE)
  36. return 1;
  37. else if (base == EMIF2_BASE)
  38. return 2;
  39. else
  40. return 0;
  41. }
  42. static inline u32 get_mr(u32 base, u32 cs, u32 mr_addr)
  43. {
  44. u32 mr;
  45. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  46. mr_addr |= cs << EMIF_REG_CS_SHIFT;
  47. writel(mr_addr, &emif->emif_lpddr2_mode_reg_cfg);
  48. if (omap_revision() == OMAP4430_ES2_0)
  49. mr = readl(&emif->emif_lpddr2_mode_reg_data_es2);
  50. else
  51. mr = readl(&emif->emif_lpddr2_mode_reg_data);
  52. debug("get_mr: EMIF%d cs %d mr %08x val 0x%x\n", emif_num(base),
  53. cs, mr_addr, mr);
  54. return mr;
  55. }
  56. static inline void set_mr(u32 base, u32 cs, u32 mr_addr, u32 mr_val)
  57. {
  58. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  59. mr_addr |= cs << EMIF_REG_CS_SHIFT;
  60. writel(mr_addr, &emif->emif_lpddr2_mode_reg_cfg);
  61. writel(mr_val, &emif->emif_lpddr2_mode_reg_data);
  62. }
  63. void emif_reset_phy(u32 base)
  64. {
  65. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  66. u32 iodft;
  67. iodft = readl(&emif->emif_iodft_tlgc);
  68. iodft |= EMIF_REG_RESET_PHY_MASK;
  69. writel(iodft, &emif->emif_iodft_tlgc);
  70. }
  71. static void do_lpddr2_init(u32 base, u32 cs)
  72. {
  73. u32 mr_addr;
  74. /* Wait till device auto initialization is complete */
  75. while (get_mr(base, cs, LPDDR2_MR0) & LPDDR2_MR0_DAI_MASK)
  76. ;
  77. set_mr(base, cs, LPDDR2_MR10, MR10_ZQ_ZQINIT);
  78. /*
  79. * tZQINIT = 1 us
  80. * Enough loops assuming a maximum of 2GHz
  81. */
  82. sdelay(2000);
  83. if (omap_revision() >= OMAP5430_ES1_0)
  84. set_mr(base, cs, LPDDR2_MR1, MR1_BL_8_BT_SEQ_WRAP_EN_NWR_8);
  85. else
  86. set_mr(base, cs, LPDDR2_MR1, MR1_BL_8_BT_SEQ_WRAP_EN_NWR_3);
  87. set_mr(base, cs, LPDDR2_MR16, MR16_REF_FULL_ARRAY);
  88. /*
  89. * Enable refresh along with writing MR2
  90. * Encoding of RL in MR2 is (RL - 2)
  91. */
  92. mr_addr = LPDDR2_MR2 | EMIF_REG_REFRESH_EN_MASK;
  93. set_mr(base, cs, mr_addr, RL_FINAL - 2);
  94. if (omap_revision() >= OMAP5430_ES1_0)
  95. set_mr(base, cs, LPDDR2_MR3, 0x1);
  96. }
  97. static void lpddr2_init(u32 base, const struct emif_regs *regs)
  98. {
  99. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  100. u32 *ext_phy_ctrl_base = 0;
  101. u32 *emif_ext_phy_ctrl_base = 0;
  102. u32 i = 0;
  103. /* Not NVM */
  104. clrbits_le32(&emif->emif_lpddr2_nvm_config, EMIF_REG_CS1NVMEN_MASK);
  105. /*
  106. * Keep REG_INITREF_DIS = 1 to prevent re-initialization of SDRAM
  107. * when EMIF_SDRAM_CONFIG register is written
  108. */
  109. setbits_le32(&emif->emif_sdram_ref_ctrl, EMIF_REG_INITREF_DIS_MASK);
  110. /*
  111. * Set the SDRAM_CONFIG and PHY_CTRL for the
  112. * un-locked frequency & default RL
  113. */
  114. writel(regs->sdram_config_init, &emif->emif_sdram_config);
  115. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1);
  116. ext_phy_ctrl_base = (u32 *) &(regs->emif_ddr_ext_phy_ctrl_1);
  117. emif_ext_phy_ctrl_base = (u32 *) &(emif->emif_ddr_ext_phy_ctrl_1);
  118. if (omap_revision() >= OMAP5430_ES1_0) {
  119. /* Configure external phy control timing registers */
  120. for (i = 0; i < EMIF_EXT_PHY_CTRL_TIMING_REG; i++) {
  121. writel(*ext_phy_ctrl_base, emif_ext_phy_ctrl_base++);
  122. /* Update shadow registers */
  123. writel(*ext_phy_ctrl_base++, emif_ext_phy_ctrl_base++);
  124. }
  125. /*
  126. * external phy 6-24 registers do not change with
  127. * ddr frequency
  128. */
  129. for (i = 0; i < EMIF_EXT_PHY_CTRL_CONST_REG; i++) {
  130. writel(ext_phy_ctrl_const_base[i],
  131. emif_ext_phy_ctrl_base++);
  132. /* Update shadow registers */
  133. writel(ext_phy_ctrl_const_base[i],
  134. emif_ext_phy_ctrl_base++);
  135. }
  136. }
  137. do_lpddr2_init(base, CS0);
  138. if (regs->sdram_config & EMIF_REG_EBANK_MASK)
  139. do_lpddr2_init(base, CS1);
  140. writel(regs->sdram_config, &emif->emif_sdram_config);
  141. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1);
  142. /* Enable refresh now */
  143. clrbits_le32(&emif->emif_sdram_ref_ctrl, EMIF_REG_INITREF_DIS_MASK);
  144. }
  145. void emif_update_timings(u32 base, const struct emif_regs *regs)
  146. {
  147. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  148. writel(regs->ref_ctrl, &emif->emif_sdram_ref_ctrl_shdw);
  149. writel(regs->sdram_tim1, &emif->emif_sdram_tim_1_shdw);
  150. writel(regs->sdram_tim2, &emif->emif_sdram_tim_2_shdw);
  151. writel(regs->sdram_tim3, &emif->emif_sdram_tim_3_shdw);
  152. if (omap_revision() == OMAP4430_ES1_0) {
  153. /* ES1 bug EMIF should be in force idle during freq_update */
  154. writel(0, &emif->emif_pwr_mgmt_ctrl);
  155. } else {
  156. writel(EMIF_PWR_MGMT_CTRL, &emif->emif_pwr_mgmt_ctrl);
  157. writel(EMIF_PWR_MGMT_CTRL_SHDW, &emif->emif_pwr_mgmt_ctrl_shdw);
  158. }
  159. writel(regs->read_idle_ctrl, &emif->emif_read_idlectrl_shdw);
  160. writel(regs->zq_config, &emif->emif_zq_config);
  161. writel(regs->temp_alert_config, &emif->emif_temp_alert_config);
  162. writel(regs->emif_ddr_phy_ctlr_1, &emif->emif_ddr_phy_ctrl_1_shdw);
  163. if (omap_revision() == OMAP5430_ES1_0) {
  164. writel(EMIF_L3_CONFIG_VAL_SYS_10_MPU_5_LL_0,
  165. &emif->emif_l3_config);
  166. } else if (omap_revision() >= OMAP4460_ES1_0) {
  167. writel(EMIF_L3_CONFIG_VAL_SYS_10_MPU_3_LL_0,
  168. &emif->emif_l3_config);
  169. } else {
  170. writel(EMIF_L3_CONFIG_VAL_SYS_10_LL_0,
  171. &emif->emif_l3_config);
  172. }
  173. }
  174. #ifndef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  175. #define print_timing_reg(reg) debug(#reg" - 0x%08x\n", (reg))
  176. /*
  177. * Organization and refresh requirements for LPDDR2 devices of different
  178. * types and densities. Derived from JESD209-2 section 2.4
  179. */
  180. const struct lpddr2_addressing addressing_table[] = {
  181. /* Banks tREFIx10 rowx32,rowx16 colx32,colx16 density */
  182. {BANKS4, T_REFI_15_6, {ROW_12, ROW_12}, {COL_7, COL_8} },/*64M */
  183. {BANKS4, T_REFI_15_6, {ROW_12, ROW_12}, {COL_8, COL_9} },/*128M */
  184. {BANKS4, T_REFI_7_8, {ROW_13, ROW_13}, {COL_8, COL_9} },/*256M */
  185. {BANKS4, T_REFI_7_8, {ROW_13, ROW_13}, {COL_9, COL_10} },/*512M */
  186. {BANKS8, T_REFI_7_8, {ROW_13, ROW_13}, {COL_9, COL_10} },/*1GS4 */
  187. {BANKS8, T_REFI_3_9, {ROW_14, ROW_14}, {COL_9, COL_10} },/*2GS4 */
  188. {BANKS8, T_REFI_3_9, {ROW_14, ROW_14}, {COL_10, COL_11} },/*4G */
  189. {BANKS8, T_REFI_3_9, {ROW_15, ROW_15}, {COL_10, COL_11} },/*8G */
  190. {BANKS4, T_REFI_7_8, {ROW_14, ROW_14}, {COL_9, COL_10} },/*1GS2 */
  191. {BANKS4, T_REFI_3_9, {ROW_15, ROW_15}, {COL_9, COL_10} },/*2GS2 */
  192. };
  193. static const u32 lpddr2_density_2_size_in_mbytes[] = {
  194. 8, /* 64Mb */
  195. 16, /* 128Mb */
  196. 32, /* 256Mb */
  197. 64, /* 512Mb */
  198. 128, /* 1Gb */
  199. 256, /* 2Gb */
  200. 512, /* 4Gb */
  201. 1024, /* 8Gb */
  202. 2048, /* 16Gb */
  203. 4096 /* 32Gb */
  204. };
  205. /*
  206. * Calculate the period of DDR clock from frequency value and set the
  207. * denominator and numerator in global variables for easy access later
  208. */
  209. static void set_ddr_clk_period(u32 freq)
  210. {
  211. /*
  212. * period = 1/freq
  213. * period_in_ns = 10^9/freq
  214. */
  215. *T_num = 1000000000;
  216. *T_den = freq;
  217. cancel_out(T_num, T_den, 200);
  218. }
  219. /*
  220. * Convert time in nano seconds to number of cycles of DDR clock
  221. */
  222. static inline u32 ns_2_cycles(u32 ns)
  223. {
  224. return ((ns * (*T_den)) + (*T_num) - 1) / (*T_num);
  225. }
  226. /*
  227. * ns_2_cycles with the difference that the time passed is 2 times the actual
  228. * value(to avoid fractions). The cycles returned is for the original value of
  229. * the timing parameter
  230. */
  231. static inline u32 ns_x2_2_cycles(u32 ns)
  232. {
  233. return ((ns * (*T_den)) + (*T_num) * 2 - 1) / ((*T_num) * 2);
  234. }
  235. /*
  236. * Find addressing table index based on the device's type(S2 or S4) and
  237. * density
  238. */
  239. s8 addressing_table_index(u8 type, u8 density, u8 width)
  240. {
  241. u8 index;
  242. if ((density > LPDDR2_DENSITY_8Gb) || (width == LPDDR2_IO_WIDTH_8))
  243. return -1;
  244. /*
  245. * Look at the way ADDR_TABLE_INDEX* values have been defined
  246. * in emif.h compared to LPDDR2_DENSITY_* values
  247. * The table is layed out in the increasing order of density
  248. * (ignoring type). The exceptions 1GS2 and 2GS2 have been placed
  249. * at the end
  250. */
  251. if ((type == LPDDR2_TYPE_S2) && (density == LPDDR2_DENSITY_1Gb))
  252. index = ADDR_TABLE_INDEX1GS2;
  253. else if ((type == LPDDR2_TYPE_S2) && (density == LPDDR2_DENSITY_2Gb))
  254. index = ADDR_TABLE_INDEX2GS2;
  255. else
  256. index = density;
  257. debug("emif: addressing table index %d\n", index);
  258. return index;
  259. }
  260. /*
  261. * Find the the right timing table from the array of timing
  262. * tables of the device using DDR clock frequency
  263. */
  264. static const struct lpddr2_ac_timings *get_timings_table(const struct
  265. lpddr2_ac_timings const *const *device_timings,
  266. u32 freq)
  267. {
  268. u32 i, temp, freq_nearest;
  269. const struct lpddr2_ac_timings *timings = 0;
  270. emif_assert(freq <= MAX_LPDDR2_FREQ);
  271. emif_assert(device_timings);
  272. /*
  273. * Start with the maximum allowed frequency - that is always safe
  274. */
  275. freq_nearest = MAX_LPDDR2_FREQ;
  276. /*
  277. * Find the timings table that has the max frequency value:
  278. * i. Above or equal to the DDR frequency - safe
  279. * ii. The lowest that satisfies condition (i) - optimal
  280. */
  281. for (i = 0; (i < MAX_NUM_SPEEDBINS) && device_timings[i]; i++) {
  282. temp = device_timings[i]->max_freq;
  283. if ((temp >= freq) && (temp <= freq_nearest)) {
  284. freq_nearest = temp;
  285. timings = device_timings[i];
  286. }
  287. }
  288. debug("emif: timings table: %d\n", freq_nearest);
  289. return timings;
  290. }
  291. /*
  292. * Finds the value of emif_sdram_config_reg
  293. * All parameters are programmed based on the device on CS0.
  294. * If there is a device on CS1, it will be same as that on CS0 or
  295. * it will be NVM. We don't support NVM yet.
  296. * If cs1_device pointer is NULL it is assumed that there is no device
  297. * on CS1
  298. */
  299. static u32 get_sdram_config_reg(const struct lpddr2_device_details *cs0_device,
  300. const struct lpddr2_device_details *cs1_device,
  301. const struct lpddr2_addressing *addressing,
  302. u8 RL)
  303. {
  304. u32 config_reg = 0;
  305. config_reg |= (cs0_device->type + 4) << EMIF_REG_SDRAM_TYPE_SHIFT;
  306. config_reg |= EMIF_INTERLEAVING_POLICY_MAX_INTERLEAVING <<
  307. EMIF_REG_IBANK_POS_SHIFT;
  308. config_reg |= cs0_device->io_width << EMIF_REG_NARROW_MODE_SHIFT;
  309. config_reg |= RL << EMIF_REG_CL_SHIFT;
  310. config_reg |= addressing->row_sz[cs0_device->io_width] <<
  311. EMIF_REG_ROWSIZE_SHIFT;
  312. config_reg |= addressing->num_banks << EMIF_REG_IBANK_SHIFT;
  313. config_reg |= (cs1_device ? EBANK_CS1_EN : EBANK_CS1_DIS) <<
  314. EMIF_REG_EBANK_SHIFT;
  315. config_reg |= addressing->col_sz[cs0_device->io_width] <<
  316. EMIF_REG_PAGESIZE_SHIFT;
  317. return config_reg;
  318. }
  319. static u32 get_sdram_ref_ctrl(u32 freq,
  320. const struct lpddr2_addressing *addressing)
  321. {
  322. u32 ref_ctrl = 0, val = 0, freq_khz;
  323. freq_khz = freq / 1000;
  324. /*
  325. * refresh rate to be set is 'tREFI * freq in MHz
  326. * division by 10000 to account for khz and x10 in t_REFI_us_x10
  327. */
  328. val = addressing->t_REFI_us_x10 * freq_khz / 10000;
  329. ref_ctrl |= val << EMIF_REG_REFRESH_RATE_SHIFT;
  330. return ref_ctrl;
  331. }
  332. static u32 get_sdram_tim_1_reg(const struct lpddr2_ac_timings *timings,
  333. const struct lpddr2_min_tck *min_tck,
  334. const struct lpddr2_addressing *addressing)
  335. {
  336. u32 tim1 = 0, val = 0;
  337. val = max(min_tck->tWTR, ns_x2_2_cycles(timings->tWTRx2)) - 1;
  338. tim1 |= val << EMIF_REG_T_WTR_SHIFT;
  339. if (addressing->num_banks == BANKS8)
  340. val = (timings->tFAW * (*T_den) + 4 * (*T_num) - 1) /
  341. (4 * (*T_num)) - 1;
  342. else
  343. val = max(min_tck->tRRD, ns_2_cycles(timings->tRRD)) - 1;
  344. tim1 |= val << EMIF_REG_T_RRD_SHIFT;
  345. val = ns_2_cycles(timings->tRASmin + timings->tRPab) - 1;
  346. tim1 |= val << EMIF_REG_T_RC_SHIFT;
  347. val = max(min_tck->tRAS_MIN, ns_2_cycles(timings->tRASmin)) - 1;
  348. tim1 |= val << EMIF_REG_T_RAS_SHIFT;
  349. val = max(min_tck->tWR, ns_2_cycles(timings->tWR)) - 1;
  350. tim1 |= val << EMIF_REG_T_WR_SHIFT;
  351. val = max(min_tck->tRCD, ns_2_cycles(timings->tRCD)) - 1;
  352. tim1 |= val << EMIF_REG_T_RCD_SHIFT;
  353. val = max(min_tck->tRP_AB, ns_2_cycles(timings->tRPab)) - 1;
  354. tim1 |= val << EMIF_REG_T_RP_SHIFT;
  355. return tim1;
  356. }
  357. static u32 get_sdram_tim_2_reg(const struct lpddr2_ac_timings *timings,
  358. const struct lpddr2_min_tck *min_tck)
  359. {
  360. u32 tim2 = 0, val = 0;
  361. val = max(min_tck->tCKE, timings->tCKE) - 1;
  362. tim2 |= val << EMIF_REG_T_CKE_SHIFT;
  363. val = max(min_tck->tRTP, ns_x2_2_cycles(timings->tRTPx2)) - 1;
  364. tim2 |= val << EMIF_REG_T_RTP_SHIFT;
  365. /*
  366. * tXSRD = tRFCab + 10 ns. XSRD and XSNR should have the
  367. * same value
  368. */
  369. val = ns_2_cycles(timings->tXSR) - 1;
  370. tim2 |= val << EMIF_REG_T_XSRD_SHIFT;
  371. tim2 |= val << EMIF_REG_T_XSNR_SHIFT;
  372. val = max(min_tck->tXP, ns_x2_2_cycles(timings->tXPx2)) - 1;
  373. tim2 |= val << EMIF_REG_T_XP_SHIFT;
  374. return tim2;
  375. }
  376. static u32 get_sdram_tim_3_reg(const struct lpddr2_ac_timings *timings,
  377. const struct lpddr2_min_tck *min_tck,
  378. const struct lpddr2_addressing *addressing)
  379. {
  380. u32 tim3 = 0, val = 0;
  381. val = min(timings->tRASmax * 10 / addressing->t_REFI_us_x10 - 1, 0xF);
  382. tim3 |= val << EMIF_REG_T_RAS_MAX_SHIFT;
  383. val = ns_2_cycles(timings->tRFCab) - 1;
  384. tim3 |= val << EMIF_REG_T_RFC_SHIFT;
  385. val = ns_x2_2_cycles(timings->tDQSCKMAXx2) - 1;
  386. tim3 |= val << EMIF_REG_T_TDQSCKMAX_SHIFT;
  387. val = ns_2_cycles(timings->tZQCS) - 1;
  388. tim3 |= val << EMIF_REG_ZQ_ZQCS_SHIFT;
  389. val = max(min_tck->tCKESR, ns_2_cycles(timings->tCKESR)) - 1;
  390. tim3 |= val << EMIF_REG_T_CKESR_SHIFT;
  391. return tim3;
  392. }
  393. static u32 get_zq_config_reg(const struct lpddr2_device_details *cs1_device,
  394. const struct lpddr2_addressing *addressing,
  395. u8 volt_ramp)
  396. {
  397. u32 zq = 0, val = 0;
  398. if (volt_ramp)
  399. val =
  400. EMIF_ZQCS_INTERVAL_DVFS_IN_US * 10 /
  401. addressing->t_REFI_us_x10;
  402. else
  403. val =
  404. EMIF_ZQCS_INTERVAL_NORMAL_IN_US * 10 /
  405. addressing->t_REFI_us_x10;
  406. zq |= val << EMIF_REG_ZQ_REFINTERVAL_SHIFT;
  407. zq |= (REG_ZQ_ZQCL_MULT - 1) << EMIF_REG_ZQ_ZQCL_MULT_SHIFT;
  408. zq |= (REG_ZQ_ZQINIT_MULT - 1) << EMIF_REG_ZQ_ZQINIT_MULT_SHIFT;
  409. zq |= REG_ZQ_SFEXITEN_ENABLE << EMIF_REG_ZQ_SFEXITEN_SHIFT;
  410. /*
  411. * Assuming that two chipselects have a single calibration resistor
  412. * If there are indeed two calibration resistors, then this flag should
  413. * be enabled to take advantage of dual calibration feature.
  414. * This data should ideally come from board files. But considering
  415. * that none of the boards today have calibration resistors per CS,
  416. * it would be an unnecessary overhead.
  417. */
  418. zq |= REG_ZQ_DUALCALEN_DISABLE << EMIF_REG_ZQ_DUALCALEN_SHIFT;
  419. zq |= REG_ZQ_CS0EN_ENABLE << EMIF_REG_ZQ_CS0EN_SHIFT;
  420. zq |= (cs1_device ? 1 : 0) << EMIF_REG_ZQ_CS1EN_SHIFT;
  421. return zq;
  422. }
  423. static u32 get_temp_alert_config(const struct lpddr2_device_details *cs1_device,
  424. const struct lpddr2_addressing *addressing,
  425. u8 is_derated)
  426. {
  427. u32 alert = 0, interval;
  428. interval =
  429. TEMP_ALERT_POLL_INTERVAL_MS * 10000 / addressing->t_REFI_us_x10;
  430. if (is_derated)
  431. interval *= 4;
  432. alert |= interval << EMIF_REG_TA_REFINTERVAL_SHIFT;
  433. alert |= TEMP_ALERT_CONFIG_DEVCT_1 << EMIF_REG_TA_DEVCNT_SHIFT;
  434. alert |= TEMP_ALERT_CONFIG_DEVWDT_32 << EMIF_REG_TA_DEVWDT_SHIFT;
  435. alert |= 1 << EMIF_REG_TA_SFEXITEN_SHIFT;
  436. alert |= 1 << EMIF_REG_TA_CS0EN_SHIFT;
  437. alert |= (cs1_device ? 1 : 0) << EMIF_REG_TA_CS1EN_SHIFT;
  438. return alert;
  439. }
  440. static u32 get_read_idle_ctrl_reg(u8 volt_ramp)
  441. {
  442. u32 idle = 0, val = 0;
  443. if (volt_ramp)
  444. val = ns_2_cycles(READ_IDLE_INTERVAL_DVFS) / 64 - 1;
  445. else
  446. /*Maximum value in normal conditions - suggested by hw team */
  447. val = 0x1FF;
  448. idle |= val << EMIF_REG_READ_IDLE_INTERVAL_SHIFT;
  449. idle |= EMIF_REG_READ_IDLE_LEN_VAL << EMIF_REG_READ_IDLE_LEN_SHIFT;
  450. return idle;
  451. }
  452. static u32 get_ddr_phy_ctrl_1(u32 freq, u8 RL)
  453. {
  454. u32 phy = 0, val = 0;
  455. phy |= (RL + 2) << EMIF_REG_READ_LATENCY_SHIFT;
  456. if (freq <= 100000000)
  457. val = EMIF_DLL_SLAVE_DLY_CTRL_100_MHZ_AND_LESS;
  458. else if (freq <= 200000000)
  459. val = EMIF_DLL_SLAVE_DLY_CTRL_200_MHZ;
  460. else
  461. val = EMIF_DLL_SLAVE_DLY_CTRL_400_MHZ;
  462. phy |= val << EMIF_REG_DLL_SLAVE_DLY_CTRL_SHIFT;
  463. /* Other fields are constant magic values. Hardcode them together */
  464. phy |= EMIF_DDR_PHY_CTRL_1_BASE_VAL <<
  465. EMIF_EMIF_DDR_PHY_CTRL_1_BASE_VAL_SHIFT;
  466. return phy;
  467. }
  468. static u32 get_emif_mem_size(struct emif_device_details *devices)
  469. {
  470. u32 size_mbytes = 0, temp;
  471. if (!devices)
  472. return 0;
  473. if (devices->cs0_device_details) {
  474. temp = devices->cs0_device_details->density;
  475. size_mbytes += lpddr2_density_2_size_in_mbytes[temp];
  476. }
  477. if (devices->cs1_device_details) {
  478. temp = devices->cs1_device_details->density;
  479. size_mbytes += lpddr2_density_2_size_in_mbytes[temp];
  480. }
  481. /* convert to bytes */
  482. return size_mbytes << 20;
  483. }
  484. /* Gets the encoding corresponding to a given DMM section size */
  485. u32 get_dmm_section_size_map(u32 section_size)
  486. {
  487. /*
  488. * Section size mapping:
  489. * 0x0: 16-MiB section
  490. * 0x1: 32-MiB section
  491. * 0x2: 64-MiB section
  492. * 0x3: 128-MiB section
  493. * 0x4: 256-MiB section
  494. * 0x5: 512-MiB section
  495. * 0x6: 1-GiB section
  496. * 0x7: 2-GiB section
  497. */
  498. section_size >>= 24; /* divide by 16 MB */
  499. return log_2_n_round_down(section_size);
  500. }
  501. static void emif_calculate_regs(
  502. const struct emif_device_details *emif_dev_details,
  503. u32 freq, struct emif_regs *regs)
  504. {
  505. u32 temp, sys_freq;
  506. const struct lpddr2_addressing *addressing;
  507. const struct lpddr2_ac_timings *timings;
  508. const struct lpddr2_min_tck *min_tck;
  509. const struct lpddr2_device_details *cs0_dev_details =
  510. emif_dev_details->cs0_device_details;
  511. const struct lpddr2_device_details *cs1_dev_details =
  512. emif_dev_details->cs1_device_details;
  513. const struct lpddr2_device_timings *cs0_dev_timings =
  514. emif_dev_details->cs0_device_timings;
  515. emif_assert(emif_dev_details);
  516. emif_assert(regs);
  517. /*
  518. * You can not have a device on CS1 without one on CS0
  519. * So configuring EMIF without a device on CS0 doesn't
  520. * make sense
  521. */
  522. emif_assert(cs0_dev_details);
  523. emif_assert(cs0_dev_details->type != LPDDR2_TYPE_NVM);
  524. /*
  525. * If there is a device on CS1 it should be same type as CS0
  526. * (or NVM. But NVM is not supported in this driver yet)
  527. */
  528. emif_assert((cs1_dev_details == NULL) ||
  529. (cs1_dev_details->type == LPDDR2_TYPE_NVM) ||
  530. (cs0_dev_details->type == cs1_dev_details->type));
  531. emif_assert(freq <= MAX_LPDDR2_FREQ);
  532. set_ddr_clk_period(freq);
  533. /*
  534. * The device on CS0 is used for all timing calculations
  535. * There is only one set of registers for timings per EMIF. So, if the
  536. * second CS(CS1) has a device, it should have the same timings as the
  537. * device on CS0
  538. */
  539. timings = get_timings_table(cs0_dev_timings->ac_timings, freq);
  540. emif_assert(timings);
  541. min_tck = cs0_dev_timings->min_tck;
  542. temp = addressing_table_index(cs0_dev_details->type,
  543. cs0_dev_details->density,
  544. cs0_dev_details->io_width);
  545. emif_assert((temp >= 0));
  546. addressing = &(addressing_table[temp]);
  547. emif_assert(addressing);
  548. sys_freq = get_sys_clk_freq();
  549. regs->sdram_config_init = get_sdram_config_reg(cs0_dev_details,
  550. cs1_dev_details,
  551. addressing, RL_BOOT);
  552. regs->sdram_config = get_sdram_config_reg(cs0_dev_details,
  553. cs1_dev_details,
  554. addressing, RL_FINAL);
  555. regs->ref_ctrl = get_sdram_ref_ctrl(freq, addressing);
  556. regs->sdram_tim1 = get_sdram_tim_1_reg(timings, min_tck, addressing);
  557. regs->sdram_tim2 = get_sdram_tim_2_reg(timings, min_tck);
  558. regs->sdram_tim3 = get_sdram_tim_3_reg(timings, min_tck, addressing);
  559. regs->read_idle_ctrl = get_read_idle_ctrl_reg(LPDDR2_VOLTAGE_STABLE);
  560. regs->temp_alert_config =
  561. get_temp_alert_config(cs1_dev_details, addressing, 0);
  562. regs->zq_config = get_zq_config_reg(cs1_dev_details, addressing,
  563. LPDDR2_VOLTAGE_STABLE);
  564. regs->emif_ddr_phy_ctlr_1_init =
  565. get_ddr_phy_ctrl_1(sys_freq / 2, RL_BOOT);
  566. regs->emif_ddr_phy_ctlr_1 =
  567. get_ddr_phy_ctrl_1(freq, RL_FINAL);
  568. regs->freq = freq;
  569. print_timing_reg(regs->sdram_config_init);
  570. print_timing_reg(regs->sdram_config);
  571. print_timing_reg(regs->ref_ctrl);
  572. print_timing_reg(regs->sdram_tim1);
  573. print_timing_reg(regs->sdram_tim2);
  574. print_timing_reg(regs->sdram_tim3);
  575. print_timing_reg(regs->read_idle_ctrl);
  576. print_timing_reg(regs->temp_alert_config);
  577. print_timing_reg(regs->zq_config);
  578. print_timing_reg(regs->emif_ddr_phy_ctlr_1);
  579. print_timing_reg(regs->emif_ddr_phy_ctlr_1_init);
  580. }
  581. #endif /* CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS */
  582. #ifdef CONFIG_SYS_AUTOMATIC_SDRAM_DETECTION
  583. const char *get_lpddr2_type(u8 type_id)
  584. {
  585. switch (type_id) {
  586. case LPDDR2_TYPE_S4:
  587. return "LPDDR2-S4";
  588. case LPDDR2_TYPE_S2:
  589. return "LPDDR2-S2";
  590. default:
  591. return NULL;
  592. }
  593. }
  594. const char *get_lpddr2_io_width(u8 width_id)
  595. {
  596. switch (width_id) {
  597. case LPDDR2_IO_WIDTH_8:
  598. return "x8";
  599. case LPDDR2_IO_WIDTH_16:
  600. return "x16";
  601. case LPDDR2_IO_WIDTH_32:
  602. return "x32";
  603. default:
  604. return NULL;
  605. }
  606. }
  607. const char *get_lpddr2_manufacturer(u32 manufacturer)
  608. {
  609. switch (manufacturer) {
  610. case LPDDR2_MANUFACTURER_SAMSUNG:
  611. return "Samsung";
  612. case LPDDR2_MANUFACTURER_QIMONDA:
  613. return "Qimonda";
  614. case LPDDR2_MANUFACTURER_ELPIDA:
  615. return "Elpida";
  616. case LPDDR2_MANUFACTURER_ETRON:
  617. return "Etron";
  618. case LPDDR2_MANUFACTURER_NANYA:
  619. return "Nanya";
  620. case LPDDR2_MANUFACTURER_HYNIX:
  621. return "Hynix";
  622. case LPDDR2_MANUFACTURER_MOSEL:
  623. return "Mosel";
  624. case LPDDR2_MANUFACTURER_WINBOND:
  625. return "Winbond";
  626. case LPDDR2_MANUFACTURER_ESMT:
  627. return "ESMT";
  628. case LPDDR2_MANUFACTURER_SPANSION:
  629. return "Spansion";
  630. case LPDDR2_MANUFACTURER_SST:
  631. return "SST";
  632. case LPDDR2_MANUFACTURER_ZMOS:
  633. return "ZMOS";
  634. case LPDDR2_MANUFACTURER_INTEL:
  635. return "Intel";
  636. case LPDDR2_MANUFACTURER_NUMONYX:
  637. return "Numonyx";
  638. case LPDDR2_MANUFACTURER_MICRON:
  639. return "Micron";
  640. default:
  641. return NULL;
  642. }
  643. }
  644. static void display_sdram_details(u32 emif_nr, u32 cs,
  645. struct lpddr2_device_details *device)
  646. {
  647. const char *mfg_str;
  648. const char *type_str;
  649. char density_str[10];
  650. u32 density;
  651. debug("EMIF%d CS%d\t", emif_nr, cs);
  652. if (!device) {
  653. debug("None\n");
  654. return;
  655. }
  656. mfg_str = get_lpddr2_manufacturer(device->manufacturer);
  657. type_str = get_lpddr2_type(device->type);
  658. density = lpddr2_density_2_size_in_mbytes[device->density];
  659. if ((density / 1024 * 1024) == density) {
  660. density /= 1024;
  661. sprintf(density_str, "%d GB", density);
  662. } else
  663. sprintf(density_str, "%d MB", density);
  664. if (mfg_str && type_str)
  665. debug("%s\t\t%s\t%s\n", mfg_str, type_str, density_str);
  666. }
  667. static u8 is_lpddr2_sdram_present(u32 base, u32 cs,
  668. struct lpddr2_device_details *lpddr2_device)
  669. {
  670. u32 mr = 0, temp;
  671. mr = get_mr(base, cs, LPDDR2_MR0);
  672. if (mr > 0xFF) {
  673. /* Mode register value bigger than 8 bit */
  674. return 0;
  675. }
  676. temp = (mr & LPDDR2_MR0_DI_MASK) >> LPDDR2_MR0_DI_SHIFT;
  677. if (temp) {
  678. /* Not SDRAM */
  679. return 0;
  680. }
  681. temp = (mr & LPDDR2_MR0_DNVI_MASK) >> LPDDR2_MR0_DNVI_SHIFT;
  682. if (temp) {
  683. /* DNV supported - But DNV is only supported for NVM */
  684. return 0;
  685. }
  686. mr = get_mr(base, cs, LPDDR2_MR4);
  687. if (mr > 0xFF) {
  688. /* Mode register value bigger than 8 bit */
  689. return 0;
  690. }
  691. mr = get_mr(base, cs, LPDDR2_MR5);
  692. if (mr >= 0xFF) {
  693. /* Mode register value bigger than 8 bit */
  694. return 0;
  695. }
  696. if (!get_lpddr2_manufacturer(mr)) {
  697. /* Manufacturer not identified */
  698. return 0;
  699. }
  700. lpddr2_device->manufacturer = mr;
  701. mr = get_mr(base, cs, LPDDR2_MR6);
  702. if (mr >= 0xFF) {
  703. /* Mode register value bigger than 8 bit */
  704. return 0;
  705. }
  706. mr = get_mr(base, cs, LPDDR2_MR7);
  707. if (mr >= 0xFF) {
  708. /* Mode register value bigger than 8 bit */
  709. return 0;
  710. }
  711. mr = get_mr(base, cs, LPDDR2_MR8);
  712. if (mr >= 0xFF) {
  713. /* Mode register value bigger than 8 bit */
  714. return 0;
  715. }
  716. temp = (mr & MR8_TYPE_MASK) >> MR8_TYPE_SHIFT;
  717. if (!get_lpddr2_type(temp)) {
  718. /* Not SDRAM */
  719. return 0;
  720. }
  721. lpddr2_device->type = temp;
  722. temp = (mr & MR8_DENSITY_MASK) >> MR8_DENSITY_SHIFT;
  723. if (temp > LPDDR2_DENSITY_32Gb) {
  724. /* Density not supported */
  725. return 0;
  726. }
  727. lpddr2_device->density = temp;
  728. temp = (mr & MR8_IO_WIDTH_MASK) >> MR8_IO_WIDTH_SHIFT;
  729. if (!get_lpddr2_io_width(temp)) {
  730. /* IO width unsupported value */
  731. return 0;
  732. }
  733. lpddr2_device->io_width = temp;
  734. /*
  735. * If all the above tests pass we should
  736. * have a device on this chip-select
  737. */
  738. return 1;
  739. }
  740. struct lpddr2_device_details *emif_get_device_details(u32 emif_nr, u8 cs,
  741. struct lpddr2_device_details *lpddr2_dev_details)
  742. {
  743. u32 phy;
  744. u32 base = (emif_nr == 1) ? EMIF1_BASE : EMIF2_BASE;
  745. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  746. if (!lpddr2_dev_details)
  747. return NULL;
  748. /* Do the minimum init for mode register accesses */
  749. if (!running_from_sdram()) {
  750. phy = get_ddr_phy_ctrl_1(get_sys_clk_freq() / 2, RL_BOOT);
  751. writel(phy, &emif->emif_ddr_phy_ctrl_1);
  752. }
  753. if (!(is_lpddr2_sdram_present(base, cs, lpddr2_dev_details)))
  754. return NULL;
  755. display_sdram_details(emif_num(base), cs, lpddr2_dev_details);
  756. return lpddr2_dev_details;
  757. }
  758. #endif /* CONFIG_SYS_AUTOMATIC_SDRAM_DETECTION */
  759. static void do_sdram_init(u32 base)
  760. {
  761. const struct emif_regs *regs;
  762. u32 in_sdram, emif_nr;
  763. debug(">>do_sdram_init() %x\n", base);
  764. in_sdram = running_from_sdram();
  765. emif_nr = (base == EMIF1_BASE) ? 1 : 2;
  766. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  767. emif_get_reg_dump(emif_nr, &regs);
  768. if (!regs) {
  769. debug("EMIF: reg dump not provided\n");
  770. return;
  771. }
  772. #else
  773. /*
  774. * The user has not provided the register values. We need to
  775. * calculate it based on the timings and the DDR frequency
  776. */
  777. struct emif_device_details dev_details;
  778. struct emif_regs calculated_regs;
  779. /*
  780. * Get device details:
  781. * - Discovered if CONFIG_SYS_AUTOMATIC_SDRAM_DETECTION is set
  782. * - Obtained from user otherwise
  783. */
  784. struct lpddr2_device_details cs0_dev_details, cs1_dev_details;
  785. emif_reset_phy(base);
  786. dev_details.cs0_device_details = emif_get_device_details(emif_nr, CS0,
  787. &cs0_dev_details);
  788. dev_details.cs1_device_details = emif_get_device_details(emif_nr, CS1,
  789. &cs1_dev_details);
  790. emif_reset_phy(base);
  791. /* Return if no devices on this EMIF */
  792. if (!dev_details.cs0_device_details &&
  793. !dev_details.cs1_device_details) {
  794. emif_sizes[emif_nr - 1] = 0;
  795. return;
  796. }
  797. if (!in_sdram)
  798. emif_sizes[emif_nr - 1] = get_emif_mem_size(&dev_details);
  799. /*
  800. * Get device timings:
  801. * - Default timings specified by JESD209-2 if
  802. * CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS is set
  803. * - Obtained from user otherwise
  804. */
  805. emif_get_device_timings(emif_nr, &dev_details.cs0_device_timings,
  806. &dev_details.cs1_device_timings);
  807. /* Calculate the register values */
  808. emif_calculate_regs(&dev_details, omap_ddr_clk(), &calculated_regs);
  809. regs = &calculated_regs;
  810. #endif /* CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS */
  811. /*
  812. * Initializing the LPDDR2 device can not happen from SDRAM.
  813. * Changing the timing registers in EMIF can happen(going from one
  814. * OPP to another)
  815. */
  816. if (!in_sdram)
  817. lpddr2_init(base, regs);
  818. /* Write to the shadow registers */
  819. emif_update_timings(base, regs);
  820. debug("<<do_sdram_init() %x\n", base);
  821. }
  822. void emif_post_init_config(u32 base)
  823. {
  824. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  825. u32 omap_rev = omap_revision();
  826. if (omap_rev == OMAP5430_ES1_0)
  827. return;
  828. /* reset phy on ES2.0 */
  829. if (omap_rev == OMAP4430_ES2_0)
  830. emif_reset_phy(base);
  831. /* Put EMIF back in smart idle on ES1.0 */
  832. if (omap_rev == OMAP4430_ES1_0)
  833. writel(0x80000000, &emif->emif_pwr_mgmt_ctrl);
  834. }
  835. void dmm_init(u32 base)
  836. {
  837. const struct dmm_lisa_map_regs *lisa_map_regs;
  838. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  839. emif_get_dmm_regs(&lisa_map_regs);
  840. #else
  841. u32 emif1_size, emif2_size, mapped_size, section_map = 0;
  842. u32 section_cnt, sys_addr;
  843. struct dmm_lisa_map_regs lis_map_regs_calculated = {0};
  844. mapped_size = 0;
  845. section_cnt = 3;
  846. sys_addr = CONFIG_SYS_SDRAM_BASE;
  847. emif1_size = emif_sizes[0];
  848. emif2_size = emif_sizes[1];
  849. debug("emif1_size 0x%x emif2_size 0x%x\n", emif1_size, emif2_size);
  850. if (!emif1_size && !emif2_size)
  851. return;
  852. /* symmetric interleaved section */
  853. if (emif1_size && emif2_size) {
  854. mapped_size = min(emif1_size, emif2_size);
  855. section_map = DMM_LISA_MAP_INTERLEAVED_BASE_VAL;
  856. section_map |= 0 << EMIF_SDRC_ADDR_SHIFT;
  857. /* only MSB */
  858. section_map |= (sys_addr >> 24) <<
  859. EMIF_SYS_ADDR_SHIFT;
  860. section_map |= get_dmm_section_size_map(mapped_size * 2)
  861. << EMIF_SYS_SIZE_SHIFT;
  862. lis_map_regs_calculated.dmm_lisa_map_3 = section_map;
  863. emif1_size -= mapped_size;
  864. emif2_size -= mapped_size;
  865. sys_addr += (mapped_size * 2);
  866. section_cnt--;
  867. }
  868. /*
  869. * Single EMIF section(we can have a maximum of 1 single EMIF
  870. * section- either EMIF1 or EMIF2 or none, but not both)
  871. */
  872. if (emif1_size) {
  873. section_map = DMM_LISA_MAP_EMIF1_ONLY_BASE_VAL;
  874. section_map |= get_dmm_section_size_map(emif1_size)
  875. << EMIF_SYS_SIZE_SHIFT;
  876. /* only MSB */
  877. section_map |= (mapped_size >> 24) <<
  878. EMIF_SDRC_ADDR_SHIFT;
  879. /* only MSB */
  880. section_map |= (sys_addr >> 24) << EMIF_SYS_ADDR_SHIFT;
  881. section_cnt--;
  882. }
  883. if (emif2_size) {
  884. section_map = DMM_LISA_MAP_EMIF2_ONLY_BASE_VAL;
  885. section_map |= get_dmm_section_size_map(emif2_size) <<
  886. EMIF_SYS_SIZE_SHIFT;
  887. /* only MSB */
  888. section_map |= mapped_size >> 24 << EMIF_SDRC_ADDR_SHIFT;
  889. /* only MSB */
  890. section_map |= sys_addr >> 24 << EMIF_SYS_ADDR_SHIFT;
  891. section_cnt--;
  892. }
  893. if (section_cnt == 2) {
  894. /* Only 1 section - either symmetric or single EMIF */
  895. lis_map_regs_calculated.dmm_lisa_map_3 = section_map;
  896. lis_map_regs_calculated.dmm_lisa_map_2 = 0;
  897. lis_map_regs_calculated.dmm_lisa_map_1 = 0;
  898. } else {
  899. /* 2 sections - 1 symmetric, 1 single EMIF */
  900. lis_map_regs_calculated.dmm_lisa_map_2 = section_map;
  901. lis_map_regs_calculated.dmm_lisa_map_1 = 0;
  902. }
  903. /* TRAP for invalid TILER mappings in section 0 */
  904. lis_map_regs_calculated.dmm_lisa_map_0 = DMM_LISA_MAP_0_INVAL_ADDR_TRAP;
  905. lisa_map_regs = &lis_map_regs_calculated;
  906. #endif
  907. struct dmm_lisa_map_regs *hw_lisa_map_regs =
  908. (struct dmm_lisa_map_regs *)base;
  909. writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
  910. writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
  911. writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
  912. writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
  913. writel(lisa_map_regs->dmm_lisa_map_3,
  914. &hw_lisa_map_regs->dmm_lisa_map_3);
  915. writel(lisa_map_regs->dmm_lisa_map_2,
  916. &hw_lisa_map_regs->dmm_lisa_map_2);
  917. writel(lisa_map_regs->dmm_lisa_map_1,
  918. &hw_lisa_map_regs->dmm_lisa_map_1);
  919. writel(lisa_map_regs->dmm_lisa_map_0,
  920. &hw_lisa_map_regs->dmm_lisa_map_0);
  921. if (omap_revision() >= OMAP4460_ES1_0) {
  922. hw_lisa_map_regs =
  923. (struct dmm_lisa_map_regs *)MA_BASE;
  924. writel(lisa_map_regs->dmm_lisa_map_3,
  925. &hw_lisa_map_regs->dmm_lisa_map_3);
  926. writel(lisa_map_regs->dmm_lisa_map_2,
  927. &hw_lisa_map_regs->dmm_lisa_map_2);
  928. writel(lisa_map_regs->dmm_lisa_map_1,
  929. &hw_lisa_map_regs->dmm_lisa_map_1);
  930. writel(lisa_map_regs->dmm_lisa_map_0,
  931. &hw_lisa_map_regs->dmm_lisa_map_0);
  932. }
  933. }
  934. /*
  935. * SDRAM initialization:
  936. * SDRAM initialization has two parts:
  937. * 1. Configuring the SDRAM device
  938. * 2. Update the AC timings related parameters in the EMIF module
  939. * (1) should be done only once and should not be done while we are
  940. * running from SDRAM.
  941. * (2) can and should be done more than once if OPP changes.
  942. * Particularly, this may be needed when we boot without SPL and
  943. * and using Configuration Header(CH). ROM code supports only at 50% OPP
  944. * at boot (low power boot). So u-boot has to switch to OPP100 and update
  945. * the frequency. So,
  946. * Doing (1) and (2) makes sense - first time initialization
  947. * Doing (2) and not (1) makes sense - OPP change (when using CH)
  948. * Doing (1) and not (2) doen't make sense
  949. * See do_sdram_init() for the details
  950. */
  951. void sdram_init(void)
  952. {
  953. u32 in_sdram, size_prog, size_detect;
  954. debug(">>sdram_init()\n");
  955. if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
  956. return;
  957. in_sdram = running_from_sdram();
  958. debug("in_sdram = %d\n", in_sdram);
  959. if (!in_sdram)
  960. bypass_dpll(&prcm->cm_clkmode_dpll_core);
  961. do_sdram_init(EMIF1_BASE);
  962. do_sdram_init(EMIF2_BASE);
  963. if (!in_sdram) {
  964. dmm_init(DMM_BASE);
  965. emif_post_init_config(EMIF1_BASE);
  966. emif_post_init_config(EMIF2_BASE);
  967. }
  968. /* for the shadow registers to take effect */
  969. freq_update_core();
  970. /* Do some testing after the init */
  971. if (!in_sdram) {
  972. size_prog = omap_sdram_size();
  973. size_detect = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
  974. size_prog);
  975. /* Compare with the size programmed */
  976. if (size_detect != size_prog) {
  977. printf("SDRAM: identified size not same as expected"
  978. " size identified: %x expected: %x\n",
  979. size_detect,
  980. size_prog);
  981. } else
  982. debug("get_ram_size() successful");
  983. }
  984. debug("<<sdram_init()\n");
  985. }