sbc8548.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. * Copyright 2007 Wind River Systemes, Inc. <www.windriver.com>
  3. * Copyright 2007 Embedded Specialties, Inc.
  4. *
  5. * Copyright 2004, 2007 Freescale Semiconductor.
  6. *
  7. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <pci.h>
  29. #include <asm/processor.h>
  30. #include <asm/immap_85xx.h>
  31. #include <asm/immap_fsl_pci.h>
  32. #include <asm/fsl_ddr_sdram.h>
  33. #include <spd_sdram.h>
  34. #include <miiphy.h>
  35. #include <libfdt.h>
  36. #include <fdt_support.h>
  37. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  38. extern void ddr_enable_ecc(unsigned int dram_size);
  39. #endif
  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_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  51. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  52. volatile u_char *rev= (void *)CONFIG_SYS_BD_REV;
  53. printf ("Board: Wind River SBC8548 Rev. 0x%01x\n",
  54. (*rev) >> 4);
  55. /*
  56. * Initialize local bus.
  57. */
  58. local_bus_init ();
  59. /*
  60. * Fix CPU2 errata: A core hang possible while executing a
  61. * msync instruction and a snoopable transaction from an I/O
  62. * master tagged to make quick forward progress is present.
  63. */
  64. ecm->eebpcr |= (1 << 16);
  65. /*
  66. * Hack TSEC 3 and 4 IO voltages.
  67. */
  68. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  69. ecm->eedr = 0xffffffff; /* clear ecm errors */
  70. ecm->eeer = 0xffffffff; /* enable ecm errors */
  71. return 0;
  72. }
  73. phys_size_t
  74. initdram(int board_type)
  75. {
  76. long dram_size = 0;
  77. puts("Initializing\n");
  78. #if defined(CONFIG_DDR_DLL)
  79. {
  80. /*
  81. * Work around to stabilize DDR DLL MSYNC_IN.
  82. * Errata DDR9 seems to have been fixed.
  83. * This is now the workaround for Errata DDR11:
  84. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  85. */
  86. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  87. gur->ddrdllcr = 0x81000000;
  88. asm("sync;isync;msync");
  89. udelay(200);
  90. }
  91. #endif
  92. #if defined(CONFIG_SPD_EEPROM)
  93. dram_size = fsl_ddr_sdram();
  94. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  95. dram_size *= 0x100000;
  96. #else
  97. dram_size = fixed_sdram ();
  98. #endif
  99. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  100. /*
  101. * Initialize and enable DDR ECC.
  102. */
  103. ddr_enable_ecc(dram_size);
  104. #endif
  105. /*
  106. * SDRAM Initialization
  107. */
  108. sdram_init();
  109. puts(" DDR: ");
  110. return dram_size;
  111. }
  112. /*
  113. * Initialize Local Bus
  114. */
  115. void
  116. local_bus_init(void)
  117. {
  118. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  119. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  120. uint clkdiv;
  121. uint lbc_hz;
  122. sys_info_t sysinfo;
  123. get_sys_info(&sysinfo);
  124. clkdiv = (lbc->lcrr & 0x0f) * 2;
  125. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  126. gur->lbiuiplldcr1 = 0x00078080;
  127. if (clkdiv == 16) {
  128. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  129. } else if (clkdiv == 8) {
  130. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  131. } else if (clkdiv == 4) {
  132. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  133. }
  134. lbc->lcrr |= 0x00030000;
  135. asm("sync;isync;msync");
  136. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  137. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  138. }
  139. /*
  140. * Initialize SDRAM memory on the Local Bus.
  141. */
  142. void
  143. sdram_init(void)
  144. {
  145. #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
  146. uint idx;
  147. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  148. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  149. uint lsdmr_common;
  150. puts(" SDRAM: ");
  151. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  152. /*
  153. * Setup SDRAM Base and Option Registers
  154. */
  155. lbc->or3 = CONFIG_SYS_OR3_PRELIM;
  156. asm("msync");
  157. lbc->br3 = CONFIG_SYS_BR3_PRELIM;
  158. asm("msync");
  159. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  160. asm("msync");
  161. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  162. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  163. asm("msync");
  164. /*
  165. * MPC8548 uses "new" 15-16 style addressing.
  166. */
  167. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  168. lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1516;
  169. /*
  170. * Issue PRECHARGE ALL command.
  171. */
  172. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_PCHALL;
  173. asm("sync;msync");
  174. *sdram_addr = 0xff;
  175. ppcDcbf((unsigned long) sdram_addr);
  176. udelay(100);
  177. /*
  178. * Issue 8 AUTO REFRESH commands.
  179. */
  180. for (idx = 0; idx < 8; idx++) {
  181. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_ARFRSH;
  182. asm("sync;msync");
  183. *sdram_addr = 0xff;
  184. ppcDcbf((unsigned long) sdram_addr);
  185. udelay(100);
  186. }
  187. /*
  188. * Issue 8 MODE-set command.
  189. */
  190. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_MRW;
  191. asm("sync;msync");
  192. *sdram_addr = 0xff;
  193. ppcDcbf((unsigned long) sdram_addr);
  194. udelay(100);
  195. /*
  196. * Issue NORMAL OP command.
  197. */
  198. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_NORMAL;
  199. asm("sync;msync");
  200. *sdram_addr = 0xff;
  201. ppcDcbf((unsigned long) sdram_addr);
  202. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  203. #endif /* enable SDRAM init */
  204. }
  205. #if defined(CONFIG_SYS_DRAM_TEST)
  206. int
  207. testdram(void)
  208. {
  209. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  210. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  211. uint *p;
  212. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  213. CONFIG_SYS_MEMTEST_START,
  214. CONFIG_SYS_MEMTEST_END);
  215. printf("DRAM test phase 1:\n");
  216. for (p = pstart; p < pend; p++)
  217. *p = 0xaaaaaaaa;
  218. for (p = pstart; p < pend; p++) {
  219. if (*p != 0xaaaaaaaa) {
  220. printf ("DRAM test fails at: %08x\n", (uint) p);
  221. return 1;
  222. }
  223. }
  224. printf("DRAM test phase 2:\n");
  225. for (p = pstart; p < pend; p++)
  226. *p = 0x55555555;
  227. for (p = pstart; p < pend; p++) {
  228. if (*p != 0x55555555) {
  229. printf ("DRAM test fails at: %08x\n", (uint) p);
  230. return 1;
  231. }
  232. }
  233. printf("DRAM test passed.\n");
  234. return 0;
  235. }
  236. #endif
  237. #if !defined(CONFIG_SPD_EEPROM)
  238. /*************************************************************************
  239. * fixed_sdram init -- doesn't use serial presence detect.
  240. * assumes 256MB DDR2 SDRAM SODIMM, without ECC, running at DDR400 speed.
  241. ************************************************************************/
  242. long int fixed_sdram (void)
  243. {
  244. #define CONFIG_SYS_DDR_CONTROL 0xc300c000
  245. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  246. ddr->cs0_bnds = 0x0000007f;
  247. ddr->cs1_bnds = 0x008000ff;
  248. ddr->cs2_bnds = 0x00000000;
  249. ddr->cs3_bnds = 0x00000000;
  250. ddr->cs0_config = 0x80010101;
  251. ddr->cs1_config = 0x80010101;
  252. ddr->cs2_config = 0x00000000;
  253. ddr->cs3_config = 0x00000000;
  254. ddr->timing_cfg_3 = 0x00000000;
  255. ddr->timing_cfg_0 = 0x00220802;
  256. ddr->timing_cfg_1 = 0x38377322;
  257. ddr->timing_cfg_2 = 0x0fa044C7;
  258. ddr->sdram_cfg = 0x4300C000;
  259. ddr->sdram_cfg_2 = 0x24401000;
  260. ddr->sdram_mode = 0x23C00542;
  261. ddr->sdram_mode_2 = 0x00000000;
  262. ddr->sdram_interval = 0x05080100;
  263. ddr->sdram_md_cntl = 0x00000000;
  264. ddr->sdram_data_init = 0x00000000;
  265. ddr->sdram_clk_cntl = 0x03800000;
  266. asm("sync;isync;msync");
  267. udelay(500);
  268. #if defined (CONFIG_DDR_ECC)
  269. /* Enable ECC checking */
  270. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  271. #else
  272. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  273. #endif
  274. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  275. }
  276. #endif
  277. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  278. /* For some reason the Tundra PCI bridge shows up on itself as a
  279. * different device. Work around that by refusing to configure it.
  280. */
  281. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  282. static struct pci_config_table pci_sbc8548_config_table[] = {
  283. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  284. {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
  285. {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
  286. mpc85xx_config_via_usbide, {0,0,0}},
  287. {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
  288. mpc85xx_config_via_usb, {0,0,0}},
  289. {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
  290. mpc85xx_config_via_usb2, {0,0,0}},
  291. {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
  292. mpc85xx_config_via_power, {0,0,0}},
  293. {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
  294. mpc85xx_config_via_ac97, {0,0,0}},
  295. {},
  296. };
  297. static struct pci_controller pci1_hose = {
  298. config_table: pci_sbc8548_config_table};
  299. #endif /* CONFIG_PCI */
  300. #ifdef CONFIG_PCI2
  301. static struct pci_controller pci2_hose;
  302. #endif /* CONFIG_PCI2 */
  303. #ifdef CONFIG_PCIE1
  304. static struct pci_controller pcie1_hose;
  305. #endif /* CONFIG_PCIE1 */
  306. int first_free_busno=0;
  307. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  308. extern void fsl_pci_init(struct pci_controller *hose);
  309. void
  310. pci_init_board(void)
  311. {
  312. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  313. #ifdef CONFIG_PCI1
  314. {
  315. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  316. struct pci_controller *hose = &pci1_hose;
  317. struct pci_config_table *table;
  318. struct pci_region *r = hose->regions;
  319. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  320. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  321. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  322. uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
  323. uint pci_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  324. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  325. printf (" PCI: %d bit, %s MHz, %s, %s, %s\n",
  326. (pci_32) ? 32 : 64,
  327. (pci_speed == 33333000) ? "33" :
  328. (pci_speed == 66666000) ? "66" : "unknown",
  329. pci_clk_sel ? "sync" : "async",
  330. pci_agent ? "agent" : "host",
  331. pci_arb ? "arbiter" : "external-arbiter"
  332. );
  333. /* inbound */
  334. r += fsl_pci_setup_inbound_windows(r);
  335. /* outbound memory */
  336. pci_set_region(r++,
  337. CONFIG_SYS_PCI1_MEM_BASE,
  338. CONFIG_SYS_PCI1_MEM_PHYS,
  339. CONFIG_SYS_PCI1_MEM_SIZE,
  340. PCI_REGION_MEM);
  341. /* outbound io */
  342. pci_set_region(r++,
  343. CONFIG_SYS_PCI1_IO_BASE,
  344. CONFIG_SYS_PCI1_IO_PHYS,
  345. CONFIG_SYS_PCI1_IO_SIZE,
  346. PCI_REGION_IO);
  347. hose->region_count = r - hose->regions;
  348. /* relocate config table pointers */
  349. hose->config_table = \
  350. (struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
  351. for (table = hose->config_table; table && table->vendor; table++)
  352. table->config_device += gd->reloc_off;
  353. hose->first_busno=first_free_busno;
  354. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  355. fsl_pci_init(hose);
  356. first_free_busno=hose->last_busno+1;
  357. printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  358. #ifdef CONFIG_PCIX_CHECK
  359. if (!(gur->pordevsr & PORDEVSR_PCI)) {
  360. /* PCI-X init */
  361. if (CONFIG_SYS_CLK_FREQ < 66000000)
  362. printf("PCI-X will only work at 66 MHz\n");
  363. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  364. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  365. pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
  366. }
  367. #endif
  368. } else {
  369. printf (" PCI: disabled\n");
  370. }
  371. }
  372. #else
  373. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  374. #endif
  375. #ifdef CONFIG_PCI2
  376. {
  377. uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
  378. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  379. if (pci_dual) {
  380. printf (" PCI2: 32 bit, 66 MHz, %s\n",
  381. pci2_clk_sel ? "sync" : "async");
  382. } else {
  383. printf (" PCI2: disabled\n");
  384. }
  385. }
  386. #else
  387. gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
  388. #endif /* CONFIG_PCI2 */
  389. #ifdef CONFIG_PCIE1
  390. {
  391. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  392. struct pci_controller *hose = &pcie1_hose;
  393. int pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  394. struct pci_region *r = hose->regions;
  395. int pcie_configured = io_sel >= 1;
  396. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  397. printf ("\n PCIE connected to slot as %s (base address %x)",
  398. pcie_ep ? "End Point" : "Root Complex",
  399. (uint)pci);
  400. if (pci->pme_msg_det) {
  401. pci->pme_msg_det = 0xffffffff;
  402. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  403. }
  404. printf ("\n");
  405. /* inbound */
  406. pci_set_region(r++,
  407. CONFIG_SYS_PCI_MEMORY_BUS,
  408. CONFIG_SYS_PCI_MEMORY_PHYS,
  409. CONFIG_SYS_PCI_MEMORY_SIZE,
  410. PCI_REGION_MEM | PCI_REGION_MEMORY);
  411. /* outbound memory */
  412. pci_set_region(r++,
  413. CONFIG_SYS_PCIE1_MEM_BASE,
  414. CONFIG_SYS_PCIE1_MEM_PHYS,
  415. CONFIG_SYS_PCIE1_MEM_SIZE,
  416. PCI_REGION_MEM);
  417. /* outbound io */
  418. pci_set_region(r++,
  419. CONFIG_SYS_PCIE1_IO_BASE,
  420. CONFIG_SYS_PCIE1_IO_PHYS,
  421. CONFIG_SYS_PCIE1_IO_SIZE,
  422. PCI_REGION_IO);
  423. hose->region_count = r - hose->regions;
  424. hose->first_busno=first_free_busno;
  425. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  426. fsl_pci_init(hose);
  427. printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
  428. first_free_busno=hose->last_busno+1;
  429. } else {
  430. printf (" PCIE: disabled\n");
  431. }
  432. }
  433. #else
  434. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  435. #endif
  436. }
  437. int last_stage_init(void)
  438. {
  439. return 0;
  440. }
  441. #if defined(CONFIG_OF_BOARD_SETUP)
  442. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  443. struct pci_controller *hose);
  444. void ft_board_setup(void *blob, bd_t *bd)
  445. {
  446. ft_cpu_setup(blob, bd);
  447. #ifdef CONFIG_PCI1
  448. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  449. #endif
  450. #ifdef CONFIG_PCIE1
  451. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  452. #endif
  453. }
  454. #endif