mpc8540eval.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/immap_85xx.h>
  28. #include <spd.h>
  29. extern long int spd_sdram (void);
  30. long int fixed_sdram (void);
  31. int board_pre_init (void)
  32. {
  33. #if defined(CONFIG_PCI)
  34. volatile ccsr_pcix_t *pci = (void *)(CFG_MPC85xx_PCIX_ADDR);
  35. pci->peer &= 0xffffffdf; /* disable master abort */
  36. #endif
  37. return 0;
  38. }
  39. int checkboard (void)
  40. {
  41. sys_info_t sysinfo;
  42. get_sys_info (&sysinfo);
  43. printf ("Board: Freescale MPC8540EVAL Board\n");
  44. printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
  45. printf ("\tCCB: %lu MHz\n", sysinfo.freqSystemBus / 1000000);
  46. printf ("\tDDR: %lu MHz\n", sysinfo.freqSystemBus / 2000000);
  47. if((CFG_LBC_LCRR & 0x0f) == 2 || (CFG_LBC_LCRR & 0x0f) == 4 \
  48. || (CFG_LBC_LCRR & 0x0f) == 8) {
  49. printf ("\tLBC: %lu MHz\n",
  50. sysinfo.freqSystemBus / 1000000/(CFG_LBC_LCRR & 0x0f));
  51. } else {
  52. printf("\tLBC: unknown\n");
  53. }
  54. printf("L1 D-cache 32KB, L1 I-cache 32KB enabled.\n");
  55. return (0);
  56. }
  57. long int initdram (int board_type)
  58. {
  59. long dram_size = 0;
  60. extern long spd_sdram (void);
  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 = spd_sdram ();
  78. #else
  79. dram_size = fixed_sdram ();
  80. #endif
  81. #if defined(CFG_RAMBOOT)
  82. return dram_size;
  83. #endif
  84. #if !defined(CONFIG_RAM_AS_FLASH) /* LocalBus is not emulating flash */
  85. get_sys_info(&sysinfo);
  86. /* if localbus freq is less than 66Mhz,we use bypass mode,otherwise use DLL */
  87. if(sysinfo.freqSystemBus/(CFG_LBC_LCRR & 0x0f) < 66000000) {
  88. lbc->lcrr = (CFG_LBC_LCRR & 0x0fffffff)| 0x80000000;
  89. } else {
  90. lbc->lcrr = CFG_LBC_LCRR & 0x7fffffff;
  91. udelay(200);
  92. temp_lbcdll = gur->lbcdllcr;
  93. gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16 ) | 0x80000000;
  94. asm("sync;isync;msync");
  95. }
  96. lbc->or2 = CFG_OR2_PRELIM; /* 64MB SDRAM */
  97. lbc->br2 = CFG_BR2_PRELIM;
  98. lbc->lbcr = CFG_LBC_LBCR;
  99. lbc->lsdmr = CFG_LBC_LSDMR_1;
  100. asm("sync");
  101. * (ulong *)0 = 0x000000ff;
  102. lbc->lsdmr = CFG_LBC_LSDMR_2;
  103. asm("sync");
  104. * (ulong *)0 = 0x000000ff;
  105. lbc->lsdmr = CFG_LBC_LSDMR_3;
  106. asm("sync");
  107. * (ulong *)0 = 0x000000ff;
  108. lbc->lsdmr = CFG_LBC_LSDMR_4;
  109. asm("sync");
  110. * (ulong *)0 = 0x000000ff;
  111. lbc->lsdmr = CFG_LBC_LSDMR_5;
  112. asm("sync");
  113. lbc->lsrt = CFG_LBC_LSRT;
  114. asm("sync");
  115. lbc->mrtpr = CFG_LBC_MRTPR;
  116. asm("sync");
  117. #endif
  118. #if defined(CONFIG_DDR_ECC)
  119. {
  120. /* Initialize all of memory for ECC, then
  121. * enable errors */
  122. uint *p = 0;
  123. uint i = 0;
  124. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  125. dma_init();
  126. for (*p = 0; p < (uint *)(8 * 1024); p++) {
  127. if (((unsigned int)p & 0x1f) == 0) { dcbz(p); }
  128. *p = (unsigned int)0xdeadbeef;
  129. if (((unsigned int)p & 0x1c) == 0x1c) { dcbf(p); }
  130. }
  131. /* 8K */
  132. dma_xfer((uint *)0x2000,0x2000,(uint *)0);
  133. /* 16K */
  134. dma_xfer((uint *)0x4000,0x4000,(uint *)0);
  135. /* 32K */
  136. dma_xfer((uint *)0x8000,0x8000,(uint *)0);
  137. /* 64K */
  138. dma_xfer((uint *)0x10000,0x10000,(uint *)0);
  139. /* 128k */
  140. dma_xfer((uint *)0x20000,0x20000,(uint *)0);
  141. /* 256k */
  142. dma_xfer((uint *)0x40000,0x40000,(uint *)0);
  143. /* 512k */
  144. dma_xfer((uint *)0x80000,0x80000,(uint *)0);
  145. /* 1M */
  146. dma_xfer((uint *)0x100000,0x100000,(uint *)0);
  147. /* 2M */
  148. dma_xfer((uint *)0x200000,0x200000,(uint *)0);
  149. /* 4M */
  150. dma_xfer((uint *)0x400000,0x400000,(uint *)0);
  151. for (i = 1; i < dram_size / 0x800000; i++) {
  152. dma_xfer((uint *)(0x800000*i),0x800000,(uint *)0);
  153. }
  154. /* Enable errors for ECC */
  155. ddr->err_disable = 0x00000000;
  156. asm("sync;isync;msync");
  157. }
  158. #endif
  159. return dram_size;
  160. }
  161. #if defined(CFG_DRAM_TEST)
  162. int testdram (void)
  163. {
  164. uint *pstart = (uint *) CFG_MEMTEST_START;
  165. uint *pend = (uint *) CFG_MEMTEST_END;
  166. uint *p;
  167. printf("SDRAM test phase 1:\n");
  168. for (p = pstart; p < pend; p++)
  169. *p = 0xaaaaaaaa;
  170. for (p = pstart; p < pend; p++) {
  171. if (*p != 0xaaaaaaaa) {
  172. printf ("SDRAM test fails at: %08x\n", (uint) p);
  173. return 1;
  174. }
  175. }
  176. printf("SDRAM test phase 2:\n");
  177. for (p = pstart; p < pend; p++)
  178. *p = 0x55555555;
  179. for (p = pstart; p < pend; p++) {
  180. if (*p != 0x55555555) {
  181. printf ("SDRAM test fails at: %08x\n", (uint) p);
  182. return 1;
  183. }
  184. }
  185. printf("SDRAM test passed.\n");
  186. return 0;
  187. }
  188. #endif
  189. #if !defined(CONFIG_SPD_EEPROM)
  190. /*************************************************************************
  191. * fixed sdram init -- doesn't use serial presence detect.
  192. ************************************************************************/
  193. long int fixed_sdram (void)
  194. {
  195. #ifndef CFG_RAMBOOT
  196. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  197. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  198. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  199. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  200. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  201. ddr->sdram_mode = CFG_DDR_MODE;
  202. ddr->sdram_interval = CFG_DDR_INTERVAL;
  203. #if defined (CONFIG_DDR_ECC)
  204. ddr->err_disable = 0x0000000D;
  205. ddr->err_sbe = 0x00ff0000;
  206. #endif
  207. asm("sync;isync;msync");
  208. udelay(500);
  209. #if defined (CONFIG_DDR_ECC)
  210. /* Enable ECC checking */
  211. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  212. #else
  213. ddr->sdram_cfg = CFG_DDR_CONTROL;
  214. #endif
  215. asm("sync; isync; msync");
  216. udelay(500);
  217. #endif
  218. return (CFG_SDRAM_SIZE * 1024 * 1024);
  219. }
  220. #endif /* !defined(CONFIG_SPD_EEPROM) */