mpc8540eval.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * (C) Copyright 2002,2003, Motorola Inc.
  3. * Xianghua Xiao, (X.Xiao@motorola.com)
  4. *
  5. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/fsl_ddr_sdram.h>
  30. #include <spd_sdram.h>
  31. long int fixed_sdram (void);
  32. int board_pre_init (void)
  33. {
  34. #if defined(CONFIG_PCI)
  35. volatile ccsr_pcix_t *pci = (void *)(CFG_MPC85xx_PCIX_ADDR);
  36. pci->peer &= 0xffffffdf; /* disable master abort */
  37. #endif
  38. return 0;
  39. }
  40. int checkboard (void)
  41. {
  42. sys_info_t sysinfo;
  43. get_sys_info (&sysinfo);
  44. printf ("Board: Freescale MPC8540EVAL Board\n");
  45. printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
  46. printf ("\tCCB: %lu MHz\n", sysinfo.freqSystemBus / 1000000);
  47. printf ("\tDDR: %lu MHz\n", sysinfo.freqSystemBus / 2000000);
  48. if((CFG_LBC_LCRR & 0x0f) == 2 || (CFG_LBC_LCRR & 0x0f) == 4 \
  49. || (CFG_LBC_LCRR & 0x0f) == 8) {
  50. printf ("\tLBC: %lu MHz\n",
  51. sysinfo.freqSystemBus / 1000000/(CFG_LBC_LCRR & 0x0f));
  52. } else {
  53. printf("\tLBC: unknown\n");
  54. }
  55. printf("L1 D-cache 32KB, L1 I-cache 32KB enabled.\n");
  56. return (0);
  57. }
  58. phys_size_t initdram (int board_type)
  59. {
  60. long dram_size = 0;
  61. #if !defined(CONFIG_RAM_AS_FLASH)
  62. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  63. sys_info_t sysinfo;
  64. uint temp_lbcdll = 0;
  65. #endif
  66. #if !defined(CONFIG_RAM_AS_FLASH) || defined(CONFIG_DDR_DLL)
  67. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  68. #endif
  69. #if defined(CONFIG_DDR_DLL)
  70. uint temp_ddrdll = 0;
  71. /* Work around to stabilize DDR DLL */
  72. temp_ddrdll = gur->ddrdllcr;
  73. gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
  74. asm("sync;isync;msync");
  75. #endif
  76. #if defined(CONFIG_SPD_EEPROM)
  77. dram_size = fsl_ddr_sdram();
  78. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  79. dram_size *= 0x100000;
  80. #else
  81. dram_size = fixed_sdram ();
  82. #endif
  83. #if defined(CFG_RAMBOOT)
  84. return dram_size;
  85. #endif
  86. #if !defined(CONFIG_RAM_AS_FLASH) /* LocalBus is not emulating flash */
  87. get_sys_info(&sysinfo);
  88. /* if localbus freq is less than 66Mhz,we use bypass mode,otherwise use DLL */
  89. if(sysinfo.freqSystemBus/(CFG_LBC_LCRR & 0x0f) < 66000000) {
  90. lbc->lcrr = (CFG_LBC_LCRR & 0x0fffffff)| 0x80000000;
  91. } else {
  92. lbc->lcrr = CFG_LBC_LCRR & 0x7fffffff;
  93. udelay(200);
  94. temp_lbcdll = gur->lbcdllcr;
  95. gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16 ) | 0x80000000;
  96. asm("sync;isync;msync");
  97. }
  98. lbc->or2 = CFG_OR2_PRELIM; /* 64MB SDRAM */
  99. lbc->br2 = CFG_BR2_PRELIM;
  100. lbc->lbcr = CFG_LBC_LBCR;
  101. lbc->lsdmr = CFG_LBC_LSDMR_1;
  102. asm("sync");
  103. * (ulong *)0 = 0x000000ff;
  104. lbc->lsdmr = CFG_LBC_LSDMR_2;
  105. asm("sync");
  106. * (ulong *)0 = 0x000000ff;
  107. lbc->lsdmr = CFG_LBC_LSDMR_3;
  108. asm("sync");
  109. * (ulong *)0 = 0x000000ff;
  110. lbc->lsdmr = CFG_LBC_LSDMR_4;
  111. asm("sync");
  112. * (ulong *)0 = 0x000000ff;
  113. lbc->lsdmr = CFG_LBC_LSDMR_5;
  114. asm("sync");
  115. lbc->lsrt = CFG_LBC_LSRT;
  116. asm("sync");
  117. lbc->mrtpr = CFG_LBC_MRTPR;
  118. asm("sync");
  119. #endif
  120. #if defined(CONFIG_DDR_ECC)
  121. {
  122. /* Initialize all of memory for ECC, then
  123. * enable errors */
  124. uint *p = 0;
  125. uint i = 0;
  126. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  127. dma_init();
  128. for (*p = 0; p < (uint *)(8 * 1024); p++) {
  129. if (((unsigned int)p & 0x1f) == 0) { dcbz(p); }
  130. *p = (unsigned int)0xdeadbeef;
  131. if (((unsigned int)p & 0x1c) == 0x1c) { dcbf(p); }
  132. }
  133. /* 8K */
  134. dma_xfer((uint *)0x2000,0x2000,(uint *)0);
  135. /* 16K */
  136. dma_xfer((uint *)0x4000,0x4000,(uint *)0);
  137. /* 32K */
  138. dma_xfer((uint *)0x8000,0x8000,(uint *)0);
  139. /* 64K */
  140. dma_xfer((uint *)0x10000,0x10000,(uint *)0);
  141. /* 128k */
  142. dma_xfer((uint *)0x20000,0x20000,(uint *)0);
  143. /* 256k */
  144. dma_xfer((uint *)0x40000,0x40000,(uint *)0);
  145. /* 512k */
  146. dma_xfer((uint *)0x80000,0x80000,(uint *)0);
  147. /* 1M */
  148. dma_xfer((uint *)0x100000,0x100000,(uint *)0);
  149. /* 2M */
  150. dma_xfer((uint *)0x200000,0x200000,(uint *)0);
  151. /* 4M */
  152. dma_xfer((uint *)0x400000,0x400000,(uint *)0);
  153. for (i = 1; i < dram_size / 0x800000; i++) {
  154. dma_xfer((uint *)(0x800000*i),0x800000,(uint *)0);
  155. }
  156. /* Enable errors for ECC */
  157. ddr->err_disable = 0x00000000;
  158. asm("sync;isync;msync");
  159. }
  160. #endif
  161. return dram_size;
  162. }
  163. #if defined(CFG_DRAM_TEST)
  164. int testdram (void)
  165. {
  166. uint *pstart = (uint *) CFG_MEMTEST_START;
  167. uint *pend = (uint *) CFG_MEMTEST_END;
  168. uint *p;
  169. printf("SDRAM test phase 1:\n");
  170. for (p = pstart; p < pend; p++)
  171. *p = 0xaaaaaaaa;
  172. for (p = pstart; p < pend; p++) {
  173. if (*p != 0xaaaaaaaa) {
  174. printf ("SDRAM test fails at: %08x\n", (uint) p);
  175. return 1;
  176. }
  177. }
  178. printf("SDRAM test phase 2:\n");
  179. for (p = pstart; p < pend; p++)
  180. *p = 0x55555555;
  181. for (p = pstart; p < pend; p++) {
  182. if (*p != 0x55555555) {
  183. printf ("SDRAM test fails at: %08x\n", (uint) p);
  184. return 1;
  185. }
  186. }
  187. printf("SDRAM test passed.\n");
  188. return 0;
  189. }
  190. #endif
  191. #if !defined(CONFIG_SPD_EEPROM)
  192. /*************************************************************************
  193. * fixed sdram init -- doesn't use serial presence detect.
  194. ************************************************************************/
  195. long int fixed_sdram (void)
  196. {
  197. #ifndef CFG_RAMBOOT
  198. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  199. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  200. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  201. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  202. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  203. ddr->sdram_mode = CFG_DDR_MODE;
  204. ddr->sdram_interval = CFG_DDR_INTERVAL;
  205. #if defined (CONFIG_DDR_ECC)
  206. ddr->err_disable = 0x0000000D;
  207. ddr->err_sbe = 0x00ff0000;
  208. #endif
  209. asm("sync;isync;msync");
  210. udelay(500);
  211. #if defined (CONFIG_DDR_ECC)
  212. /* Enable ECC checking */
  213. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  214. #else
  215. ddr->sdram_cfg = CFG_DDR_CONTROL;
  216. #endif
  217. asm("sync; isync; msync");
  218. udelay(500);
  219. #endif
  220. return (CFG_SDRAM_SIZE * 1024 * 1024);
  221. }
  222. #endif /* !defined(CONFIG_SPD_EEPROM) */