dmc_init.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /*
  2. * Memory setup for SMDK5250 board based on EXYNOS5
  3. *
  4. * Copyright (C) 2012 Samsung Electronics
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <config.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/dmc.h>
  27. #include <asm/arch/clock.h>
  28. #include <asm/arch/cpu.h>
  29. #include "setup.h"
  30. /* APLL : 1GHz */
  31. /* MCLK_CDREX: MCLK_CDREX_533*/
  32. /* LPDDR support: LPDDR2 */
  33. static void reset_phy_ctrl(void);
  34. static void config_zq(struct exynos5_phy_control *,
  35. struct exynos5_phy_control *);
  36. static void update_reset_dll(struct exynos5_dmc *);
  37. static void config_cdrex(void);
  38. static void config_mrs(struct exynos5_dmc *);
  39. static void sec_sdram_phy_init(struct exynos5_dmc *);
  40. static void config_prech(struct exynos5_dmc *);
  41. static void config_rdlvl(struct exynos5_dmc *,
  42. struct exynos5_phy_control *,
  43. struct exynos5_phy_control *);
  44. static void config_memory(struct exynos5_dmc *);
  45. static void config_offsets(unsigned int,
  46. struct exynos5_phy_control *,
  47. struct exynos5_phy_control *);
  48. static void reset_phy_ctrl(void)
  49. {
  50. struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
  51. writel(PHY_RESET_VAL, &clk->lpddr3phy_ctrl);
  52. sdelay(0x10000);
  53. }
  54. static void config_zq(struct exynos5_phy_control *phy0_ctrl,
  55. struct exynos5_phy_control *phy1_ctrl)
  56. {
  57. unsigned long val = 0;
  58. /*
  59. * ZQ Calibration:
  60. * Select Driver Strength,
  61. * long calibration for manual calibration
  62. */
  63. val = PHY_CON16_RESET_VAL;
  64. SET_ZQ_MODE_DDS_VAL(val);
  65. SET_ZQ_MODE_TERM_VAL(val);
  66. val |= ZQ_CLK_DIV_EN;
  67. writel(val, &phy0_ctrl->phy_con16);
  68. writel(val, &phy1_ctrl->phy_con16);
  69. /* Disable termination */
  70. val |= ZQ_MODE_NOTERM;
  71. writel(val, &phy0_ctrl->phy_con16);
  72. writel(val, &phy1_ctrl->phy_con16);
  73. /* ZQ_MANUAL_START: Enable */
  74. val |= ZQ_MANUAL_STR;
  75. writel(val, &phy0_ctrl->phy_con16);
  76. writel(val, &phy1_ctrl->phy_con16);
  77. sdelay(0x10000);
  78. /* ZQ_MANUAL_START: Disable */
  79. val &= ~ZQ_MANUAL_STR;
  80. writel(val, &phy0_ctrl->phy_con16);
  81. writel(val, &phy1_ctrl->phy_con16);
  82. }
  83. static void update_reset_dll(struct exynos5_dmc *dmc)
  84. {
  85. unsigned long val;
  86. /*
  87. * Update DLL Information:
  88. * Force DLL Resyncronization
  89. */
  90. val = readl(&dmc->phycontrol0);
  91. val |= FP_RSYNC;
  92. writel(val, &dmc->phycontrol0);
  93. /* Reset Force DLL Resyncronization */
  94. val = readl(&dmc->phycontrol0);
  95. val &= ~FP_RSYNC;
  96. writel(val, &dmc->phycontrol0);
  97. }
  98. static void config_mrs(struct exynos5_dmc *dmc)
  99. {
  100. unsigned long channel, chip, mask = 0, val;
  101. for (channel = 0; channel < CONFIG_DMC_CHANNELS; channel++) {
  102. SET_CMD_CHANNEL(mask, channel);
  103. for (chip = 0; chip < CONFIG_CHIPS_PER_CHANNEL; chip++) {
  104. /*
  105. * NOP CMD:
  106. * Assert and hold CKE to logic high level
  107. */
  108. SET_CMD_CHIP(mask, chip);
  109. val = DIRECT_CMD_NOP | mask;
  110. writel(val, &dmc->directcmd);
  111. sdelay(0x10000);
  112. /* EMRS, MRS Cmds(Mode Reg Settings) Using Direct Cmd */
  113. val = DIRECT_CMD_MRS1 | mask;
  114. writel(val, &dmc->directcmd);
  115. sdelay(0x10000);
  116. val = DIRECT_CMD_MRS2 | mask;
  117. writel(val, &dmc->directcmd);
  118. sdelay(0x10000);
  119. /* MCLK_CDREX_533 */
  120. val = DIRECT_CMD_MRS3 | mask;
  121. writel(val, &dmc->directcmd);
  122. sdelay(0x10000);
  123. val = DIRECT_CMD_MRS4 | mask;
  124. writel(val, &dmc->directcmd);
  125. sdelay(0x10000);
  126. }
  127. }
  128. }
  129. static void config_prech(struct exynos5_dmc *dmc)
  130. {
  131. unsigned long channel, chip, mask = 0, val;
  132. for (channel = 0; channel < CONFIG_DMC_CHANNELS; channel++) {
  133. SET_CMD_CHANNEL(mask, channel);
  134. for (chip = 0; chip < CONFIG_CHIPS_PER_CHANNEL; chip++) {
  135. SET_CMD_CHIP(mask, chip);
  136. /* PALL (all banks precharge) CMD */
  137. val = DIRECT_CMD_PALL | mask;
  138. writel(val, &dmc->directcmd);
  139. sdelay(0x10000);
  140. }
  141. }
  142. }
  143. static void sec_sdram_phy_init(struct exynos5_dmc *dmc)
  144. {
  145. unsigned long val;
  146. val = readl(&dmc->concontrol);
  147. val |= DFI_INIT_START;
  148. writel(val, &dmc->concontrol);
  149. sdelay(0x10000);
  150. val = readl(&dmc->concontrol);
  151. val &= ~DFI_INIT_START;
  152. writel(val, &dmc->concontrol);
  153. }
  154. static void config_offsets(unsigned int state,
  155. struct exynos5_phy_control *phy0_ctrl,
  156. struct exynos5_phy_control *phy1_ctrl)
  157. {
  158. unsigned long val;
  159. /* Set Offsets to read DQS */
  160. val = (state == SET) ? SET_DQS_OFFSET_VAL : RESET_DQS_OFFSET_VAL;
  161. writel(val, &phy0_ctrl->phy_con4);
  162. writel(val, &phy1_ctrl->phy_con4);
  163. /* Set Offsets to read DQ */
  164. val = (state == SET) ? SET_DQ_OFFSET_VAL : RESET_DQ_OFFSET_VAL;
  165. writel(val, &phy0_ctrl->phy_con6);
  166. writel(val, &phy1_ctrl->phy_con6);
  167. /* Debug Offset */
  168. val = (state == SET) ? SET_DEBUG_OFFSET_VAL : RESET_DEBUG_OFFSET_VAL;
  169. writel(val, &phy0_ctrl->phy_con10);
  170. writel(val, &phy1_ctrl->phy_con10);
  171. }
  172. static void config_cdrex(void)
  173. {
  174. struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
  175. writel(CLK_DIV_CDREX_VAL, &clk->div_cdrex);
  176. writel(CLK_SRC_CDREX_VAL, &clk->src_cdrex);
  177. sdelay(0x30000);
  178. }
  179. static void config_ctrl_dll_on(unsigned int state,
  180. unsigned int ctrl_force_val,
  181. struct exynos5_phy_control *phy0_ctrl,
  182. struct exynos5_phy_control *phy1_ctrl)
  183. {
  184. unsigned long val;
  185. val = readl(&phy0_ctrl->phy_con12);
  186. CONFIG_CTRL_DLL_ON(val, state);
  187. SET_CTRL_FORCE_VAL(val, ctrl_force_val);
  188. writel(val, &phy0_ctrl->phy_con12);
  189. val = readl(&phy1_ctrl->phy_con12);
  190. CONFIG_CTRL_DLL_ON(val, state);
  191. SET_CTRL_FORCE_VAL(val, ctrl_force_val);
  192. writel(val, &phy1_ctrl->phy_con12);
  193. }
  194. static void config_ctrl_start(unsigned int state,
  195. struct exynos5_phy_control *phy0_ctrl,
  196. struct exynos5_phy_control *phy1_ctrl)
  197. {
  198. unsigned long val;
  199. val = readl(&phy0_ctrl->phy_con12);
  200. CONFIG_CTRL_START(val, state);
  201. writel(val, &phy0_ctrl->phy_con12);
  202. val = readl(&phy1_ctrl->phy_con12);
  203. CONFIG_CTRL_START(val, state);
  204. writel(val, &phy1_ctrl->phy_con12);
  205. }
  206. #if defined(CONFIG_RD_LVL)
  207. static void config_rdlvl(struct exynos5_dmc *dmc,
  208. struct exynos5_phy_control *phy0_ctrl,
  209. struct exynos5_phy_control *phy1_ctrl)
  210. {
  211. unsigned long val;
  212. /* Disable CTRL_DLL_ON and set ctrl_force */
  213. config_ctrl_dll_on(RESET, 0x2D, phy0_ctrl, phy1_ctrl);
  214. /*
  215. * Set ctrl_gateadj, ctrl_readadj
  216. * ctrl_gateduradj, rdlvl_pass_adj
  217. * rdlvl_rddataPadj
  218. */
  219. val = SET_RDLVL_RDDATAPADJ;
  220. writel(val, &phy0_ctrl->phy_con1);
  221. writel(val, &phy1_ctrl->phy_con1);
  222. /* LPDDR2 Address */
  223. writel(LPDDR2_ADDR, &phy0_ctrl->phy_con22);
  224. writel(LPDDR2_ADDR, &phy1_ctrl->phy_con22);
  225. /* Enable Byte Read Leveling set ctrl_ddr_mode */
  226. val = readl(&phy0_ctrl->phy_con0);
  227. val |= BYTE_RDLVL_EN;
  228. writel(val, &phy0_ctrl->phy_con0);
  229. val = readl(&phy1_ctrl->phy_con0);
  230. val |= BYTE_RDLVL_EN;
  231. writel(val, &phy1_ctrl->phy_con0);
  232. /* rdlvl_en: Use levelling offset instead ctrl_shiftc */
  233. val = PHY_CON2_RESET_VAL | RDLVL_EN;
  234. writel(val, &phy0_ctrl->phy_con2);
  235. writel(val, &phy1_ctrl->phy_con2);
  236. sdelay(0x10000);
  237. /* Enable Data Eye Training */
  238. val = readl(&dmc->rdlvl_config);
  239. val |= CTRL_RDLVL_DATA_EN;
  240. writel(val, &dmc->rdlvl_config);
  241. sdelay(0x10000);
  242. /* Disable Data Eye Training */
  243. val = readl(&dmc->rdlvl_config);
  244. val &= ~CTRL_RDLVL_DATA_EN;
  245. writel(val, &dmc->rdlvl_config);
  246. /* RdDeSkew_clear: Clear */
  247. val = readl(&phy0_ctrl->phy_con2);
  248. val |= RDDSKEW_CLEAR;
  249. writel(val, &phy0_ctrl->phy_con2);
  250. val = readl(&phy1_ctrl->phy_con2);
  251. val |= RDDSKEW_CLEAR;
  252. writel(val, &phy1_ctrl->phy_con2);
  253. /* Enable CTRL_DLL_ON */
  254. config_ctrl_dll_on(SET, 0x0, phy0_ctrl, phy1_ctrl);
  255. update_reset_dll(dmc);
  256. sdelay(0x10000);
  257. /* ctrl_atgte: ctrl_gate_p*, ctrl_read_p* generated by PHY */
  258. val = readl(&phy0_ctrl->phy_con0);
  259. val &= ~CTRL_ATGATE;
  260. writel(val, &phy0_ctrl->phy_con0);
  261. val = readl(&phy1_ctrl->phy_con0);
  262. val &= ~CTRL_ATGATE;
  263. writel(val, &phy1_ctrl->phy_con0);
  264. }
  265. #endif
  266. static void config_memory(struct exynos5_dmc *dmc)
  267. {
  268. /*
  269. * Memory Configuration Chip 0
  270. * Address Mapping: Interleaved
  271. * Number of Column address Bits: 10 bits
  272. * Number of Rows Address Bits: 14
  273. * Number of Banks: 8
  274. */
  275. writel(DMC_MEMCONFIG0_VAL, &dmc->memconfig0);
  276. /*
  277. * Memory Configuration Chip 1
  278. * Address Mapping: Interleaved
  279. * Number of Column address Bits: 10 bits
  280. * Number of Rows Address Bits: 14
  281. * Number of Banks: 8
  282. */
  283. writel(DMC_MEMCONFIG1_VAL, &dmc->memconfig1);
  284. /*
  285. * Chip0: AXI
  286. * AXI Base Address: 0x40000000
  287. * AXI Base Address Mask: 0x780
  288. */
  289. writel(DMC_MEMBASECONFIG0_VAL, &dmc->membaseconfig0);
  290. /*
  291. * Chip1: AXI
  292. * AXI Base Address: 0x80000000
  293. * AXI Base Address Mask: 0x780
  294. */
  295. writel(DMC_MEMBASECONFIG1_VAL, &dmc->membaseconfig1);
  296. }
  297. void mem_ctrl_init()
  298. {
  299. struct exynos5_phy_control *phy0_ctrl, *phy1_ctrl;
  300. struct exynos5_dmc *dmc;
  301. unsigned long val;
  302. phy0_ctrl = (struct exynos5_phy_control *)EXYNOS5_DMC_PHY0_BASE;
  303. phy1_ctrl = (struct exynos5_phy_control *)EXYNOS5_DMC_PHY1_BASE;
  304. dmc = (struct exynos5_dmc *)EXYNOS5_DMC_CTRL_BASE;
  305. /* Reset PHY Controllor: PHY_RESET[0] */
  306. reset_phy_ctrl();
  307. /*set Read Latancy and Burst Length for PHY0 and PHY1 */
  308. writel(PHY_CON42_VAL, &phy0_ctrl->phy_con42);
  309. writel(PHY_CON42_VAL, &phy1_ctrl->phy_con42);
  310. /* ZQ Cofiguration */
  311. config_zq(phy0_ctrl, phy1_ctrl);
  312. /* Operation Mode : LPDDR2 */
  313. val = PHY_CON0_RESET_VAL;
  314. SET_CTRL_DDR_MODE(val, DDR_MODE_LPDDR2);
  315. writel(val, &phy0_ctrl->phy_con0);
  316. writel(val, &phy1_ctrl->phy_con0);
  317. /* DQS, DQ: Signal, for LPDDR2: Always Set */
  318. val = CTRL_PULLD_DQ | CTRL_PULLD_DQS;
  319. writel(val, &phy0_ctrl->phy_con14);
  320. writel(val, &phy1_ctrl->phy_con14);
  321. /* Init SEC SDRAM PHY */
  322. sec_sdram_phy_init(dmc);
  323. sdelay(0x10000);
  324. update_reset_dll(dmc);
  325. /*
  326. * Dynamic Clock: Always Running
  327. * Memory Burst length: 4
  328. * Number of chips: 2
  329. * Memory Bus width: 32 bit
  330. * Memory Type: LPDDR2-S4
  331. * Additional Latancy for PLL: 1 Cycle
  332. */
  333. writel(DMC_MEMCONTROL_VAL, &dmc->memcontrol);
  334. config_memory(dmc);
  335. /* Precharge Configuration */
  336. writel(DMC_PRECHCONFIG_VAL, &dmc->prechconfig);
  337. /* Power Down mode Configuration */
  338. writel(DMC_PWRDNCONFIG_VAL, &dmc->pwrdnconfig);
  339. /* Periodic Refrese Interval */
  340. writel(DMC_TIMINGREF_VAL, &dmc->timingref);
  341. /*
  342. * TimingRow, TimingData, TimingPower Setting:
  343. * Values as per Memory AC Parameters
  344. */
  345. writel(DMC_TIMINGROW_VAL, &dmc->timingrow);
  346. writel(DMC_TIMINGDATA_VAL, &dmc->timingdata);
  347. writel(DMC_TIMINGPOWER_VAL, &dmc->timingpower);
  348. /* Memory Channel Inteleaving Size: 128 Bytes */
  349. writel(CONFIG_IV_SIZE, &dmc->ivcontrol);
  350. /* Set DQS, DQ and DEBUG offsets */
  351. config_offsets(SET, phy0_ctrl, phy1_ctrl);
  352. /* Disable CTRL_DLL_ON and set ctrl_force */
  353. config_ctrl_dll_on(RESET, 0x7F, phy0_ctrl, phy1_ctrl);
  354. sdelay(0x10000);
  355. update_reset_dll(dmc);
  356. /* Config MRS(Mode Register Settingg) */
  357. config_mrs(dmc);
  358. config_cdrex();
  359. /* Reset DQS DQ and DEBUG offsets */
  360. config_offsets(RESET, phy0_ctrl, phy1_ctrl);
  361. /* Enable CTRL_DLL_ON */
  362. config_ctrl_dll_on(SET, 0x0, phy0_ctrl, phy1_ctrl);
  363. /* Stop DLL Locking */
  364. config_ctrl_start(RESET, phy0_ctrl, phy1_ctrl);
  365. sdelay(0x10000);
  366. /* Start DLL Locking */
  367. config_ctrl_start(SET, phy0_ctrl, phy1_ctrl);
  368. sdelay(0x10000);
  369. update_reset_dll(dmc);
  370. #if defined(CONFIG_RD_LVL)
  371. config_rdlvl(dmc, phy0_ctrl, phy1_ctrl);
  372. #endif
  373. config_prech(dmc);
  374. /*
  375. * Dynamic Clock: Stops During Idle Period
  376. * Dynamic Power Down: Enable
  377. * Dynamic Self refresh: Enable
  378. */
  379. val = readl(&dmc->memcontrol);
  380. val |= CLK_STOP_EN | DPWRDN_EN | DSREF_EN;
  381. writel(val, &dmc->memcontrol);
  382. /* Start Auto refresh */
  383. val = readl(&dmc->concontrol);
  384. val |= AREF_EN;
  385. writel(val, &dmc->concontrol);
  386. }