mpc8540eval.c 6.3 KB

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