spd_sdram.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * (C) Copyright 2006 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2006
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
  8. * (C) Copyright 2003 Motorola Inc.
  9. * Xianghua Xiao (X.Xiao@motorola.com)
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <asm/processor.h>
  31. #include <i2c.h>
  32. #include <spd.h>
  33. #include <asm/mmu.h>
  34. #include <spd_sdram.h>
  35. #ifdef CONFIG_SPD_EEPROM
  36. DECLARE_GLOBAL_DATA_PTR;
  37. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  38. extern void dma_init(void);
  39. extern uint dma_check(void);
  40. extern int dma_xfer(void *dest, uint count, void *src);
  41. #endif
  42. #ifndef CFG_READ_SPD
  43. #define CFG_READ_SPD i2c_read
  44. #endif
  45. /*
  46. * Convert picoseconds into clock cycles (rounding up if needed).
  47. */
  48. int
  49. picos_to_clk(int picos)
  50. {
  51. unsigned int ddr_bus_clk;
  52. int clks;
  53. ddr_bus_clk = gd->ddr_clk >> 1;
  54. clks = picos / ((1000000000 / ddr_bus_clk) * 1000);
  55. if (picos % ((1000000000 / ddr_bus_clk) * 1000) != 0)
  56. clks++;
  57. return clks;
  58. }
  59. unsigned int banksize(unsigned char row_dens)
  60. {
  61. return ((row_dens >> 2) | ((row_dens & 3) << 6)) << 24;
  62. }
  63. int read_spd(uint addr)
  64. {
  65. return ((int) addr);
  66. }
  67. #undef SPD_DEBUG
  68. #ifdef SPD_DEBUG
  69. static void spd_debug(spd_eeprom_t *spd)
  70. {
  71. printf ("\nDIMM type: %-18.18s\n", spd->mpart);
  72. printf ("SPD size: %d\n", spd->info_size);
  73. printf ("EEPROM size: %d\n", 1 << spd->chip_size);
  74. printf ("Memory type: %d\n", spd->mem_type);
  75. printf ("Row addr: %d\n", spd->nrow_addr);
  76. printf ("Column addr: %d\n", spd->ncol_addr);
  77. printf ("# of rows: %d\n", spd->nrows);
  78. printf ("Row density: %d\n", spd->row_dens);
  79. printf ("# of banks: %d\n", spd->nbanks);
  80. printf ("Data width: %d\n",
  81. 256 * spd->dataw_msb + spd->dataw_lsb);
  82. printf ("Chip width: %d\n", spd->primw);
  83. printf ("Refresh rate: %02X\n", spd->refresh);
  84. printf ("CAS latencies: %02X\n", spd->cas_lat);
  85. printf ("Write latencies: %02X\n", spd->write_lat);
  86. printf ("tRP: %d\n", spd->trp);
  87. printf ("tRCD: %d\n", spd->trcd);
  88. printf ("\n");
  89. }
  90. #endif /* SPD_DEBUG */
  91. long int spd_sdram()
  92. {
  93. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  94. volatile ddr83xx_t *ddr = &immap->ddr;
  95. volatile law83xx_t *ecm = &immap->sysconf.ddrlaw[0];
  96. spd_eeprom_t spd;
  97. unsigned int memsize;
  98. unsigned int law_size;
  99. unsigned char caslat, caslat_ctrl;
  100. unsigned char burstlen;
  101. unsigned int max_bus_clk;
  102. unsigned int max_data_rate, effective_data_rate;
  103. unsigned int ddrc_clk;
  104. unsigned int refresh_clk;
  105. unsigned sdram_cfg;
  106. unsigned int ddrc_ecc_enable;
  107. /* Read SPD parameters with I2C */
  108. CFG_READ_SPD(SPD_EEPROM_ADDRESS, 0, 1, (uchar *) & spd, sizeof (spd));
  109. #ifdef SPD_DEBUG
  110. spd_debug(&spd);
  111. #endif
  112. /* Check the memory type */
  113. if (spd.mem_type != SPD_MEMTYPE_DDR) {
  114. printf("DDR: Module mem type is %02X\n", spd.mem_type);
  115. return 0;
  116. }
  117. /* Check the number of physical bank */
  118. if (spd.nrows > 2) {
  119. printf("DDR: The number of physical bank is %02X\n", spd.nrows);
  120. return 0;
  121. }
  122. /* Check if the number of row of the module is in the range of DDRC */
  123. if (spd.nrow_addr < 12 || spd.nrow_addr > 14) {
  124. printf("DDR: Row number is out of range of DDRC, row=%02X\n",
  125. spd.nrow_addr);
  126. return 0;
  127. }
  128. /* Check if the number of col of the module is in the range of DDRC */
  129. if (spd.ncol_addr < 8 || spd.ncol_addr > 11) {
  130. printf("DDR: Col number is out of range of DDRC, col=%02X\n",
  131. spd.ncol_addr);
  132. return 0;
  133. }
  134. /* Setup DDR chip select register */
  135. #ifdef CFG_83XX_DDR_USES_CS0
  136. ddr->csbnds[0].csbnds = (banksize(spd.row_dens) >> 24) - 1;
  137. ddr->cs_config[0] = ( 1 << 31
  138. | (spd.nrow_addr - 12) << 8
  139. | (spd.ncol_addr - 8) );
  140. debug("\n");
  141. debug("cs0_bnds = 0x%08x\n",ddr->csbnds[0].csbnds);
  142. debug("cs0_config = 0x%08x\n",ddr->cs_config[0]);
  143. if (spd.nrows == 2) {
  144. ddr->csbnds[1].csbnds = ( (banksize(spd.row_dens) >> 8)
  145. | ((banksize(spd.row_dens) >> 23) - 1) );
  146. ddr->cs_config[1] = ( 1<<31
  147. | (spd.nrow_addr-12) << 8
  148. | (spd.ncol_addr-8) );
  149. debug("cs1_bnds = 0x%08x\n",ddr->csbnds[1].csbnds);
  150. debug("cs1_config = 0x%08x\n",ddr->cs_config[1]);
  151. }
  152. #else
  153. ddr->csbnds[2].csbnds = (banksize(spd.row_dens) >> 24) - 1;
  154. ddr->cs_config[2] = ( 1 << 31
  155. | (spd.nrow_addr - 12) << 8
  156. | (spd.ncol_addr - 8) );
  157. debug("\n");
  158. debug("cs2_bnds = 0x%08x\n",ddr->csbnds[2].csbnds);
  159. debug("cs2_config = 0x%08x\n",ddr->cs_config[2]);
  160. if (spd.nrows == 2) {
  161. ddr->csbnds[3].csbnds = ( (banksize(spd.row_dens) >> 8)
  162. | ((banksize(spd.row_dens) >> 23) - 1) );
  163. ddr->cs_config[3] = ( 1<<31
  164. | (spd.nrow_addr-12) << 8
  165. | (spd.ncol_addr-8) );
  166. debug("cs3_bnds = 0x%08x\n",ddr->csbnds[3].csbnds);
  167. debug("cs3_config = 0x%08x\n",ddr->cs_config[3]);
  168. }
  169. #endif
  170. if (spd.mem_type != 0x07) {
  171. puts("No DDR module found!\n");
  172. return 0;
  173. }
  174. /*
  175. * Figure out memory size in Megabytes.
  176. */
  177. memsize = spd.nrows * banksize(spd.row_dens) / 0x100000;
  178. /*
  179. * First supported LAW size is 16M, at LAWAR_SIZE_16M == 23.
  180. */
  181. law_size = 19 + __ilog2(memsize);
  182. /*
  183. * Set up LAWBAR for all of DDR.
  184. */
  185. ecm->bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff);
  186. ecm->ar = (LAWAR_EN | LAWAR_TRGT_IF_DDR | (LAWAR_SIZE & law_size));
  187. debug("DDR:bar=0x%08x\n", ecm->bar);
  188. debug("DDR:ar=0x%08x\n", ecm->ar);
  189. /*
  190. * Find the largest CAS by locating the highest 1 bit
  191. * in the spd.cas_lat field. Translate it to a DDR
  192. * controller field value:
  193. *
  194. * CAS Lat DDR I Ctrl
  195. * Clocks SPD Bit Value
  196. * -------+--------+---------
  197. * 1.0 0 001
  198. * 1.5 1 010
  199. * 2.0 2 011
  200. * 2.5 3 100
  201. * 3.0 4 101
  202. * 3.5 5 110
  203. * 4.0 6 111
  204. */
  205. caslat = __ilog2(spd.cas_lat);
  206. if (caslat > 6 ) {
  207. printf("DDR: Invalid SPD CAS Latency, caslat=%02X\n",
  208. spd.cas_lat);
  209. return 0;
  210. }
  211. max_bus_clk = 1000 *10 / (((spd.clk_cycle & 0xF0) >> 4) * 10
  212. + (spd.clk_cycle & 0x0f));
  213. max_data_rate = max_bus_clk * 2;
  214. debug("DDR:Module maximum data rate is: %dMhz\n", max_data_rate);
  215. ddrc_clk = gd->ddr_clk / 1000000;
  216. if (max_data_rate >= 390) { /* it is DDR 400 */
  217. if (ddrc_clk <= 410 && ddrc_clk > 350) {
  218. /* DDR controller clk at 350~410 */
  219. effective_data_rate = 400; /* 5ns */
  220. caslat = caslat;
  221. } else if (ddrc_clk <= 350 && ddrc_clk > 280) {
  222. /* DDR controller clk at 280~350 */
  223. effective_data_rate = 333; /* 6ns */
  224. if (spd.clk_cycle2 == 0x60)
  225. caslat = caslat - 1;
  226. else
  227. caslat = caslat;
  228. } else if (ddrc_clk <= 280 && ddrc_clk > 230) {
  229. /* DDR controller clk at 230~280 */
  230. effective_data_rate = 266; /* 7.5ns */
  231. if (spd.clk_cycle3 == 0x75)
  232. caslat = caslat - 2;
  233. else if (spd.clk_cycle2 == 0x60)
  234. caslat = caslat - 1;
  235. else
  236. caslat = caslat;
  237. } else if (ddrc_clk <= 230 && ddrc_clk > 90) {
  238. /* DDR controller clk at 90~230 */
  239. effective_data_rate = 200; /* 10ns */
  240. if (spd.clk_cycle3 == 0x75)
  241. caslat = caslat - 2;
  242. else if (spd.clk_cycle2 == 0x60)
  243. caslat = caslat - 1;
  244. else
  245. caslat = caslat;
  246. }
  247. } else if (max_data_rate >= 323) { /* it is DDR 333 */
  248. if (ddrc_clk <= 350 && ddrc_clk > 280) {
  249. /* DDR controller clk at 280~350 */
  250. effective_data_rate = 333; /* 6ns */
  251. caslat = caslat;
  252. } else if (ddrc_clk <= 280 && ddrc_clk > 230) {
  253. /* DDR controller clk at 230~280 */
  254. effective_data_rate = 266; /* 7.5ns */
  255. if (spd.clk_cycle2 == 0x75)
  256. caslat = caslat - 1;
  257. else
  258. caslat = caslat;
  259. } else if (ddrc_clk <= 230 && ddrc_clk > 90) {
  260. /* DDR controller clk at 90~230 */
  261. effective_data_rate = 200; /* 10ns */
  262. if (spd.clk_cycle3 == 0xa0)
  263. caslat = caslat - 2;
  264. else if (spd.clk_cycle2 == 0x75)
  265. caslat = caslat - 1;
  266. else
  267. caslat = caslat;
  268. }
  269. } else if (max_data_rate >= 256) { /* it is DDR 266 */
  270. if (ddrc_clk <= 350 && ddrc_clk > 280) {
  271. /* DDR controller clk at 280~350 */
  272. printf("DDR: DDR controller freq is more than "
  273. "max data rate of the module\n");
  274. return 0;
  275. } else if (ddrc_clk <= 280 && ddrc_clk > 230) {
  276. /* DDR controller clk at 230~280 */
  277. effective_data_rate = 266; /* 7.5ns */
  278. caslat = caslat;
  279. } else if (ddrc_clk <= 230 && ddrc_clk > 90) {
  280. /* DDR controller clk at 90~230 */
  281. effective_data_rate = 200; /* 10ns */
  282. if (spd.clk_cycle2 == 0xa0)
  283. caslat = caslat - 1;
  284. }
  285. } else if (max_data_rate >= 190) { /* it is DDR 200 */
  286. if (ddrc_clk <= 350 && ddrc_clk > 230) {
  287. /* DDR controller clk at 230~350 */
  288. printf("DDR: DDR controller freq is more than "
  289. "max data rate of the module\n");
  290. return 0;
  291. } else if (ddrc_clk <= 230 && ddrc_clk > 90) {
  292. /* DDR controller clk at 90~230 */
  293. effective_data_rate = 200; /* 10ns */
  294. caslat = caslat;
  295. }
  296. }
  297. debug("DDR:Effective data rate is: %dMhz\n", effective_data_rate);
  298. debug("DDR:The MSB 1 of CAS Latency is: %d\n", caslat);
  299. /*
  300. * Errata DDR6 work around: input enable 2 cycles earlier.
  301. * including MPC834x Rev1.0/1.1 and MPC8360 Rev1.1/1.2.
  302. */
  303. if (caslat == 2)
  304. ddr->debug_reg = 0x201c0000; /* CL=2 */
  305. else if (caslat == 3)
  306. ddr->debug_reg = 0x202c0000; /* CL=2.5 */
  307. else if (caslat == 4)
  308. ddr->debug_reg = 0x202c0000; /* CL=3.0 */
  309. __asm__ __volatile__ ("sync");
  310. debug("Errata DDR6 (debug_reg=0x%08x)\n", ddr->debug_reg);
  311. /*
  312. * note: caslat must also be programmed into ddr->sdram_mode
  313. * register.
  314. *
  315. * note: WRREC(Twr) and WRTORD(Twtr) are not in SPD,
  316. * use conservative value here.
  317. */
  318. caslat_ctrl = (caslat + 1) & 0x07; /* see as above */
  319. ddr->timing_cfg_1 =
  320. (((picos_to_clk(spd.trp * 250) & 0x07) << 28 ) |
  321. ((picos_to_clk(spd.tras * 1000) & 0x0f ) << 24 ) |
  322. ((picos_to_clk(spd.trcd * 250) & 0x07) << 20 ) |
  323. ((caslat_ctrl & 0x07) << 16 ) |
  324. (((picos_to_clk(spd.trfc * 1000) - 8) & 0x0f) << 12 ) |
  325. ( 0x300 ) |
  326. ((picos_to_clk(spd.trrd * 250) & 0x07) << 4) | 1);
  327. ddr->timing_cfg_2 = 0x00000800;
  328. debug("DDR:timing_cfg_1=0x%08x\n", ddr->timing_cfg_1);
  329. debug("DDR:timing_cfg_2=0x%08x\n", ddr->timing_cfg_2);
  330. /* Setup init value, but not enable */
  331. ddr->sdram_cfg = 0x42000000;
  332. /* Check DIMM data bus width */
  333. if (spd.dataw_lsb == 0x20) {
  334. burstlen = 0x03; /* 32 bit data bus, burst len is 8 */
  335. printf("\n DDR DIMM: data bus width is 32 bit");
  336. } else {
  337. burstlen = 0x02; /* Others act as 64 bit bus, burst len is 4 */
  338. printf("\n DDR DIMM: data bus width is 64 bit");
  339. }
  340. /* Is this an ECC DDR chip? */
  341. if (spd.config == 0x02)
  342. printf(" with ECC\n");
  343. else
  344. printf(" without ECC\n");
  345. /* Burst length is always 4 for 64 bit data bus, 8 for 32 bit data bus,
  346. Burst type is sequential
  347. */
  348. switch (caslat) {
  349. case 1:
  350. ddr->sdram_mode = 0x50 | burstlen; /* CL=1.5 */
  351. break;
  352. case 2:
  353. ddr->sdram_mode = 0x20 | burstlen; /* CL=2.0 */
  354. break;
  355. case 3:
  356. ddr->sdram_mode = 0x60 | burstlen; /* CL=2.5 */
  357. break;
  358. case 4:
  359. ddr->sdram_mode = 0x30 | burstlen; /* CL=3.0 */
  360. break;
  361. default:
  362. printf("DDR:only CL 1.5, 2.0, 2.5, 3.0 is supported\n");
  363. return 0;
  364. }
  365. debug("DDR:sdram_mode=0x%08x\n", ddr->sdram_mode);
  366. switch (spd.refresh) {
  367. case 0x00:
  368. case 0x80:
  369. refresh_clk = picos_to_clk(15625000);
  370. break;
  371. case 0x01:
  372. case 0x81:
  373. refresh_clk = picos_to_clk(3900000);
  374. break;
  375. case 0x02:
  376. case 0x82:
  377. refresh_clk = picos_to_clk(7800000);
  378. break;
  379. case 0x03:
  380. case 0x83:
  381. refresh_clk = picos_to_clk(31300000);
  382. break;
  383. case 0x04:
  384. case 0x84:
  385. refresh_clk = picos_to_clk(62500000);
  386. break;
  387. case 0x05:
  388. case 0x85:
  389. refresh_clk = picos_to_clk(125000000);
  390. break;
  391. default:
  392. refresh_clk = 0x512;
  393. break;
  394. }
  395. /*
  396. * Set BSTOPRE to 0x100 for page mode
  397. * If auto-charge is used, set BSTOPRE = 0
  398. */
  399. ddr->sdram_interval = ((refresh_clk & 0x3fff) << 16) | 0x100;
  400. debug("DDR:sdram_interval=0x%08x\n", ddr->sdram_interval);
  401. /* SS_EN = 0, source synchronous disable
  402. * CLK_ADJST = 0, MCK/MCK# is launched aligned with addr/cmd
  403. */
  404. ddr->sdram_clk_cntl = 0x00000000;
  405. debug("DDR:sdram_clk_cntl=0x%08x\n", ddr->sdram_clk_cntl);
  406. asm("sync;isync");
  407. udelay(600);
  408. /*
  409. * Figure out the settings for the sdram_cfg register. Build up
  410. * the value in 'sdram_cfg' before writing since the write into
  411. * the register will actually enable the memory controller, and all
  412. * settings must be done before enabling.
  413. *
  414. * sdram_cfg[0] = 1 (ddr sdram logic enable)
  415. * sdram_cfg[1] = 1 (self-refresh-enable)
  416. * sdram_cfg[6:7] = 2 (SDRAM type = DDR SDRAM)
  417. * sdram_cfg[12] = 0 (32_BE =0 , 64 bit bus mode)
  418. * sdram_cfg[13] = 0 (8_BE =0, 4-beat bursts)
  419. */
  420. sdram_cfg = 0xC2000000;
  421. /* sdram_cfg[3] = RD_EN - registered DIMM enable */
  422. if (spd.mod_attr & 0x02)
  423. sdram_cfg |= 0x10000000;
  424. /* The DIMM is 32bit width */
  425. if (spd.dataw_lsb == 0x20)
  426. sdram_cfg |= 0x000C0000;
  427. ddrc_ecc_enable = 0;
  428. #if defined(CONFIG_DDR_ECC)
  429. /* Enable ECC with sdram_cfg[2] */
  430. if (spd.config == 0x02) {
  431. sdram_cfg |= 0x20000000;
  432. ddrc_ecc_enable = 1;
  433. /* disable error detection */
  434. ddr->err_disable = ~ECC_ERROR_ENABLE;
  435. /* set single bit error threshold to maximum value,
  436. * reset counter to zero */
  437. ddr->err_sbe = (255 << ECC_ERROR_MAN_SBET_SHIFT) |
  438. (0 << ECC_ERROR_MAN_SBEC_SHIFT);
  439. }
  440. debug("DDR:err_disable=0x%08x\n", ddr->err_disable);
  441. debug("DDR:err_sbe=0x%08x\n", ddr->err_sbe);
  442. #endif
  443. printf(" DDRC ECC mode: %s\n", ddrc_ecc_enable ? "ON":"OFF");
  444. #if defined(CONFIG_DDR_2T_TIMING)
  445. /*
  446. * Enable 2T timing by setting sdram_cfg[16].
  447. */
  448. sdram_cfg |= SDRAM_CFG_2T_EN;
  449. #endif
  450. /* Enable controller, and GO! */
  451. ddr->sdram_cfg = sdram_cfg;
  452. asm("sync;isync");
  453. udelay(500);
  454. debug("DDR:sdram_cfg=0x%08x\n", ddr->sdram_cfg);
  455. return memsize; /*in MBytes*/
  456. }
  457. #endif /* CONFIG_SPD_EEPROM */
  458. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  459. /*
  460. * Use timebase counter, get_timer() is not availabe
  461. * at this point of initialization yet.
  462. */
  463. static __inline__ unsigned long get_tbms (void)
  464. {
  465. unsigned long tbl;
  466. unsigned long tbu1, tbu2;
  467. unsigned long ms;
  468. unsigned long long tmp;
  469. ulong tbclk = get_tbclk();
  470. /* get the timebase ticks */
  471. do {
  472. asm volatile ("mftbu %0":"=r" (tbu1):);
  473. asm volatile ("mftb %0":"=r" (tbl):);
  474. asm volatile ("mftbu %0":"=r" (tbu2):);
  475. } while (tbu1 != tbu2);
  476. /* convert ticks to ms */
  477. tmp = (unsigned long long)(tbu1);
  478. tmp = (tmp << 32);
  479. tmp += (unsigned long long)(tbl);
  480. ms = tmp/(tbclk/1000);
  481. return ms;
  482. }
  483. /*
  484. * Initialize all of memory for ECC, then enable errors.
  485. */
  486. /* #define CONFIG_DDR_ECC_INIT_VIA_DMA */
  487. void ddr_enable_ecc(unsigned int dram_size)
  488. {
  489. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  490. volatile ddr83xx_t *ddr= &immap->ddr;
  491. unsigned long t_start, t_end;
  492. register u64 *p;
  493. register uint size;
  494. unsigned int pattern[2];
  495. #if defined(CONFIG_DDR_ECC_INIT_VIA_DMA)
  496. uint i;
  497. #endif
  498. icache_enable();
  499. t_start = get_tbms();
  500. pattern[0] = 0xdeadbeef;
  501. pattern[1] = 0xdeadbeef;
  502. #if !defined(CONFIG_DDR_ECC_INIT_VIA_DMA)
  503. debug("ddr init: CPU FP write method\n");
  504. size = dram_size;
  505. for (p = 0; p < (u64*)(size); p++) {
  506. ppcDWstore((u32*)p, pattern);
  507. }
  508. __asm__ __volatile__ ("sync");
  509. #else
  510. debug("ddr init: DMA method\n");
  511. size = 0x2000;
  512. for (p = 0; p < (u64*)(size); p++) {
  513. ppcDWstore((u32*)p, pattern);
  514. }
  515. __asm__ __volatile__ ("sync");
  516. /* Initialise DMA for direct transfer */
  517. dma_init();
  518. /* Start DMA to transfer */
  519. dma_xfer((uint *)0x2000, 0x2000, (uint *)0); /* 8K */
  520. dma_xfer((uint *)0x4000, 0x4000, (uint *)0); /* 16K */
  521. dma_xfer((uint *)0x8000, 0x8000, (uint *)0); /* 32K */
  522. dma_xfer((uint *)0x10000, 0x10000, (uint *)0); /* 64K */
  523. dma_xfer((uint *)0x20000, 0x20000, (uint *)0); /* 128K */
  524. dma_xfer((uint *)0x40000, 0x40000, (uint *)0); /* 256K */
  525. dma_xfer((uint *)0x80000, 0x80000, (uint *)0); /* 512K */
  526. dma_xfer((uint *)0x100000, 0x100000, (uint *)0); /* 1M */
  527. dma_xfer((uint *)0x200000, 0x200000, (uint *)0); /* 2M */
  528. dma_xfer((uint *)0x400000, 0x400000, (uint *)0); /* 4M */
  529. for (i = 1; i < dram_size / 0x800000; i++) {
  530. dma_xfer((uint *)(0x800000*i), 0x800000, (uint *)0);
  531. }
  532. #endif
  533. t_end = get_tbms();
  534. icache_disable();
  535. debug("\nREADY!!\n");
  536. debug("ddr init duration: %ld ms\n", t_end - t_start);
  537. /* Clear All ECC Errors */
  538. if ((ddr->err_detect & ECC_ERROR_DETECT_MME) == ECC_ERROR_DETECT_MME)
  539. ddr->err_detect |= ECC_ERROR_DETECT_MME;
  540. if ((ddr->err_detect & ECC_ERROR_DETECT_MBE) == ECC_ERROR_DETECT_MBE)
  541. ddr->err_detect |= ECC_ERROR_DETECT_MBE;
  542. if ((ddr->err_detect & ECC_ERROR_DETECT_SBE) == ECC_ERROR_DETECT_SBE)
  543. ddr->err_detect |= ECC_ERROR_DETECT_SBE;
  544. if ((ddr->err_detect & ECC_ERROR_DETECT_MSE) == ECC_ERROR_DETECT_MSE)
  545. ddr->err_detect |= ECC_ERROR_DETECT_MSE;
  546. /* Disable ECC-Interrupts */
  547. ddr->err_int_en &= ECC_ERR_INT_DISABLE;
  548. /* Enable errors for ECC */
  549. ddr->err_disable &= ECC_ERROR_ENABLE;
  550. __asm__ __volatile__ ("sync");
  551. __asm__ __volatile__ ("isync");
  552. }
  553. #endif /* CONFIG_DDR_ECC */