sbc8548.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 fsl_lbc_t *lbc = LBC_BASE_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 fsl_lbc_t *lbc = LBC_BASE_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. set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
  139. set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
  140. set_lbc_or(4, CONFIG_SYS_OR4_PRELIM);
  141. set_lbc_br(4, CONFIG_SYS_BR4_PRELIM);
  142. out_be32(&lbc->lbcr, CONFIG_SYS_LBC_LBCR);
  143. asm("msync");
  144. out_be32(&lbc->lsrt, CONFIG_SYS_LBC_LSRT);
  145. out_be32(&lbc->mrtpr, CONFIG_SYS_LBC_MRTPR);
  146. asm("msync");
  147. /*
  148. * MPC8548 uses "new" 15-16 style addressing.
  149. */
  150. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  151. lsdmr_common |= LSDMR_BSMA1516;
  152. /*
  153. * Issue PRECHARGE ALL command.
  154. */
  155. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_PCHALL);
  156. asm("sync;msync");
  157. *sdram_addr = 0xff;
  158. ppcDcbf((unsigned long) sdram_addr);
  159. udelay(100);
  160. /*
  161. * Issue 8 AUTO REFRESH commands.
  162. */
  163. for (idx = 0; idx < 8; idx++) {
  164. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_ARFRSH);
  165. asm("sync;msync");
  166. *sdram_addr = 0xff;
  167. ppcDcbf((unsigned long) sdram_addr);
  168. udelay(100);
  169. }
  170. /*
  171. * Issue 8 MODE-set command.
  172. */
  173. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_MRW);
  174. asm("sync;msync");
  175. *sdram_addr = 0xff;
  176. ppcDcbf((unsigned long) sdram_addr);
  177. udelay(100);
  178. /*
  179. * Issue NORMAL OP command.
  180. */
  181. out_be32(&lbc->lsdmr, lsdmr_common | LSDMR_OP_NORMAL);
  182. asm("sync;msync");
  183. *sdram_addr = 0xff;
  184. ppcDcbf((unsigned long) sdram_addr);
  185. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  186. #endif /* enable SDRAM init */
  187. }
  188. #if defined(CONFIG_SYS_DRAM_TEST)
  189. int
  190. testdram(void)
  191. {
  192. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  193. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  194. uint *p;
  195. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  196. CONFIG_SYS_MEMTEST_START,
  197. CONFIG_SYS_MEMTEST_END);
  198. printf("DRAM test phase 1:\n");
  199. for (p = pstart; p < pend; p++)
  200. *p = 0xaaaaaaaa;
  201. for (p = pstart; p < pend; p++) {
  202. if (*p != 0xaaaaaaaa) {
  203. printf ("DRAM test fails at: %08x\n", (uint) p);
  204. return 1;
  205. }
  206. }
  207. printf("DRAM test phase 2:\n");
  208. for (p = pstart; p < pend; p++)
  209. *p = 0x55555555;
  210. for (p = pstart; p < pend; p++) {
  211. if (*p != 0x55555555) {
  212. printf ("DRAM test fails at: %08x\n", (uint) p);
  213. return 1;
  214. }
  215. }
  216. printf("DRAM test passed.\n");
  217. return 0;
  218. }
  219. #endif
  220. #if !defined(CONFIG_SPD_EEPROM)
  221. #define CONFIG_SYS_DDR_CONTROL 0xc300c000
  222. /*************************************************************************
  223. * fixed_sdram init -- doesn't use serial presence detect.
  224. * assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  225. ************************************************************************/
  226. long int fixed_sdram (void)
  227. {
  228. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  229. out_be32(&ddr->cs0_bnds, 0x0000007f);
  230. out_be32(&ddr->cs1_bnds, 0x008000ff);
  231. out_be32(&ddr->cs2_bnds, 0x00000000);
  232. out_be32(&ddr->cs3_bnds, 0x00000000);
  233. out_be32(&ddr->cs0_config, 0x80010101);
  234. out_be32(&ddr->cs1_config, 0x80010101);
  235. out_be32(&ddr->cs2_config, 0x00000000);
  236. out_be32(&ddr->cs3_config, 0x00000000);
  237. out_be32(&ddr->timing_cfg_3, 0x00000000);
  238. out_be32(&ddr->timing_cfg_0, 0x00220802);
  239. out_be32(&ddr->timing_cfg_1, 0x38377322);
  240. out_be32(&ddr->timing_cfg_2, 0x0fa044C7);
  241. out_be32(&ddr->sdram_cfg, 0x4300C000);
  242. out_be32(&ddr->sdram_cfg_2, 0x24401000);
  243. out_be32(&ddr->sdram_mode, 0x23C00542);
  244. out_be32(&ddr->sdram_mode_2, 0x00000000);
  245. out_be32(&ddr->sdram_interval, 0x05080100);
  246. out_be32(&ddr->sdram_md_cntl, 0x00000000);
  247. out_be32(&ddr->sdram_data_init, 0x00000000);
  248. out_be32(&ddr->sdram_clk_cntl, 0x03800000);
  249. asm("sync;isync;msync");
  250. udelay(500);
  251. #if defined (CONFIG_DDR_ECC)
  252. /* Enable ECC checking */
  253. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL | 0x20000000);
  254. #else
  255. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  256. #endif
  257. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  258. }
  259. #endif
  260. #ifdef CONFIG_PCI1
  261. static struct pci_controller pci1_hose;
  262. #endif /* CONFIG_PCI1 */
  263. #ifdef CONFIG_PCIE1
  264. static struct pci_controller pcie1_hose;
  265. #endif /* CONFIG_PCIE1 */
  266. #ifdef CONFIG_PCI
  267. void
  268. pci_init_board(void)
  269. {
  270. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  271. struct fsl_pci_info pci_info[2];
  272. u32 devdisr, pordevsr, porpllsr, io_sel;
  273. int first_free_busno = 0;
  274. int num = 0;
  275. #ifdef CONFIG_PCIE1
  276. int pcie_configured;
  277. #endif
  278. devdisr = in_be32(&gur->devdisr);
  279. pordevsr = in_be32(&gur->pordevsr);
  280. porpllsr = in_be32(&gur->porpllsr);
  281. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  282. debug(" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  283. #ifdef CONFIG_PCI1
  284. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  285. uint pci_32 = pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  286. uint pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  287. uint pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  288. uint pci_speed = CONFIG_SYS_CLK_FREQ; /* get_clock_freq() */
  289. printf (" PCI host: %d bit, %s MHz, %s, %s\n",
  290. (pci_32) ? 32 : 64,
  291. (pci_speed == 33000000) ? "33" :
  292. (pci_speed == 66000000) ? "66" : "unknown",
  293. pci_clk_sel ? "sync" : "async",
  294. pci_arb ? "arbiter" : "external-arbiter");
  295. SET_STD_PCI_INFO(pci_info[num], 1);
  296. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  297. &pci1_hose, first_free_busno);
  298. } else {
  299. printf (" PCI: disabled\n");
  300. }
  301. puts("\n");
  302. #else
  303. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  304. #endif
  305. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI2); /* disable PCI2 */
  306. #ifdef CONFIG_PCIE1
  307. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  308. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  309. SET_STD_PCIE_INFO(pci_info[num], 1);
  310. printf (" PCIE at base address %lx\n", pci_info[num].regs);
  311. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  312. &pcie1_hose, first_free_busno);
  313. } else {
  314. printf (" PCIE: disabled\n");
  315. }
  316. puts("\n");
  317. #else
  318. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  319. #endif
  320. }
  321. #endif
  322. int board_eth_init(bd_t *bis)
  323. {
  324. tsec_standard_init(bis);
  325. pci_eth_init(bis);
  326. return 0; /* otherwise cpu_eth_init gets run */
  327. }
  328. int last_stage_init(void)
  329. {
  330. return 0;
  331. }
  332. #if defined(CONFIG_OF_BOARD_SETUP)
  333. void ft_board_setup(void *blob, bd_t *bd)
  334. {
  335. ft_cpu_setup(blob, bd);
  336. #ifdef CONFIG_FSL_PCI_INIT
  337. FT_FSL_PCI_SETUP;
  338. #endif
  339. }
  340. #endif