spd_sdram.c 17 KB

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