mpc8544ds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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/mmu.h>
  27. #include <asm/immap_85xx.h>
  28. #include <asm/immap_fsl_pci.h>
  29. #include <asm/fsl_ddr_sdram.h>
  30. #include <asm/io.h>
  31. #include <miiphy.h>
  32. #include <libfdt.h>
  33. #include <fdt_support.h>
  34. #include <tsec.h>
  35. #include "../common/pixis.h"
  36. #include "../common/sgmii_riser.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. int checkboard (void)
  41. {
  42. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  43. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  44. volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
  45. if ((uint)&gur->porpllsr != 0xe00e0000) {
  46. printf("immap size error %lx\n",(ulong)&gur->porpllsr);
  47. }
  48. printf ("Board: MPC8544DS, System ID: 0x%02x, "
  49. "System Version: 0x%02x, FPGA Version: 0x%02x\n",
  50. in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
  51. in8(PIXIS_BASE + PIXIS_PVER));
  52. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  53. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  54. ecm->eedr = 0xffffffff; /* Clear ecm errors */
  55. ecm->eeer = 0xffffffff; /* Enable ecm errors */
  56. return 0;
  57. }
  58. phys_size_t
  59. initdram(int board_type)
  60. {
  61. long dram_size = 0;
  62. puts("Initializing\n");
  63. dram_size = fsl_ddr_sdram();
  64. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  65. dram_size *= 0x100000;
  66. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  67. /*
  68. * Initialize and enable DDR ECC.
  69. */
  70. ddr_enable_ecc(dram_size);
  71. #endif
  72. puts(" DDR: ");
  73. return dram_size;
  74. }
  75. #ifdef CONFIG_PCI1
  76. static struct pci_controller pci1_hose;
  77. #endif
  78. #ifdef CONFIG_PCIE1
  79. static struct pci_controller pcie1_hose;
  80. #endif
  81. #ifdef CONFIG_PCIE2
  82. static struct pci_controller pcie2_hose;
  83. #endif
  84. #ifdef CONFIG_PCIE3
  85. static struct pci_controller pcie3_hose;
  86. #endif
  87. int first_free_busno=0;
  88. void
  89. pci_init_board(void)
  90. {
  91. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  92. uint devdisr = gur->devdisr;
  93. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  94. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  95. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  96. devdisr, io_sel, host_agent);
  97. if (io_sel & 1) {
  98. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  99. printf (" eTSEC1 is in sgmii mode.\n");
  100. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  101. printf (" eTSEC3 is in sgmii mode.\n");
  102. }
  103. #ifdef CONFIG_PCIE3
  104. {
  105. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE3_ADDR;
  106. extern void fsl_pci_init(struct pci_controller *hose);
  107. struct pci_controller *hose = &pcie3_hose;
  108. int pcie_ep = (host_agent == 1);
  109. int pcie_configured = io_sel >= 1;
  110. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  111. printf ("\n PCIE3 connected to ULI as %s (base address %x)",
  112. pcie_ep ? "End Point" : "Root Complex",
  113. (uint)pci);
  114. if (pci->pme_msg_det) {
  115. pci->pme_msg_det = 0xffffffff;
  116. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  117. }
  118. printf ("\n");
  119. /* inbound */
  120. pci_set_region(hose->regions + 0,
  121. CFG_PCI_MEMORY_BUS,
  122. CFG_PCI_MEMORY_PHYS,
  123. CFG_PCI_MEMORY_SIZE,
  124. PCI_REGION_MEM | PCI_REGION_MEMORY);
  125. /* outbound memory */
  126. pci_set_region(hose->regions + 1,
  127. CFG_PCIE3_MEM_BASE,
  128. CFG_PCIE3_MEM_PHYS,
  129. CFG_PCIE3_MEM_SIZE,
  130. PCI_REGION_MEM);
  131. /* outbound io */
  132. pci_set_region(hose->regions + 2,
  133. CFG_PCIE3_IO_BASE,
  134. CFG_PCIE3_IO_PHYS,
  135. CFG_PCIE3_IO_SIZE,
  136. PCI_REGION_IO);
  137. hose->region_count = 3;
  138. #ifdef CFG_PCIE3_MEM_BASE2
  139. /* outbound memory */
  140. pci_set_region(hose->regions + 3,
  141. CFG_PCIE3_MEM_BASE2,
  142. CFG_PCIE3_MEM_PHYS2,
  143. CFG_PCIE3_MEM_SIZE2,
  144. PCI_REGION_MEM);
  145. hose->region_count++;
  146. #endif
  147. hose->first_busno=first_free_busno;
  148. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  149. fsl_pci_init(hose);
  150. first_free_busno=hose->last_busno+1;
  151. printf (" PCIE3 on bus %02x - %02x\n",
  152. hose->first_busno,hose->last_busno);
  153. /*
  154. * Activate ULI1575 legacy chip by performing a fake
  155. * memory access. Needed to make ULI RTC work.
  156. */
  157. in_be32((u32 *)CFG_PCIE3_MEM_BASE);
  158. } else {
  159. printf (" PCIE3: disabled\n");
  160. }
  161. }
  162. #else
  163. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  164. #endif
  165. #ifdef CONFIG_PCIE1
  166. {
  167. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  168. extern void fsl_pci_init(struct pci_controller *hose);
  169. struct pci_controller *hose = &pcie1_hose;
  170. int pcie_ep = (host_agent == 5);
  171. int pcie_configured = io_sel & 6;
  172. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  173. printf ("\n PCIE1 connected to Slot2 as %s (base address %x)",
  174. pcie_ep ? "End Point" : "Root Complex",
  175. (uint)pci);
  176. if (pci->pme_msg_det) {
  177. pci->pme_msg_det = 0xffffffff;
  178. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  179. }
  180. printf ("\n");
  181. /* inbound */
  182. pci_set_region(hose->regions + 0,
  183. CFG_PCI_MEMORY_BUS,
  184. CFG_PCI_MEMORY_PHYS,
  185. CFG_PCI_MEMORY_SIZE,
  186. PCI_REGION_MEM | PCI_REGION_MEMORY);
  187. /* outbound memory */
  188. pci_set_region(hose->regions + 1,
  189. CFG_PCIE1_MEM_BASE,
  190. CFG_PCIE1_MEM_PHYS,
  191. CFG_PCIE1_MEM_SIZE,
  192. PCI_REGION_MEM);
  193. /* outbound io */
  194. pci_set_region(hose->regions + 2,
  195. CFG_PCIE1_IO_BASE,
  196. CFG_PCIE1_IO_PHYS,
  197. CFG_PCIE1_IO_SIZE,
  198. PCI_REGION_IO);
  199. hose->region_count = 3;
  200. #ifdef CFG_PCIE1_MEM_BASE2
  201. /* outbound memory */
  202. pci_set_region(hose->regions + 3,
  203. CFG_PCIE1_MEM_BASE2,
  204. CFG_PCIE1_MEM_PHYS2,
  205. CFG_PCIE1_MEM_SIZE2,
  206. PCI_REGION_MEM);
  207. hose->region_count++;
  208. #endif
  209. hose->first_busno=first_free_busno;
  210. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  211. fsl_pci_init(hose);
  212. first_free_busno=hose->last_busno+1;
  213. printf(" PCIE1 on bus %02x - %02x\n",
  214. hose->first_busno,hose->last_busno);
  215. } else {
  216. printf (" PCIE1: disabled\n");
  217. }
  218. }
  219. #else
  220. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  221. #endif
  222. #ifdef CONFIG_PCIE2
  223. {
  224. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  225. extern void fsl_pci_init(struct pci_controller *hose);
  226. struct pci_controller *hose = &pcie2_hose;
  227. int pcie_ep = (host_agent == 3);
  228. int pcie_configured = io_sel & 4;
  229. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  230. printf ("\n PCIE2 connected to Slot 1 as %s (base address %x)",
  231. pcie_ep ? "End Point" : "Root Complex",
  232. (uint)pci);
  233. if (pci->pme_msg_det) {
  234. pci->pme_msg_det = 0xffffffff;
  235. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  236. }
  237. printf ("\n");
  238. /* inbound */
  239. pci_set_region(hose->regions + 0,
  240. CFG_PCI_MEMORY_BUS,
  241. CFG_PCI_MEMORY_PHYS,
  242. CFG_PCI_MEMORY_SIZE,
  243. PCI_REGION_MEM | PCI_REGION_MEMORY);
  244. /* outbound memory */
  245. pci_set_region(hose->regions + 1,
  246. CFG_PCIE2_MEM_BASE,
  247. CFG_PCIE2_MEM_PHYS,
  248. CFG_PCIE2_MEM_SIZE,
  249. PCI_REGION_MEM);
  250. /* outbound io */
  251. pci_set_region(hose->regions + 2,
  252. CFG_PCIE2_IO_BASE,
  253. CFG_PCIE2_IO_PHYS,
  254. CFG_PCIE2_IO_SIZE,
  255. PCI_REGION_IO);
  256. hose->region_count = 3;
  257. #ifdef CFG_PCIE2_MEM_BASE2
  258. /* outbound memory */
  259. pci_set_region(hose->regions + 3,
  260. CFG_PCIE2_MEM_BASE2,
  261. CFG_PCIE2_MEM_PHYS2,
  262. CFG_PCIE2_MEM_SIZE2,
  263. PCI_REGION_MEM);
  264. hose->region_count++;
  265. #endif
  266. hose->first_busno=first_free_busno;
  267. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  268. fsl_pci_init(hose);
  269. first_free_busno=hose->last_busno+1;
  270. printf (" PCIE2 on bus %02x - %02x\n",
  271. hose->first_busno,hose->last_busno);
  272. } else {
  273. printf (" PCIE2: disabled\n");
  274. }
  275. }
  276. #else
  277. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  278. #endif
  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. uint pci_agent = (host_agent == 6);
  285. uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */
  286. uint pci_32 = 1;
  287. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  288. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  289. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  290. printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
  291. (pci_32) ? 32 : 64,
  292. (pci_speed == 33333000) ? "33" :
  293. (pci_speed == 66666000) ? "66" : "unknown",
  294. pci_clk_sel ? "sync" : "async",
  295. pci_agent ? "agent" : "host",
  296. pci_arb ? "arbiter" : "external-arbiter",
  297. (uint)pci
  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. #ifdef CFG_PCIE3_MEM_BASE2
  319. /* outbound memory */
  320. pci_set_region(hose->regions + 3,
  321. CFG_PCIE3_MEM_BASE2,
  322. CFG_PCIE3_MEM_PHYS2,
  323. CFG_PCIE3_MEM_SIZE2,
  324. PCI_REGION_MEM);
  325. hose->region_count++;
  326. #endif
  327. hose->first_busno=first_free_busno;
  328. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  329. fsl_pci_init(hose);
  330. first_free_busno=hose->last_busno+1;
  331. printf ("PCI on bus %02x - %02x\n",
  332. hose->first_busno,hose->last_busno);
  333. } else {
  334. printf (" PCI: disabled\n");
  335. }
  336. }
  337. #else
  338. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  339. #endif
  340. }
  341. int last_stage_init(void)
  342. {
  343. return 0;
  344. }
  345. unsigned long
  346. get_board_sys_clk(ulong dummy)
  347. {
  348. u8 i, go_bit, rd_clks;
  349. ulong val = 0;
  350. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  351. go_bit &= 0x01;
  352. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  353. rd_clks &= 0x1C;
  354. /*
  355. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  356. * should we be using the AUX register. Remember, we also set the
  357. * GO bit to boot from the alternate bank on the on-board flash
  358. */
  359. if (go_bit) {
  360. if (rd_clks == 0x1c)
  361. i = in8(PIXIS_BASE + PIXIS_AUX);
  362. else
  363. i = in8(PIXIS_BASE + PIXIS_SPD);
  364. } else {
  365. i = in8(PIXIS_BASE + PIXIS_SPD);
  366. }
  367. i &= 0x07;
  368. switch (i) {
  369. case 0:
  370. val = 33333333;
  371. break;
  372. case 1:
  373. val = 40000000;
  374. break;
  375. case 2:
  376. val = 50000000;
  377. break;
  378. case 3:
  379. val = 66666666;
  380. break;
  381. case 4:
  382. val = 83000000;
  383. break;
  384. case 5:
  385. val = 100000000;
  386. break;
  387. case 6:
  388. val = 133333333;
  389. break;
  390. case 7:
  391. val = 166666666;
  392. break;
  393. }
  394. return val;
  395. }
  396. #ifdef CONFIG_TSEC_ENET
  397. int board_eth_init(bd_t *bis)
  398. {
  399. struct tsec_info_struct tsec_info[2];
  400. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  401. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  402. int num = 0;
  403. #ifdef CONFIG_TSEC1
  404. SET_STD_TSEC_INFO(tsec_info[num], 1);
  405. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  406. tsec_info[num].flags |= TSEC_SGMII;
  407. num++;
  408. #endif
  409. #ifdef CONFIG_TSEC3
  410. SET_STD_TSEC_INFO(tsec_info[num], 3);
  411. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  412. tsec_info[num].flags |= TSEC_SGMII;
  413. num++;
  414. #endif
  415. if (!num) {
  416. printf("No TSECs initialized\n");
  417. return 0;
  418. }
  419. if (io_sel & 1)
  420. fsl_sgmii_riser_init(tsec_info, num);
  421. tsec_eth_init(bis, tsec_info, num);
  422. return 0;
  423. }
  424. #endif
  425. #if defined(CONFIG_OF_BOARD_SETUP)
  426. void
  427. ft_board_setup(void *blob, bd_t *bd)
  428. {
  429. int node, tmp[2];
  430. const char *path;
  431. ft_cpu_setup(blob, bd);
  432. node = fdt_path_offset(blob, "/aliases");
  433. tmp[0] = 0;
  434. if (node >= 0) {
  435. #ifdef CONFIG_PCI1
  436. path = fdt_getprop(blob, node, "pci0", NULL);
  437. if (path) {
  438. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  439. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  440. }
  441. #endif
  442. #ifdef CONFIG_PCIE2
  443. path = fdt_getprop(blob, node, "pci1", NULL);
  444. if (path) {
  445. tmp[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
  446. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  447. }
  448. #endif
  449. #ifdef CONFIG_PCIE1
  450. path = fdt_getprop(blob, node, "pci2", NULL);
  451. if (path) {
  452. tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  453. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  454. }
  455. #endif
  456. #ifdef CONFIG_PCIE3
  457. path = fdt_getprop(blob, node, "pci3", NULL);
  458. if (path) {
  459. tmp[1] = pcie3_hose.last_busno - pcie3_hose.first_busno;
  460. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  461. }
  462. #endif
  463. }
  464. }
  465. #endif