pm854.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * (C) Copyright 2002,2003, Motorola Inc.
  4. * Xianghua Xiao, (X.Xiao@motorola.com)
  5. *
  6. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <pci.h>
  28. #include <asm/processor.h>
  29. #include <asm/mmu.h>
  30. #include <asm/immap_85xx.h>
  31. #include <asm/fsl_ddr_sdram.h>
  32. #include <spd_sdram.h>
  33. #if defined(CONFIG_DDR_ECC)
  34. extern void ddr_enable_ecc(unsigned int dram_size);
  35. #endif
  36. void local_bus_init(void);
  37. void sdram_init(void);
  38. long int fixed_sdram(void);
  39. int board_early_init_f (void)
  40. {
  41. #if defined(CONFIG_PCI)
  42. volatile ccsr_pcix_t *pci = (void *)(CFG_MPC85xx_PCIX_ADDR);
  43. pci->peer &= 0xffffffdf; /* disable master abort */
  44. #endif
  45. return 0;
  46. }
  47. int checkboard (void)
  48. {
  49. puts("Board: MicroSys PM854\n");
  50. #ifdef CONFIG_PCI
  51. printf(" PCI1: 32 bit, %d MHz (compiled)\n",
  52. CONFIG_SYS_CLK_FREQ / 1000000);
  53. #else
  54. printf(" PCI1: disabled\n");
  55. #endif
  56. /*
  57. * Initialize local bus.
  58. */
  59. local_bus_init();
  60. return 0;
  61. }
  62. phys_size_t
  63. initdram(int board_type)
  64. {
  65. long dram_size = 0;
  66. puts("Initializing\n");
  67. #if defined(CONFIG_DDR_DLL)
  68. {
  69. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  70. int i,x;
  71. x = 10;
  72. /*
  73. * Work around to stabilize DDR DLL
  74. */
  75. gur->ddrdllcr = 0x81000000;
  76. asm("sync;isync;msync");
  77. udelay (200);
  78. while (gur->ddrdllcr != 0x81000100)
  79. {
  80. gur->devdisr = gur->devdisr | 0x00010000;
  81. asm("sync;isync;msync");
  82. for (i=0; i<x; i++)
  83. ;
  84. gur->devdisr = gur->devdisr & 0xfff7ffff;
  85. asm("sync;isync;msync");
  86. x++;
  87. }
  88. }
  89. #endif
  90. #if defined(CONFIG_SPD_EEPROM)
  91. dram_size = fsl_ddr_sdram();
  92. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  93. dram_size *= 0x100000;
  94. #else
  95. dram_size = fixed_sdram ();
  96. #endif
  97. #if defined(CONFIG_DDR_ECC)
  98. /*
  99. * Initialize and enable DDR ECC.
  100. */
  101. ddr_enable_ecc(dram_size);
  102. #endif
  103. puts(" DDR: ");
  104. return dram_size;
  105. }
  106. /*
  107. * Initialize Local Bus
  108. */
  109. void
  110. local_bus_init(void)
  111. {
  112. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  113. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  114. uint clkdiv;
  115. uint lbc_hz;
  116. sys_info_t sysinfo;
  117. /*
  118. * Errata LBC11.
  119. * Fix Local Bus clock glitch when DLL is enabled.
  120. *
  121. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  122. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  123. * Between 66 and 133, the DLL is enabled with an override workaround.
  124. */
  125. get_sys_info(&sysinfo);
  126. clkdiv = lbc->lcrr & 0x0f;
  127. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  128. if (lbc_hz < 66) {
  129. lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
  130. } else if (lbc_hz >= 133) {
  131. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  132. } else {
  133. /*
  134. * On REV1 boards, need to change CLKDIV before enable DLL.
  135. * Default CLKDIV is 8, change it to 4 temporarily.
  136. */
  137. uint pvr = get_pvr();
  138. uint temp_lbcdll = 0;
  139. if (pvr == PVR_85xx_REV1) {
  140. /* FIXME: Justify the high bit here. */
  141. lbc->lcrr = 0x10000004;
  142. }
  143. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  144. udelay(200);
  145. /*
  146. * Sample LBC DLL ctrl reg, upshift it to set the
  147. * override bits.
  148. */
  149. temp_lbcdll = gur->lbcdllcr;
  150. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  151. asm("sync;isync;msync");
  152. }
  153. }
  154. #if defined(CFG_DRAM_TEST)
  155. int testdram (void)
  156. {
  157. uint *pstart = (uint *) CFG_MEMTEST_START;
  158. uint *pend = (uint *) CFG_MEMTEST_END;
  159. uint *p;
  160. printf("SDRAM test phase 1:\n");
  161. for (p = pstart; p < pend; p++)
  162. *p = 0xaaaaaaaa;
  163. for (p = pstart; p < pend; p++) {
  164. if (*p != 0xaaaaaaaa) {
  165. printf ("SDRAM test fails at: %08x\n", (uint) p);
  166. return 1;
  167. }
  168. }
  169. printf("SDRAM test phase 2:\n");
  170. for (p = pstart; p < pend; p++)
  171. *p = 0x55555555;
  172. for (p = pstart; p < pend; p++) {
  173. if (*p != 0x55555555) {
  174. printf ("SDRAM test fails at: %08x\n", (uint) p);
  175. return 1;
  176. }
  177. }
  178. printf("SDRAM test passed.\n");
  179. return 0;
  180. }
  181. #endif
  182. #if !defined(CONFIG_SPD_EEPROM)
  183. /*************************************************************************
  184. * fixed sdram init -- doesn't use serial presence detect.
  185. ************************************************************************/
  186. long int fixed_sdram (void)
  187. {
  188. #ifndef CFG_RAMBOOT
  189. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  190. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  191. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  192. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  193. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  194. ddr->sdram_mode = CFG_DDR_MODE;
  195. ddr->sdram_interval = CFG_DDR_INTERVAL;
  196. #if defined (CONFIG_DDR_ECC)
  197. ddr->err_disable = 0x0000000D;
  198. ddr->err_sbe = 0x00ff0000;
  199. #endif
  200. asm("sync;isync;msync");
  201. udelay(500);
  202. #if defined (CONFIG_DDR_ECC)
  203. /* Enable ECC checking */
  204. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  205. #else
  206. ddr->sdram_cfg = CFG_DDR_CONTROL;
  207. #endif
  208. asm("sync; isync; msync");
  209. udelay(500);
  210. #endif
  211. return CFG_SDRAM_SIZE * 1024 * 1024;
  212. }
  213. #endif /* !defined(CONFIG_SPD_EEPROM) */
  214. #if defined(CONFIG_PCI)
  215. /*
  216. * Initialize PCI Devices, report devices found.
  217. */
  218. #ifndef CONFIG_PCI_PNP
  219. static struct pci_config_table pci_pm854_config_table[] = {
  220. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  221. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  222. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  223. PCI_ENET0_MEMADDR,
  224. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  225. } },
  226. { }
  227. };
  228. #endif
  229. static struct pci_controller hose = {
  230. #ifndef CONFIG_PCI_PNP
  231. config_table: pci_pm854_config_table,
  232. #endif
  233. };
  234. #endif /* CONFIG_PCI */
  235. void
  236. pci_init_board(void)
  237. {
  238. #ifdef CONFIG_PCI
  239. pci_mpc85xx_init(&hose);
  240. #endif /* CONFIG_PCI */
  241. }