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