mpc8544ds.c 12 KB

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