mpc8544ds.c 13 KB

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