sbc8548.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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 <miiphy.h>
  36. #include <libfdt.h>
  37. #include <fdt_support.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. void local_bus_init(void);
  40. void sdram_init(void);
  41. long int fixed_sdram (void);
  42. int board_early_init_f (void)
  43. {
  44. return 0;
  45. }
  46. int checkboard (void)
  47. {
  48. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  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. (*rev) >> 4);
  53. /*
  54. * Initialize local bus.
  55. */
  56. local_bus_init ();
  57. /*
  58. * Hack TSEC 3 and 4 IO voltages.
  59. */
  60. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  61. ecm->eedr = 0xffffffff; /* clear ecm errors */
  62. ecm->eeer = 0xffffffff; /* enable ecm errors */
  63. return 0;
  64. }
  65. phys_size_t
  66. initdram(int board_type)
  67. {
  68. long dram_size = 0;
  69. puts("Initializing\n");
  70. #if defined(CONFIG_DDR_DLL)
  71. {
  72. /*
  73. * Work around to stabilize DDR DLL MSYNC_IN.
  74. * Errata DDR9 seems to have been fixed.
  75. * This is now the workaround for Errata DDR11:
  76. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  77. */
  78. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  79. gur->ddrdllcr = 0x81000000;
  80. asm("sync;isync;msync");
  81. udelay(200);
  82. }
  83. #endif
  84. #if defined(CONFIG_SPD_EEPROM)
  85. dram_size = fsl_ddr_sdram();
  86. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  87. dram_size *= 0x100000;
  88. #else
  89. dram_size = fixed_sdram ();
  90. #endif
  91. /*
  92. * SDRAM Initialization
  93. */
  94. sdram_init();
  95. puts(" DDR: ");
  96. return dram_size;
  97. }
  98. /*
  99. * Initialize Local Bus
  100. */
  101. void
  102. local_bus_init(void)
  103. {
  104. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  105. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  106. uint clkdiv;
  107. uint lbc_hz;
  108. sys_info_t sysinfo;
  109. get_sys_info(&sysinfo);
  110. clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
  111. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  112. gur->lbiuiplldcr1 = 0x00078080;
  113. if (clkdiv == 16) {
  114. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  115. } else if (clkdiv == 8) {
  116. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  117. } else if (clkdiv == 4) {
  118. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  119. }
  120. lbc->lcrr |= 0x00030000;
  121. asm("sync;isync;msync");
  122. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  123. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  124. }
  125. /*
  126. * Initialize SDRAM memory on the Local Bus.
  127. */
  128. void
  129. sdram_init(void)
  130. {
  131. #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
  132. uint idx;
  133. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  134. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  135. uint lsdmr_common;
  136. puts(" SDRAM: ");
  137. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  138. /*
  139. * Setup SDRAM Base and Option Registers
  140. */
  141. lbc->or3 = CONFIG_SYS_OR3_PRELIM;
  142. asm("msync");
  143. lbc->br3 = CONFIG_SYS_BR3_PRELIM;
  144. asm("msync");
  145. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  146. asm("msync");
  147. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  148. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  149. asm("msync");
  150. /*
  151. * MPC8548 uses "new" 15-16 style addressing.
  152. */
  153. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  154. lsdmr_common |= LSDMR_BSMA1516;
  155. /*
  156. * Issue PRECHARGE ALL command.
  157. */
  158. lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
  159. asm("sync;msync");
  160. *sdram_addr = 0xff;
  161. ppcDcbf((unsigned long) sdram_addr);
  162. udelay(100);
  163. /*
  164. * Issue 8 AUTO REFRESH commands.
  165. */
  166. for (idx = 0; idx < 8; idx++) {
  167. lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
  168. asm("sync;msync");
  169. *sdram_addr = 0xff;
  170. ppcDcbf((unsigned long) sdram_addr);
  171. udelay(100);
  172. }
  173. /*
  174. * Issue 8 MODE-set command.
  175. */
  176. lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
  177. asm("sync;msync");
  178. *sdram_addr = 0xff;
  179. ppcDcbf((unsigned long) sdram_addr);
  180. udelay(100);
  181. /*
  182. * Issue NORMAL OP command.
  183. */
  184. lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
  185. asm("sync;msync");
  186. *sdram_addr = 0xff;
  187. ppcDcbf((unsigned long) sdram_addr);
  188. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  189. #endif /* enable SDRAM init */
  190. }
  191. #if defined(CONFIG_SYS_DRAM_TEST)
  192. int
  193. testdram(void)
  194. {
  195. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  196. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  197. uint *p;
  198. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  199. CONFIG_SYS_MEMTEST_START,
  200. CONFIG_SYS_MEMTEST_END);
  201. printf("DRAM test phase 1:\n");
  202. for (p = pstart; p < pend; p++)
  203. *p = 0xaaaaaaaa;
  204. for (p = pstart; p < pend; p++) {
  205. if (*p != 0xaaaaaaaa) {
  206. printf ("DRAM test fails at: %08x\n", (uint) p);
  207. return 1;
  208. }
  209. }
  210. printf("DRAM test phase 2:\n");
  211. for (p = pstart; p < pend; p++)
  212. *p = 0x55555555;
  213. for (p = pstart; p < pend; p++) {
  214. if (*p != 0x55555555) {
  215. printf ("DRAM test fails at: %08x\n", (uint) p);
  216. return 1;
  217. }
  218. }
  219. printf("DRAM test passed.\n");
  220. return 0;
  221. }
  222. #endif
  223. #if !defined(CONFIG_SPD_EEPROM)
  224. /*************************************************************************
  225. * fixed_sdram init -- doesn't use serial presence detect.
  226. * assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  227. ************************************************************************/
  228. long int fixed_sdram (void)
  229. {
  230. #define CONFIG_SYS_DDR_CONTROL 0xc300c000
  231. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  232. ddr->cs0_bnds = 0x0000007f;
  233. ddr->cs1_bnds = 0x008000ff;
  234. ddr->cs2_bnds = 0x00000000;
  235. ddr->cs3_bnds = 0x00000000;
  236. ddr->cs0_config = 0x80010101;
  237. ddr->cs1_config = 0x80010101;
  238. ddr->cs2_config = 0x00000000;
  239. ddr->cs3_config = 0x00000000;
  240. ddr->timing_cfg_3 = 0x00000000;
  241. ddr->timing_cfg_0 = 0x00220802;
  242. ddr->timing_cfg_1 = 0x38377322;
  243. ddr->timing_cfg_2 = 0x0fa044C7;
  244. ddr->sdram_cfg = 0x4300C000;
  245. ddr->sdram_cfg_2 = 0x24401000;
  246. ddr->sdram_mode = 0x23C00542;
  247. ddr->sdram_mode_2 = 0x00000000;
  248. ddr->sdram_interval = 0x05080100;
  249. ddr->sdram_md_cntl = 0x00000000;
  250. ddr->sdram_data_init = 0x00000000;
  251. ddr->sdram_clk_cntl = 0x03800000;
  252. asm("sync;isync;msync");
  253. udelay(500);
  254. #if defined (CONFIG_DDR_ECC)
  255. /* Enable ECC checking */
  256. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  257. #else
  258. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  259. #endif
  260. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  261. }
  262. #endif
  263. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  264. /* For some reason the Tundra PCI bridge shows up on itself as a
  265. * different device. Work around that by refusing to configure it.
  266. */
  267. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  268. static struct pci_config_table pci_sbc8548_config_table[] = {
  269. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  270. {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
  271. {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
  272. mpc85xx_config_via_usbide, {0,0,0}},
  273. {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
  274. mpc85xx_config_via_usb, {0,0,0}},
  275. {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
  276. mpc85xx_config_via_usb2, {0,0,0}},
  277. {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
  278. mpc85xx_config_via_power, {0,0,0}},
  279. {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
  280. mpc85xx_config_via_ac97, {0,0,0}},
  281. {},
  282. };
  283. static struct pci_controller pci1_hose = {
  284. config_table: pci_sbc8548_config_table};
  285. #endif /* CONFIG_PCI */
  286. #ifdef CONFIG_PCI2
  287. static struct pci_controller pci2_hose;
  288. #endif /* CONFIG_PCI2 */
  289. #ifdef CONFIG_PCIE1
  290. static struct pci_controller pcie1_hose;
  291. #endif /* CONFIG_PCIE1 */
  292. int first_free_busno=0;
  293. void
  294. pci_init_board(void)
  295. {
  296. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  297. #ifdef CONFIG_PCI1
  298. {
  299. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  300. struct pci_controller *hose = &pci1_hose;
  301. struct pci_config_table *table;
  302. struct pci_region *r = hose->regions;
  303. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  304. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  305. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  306. uint pci_agent = is_fsl_pci_agent(LAW_TRGT_IF_PCI_1, host_agent);
  307. uint pci_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  308. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  309. printf (" PCI: %d bit, %s MHz, %s, %s, %s\n",
  310. (pci_32) ? 32 : 64,
  311. (pci_speed == 33333000) ? "33" :
  312. (pci_speed == 66666000) ? "66" : "unknown",
  313. pci_clk_sel ? "sync" : "async",
  314. pci_agent ? "agent" : "host",
  315. pci_arb ? "arbiter" : "external-arbiter"
  316. );
  317. /* outbound memory */
  318. pci_set_region(r++,
  319. CONFIG_SYS_PCI1_MEM_BASE,
  320. CONFIG_SYS_PCI1_MEM_PHYS,
  321. CONFIG_SYS_PCI1_MEM_SIZE,
  322. PCI_REGION_MEM);
  323. /* outbound io */
  324. pci_set_region(r++,
  325. CONFIG_SYS_PCI1_IO_BASE,
  326. CONFIG_SYS_PCI1_IO_PHYS,
  327. CONFIG_SYS_PCI1_IO_SIZE,
  328. PCI_REGION_IO);
  329. hose->region_count = r - hose->regions;
  330. /* relocate config table pointers */
  331. hose->config_table = \
  332. (struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
  333. for (table = hose->config_table; table && table->vendor; table++)
  334. table->config_device += gd->reloc_off;
  335. hose->first_busno=first_free_busno;
  336. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  337. first_free_busno=hose->last_busno+1;
  338. printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  339. #ifdef CONFIG_PCIX_CHECK
  340. if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
  341. /* PCI-X init */
  342. if (CONFIG_SYS_CLK_FREQ < 66000000)
  343. printf("PCI-X will only work at 66 MHz\n");
  344. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  345. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  346. pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
  347. }
  348. #endif
  349. } else {
  350. printf (" PCI: disabled\n");
  351. }
  352. }
  353. #else
  354. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  355. #endif
  356. #ifdef CONFIG_PCI2
  357. {
  358. uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
  359. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  360. if (pci_dual) {
  361. printf (" PCI2: 32 bit, 66 MHz, %s\n",
  362. pci2_clk_sel ? "sync" : "async");
  363. } else {
  364. printf (" PCI2: disabled\n");
  365. }
  366. }
  367. #else
  368. gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
  369. #endif /* CONFIG_PCI2 */
  370. #ifdef CONFIG_PCIE1
  371. {
  372. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  373. struct pci_controller *hose = &pcie1_hose;
  374. int pcie_ep = is_fsl_pci_agent(LAW_TRGT_IF_PCIE_1, host_agent);
  375. struct pci_region *r = hose->regions;
  376. int pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  377. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  378. printf ("\n PCIE connected to slot as %s (base address %x)",
  379. pcie_ep ? "End Point" : "Root Complex",
  380. (uint)pci);
  381. if (pci->pme_msg_det) {
  382. pci->pme_msg_det = 0xffffffff;
  383. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  384. }
  385. printf ("\n");
  386. /* outbound memory */
  387. pci_set_region(r++,
  388. CONFIG_SYS_PCIE1_MEM_BASE,
  389. CONFIG_SYS_PCIE1_MEM_PHYS,
  390. CONFIG_SYS_PCIE1_MEM_SIZE,
  391. PCI_REGION_MEM);
  392. /* outbound io */
  393. pci_set_region(r++,
  394. CONFIG_SYS_PCIE1_IO_BASE,
  395. CONFIG_SYS_PCIE1_IO_PHYS,
  396. CONFIG_SYS_PCIE1_IO_SIZE,
  397. PCI_REGION_IO);
  398. hose->region_count = r - hose->regions;
  399. hose->first_busno=first_free_busno;
  400. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  401. printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
  402. first_free_busno=hose->last_busno+1;
  403. } else {
  404. printf (" PCIE: disabled\n");
  405. }
  406. }
  407. #else
  408. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  409. #endif
  410. }
  411. int last_stage_init(void)
  412. {
  413. return 0;
  414. }
  415. #if defined(CONFIG_OF_BOARD_SETUP)
  416. void ft_board_setup(void *blob, bd_t *bd)
  417. {
  418. ft_cpu_setup(blob, bd);
  419. #ifdef CONFIG_PCI1
  420. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  421. #endif
  422. #ifdef CONFIG_PCIE1
  423. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  424. #endif
  425. }
  426. #endif