mpc8544ds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <pci.h>
  25. #include <asm/processor.h>
  26. #include <asm/immap_85xx.h>
  27. #include <asm/immap_fsl_pci.h>
  28. #include <asm/io.h>
  29. #include <spd.h>
  30. #include <miiphy.h>
  31. #include <libfdt.h>
  32. #include <fdt_support.h>
  33. #include "../common/pixis.h"
  34. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  35. extern void ddr_enable_ecc(unsigned int dram_size);
  36. #endif
  37. extern long int spd_sdram(void);
  38. void sdram_init(void);
  39. int board_early_init_f (void)
  40. {
  41. return 0;
  42. }
  43. int checkboard (void)
  44. {
  45. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  46. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  47. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  48. volatile ccsr_local_ecm_t *ecm = &immap->im_local_ecm;
  49. if ((uint)&gur->porpllsr != 0xe00e0000) {
  50. printf("immap size error %x\n",&gur->porpllsr);
  51. }
  52. printf ("Board: MPC8544DS\n");
  53. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  54. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  55. ecm->eedr = 0xffffffff; /* Clear ecm errors */
  56. ecm->eeer = 0xffffffff; /* Enable ecm errors */
  57. return 0;
  58. }
  59. long int
  60. initdram(int board_type)
  61. {
  62. long dram_size = 0;
  63. puts("Initializing\n");
  64. dram_size = spd_sdram();
  65. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  66. /*
  67. * Initialize and enable DDR ECC.
  68. */
  69. ddr_enable_ecc(dram_size);
  70. #endif
  71. puts(" DDR: ");
  72. return dram_size;
  73. }
  74. #if defined(CFG_DRAM_TEST)
  75. int
  76. testdram(void)
  77. {
  78. uint *pstart = (uint *) CFG_MEMTEST_START;
  79. uint *pend = (uint *) CFG_MEMTEST_END;
  80. uint *p;
  81. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  82. CFG_MEMTEST_START,
  83. CFG_MEMTEST_END);
  84. printf("DRAM test phase 1:\n");
  85. for (p = pstart; p < pend; p++)
  86. *p = 0xaaaaaaaa;
  87. for (p = pstart; p < pend; p++) {
  88. if (*p != 0xaaaaaaaa) {
  89. printf ("DRAM test fails at: %08x\n", (uint) p);
  90. return 1;
  91. }
  92. }
  93. printf("DRAM test phase 2:\n");
  94. for (p = pstart; p < pend; p++)
  95. *p = 0x55555555;
  96. for (p = pstart; p < pend; p++) {
  97. if (*p != 0x55555555) {
  98. printf ("DRAM test fails at: %08x\n", (uint) p);
  99. return 1;
  100. }
  101. }
  102. printf("DRAM test passed.\n");
  103. return 0;
  104. }
  105. #endif
  106. #ifdef CONFIG_PCI1
  107. static struct pci_controller pci1_hose;
  108. #endif
  109. #ifdef CONFIG_PCIE1
  110. static struct pci_controller pcie1_hose;
  111. #endif
  112. #ifdef CONFIG_PCIE2
  113. static struct pci_controller pcie2_hose;
  114. #endif
  115. #ifdef CONFIG_PCIE3
  116. static struct pci_controller pcie3_hose;
  117. #endif
  118. int first_free_busno=0;
  119. void
  120. pci_init_board(void)
  121. {
  122. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  123. uint devdisr = gur->devdisr;
  124. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  125. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  126. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  127. devdisr, io_sel, host_agent);
  128. if (io_sel & 1) {
  129. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  130. printf (" eTSEC1 is in sgmii mode.\n");
  131. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  132. printf (" eTSEC3 is in sgmii mode.\n");
  133. }
  134. #ifdef CONFIG_PCIE3
  135. {
  136. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE3_ADDR;
  137. extern void fsl_pci_init(struct pci_controller *hose);
  138. struct pci_controller *hose = &pcie3_hose;
  139. int pcie_ep = (host_agent == 3);
  140. int pcie_configured = io_sel >= 1;
  141. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  142. printf ("\n PCIE3 connected to ULI as %s (base address %x)",
  143. pcie_ep ? "End Point" : "Root Complex",
  144. (uint)pci);
  145. if (pci->pme_msg_det) {
  146. pci->pme_msg_det = 0xffffffff;
  147. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  148. }
  149. printf ("\n");
  150. /* inbound */
  151. pci_set_region(hose->regions + 0,
  152. CFG_PCI_MEMORY_BUS,
  153. CFG_PCI_MEMORY_PHYS,
  154. CFG_PCI_MEMORY_SIZE,
  155. PCI_REGION_MEM | PCI_REGION_MEMORY);
  156. /* outbound memory */
  157. pci_set_region(hose->regions + 1,
  158. CFG_PCIE3_MEM_BASE,
  159. CFG_PCIE3_MEM_PHYS,
  160. CFG_PCIE3_MEM_SIZE,
  161. PCI_REGION_MEM);
  162. /* outbound io */
  163. pci_set_region(hose->regions + 2,
  164. CFG_PCIE3_IO_BASE,
  165. CFG_PCIE3_IO_PHYS,
  166. CFG_PCIE3_IO_SIZE,
  167. PCI_REGION_IO);
  168. hose->region_count = 3;
  169. #ifdef CFG_PCIE3_MEM_BASE2
  170. /* outbound memory */
  171. pci_set_region(hose->regions + 3,
  172. CFG_PCIE3_MEM_BASE2,
  173. CFG_PCIE3_MEM_PHYS2,
  174. CFG_PCIE3_MEM_SIZE2,
  175. PCI_REGION_MEM);
  176. hose->region_count++;
  177. #endif
  178. hose->first_busno=first_free_busno;
  179. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  180. fsl_pci_init(hose);
  181. first_free_busno=hose->last_busno+1;
  182. printf (" PCIE3 on bus %02x - %02x\n",
  183. hose->first_busno,hose->last_busno);
  184. /*
  185. * Activate ULI1575 legacy chip by performing a fake
  186. * memory access. Needed to make ULI RTC work.
  187. */
  188. in_be32((u32 *)CFG_PCIE3_MEM_BASE);
  189. } else {
  190. printf (" PCIE3: disabled\n");
  191. }
  192. }
  193. #else
  194. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  195. #endif
  196. #ifdef CONFIG_PCIE1
  197. {
  198. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  199. extern void fsl_pci_init(struct pci_controller *hose);
  200. struct pci_controller *hose = &pcie1_hose;
  201. int pcie_ep = (host_agent == 5);
  202. int pcie_configured = io_sel & 6;
  203. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  204. printf ("\n PCIE1 connected to Slot2 as %s (base address %x)",
  205. pcie_ep ? "End Point" : "Root Complex",
  206. (uint)pci);
  207. if (pci->pme_msg_det) {
  208. pci->pme_msg_det = 0xffffffff;
  209. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  210. }
  211. printf ("\n");
  212. /* inbound */
  213. pci_set_region(hose->regions + 0,
  214. CFG_PCI_MEMORY_BUS,
  215. CFG_PCI_MEMORY_PHYS,
  216. CFG_PCI_MEMORY_SIZE,
  217. PCI_REGION_MEM | PCI_REGION_MEMORY);
  218. /* outbound memory */
  219. pci_set_region(hose->regions + 1,
  220. CFG_PCIE1_MEM_BASE,
  221. CFG_PCIE1_MEM_PHYS,
  222. CFG_PCIE1_MEM_SIZE,
  223. PCI_REGION_MEM);
  224. /* outbound io */
  225. pci_set_region(hose->regions + 2,
  226. CFG_PCIE1_IO_BASE,
  227. CFG_PCIE1_IO_PHYS,
  228. CFG_PCIE1_IO_SIZE,
  229. PCI_REGION_IO);
  230. hose->region_count = 3;
  231. #ifdef CFG_PCIE1_MEM_BASE2
  232. /* outbound memory */
  233. pci_set_region(hose->regions + 3,
  234. CFG_PCIE1_MEM_BASE2,
  235. CFG_PCIE1_MEM_PHYS2,
  236. CFG_PCIE1_MEM_SIZE2,
  237. PCI_REGION_MEM);
  238. hose->region_count++;
  239. #endif
  240. hose->first_busno=first_free_busno;
  241. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  242. fsl_pci_init(hose);
  243. first_free_busno=hose->last_busno+1;
  244. printf(" PCIE1 on bus %02x - %02x\n",
  245. hose->first_busno,hose->last_busno);
  246. } else {
  247. printf (" PCIE1: disabled\n");
  248. }
  249. }
  250. #else
  251. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  252. #endif
  253. #ifdef CONFIG_PCIE2
  254. {
  255. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  256. extern void fsl_pci_init(struct pci_controller *hose);
  257. struct pci_controller *hose = &pcie2_hose;
  258. int pcie_ep = (host_agent == 3);
  259. int pcie_configured = io_sel & 4;
  260. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  261. printf ("\n PCIE2 connected to Slot 1 as %s (base address %x)",
  262. pcie_ep ? "End Point" : "Root Complex",
  263. (uint)pci);
  264. if (pci->pme_msg_det) {
  265. pci->pme_msg_det = 0xffffffff;
  266. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  267. }
  268. printf ("\n");
  269. /* inbound */
  270. pci_set_region(hose->regions + 0,
  271. CFG_PCI_MEMORY_BUS,
  272. CFG_PCI_MEMORY_PHYS,
  273. CFG_PCI_MEMORY_SIZE,
  274. PCI_REGION_MEM | PCI_REGION_MEMORY);
  275. /* outbound memory */
  276. pci_set_region(hose->regions + 1,
  277. CFG_PCIE2_MEM_BASE,
  278. CFG_PCIE2_MEM_PHYS,
  279. CFG_PCIE2_MEM_SIZE,
  280. PCI_REGION_MEM);
  281. /* outbound io */
  282. pci_set_region(hose->regions + 2,
  283. CFG_PCIE2_IO_BASE,
  284. CFG_PCIE2_IO_PHYS,
  285. CFG_PCIE2_IO_SIZE,
  286. PCI_REGION_IO);
  287. hose->region_count = 3;
  288. #ifdef CFG_PCIE2_MEM_BASE2
  289. /* outbound memory */
  290. pci_set_region(hose->regions + 3,
  291. CFG_PCIE2_MEM_BASE2,
  292. CFG_PCIE2_MEM_PHYS2,
  293. CFG_PCIE2_MEM_SIZE2,
  294. PCI_REGION_MEM);
  295. hose->region_count++;
  296. #endif
  297. hose->first_busno=first_free_busno;
  298. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  299. fsl_pci_init(hose);
  300. first_free_busno=hose->last_busno+1;
  301. printf (" PCIE2 on bus %02x - %02x\n",
  302. hose->first_busno,hose->last_busno);
  303. } else {
  304. printf (" PCIE2: disabled\n");
  305. }
  306. }
  307. #else
  308. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  309. #endif
  310. #ifdef CONFIG_PCI1
  311. {
  312. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  313. extern void fsl_pci_init(struct pci_controller *hose);
  314. struct pci_controller *hose = &pci1_hose;
  315. uint pci_agent = (host_agent == 6);
  316. uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */
  317. uint pci_32 = 1;
  318. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  319. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  320. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  321. printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
  322. (pci_32) ? 32 : 64,
  323. (pci_speed == 33333000) ? "33" :
  324. (pci_speed == 66666000) ? "66" : "unknown",
  325. pci_clk_sel ? "sync" : "async",
  326. pci_agent ? "agent" : "host",
  327. pci_arb ? "arbiter" : "external-arbiter",
  328. (uint)pci
  329. );
  330. /* inbound */
  331. pci_set_region(hose->regions + 0,
  332. CFG_PCI_MEMORY_BUS,
  333. CFG_PCI_MEMORY_PHYS,
  334. CFG_PCI_MEMORY_SIZE,
  335. PCI_REGION_MEM | PCI_REGION_MEMORY);
  336. /* outbound memory */
  337. pci_set_region(hose->regions + 1,
  338. CFG_PCI1_MEM_BASE,
  339. CFG_PCI1_MEM_PHYS,
  340. CFG_PCI1_MEM_SIZE,
  341. PCI_REGION_MEM);
  342. /* outbound io */
  343. pci_set_region(hose->regions + 2,
  344. CFG_PCI1_IO_BASE,
  345. CFG_PCI1_IO_PHYS,
  346. CFG_PCI1_IO_SIZE,
  347. PCI_REGION_IO);
  348. hose->region_count = 3;
  349. #ifdef CFG_PCIE3_MEM_BASE2
  350. /* outbound memory */
  351. pci_set_region(hose->regions + 3,
  352. CFG_PCIE3_MEM_BASE2,
  353. CFG_PCIE3_MEM_PHYS2,
  354. CFG_PCIE3_MEM_SIZE2,
  355. PCI_REGION_MEM);
  356. hose->region_count++;
  357. #endif
  358. hose->first_busno=first_free_busno;
  359. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  360. fsl_pci_init(hose);
  361. first_free_busno=hose->last_busno+1;
  362. printf ("PCI on bus %02x - %02x\n",
  363. hose->first_busno,hose->last_busno);
  364. } else {
  365. printf (" PCI: disabled\n");
  366. }
  367. }
  368. #else
  369. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  370. #endif
  371. }
  372. int last_stage_init(void)
  373. {
  374. return 0;
  375. }
  376. unsigned long
  377. get_board_sys_clk(ulong dummy)
  378. {
  379. u8 i, go_bit, rd_clks;
  380. ulong val = 0;
  381. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  382. go_bit &= 0x01;
  383. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  384. rd_clks &= 0x1C;
  385. /*
  386. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  387. * should we be using the AUX register. Remember, we also set the
  388. * GO bit to boot from the alternate bank on the on-board flash
  389. */
  390. if (go_bit) {
  391. if (rd_clks == 0x1c)
  392. i = in8(PIXIS_BASE + PIXIS_AUX);
  393. else
  394. i = in8(PIXIS_BASE + PIXIS_SPD);
  395. } else {
  396. i = in8(PIXIS_BASE + PIXIS_SPD);
  397. }
  398. i &= 0x07;
  399. switch (i) {
  400. case 0:
  401. val = 33333333;
  402. break;
  403. case 1:
  404. val = 40000000;
  405. break;
  406. case 2:
  407. val = 50000000;
  408. break;
  409. case 3:
  410. val = 66666666;
  411. break;
  412. case 4:
  413. val = 83000000;
  414. break;
  415. case 5:
  416. val = 100000000;
  417. break;
  418. case 6:
  419. val = 133333333;
  420. break;
  421. case 7:
  422. val = 166666666;
  423. break;
  424. }
  425. return val;
  426. }
  427. #if defined(CONFIG_OF_BOARD_SETUP)
  428. void
  429. ft_board_setup(void *blob, bd_t *bd)
  430. {
  431. int node, tmp[2];
  432. const char *path;
  433. ft_cpu_setup(blob, bd);
  434. node = fdt_path_offset(blob, "/aliases");
  435. tmp[0] = 0;
  436. if (node >= 0) {
  437. #ifdef CONFIG_PCI1
  438. path = fdt_getprop(blob, node, "pci0", NULL);
  439. if (path) {
  440. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  441. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  442. }
  443. #endif
  444. #ifdef CONFIG_PCIE2
  445. path = fdt_getprop(blob, node, "pci1", NULL);
  446. if (path) {
  447. tmp[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
  448. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  449. }
  450. #endif
  451. #ifdef CONFIG_PCIE1
  452. path = fdt_getprop(blob, node, "pci2", NULL);
  453. if (path) {
  454. tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  455. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  456. }
  457. #endif
  458. #ifdef CONFIG_PCIE3
  459. path = fdt_getprop(blob, node, "pci3", NULL);
  460. if (path) {
  461. tmp[1] = pcie3_hose.last_busno - pcie3_hose.first_busno;
  462. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  463. }
  464. #endif
  465. }
  466. }
  467. #endif