pm854.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/immap_85xx.h>
  30. #include <spd_sdram.h>
  31. #if defined(CONFIG_DDR_ECC)
  32. extern void ddr_enable_ecc(unsigned int dram_size);
  33. #endif
  34. void local_bus_init(void);
  35. void sdram_init(void);
  36. long int fixed_sdram(void);
  37. int board_early_init_f (void)
  38. {
  39. #if defined(CONFIG_PCI)
  40. volatile ccsr_pcix_t *pci = (void *)(CFG_MPC85xx_PCIX_ADDR);
  41. pci->peer &= 0xffffffdf; /* disable master abort */
  42. #endif
  43. return 0;
  44. }
  45. int checkboard (void)
  46. {
  47. puts("Board: MicroSys PM854\n");
  48. #ifdef CONFIG_PCI
  49. printf(" PCI1: 32 bit, %d MHz (compiled)\n",
  50. CONFIG_SYS_CLK_FREQ / 1000000);
  51. #else
  52. printf(" PCI1: disabled\n");
  53. #endif
  54. /*
  55. * Initialize local bus.
  56. */
  57. local_bus_init();
  58. return 0;
  59. }
  60. long int
  61. initdram(int board_type)
  62. {
  63. long dram_size = 0;
  64. puts("Initializing\n");
  65. #if defined(CONFIG_DDR_DLL)
  66. {
  67. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  68. int i,x;
  69. x = 10;
  70. /*
  71. * Work around to stabilize DDR DLL
  72. */
  73. gur->ddrdllcr = 0x81000000;
  74. asm("sync;isync;msync");
  75. udelay (200);
  76. while (gur->ddrdllcr != 0x81000100)
  77. {
  78. gur->devdisr = gur->devdisr | 0x00010000;
  79. asm("sync;isync;msync");
  80. for (i=0; i<x; i++)
  81. ;
  82. gur->devdisr = gur->devdisr & 0xfff7ffff;
  83. asm("sync;isync;msync");
  84. x++;
  85. }
  86. }
  87. #endif
  88. #if defined(CONFIG_SPD_EEPROM)
  89. dram_size = spd_sdram ();
  90. #else
  91. dram_size = fixed_sdram ();
  92. #endif
  93. #if defined(CONFIG_DDR_ECC)
  94. /*
  95. * Initialize and enable DDR ECC.
  96. */
  97. ddr_enable_ecc(dram_size);
  98. #endif
  99. puts(" DDR: ");
  100. return dram_size;
  101. }
  102. /*
  103. * Initialize Local Bus
  104. */
  105. void
  106. local_bus_init(void)
  107. {
  108. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  109. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  110. uint clkdiv;
  111. uint lbc_hz;
  112. sys_info_t sysinfo;
  113. /*
  114. * Errata LBC11.
  115. * Fix Local Bus clock glitch when DLL is enabled.
  116. *
  117. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  118. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  119. * Between 66 and 133, the DLL is enabled with an override workaround.
  120. */
  121. get_sys_info(&sysinfo);
  122. clkdiv = lbc->lcrr & 0x0f;
  123. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  124. if (lbc_hz < 66) {
  125. lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
  126. } else if (lbc_hz >= 133) {
  127. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  128. } else {
  129. /*
  130. * On REV1 boards, need to change CLKDIV before enable DLL.
  131. * Default CLKDIV is 8, change it to 4 temporarily.
  132. */
  133. uint pvr = get_pvr();
  134. uint temp_lbcdll = 0;
  135. if (pvr == PVR_85xx_REV1) {
  136. /* FIXME: Justify the high bit here. */
  137. lbc->lcrr = 0x10000004;
  138. }
  139. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  140. udelay(200);
  141. /*
  142. * Sample LBC DLL ctrl reg, upshift it to set the
  143. * override bits.
  144. */
  145. temp_lbcdll = gur->lbcdllcr;
  146. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  147. asm("sync;isync;msync");
  148. }
  149. }
  150. #if defined(CFG_DRAM_TEST)
  151. int testdram (void)
  152. {
  153. uint *pstart = (uint *) CFG_MEMTEST_START;
  154. uint *pend = (uint *) CFG_MEMTEST_END;
  155. uint *p;
  156. printf("SDRAM test phase 1:\n");
  157. for (p = pstart; p < pend; p++)
  158. *p = 0xaaaaaaaa;
  159. for (p = pstart; p < pend; p++) {
  160. if (*p != 0xaaaaaaaa) {
  161. printf ("SDRAM test fails at: %08x\n", (uint) p);
  162. return 1;
  163. }
  164. }
  165. printf("SDRAM test phase 2:\n");
  166. for (p = pstart; p < pend; p++)
  167. *p = 0x55555555;
  168. for (p = pstart; p < pend; p++) {
  169. if (*p != 0x55555555) {
  170. printf ("SDRAM test fails at: %08x\n", (uint) p);
  171. return 1;
  172. }
  173. }
  174. printf("SDRAM test passed.\n");
  175. return 0;
  176. }
  177. #endif
  178. #if !defined(CONFIG_SPD_EEPROM)
  179. /*************************************************************************
  180. * fixed sdram init -- doesn't use serial presence detect.
  181. ************************************************************************/
  182. long int fixed_sdram (void)
  183. {
  184. #ifndef CFG_RAMBOOT
  185. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  186. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  187. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  188. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  189. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  190. ddr->sdram_mode = CFG_DDR_MODE;
  191. ddr->sdram_interval = CFG_DDR_INTERVAL;
  192. #if defined (CONFIG_DDR_ECC)
  193. ddr->err_disable = 0x0000000D;
  194. ddr->err_sbe = 0x00ff0000;
  195. #endif
  196. asm("sync;isync;msync");
  197. udelay(500);
  198. #if defined (CONFIG_DDR_ECC)
  199. /* Enable ECC checking */
  200. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  201. #else
  202. ddr->sdram_cfg = CFG_DDR_CONTROL;
  203. #endif
  204. asm("sync; isync; msync");
  205. udelay(500);
  206. #endif
  207. return CFG_SDRAM_SIZE * 1024 * 1024;
  208. }
  209. #endif /* !defined(CONFIG_SPD_EEPROM) */
  210. #if defined(CONFIG_PCI)
  211. /*
  212. * Initialize PCI Devices, report devices found.
  213. */
  214. #ifndef CONFIG_PCI_PNP
  215. static struct pci_config_table pci_pm854_config_table[] = {
  216. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  217. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  218. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  219. PCI_ENET0_MEMADDR,
  220. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  221. } },
  222. { }
  223. };
  224. #endif
  225. static struct pci_controller hose = {
  226. #ifndef CONFIG_PCI_PNP
  227. config_table: pci_pm854_config_table,
  228. #endif
  229. };
  230. #endif /* CONFIG_PCI */
  231. void
  232. pci_init_board(void)
  233. {
  234. #ifdef CONFIG_PCI
  235. pci_mpc85xx_init(&hose);
  236. #endif /* CONFIG_PCI */
  237. }