mpc8572ds.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Copyright 2007-2008 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/mmu.h>
  27. #include <asm/immap_85xx.h>
  28. #include <asm/immap_fsl_pci.h>
  29. #include <asm/fsl_ddr_sdram.h>
  30. #include <asm/io.h>
  31. #include <miiphy.h>
  32. #include <libfdt.h>
  33. #include <fdt_support.h>
  34. #include "../common/pixis.h"
  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. long int fixed_sdram(void);
  39. int checkboard (void)
  40. {
  41. printf ("Board: MPC8572DS, System ID: 0x%02x, "
  42. "System Version: 0x%02x, FPGA Version: 0x%02x\n",
  43. in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
  44. in8(PIXIS_BASE + PIXIS_PVER));
  45. return 0;
  46. }
  47. phys_size_t initdram(int board_type)
  48. {
  49. phys_size_t dram_size = 0;
  50. puts("Initializing....");
  51. #ifdef CONFIG_SPD_EEPROM
  52. dram_size = fsl_ddr_sdram();
  53. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  54. dram_size *= 0x100000;
  55. #else
  56. dram_size = fixed_sdram();
  57. #endif
  58. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  59. /*
  60. * Initialize and enable DDR ECC.
  61. */
  62. ddr_enable_ecc(dram_size);
  63. #endif
  64. puts(" DDR: ");
  65. return dram_size;
  66. }
  67. #if !defined(CONFIG_SPD_EEPROM)
  68. /*
  69. * Fixed sdram init -- doesn't use serial presence detect.
  70. */
  71. phys_size_t fixed_sdram (void)
  72. {
  73. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  74. volatile ccsr_ddr_t *ddr= &immap->im_ddr;
  75. uint d_init;
  76. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  77. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  78. ddr->timing_cfg_3 = CFG_DDR_TIMING_3;
  79. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  80. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  81. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  82. ddr->sdram_mode = CFG_DDR_MODE_1;
  83. ddr->sdram_mode_2 = CFG_DDR_MODE_2;
  84. ddr->sdram_interval = CFG_DDR_INTERVAL;
  85. ddr->sdram_data_init = CFG_DDR_DATA_INIT;
  86. ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
  87. ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
  88. #if defined (CONFIG_DDR_ECC)
  89. ddr->err_int_en = CFG_DDR_ERR_INT_EN;
  90. ddr->err_disable = CFG_DDR_ERR_DIS;
  91. ddr->err_sbe = CFG_DDR_SBE;
  92. #endif
  93. asm("sync;isync");
  94. udelay(500);
  95. ddr->sdram_cfg = CFG_DDR_CONTROL;
  96. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  97. d_init = 1;
  98. debug("DDR - 1st controller: memory initializing\n");
  99. /*
  100. * Poll until memory is initialized.
  101. * 512 Meg at 400 might hit this 200 times or so.
  102. */
  103. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
  104. udelay(1000);
  105. }
  106. debug("DDR: memory initialized\n\n");
  107. asm("sync; isync");
  108. udelay(500);
  109. #endif
  110. return 512 * 1024 * 1024;
  111. }
  112. #endif
  113. #ifdef CONFIG_PCIE1
  114. static struct pci_controller pcie1_hose;
  115. #endif
  116. #ifdef CONFIG_PCIE2
  117. static struct pci_controller pcie2_hose;
  118. #endif
  119. #ifdef CONFIG_PCIE3
  120. static struct pci_controller pcie3_hose;
  121. #endif
  122. int first_free_busno=0;
  123. #ifdef CONFIG_PCI
  124. void pci_init_board(void)
  125. {
  126. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  127. uint devdisr = gur->devdisr;
  128. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  129. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  130. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  131. devdisr, io_sel, host_agent);
  132. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  133. printf (" eTSEC1 is in sgmii mode.\n");
  134. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
  135. printf (" eTSEC2 is in sgmii mode.\n");
  136. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  137. printf (" eTSEC3 is in sgmii mode.\n");
  138. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII4_DIS))
  139. printf (" eTSEC4 is in sgmii mode.\n");
  140. #ifdef CONFIG_PCIE3
  141. {
  142. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE3_ADDR;
  143. extern void fsl_pci_init(struct pci_controller *hose);
  144. struct pci_controller *hose = &pcie3_hose;
  145. int pcie_ep = (host_agent == 0) || (host_agent == 3) ||
  146. (host_agent == 5) || (host_agent == 6);
  147. int pcie_configured = io_sel >= 1;
  148. u32 temp32;
  149. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  150. printf ("\n PCIE3 connected to ULI as %s (base address %x)",
  151. pcie_ep ? "End Point" : "Root Complex",
  152. (uint)pci);
  153. if (pci->pme_msg_det) {
  154. pci->pme_msg_det = 0xffffffff;
  155. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  156. }
  157. printf ("\n");
  158. /* inbound */
  159. pci_set_region(hose->regions + 0,
  160. CFG_PCI_MEMORY_BUS,
  161. CFG_PCI_MEMORY_PHYS,
  162. CFG_PCI_MEMORY_SIZE,
  163. PCI_REGION_MEM | PCI_REGION_MEMORY);
  164. /* outbound memory */
  165. pci_set_region(hose->regions + 1,
  166. CFG_PCIE3_MEM_BASE,
  167. CFG_PCIE3_MEM_PHYS,
  168. CFG_PCIE3_MEM_SIZE,
  169. PCI_REGION_MEM);
  170. /* outbound io */
  171. pci_set_region(hose->regions + 2,
  172. CFG_PCIE3_IO_BASE,
  173. CFG_PCIE3_IO_PHYS,
  174. CFG_PCIE3_IO_SIZE,
  175. PCI_REGION_IO);
  176. hose->region_count = 3;
  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. * Device 1d has the first on-board memory BAR.
  187. */
  188. pci_hose_read_config_dword(hose, PCI_BDF(2, 0x1d, 0 ),
  189. PCI_BASE_ADDRESS_1, &temp32);
  190. if (temp32 >= CFG_PCIE3_MEM_PHYS) {
  191. debug(" uli1572 read to %x\n", temp32);
  192. in_be32((unsigned *)temp32);
  193. }
  194. } else {
  195. printf (" PCIE3: disabled\n");
  196. }
  197. }
  198. #else
  199. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  200. #endif
  201. #ifdef CONFIG_PCIE2
  202. {
  203. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  204. extern void fsl_pci_init(struct pci_controller *hose);
  205. struct pci_controller *hose = &pcie2_hose;
  206. int pcie_ep = (host_agent == 2) || (host_agent == 4) ||
  207. (host_agent == 6);
  208. int pcie_configured = io_sel & 4;
  209. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  210. printf ("\n PCIE2 connected to Slot 1 as %s (base address %x)",
  211. pcie_ep ? "End Point" : "Root Complex",
  212. (uint)pci);
  213. if (pci->pme_msg_det) {
  214. pci->pme_msg_det = 0xffffffff;
  215. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  216. }
  217. printf ("\n");
  218. /* inbound */
  219. pci_set_region(hose->regions + 0,
  220. CFG_PCI_MEMORY_BUS,
  221. CFG_PCI_MEMORY_PHYS,
  222. CFG_PCI_MEMORY_SIZE,
  223. PCI_REGION_MEM | PCI_REGION_MEMORY);
  224. /* outbound memory */
  225. pci_set_region(hose->regions + 1,
  226. CFG_PCIE2_MEM_BASE,
  227. CFG_PCIE2_MEM_PHYS,
  228. CFG_PCIE2_MEM_SIZE,
  229. PCI_REGION_MEM);
  230. /* outbound io */
  231. pci_set_region(hose->regions + 2,
  232. CFG_PCIE2_IO_BASE,
  233. CFG_PCIE2_IO_PHYS,
  234. CFG_PCIE2_IO_SIZE,
  235. PCI_REGION_IO);
  236. hose->region_count = 3;
  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 (" PCIE2 on bus %02x - %02x\n",
  242. hose->first_busno,hose->last_busno);
  243. } else {
  244. printf (" PCIE2: disabled\n");
  245. }
  246. }
  247. #else
  248. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  249. #endif
  250. #ifdef CONFIG_PCIE1
  251. {
  252. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  253. extern void fsl_pci_init(struct pci_controller *hose);
  254. struct pci_controller *hose = &pcie1_hose;
  255. int pcie_ep = (host_agent == 1) || (host_agent == 4) ||
  256. (host_agent == 5);
  257. int pcie_configured = io_sel & 6;
  258. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  259. printf ("\n PCIE1 connected to Slot 2 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_PCIE1_MEM_BASE,
  276. CFG_PCIE1_MEM_PHYS,
  277. CFG_PCIE1_MEM_SIZE,
  278. PCI_REGION_MEM);
  279. /* outbound io */
  280. pci_set_region(hose->regions + 2,
  281. CFG_PCIE1_IO_BASE,
  282. CFG_PCIE1_IO_PHYS,
  283. CFG_PCIE1_IO_SIZE,
  284. PCI_REGION_IO);
  285. hose->region_count = 3;
  286. hose->first_busno=first_free_busno;
  287. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  288. fsl_pci_init(hose);
  289. first_free_busno=hose->last_busno+1;
  290. printf(" PCIE1 on bus %02x - %02x\n",
  291. hose->first_busno,hose->last_busno);
  292. } else {
  293. printf (" PCIE1: disabled\n");
  294. }
  295. }
  296. #else
  297. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  298. #endif
  299. }
  300. #endif
  301. int board_early_init_r(void)
  302. {
  303. unsigned int i;
  304. const unsigned int flashbase = CFG_FLASH_BASE;
  305. const u8 flash_esel = 2;
  306. /*
  307. * Remap Boot flash + PROMJET region to caching-inhibited
  308. * so that flash can be erased properly.
  309. */
  310. /* Invalidate any remaining lines of the flash from caches. */
  311. for (i = 0; i < 256*1024*1024; i+=32) {
  312. asm volatile ("dcbi %0,%1": : "b" (flashbase), "r" (i));
  313. asm volatile ("icbi %0,%1": : "b" (flashbase), "r" (i));
  314. }
  315. /* invalidate existing TLB entry for flash + promjet */
  316. disable_tlb(flash_esel);
  317. set_tlb(1, flashbase, flashbase, /* tlb, epn, rpn */
  318. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
  319. 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */
  320. return 0;
  321. }
  322. #ifdef CONFIG_GET_CLK_FROM_ICS307
  323. /* decode S[0-2] to Output Divider (OD) */
  324. static unsigned char ics307_S_to_OD[] = {
  325. 10, 2, 8, 4, 5, 7, 3, 6
  326. };
  327. /* Calculate frequency being generated by ICS307-02 clock chip based upon
  328. * the control bytes being programmed into it. */
  329. /* XXX: This function should probably go into a common library */
  330. static unsigned long
  331. ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2)
  332. {
  333. const unsigned long InputFrequency = CONFIG_ICS307_REFCLK_HZ;
  334. unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
  335. unsigned long RDW = cw2 & 0x7F;
  336. unsigned long OD = ics307_S_to_OD[cw0 & 0x7];
  337. unsigned long freq;
  338. /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */
  339. /* cw0: C1 C0 TTL F1 F0 S2 S1 S0
  340. * cw1: V8 V7 V6 V5 V4 V3 V2 V1
  341. * cw2: V0 R6 R5 R4 R3 R2 R1 R0
  342. *
  343. * R6:R0 = Reference Divider Word (RDW)
  344. * V8:V0 = VCO Divider Word (VDW)
  345. * S2:S0 = Output Divider Select (OD)
  346. * F1:F0 = Function of CLK2 Output
  347. * TTL = duty cycle
  348. * C1:C0 = internal load capacitance for cyrstal
  349. */
  350. /* Adding 1 to get a "nicely" rounded number, but this needs
  351. * more tweaking to get a "properly" rounded number. */
  352. freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD));
  353. debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2,
  354. freq);
  355. return freq;
  356. }
  357. unsigned long get_board_sys_clk(ulong dummy)
  358. {
  359. return ics307_clk_freq (
  360. in8(PIXIS_BASE + PIXIS_VSYSCLK0),
  361. in8(PIXIS_BASE + PIXIS_VSYSCLK1),
  362. in8(PIXIS_BASE + PIXIS_VSYSCLK2)
  363. );
  364. }
  365. unsigned long get_board_ddr_clk(ulong dummy)
  366. {
  367. return ics307_clk_freq (
  368. in8(PIXIS_BASE + PIXIS_VDDRCLK0),
  369. in8(PIXIS_BASE + PIXIS_VDDRCLK1),
  370. in8(PIXIS_BASE + PIXIS_VDDRCLK2)
  371. );
  372. }
  373. #else
  374. unsigned long get_board_sys_clk(ulong dummy)
  375. {
  376. u8 i;
  377. ulong val = 0;
  378. i = in8(PIXIS_BASE + PIXIS_SPD);
  379. i &= 0x07;
  380. switch (i) {
  381. case 0:
  382. val = 33333333;
  383. break;
  384. case 1:
  385. val = 40000000;
  386. break;
  387. case 2:
  388. val = 50000000;
  389. break;
  390. case 3:
  391. val = 66666666;
  392. break;
  393. case 4:
  394. val = 83333333;
  395. break;
  396. case 5:
  397. val = 100000000;
  398. break;
  399. case 6:
  400. val = 133333333;
  401. break;
  402. case 7:
  403. val = 166666666;
  404. break;
  405. }
  406. return val;
  407. }
  408. unsigned long get_board_ddr_clk(ulong dummy)
  409. {
  410. u8 i;
  411. ulong val = 0;
  412. i = in8(PIXIS_BASE + PIXIS_SPD);
  413. i &= 0x38;
  414. i >>= 3;
  415. switch (i) {
  416. case 0:
  417. val = 33333333;
  418. break;
  419. case 1:
  420. val = 40000000;
  421. break;
  422. case 2:
  423. val = 50000000;
  424. break;
  425. case 3:
  426. val = 66666666;
  427. break;
  428. case 4:
  429. val = 83333333;
  430. break;
  431. case 5:
  432. val = 100000000;
  433. break;
  434. case 6:
  435. val = 133333333;
  436. break;
  437. case 7:
  438. val = 166666666;
  439. break;
  440. }
  441. return val;
  442. }
  443. #endif
  444. #if defined(CONFIG_OF_BOARD_SETUP)
  445. void ft_board_setup(void *blob, bd_t *bd)
  446. {
  447. int node, tmp[2];
  448. const char *path;
  449. ulong base, size;
  450. ft_cpu_setup(blob, bd);
  451. base = getenv_bootm_low();
  452. size = getenv_bootm_size();
  453. fdt_fixup_memory(blob, (u64)base, (u64)size);
  454. node = fdt_path_offset(blob, "/aliases");
  455. tmp[0] = 0;
  456. if (node >= 0) {
  457. #ifdef CONFIG_PCIE3
  458. path = fdt_getprop(blob, node, "pci0", 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. #ifdef CONFIG_PCIE2
  465. path = fdt_getprop(blob, node, "pci1", NULL);
  466. if (path) {
  467. tmp[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
  468. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  469. }
  470. #endif
  471. #ifdef CONFIG_PCIE1
  472. path = fdt_getprop(blob, node, "pci2", NULL);
  473. if (path) {
  474. tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  475. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  476. }
  477. #endif
  478. }
  479. }
  480. #endif
  481. #ifdef CONFIG_MP
  482. extern void cpu_mp_lmb_reserve(struct lmb *lmb);
  483. void board_lmb_reserve(struct lmb *lmb)
  484. {
  485. cpu_mp_lmb_reserve(lmb);
  486. }
  487. #endif