mpc8548cds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * Copyright 2004, 2007 Freescale Semiconductor.
  3. *
  4. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/immap_85xx.h>
  28. #include <asm/immap_fsl_pci.h>
  29. #include <spd.h>
  30. #include <miiphy.h>
  31. #include "../common/cadmus.h"
  32. #include "../common/eeprom.h"
  33. #include "../common/via.h"
  34. #if defined(CONFIG_OF_FLAT_TREE)
  35. #include <ft_build.h>
  36. #endif
  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. extern long int spd_sdram(void);
  42. void local_bus_init(void);
  43. void sdram_init(void);
  44. int board_early_init_f (void)
  45. {
  46. return 0;
  47. }
  48. int checkboard (void)
  49. {
  50. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  51. volatile ccsr_gur_t *gur = &immap->im_gur;
  52. volatile ccsr_local_ecm_t *ecm = &immap->im_local_ecm;
  53. /* PCI slot in USER bits CSR[6:7] by convention. */
  54. uint pci_slot = get_pci_slot ();
  55. uint cpu_board_rev = get_cpu_board_revision ();
  56. printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
  57. get_board_version (), pci_slot);
  58. printf ("CPU Board Revision %d.%d (0x%04x)\n",
  59. MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
  60. MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
  61. /*
  62. * Initialize local bus.
  63. */
  64. local_bus_init ();
  65. /*
  66. * Fix CPU2 errata: A core hang possible while executing a
  67. * msync instruction and a snoopable transaction from an I/O
  68. * master tagged to make quick forward progress is present.
  69. */
  70. ecm->eebpcr |= (1 << 16);
  71. /*
  72. * Hack TSEC 3 and 4 IO voltages.
  73. */
  74. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  75. ecm->eedr = 0xffffffff; /* clear ecm errors */
  76. ecm->eeer = 0xffffffff; /* enable ecm errors */
  77. return 0;
  78. }
  79. long int
  80. initdram(int board_type)
  81. {
  82. long dram_size = 0;
  83. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  84. puts("Initializing\n");
  85. #if defined(CONFIG_DDR_DLL)
  86. {
  87. /*
  88. * Work around to stabilize DDR DLL MSYNC_IN.
  89. * Errata DDR9 seems to have been fixed.
  90. * This is now the workaround for Errata DDR11:
  91. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  92. */
  93. volatile ccsr_gur_t *gur= &immap->im_gur;
  94. gur->ddrdllcr = 0x81000000;
  95. asm("sync;isync;msync");
  96. udelay(200);
  97. }
  98. #endif
  99. dram_size = spd_sdram();
  100. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  101. /*
  102. * Initialize and enable DDR ECC.
  103. */
  104. ddr_enable_ecc(dram_size);
  105. #endif
  106. /*
  107. * SDRAM Initialization
  108. */
  109. sdram_init();
  110. puts(" DDR: ");
  111. return dram_size;
  112. }
  113. /*
  114. * Initialize Local Bus
  115. */
  116. void
  117. local_bus_init(void)
  118. {
  119. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  120. volatile ccsr_gur_t *gur = &immap->im_gur;
  121. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  122. uint clkdiv;
  123. uint lbc_hz;
  124. sys_info_t sysinfo;
  125. get_sys_info(&sysinfo);
  126. clkdiv = (lbc->lcrr & 0x0f) * 2;
  127. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  128. gur->lbiuiplldcr1 = 0x00078080;
  129. if (clkdiv == 16) {
  130. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  131. } else if (clkdiv == 8) {
  132. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  133. } else if (clkdiv == 4) {
  134. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  135. }
  136. lbc->lcrr |= 0x00030000;
  137. asm("sync;isync;msync");
  138. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  139. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  140. }
  141. /*
  142. * Initialize SDRAM memory on the Local Bus.
  143. */
  144. void
  145. sdram_init(void)
  146. {
  147. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  148. uint idx;
  149. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  150. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  151. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  152. uint cpu_board_rev;
  153. uint lsdmr_common;
  154. puts(" SDRAM: ");
  155. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  156. /*
  157. * Setup SDRAM Base and Option Registers
  158. */
  159. lbc->or2 = CFG_OR2_PRELIM;
  160. asm("msync");
  161. lbc->br2 = CFG_BR2_PRELIM;
  162. asm("msync");
  163. lbc->lbcr = CFG_LBC_LBCR;
  164. asm("msync");
  165. lbc->lsrt = CFG_LBC_LSRT;
  166. lbc->mrtpr = CFG_LBC_MRTPR;
  167. asm("msync");
  168. /*
  169. * MPC8548 uses "new" 15-16 style addressing.
  170. */
  171. cpu_board_rev = get_cpu_board_revision();
  172. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  173. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  174. /*
  175. * Issue PRECHARGE ALL command.
  176. */
  177. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  178. asm("sync;msync");
  179. *sdram_addr = 0xff;
  180. ppcDcbf((unsigned long) sdram_addr);
  181. udelay(100);
  182. /*
  183. * Issue 8 AUTO REFRESH commands.
  184. */
  185. for (idx = 0; idx < 8; idx++) {
  186. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  187. asm("sync;msync");
  188. *sdram_addr = 0xff;
  189. ppcDcbf((unsigned long) sdram_addr);
  190. udelay(100);
  191. }
  192. /*
  193. * Issue 8 MODE-set command.
  194. */
  195. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  196. asm("sync;msync");
  197. *sdram_addr = 0xff;
  198. ppcDcbf((unsigned long) sdram_addr);
  199. udelay(100);
  200. /*
  201. * Issue NORMAL OP command.
  202. */
  203. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  204. asm("sync;msync");
  205. *sdram_addr = 0xff;
  206. ppcDcbf((unsigned long) sdram_addr);
  207. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  208. #endif /* enable SDRAM init */
  209. }
  210. #if defined(CFG_DRAM_TEST)
  211. int
  212. testdram(void)
  213. {
  214. uint *pstart = (uint *) CFG_MEMTEST_START;
  215. uint *pend = (uint *) CFG_MEMTEST_END;
  216. uint *p;
  217. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  218. CFG_MEMTEST_START,
  219. CFG_MEMTEST_END);
  220. printf("DRAM test phase 1:\n");
  221. for (p = pstart; p < pend; p++)
  222. *p = 0xaaaaaaaa;
  223. for (p = pstart; p < pend; p++) {
  224. if (*p != 0xaaaaaaaa) {
  225. printf ("DRAM test fails at: %08x\n", (uint) p);
  226. return 1;
  227. }
  228. }
  229. printf("DRAM test phase 2:\n");
  230. for (p = pstart; p < pend; p++)
  231. *p = 0x55555555;
  232. for (p = pstart; p < pend; p++) {
  233. if (*p != 0x55555555) {
  234. printf ("DRAM test fails at: %08x\n", (uint) p);
  235. return 1;
  236. }
  237. }
  238. printf("DRAM test passed.\n");
  239. return 0;
  240. }
  241. #endif
  242. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  243. /* For some reason the Tundra PCI bridge shows up on itself as a
  244. * different device. Work around that by refusing to configure it.
  245. */
  246. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  247. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  248. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  249. {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
  250. {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
  251. mpc85xx_config_via_usbide, {0,0,0}},
  252. {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
  253. mpc85xx_config_via_usb, {0,0,0}},
  254. {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
  255. mpc85xx_config_via_usb2, {0,0,0}},
  256. {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
  257. mpc85xx_config_via_power, {0,0,0}},
  258. {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
  259. mpc85xx_config_via_ac97, {0,0,0}},
  260. {},
  261. };
  262. static struct pci_controller pci1_hose = {
  263. config_table: pci_mpc85xxcds_config_table};
  264. #endif /* CONFIG_PCI */
  265. #ifdef CONFIG_PCI2
  266. static struct pci_controller pci2_hose;
  267. #endif /* CONFIG_PCI2 */
  268. #ifdef CONFIG_PCIE1
  269. static struct pci_controller pcie1_hose;
  270. #endif /* CONFIG_PCIE1 */
  271. int first_free_busno=0;
  272. void
  273. pci_init_board(void)
  274. {
  275. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  276. volatile ccsr_gur_t *gur = &immap->im_gur;
  277. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  278. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  279. #ifdef CONFIG_PCI1
  280. {
  281. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  282. extern void fsl_pci_init(struct pci_controller *hose);
  283. struct pci_controller *hose = &pci1_hose;
  284. struct pci_config_table *table;
  285. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  286. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  287. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  288. uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
  289. uint pci_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  290. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  291. printf (" PCI: %d bit, %s MHz, %s, %s, %s\n",
  292. (pci_32) ? 32 : 64,
  293. (pci_speed == 33333000) ? "33" :
  294. (pci_speed == 66666000) ? "66" : "unknown",
  295. pci_clk_sel ? "sync" : "async",
  296. pci_agent ? "agent" : "host",
  297. pci_arb ? "arbiter" : "external-arbiter"
  298. );
  299. /* inbound */
  300. pci_set_region(hose->regions + 0,
  301. CFG_PCI_MEMORY_BUS,
  302. CFG_PCI_MEMORY_PHYS,
  303. CFG_PCI_MEMORY_SIZE,
  304. PCI_REGION_MEM | PCI_REGION_MEMORY);
  305. /* outbound memory */
  306. pci_set_region(hose->regions + 1,
  307. CFG_PCI1_MEM_BASE,
  308. CFG_PCI1_MEM_PHYS,
  309. CFG_PCI1_MEM_SIZE,
  310. PCI_REGION_MEM);
  311. /* outbound io */
  312. pci_set_region(hose->regions + 2,
  313. CFG_PCI1_IO_BASE,
  314. CFG_PCI1_IO_PHYS,
  315. CFG_PCI1_IO_SIZE,
  316. PCI_REGION_IO);
  317. hose->region_count = 3;
  318. /* relocate config table pointers */
  319. hose->config_table = \
  320. (struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
  321. for (table = hose->config_table; table && table->vendor; table++)
  322. table->config_device += gd->reloc_off;
  323. hose->first_busno=first_free_busno;
  324. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  325. fsl_pci_init(hose);
  326. first_free_busno=hose->last_busno+1;
  327. printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  328. #ifdef CONFIG_PCIX_CHECK
  329. if (!(gur->pordevsr & PORDEVSR_PCI)) {
  330. /* PCI-X init */
  331. if (CONFIG_SYS_CLK_FREQ < 66000000)
  332. printf("PCI-X will only work at 66 MHz\n");
  333. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  334. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  335. pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
  336. }
  337. #endif
  338. } else {
  339. printf (" PCI: disabled\n");
  340. }
  341. }
  342. #else
  343. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  344. #endif
  345. #ifdef CONFIG_PCI2
  346. {
  347. uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
  348. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  349. if (pci_dual) {
  350. printf (" PCI2: 32 bit, 66 MHz, %s\n",
  351. pci2_clk_sel ? "sync" : "async");
  352. } else {
  353. printf (" PCI2: disabled\n");
  354. }
  355. }
  356. #else
  357. gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
  358. #endif /* CONFIG_PCI2 */
  359. #ifdef CONFIG_PCIE1
  360. {
  361. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  362. extern void fsl_pci_init(struct pci_controller *hose);
  363. struct pci_controller *hose = &pcie1_hose;
  364. int pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  365. int pcie_configured = io_sel >= 1;
  366. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  367. printf ("\n PCIE connected to slot as %s (base address %x)",
  368. pcie_ep ? "End Point" : "Root Complex",
  369. (uint)pci);
  370. if (pci->pme_msg_det) {
  371. pci->pme_msg_det = 0xffffffff;
  372. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  373. }
  374. printf ("\n");
  375. /* inbound */
  376. pci_set_region(hose->regions + 0,
  377. CFG_PCI_MEMORY_BUS,
  378. CFG_PCI_MEMORY_PHYS,
  379. CFG_PCI_MEMORY_SIZE,
  380. PCI_REGION_MEM | PCI_REGION_MEMORY);
  381. /* outbound memory */
  382. pci_set_region(hose->regions + 1,
  383. CFG_PCIE1_MEM_BASE,
  384. CFG_PCIE1_MEM_PHYS,
  385. CFG_PCIE1_MEM_SIZE,
  386. PCI_REGION_MEM);
  387. /* outbound io */
  388. pci_set_region(hose->regions + 2,
  389. CFG_PCIE1_IO_BASE,
  390. CFG_PCIE1_IO_PHYS,
  391. CFG_PCIE1_IO_SIZE,
  392. PCI_REGION_IO);
  393. hose->region_count = 3;
  394. hose->first_busno=first_free_busno;
  395. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  396. fsl_pci_init(hose);
  397. printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
  398. first_free_busno=hose->last_busno+1;
  399. } else {
  400. printf (" PCIE: disabled\n");
  401. }
  402. }
  403. #else
  404. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  405. #endif
  406. }
  407. int last_stage_init(void)
  408. {
  409. unsigned short temp;
  410. /* Change the resistors for the PHY */
  411. /* This is needed to get the RGMII working for the 1.3+
  412. * CDS cards */
  413. if (get_board_version() == 0x13) {
  414. miiphy_write(CONFIG_TSEC1_NAME,
  415. TSEC1_PHY_ADDR, 29, 18);
  416. miiphy_read(CONFIG_TSEC1_NAME,
  417. TSEC1_PHY_ADDR, 30, &temp);
  418. temp = (temp & 0xf03f);
  419. temp |= 2 << 9; /* 36 ohm */
  420. temp |= 2 << 6; /* 39 ohm */
  421. miiphy_write(CONFIG_TSEC1_NAME,
  422. TSEC1_PHY_ADDR, 30, temp);
  423. miiphy_write(CONFIG_TSEC1_NAME,
  424. TSEC1_PHY_ADDR, 29, 3);
  425. miiphy_write(CONFIG_TSEC1_NAME,
  426. TSEC1_PHY_ADDR, 30, 0x8000);
  427. }
  428. return 0;
  429. }
  430. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  431. void
  432. ft_pci_setup(void *blob, bd_t *bd)
  433. {
  434. u32 *p;
  435. int len;
  436. #ifdef CONFIG_PCI1
  437. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8000/bus-range", &len);
  438. if (p != NULL) {
  439. p[0] = 0;
  440. p[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  441. debug("PCI@8000 first_busno=%d last_busno=%d\n",p[0],p[1]);
  442. }
  443. #endif
  444. #ifdef CONFIG_PCIE1
  445. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@a000/bus-range", &len);
  446. if (p != NULL) {
  447. p[0] = 0;
  448. p[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  449. debug("PCI@a000 first_busno=%d last_busno=%d\n",p[0],p[1]);
  450. }
  451. #endif
  452. }
  453. #endif