spd_sdram.c 17 KB

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