dram_sun9i.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * sun9i dram controller initialisation
  4. *
  5. * (C) Copyright 2007-2015
  6. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  7. * Jerry Wang <wangflord@allwinnertech.com>
  8. *
  9. * (C) Copyright 2016 Theobroma Systems Design und Consulting GmbH
  10. * Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
  11. */
  12. #include <common.h>
  13. #include <dm.h>
  14. #include <errno.h>
  15. #include <ram.h>
  16. #include <asm/io.h>
  17. #include <asm/arch/clock.h>
  18. #include <asm/arch/dram.h>
  19. #include <asm/arch/sys_proto.h>
  20. #define DRAM_CLK (CONFIG_DRAM_CLK * 1000000)
  21. /*
  22. * The following amounts to an extensive rewrite of the code received from
  23. * Allwinner as part of the open-source bootloader release (refer to
  24. * https://github.com/allwinner-zh/bootloader.git) and augments the upstream
  25. * sources (which act as the primary reference point for the inner workings
  26. * of the 'underdocumented' DRAM controller in the A80) using the following
  27. * documentation for other memory controllers based on the (Synopsys)
  28. * Designware IP (DDR memory protocol controller and DDR PHY)
  29. * * TI Keystone II Architecture: DDR3 Memory Controller, User's Guide
  30. * Document 'SPRUHN7C', Oct 2013 (revised March 2015)
  31. * * Xilinx Zynq UltraScale+ MPSoC Register Reference
  32. * document ug1087 (v1.0)
  33. * Note that the Zynq-documentation provides a very close match for the DDR
  34. * memory protocol controller (and provides a very good guide to the rounding
  35. * rules for various timings), whereas the TI Keystone II document should be
  36. * referred to for DDR PHY specifics only.
  37. *
  38. * The DRAM controller in the A80 runs at half the frequency of the DDR PHY
  39. * (i.e. the rules for MEMC_FREQ_RATIO=2 from the Zynq-documentation apply).
  40. *
  41. * Known limitations
  42. * =================
  43. * In the current state, the following features are not fully supported and
  44. * a number of simplifying assumptions have been made:
  45. * 1) Only DDR3 support is implemented, as our test platform (the A80-Q7
  46. * module) is designed to accomodate DDR3/DDR3L.
  47. * 2) Only 2T-mode has been implemented and tested.
  48. * 3) The controller supports two different clocking strategies (PLL6 can
  49. * either be 2*CK or CK/2)... we only support the 2*CK clock at this
  50. * time and haven't verified whether the alternative clocking strategy
  51. * works. If you are interested in porting this over/testing this,
  52. * please refer to cases where bit 0 of 'dram_tpr8' is tested in the
  53. * original code from Allwinner.
  54. * 4) Support for 2 ranks per controller is not implemented (as we don't
  55. * the hardware to test it).
  56. *
  57. * Future directions
  58. * =================
  59. * The driver should be driven from a device-tree based configuration that
  60. * can dynamically provide the necessary timing parameters (i.e. target
  61. * frequency and speed-bin information)---the data structures used in the
  62. * calculation of the timing parameters are already designed to capture
  63. * similar information as the device tree would provide.
  64. *
  65. * To enable a device-tree based configuration of the sun9i platform, we
  66. * will need to enable CONFIG_TPL and bootstrap in 3 stages: initially
  67. * into SRAM A1 (40KB) and next into SRAM A2 (160KB)---which would be the
  68. * stage to initialise the platform via the device-tree---before having
  69. * the full U-Boot run from DDR.
  70. */
  71. /*
  72. * A number of DDR3 timings are given as "the greater of a fixed number of
  73. * clock cycles (CK) or nanoseconds. We express these using a structure
  74. * that holds a cycle count and a duration in picoseconds (so we can model
  75. * sub-ns timings, such as 7.5ns without losing precision or resorting to
  76. * rounding up early.
  77. */
  78. struct dram_sun9i_timing {
  79. u32 ck;
  80. u32 ps;
  81. };
  82. /* */
  83. struct dram_sun9i_cl_cwl_timing {
  84. u32 CL;
  85. u32 CWL;
  86. u32 tCKmin; /* in ps */
  87. u32 tCKmax; /* in ps */
  88. };
  89. struct dram_sun9i_para {
  90. u32 dram_type;
  91. u8 bus_width;
  92. u8 chan;
  93. u8 rank;
  94. u8 rows;
  95. u16 page_size;
  96. /* Timing information for each speed-bin */
  97. struct dram_sun9i_cl_cwl_timing *cl_cwl_table;
  98. u32 cl_cwl_numentries;
  99. /*
  100. * For the timings, we try to keep the order and grouping used in
  101. * JEDEC Standard No. 79-3F
  102. */
  103. /* timings */
  104. u32 tREFI; /* in ns */
  105. u32 tRFC; /* in ns */
  106. u32 tRAS; /* in ps */
  107. /* command and address timing */
  108. u32 tDLLK; /* in nCK */
  109. struct dram_sun9i_timing tRTP;
  110. struct dram_sun9i_timing tWTR;
  111. u32 tWR; /* in nCK */
  112. u32 tMRD; /* in nCK */
  113. struct dram_sun9i_timing tMOD;
  114. u32 tRCD; /* in ps */
  115. u32 tRP; /* in ps */
  116. u32 tRC; /* in ps */
  117. u32 tCCD; /* in nCK */
  118. struct dram_sun9i_timing tRRD;
  119. u32 tFAW; /* in ps */
  120. /* calibration timing */
  121. /* struct dram_sun9i_timing tZQinit; */
  122. struct dram_sun9i_timing tZQoper;
  123. struct dram_sun9i_timing tZQCS;
  124. /* reset timing */
  125. /* struct dram_sun9i_timing tXPR; */
  126. /* self-refresh timings */
  127. struct dram_sun9i_timing tXS;
  128. u32 tXSDLL; /* in nCK */
  129. /* struct dram_sun9i_timing tCKESR; */
  130. struct dram_sun9i_timing tCKSRE;
  131. struct dram_sun9i_timing tCKSRX;
  132. /* power-down timings */
  133. struct dram_sun9i_timing tXP;
  134. struct dram_sun9i_timing tXPDLL;
  135. struct dram_sun9i_timing tCKE;
  136. /* write leveling timings */
  137. u32 tWLMRD; /* min, in nCK */
  138. /* u32 tWLDQSEN; min, in nCK */
  139. u32 tWLO; /* max, in ns */
  140. /* u32 tWLOE; max, in ns */
  141. /* u32 tCKDPX; in nCK */
  142. /* u32 tCKCSX; in nCK */
  143. };
  144. static void mctl_sys_init(void);
  145. #define SCHED_RDWR_IDLE_GAP(n) ((n & 0xff) << 24)
  146. #define SCHED_GO2CRITICAL_HYSTERESIS(n) ((n & 0xff) << 16)
  147. #define SCHED_LPR_NUM_ENTRIES(n) ((n & 0xff) << 8)
  148. #define SCHED_PAGECLOSE (1 << 2)
  149. #define SCHED_PREFER_WRITE (1 << 1)
  150. #define SCHED_FORCE_LOW_PRI_N (1 << 0)
  151. #define SCHED_CONFIG (SCHED_RDWR_IDLE_GAP(0xf) | \
  152. SCHED_GO2CRITICAL_HYSTERESIS(0x80) | \
  153. SCHED_LPR_NUM_ENTRIES(0x20) | \
  154. SCHED_FORCE_LOW_PRI_N)
  155. #define PERFHPR0_CONFIG 0x0000001f
  156. #define PERFHPR1_CONFIG 0x1f00001f
  157. #define PERFLPR0_CONFIG 0x000000ff
  158. #define PERFLPR1_CONFIG 0x0f0000ff
  159. #define PERFWR0_CONFIG 0x000000ff
  160. #define PERFWR1_CONFIG 0x0f0001ff
  161. static void mctl_ctl_sched_init(unsigned long base)
  162. {
  163. struct sunxi_mctl_ctl_reg *mctl_ctl =
  164. (struct sunxi_mctl_ctl_reg *)base;
  165. /* Needs to be done before the global clk enable... */
  166. writel(SCHED_CONFIG, &mctl_ctl->sched);
  167. writel(PERFHPR0_CONFIG, &mctl_ctl->perfhpr0);
  168. writel(PERFHPR1_CONFIG, &mctl_ctl->perfhpr1);
  169. writel(PERFLPR0_CONFIG, &mctl_ctl->perflpr0);
  170. writel(PERFLPR1_CONFIG, &mctl_ctl->perflpr1);
  171. writel(PERFWR0_CONFIG, &mctl_ctl->perfwr0);
  172. writel(PERFWR1_CONFIG, &mctl_ctl->perfwr1);
  173. }
  174. static void mctl_sys_init(void)
  175. {
  176. struct sunxi_ccm_reg * const ccm =
  177. (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  178. struct sunxi_mctl_com_reg * const mctl_com =
  179. (struct sunxi_mctl_com_reg *)SUNXI_DRAM_COM_BASE;
  180. debug("Setting PLL6 to %d\n", DRAM_CLK * 2);
  181. clock_set_pll6(DRAM_CLK * 2);
  182. /* Original dram init code which may come in handy later
  183. ********************************************************
  184. clock_set_pll6(use_2channelPLL ? (DRAM_CLK * 2) :
  185. (DRAM_CLK / 2), false);
  186. if ((para->dram_clk <= 400)|((para->dram_tpr8 & 0x1)==0)) {
  187. * PLL6 should be 2*CK *
  188. * ccm_setup_pll6_ddr_clk(PLL6_DDR_CLK); *
  189. ccm_setup_pll6_ddr_clk((1000000 * (para->dram_clk) * 2), 0);
  190. } else {
  191. * PLL6 should be CK/2 *
  192. ccm_setup_pll6_ddr_clk((1000000 * (para->dram_clk) / 2), 1);
  193. }
  194. if (para->dram_tpr13 & (0xf<<18)) {
  195. *
  196. * bit21:bit18=0001:pll swing 0.4
  197. * bit21:bit18=0010:pll swing 0.3
  198. * bit21:bit18=0100:pll swing 0.2
  199. * bit21:bit18=1000:pll swing 0.1
  200. *
  201. dram_dbg("DRAM fre extend open !\n");
  202. reg_val=mctl_read_w(CCM_PLL6_DDR_REG);
  203. reg_val&=(0x1<<16);
  204. reg_val=reg_val>>16;
  205. if(para->dram_tpr13 & (0x1<<18))
  206. {
  207. mctl_write_w(CCM_PLL_BASE + 0x114,
  208. (0x3333U|(0x3<<17)|(reg_val<<19)|(0x120U<<20)|
  209. (0x2U<<29)|(0x1U<<31)));
  210. }
  211. else if(para->dram_tpr13 & (0x1<<19))
  212. {
  213. mctl_write_w(CCM_PLL_BASE + 0x114,
  214. (0x6666U|(0x3U<<17)|(reg_val<<19)|(0xD8U<<20)|
  215. (0x2U<<29)|(0x1U<<31)));
  216. }
  217. else if(para->dram_tpr13 & (0x1<<20))
  218. {
  219. mctl_write_w(CCM_PLL_BASE + 0x114,
  220. (0x9999U|(0x3U<<17)|(reg_val<<19)|(0x90U<<20)|
  221. (0x2U<<29)|(0x1U<<31)));
  222. }
  223. else if(para->dram_tpr13 & (0x1<<21))
  224. {
  225. mctl_write_w(CCM_PLL_BASE + 0x114,
  226. (0xccccU|(0x3U<<17)|(reg_val<<19)|(0x48U<<20)|
  227. (0x2U<<29)|(0x1U<<31)));
  228. }
  229. //frequency extend open
  230. reg_val = mctl_read_w(CCM_PLL6_DDR_REG);
  231. reg_val |= ((0x1<<24)|(0x1<<30));
  232. mctl_write_w(CCM_PLL6_DDR_REG, reg_val);
  233. while(mctl_read_w(CCM_PLL6_DDR_REG) & (0x1<<30));
  234. }
  235. aw_delay(0x20000); //make some delay
  236. ********************************************************
  237. */
  238. /* assert mctl reset */
  239. clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_MCTL);
  240. /* stop mctl clock */
  241. clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_MCTL);
  242. sdelay(2000);
  243. /* deassert mctl reset */
  244. setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_MCTL);
  245. /* enable mctl clock */
  246. setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_MCTL);
  247. /* set up the transactions scheduling before enabling the global clk */
  248. mctl_ctl_sched_init(SUNXI_DRAM_CTL0_BASE);
  249. mctl_ctl_sched_init(SUNXI_DRAM_CTL1_BASE);
  250. sdelay(1000);
  251. debug("2\n");
  252. /* (3 << 12): PLL_DDR */
  253. writel((3 << 12) | (1 << 16), &ccm->dram_clk_cfg);
  254. do {
  255. debug("Waiting for DRAM_CLK_CFG\n");
  256. sdelay(10000);
  257. } while (readl(&ccm->dram_clk_cfg) & (1 << 16));
  258. setbits_le32(&ccm->dram_clk_cfg, (1 << 31));
  259. /* TODO: we only support the common case ... i.e. 2*CK */
  260. setbits_le32(&mctl_com->ccr, (1 << 14) | (1 << 30));
  261. writel(2, &mctl_com->rmcr); /* controller clock is PLL6/4 */
  262. sdelay(2000);
  263. /* Original dram init code which may come in handy later
  264. ********************************************************
  265. if ((para->dram_clk <= 400) | ((para->dram_tpr8 & 0x1) == 0)) {
  266. * PLL6 should be 2*CK *
  267. * gating 2 channel pll *
  268. reg_val = mctl_read_w(MC_CCR);
  269. reg_val |= ((0x1 << 14) | (0x1U << 30));
  270. mctl_write_w(MC_CCR, reg_val);
  271. mctl_write_w(MC_RMCR, 0x2); * controller clock use pll6/4 *
  272. } else {
  273. * enable 2 channel pll *
  274. reg_val = mctl_read_w(MC_CCR);
  275. reg_val &= ~((0x1 << 14) | (0x1U << 30));
  276. mctl_write_w(MC_CCR, reg_val);
  277. mctl_write_w(MC_RMCR, 0x0); * controller clock use pll6 *
  278. }
  279. reg_val = mctl_read_w(MC_CCR);
  280. reg_val &= ~((0x1<<15)|(0x1U<<31));
  281. mctl_write_w(MC_CCR, reg_val);
  282. aw_delay(20);
  283. //aw_delay(0x10);
  284. ********************************************************
  285. */
  286. clrbits_le32(&mctl_com->ccr, MCTL_CCR_CH0_CLK_EN | MCTL_CCR_CH1_CLK_EN);
  287. sdelay(1000);
  288. setbits_le32(&mctl_com->ccr, MCTL_CCR_CH0_CLK_EN);
  289. /* TODO if (para->chan == 2) */
  290. setbits_le32(&mctl_com->ccr, MCTL_CCR_CH1_CLK_EN);
  291. }
  292. static void mctl_com_init(struct dram_sun9i_para *para)
  293. {
  294. struct sunxi_mctl_com_reg * const mctl_com =
  295. (struct sunxi_mctl_com_reg *)SUNXI_DRAM_COM_BASE;
  296. /* TODO: hard-wired for DDR3 now */
  297. writel(((para->chan == 2) ? MCTL_CR_CHANNEL_DUAL :
  298. MCTL_CR_CHANNEL_SINGLE)
  299. | MCTL_CR_DRAMTYPE_DDR3 | MCTL_CR_BANK(1)
  300. | MCTL_CR_ROW(para->rows)
  301. | ((para->bus_width == 32) ? MCTL_CR_BUSW32 : MCTL_CR_BUSW16)
  302. | MCTL_CR_PAGE_SIZE(para->page_size) | MCTL_CR_RANK(para->rank),
  303. &mctl_com->cr);
  304. debug("CR: %d\n", readl(&mctl_com->cr));
  305. }
  306. static u32 mctl_channel_init(u32 ch_index, struct dram_sun9i_para *para)
  307. {
  308. struct sunxi_mctl_ctl_reg *mctl_ctl;
  309. struct sunxi_mctl_phy_reg *mctl_phy;
  310. u32 CL = 0;
  311. u32 CWL = 0;
  312. u16 mr[4] = { 0, };
  313. #define PS2CYCLES_FLOOR(n) ((n * CONFIG_DRAM_CLK) / 1000000)
  314. #define PS2CYCLES_ROUNDUP(n) ((n * CONFIG_DRAM_CLK + 999999) / 1000000)
  315. #define NS2CYCLES_FLOOR(n) ((n * CONFIG_DRAM_CLK) / 1000)
  316. #define NS2CYCLES_ROUNDUP(n) ((n * CONFIG_DRAM_CLK + 999) / 1000)
  317. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  318. /*
  319. * Convert the values to cycle counts (nCK) from what is provided
  320. * by the definition of each speed bin.
  321. */
  322. /* const u32 tREFI = NS2CYCLES_FLOOR(para->tREFI); */
  323. const u32 tREFI = NS2CYCLES_FLOOR(para->tREFI);
  324. const u32 tRFC = NS2CYCLES_ROUNDUP(para->tRFC);
  325. const u32 tRCD = PS2CYCLES_ROUNDUP(para->tRCD);
  326. const u32 tRP = PS2CYCLES_ROUNDUP(para->tRP);
  327. const u32 tRC = PS2CYCLES_ROUNDUP(para->tRC);
  328. const u32 tRAS = PS2CYCLES_ROUNDUP(para->tRAS);
  329. /* command and address timing */
  330. const u32 tDLLK = para->tDLLK;
  331. const u32 tRTP = MAX(para->tRTP.ck, PS2CYCLES_ROUNDUP(para->tRTP.ps));
  332. const u32 tWTR = MAX(para->tWTR.ck, PS2CYCLES_ROUNDUP(para->tWTR.ps));
  333. const u32 tWR = NS2CYCLES_FLOOR(para->tWR);
  334. const u32 tMRD = para->tMRD;
  335. const u32 tMOD = MAX(para->tMOD.ck, PS2CYCLES_ROUNDUP(para->tMOD.ps));
  336. const u32 tCCD = para->tCCD;
  337. const u32 tRRD = MAX(para->tRRD.ck, PS2CYCLES_ROUNDUP(para->tRRD.ps));
  338. const u32 tFAW = PS2CYCLES_ROUNDUP(para->tFAW);
  339. /* calibration timings */
  340. /* const u32 tZQinit = MAX(para->tZQinit.ck,
  341. PS2CYCLES_ROUNDUP(para->tZQinit.ps)); */
  342. const u32 tZQoper = MAX(para->tZQoper.ck,
  343. PS2CYCLES_ROUNDUP(para->tZQoper.ps));
  344. const u32 tZQCS = MAX(para->tZQCS.ck,
  345. PS2CYCLES_ROUNDUP(para->tZQCS.ps));
  346. /* reset timing */
  347. /* const u32 tXPR = MAX(para->tXPR.ck,
  348. PS2CYCLES_ROUNDUP(para->tXPR.ps)); */
  349. /* power-down timings */
  350. const u32 tXP = MAX(para->tXP.ck, PS2CYCLES_ROUNDUP(para->tXP.ps));
  351. const u32 tXPDLL = MAX(para->tXPDLL.ck,
  352. PS2CYCLES_ROUNDUP(para->tXPDLL.ps));
  353. const u32 tCKE = MAX(para->tCKE.ck, PS2CYCLES_ROUNDUP(para->tCKE.ps));
  354. /*
  355. * self-refresh timings (keep below power-down timings, as tCKESR
  356. * needs to be calculated based on the nCK value of tCKE)
  357. */
  358. const u32 tXS = MAX(para->tXS.ck, PS2CYCLES_ROUNDUP(para->tXS.ps));
  359. const u32 tXSDLL = para->tXSDLL;
  360. const u32 tCKSRE = MAX(para->tCKSRE.ck,
  361. PS2CYCLES_ROUNDUP(para->tCKSRE.ps));
  362. const u32 tCKESR = tCKE + 1;
  363. const u32 tCKSRX = MAX(para->tCKSRX.ck,
  364. PS2CYCLES_ROUNDUP(para->tCKSRX.ps));
  365. /* write leveling timings */
  366. const u32 tWLMRD = para->tWLMRD;
  367. /* const u32 tWLDQSEN = para->tWLDQSEN; */
  368. const u32 tWLO = PS2CYCLES_FLOOR(para->tWLO);
  369. /* const u32 tWLOE = PS2CYCLES_FLOOR(para->tWLOE); */
  370. const u32 tRASmax = tREFI * 9;
  371. int i;
  372. for (i = 0; i < para->cl_cwl_numentries; ++i) {
  373. const u32 tCK = 1000000 / CONFIG_DRAM_CLK;
  374. if ((para->cl_cwl_table[i].tCKmin <= tCK) &&
  375. (tCK < para->cl_cwl_table[i].tCKmax)) {
  376. CL = para->cl_cwl_table[i].CL;
  377. CWL = para->cl_cwl_table[i].CWL;
  378. debug("found CL/CWL: CL = %d, CWL = %d\n", CL, CWL);
  379. break;
  380. }
  381. }
  382. if ((CL == 0) && (CWL == 0)) {
  383. printf("failed to find valid CL/CWL for operating point %d MHz\n",
  384. CONFIG_DRAM_CLK);
  385. return 0;
  386. }
  387. if (ch_index == 0) {
  388. mctl_ctl = (struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
  389. mctl_phy = (struct sunxi_mctl_phy_reg *)SUNXI_DRAM_PHY0_BASE;
  390. } else {
  391. mctl_ctl = (struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL1_BASE;
  392. mctl_phy = (struct sunxi_mctl_phy_reg *)SUNXI_DRAM_PHY1_BASE;
  393. }
  394. if (para->dram_type == DRAM_TYPE_DDR3) {
  395. mr[0] = DDR3_MR0_PPD_FAST_EXIT | DDR3_MR0_WR(tWR) |
  396. DDR3_MR0_CL(CL);
  397. mr[1] = DDR3_MR1_RTT120OHM;
  398. mr[2] = DDR3_MR2_TWL(CWL);
  399. mr[3] = 0;
  400. /*
  401. * DRAM3 initialisation requires holding CKE LOW for
  402. * at least 500us prior to starting the initialisation
  403. * sequence and at least 10ns after driving CKE HIGH
  404. * before the initialisation sequence may be started).
  405. *
  406. * Refer to Micron document "TN-41-07: DDR3 Power-Up,
  407. * Initialization, and Reset DDR3 Initialization
  408. * Routine" for details).
  409. */
  410. writel(MCTL_INIT0_POST_CKE_x1024(1) |
  411. MCTL_INIT0_PRE_CKE_x1024(
  412. (500 * CONFIG_DRAM_CLK + 1023) / 1024), /* 500us */
  413. &mctl_ctl->init[0]);
  414. writel(MCTL_INIT1_DRAM_RSTN_x1024(1),
  415. &mctl_ctl->init[1]);
  416. /* INIT2 is not used for DDR3 */
  417. writel(MCTL_INIT3_MR(mr[0]) | MCTL_INIT3_EMR(mr[1]),
  418. &mctl_ctl->init[3]);
  419. writel(MCTL_INIT4_EMR2(mr[2]) | MCTL_INIT4_EMR3(mr[3]),
  420. &mctl_ctl->init[4]);
  421. writel(MCTL_INIT5_DEV_ZQINIT_x32(512 / 32), /* 512 cycles */
  422. &mctl_ctl->init[5]);
  423. } else {
  424. /* !!! UNTESTED !!! */
  425. /*
  426. * LPDDR2 and/or LPDDR3 require a 200us minimum delay
  427. * after driving CKE HIGH in the initialisation sequence.
  428. */
  429. writel(MCTL_INIT0_POST_CKE_x1024(
  430. (200 * CONFIG_DRAM_CLK + 1023) / 1024),
  431. &mctl_ctl->init[0]);
  432. writel(MCTL_INIT1_DRAM_RSTN_x1024(1),
  433. &mctl_ctl->init[1]);
  434. writel(MCTL_INIT2_IDLE_AFTER_RESET_x32(
  435. (CONFIG_DRAM_CLK + 31) / 32) /* 1us */
  436. | MCTL_INIT2_MIN_STABLE_CLOCK_x1(5), /* 5 cycles */
  437. &mctl_ctl->init[2]);
  438. writel(MCTL_INIT3_MR(mr[1]) | MCTL_INIT3_EMR(mr[2]),
  439. &mctl_ctl->init[3]);
  440. writel(MCTL_INIT4_EMR2(mr[3]),
  441. &mctl_ctl->init[4]);
  442. writel(MCTL_INIT5_DEV_ZQINIT_x32(
  443. (CONFIG_DRAM_CLK + 31) / 32) /* 1us */
  444. | MCTL_INIT5_MAX_AUTO_INIT_x1024(
  445. (10 * CONFIG_DRAM_CLK + 1023) / 1024),
  446. &mctl_ctl->init[5]);
  447. }
  448. /* (DDR3) We always use a burst-length of 8. */
  449. #define MCTL_BL 8
  450. /* wr2pre: WL + BL/2 + tWR */
  451. #define WR2PRE (MCTL_BL/2 + CWL + tWTR)
  452. /* wr2rd = CWL + BL/2 + tWTR */
  453. #define WR2RD (MCTL_BL/2 + CWL + tWTR)
  454. /*
  455. * rd2wr = RL + BL/2 + 2 - WL (for DDR3)
  456. * rd2wr = RL + BL/2 + RU(tDQSCKmax/tCK) + 1 - WL (for LPDDR2/LPDDR3)
  457. */
  458. #define RD2WR (CL + MCTL_BL/2 + 2 - CWL)
  459. #define MCTL_PHY_TRTW 0
  460. #define MCTL_PHY_TRTODT 0
  461. #define MCTL_DIV2(n) ((n + 1)/2)
  462. #define MCTL_DIV32(n) (n/32)
  463. #define MCTL_DIV1024(n) (n/1024)
  464. writel((MCTL_DIV2(WR2PRE) << 24) | (MCTL_DIV2(tFAW) << 16) |
  465. (MCTL_DIV1024(tRASmax) << 8) | (MCTL_DIV2(tRAS) << 0),
  466. &mctl_ctl->dramtmg[0]);
  467. writel((MCTL_DIV2(tXP) << 16) | (MCTL_DIV2(tRTP) << 8) |
  468. (MCTL_DIV2(tRC) << 0),
  469. &mctl_ctl->dramtmg[1]);
  470. writel((MCTL_DIV2(CWL) << 24) | (MCTL_DIV2(CL) << 16) |
  471. (MCTL_DIV2(RD2WR) << 8) | (MCTL_DIV2(WR2RD) << 0),
  472. &mctl_ctl->dramtmg[2]);
  473. /*
  474. * Note: tMRW is located at bit 16 (and up) in DRAMTMG3...
  475. * this is only relevant for LPDDR2/LPDDR3
  476. */
  477. writel((MCTL_DIV2(tMRD) << 12) | (MCTL_DIV2(tMOD) << 0),
  478. &mctl_ctl->dramtmg[3]);
  479. writel((MCTL_DIV2(tRCD) << 24) | (MCTL_DIV2(tCCD) << 16) |
  480. (MCTL_DIV2(tRRD) << 8) | (MCTL_DIV2(tRP) << 0),
  481. &mctl_ctl->dramtmg[4]);
  482. writel((MCTL_DIV2(tCKSRX) << 24) | (MCTL_DIV2(tCKSRE) << 16) |
  483. (MCTL_DIV2(tCKESR) << 8) | (MCTL_DIV2(tCKE) << 0),
  484. &mctl_ctl->dramtmg[5]);
  485. /* These timings are relevant for LPDDR2/LPDDR3 only */
  486. /* writel((MCTL_TCKDPDE << 24) | (MCTL_TCKDPX << 16) |
  487. (MCTL_TCKCSX << 0), &mctl_ctl->dramtmg[6]); */
  488. /* printf("DRAMTMG7 reset value: 0x%x\n",
  489. readl(&mctl_ctl->dramtmg[7])); */
  490. /* DRAMTMG7 reset value: 0x202 */
  491. /* DRAMTMG7 should contain t_ckpde and t_ckpdx: check reset values!!! */
  492. /* printf("DRAMTMG8 reset value: 0x%x\n",
  493. readl(&mctl_ctl->dramtmg[8])); */
  494. /* DRAMTMG8 reset value: 0x44 */
  495. writel((MCTL_DIV32(tXSDLL) << 0), &mctl_ctl->dramtmg[8]);
  496. writel((MCTL_DIV32(tREFI) << 16) | (MCTL_DIV2(tRFC) << 0),
  497. &mctl_ctl->rfshtmg);
  498. if (para->dram_type == DRAM_TYPE_DDR3) {
  499. writel((2 << 24) | ((MCTL_DIV2(CL) - 2) << 16) |
  500. (1 << 8) | ((MCTL_DIV2(CWL) - 2) << 0),
  501. &mctl_ctl->dfitmg[0]);
  502. } else {
  503. /* TODO */
  504. }
  505. /* TODO: handle the case of the write latency domain going to 0 ... */
  506. /*
  507. * Disable dfi_init_complete_en (the triggering of the SDRAM
  508. * initialisation when the PHY initialisation completes).
  509. */
  510. clrbits_le32(&mctl_ctl->dfimisc, MCTL_DFIMISC_DFI_INIT_COMPLETE_EN);
  511. /* Disable the automatic generation of DLL calibration requests */
  512. setbits_le32(&mctl_ctl->dfiupd[0], MCTL_DFIUPD0_DIS_AUTO_CTRLUPD);
  513. /* A80-Q7: 2T, 1 rank, DDR3, full-32bit-DQ */
  514. /* TODO: make 2T and BUSWIDTH configurable */
  515. writel(MCTL_MSTR_DEVICETYPE(para->dram_type) |
  516. MCTL_MSTR_BURSTLENGTH(para->dram_type) |
  517. MCTL_MSTR_ACTIVERANKS(para->rank) |
  518. MCTL_MSTR_2TMODE | MCTL_MSTR_BUSWIDTH32,
  519. &mctl_ctl->mstr);
  520. if (para->dram_type == DRAM_TYPE_DDR3) {
  521. writel(MCTL_ZQCTRL0_TZQCL(MCTL_DIV2(tZQoper)) |
  522. (MCTL_DIV2(tZQCS)), &mctl_ctl->zqctrl[0]);
  523. /*
  524. * TODO: is the following really necessary as the bottom
  525. * half should already be 0x100 and the upper half should
  526. * be ignored for a DDR3 device???
  527. */
  528. writel(MCTL_ZQCTRL1_TZQSI_x1024(0x100),
  529. &mctl_ctl->zqctrl[1]);
  530. } else {
  531. writel(MCTL_ZQCTRL0_TZQCL(0x200) | MCTL_ZQCTRL0_TZQCS(0x40),
  532. &mctl_ctl->zqctrl[0]);
  533. writel(MCTL_ZQCTRL1_TZQRESET(0x28) |
  534. MCTL_ZQCTRL1_TZQSI_x1024(0x100),
  535. &mctl_ctl->zqctrl[1]);
  536. }
  537. /* Assert dfi_init_complete signal */
  538. setbits_le32(&mctl_ctl->dfimisc, MCTL_DFIMISC_DFI_INIT_COMPLETE_EN);
  539. /* Disable auto-refresh */
  540. setbits_le32(&mctl_ctl->rfshctl3, MCTL_RFSHCTL3_DIS_AUTO_REFRESH);
  541. /* PHY initialisation */
  542. /* TODO: make 2T and 8-bank mode configurable */
  543. writel(MCTL_PHY_DCR_BYTEMASK | MCTL_PHY_DCR_2TMODE |
  544. MCTL_PHY_DCR_DDR8BNK | MCTL_PHY_DRAMMODE_DDR3,
  545. &mctl_phy->dcr);
  546. /* For LPDDR2 or LPDDR3, set DQSGX to 0 before training. */
  547. if (para->dram_type != DRAM_TYPE_DDR3)
  548. clrbits_le32(&mctl_phy->dsgcr, (3 << 6));
  549. writel(mr[0], &mctl_phy->mr0);
  550. writel(mr[1], &mctl_phy->mr1);
  551. writel(mr[2], &mctl_phy->mr2);
  552. writel(mr[3], &mctl_phy->mr3);
  553. /*
  554. * The DFI PHY is running at full rate. We thus use the actual
  555. * timings in clock cycles here.
  556. */
  557. writel((tRC << 26) | (tRRD << 22) | (tRAS << 16) |
  558. (tRCD << 12) | (tRP << 8) | (tWTR << 4) | (tRTP << 0),
  559. &mctl_phy->dtpr[0]);
  560. writel((tMRD << 0) | ((tMOD - 12) << 2) | (tFAW << 5) |
  561. (tRFC << 11) | (tWLMRD << 20) | (tWLO << 26),
  562. &mctl_phy->dtpr[1]);
  563. writel((tXS << 0) | (MAX(tXP, tXPDLL) << 10) |
  564. (tCKE << 15) | (tDLLK << 19) |
  565. (MCTL_PHY_TRTODT << 29) | (MCTL_PHY_TRTW << 30) |
  566. (((tCCD - 4) & 0x1) << 31),
  567. &mctl_phy->dtpr[2]);
  568. /* tDQSCK and tDQSCKmax are used LPDDR2/LPDDR3 */
  569. /* writel((tDQSCK << 0) | (tDQSCKMAX << 3), &mctl_phy->dtpr[3]); */
  570. /*
  571. * We use the same values used by Allwinner's Boot0 for the PTR
  572. * (PHY timing register) configuration that is tied to the PHY
  573. * implementation.
  574. */
  575. writel(0x42C21590, &mctl_phy->ptr[0]);
  576. writel(0xD05612C0, &mctl_phy->ptr[1]);
  577. if (para->dram_type == DRAM_TYPE_DDR3) {
  578. const unsigned int tdinit0 = 500 * CONFIG_DRAM_CLK; /* 500us */
  579. const unsigned int tdinit1 = (360 * CONFIG_DRAM_CLK + 999) /
  580. 1000; /* 360ns */
  581. const unsigned int tdinit2 = 200 * CONFIG_DRAM_CLK; /* 200us */
  582. const unsigned int tdinit3 = CONFIG_DRAM_CLK; /* 1us */
  583. writel((tdinit1 << 20) | tdinit0, &mctl_phy->ptr[3]);
  584. writel((tdinit3 << 18) | tdinit2, &mctl_phy->ptr[4]);
  585. } else {
  586. /* LPDDR2 or LPDDR3 */
  587. const unsigned int tdinit0 = (100 * CONFIG_DRAM_CLK + 999) /
  588. 1000; /* 100ns */
  589. const unsigned int tdinit1 = 200 * CONFIG_DRAM_CLK; /* 200us */
  590. const unsigned int tdinit2 = 22 * CONFIG_DRAM_CLK; /* 11us */
  591. const unsigned int tdinit3 = 2 * CONFIG_DRAM_CLK; /* 2us */
  592. writel((tdinit1 << 20) | tdinit0, &mctl_phy->ptr[3]);
  593. writel((tdinit3 << 18) | tdinit2, &mctl_phy->ptr[4]);
  594. }
  595. /* TEST ME */
  596. writel(0x00203131, &mctl_phy->acmdlr);
  597. /* TODO: can we enable this for 2 ranks, even when we don't know yet */
  598. writel(MCTL_DTCR_DEFAULT | MCTL_DTCR_RANKEN(para->rank),
  599. &mctl_phy->dtcr);
  600. /* TODO: half width */
  601. debug("DX2GCR0 reset: 0x%x\n", readl(&mctl_phy->dx[2].gcr[0]));
  602. writel(0x7C000285, &mctl_phy->dx[2].gcr[0]);
  603. writel(0x7C000285, &mctl_phy->dx[3].gcr[0]);
  604. clrsetbits_le32(&mctl_phy->zq[0].pr, 0xff,
  605. (CONFIG_DRAM_ZQ >> 0) & 0xff); /* CK/CA */
  606. clrsetbits_le32(&mctl_phy->zq[1].pr, 0xff,
  607. (CONFIG_DRAM_ZQ >> 8) & 0xff); /* DX0/DX1 */
  608. clrsetbits_le32(&mctl_phy->zq[2].pr, 0xff,
  609. (CONFIG_DRAM_ZQ >> 16) & 0xff); /* DX2/DX3 */
  610. /* TODO: make configurable & implement non-ODT path */
  611. if (1) {
  612. int lane;
  613. for (lane = 0; lane < 4; ++lane) {
  614. clrbits_le32(&mctl_phy->dx[lane].gcr[2], 0xffff);
  615. clrbits_le32(&mctl_phy->dx[lane].gcr[3],
  616. (0x3<<12) | (0x3<<4));
  617. }
  618. } else {
  619. /* TODO: check */
  620. int lane;
  621. for (lane = 0; lane < 4; ++lane) {
  622. clrsetbits_le32(&mctl_phy->dx[lane].gcr[2], 0xffff,
  623. 0xaaaa);
  624. if (para->dram_type == DRAM_TYPE_DDR3)
  625. setbits_le32(&mctl_phy->dx[lane].gcr[3],
  626. (0x3<<12) | (0x3<<4));
  627. else
  628. setbits_le32(&mctl_phy->dx[lane].gcr[3],
  629. 0x00000012);
  630. }
  631. }
  632. writel(0x04058D02, &mctl_phy->zq[0].cr); /* CK/CA */
  633. writel(0x04058D02, &mctl_phy->zq[1].cr); /* DX0/DX1 */
  634. writel(0x04058D02, &mctl_phy->zq[2].cr); /* DX2/DX3 */
  635. /* Disable auto-refresh prior to data training */
  636. setbits_le32(&mctl_ctl->rfshctl3, MCTL_RFSHCTL3_DIS_AUTO_REFRESH);
  637. setbits_le32(&mctl_phy->dsgcr, 0xf << 24); /* unclear what this is... */
  638. /* TODO: IODDRM (IO DDR-MODE) for DDR3L */
  639. clrsetbits_le32(&mctl_phy->pgcr[1],
  640. MCTL_PGCR1_ZCKSEL_MASK,
  641. MCTL_PGCR1_IODDRM_DDR3 | MCTL_PGCR1_INHVT_EN);
  642. setbits_le32(&mctl_phy->pllcr, 0x3 << 19); /* PLL frequency select */
  643. /* TODO: single-channel PLL mode??? missing */
  644. setbits_le32(&mctl_phy->pllcr,
  645. MCTL_PLLGCR_PLL_BYPASS | MCTL_PLLGCR_PLL_POWERDOWN);
  646. /* setbits_le32(&mctl_phy->pir, MCTL_PIR_PLL_BYPASS); included below */
  647. /* Disable VT compensation */
  648. clrbits_le32(&mctl_phy->pgcr[0], 0x3f);
  649. /* TODO: "other" PLL mode ... 0x20000 seems to be the PLL Bypass */
  650. if (para->dram_type == DRAM_TYPE_DDR3)
  651. clrsetbits_le32(&mctl_phy->pir, MCTL_PIR_MASK, 0x20df3);
  652. else
  653. clrsetbits_le32(&mctl_phy->pir, MCTL_PIR_MASK, 0x2c573);
  654. sdelay(10000); /* XXX necessary? */
  655. /* Wait for the INIT bit to clear itself... */
  656. while ((readl(&mctl_phy->pir) & MCTL_PIR_INIT) != MCTL_PIR_INIT) {
  657. /* not done yet -- keep spinning */
  658. debug("MCTL_PIR_INIT not set\n");
  659. sdelay(1000);
  660. /* TODO: implement timeout */
  661. }
  662. /* TODO: not used --- there's a "2rank debug" section here */
  663. /* Original dram init code which may come in handy later
  664. ********************************************************
  665. * LPDDR2 and LPDDR3 *
  666. if ((para->dram_type) == 6 || (para->dram_type) == 7) {
  667. reg_val = mctl_read_w(P0_DSGCR + ch_offset);
  668. reg_val &= (~(0x3<<6)); * set DQSGX to 1 *
  669. reg_val |= (0x1<<6); * dqs gate extend *
  670. mctl_write_w(P0_DSGCR + ch_offset, reg_val);
  671. dram_dbg("DQS Gate Extend Enable!\n", ch_index);
  672. }
  673. * Disable ZCAL after initial--for nand dma debug--20140330 by YSZ *
  674. if (para->dram_tpr13 & (0x1<<31)) {
  675. reg_val = mctl_read_w(P0_ZQ0CR + ch_offset);
  676. reg_val |= (0x7<<11);
  677. mctl_write_w(P0_ZQ0CR + ch_offset, reg_val);
  678. }
  679. ********************************************************
  680. */
  681. /*
  682. * TODO: more 2-rank support
  683. * (setting the "dqs gate delay to average between 2 rank")
  684. */
  685. /* check if any errors are set */
  686. if (readl(&mctl_phy->pgsr[0]) & MCTL_PGSR0_ERRORS) {
  687. debug("Channel %d unavailable!\n", ch_index);
  688. return 0;
  689. } else{
  690. /* initial OK */
  691. debug("Channel %d OK!\n", ch_index);
  692. /* return 1; */
  693. }
  694. while ((readl(&mctl_ctl->stat) & 0x1) != 0x1) {
  695. debug("Waiting for INIT to be done (controller to come up into 'normal operating' mode\n");
  696. sdelay(100000);
  697. /* init not done */
  698. /* TODO: implement time-out */
  699. }
  700. debug("done\n");
  701. /* "DDR is controller by contoller" */
  702. clrbits_le32(&mctl_phy->pgcr[3], (1 << 25));
  703. /* TODO: is the following necessary? */
  704. debug("DFIMISC before writing 0: 0x%x\n", readl(&mctl_ctl->dfimisc));
  705. writel(0, &mctl_ctl->dfimisc);
  706. /* Enable auto-refresh */
  707. clrbits_le32(&mctl_ctl->rfshctl3, MCTL_RFSHCTL3_DIS_AUTO_REFRESH);
  708. debug("channel_init complete\n");
  709. return 1;
  710. }
  711. signed int DRAMC_get_dram_size(void)
  712. {
  713. struct sunxi_mctl_com_reg * const mctl_com =
  714. (struct sunxi_mctl_com_reg *)SUNXI_DRAM_COM_BASE;
  715. unsigned int reg_val;
  716. unsigned int dram_size;
  717. unsigned int temp;
  718. reg_val = readl(&mctl_com->cr);
  719. temp = (reg_val >> 8) & 0xf; /* page size code */
  720. dram_size = (temp - 6); /* (1 << dram_size) * 512Bytes */
  721. temp = (reg_val >> 4) & 0xf; /* row width code */
  722. dram_size += (temp + 1); /* (1 << dram_size) * 512Bytes */
  723. temp = (reg_val >> 2) & 0x3; /* bank number code */
  724. dram_size += (temp + 2); /* (1 << dram_size) * 512Bytes */
  725. temp = reg_val & 0x3; /* rank number code */
  726. dram_size += temp; /* (1 << dram_size) * 512Bytes */
  727. temp = (reg_val >> 19) & 0x1; /* channel number code */
  728. dram_size += temp; /* (1 << dram_size) * 512Bytes */
  729. dram_size = dram_size - 11; /* (1 << dram_size) MBytes */
  730. return 1 << dram_size;
  731. }
  732. unsigned long sunxi_dram_init(void)
  733. {
  734. struct sunxi_mctl_com_reg * const mctl_com =
  735. (struct sunxi_mctl_com_reg *)SUNXI_DRAM_COM_BASE;
  736. struct dram_sun9i_cl_cwl_timing cl_cwl[] = {
  737. { .CL = 5, .CWL = 5, .tCKmin = 3000, .tCKmax = 3300 },
  738. { .CL = 6, .CWL = 5, .tCKmin = 2500, .tCKmax = 3300 },
  739. { .CL = 8, .CWL = 6, .tCKmin = 1875, .tCKmax = 2500 },
  740. { .CL = 10, .CWL = 7, .tCKmin = 1500, .tCKmax = 1875 },
  741. { .CL = 11, .CWL = 8, .tCKmin = 1250, .tCKmax = 1500 }
  742. };
  743. /* Set initial parameters, these get modified by the autodetect code */
  744. struct dram_sun9i_para para = {
  745. .dram_type = DRAM_TYPE_DDR3,
  746. .bus_width = 32,
  747. .chan = 2,
  748. .rank = 1,
  749. /* .rank = 2, */
  750. .page_size = 4096,
  751. /* .rows = 16, */
  752. .rows = 15,
  753. /* CL/CWL table for the speed bin */
  754. .cl_cwl_table = cl_cwl,
  755. .cl_cwl_numentries = sizeof(cl_cwl) /
  756. sizeof(struct dram_sun9i_cl_cwl_timing),
  757. /* timings */
  758. .tREFI = 7800, /* 7.8us (up to 85 degC) */
  759. .tRFC = 260, /* 260ns for 4GBit devices */
  760. /* 350ns @ 8GBit */
  761. .tRCD = 13750,
  762. .tRP = 13750,
  763. .tRC = 48750,
  764. .tRAS = 35000,
  765. .tDLLK = 512,
  766. .tRTP = { .ck = 4, .ps = 7500 },
  767. .tWTR = { .ck = 4, .ps = 7500 },
  768. .tWR = 15,
  769. .tMRD = 4,
  770. .tMOD = { .ck = 12, .ps = 15000 },
  771. .tCCD = 4,
  772. .tRRD = { .ck = 4, .ps = 7500 },
  773. .tFAW = 40,
  774. /* calibration timing */
  775. /* .tZQinit = { .ck = 512, .ps = 640000 }, */
  776. .tZQoper = { .ck = 256, .ps = 320000 },
  777. .tZQCS = { .ck = 64, .ps = 80000 },
  778. /* reset timing */
  779. /* .tXPR = { .ck = 5, .ps = 10000 }, */
  780. /* self-refresh timings */
  781. .tXS = { .ck = 5, .ps = 10000 },
  782. .tXSDLL = 512,
  783. .tCKSRE = { .ck = 5, .ps = 10000 },
  784. .tCKSRX = { .ck = 5, .ps = 10000 },
  785. /* power-down timings */
  786. .tXP = { .ck = 3, .ps = 6000 },
  787. .tXPDLL = { .ck = 10, .ps = 24000 },
  788. .tCKE = { .ck = 3, .ps = 5000 },
  789. /* write leveling timings */
  790. .tWLMRD = 40,
  791. /* .tWLDQSEN = 25, */
  792. .tWLO = 7500,
  793. /* .tWLOE = 2000, */
  794. };
  795. /*
  796. * Disable A80 internal 240 ohm resistor.
  797. *
  798. * This code sequence is adapated from Allwinner's Boot0 (see
  799. * https://github.com/allwinner-zh/bootloader.git), as there
  800. * is no documentation for these two registers in the R_PRCM
  801. * block.
  802. */
  803. setbits_le32(SUNXI_PRCM_BASE + 0x1e0, (0x3 << 8));
  804. writel(0, SUNXI_PRCM_BASE + 0x1e8);
  805. mctl_sys_init();
  806. if (!mctl_channel_init(0, &para))
  807. return 0;
  808. /* dual-channel */
  809. if (!mctl_channel_init(1, &para)) {
  810. /* disable channel 1 */
  811. clrsetbits_le32(&mctl_com->cr, MCTL_CR_CHANNEL_MASK,
  812. MCTL_CR_CHANNEL_SINGLE);
  813. /* disable channel 1 global clock */
  814. clrbits_le32(&mctl_com->cr, MCTL_CCR_CH1_CLK_EN);
  815. }
  816. mctl_com_init(&para);
  817. /* return the proper RAM size */
  818. return DRAMC_get_dram_size() << 20;
  819. }