sbc8548.c 6.8 KB

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