pm854.c 6.5 KB

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