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