mpc8544ds.c 13 KB

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