mpc8540eval.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 immap_t *immr = (immap_t *)CFG_IMMR;
  35. volatile ccsr_pcix_t *pci = &immr->im_pcix;
  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. long int initdram (int board_type)
  59. {
  60. long dram_size = 0;
  61. extern long spd_sdram (void);
  62. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  63. #if !defined(CONFIG_RAM_AS_FLASH)
  64. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  65. sys_info_t sysinfo;
  66. uint temp_lbcdll = 0;
  67. #endif
  68. #if !defined(CONFIG_RAM_AS_FLASH) || defined(CONFIG_DDR_DLL)
  69. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  70. #endif
  71. #if defined(CONFIG_DDR_DLL)
  72. uint temp_ddrdll = 0;
  73. /* Work around to stabilize DDR DLL */
  74. temp_ddrdll = gur->ddrdllcr;
  75. gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
  76. asm("sync;isync;msync");
  77. #endif
  78. #if defined(CONFIG_SPD_EEPROM)
  79. dram_size = spd_sdram ();
  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 immap_t *immap = (immap_t *)CFG_IMMR;
  127. volatile ccsr_ddr_t *ddr= &immap->im_ddr;
  128. dma_init();
  129. for (*p = 0; p < (uint *)(8 * 1024); p++) {
  130. if (((unsigned int)p & 0x1f) == 0) { dcbz(p); }
  131. *p = (unsigned int)0xdeadbeef;
  132. if (((unsigned int)p & 0x1c) == 0x1c) { dcbf(p); }
  133. }
  134. /* 8K */
  135. dma_xfer((uint *)0x2000,0x2000,(uint *)0);
  136. /* 16K */
  137. dma_xfer((uint *)0x4000,0x4000,(uint *)0);
  138. /* 32K */
  139. dma_xfer((uint *)0x8000,0x8000,(uint *)0);
  140. /* 64K */
  141. dma_xfer((uint *)0x10000,0x10000,(uint *)0);
  142. /* 128k */
  143. dma_xfer((uint *)0x20000,0x20000,(uint *)0);
  144. /* 256k */
  145. dma_xfer((uint *)0x40000,0x40000,(uint *)0);
  146. /* 512k */
  147. dma_xfer((uint *)0x80000,0x80000,(uint *)0);
  148. /* 1M */
  149. dma_xfer((uint *)0x100000,0x100000,(uint *)0);
  150. /* 2M */
  151. dma_xfer((uint *)0x200000,0x200000,(uint *)0);
  152. /* 4M */
  153. dma_xfer((uint *)0x400000,0x400000,(uint *)0);
  154. for (i = 1; i < dram_size / 0x800000; i++) {
  155. dma_xfer((uint *)(0x800000*i),0x800000,(uint *)0);
  156. }
  157. /* Enable errors for ECC */
  158. ddr->err_disable = 0x00000000;
  159. asm("sync;isync;msync");
  160. }
  161. #endif
  162. return dram_size;
  163. }
  164. #if defined(CFG_DRAM_TEST)
  165. int testdram (void)
  166. {
  167. uint *pstart = (uint *) CFG_MEMTEST_START;
  168. uint *pend = (uint *) CFG_MEMTEST_END;
  169. uint *p;
  170. printf("SDRAM test phase 1:\n");
  171. for (p = pstart; p < pend; p++)
  172. *p = 0xaaaaaaaa;
  173. for (p = pstart; p < pend; p++) {
  174. if (*p != 0xaaaaaaaa) {
  175. printf ("SDRAM test fails at: %08x\n", (uint) p);
  176. return 1;
  177. }
  178. }
  179. printf("SDRAM test phase 2:\n");
  180. for (p = pstart; p < pend; p++)
  181. *p = 0x55555555;
  182. for (p = pstart; p < pend; p++) {
  183. if (*p != 0x55555555) {
  184. printf ("SDRAM test fails at: %08x\n", (uint) p);
  185. return 1;
  186. }
  187. }
  188. printf("SDRAM test passed.\n");
  189. return 0;
  190. }
  191. #endif
  192. #if !defined(CONFIG_SPD_EEPROM)
  193. /*************************************************************************
  194. * fixed sdram init -- doesn't use serial presence detect.
  195. ************************************************************************/
  196. long int fixed_sdram (void)
  197. {
  198. #ifndef CFG_RAMBOOT
  199. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  200. volatile ccsr_ddr_t *ddr= &immap->im_ddr;
  201. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  202. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  203. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  204. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  205. ddr->sdram_mode = CFG_DDR_MODE;
  206. ddr->sdram_interval = CFG_DDR_INTERVAL;
  207. #if defined (CONFIG_DDR_ECC)
  208. ddr->err_disable = 0x0000000D;
  209. ddr->err_sbe = 0x00ff0000;
  210. #endif
  211. asm("sync;isync;msync");
  212. udelay(500);
  213. #if defined (CONFIG_DDR_ECC)
  214. /* Enable ECC checking */
  215. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  216. #else
  217. ddr->sdram_cfg = CFG_DDR_CONTROL;
  218. #endif
  219. asm("sync; isync; msync");
  220. udelay(500);
  221. #endif
  222. return (CFG_SDRAM_SIZE * 1024 * 1024);
  223. }
  224. #endif /* !defined(CONFIG_SPD_EEPROM) */