mpc8548cds.c 13 KB

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