mpc8544ds.c 13 KB

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