mpc8569mds.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. /* UCC_1_RGMII */
  45. {2, 11, 2, 0, 1}, /* CLK12 */
  46. {0, 0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0 */
  47. {0, 1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1 */
  48. {0, 2, 1, 0, 1}, /* ENET1_TXD2_SER1_TXD2 */
  49. {0, 3, 1, 0, 2}, /* ENET1_TXD3_SER1_TXD3 */
  50. {0, 6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0 */
  51. {0, 7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1 */
  52. {0, 8, 2, 0, 2}, /* ENET1_RXD2_SER1_RXD2 */
  53. {0, 9, 2, 0, 2}, /* ENET1_RXD3_SER1_RXD3 */
  54. {0, 4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
  55. {0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B */
  56. {2, 8, 2, 0, 1}, /* ENET1_GRXCLK */
  57. {2, 20, 1, 0, 2}, /* ENET1_GTXCLK */
  58. /* UCC_2_RGMII */
  59. {2, 16, 2, 0, 3}, /* CLK17 */
  60. {0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0 */
  61. {0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1 */
  62. {0, 16, 1, 0, 1}, /* ENET2_TXD2_SER2_TXD2 */
  63. {0, 17, 1, 0, 1}, /* ENET2_TXD3_SER2_TXD3 */
  64. {0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0 */
  65. {0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1 */
  66. {0, 22, 2, 0, 1}, /* ENET2_RXD2_SER2_RXD2 */
  67. {0, 23, 2, 0, 1}, /* ENET2_RXD3_SER2_RXD3 */
  68. {0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B */
  69. {0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B */
  70. {2, 3, 2, 0, 1}, /* ENET2_GRXCLK */
  71. {2, 2, 1, 0, 2}, /* ENET2_GTXCLK */
  72. /* UART1 is muxed with QE PortF bit [9-12].*/
  73. {5, 12, 2, 0, 3}, /* UART1_SIN */
  74. {5, 9, 1, 0, 3}, /* UART1_SOUT */
  75. {5, 10, 2, 0, 3}, /* UART1_CTS_B */
  76. {5, 11, 1, 0, 2}, /* UART1_RTS_B */
  77. {0, 0, 0, 0, QE_IOP_TAB_END} /* END of table */
  78. };
  79. void local_bus_init(void);
  80. int board_early_init_f (void)
  81. {
  82. /*
  83. * Initialize local bus.
  84. */
  85. local_bus_init ();
  86. enable_8569mds_flash_write();
  87. #ifdef CONFIG_QE
  88. enable_8569mds_qe_mdio();
  89. #endif
  90. #if CONFIG_SYS_I2C2_OFFSET
  91. /* Enable I2C2 signals instead of SD signals */
  92. volatile struct ccsr_gur *gur;
  93. gur = (struct ccsr_gur *)(CONFIG_SYS_IMMR + 0xe0000);
  94. gur->plppar1 &= ~PLPPAR1_I2C_BIT_MASK;
  95. gur->plppar1 |= PLPPAR1_I2C2_VAL;
  96. gur->plpdir1 &= ~PLPDIR1_I2C_BIT_MASK;
  97. gur->plpdir1 |= PLPDIR1_I2C2_VAL;
  98. disable_8569mds_brd_eeprom_write_protect();
  99. #endif
  100. return 0;
  101. }
  102. int checkboard (void)
  103. {
  104. printf ("Board: 8569 MDS\n");
  105. return 0;
  106. }
  107. phys_size_t
  108. initdram(int board_type)
  109. {
  110. long dram_size = 0;
  111. puts("Initializing\n");
  112. #if defined(CONFIG_DDR_DLL)
  113. /*
  114. * Work around to stabilize DDR DLL MSYNC_IN.
  115. * Errata DDR9 seems to have been fixed.
  116. * This is now the workaround for Errata DDR11:
  117. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  118. */
  119. volatile ccsr_gur_t *gur =
  120. (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  121. out_be32(&gur->ddrdllcr, 0x81000000);
  122. udelay(200);
  123. #endif
  124. #ifdef CONFIG_SPD_EEPROM
  125. dram_size = fsl_ddr_sdram();
  126. #else
  127. dram_size = fixed_sdram();
  128. #endif
  129. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  130. dram_size *= 0x100000;
  131. puts(" DDR: ");
  132. return dram_size;
  133. }
  134. #if !defined(CONFIG_SPD_EEPROM)
  135. phys_size_t fixed_sdram(void)
  136. {
  137. volatile ccsr_ddr_t *ddr = (ccsr_ddr_t *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  138. uint d_init;
  139. out_be32(&ddr->cs0_bnds, CONFIG_SYS_DDR_CS0_BNDS);
  140. out_be32(&ddr->cs0_config, CONFIG_SYS_DDR_CS0_CONFIG);
  141. out_be32(&ddr->timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  142. out_be32(&ddr->timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  143. out_be32(&ddr->timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  144. out_be32(&ddr->timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  145. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
  146. out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
  147. out_be32(&ddr->sdram_mode, CONFIG_SYS_DDR_SDRAM_MODE);
  148. out_be32(&ddr->sdram_mode_2, CONFIG_SYS_DDR_SDRAM_MODE_2);
  149. out_be32(&ddr->sdram_interval, CONFIG_SYS_DDR_SDRAM_INTERVAL);
  150. out_be32(&ddr->sdram_data_init, CONFIG_SYS_DDR_DATA_INIT);
  151. out_be32(&ddr->sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
  152. out_be32(&ddr->timing_cfg_4, CONFIG_SYS_DDR_TIMING_4);
  153. out_be32(&ddr->timing_cfg_5, CONFIG_SYS_DDR_TIMING_5);
  154. out_be32(&ddr->ddr_zq_cntl, CONFIG_SYS_DDR_ZQ_CNTL);
  155. out_be32(&ddr->ddr_wrlvl_cntl, CONFIG_SYS_DDR_WRLVL_CNTL);
  156. out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
  157. #if defined (CONFIG_DDR_ECC)
  158. out_be32(&ddr->err_int_en, CONFIG_SYS_DDR_ERR_INT_EN);
  159. out_be32(&ddr->err_disable, CONFIG_SYS_DDR_ERR_DIS);
  160. out_be32(&ddr->err_sbe, CONFIG_SYS_DDR_SBE);
  161. #endif
  162. udelay(500);
  163. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  164. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  165. d_init = 1;
  166. debug("DDR - 1st controller: memory initializing\n");
  167. /*
  168. * Poll until memory is initialized.
  169. * 512 Meg at 400 might hit this 200 times or so.
  170. */
  171. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
  172. udelay(1000);
  173. }
  174. debug("DDR: memory initialized\n\n");
  175. udelay(500);
  176. #endif
  177. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  178. }
  179. #endif
  180. /*
  181. * Initialize Local Bus
  182. */
  183. void
  184. local_bus_init(void)
  185. {
  186. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  187. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  188. uint clkdiv;
  189. uint lbc_hz;
  190. sys_info_t sysinfo;
  191. get_sys_info(&sysinfo);
  192. clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
  193. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  194. out_be32(&gur->lbiuiplldcr1, 0x00078080);
  195. if (clkdiv == 16)
  196. out_be32(&gur->lbiuiplldcr0, 0x7c0f1bf0);
  197. else if (clkdiv == 8)
  198. out_be32(&gur->lbiuiplldcr0, 0x6c0f1bf0);
  199. else if (clkdiv == 4)
  200. out_be32(&gur->lbiuiplldcr0, 0x5c0f1bf0);
  201. out_be32(&lbc->lcrr, (u32)in_be32(&lbc->lcrr)| 0x00030000);
  202. }
  203. #ifdef CONFIG_PCIE1
  204. static struct pci_controller pcie1_hose;
  205. #endif /* CONFIG_PCIE1 */
  206. int first_free_busno = 0;
  207. #ifdef CONFIG_PCI
  208. void
  209. pci_init_board(void)
  210. {
  211. volatile ccsr_gur_t *gur;
  212. uint io_sel;
  213. uint host_agent;
  214. gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  215. io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  216. host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  217. #ifdef CONFIG_PCIE1
  218. {
  219. volatile ccsr_fsl_pci_t *pci;
  220. struct pci_controller *hose;
  221. int pcie_ep;
  222. struct pci_region *r;
  223. int pcie_configured;
  224. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  225. hose = &pcie1_hose;
  226. pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  227. r = hose->regions;
  228. pcie_configured = io_sel >= 1;
  229. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  230. printf ("\n PCIE connected to slot as %s (base address %x)",
  231. pcie_ep ? "End Point" : "Root Complex",
  232. (uint)pci);
  233. if (pci->pme_msg_det) {
  234. pci->pme_msg_det = 0xffffffff;
  235. debug (" with errors. Clearing. Now 0x%08x",
  236. pci->pme_msg_det);
  237. }
  238. printf ("\n");
  239. /* inbound */
  240. r += fsl_pci_setup_inbound_windows(r);
  241. /* outbound memory */
  242. pci_set_region(r++,
  243. CONFIG_SYS_PCIE1_MEM_BUS,
  244. CONFIG_SYS_PCIE1_MEM_PHYS,
  245. CONFIG_SYS_PCIE1_MEM_SIZE,
  246. PCI_REGION_MEM);
  247. /* outbound io */
  248. pci_set_region(r++,
  249. CONFIG_SYS_PCIE1_IO_BUS,
  250. CONFIG_SYS_PCIE1_IO_PHYS,
  251. CONFIG_SYS_PCIE1_IO_SIZE,
  252. PCI_REGION_IO);
  253. hose->region_count = r - hose->regions;
  254. hose->first_busno=first_free_busno;
  255. pci_setup_indirect(hose, (int) &pci->cfg_addr,
  256. (int) &pci->cfg_data);
  257. fsl_pci_init(hose);
  258. printf ("PCIE on bus %02x - %02x\n",
  259. hose->first_busno,hose->last_busno);
  260. first_free_busno=hose->last_busno+1;
  261. } else {
  262. printf (" PCIE: disabled\n");
  263. }
  264. }
  265. #else
  266. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  267. #endif
  268. }
  269. #endif /* CONFIG_PCI */
  270. #if defined(CONFIG_OF_BOARD_SETUP)
  271. void ft_board_setup(void *blob, bd_t *bd)
  272. {
  273. ft_cpu_setup(blob, bd);
  274. #ifdef CONFIG_PCIE1
  275. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  276. #endif
  277. }
  278. #endif