mpc8572ds.c 14 KB

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