pm854.c 6.2 KB

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