sbc8548.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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;
  70. uint lbc_hz;
  71. sys_info_t sysinfo;
  72. get_sys_info(&sysinfo);
  73. clkdiv = (in_be32(&lbc->lcrr) & LCRR_CLKDIV) * 2;
  74. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  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. setbits_be32(&lbc->lcrr, 0x00030000);
  84. asm("sync;isync;msync");
  85. out_be32(&lbc->ltesr, 0xffffffff); /* Clear LBC error IRQs */
  86. out_be32(&lbc->lteir, 0xffffffff); /* Enable LBC error IRQs */
  87. }
  88. /*
  89. * Initialize SDRAM memory on the Local Bus.
  90. */
  91. void
  92. sdram_init(void)
  93. {
  94. #if defined(CONFIG_SYS_LBC_SDRAM_SIZE)
  95. uint idx;
  96. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  97. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  98. uint lsdmr_common;
  99. puts(" SDRAM: ");
  100. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  101. /*
  102. * Setup SDRAM Base and Option Registers
  103. */
  104. set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
  105. set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
  106. set_lbc_or(4, CONFIG_SYS_OR4_PRELIM);
  107. set_lbc_br(4, CONFIG_SYS_BR4_PRELIM);
  108. out_be32(&lbc->lbcr, CONFIG_SYS_LBC_LBCR);
  109. asm("msync");
  110. out_be32(&lbc->lsrt, CONFIG_SYS_LBC_LSRT);
  111. out_be32(&lbc->mrtpr, CONFIG_SYS_LBC_MRTPR);
  112. asm("msync");
  113. /*
  114. * MPC8548 uses "new" 15-16 style addressing.
  115. */
  116. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  117. lsdmr_common |= LSDMR_BSMA1516;
  118. /*
  119. * Issue PRECHARGE ALL command.
  120. */
  121. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_PCHALL);
  122. asm("sync;msync");
  123. *sdram_addr = 0xff;
  124. ppcDcbf((unsigned long) sdram_addr);
  125. udelay(100);
  126. /*
  127. * Issue 8 AUTO REFRESH commands.
  128. */
  129. for (idx = 0; idx < 8; idx++) {
  130. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_ARFRSH);
  131. asm("sync;msync");
  132. *sdram_addr = 0xff;
  133. ppcDcbf((unsigned long) sdram_addr);
  134. udelay(100);
  135. }
  136. /*
  137. * Issue 8 MODE-set command.
  138. */
  139. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_MRW);
  140. asm("sync;msync");
  141. *sdram_addr = 0xff;
  142. ppcDcbf((unsigned long) sdram_addr);
  143. udelay(100);
  144. /*
  145. * Issue NORMAL OP command.
  146. */
  147. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_NORMAL);
  148. asm("sync;msync");
  149. *sdram_addr = 0xff;
  150. ppcDcbf((unsigned long) sdram_addr);
  151. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  152. #endif /* enable SDRAM init */
  153. }
  154. #if defined(CONFIG_SYS_DRAM_TEST)
  155. int
  156. testdram(void)
  157. {
  158. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  159. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  160. uint *p;
  161. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  162. CONFIG_SYS_MEMTEST_START,
  163. CONFIG_SYS_MEMTEST_END);
  164. printf("DRAM test phase 1:\n");
  165. for (p = pstart; p < pend; p++)
  166. *p = 0xaaaaaaaa;
  167. for (p = pstart; p < pend; p++) {
  168. if (*p != 0xaaaaaaaa) {
  169. printf ("DRAM test fails at: %08x\n", (uint) p);
  170. return 1;
  171. }
  172. }
  173. printf("DRAM test phase 2:\n");
  174. for (p = pstart; p < pend; p++)
  175. *p = 0x55555555;
  176. for (p = pstart; p < pend; p++) {
  177. if (*p != 0x55555555) {
  178. printf ("DRAM test fails at: %08x\n", (uint) p);
  179. return 1;
  180. }
  181. }
  182. printf("DRAM test passed.\n");
  183. return 0;
  184. }
  185. #endif
  186. #if !defined(CONFIG_SPD_EEPROM)
  187. #define CONFIG_SYS_DDR_CONTROL 0xc300c000
  188. /*************************************************************************
  189. * fixed_sdram init -- doesn't use serial presence detect.
  190. * assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  191. ************************************************************************/
  192. phys_size_t fixed_sdram(void)
  193. {
  194. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  195. out_be32(&ddr->cs0_bnds, 0x0000007f);
  196. out_be32(&ddr->cs1_bnds, 0x008000ff);
  197. out_be32(&ddr->cs2_bnds, 0x00000000);
  198. out_be32(&ddr->cs3_bnds, 0x00000000);
  199. out_be32(&ddr->cs0_config, 0x80010101);
  200. out_be32(&ddr->cs1_config, 0x80010101);
  201. out_be32(&ddr->cs2_config, 0x00000000);
  202. out_be32(&ddr->cs3_config, 0x00000000);
  203. out_be32(&ddr->timing_cfg_3, 0x00000000);
  204. out_be32(&ddr->timing_cfg_0, 0x00220802);
  205. out_be32(&ddr->timing_cfg_1, 0x38377322);
  206. out_be32(&ddr->timing_cfg_2, 0x0fa044C7);
  207. out_be32(&ddr->sdram_cfg, 0x4300C000);
  208. out_be32(&ddr->sdram_cfg_2, 0x24401000);
  209. out_be32(&ddr->sdram_mode, 0x23C00542);
  210. out_be32(&ddr->sdram_mode_2, 0x00000000);
  211. out_be32(&ddr->sdram_interval, 0x05080100);
  212. out_be32(&ddr->sdram_md_cntl, 0x00000000);
  213. out_be32(&ddr->sdram_data_init, 0x00000000);
  214. out_be32(&ddr->sdram_clk_cntl, 0x03800000);
  215. asm("sync;isync;msync");
  216. udelay(500);
  217. #if defined (CONFIG_DDR_ECC)
  218. /* Enable ECC checking */
  219. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL | 0x20000000);
  220. #else
  221. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  222. #endif
  223. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  224. }
  225. #endif
  226. #ifdef CONFIG_PCI1
  227. static struct pci_controller pci1_hose;
  228. #endif /* CONFIG_PCI1 */
  229. #ifdef CONFIG_PCIE1
  230. static struct pci_controller pcie1_hose;
  231. #endif /* CONFIG_PCIE1 */
  232. #ifdef CONFIG_PCI
  233. void
  234. pci_init_board(void)
  235. {
  236. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  237. struct fsl_pci_info pci_info[2];
  238. u32 devdisr, pordevsr, porpllsr, io_sel;
  239. int first_free_busno = 0;
  240. int num = 0;
  241. #ifdef CONFIG_PCIE1
  242. int pcie_configured;
  243. #endif
  244. devdisr = in_be32(&gur->devdisr);
  245. pordevsr = in_be32(&gur->pordevsr);
  246. porpllsr = in_be32(&gur->porpllsr);
  247. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  248. debug(" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  249. #ifdef CONFIG_PCI1
  250. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  251. uint pci_32 = pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  252. uint pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  253. uint pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  254. uint pci_speed = CONFIG_SYS_CLK_FREQ; /* get_clock_freq() */
  255. printf("PCI: Host, %d bit, %s MHz, %s, %s\n",
  256. (pci_32) ? 32 : 64,
  257. (pci_speed == 33000000) ? "33" :
  258. (pci_speed == 66000000) ? "66" : "unknown",
  259. pci_clk_sel ? "sync" : "async",
  260. pci_arb ? "arbiter" : "external-arbiter");
  261. SET_STD_PCI_INFO(pci_info[num], 1);
  262. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  263. &pci1_hose, first_free_busno);
  264. } else {
  265. printf("PCI: disabled\n");
  266. }
  267. puts("\n");
  268. #else
  269. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  270. #endif
  271. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI2); /* disable PCI2 */
  272. #ifdef CONFIG_PCIE1
  273. pcie_configured = is_serdes_configured(PCIE1);
  274. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  275. SET_STD_PCIE_INFO(pci_info[num], 1);
  276. printf("PCIE: base address %lx\n", pci_info[num].regs);
  277. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  278. &pcie1_hose, first_free_busno);
  279. } else {
  280. printf("PCIE: disabled\n");
  281. }
  282. puts("\n");
  283. #else
  284. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  285. #endif
  286. }
  287. #endif
  288. int board_eth_init(bd_t *bis)
  289. {
  290. tsec_standard_init(bis);
  291. pci_eth_init(bis);
  292. return 0; /* otherwise cpu_eth_init gets run */
  293. }
  294. int last_stage_init(void)
  295. {
  296. return 0;
  297. }
  298. #if defined(CONFIG_OF_BOARD_SETUP)
  299. void ft_board_setup(void *blob, bd_t *bd)
  300. {
  301. ft_cpu_setup(blob, bd);
  302. #ifdef CONFIG_FSL_PCI_INIT
  303. FT_FSL_PCI_SETUP;
  304. #endif
  305. }
  306. #endif