mpc8544ds.c 13 KB

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