mpc8540eval.c 6.8 KB

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