sbc8548.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright 2007,2009 Wind River Systems, Inc. <www.windriver.com>
  3. *
  4. * Copyright 2007 Embedded Specialties, Inc.
  5. *
  6. * Copyright 2004, 2007 Freescale Semiconductor.
  7. *
  8. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <pci.h>
  30. #include <asm/processor.h>
  31. #include <asm/immap_85xx.h>
  32. #include <asm/fsl_pci.h>
  33. #include <asm/fsl_ddr_sdram.h>
  34. #include <asm/fsl_serdes.h>
  35. #include <spd_sdram.h>
  36. #include <netdev.h>
  37. #include <tsec.h>
  38. #include <miiphy.h>
  39. #include <libfdt.h>
  40. #include <fdt_support.h>
  41. DECLARE_GLOBAL_DATA_PTR;
  42. void local_bus_init(void);
  43. int board_early_init_f (void)
  44. {
  45. return 0;
  46. }
  47. int checkboard (void)
  48. {
  49. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  50. volatile u_char *rev= (void *)CONFIG_SYS_BD_REV;
  51. printf ("Board: Wind River SBC8548 Rev. 0x%01x\n",
  52. in_8(rev) >> 4);
  53. /*
  54. * Initialize local bus.
  55. */
  56. local_bus_init ();
  57. out_be32(&ecm->eedr, 0xffffffff); /* clear ecm errors */
  58. out_be32(&ecm->eeer, 0xffffffff); /* enable ecm errors */
  59. return 0;
  60. }
  61. /*
  62. * Initialize Local Bus
  63. */
  64. void
  65. local_bus_init(void)
  66. {
  67. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  68. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  69. uint clkdiv, lbc_mhz, lcrr = CONFIG_SYS_LBC_LCRR;
  70. sys_info_t sysinfo;
  71. get_sys_info(&sysinfo);
  72. lbc_mhz = sysinfo.freqLocalBus / 1000000;
  73. clkdiv = sysinfo.freqSystemBus / sysinfo.freqLocalBus;
  74. debug("LCRR=0x%x, CD=%d, MHz=%d\n", lcrr, clkdiv, lbc_mhz);
  75. out_be32(&gur->lbiuiplldcr1, 0x00078080);
  76. if (clkdiv == 16) {
  77. out_be32(&gur->lbiuiplldcr0, 0x7c0f1bf0);
  78. } else if (clkdiv == 8) {
  79. out_be32(&gur->lbiuiplldcr0, 0x6c0f1bf0);
  80. } else if (clkdiv == 4) {
  81. out_be32(&gur->lbiuiplldcr0, 0x5c0f1bf0);
  82. }
  83. /*
  84. * Local Bus Clock > 83.3 MHz. According to timing
  85. * specifications set LCRR[EADC] to 2 delay cycles.
  86. */
  87. if (lbc_mhz > 83) {
  88. lcrr &= ~LCRR_EADC;
  89. lcrr |= LCRR_EADC_2;
  90. }
  91. /*
  92. * According to MPC8548ERMAD Rev. 1.3, 13.3.1.16, 13-30
  93. * disable PLL bypass for Local Bus Clock > 83 MHz.
  94. */
  95. if (lbc_mhz >= 66)
  96. lcrr &= (~LCRR_DBYP); /* DLL Enabled */
  97. else
  98. lcrr |= LCRR_DBYP; /* DLL Bypass */
  99. out_be32(&lbc->lcrr, lcrr);
  100. asm("sync;isync;msync");
  101. /*
  102. * According to MPC8548ERMAD Rev.1.3 read back LCRR
  103. * and terminate with isync
  104. */
  105. lcrr = in_be32(&lbc->lcrr);
  106. asm ("isync;");
  107. /* let DLL stabilize */
  108. udelay(500);
  109. out_be32(&lbc->ltesr, 0xffffffff); /* Clear LBC error IRQs */
  110. out_be32(&lbc->lteir, 0xffffffff); /* Enable LBC error IRQs */
  111. }
  112. /*
  113. * Initialize SDRAM memory on the Local Bus.
  114. */
  115. void lbc_sdram_init(void)
  116. {
  117. #if defined(CONFIG_SYS_LBC_SDRAM_SIZE)
  118. uint idx;
  119. const unsigned long size = CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024;
  120. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  121. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  122. uint *sdram_addr2 = (uint *)(CONFIG_SYS_LBC_SDRAM_BASE + size/2);
  123. puts(" SDRAM: ");
  124. print_size(size, "\n");
  125. /*
  126. * Setup SDRAM Base and Option Registers
  127. */
  128. set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
  129. set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
  130. set_lbc_or(4, CONFIG_SYS_OR4_PRELIM);
  131. set_lbc_br(4, CONFIG_SYS_BR4_PRELIM);
  132. out_be32(&lbc->lbcr, CONFIG_SYS_LBC_LBCR);
  133. asm("msync");
  134. out_be32(&lbc->lsrt, CONFIG_SYS_LBC_LSRT);
  135. out_be32(&lbc->mrtpr, CONFIG_SYS_LBC_MRTPR);
  136. asm("msync");
  137. /*
  138. * Issue PRECHARGE ALL command.
  139. */
  140. out_be32(&lbc->lsdmr, CONFIG_SYS_LBC_LSDMR_PCHALL);
  141. asm("sync;msync");
  142. *sdram_addr = 0xff;
  143. ppcDcbf((unsigned long) sdram_addr);
  144. *sdram_addr2 = 0xff;
  145. ppcDcbf((unsigned long) sdram_addr2);
  146. udelay(100);
  147. /*
  148. * Issue 8 AUTO REFRESH commands.
  149. */
  150. for (idx = 0; idx < 8; idx++) {
  151. out_be32(&lbc->lsdmr, CONFIG_SYS_LBC_LSDMR_ARFRSH);
  152. asm("sync;msync");
  153. *sdram_addr = 0xff;
  154. ppcDcbf((unsigned long) sdram_addr);
  155. *sdram_addr2 = 0xff;
  156. ppcDcbf((unsigned long) sdram_addr2);
  157. udelay(100);
  158. }
  159. /*
  160. * Issue 8 MODE-set command.
  161. */
  162. out_be32(&lbc->lsdmr, CONFIG_SYS_LBC_LSDMR_MRW);
  163. asm("sync;msync");
  164. *sdram_addr = 0xff;
  165. ppcDcbf((unsigned long) sdram_addr);
  166. *sdram_addr2 = 0xff;
  167. ppcDcbf((unsigned long) sdram_addr2);
  168. udelay(100);
  169. /*
  170. * Issue RFEN command.
  171. */
  172. out_be32(&lbc->lsdmr, CONFIG_SYS_LBC_LSDMR_RFEN);
  173. asm("sync;msync");
  174. *sdram_addr = 0xff;
  175. ppcDcbf((unsigned long) sdram_addr);
  176. *sdram_addr2 = 0xff;
  177. ppcDcbf((unsigned long) sdram_addr2);
  178. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  179. #endif /* enable SDRAM init */
  180. }
  181. #if defined(CONFIG_SYS_DRAM_TEST)
  182. int
  183. testdram(void)
  184. {
  185. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  186. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  187. uint *p;
  188. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  189. CONFIG_SYS_MEMTEST_START,
  190. CONFIG_SYS_MEMTEST_END);
  191. printf("DRAM test phase 1:\n");
  192. for (p = pstart; p < pend; p++)
  193. *p = 0xaaaaaaaa;
  194. for (p = pstart; p < pend; p++) {
  195. if (*p != 0xaaaaaaaa) {
  196. printf ("DRAM test fails at: %08x\n", (uint) p);
  197. return 1;
  198. }
  199. }
  200. printf("DRAM test phase 2:\n");
  201. for (p = pstart; p < pend; p++)
  202. *p = 0x55555555;
  203. for (p = pstart; p < pend; p++) {
  204. if (*p != 0x55555555) {
  205. printf ("DRAM test fails at: %08x\n", (uint) p);
  206. return 1;
  207. }
  208. }
  209. printf("DRAM test passed.\n");
  210. return 0;
  211. }
  212. #endif
  213. #ifdef CONFIG_PCI1
  214. static struct pci_controller pci1_hose;
  215. #endif /* CONFIG_PCI1 */
  216. #ifdef CONFIG_PCI
  217. void
  218. pci_init_board(void)
  219. {
  220. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  221. int first_free_busno = 0;
  222. #ifdef CONFIG_PCI1
  223. struct fsl_pci_info pci_info;
  224. u32 devdisr = in_be32(&gur->devdisr);
  225. u32 pordevsr = in_be32(&gur->pordevsr);
  226. u32 porpllsr = in_be32(&gur->porpllsr);
  227. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  228. uint pci_32 = pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  229. uint pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  230. uint pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  231. uint pci_speed = CONFIG_SYS_CLK_FREQ; /* get_clock_freq() */
  232. printf("PCI: Host, %d bit, %s MHz, %s, %s\n",
  233. (pci_32) ? 32 : 64,
  234. (pci_speed == 33000000) ? "33" :
  235. (pci_speed == 66000000) ? "66" : "unknown",
  236. pci_clk_sel ? "sync" : "async",
  237. pci_arb ? "arbiter" : "external-arbiter");
  238. SET_STD_PCI_INFO(pci_info, 1);
  239. set_next_law(pci_info.mem_phys,
  240. law_size_bits(pci_info.mem_size), pci_info.law);
  241. set_next_law(pci_info.io_phys,
  242. law_size_bits(pci_info.io_size), pci_info.law);
  243. first_free_busno = fsl_pci_init_port(&pci_info,
  244. &pci1_hose, first_free_busno);
  245. } else {
  246. printf("PCI: disabled\n");
  247. }
  248. puts("\n");
  249. #else
  250. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  251. #endif
  252. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI2); /* disable PCI2 */
  253. fsl_pcie_init_board(first_free_busno);
  254. }
  255. #endif
  256. int board_eth_init(bd_t *bis)
  257. {
  258. tsec_standard_init(bis);
  259. pci_eth_init(bis);
  260. return 0; /* otherwise cpu_eth_init gets run */
  261. }
  262. int last_stage_init(void)
  263. {
  264. return 0;
  265. }
  266. #if defined(CONFIG_OF_BOARD_SETUP)
  267. void ft_board_setup(void *blob, bd_t *bd)
  268. {
  269. ft_cpu_setup(blob, bd);
  270. #ifdef CONFIG_FSL_PCI_INIT
  271. FT_FSL_PCI_SETUP;
  272. #endif
  273. }
  274. #endif