sbc8548.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 <spd_sdram.h>
  35. #include <netdev.h>
  36. #include <tsec.h>
  37. #include <miiphy.h>
  38. #include <libfdt.h>
  39. #include <fdt_support.h>
  40. DECLARE_GLOBAL_DATA_PTR;
  41. void local_bus_init(void);
  42. void sdram_init(void);
  43. long int fixed_sdram (void);
  44. int board_early_init_f (void)
  45. {
  46. return 0;
  47. }
  48. int checkboard (void)
  49. {
  50. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  51. volatile u_char *rev= (void *)CONFIG_SYS_BD_REV;
  52. printf ("Board: Wind River SBC8548 Rev. 0x%01x\n",
  53. in_8(rev) >> 4);
  54. /*
  55. * Initialize local bus.
  56. */
  57. local_bus_init ();
  58. out_be32(&ecm->eedr, 0xffffffff); /* clear ecm errors */
  59. out_be32(&ecm->eeer, 0xffffffff); /* enable ecm errors */
  60. return 0;
  61. }
  62. phys_size_t
  63. initdram(int board_type)
  64. {
  65. long dram_size = 0;
  66. puts("Initializing\n");
  67. #if defined(CONFIG_DDR_DLL)
  68. {
  69. /*
  70. * Work around to stabilize DDR DLL MSYNC_IN.
  71. * Errata DDR9 seems to have been fixed.
  72. * This is now the workaround for Errata DDR11:
  73. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  74. */
  75. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  76. out_be32(&gur->ddrdllcr, 0x81000000);
  77. asm("sync;isync;msync");
  78. udelay(200);
  79. }
  80. #endif
  81. #if defined(CONFIG_SPD_EEPROM)
  82. dram_size = fsl_ddr_sdram();
  83. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  84. dram_size *= 0x100000;
  85. #else
  86. dram_size = fixed_sdram ();
  87. #endif
  88. /*
  89. * SDRAM Initialization
  90. */
  91. sdram_init();
  92. puts(" DDR: ");
  93. return dram_size;
  94. }
  95. /*
  96. * Initialize Local Bus
  97. */
  98. void
  99. local_bus_init(void)
  100. {
  101. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  102. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  103. uint clkdiv;
  104. uint lbc_hz;
  105. sys_info_t sysinfo;
  106. get_sys_info(&sysinfo);
  107. clkdiv = (in_be32(&lbc->lcrr) & LCRR_CLKDIV) * 2;
  108. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  109. out_be32(&gur->lbiuiplldcr1, 0x00078080);
  110. if (clkdiv == 16) {
  111. out_be32(&gur->lbiuiplldcr0, 0x7c0f1bf0);
  112. } else if (clkdiv == 8) {
  113. out_be32(&gur->lbiuiplldcr0, 0x6c0f1bf0);
  114. } else if (clkdiv == 4) {
  115. out_be32(&gur->lbiuiplldcr0, 0x5c0f1bf0);
  116. }
  117. setbits_be32(&lbc->lcrr, 0x00030000);
  118. asm("sync;isync;msync");
  119. out_be32(&lbc->ltesr, 0xffffffff); /* Clear LBC error IRQs */
  120. out_be32(&lbc->lteir, 0xffffffff); /* Enable LBC error IRQs */
  121. }
  122. /*
  123. * Initialize SDRAM memory on the Local Bus.
  124. */
  125. void
  126. sdram_init(void)
  127. {
  128. #if defined(CONFIG_SYS_LBC_SDRAM_SIZE)
  129. uint idx;
  130. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  131. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  132. uint lsdmr_common;
  133. puts(" SDRAM: ");
  134. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  135. /*
  136. * Setup SDRAM Base and Option Registers
  137. */
  138. out_be32(&lbc->or3, CONFIG_SYS_OR3_PRELIM);
  139. asm("msync");
  140. out_be32(&lbc->br3, CONFIG_SYS_BR3_PRELIM);
  141. asm("msync");
  142. out_be32(&lbc->or4, CONFIG_SYS_OR4_PRELIM);
  143. asm("msync");
  144. out_be32(&lbc->br4, CONFIG_SYS_BR4_PRELIM);
  145. asm("msync");
  146. out_be32(&lbc->lbcr, CONFIG_SYS_LBC_LBCR);
  147. asm("msync");
  148. out_be32(&lbc->lsrt, CONFIG_SYS_LBC_LSRT);
  149. out_be32(&lbc->mrtpr, CONFIG_SYS_LBC_MRTPR);
  150. asm("msync");
  151. /*
  152. * MPC8548 uses "new" 15-16 style addressing.
  153. */
  154. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  155. lsdmr_common |= LSDMR_BSMA1516;
  156. /*
  157. * Issue PRECHARGE ALL command.
  158. */
  159. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_PCHALL);
  160. asm("sync;msync");
  161. *sdram_addr = 0xff;
  162. ppcDcbf((unsigned long) sdram_addr);
  163. udelay(100);
  164. /*
  165. * Issue 8 AUTO REFRESH commands.
  166. */
  167. for (idx = 0; idx < 8; idx++) {
  168. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_ARFRSH);
  169. asm("sync;msync");
  170. *sdram_addr = 0xff;
  171. ppcDcbf((unsigned long) sdram_addr);
  172. udelay(100);
  173. }
  174. /*
  175. * Issue 8 MODE-set command.
  176. */
  177. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_MRW);
  178. asm("sync;msync");
  179. *sdram_addr = 0xff;
  180. ppcDcbf((unsigned long) sdram_addr);
  181. udelay(100);
  182. /*
  183. * Issue NORMAL OP command.
  184. */
  185. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_NORMAL);
  186. asm("sync;msync");
  187. *sdram_addr = 0xff;
  188. ppcDcbf((unsigned long) sdram_addr);
  189. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  190. #endif /* enable SDRAM init */
  191. }
  192. #if defined(CONFIG_SYS_DRAM_TEST)
  193. int
  194. testdram(void)
  195. {
  196. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  197. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  198. uint *p;
  199. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  200. CONFIG_SYS_MEMTEST_START,
  201. CONFIG_SYS_MEMTEST_END);
  202. printf("DRAM test phase 1:\n");
  203. for (p = pstart; p < pend; p++)
  204. *p = 0xaaaaaaaa;
  205. for (p = pstart; p < pend; p++) {
  206. if (*p != 0xaaaaaaaa) {
  207. printf ("DRAM test fails at: %08x\n", (uint) p);
  208. return 1;
  209. }
  210. }
  211. printf("DRAM test phase 2:\n");
  212. for (p = pstart; p < pend; p++)
  213. *p = 0x55555555;
  214. for (p = pstart; p < pend; p++) {
  215. if (*p != 0x55555555) {
  216. printf ("DRAM test fails at: %08x\n", (uint) p);
  217. return 1;
  218. }
  219. }
  220. printf("DRAM test passed.\n");
  221. return 0;
  222. }
  223. #endif
  224. #if !defined(CONFIG_SPD_EEPROM)
  225. #define CONFIG_SYS_DDR_CONTROL 0xc300c000
  226. /*************************************************************************
  227. * fixed_sdram init -- doesn't use serial presence detect.
  228. * assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  229. ************************************************************************/
  230. long int fixed_sdram (void)
  231. {
  232. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  233. out_be32(&ddr->cs0_bnds, 0x0000007f);
  234. out_be32(&ddr->cs1_bnds, 0x008000ff);
  235. out_be32(&ddr->cs2_bnds, 0x00000000);
  236. out_be32(&ddr->cs3_bnds, 0x00000000);
  237. out_be32(&ddr->cs0_config, 0x80010101);
  238. out_be32(&ddr->cs1_config, 0x80010101);
  239. out_be32(&ddr->cs2_config, 0x00000000);
  240. out_be32(&ddr->cs3_config, 0x00000000);
  241. out_be32(&ddr->timing_cfg_3, 0x00000000);
  242. out_be32(&ddr->timing_cfg_0, 0x00220802);
  243. out_be32(&ddr->timing_cfg_1, 0x38377322);
  244. out_be32(&ddr->timing_cfg_2, 0x0fa044C7);
  245. out_be32(&ddr->sdram_cfg, 0x4300C000);
  246. out_be32(&ddr->sdram_cfg_2, 0x24401000);
  247. out_be32(&ddr->sdram_mode, 0x23C00542);
  248. out_be32(&ddr->sdram_mode_2, 0x00000000);
  249. out_be32(&ddr->sdram_interval, 0x05080100);
  250. out_be32(&ddr->sdram_md_cntl, 0x00000000);
  251. out_be32(&ddr->sdram_data_init, 0x00000000);
  252. out_be32(&ddr->sdram_clk_cntl, 0x03800000);
  253. asm("sync;isync;msync");
  254. udelay(500);
  255. #if defined (CONFIG_DDR_ECC)
  256. /* Enable ECC checking */
  257. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL | 0x20000000);
  258. #else
  259. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  260. #endif
  261. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  262. }
  263. #endif
  264. #ifdef CONFIG_PCI1
  265. static struct pci_controller pci1_hose;
  266. #endif /* CONFIG_PCI1 */
  267. #ifdef CONFIG_PCIE1
  268. static struct pci_controller pcie1_hose;
  269. #endif /* CONFIG_PCIE1 */
  270. #ifdef CONFIG_PCI
  271. void
  272. pci_init_board(void)
  273. {
  274. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  275. struct fsl_pci_info pci_info[2];
  276. u32 devdisr, pordevsr, porpllsr, io_sel;
  277. int first_free_busno = 0;
  278. int num = 0;
  279. #ifdef CONFIG_PCIE1
  280. int pcie_configured;
  281. #endif
  282. devdisr = in_be32(&gur->devdisr);
  283. pordevsr = in_be32(&gur->pordevsr);
  284. porpllsr = in_be32(&gur->porpllsr);
  285. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  286. debug(" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  287. #ifdef CONFIG_PCI1
  288. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  289. uint pci_32 = pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  290. uint pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  291. uint pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  292. uint pci_speed = CONFIG_SYS_CLK_FREQ; /* get_clock_freq() */
  293. printf (" PCI host: %d bit, %s MHz, %s, %s\n",
  294. (pci_32) ? 32 : 64,
  295. (pci_speed == 33000000) ? "33" :
  296. (pci_speed == 66000000) ? "66" : "unknown",
  297. pci_clk_sel ? "sync" : "async",
  298. pci_arb ? "arbiter" : "external-arbiter");
  299. SET_STD_PCI_INFO(pci_info[num], 1);
  300. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  301. &pci1_hose, first_free_busno);
  302. } else {
  303. printf (" PCI: disabled\n");
  304. }
  305. puts("\n");
  306. #else
  307. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  308. #endif
  309. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI2); /* disable PCI2 */
  310. #ifdef CONFIG_PCIE1
  311. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  312. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  313. SET_STD_PCIE_INFO(pci_info[num], 1);
  314. printf (" PCIE at base address %lx\n", pci_info[num].regs);
  315. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  316. &pcie1_hose, first_free_busno);
  317. } else {
  318. printf (" PCIE: disabled\n");
  319. }
  320. puts("\n");
  321. #else
  322. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  323. #endif
  324. }
  325. #endif
  326. int board_eth_init(bd_t *bis)
  327. {
  328. tsec_standard_init(bis);
  329. pci_eth_init(bis);
  330. return 0; /* otherwise cpu_eth_init gets run */
  331. }
  332. int last_stage_init(void)
  333. {
  334. return 0;
  335. }
  336. #if defined(CONFIG_OF_BOARD_SETUP)
  337. void ft_board_setup(void *blob, bd_t *bd)
  338. {
  339. ft_cpu_setup(blob, bd);
  340. #ifdef CONFIG_PCI1
  341. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  342. #endif
  343. #ifdef CONFIG_PCIE1
  344. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  345. #endif
  346. }
  347. #endif