ctrl_regs.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 as published by the Free Software Foundation.
  7. */
  8. /*
  9. * Generic driver for Freescale DDR/DDR2/DDR3 memory controller.
  10. * Based on code from spd_sdram.c
  11. * Author: James Yang [at freescale.com]
  12. */
  13. #include <common.h>
  14. #include <asm/fsl_ddr_sdram.h>
  15. #include "ddr.h"
  16. extern unsigned int picos_to_mclk(unsigned int picos);
  17. /*
  18. * Determine Rtt value.
  19. *
  20. * This should likely be either board or controller specific.
  21. *
  22. * Rtt(nominal):
  23. * 0 = Rtt disabled
  24. * 1 = 75 ohm
  25. * 2 = 150 ohm
  26. * 3 = 50 ohm
  27. *
  28. * FIXME: Apparently 8641 needs a value of 2
  29. * FIXME: Old code seys if 667 MHz or higher, use 3 on 8572
  30. *
  31. * FIXME: There was some effort down this line earlier:
  32. *
  33. * unsigned int i;
  34. * for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL/2; i++) {
  35. * if (popts->dimmslot[i].num_valid_cs
  36. * && (popts->cs_local_opts[2*i].odt_rd_cfg
  37. * || popts->cs_local_opts[2*i].odt_wr_cfg)) {
  38. * rtt = 2;
  39. * break;
  40. * }
  41. * }
  42. */
  43. static inline int fsl_ddr_get_rtt(void)
  44. {
  45. int rtt;
  46. #if defined(CONFIG_FSL_DDR1)
  47. rtt = 0;
  48. #elif defined(CONFIG_FSL_DDR2)
  49. rtt = 3;
  50. #else
  51. #error "Need Rtt value for DDR3"
  52. #endif
  53. return rtt;
  54. }
  55. /* Chip Select Configuration (CSn_CONFIG) */
  56. static void set_csn_config(int i, fsl_ddr_cfg_regs_t *ddr,
  57. const memctl_options_t *popts,
  58. const dimm_params_t *dimm_params)
  59. {
  60. unsigned int cs_n_en = 0; /* Chip Select enable */
  61. unsigned int intlv_en = 0; /* Memory controller interleave enable */
  62. unsigned int intlv_ctl = 0; /* Interleaving control */
  63. unsigned int ap_n_en = 0; /* Chip select n auto-precharge enable */
  64. unsigned int odt_rd_cfg = 0; /* ODT for reads configuration */
  65. unsigned int odt_wr_cfg = 0; /* ODT for writes configuration */
  66. unsigned int ba_bits_cs_n = 0; /* Num of bank bits for SDRAM on CSn */
  67. unsigned int row_bits_cs_n = 0; /* Num of row bits for SDRAM on CSn */
  68. unsigned int col_bits_cs_n = 0; /* Num of ocl bits for SDRAM on CSn */
  69. /* Compute CS_CONFIG only for existing ranks of each DIMM. */
  70. if ((((i&1) == 0)
  71. && (dimm_params[i/2].n_ranks == 1))
  72. || (dimm_params[i/2].n_ranks == 2)) {
  73. unsigned int n_banks_per_sdram_device;
  74. cs_n_en = 1;
  75. if (i == 0) {
  76. /* These fields only available in CS0_CONFIG */
  77. intlv_en = popts->memctl_interleaving;
  78. intlv_ctl = popts->memctl_interleaving_mode;
  79. }
  80. ap_n_en = popts->cs_local_opts[i].auto_precharge;
  81. odt_rd_cfg = popts->cs_local_opts[i].odt_rd_cfg;
  82. odt_wr_cfg = popts->cs_local_opts[i].odt_wr_cfg;
  83. n_banks_per_sdram_device
  84. = dimm_params[i/2].n_banks_per_sdram_device;
  85. ba_bits_cs_n = __ilog2(n_banks_per_sdram_device) - 2;
  86. row_bits_cs_n = dimm_params[i/2].n_row_addr - 12;
  87. col_bits_cs_n = dimm_params[i/2].n_col_addr - 8;
  88. }
  89. ddr->cs[i].config = (0
  90. | ((cs_n_en & 0x1) << 31)
  91. | ((intlv_en & 0x3) << 29)
  92. | ((intlv_ctl & 0xf) << 24)
  93. | ((ap_n_en & 0x1) << 23)
  94. /* XXX: some implementation only have 1 bit starting at left */
  95. | ((odt_rd_cfg & 0x7) << 20)
  96. /* XXX: Some implementation only have 1 bit starting at left */
  97. | ((odt_wr_cfg & 0x7) << 16)
  98. | ((ba_bits_cs_n & 0x3) << 14)
  99. | ((row_bits_cs_n & 0x7) << 8)
  100. | ((col_bits_cs_n & 0x7) << 0)
  101. );
  102. debug("FSLDDR: cs[%d]_config = 0x%08x\n", i,ddr->cs[i].config);
  103. }
  104. /* Chip Select Configuration 2 (CSn_CONFIG_2) */
  105. /* FIXME: 8572 */
  106. static void set_csn_config_2(int i, fsl_ddr_cfg_regs_t *ddr)
  107. {
  108. unsigned int pasr_cfg = 0; /* Partial array self refresh config */
  109. ddr->cs[i].config_2 = ((pasr_cfg & 7) << 24);
  110. debug("FSLDDR: cs[%d]_config_2 = 0x%08x\n", i, ddr->cs[i].config_2);
  111. }
  112. /* -3E = 667 CL5, -25 = CL6 800, -25E = CL5 800 */
  113. #if defined(CONFIG_FSL_DDR2)
  114. /*
  115. * DDR SDRAM Timing Configuration 0 (TIMING_CFG_0)
  116. *
  117. * Avoid writing for DDR I. The new PQ38 DDR controller
  118. * dreams up non-zero default values to be backwards compatible.
  119. */
  120. static void set_timing_cfg_0(fsl_ddr_cfg_regs_t *ddr)
  121. {
  122. unsigned char trwt_mclk = 0; /* Read-to-write turnaround */
  123. unsigned char twrt_mclk = 0; /* Write-to-read turnaround */
  124. /* 7.5 ns on -3E; 0 means WL - CL + BL/2 + 1 */
  125. unsigned char trrt_mclk = 0; /* Read-to-read turnaround */
  126. unsigned char twwt_mclk = 0; /* Write-to-write turnaround */
  127. /* Active powerdown exit timing (tXARD and tXARDS). */
  128. unsigned char act_pd_exit_mclk;
  129. /* Precharge powerdown exit timing (tXP). */
  130. unsigned char pre_pd_exit_mclk;
  131. /* Precharge powerdown exit timing (tAXPD). */
  132. unsigned char taxpd_mclk;
  133. /* Mode register set cycle time (tMRD). */
  134. unsigned char tmrd_mclk;
  135. /* (tXARD and tXARDS). Empirical? */
  136. act_pd_exit_mclk = 2;
  137. /* XXX: tXARD = 2, tXARDS = 7 - AL. * Empirical? */
  138. pre_pd_exit_mclk = 6;
  139. /* FIXME: tXP = 2 on Micron 667 MHz DIMM */
  140. taxpd_mclk = 8;
  141. tmrd_mclk = 2;
  142. ddr->timing_cfg_0 = (0
  143. | ((trwt_mclk & 0x3) << 30) /* RWT */
  144. | ((twrt_mclk & 0x3) << 28) /* WRT */
  145. | ((trrt_mclk & 0x3) << 26) /* RRT */
  146. | ((twwt_mclk & 0x3) << 24) /* WWT */
  147. | ((act_pd_exit_mclk & 0x7) << 20) /* ACT_PD_EXIT */
  148. | ((pre_pd_exit_mclk & 0xF) << 16) /* PRE_PD_EXIT */
  149. | ((taxpd_mclk & 0xf) << 8) /* ODT_PD_EXIT */
  150. | ((tmrd_mclk & 0xf) << 0) /* MRS_CYC */
  151. );
  152. debug("FSLDDR: timing_cfg_0 = 0x%08x\n", ddr->timing_cfg_0);
  153. }
  154. #endif /* defined(CONFIG_FSL_DDR2) */
  155. /* DDR SDRAM Timing Configuration 3 (TIMING_CFG_3) */
  156. static void set_timing_cfg_3(fsl_ddr_cfg_regs_t *ddr,
  157. const common_timing_params_t *common_dimm)
  158. {
  159. /* Extended Activate to precharge interval (tRAS) */
  160. unsigned int ext_acttopre = 0;
  161. unsigned int ext_refrec; /* Extended refresh recovery time (tRFC) */
  162. unsigned int ext_caslat = 0; /* Extended MCAS latency from READ cmd */
  163. unsigned int cntl_adj = 0; /* Control Adjust */
  164. /* If the tRAS > 19 MCLK, we use the ext mode */
  165. if (picos_to_mclk(common_dimm->tRAS_ps) > 0x13)
  166. ext_acttopre = 1;
  167. ext_refrec = (picos_to_mclk(common_dimm->tRFC_ps) - 8) >> 4;
  168. ddr->timing_cfg_3 = (0
  169. | ((ext_acttopre & 0x1) << 24)
  170. | ((ext_refrec & 0xF) << 16)
  171. | ((ext_caslat & 0x1) << 12)
  172. | ((cntl_adj & 0x7) << 0)
  173. );
  174. debug("FSLDDR: timing_cfg_3 = 0x%08x\n", ddr->timing_cfg_3);
  175. }
  176. /* DDR SDRAM Timing Configuration 1 (TIMING_CFG_1) */
  177. static void set_timing_cfg_1(fsl_ddr_cfg_regs_t *ddr,
  178. const common_timing_params_t *common_dimm,
  179. unsigned int cas_latency)
  180. {
  181. /* Precharge-to-activate interval (tRP) */
  182. unsigned char pretoact_mclk;
  183. /* Activate to precharge interval (tRAS) */
  184. unsigned char acttopre_mclk;
  185. /* Activate to read/write interval (tRCD) */
  186. unsigned char acttorw_mclk;
  187. /* CASLAT */
  188. unsigned char caslat_ctrl;
  189. /* Refresh recovery time (tRFC) ; trfc_low */
  190. unsigned char refrec_ctrl;
  191. /* Last data to precharge minimum interval (tWR) */
  192. unsigned char wrrec_mclk;
  193. /* Activate-to-activate interval (tRRD) */
  194. unsigned char acttoact_mclk;
  195. /* Last write data pair to read command issue interval (tWTR) */
  196. unsigned char wrtord_mclk;
  197. pretoact_mclk = picos_to_mclk(common_dimm->tRP_ps);
  198. acttopre_mclk = picos_to_mclk(common_dimm->tRAS_ps);
  199. acttorw_mclk = picos_to_mclk(common_dimm->tRCD_ps);
  200. /*
  201. * Translate CAS Latency to a DDR controller field value:
  202. *
  203. * CAS Lat DDR I DDR II Ctrl
  204. * Clocks SPD Bit SPD Bit Value
  205. * ------- ------- ------- -----
  206. * 1.0 0 0001
  207. * 1.5 1 0010
  208. * 2.0 2 2 0011
  209. * 2.5 3 0100
  210. * 3.0 4 3 0101
  211. * 3.5 5 0110
  212. * 4.0 4 0111
  213. * 4.5 1000
  214. * 5.0 5 1001
  215. */
  216. #if defined(CONFIG_FSL_DDR1)
  217. caslat_ctrl = (cas_latency + 1) & 0x07;
  218. #elif defined(CONFIG_FSL_DDR2)
  219. caslat_ctrl = 2 * cas_latency - 1;
  220. #else
  221. #error "Need CAS Latency help for DDR3 in fsl_ddr_sdram.c"
  222. #endif
  223. refrec_ctrl = picos_to_mclk(common_dimm->tRFC_ps) - 8;
  224. wrrec_mclk = picos_to_mclk(common_dimm->tWR_ps);
  225. acttoact_mclk = picos_to_mclk(common_dimm->tRRD_ps);
  226. wrtord_mclk = picos_to_mclk(common_dimm->tWTR_ps);
  227. ddr->timing_cfg_1 = (0
  228. | ((pretoact_mclk & 0x0F) << 28)
  229. | ((acttopre_mclk & 0x0F) << 24)
  230. | ((acttorw_mclk & 0xF) << 20)
  231. | ((caslat_ctrl & 0xF) << 16)
  232. | ((refrec_ctrl & 0xF) << 12)
  233. | ((wrrec_mclk & 0x0F) << 8)
  234. | ((acttoact_mclk & 0x07) << 4)
  235. | ((wrtord_mclk & 0x07) << 0)
  236. );
  237. debug("FSLDDR: timing_cfg_1 = 0x%08x\n", ddr->timing_cfg_1);
  238. }
  239. /* DDR SDRAM Timing Configuration 2 (TIMING_CFG_2) */
  240. static void set_timing_cfg_2(fsl_ddr_cfg_regs_t *ddr,
  241. const memctl_options_t *popts,
  242. const common_timing_params_t *common_dimm,
  243. unsigned int cas_latency,
  244. unsigned int additive_latency)
  245. {
  246. /* Additive latency */
  247. unsigned char add_lat_mclk;
  248. /* CAS-to-preamble override */
  249. unsigned short cpo;
  250. /* Write latency */
  251. unsigned char wr_lat;
  252. /* Read to precharge (tRTP) */
  253. unsigned char rd_to_pre;
  254. /* Write command to write data strobe timing adjustment */
  255. unsigned char wr_data_delay;
  256. /* Minimum CKE pulse width (tCKE) */
  257. unsigned char cke_pls;
  258. /* Window for four activates (tFAW) */
  259. unsigned short four_act;
  260. /* FIXME add check that this must be less than acttorw_mclk */
  261. add_lat_mclk = additive_latency;
  262. cpo = popts->cpo_override;
  263. #if defined(CONFIG_FSL_DDR1)
  264. /*
  265. * This is a lie. It should really be 1, but if it is
  266. * set to 1, bits overlap into the old controller's
  267. * otherwise unused ACSM field. If we leave it 0, then
  268. * the HW will magically treat it as 1 for DDR 1. Oh Yea.
  269. */
  270. wr_lat = 0;
  271. #elif defined(CONFIG_FSL_DDR2)
  272. wr_lat = cas_latency - 1;
  273. #else
  274. #error "Fix WR_LAT for DDR3"
  275. #endif
  276. rd_to_pre = picos_to_mclk(common_dimm->tRTP_ps);
  277. #if defined(CONFIG_FSL_DDR2)
  278. rd_to_pre += additive_latency;
  279. #endif
  280. wr_data_delay = popts->write_data_delay;
  281. cke_pls = picos_to_mclk(popts->tCKE_clock_pulse_width_ps);
  282. four_act = picos_to_mclk(popts->tFAW_window_four_activates_ps);
  283. ddr->timing_cfg_2 = (0
  284. | ((add_lat_mclk & 0xf) << 28)
  285. | ((cpo & 0x1f) << 23)
  286. | ((wr_lat & 0xf) << 19)
  287. | ((rd_to_pre & 0x7) << 13)
  288. | ((wr_data_delay & 0x7) << 10)
  289. | ((cke_pls & 0x7) << 6)
  290. | ((four_act & 0x3f) << 0)
  291. );
  292. debug("FSLDDR: timing_cfg_2 = 0x%08x\n", ddr->timing_cfg_2);
  293. }
  294. /* DDR SDRAM control configuration (DDR_SDRAM_CFG) */
  295. static void set_ddr_sdram_cfg(fsl_ddr_cfg_regs_t *ddr,
  296. const memctl_options_t *popts,
  297. const common_timing_params_t *common_dimm)
  298. {
  299. unsigned int mem_en; /* DDR SDRAM interface logic enable */
  300. unsigned int sren; /* Self refresh enable (during sleep) */
  301. unsigned int ecc_en; /* ECC enable. */
  302. unsigned int rd_en; /* Registered DIMM enable */
  303. unsigned int sdram_type; /* Type of SDRAM */
  304. unsigned int dyn_pwr; /* Dynamic power management mode */
  305. unsigned int dbw; /* DRAM dta bus width */
  306. unsigned int eight_be = 0; /* 8-beat burst enable, DDR2 is zero */
  307. unsigned int ncap = 0; /* Non-concurrent auto-precharge */
  308. unsigned int threeT_en; /* Enable 3T timing */
  309. unsigned int twoT_en; /* Enable 2T timing */
  310. unsigned int ba_intlv_ctl; /* Bank (CS) interleaving control */
  311. unsigned int x32_en = 0; /* x32 enable */
  312. unsigned int pchb8 = 0; /* precharge bit 8 enable */
  313. unsigned int hse; /* Global half strength override */
  314. unsigned int mem_halt = 0; /* memory controller halt */
  315. unsigned int bi = 0; /* Bypass initialization */
  316. mem_en = 1;
  317. sren = popts->self_refresh_in_sleep;
  318. if (common_dimm->all_DIMMs_ECC_capable) {
  319. /* Allow setting of ECC only if all DIMMs are ECC. */
  320. ecc_en = popts->ECC_mode;
  321. } else {
  322. ecc_en = 0;
  323. }
  324. rd_en = (common_dimm->all_DIMMs_registered
  325. && !common_dimm->all_DIMMs_unbuffered);
  326. sdram_type = CONFIG_FSL_SDRAM_TYPE;
  327. dyn_pwr = popts->dynamic_power;
  328. dbw = popts->data_bus_width;
  329. /* DDR3 must use 8-beat bursts when using 32-bit bus mode */
  330. if ((sdram_type == SDRAM_TYPE_DDR3) && (dbw == 0x1))
  331. eight_be = 1;
  332. threeT_en = popts->threeT_en;
  333. twoT_en = popts->twoT_en;
  334. ba_intlv_ctl = popts->ba_intlv_ctl;
  335. hse = popts->half_strength_driver_enable;
  336. ddr->ddr_sdram_cfg = (0
  337. | ((mem_en & 0x1) << 31)
  338. | ((sren & 0x1) << 30)
  339. | ((ecc_en & 0x1) << 29)
  340. | ((rd_en & 0x1) << 28)
  341. | ((sdram_type & 0x7) << 24)
  342. | ((dyn_pwr & 0x1) << 21)
  343. | ((dbw & 0x3) << 19)
  344. | ((eight_be & 0x1) << 18)
  345. | ((ncap & 0x1) << 17)
  346. | ((threeT_en & 0x1) << 16)
  347. | ((twoT_en & 0x1) << 15)
  348. | ((ba_intlv_ctl & 0x7F) << 8)
  349. | ((x32_en & 0x1) << 5)
  350. | ((pchb8 & 0x1) << 4)
  351. | ((hse & 0x1) << 3)
  352. | ((mem_halt & 0x1) << 1)
  353. | ((bi & 0x1) << 0)
  354. );
  355. debug("FSLDDR: ddr_sdram_cfg = 0x%08x\n", ddr->ddr_sdram_cfg);
  356. }
  357. /* DDR SDRAM control configuration 2 (DDR_SDRAM_CFG_2) */
  358. static void set_ddr_sdram_cfg_2(fsl_ddr_cfg_regs_t *ddr,
  359. const memctl_options_t *popts)
  360. {
  361. unsigned int frc_sr = 0; /* Force self refresh */
  362. unsigned int sr_ie = 0; /* Self-refresh interrupt enable */
  363. unsigned int dll_rst_dis; /* DLL reset disable */
  364. unsigned int dqs_cfg; /* DQS configuration */
  365. unsigned int odt_cfg; /* ODT configuration */
  366. unsigned int num_pr; /* Number of posted refreshes */
  367. unsigned int obc_cfg; /* On-The-Fly Burst Chop Cfg */
  368. unsigned int ap_en; /* Address Parity Enable */
  369. unsigned int d_init; /* DRAM data initialization */
  370. unsigned int rcw_en = 0; /* Register Control Word Enable */
  371. unsigned int md_en = 0; /* Mirrored DIMM Enable */
  372. dll_rst_dis = 1; /* Make this configurable */
  373. dqs_cfg = popts->DQS_config;
  374. if (popts->cs_local_opts[0].odt_rd_cfg
  375. || popts->cs_local_opts[0].odt_wr_cfg) {
  376. /* FIXME */
  377. odt_cfg = 2;
  378. } else {
  379. odt_cfg = 0;
  380. }
  381. num_pr = 1; /* Make this configurable */
  382. /*
  383. * 8572 manual says
  384. * {TIMING_CFG_1[PRETOACT]
  385. * + [DDR_SDRAM_CFG_2[NUM_PR]
  386. * * ({EXT_REFREC || REFREC} + 8 + 2)]}
  387. * << DDR_SDRAM_INTERVAL[REFINT]
  388. */
  389. obc_cfg = 0; /* Make this configurable? */
  390. ap_en = 0; /* Make this configurable? */
  391. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  392. /* Use the DDR controller to auto initialize memory. */
  393. d_init = 1;
  394. ddr->ddr_data_init = CONFIG_MEM_INIT_VALUE;
  395. debug("DDR: ddr_data_init = 0x%08x\n", ddr->ddr_data_init);
  396. #else
  397. /* Memory will be initialized via DMA, or not at all. */
  398. d_init = 0;
  399. #endif
  400. ddr->ddr_sdram_cfg_2 = (0
  401. | ((frc_sr & 0x1) << 31)
  402. | ((sr_ie & 0x1) << 30)
  403. | ((dll_rst_dis & 0x1) << 29)
  404. | ((dqs_cfg & 0x3) << 26)
  405. | ((odt_cfg & 0x3) << 21)
  406. | ((num_pr & 0xf) << 12)
  407. | ((obc_cfg & 0x1) << 6)
  408. | ((ap_en & 0x1) << 5)
  409. | ((d_init & 0x1) << 4)
  410. | ((rcw_en & 0x1) << 2)
  411. | ((md_en & 0x1) << 0)
  412. );
  413. debug("FSLDDR: ddr_sdram_cfg_2 = 0x%08x\n", ddr->ddr_sdram_cfg_2);
  414. }
  415. /* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
  416. static void set_ddr_sdram_mode_2(fsl_ddr_cfg_regs_t *ddr)
  417. {
  418. unsigned short esdmode2 = 0; /* Extended SDRAM mode 2 */
  419. unsigned short esdmode3 = 0; /* Extended SDRAM mode 3 */
  420. ddr->ddr_sdram_mode_2 = (0
  421. | ((esdmode2 & 0xFFFF) << 16)
  422. | ((esdmode3 & 0xFFFF) << 0)
  423. );
  424. debug("FSLDDR: ddr_sdram_mode_2 = 0x%08x\n", ddr->ddr_sdram_mode_2);
  425. }
  426. /* DDR SDRAM Interval Configuration (DDR_SDRAM_INTERVAL) */
  427. static void set_ddr_sdram_interval(fsl_ddr_cfg_regs_t *ddr,
  428. const memctl_options_t *popts,
  429. const common_timing_params_t *common_dimm)
  430. {
  431. unsigned int refint; /* Refresh interval */
  432. unsigned int bstopre; /* Precharge interval */
  433. refint = picos_to_mclk(common_dimm->refresh_rate_ps);
  434. bstopre = popts->bstopre;
  435. /* refint field used 0x3FFF in earlier controllers */
  436. ddr->ddr_sdram_interval = (0
  437. | ((refint & 0xFFFF) << 16)
  438. | ((bstopre & 0x3FFF) << 0)
  439. );
  440. debug("FSLDDR: ddr_sdram_interval = 0x%08x\n", ddr->ddr_sdram_interval);
  441. }
  442. /* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
  443. static void set_ddr_sdram_mode(fsl_ddr_cfg_regs_t *ddr,
  444. const memctl_options_t *popts,
  445. const common_timing_params_t *common_dimm,
  446. unsigned int cas_latency,
  447. unsigned int additive_latency)
  448. {
  449. unsigned short esdmode; /* Extended SDRAM mode */
  450. unsigned short sdmode; /* SDRAM mode */
  451. /*
  452. * FIXME: This ought to be pre-calculated in a
  453. * technology-specific routine,
  454. * e.g. compute_DDR2_mode_register(), and then the
  455. * sdmode and esdmode passed in as part of common_dimm.
  456. */
  457. /* Extended Mode Register */
  458. unsigned int mrs = 0; /* Mode Register Set */
  459. unsigned int outputs = 0; /* 0=Enabled, 1=Disabled */
  460. unsigned int rdqs_en = 0; /* RDQS Enable: 0=no, 1=yes */
  461. unsigned int dqs_en = 0; /* DQS# Enable: 0=enable, 1=disable */
  462. unsigned int ocd = 0; /* 0x0=OCD not supported,
  463. 0x7=OCD default state */
  464. unsigned int rtt;
  465. unsigned int al; /* Posted CAS# additive latency (AL) */
  466. unsigned int ods = 0; /* Output Drive Strength:
  467. 0 = Full strength (18ohm)
  468. 1 = Reduced strength (4ohm) */
  469. unsigned int dll_en = 0; /* DLL Enable 0=Enable (Normal),
  470. 1=Disable (Test/Debug) */
  471. /* Mode Register (MR) */
  472. unsigned int mr; /* Mode Register Definition */
  473. unsigned int pd; /* Power-Down Mode */
  474. unsigned int wr; /* Write Recovery */
  475. unsigned int dll_res; /* DLL Reset */
  476. unsigned int mode; /* Normal=0 or Test=1 */
  477. unsigned int caslat = 0;/* CAS# latency */
  478. /* BT: Burst Type (0=Sequential, 1=Interleaved) */
  479. unsigned int bt;
  480. unsigned int bl; /* BL: Burst Length */
  481. #if defined(CONFIG_FSL_DDR2)
  482. const unsigned int mclk_ps = get_memory_clk_period_ps();
  483. #endif
  484. rtt = fsl_ddr_get_rtt();
  485. al = additive_latency;
  486. esdmode = (0
  487. | ((mrs & 0x3) << 14)
  488. | ((outputs & 0x1) << 12)
  489. | ((rdqs_en & 0x1) << 11)
  490. | ((dqs_en & 0x1) << 10)
  491. | ((ocd & 0x7) << 7)
  492. | ((rtt & 0x2) << 5) /* rtt field is split */
  493. | ((al & 0x7) << 3)
  494. | ((rtt & 0x1) << 2) /* rtt field is split */
  495. | ((ods & 0x1) << 1)
  496. | ((dll_en & 0x1) << 0)
  497. );
  498. mr = 0; /* FIXME: CHECKME */
  499. /*
  500. * 0 = Fast Exit (Normal)
  501. * 1 = Slow Exit (Low Power)
  502. */
  503. pd = 0;
  504. #if defined(CONFIG_FSL_DDR1)
  505. wr = 0; /* Historical */
  506. #elif defined(CONFIG_FSL_DDR2)
  507. wr = (common_dimm->tWR_ps + mclk_ps - 1) / mclk_ps - 1;
  508. #else
  509. #error "Write tWR_auto for DDR3"
  510. #endif
  511. dll_res = 0;
  512. mode = 0;
  513. #if defined(CONFIG_FSL_DDR1)
  514. if (1 <= cas_latency && cas_latency <= 4) {
  515. unsigned char mode_caslat_table[4] = {
  516. 0x5, /* 1.5 clocks */
  517. 0x2, /* 2.0 clocks */
  518. 0x6, /* 2.5 clocks */
  519. 0x3 /* 3.0 clocks */
  520. };
  521. caslat = mode_caslat_table[cas_latency - 1];
  522. } else {
  523. printf("Warning: unknown cas_latency %d\n", cas_latency);
  524. }
  525. #elif defined(CONFIG_FSL_DDR2)
  526. caslat = cas_latency;
  527. #else
  528. #error "Fix the mode CAS Latency for DDR3"
  529. #endif
  530. bt = 0;
  531. switch (popts->burst_length) {
  532. case 4:
  533. bl = 2;
  534. break;
  535. case 8:
  536. bl = 3;
  537. break;
  538. default:
  539. printf("Error: invalid burst length of %u specified. "
  540. " Defaulting to 4 beats.\n",
  541. popts->burst_length);
  542. bl = 2;
  543. break;
  544. }
  545. sdmode = (0
  546. | ((mr & 0x3) << 14)
  547. | ((pd & 0x1) << 12)
  548. | ((wr & 0x7) << 9)
  549. | ((dll_res & 0x1) << 8)
  550. | ((mode & 0x1) << 7)
  551. | ((caslat & 0x7) << 4)
  552. | ((bt & 0x1) << 3)
  553. | ((bl & 0x7) << 0)
  554. );
  555. ddr->ddr_sdram_mode = (0
  556. | ((esdmode & 0xFFFF) << 16)
  557. | ((sdmode & 0xFFFF) << 0)
  558. );
  559. debug("FSLDDR: ddr_sdram_mode = 0x%08x\n", ddr->ddr_sdram_mode);
  560. }
  561. /* DDR SDRAM Data Initialization (DDR_DATA_INIT) */
  562. static void set_ddr_data_init(fsl_ddr_cfg_regs_t *ddr)
  563. {
  564. unsigned int init_value; /* Initialization value */
  565. init_value = 0xDEADBEEF;
  566. ddr->ddr_data_init = init_value;
  567. }
  568. /*
  569. * DDR SDRAM Clock Control (DDR_SDRAM_CLK_CNTL)
  570. * The old controller on the 8540/60 doesn't have this register.
  571. * Hope it's OK to set it (to 0) anyway.
  572. */
  573. static void set_ddr_sdram_clk_cntl(fsl_ddr_cfg_regs_t *ddr,
  574. const memctl_options_t *popts)
  575. {
  576. unsigned int clk_adjust; /* Clock adjust */
  577. clk_adjust = popts->clk_adjust;
  578. ddr->ddr_sdram_clk_cntl = (clk_adjust & 0xF) << 23;
  579. }
  580. /* DDR Initialization Address (DDR_INIT_ADDR) */
  581. static void set_ddr_init_addr(fsl_ddr_cfg_regs_t *ddr)
  582. {
  583. unsigned int init_addr = 0; /* Initialization address */
  584. ddr->ddr_init_addr = init_addr;
  585. }
  586. /* DDR Initialization Address (DDR_INIT_EXT_ADDR) */
  587. static void set_ddr_init_ext_addr(fsl_ddr_cfg_regs_t *ddr)
  588. {
  589. unsigned int uia = 0; /* Use initialization address */
  590. unsigned int init_ext_addr = 0; /* Initialization address */
  591. ddr->ddr_init_ext_addr = (0
  592. | ((uia & 0x1) << 31)
  593. | (init_ext_addr & 0xF)
  594. );
  595. }
  596. /* DDR SDRAM Timing Configuration 4 (TIMING_CFG_4) */
  597. static void set_timing_cfg_4(fsl_ddr_cfg_regs_t *ddr)
  598. {
  599. unsigned int rwt = 0; /* Read-to-write turnaround for same CS */
  600. unsigned int wrt = 0; /* Write-to-read turnaround for same CS */
  601. unsigned int rrt = 0; /* Read-to-read turnaround for same CS */
  602. unsigned int wwt = 0; /* Write-to-write turnaround for same CS */
  603. unsigned int dll_lock = 0; /* DDR SDRAM DLL Lock Time */
  604. ddr->timing_cfg_4 = (0
  605. | ((rwt & 0xf) << 28)
  606. | ((wrt & 0xf) << 24)
  607. | ((rrt & 0xf) << 20)
  608. | ((wwt & 0xf) << 16)
  609. | (dll_lock & 0x3)
  610. );
  611. debug("FSLDDR: timing_cfg_4 = 0x%08x\n", ddr->timing_cfg_4);
  612. }
  613. /* DDR SDRAM Timing Configuration 5 (TIMING_CFG_5) */
  614. static void set_timing_cfg_5(fsl_ddr_cfg_regs_t *ddr)
  615. {
  616. unsigned int rodt_on = 0; /* Read to ODT on */
  617. unsigned int rodt_off = 0; /* Read to ODT off */
  618. unsigned int wodt_on = 0; /* Write to ODT on */
  619. unsigned int wodt_off = 0; /* Write to ODT off */
  620. ddr->timing_cfg_5 = (0
  621. | ((rodt_on & 0x1f) << 24)
  622. | ((rodt_off & 0x7) << 20)
  623. | ((wodt_on & 0x1f) << 12)
  624. | ((wodt_off & 0x7) << 8)
  625. );
  626. debug("FSLDDR: timing_cfg_5 = 0x%08x\n", ddr->timing_cfg_5);
  627. }
  628. /* DDR ZQ Calibration Control (DDR_ZQ_CNTL) */
  629. static void set_ddr_zq_cntl(fsl_ddr_cfg_regs_t *ddr)
  630. {
  631. unsigned int zq_en = 0; /* ZQ Calibration Enable */
  632. unsigned int zqinit = 0;/* POR ZQ Calibration Time (tZQinit) */
  633. /* Normal Operation Full Calibration Time (tZQoper) */
  634. unsigned int zqoper = 0;
  635. /* Normal Operation Short Calibration Time (tZQCS) */
  636. unsigned int zqcs = 0;
  637. ddr->ddr_zq_cntl = (0
  638. | ((zq_en & 0x1) << 31)
  639. | ((zqinit & 0xF) << 24)
  640. | ((zqoper & 0xF) << 16)
  641. | ((zqcs & 0xF) << 8)
  642. );
  643. }
  644. /* DDR Write Leveling Control (DDR_WRLVL_CNTL) */
  645. static void set_ddr_wrlvl_cntl(fsl_ddr_cfg_regs_t *ddr)
  646. {
  647. unsigned int wrlvl_en = 0; /* Write Leveling Enable */
  648. /*
  649. * First DQS pulse rising edge after margining mode
  650. * is programmed (tWL_MRD)
  651. */
  652. unsigned int wrlvl_mrd = 0;
  653. /* ODT delay after margining mode is programmed (tWL_ODTEN) */
  654. unsigned int wrlvl_odten = 0;
  655. /* DQS/DQS_ delay after margining mode is programmed (tWL_DQSEN) */
  656. unsigned int wrlvl_dqsen = 0;
  657. /* WRLVL_SMPL: Write leveling sample time */
  658. unsigned int wrlvl_smpl = 0;
  659. /* WRLVL_WLR: Write leveling repeition time */
  660. unsigned int wrlvl_wlr = 0;
  661. /* WRLVL_START: Write leveling start time */
  662. unsigned int wrlvl_start = 0;
  663. ddr->ddr_wrlvl_cntl = (0
  664. | ((wrlvl_en & 0x1) << 31)
  665. | ((wrlvl_mrd & 0x7) << 24)
  666. | ((wrlvl_odten & 0x7) << 20)
  667. | ((wrlvl_dqsen & 0x7) << 16)
  668. | ((wrlvl_smpl & 0xf) << 12)
  669. | ((wrlvl_wlr & 0x7) << 8)
  670. | ((wrlvl_start & 0x1F) << 0)
  671. );
  672. }
  673. /* DDR Self Refresh Counter (DDR_SR_CNTR) */
  674. static void set_ddr_sr_cntr(fsl_ddr_cfg_regs_t *ddr, unsigned int sr_it)
  675. {
  676. /* Self Refresh Idle Threshold */
  677. ddr->ddr_sr_cntr = (sr_it & 0xF) << 16;
  678. }
  679. /* DDR Pre-Drive Conditioning Control (DDR_PD_CNTL) */
  680. static void set_ddr_pd_cntl(fsl_ddr_cfg_regs_t *ddr)
  681. {
  682. /* Termination value during pre-drive conditioning */
  683. unsigned int tvpd = 0;
  684. unsigned int pd_en = 0; /* Pre-Drive Conditioning Enable */
  685. unsigned int pdar = 0; /* Pre-Drive After Read */
  686. unsigned int pdaw = 0; /* Pre-Drive After Write */
  687. unsigned int pd_on = 0; /* Pre-Drive Conditioning On */
  688. unsigned int pd_off = 0; /* Pre-Drive Conditioning Off */
  689. ddr->ddr_pd_cntl = (0
  690. | ((pd_en & 0x1) << 31)
  691. | ((tvpd & 0x7) << 28)
  692. | ((pdar & 0x7F) << 20)
  693. | ((pdaw & 0x7F) << 12)
  694. | ((pd_on & 0x1F) << 6)
  695. | ((pd_off & 0x1F) << 0)
  696. );
  697. }
  698. /* DDR SDRAM Register Control Word 1 (DDR_SDRAM_RCW_1) */
  699. static void set_ddr_sdram_rcw_1(fsl_ddr_cfg_regs_t *ddr)
  700. {
  701. unsigned int rcw0 = 0; /* RCW0: Register Control Word 0 */
  702. unsigned int rcw1 = 0; /* RCW1: Register Control Word 1 */
  703. unsigned int rcw2 = 0; /* RCW2: Register Control Word 2 */
  704. unsigned int rcw3 = 0; /* RCW3: Register Control Word 3 */
  705. unsigned int rcw4 = 0; /* RCW4: Register Control Word 4 */
  706. unsigned int rcw5 = 0; /* RCW5: Register Control Word 5 */
  707. unsigned int rcw6 = 0; /* RCW6: Register Control Word 6 */
  708. unsigned int rcw7 = 0; /* RCW7: Register Control Word 7 */
  709. ddr->ddr_sdram_rcw_1 = (0
  710. | ((rcw0 & 0xF) << 28)
  711. | ((rcw1 & 0xF) << 24)
  712. | ((rcw2 & 0xF) << 20)
  713. | ((rcw3 & 0xF) << 16)
  714. | ((rcw4 & 0xF) << 12)
  715. | ((rcw5 & 0xF) << 8)
  716. | ((rcw6 & 0xF) << 4)
  717. | ((rcw7 & 0xF) << 0)
  718. );
  719. }
  720. /* DDR SDRAM Register Control Word 2 (DDR_SDRAM_RCW_2) */
  721. static void set_ddr_sdram_rcw_2(fsl_ddr_cfg_regs_t *ddr)
  722. {
  723. unsigned int rcw8 = 0; /* RCW0: Register Control Word 8 */
  724. unsigned int rcw9 = 0; /* RCW1: Register Control Word 9 */
  725. unsigned int rcw10 = 0; /* RCW2: Register Control Word 10 */
  726. unsigned int rcw11 = 0; /* RCW3: Register Control Word 11 */
  727. unsigned int rcw12 = 0; /* RCW4: Register Control Word 12 */
  728. unsigned int rcw13 = 0; /* RCW5: Register Control Word 13 */
  729. unsigned int rcw14 = 0; /* RCW6: Register Control Word 14 */
  730. unsigned int rcw15 = 0; /* RCW7: Register Control Word 15 */
  731. ddr->ddr_sdram_rcw_2 = (0
  732. | ((rcw8 & 0xF) << 28)
  733. | ((rcw9 & 0xF) << 24)
  734. | ((rcw10 & 0xF) << 20)
  735. | ((rcw11 & 0xF) << 16)
  736. | ((rcw12 & 0xF) << 12)
  737. | ((rcw13 & 0xF) << 8)
  738. | ((rcw14 & 0xF) << 4)
  739. | ((rcw15 & 0xF) << 0)
  740. );
  741. }
  742. unsigned int
  743. check_fsl_memctl_config_regs(const fsl_ddr_cfg_regs_t *ddr)
  744. {
  745. unsigned int res = 0;
  746. /*
  747. * Check that DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN] are
  748. * not set at the same time.
  749. */
  750. if (ddr->ddr_sdram_cfg & 0x10000000
  751. && ddr->ddr_sdram_cfg & 0x00008000) {
  752. printf("Error: DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN] "
  753. " should not be set at the same time.\n");
  754. res++;
  755. }
  756. return res;
  757. }
  758. unsigned int
  759. compute_fsl_memctl_config_regs(const memctl_options_t *popts,
  760. fsl_ddr_cfg_regs_t *ddr,
  761. const common_timing_params_t *common_dimm,
  762. const dimm_params_t *dimm_params,
  763. unsigned int dbw_cap_adj)
  764. {
  765. unsigned int i;
  766. unsigned int cas_latency;
  767. unsigned int additive_latency;
  768. unsigned int sr_it;
  769. memset(ddr, 0, sizeof(fsl_ddr_cfg_regs_t));
  770. if (common_dimm == NULL) {
  771. printf("Error: subset DIMM params struct null pointer\n");
  772. return 1;
  773. }
  774. /*
  775. * Process overrides first.
  776. *
  777. * FIXME: somehow add dereated caslat to this
  778. */
  779. cas_latency = (popts->cas_latency_override)
  780. ? popts->cas_latency_override_value
  781. : common_dimm->lowest_common_SPD_caslat;
  782. additive_latency = (popts->additive_latency_override)
  783. ? popts->additive_latency_override_value
  784. : common_dimm->additive_latency;
  785. sr_it = (popts->auto_self_refresh_en)
  786. ? popts->sr_it
  787. : 0;
  788. /* Chip Select Memory Bounds (CSn_BNDS) */
  789. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  790. phys_size_t sa = 0;
  791. phys_size_t ea = 0;
  792. if (popts->ba_intlv_ctl && (i > 0) &&
  793. ((popts->ba_intlv_ctl & 0x60) != FSL_DDR_CS2_CS3 )) {
  794. /* Don't set up boundaries for other CS
  795. * other than CS0, if bank interleaving
  796. * is enabled and not CS2+CS3 interleaved.
  797. */
  798. break;
  799. }
  800. if (dimm_params[i/2].n_ranks == 0) {
  801. debug("Skipping setup of CS%u "
  802. "because n_ranks on DIMM %u is 0\n", i, i/2);
  803. continue;
  804. }
  805. if (popts->memctl_interleaving && popts->ba_intlv_ctl) {
  806. /*
  807. * This works superbank 2CS
  808. * There are 2 memory controllers configured
  809. * identically, memory is interleaved between them,
  810. * and each controller uses rank interleaving within
  811. * itself. Therefore the starting and ending address
  812. * on each controller is twice the amount present on
  813. * each controller.
  814. */
  815. unsigned long long rank_density
  816. = dimm_params[0].capacity;
  817. ea = (2 * (rank_density >> dbw_cap_adj)) - 1;
  818. }
  819. else if (!popts->memctl_interleaving && popts->ba_intlv_ctl) {
  820. /*
  821. * If memory interleaving between controllers is NOT
  822. * enabled, the starting address for each memory
  823. * controller is distinct. However, because rank
  824. * interleaving is enabled, the starting and ending
  825. * addresses of the total memory on that memory
  826. * controller needs to be programmed into its
  827. * respective CS0_BNDS.
  828. */
  829. unsigned long long rank_density
  830. = dimm_params[i/2].rank_density;
  831. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  832. case FSL_DDR_CS0_CS1_CS2_CS3:
  833. /* CS0+CS1+CS2+CS3 interleaving, only CS0_CNDS
  834. * needs to be set.
  835. */
  836. sa = common_dimm->base_address;
  837. ea = sa + (4 * (rank_density >> dbw_cap_adj))-1;
  838. break;
  839. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  840. /* CS0+CS1 and CS2+CS3 interleaving, CS0_CNDS
  841. * and CS2_CNDS need to be set.
  842. */
  843. if (!(i&1)) {
  844. sa = dimm_params[i/2].base_address;
  845. ea = sa + (i * (rank_density >>
  846. dbw_cap_adj)) - 1;
  847. }
  848. break;
  849. case FSL_DDR_CS0_CS1:
  850. /* CS0+CS1 interleaving, CS0_CNDS needs
  851. * to be set
  852. */
  853. sa = common_dimm->base_address;
  854. ea = sa + (2 * (rank_density >> dbw_cap_adj))-1;
  855. break;
  856. case FSL_DDR_CS2_CS3:
  857. /* CS2+CS3 interleaving*/
  858. if (i == 2) {
  859. sa = dimm_params[i/2].base_address;
  860. ea = sa + (2 * (rank_density >>
  861. dbw_cap_adj)) - 1;
  862. }
  863. break;
  864. default: /* No bank(chip-select) interleaving */
  865. break;
  866. }
  867. }
  868. else if (popts->memctl_interleaving && !popts->ba_intlv_ctl) {
  869. /*
  870. * Only the rank on CS0 of each memory controller may
  871. * be used if memory controller interleaving is used
  872. * without rank interleaving within each memory
  873. * controller. However, the ending address programmed
  874. * into each CS0 must be the sum of the amount of
  875. * memory in the two CS0 ranks.
  876. */
  877. if (i == 0) {
  878. unsigned long long rank_density
  879. = dimm_params[0].rank_density;
  880. ea = (2 * (rank_density >> dbw_cap_adj)) - 1;
  881. }
  882. }
  883. else if (!popts->memctl_interleaving && !popts->ba_intlv_ctl) {
  884. /*
  885. * No rank interleaving and no memory controller
  886. * interleaving.
  887. */
  888. unsigned long long rank_density
  889. = dimm_params[i/2].rank_density;
  890. sa = dimm_params[i/2].base_address;
  891. ea = sa + (rank_density >> dbw_cap_adj) - 1;
  892. if (i&1) {
  893. if ((dimm_params[i/2].n_ranks == 1)) {
  894. /* Odd chip select, single-rank dimm */
  895. sa = 0;
  896. ea = 0;
  897. } else {
  898. /* Odd chip select, dual-rank DIMM */
  899. sa += rank_density >> dbw_cap_adj;
  900. ea += rank_density >> dbw_cap_adj;
  901. }
  902. }
  903. }
  904. sa >>= 24;
  905. ea >>= 24;
  906. ddr->cs[i].bnds = (0
  907. | ((sa & 0xFFF) << 16) /* starting address MSB */
  908. | ((ea & 0xFFF) << 0) /* ending address MSB */
  909. );
  910. debug("FSLDDR: cs[%d]_bnds = 0x%08x\n", i, ddr->cs[i].bnds);
  911. set_csn_config(i, ddr, popts, dimm_params);
  912. set_csn_config_2(i, ddr);
  913. }
  914. #if defined(CONFIG_FSL_DDR2)
  915. set_timing_cfg_0(ddr);
  916. #endif
  917. set_timing_cfg_3(ddr, common_dimm);
  918. set_timing_cfg_1(ddr, common_dimm, cas_latency);
  919. set_timing_cfg_2(ddr, popts, common_dimm,
  920. cas_latency, additive_latency);
  921. set_ddr_sdram_cfg(ddr, popts, common_dimm);
  922. set_ddr_sdram_cfg_2(ddr, popts);
  923. set_ddr_sdram_mode(ddr, popts, common_dimm,
  924. cas_latency, additive_latency);
  925. set_ddr_sdram_mode_2(ddr);
  926. set_ddr_sdram_interval(ddr, popts, common_dimm);
  927. set_ddr_data_init(ddr);
  928. set_ddr_sdram_clk_cntl(ddr, popts);
  929. set_ddr_init_addr(ddr);
  930. set_ddr_init_ext_addr(ddr);
  931. set_timing_cfg_4(ddr);
  932. set_timing_cfg_5(ddr);
  933. set_ddr_zq_cntl(ddr);
  934. set_ddr_wrlvl_cntl(ddr);
  935. set_ddr_pd_cntl(ddr);
  936. set_ddr_sr_cntr(ddr, sr_it);
  937. set_ddr_sdram_rcw_1(ddr);
  938. set_ddr_sdram_rcw_2(ddr);
  939. return check_fsl_memctl_config_regs(ddr);
  940. }