mpc8569mds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * Copyright 2009 Freescale Semiconductor.
  3. *
  4. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/fsl_pci.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <asm/io.h>
  32. #include <spd_sdram.h>
  33. #include <i2c.h>
  34. #include <ioports.h>
  35. #include <libfdt.h>
  36. #include <fdt_support.h>
  37. #include "bcsr.h"
  38. phys_size_t fixed_sdram(void);
  39. const qe_iop_conf_t qe_iop_conf_tab[] = {
  40. /* QE_MUX_MDC */
  41. {2, 31, 1, 0, 1}, /* QE_MUX_MDC */
  42. /* QE_MUX_MDIO */
  43. {2, 30, 3, 0, 2}, /* QE_MUX_MDIO */
  44. #if defined(CONFIG_SYS_UCC_RGMII_MODE)
  45. /* UCC_1_RGMII */
  46. {2, 11, 2, 0, 1}, /* CLK12 */
  47. {0, 0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0 */
  48. {0, 1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1 */
  49. {0, 2, 1, 0, 1}, /* ENET1_TXD2_SER1_TXD2 */
  50. {0, 3, 1, 0, 2}, /* ENET1_TXD3_SER1_TXD3 */
  51. {0, 6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0 */
  52. {0, 7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1 */
  53. {0, 8, 2, 0, 2}, /* ENET1_RXD2_SER1_RXD2 */
  54. {0, 9, 2, 0, 2}, /* ENET1_RXD3_SER1_RXD3 */
  55. {0, 4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
  56. {0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B */
  57. {2, 8, 2, 0, 1}, /* ENET1_GRXCLK */
  58. {2, 20, 1, 0, 2}, /* ENET1_GTXCLK */
  59. /* UCC_2_RGMII */
  60. {2, 16, 2, 0, 3}, /* CLK17 */
  61. {0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0 */
  62. {0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1 */
  63. {0, 16, 1, 0, 1}, /* ENET2_TXD2_SER2_TXD2 */
  64. {0, 17, 1, 0, 1}, /* ENET2_TXD3_SER2_TXD3 */
  65. {0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0 */
  66. {0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1 */
  67. {0, 22, 2, 0, 1}, /* ENET2_RXD2_SER2_RXD2 */
  68. {0, 23, 2, 0, 1}, /* ENET2_RXD3_SER2_RXD3 */
  69. {0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B */
  70. {0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B */
  71. {2, 3, 2, 0, 1}, /* ENET2_GRXCLK */
  72. {2, 2, 1, 0, 2}, /* ENET2_GTXCLK */
  73. /* UCC_3_RGMII */
  74. {2, 11, 2, 0, 1}, /* CLK12 */
  75. {0, 29, 1, 0, 2}, /* ENET3_TXD0_SER3_TXD0 */
  76. {0, 30, 1, 0, 3}, /* ENET3_TXD1_SER3_TXD1 */
  77. {0, 31, 1, 0, 2}, /* ENET3_TXD2_SER3_TXD2 */
  78. {1, 0, 1, 0, 3}, /* ENET3_TXD3_SER3_TXD3 */
  79. {1, 3, 2, 0, 3}, /* ENET3_RXD0_SER3_RXD0 */
  80. {1, 4, 2, 0, 1}, /* ENET3_RXD1_SER3_RXD1 */
  81. {1, 5, 2, 0, 2}, /* ENET3_RXD2_SER3_RXD2 */
  82. {1, 6, 2, 0, 3}, /* ENET3_RXD3_SER3_RXD3 */
  83. {1, 1, 1, 0, 1}, /* ENET3_TX_EN_SER3_RTS_B */
  84. {1, 9, 2, 0, 3}, /* ENET3_RX_DV_SER3_CTS_B */
  85. {2, 9, 2, 0, 2}, /* ENET3_GRXCLK */
  86. {2, 25, 1, 0, 2}, /* ENET3_GTXCLK */
  87. /* UCC_4_RGMII */
  88. {2, 16, 2, 0, 3}, /* CLK17 */
  89. {1, 12, 1, 0, 2}, /* ENET4_TXD0_SER4_TXD0 */
  90. {1, 13, 1, 0, 2}, /* ENET4_TXD1_SER4_TXD1 */
  91. {1, 14, 1, 0, 1}, /* ENET4_TXD2_SER4_TXD2 */
  92. {1, 15, 1, 0, 2}, /* ENET4_TXD3_SER4_TXD3 */
  93. {1, 18, 2, 0, 2}, /* ENET4_RXD0_SER4_RXD0 */
  94. {1, 19, 2, 0, 1}, /* ENET4_RXD1_SER4_RXD1 */
  95. {1, 20, 2, 0, 1}, /* ENET4_RXD2_SER4_RXD2 */
  96. {1, 21, 2, 0, 2}, /* ENET4_RXD3_SER4_RXD3 */
  97. {1, 16, 1, 0, 2}, /* ENET4_TX_EN_SER4_RTS_B */
  98. {1, 24, 2, 0, 3}, /* ENET4_RX_DV_SER4_CTS_B */
  99. {2, 17, 2, 0, 2}, /* ENET4_GRXCLK */
  100. {2, 24, 1, 0, 2}, /* ENET4_GTXCLK */
  101. #elif defined(CONFIG_SYS_UCC_RMII_MODE)
  102. /* UCC_1_RMII */
  103. {2, 15, 2, 0, 1}, /* CLK16 */
  104. {0, 0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0 */
  105. {0, 1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1 */
  106. {0, 6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0 */
  107. {0, 7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1 */
  108. {0, 4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
  109. {0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B */
  110. /* UCC_2_RMII */
  111. {2, 15, 2, 0, 1}, /* CLK16 */
  112. {0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0 */
  113. {0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1 */
  114. {0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0 */
  115. {0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1 */
  116. {0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B */
  117. {0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B */
  118. /* UCC_3_RMII */
  119. {2, 15, 2, 0, 1}, /* CLK16 */
  120. {0, 29, 1, 0, 2}, /* ENET3_TXD0_SER3_TXD0 */
  121. {0, 30, 1, 0, 3}, /* ENET3_TXD1_SER3_TXD1 */
  122. {1, 3, 2, 0, 3}, /* ENET3_RXD0_SER3_RXD0 */
  123. {1, 4, 2, 0, 1}, /* ENET3_RXD1_SER3_RXD1 */
  124. {1, 1, 1, 0, 1}, /* ENET3_TX_EN_SER3_RTS_B */
  125. {1, 9, 2, 0, 3}, /* ENET3_RX_DV_SER3_CTS_B */
  126. /* UCC_4_RMII */
  127. {2, 15, 2, 0, 1}, /* CLK16 */
  128. {1, 12, 1, 0, 2}, /* ENET4_TXD0_SER4_TXD0 */
  129. {1, 13, 1, 0, 2}, /* ENET4_TXD1_SER4_TXD1 */
  130. {1, 18, 2, 0, 2}, /* ENET4_RXD0_SER4_RXD0 */
  131. {1, 19, 2, 0, 1}, /* ENET4_RXD1_SER4_RXD1 */
  132. {1, 16, 1, 0, 2}, /* ENET4_TX_EN_SER4_RTS_B */
  133. {1, 24, 2, 0, 3}, /* ENET4_RX_DV_SER4_CTS_B */
  134. #endif
  135. /* UART1 is muxed with QE PortF bit [9-12].*/
  136. {5, 12, 2, 0, 3}, /* UART1_SIN */
  137. {5, 9, 1, 0, 3}, /* UART1_SOUT */
  138. {5, 10, 2, 0, 3}, /* UART1_CTS_B */
  139. {5, 11, 1, 0, 2}, /* UART1_RTS_B */
  140. {0, 0, 0, 0, QE_IOP_TAB_END} /* END of table */
  141. };
  142. void local_bus_init(void);
  143. int board_early_init_f (void)
  144. {
  145. /*
  146. * Initialize local bus.
  147. */
  148. local_bus_init ();
  149. enable_8569mds_flash_write();
  150. #ifdef CONFIG_QE
  151. enable_8569mds_qe_uec();
  152. #endif
  153. #if CONFIG_SYS_I2C2_OFFSET
  154. /* Enable I2C2 signals instead of SD signals */
  155. volatile struct ccsr_gur *gur;
  156. gur = (struct ccsr_gur *)(CONFIG_SYS_IMMR + 0xe0000);
  157. gur->plppar1 &= ~PLPPAR1_I2C_BIT_MASK;
  158. gur->plppar1 |= PLPPAR1_I2C2_VAL;
  159. gur->plpdir1 &= ~PLPDIR1_I2C_BIT_MASK;
  160. gur->plpdir1 |= PLPDIR1_I2C2_VAL;
  161. disable_8569mds_brd_eeprom_write_protect();
  162. #endif
  163. return 0;
  164. }
  165. int checkboard (void)
  166. {
  167. printf ("Board: 8569 MDS\n");
  168. return 0;
  169. }
  170. phys_size_t
  171. initdram(int board_type)
  172. {
  173. long dram_size = 0;
  174. puts("Initializing\n");
  175. #if defined(CONFIG_DDR_DLL)
  176. /*
  177. * Work around to stabilize DDR DLL MSYNC_IN.
  178. * Errata DDR9 seems to have been fixed.
  179. * This is now the workaround for Errata DDR11:
  180. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  181. */
  182. volatile ccsr_gur_t *gur =
  183. (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  184. out_be32(&gur->ddrdllcr, 0x81000000);
  185. udelay(200);
  186. #endif
  187. #ifdef CONFIG_SPD_EEPROM
  188. dram_size = fsl_ddr_sdram();
  189. #else
  190. dram_size = fixed_sdram();
  191. #endif
  192. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  193. dram_size *= 0x100000;
  194. puts(" DDR: ");
  195. return dram_size;
  196. }
  197. #if !defined(CONFIG_SPD_EEPROM)
  198. phys_size_t fixed_sdram(void)
  199. {
  200. volatile ccsr_ddr_t *ddr = (ccsr_ddr_t *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  201. uint d_init;
  202. out_be32(&ddr->cs0_bnds, CONFIG_SYS_DDR_CS0_BNDS);
  203. out_be32(&ddr->cs0_config, CONFIG_SYS_DDR_CS0_CONFIG);
  204. out_be32(&ddr->timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  205. out_be32(&ddr->timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  206. out_be32(&ddr->timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  207. out_be32(&ddr->timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  208. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
  209. out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
  210. out_be32(&ddr->sdram_mode, CONFIG_SYS_DDR_SDRAM_MODE);
  211. out_be32(&ddr->sdram_mode_2, CONFIG_SYS_DDR_SDRAM_MODE_2);
  212. out_be32(&ddr->sdram_interval, CONFIG_SYS_DDR_SDRAM_INTERVAL);
  213. out_be32(&ddr->sdram_data_init, CONFIG_SYS_DDR_DATA_INIT);
  214. out_be32(&ddr->sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
  215. out_be32(&ddr->timing_cfg_4, CONFIG_SYS_DDR_TIMING_4);
  216. out_be32(&ddr->timing_cfg_5, CONFIG_SYS_DDR_TIMING_5);
  217. out_be32(&ddr->ddr_zq_cntl, CONFIG_SYS_DDR_ZQ_CNTL);
  218. out_be32(&ddr->ddr_wrlvl_cntl, CONFIG_SYS_DDR_WRLVL_CNTL);
  219. out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
  220. #if defined (CONFIG_DDR_ECC)
  221. out_be32(&ddr->err_int_en, CONFIG_SYS_DDR_ERR_INT_EN);
  222. out_be32(&ddr->err_disable, CONFIG_SYS_DDR_ERR_DIS);
  223. out_be32(&ddr->err_sbe, CONFIG_SYS_DDR_SBE);
  224. #endif
  225. udelay(500);
  226. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  227. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  228. d_init = 1;
  229. debug("DDR - 1st controller: memory initializing\n");
  230. /*
  231. * Poll until memory is initialized.
  232. * 512 Meg at 400 might hit this 200 times or so.
  233. */
  234. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
  235. udelay(1000);
  236. }
  237. debug("DDR: memory initialized\n\n");
  238. udelay(500);
  239. #endif
  240. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  241. }
  242. #endif
  243. /*
  244. * Initialize Local Bus
  245. */
  246. void
  247. local_bus_init(void)
  248. {
  249. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  250. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  251. uint clkdiv;
  252. uint lbc_hz;
  253. sys_info_t sysinfo;
  254. get_sys_info(&sysinfo);
  255. clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
  256. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  257. out_be32(&gur->lbiuiplldcr1, 0x00078080);
  258. if (clkdiv == 16)
  259. out_be32(&gur->lbiuiplldcr0, 0x7c0f1bf0);
  260. else if (clkdiv == 8)
  261. out_be32(&gur->lbiuiplldcr0, 0x6c0f1bf0);
  262. else if (clkdiv == 4)
  263. out_be32(&gur->lbiuiplldcr0, 0x5c0f1bf0);
  264. out_be32(&lbc->lcrr, (u32)in_be32(&lbc->lcrr)| 0x00030000);
  265. }
  266. #ifdef CONFIG_PCIE1
  267. static struct pci_controller pcie1_hose;
  268. #endif /* CONFIG_PCIE1 */
  269. int first_free_busno = 0;
  270. #ifdef CONFIG_PCI
  271. void
  272. pci_init_board(void)
  273. {
  274. volatile ccsr_gur_t *gur;
  275. uint io_sel;
  276. uint host_agent;
  277. gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  278. io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  279. host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  280. #ifdef CONFIG_PCIE1
  281. {
  282. volatile ccsr_fsl_pci_t *pci;
  283. struct pci_controller *hose;
  284. int pcie_ep;
  285. struct pci_region *r;
  286. int pcie_configured;
  287. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  288. hose = &pcie1_hose;
  289. pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  290. r = hose->regions;
  291. pcie_configured = io_sel >= 1;
  292. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  293. printf ("\n PCIE connected to slot as %s (base address %x)",
  294. pcie_ep ? "End Point" : "Root Complex",
  295. (uint)pci);
  296. if (pci->pme_msg_det) {
  297. pci->pme_msg_det = 0xffffffff;
  298. debug (" with errors. Clearing. Now 0x%08x",
  299. pci->pme_msg_det);
  300. }
  301. printf ("\n");
  302. /* inbound */
  303. r += fsl_pci_setup_inbound_windows(r);
  304. /* outbound memory */
  305. pci_set_region(r++,
  306. CONFIG_SYS_PCIE1_MEM_BUS,
  307. CONFIG_SYS_PCIE1_MEM_PHYS,
  308. CONFIG_SYS_PCIE1_MEM_SIZE,
  309. PCI_REGION_MEM);
  310. /* outbound io */
  311. pci_set_region(r++,
  312. CONFIG_SYS_PCIE1_IO_BUS,
  313. CONFIG_SYS_PCIE1_IO_PHYS,
  314. CONFIG_SYS_PCIE1_IO_SIZE,
  315. PCI_REGION_IO);
  316. hose->region_count = r - hose->regions;
  317. hose->first_busno=first_free_busno;
  318. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  319. printf ("PCIE on bus %02x - %02x\n",
  320. hose->first_busno,hose->last_busno);
  321. first_free_busno=hose->last_busno+1;
  322. } else {
  323. printf (" PCIE: disabled\n");
  324. }
  325. }
  326. #else
  327. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  328. #endif
  329. }
  330. #endif /* CONFIG_PCI */
  331. #if defined(CONFIG_OF_BOARD_SETUP)
  332. void ft_board_setup(void *blob, bd_t *bd)
  333. {
  334. #if defined(CONFIG_SYS_UCC_RMII_MODE)
  335. int nodeoff, off, err;
  336. unsigned int val;
  337. const u32 *ph;
  338. const u32 *index;
  339. /* fixup device tree for supporting rmii mode */
  340. nodeoff = -1;
  341. while ((nodeoff = fdt_node_offset_by_compatible(blob, nodeoff,
  342. "ucc_geth")) >= 0) {
  343. err = fdt_setprop_string(blob, nodeoff, "tx-clock-name",
  344. "clk16");
  345. if (err < 0) {
  346. printf("WARNING: could not set tx-clock-name %s.\n",
  347. fdt_strerror(err));
  348. break;
  349. }
  350. err = fdt_setprop_string(blob, nodeoff, "phy-connection-type",
  351. "rmii");
  352. if (err < 0) {
  353. printf("WARNING: could not set phy-connection-type "
  354. "%s.\n", fdt_strerror(err));
  355. break;
  356. }
  357. index = fdt_getprop(blob, nodeoff, "cell-index", 0);
  358. if (index == NULL) {
  359. printf("WARNING: could not get cell-index of ucc\n");
  360. break;
  361. }
  362. ph = fdt_getprop(blob, nodeoff, "phy-handle", 0);
  363. if (ph == NULL) {
  364. printf("WARNING: could not get phy-handle of ucc\n");
  365. break;
  366. }
  367. off = fdt_node_offset_by_phandle(blob, *ph);
  368. if (off < 0) {
  369. printf("WARNING: could not get phy node %s.\n",
  370. fdt_strerror(err));
  371. break;
  372. }
  373. val = 0x7 + *index; /* RMII phy address starts from 0x8 */
  374. err = fdt_setprop(blob, off, "reg", &val, sizeof(u32));
  375. if (err < 0) {
  376. printf("WARNING: could not set reg for phy-handle "
  377. "%s.\n", fdt_strerror(err));
  378. break;
  379. }
  380. }
  381. #endif
  382. ft_cpu_setup(blob, bd);
  383. #ifdef CONFIG_PCIE1
  384. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  385. #endif
  386. }
  387. #endif