mpc8544ds.c 13 KB

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