mpc8540eval.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 <netdev.h>
  27. #include <asm/processor.h>
  28. #include <asm/mmu.h>
  29. #include <asm/immap_85xx.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <spd_sdram.h>
  32. long int fixed_sdram (void);
  33. int board_pre_init (void)
  34. {
  35. #if defined(CONFIG_PCI)
  36. volatile ccsr_pcix_t *pci = (void *)(CONFIG_SYS_MPC85xx_PCIX_ADDR);
  37. pci->peer &= 0xffffffdf; /* disable master abort */
  38. #endif
  39. return 0;
  40. }
  41. int checkboard (void)
  42. {
  43. sys_info_t sysinfo;
  44. get_sys_info (&sysinfo);
  45. printf ("Board: Freescale MPC8540EVAL Board\n");
  46. printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
  47. printf ("\tCCB: %lu MHz\n", sysinfo.freqSystemBus / 1000000);
  48. printf ("\tDDR: %lu MHz\n", sysinfo.freqSystemBus / 2000000);
  49. if((CONFIG_SYS_LBC_LCRR & 0x0f) == 2 || (CONFIG_SYS_LBC_LCRR & 0x0f) == 4 \
  50. || (CONFIG_SYS_LBC_LCRR & 0x0f) == 8) {
  51. printf ("\tLBC: %lu MHz\n",
  52. sysinfo.freqSystemBus / 1000000/(CONFIG_SYS_LBC_LCRR & 0x0f));
  53. } else {
  54. printf("\tLBC: unknown\n");
  55. }
  56. printf("L1 D-cache 32KB, L1 I-cache 32KB enabled.\n");
  57. return (0);
  58. }
  59. phys_size_t initdram (int board_type)
  60. {
  61. long dram_size = 0;
  62. #if !defined(CONFIG_RAM_AS_FLASH)
  63. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  64. sys_info_t sysinfo;
  65. uint temp_lbcdll = 0;
  66. #endif
  67. #if !defined(CONFIG_RAM_AS_FLASH) || defined(CONFIG_DDR_DLL)
  68. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  69. #endif
  70. #if defined(CONFIG_DDR_DLL)
  71. uint temp_ddrdll = 0;
  72. /* Work around to stabilize DDR DLL */
  73. temp_ddrdll = gur->ddrdllcr;
  74. gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
  75. asm("sync;isync;msync");
  76. #endif
  77. #if defined(CONFIG_SPD_EEPROM)
  78. dram_size = fsl_ddr_sdram();
  79. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  80. dram_size *= 0x100000;
  81. #else
  82. dram_size = fixed_sdram ();
  83. #endif
  84. #if defined(CONFIG_SYS_RAMBOOT)
  85. return dram_size;
  86. #endif
  87. #if !defined(CONFIG_RAM_AS_FLASH) /* LocalBus is not emulating flash */
  88. get_sys_info(&sysinfo);
  89. /* if localbus freq is less than 66MHz,we use bypass mode,otherwise use DLL */
  90. if(sysinfo.freqSystemBus/(CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV) < 66000000) {
  91. lbc->lcrr = (CONFIG_SYS_LBC_LCRR & 0x0fffffff)| 0x80000000;
  92. } else {
  93. lbc->lcrr = CONFIG_SYS_LBC_LCRR & 0x7fffffff;
  94. udelay(200);
  95. temp_lbcdll = gur->lbcdllcr;
  96. gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16 ) | 0x80000000;
  97. asm("sync;isync;msync");
  98. }
  99. lbc->or2 = CONFIG_SYS_OR2_PRELIM; /* 64MB SDRAM */
  100. lbc->br2 = CONFIG_SYS_BR2_PRELIM;
  101. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  102. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
  103. asm("sync");
  104. * (ulong *)0 = 0x000000ff;
  105. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
  106. asm("sync");
  107. * (ulong *)0 = 0x000000ff;
  108. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
  109. asm("sync");
  110. * (ulong *)0 = 0x000000ff;
  111. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  112. asm("sync");
  113. * (ulong *)0 = 0x000000ff;
  114. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
  115. asm("sync");
  116. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  117. asm("sync");
  118. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  119. asm("sync");
  120. #endif
  121. #if defined(CONFIG_DDR_ECC)
  122. {
  123. /* Initialize all of memory for ECC, then
  124. * enable errors */
  125. uint *p = 0;
  126. uint i = 0;
  127. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  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(CONFIG_SYS_DRAM_TEST)
  165. int testdram (void)
  166. {
  167. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  168. uint *pend = (uint *) CONFIG_SYS_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 CONFIG_SYS_RAMBOOT
  199. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  200. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  201. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  202. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  203. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  204. ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  205. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  206. #if defined (CONFIG_DDR_ECC)
  207. ddr->err_disable = 0x0000000D;
  208. ddr->err_sbe = 0x00ff0000;
  209. #endif
  210. asm("sync;isync;msync");
  211. udelay(500);
  212. #if defined (CONFIG_DDR_ECC)
  213. /* Enable ECC checking */
  214. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  215. #else
  216. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  217. #endif
  218. asm("sync; isync; msync");
  219. udelay(500);
  220. #endif
  221. return (CONFIG_SYS_SDRAM_SIZE * 1024 * 1024);
  222. }
  223. #endif /* !defined(CONFIG_SPD_EEPROM) */
  224. int board_eth_init(bd_t *bis)
  225. {
  226. /*
  227. * This board either has PCI NICs or uses the CPU's TSECs
  228. * pci_eth_init() will return 0 if no NICs found, so in that case
  229. * returning -1 will force cpu_eth_init() to be called.
  230. */
  231. int num = pci_eth_init(bis);
  232. return (num <= 0 ? -1 : num);
  233. }