emif.c 34 KB

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