p2020ds.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright 2007-2012 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <pci.h>
  9. #include <asm/processor.h>
  10. #include <asm/mmu.h>
  11. #include <asm/cache.h>
  12. #include <asm/immap_85xx.h>
  13. #include <asm/fsl_pci.h>
  14. #include <fsl_ddr_sdram.h>
  15. #include <asm/io.h>
  16. #include <asm/fsl_serdes.h>
  17. #include <miiphy.h>
  18. #include <libfdt.h>
  19. #include <fdt_support.h>
  20. #include <fsl_mdio.h>
  21. #include <tsec.h>
  22. #include <asm/fsl_law.h>
  23. #include <netdev.h>
  24. #include "../common/ngpixis.h"
  25. #include "../common/sgmii_riser.h"
  26. DECLARE_GLOBAL_DATA_PTR;
  27. int board_early_init_f(void)
  28. {
  29. #ifdef CONFIG_MMC
  30. ccsr_gur_t *gur = (ccsr_gur_t *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  31. setbits_be32(&gur->pmuxcr,
  32. (MPC85xx_PMUXCR_SDHC_CD |
  33. MPC85xx_PMUXCR_SDHC_WP));
  34. #endif
  35. return 0;
  36. }
  37. int checkboard(void)
  38. {
  39. u8 sw;
  40. printf("Board: P2020DS Sys ID: 0x%02x, "
  41. "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
  42. in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
  43. sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
  44. sw = (sw & PIXIS_LBMAP_MASK) >> PIXIS_LBMAP_SHIFT;
  45. if (sw < 0x8)
  46. /* The lower two bits are the actual vbank number */
  47. printf("vBank: %d\n", sw & 3);
  48. else
  49. puts("Promjet\n");
  50. return 0;
  51. }
  52. #if !defined(CONFIG_DDR_SPD)
  53. /*
  54. * Fixed sdram init -- doesn't use serial presence detect.
  55. */
  56. phys_size_t fixed_sdram(void)
  57. {
  58. struct ccsr_ddr __iomem *ddr =
  59. (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
  60. uint d_init;
  61. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  62. ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  63. ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  64. ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
  65. ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
  66. ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTRL;
  67. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  68. ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
  69. ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
  70. ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
  71. ddr->ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CNTL;
  72. ddr->ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CNTL;
  73. ddr->ddr_cdr1 = CONFIG_SYS_DDR_CDR1;
  74. ddr->timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4;
  75. ddr->timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5;
  76. if (!strcmp("performance", getenv("perf_mode"))) {
  77. /* Performance Mode Values */
  78. ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG_PERF;
  79. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS_PERF;
  80. ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS_PERF;
  81. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1_PERF;
  82. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2_PERF;
  83. asm("sync;isync");
  84. udelay(500);
  85. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL_PERF;
  86. } else {
  87. /* Stable Mode Values */
  88. ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG;
  89. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  90. ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS;
  91. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  92. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  93. /* ECC will be assumed in stable mode */
  94. ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
  95. ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
  96. ddr->err_sbe = CONFIG_SYS_DDR_SBE;
  97. asm("sync;isync");
  98. udelay(500);
  99. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  100. }
  101. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  102. d_init = 1;
  103. debug("DDR - 1st controller: memory initializing\n");
  104. /*
  105. * Poll until memory is initialized.
  106. * 512 Meg at 400 might hit this 200 times or so.
  107. */
  108. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
  109. udelay(1000);
  110. debug("DDR: memory initialized\n\n");
  111. asm("sync; isync");
  112. udelay(500);
  113. #endif
  114. if (set_ddr_laws(CONFIG_SYS_DDR_SDRAM_BASE,
  115. CONFIG_SYS_SDRAM_SIZE * 1024 * 1024,
  116. LAW_TRGT_IF_DDR) < 0) {
  117. printf("ERROR setting Local Access Windows for DDR\n");
  118. return 0;
  119. };
  120. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  121. }
  122. #endif
  123. #ifdef CONFIG_PCI
  124. void pci_init_board(void)
  125. {
  126. fsl_pcie_init_board(0);
  127. }
  128. #endif
  129. int board_early_init_r(void)
  130. {
  131. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  132. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  133. /*
  134. * Remap Boot flash + PROMJET region to caching-inhibited
  135. * so that flash can be erased properly.
  136. */
  137. /* Flush d-cache and invalidate i-cache of any FLASH data */
  138. flush_dcache();
  139. invalidate_icache();
  140. if (flash_esel == -1) {
  141. /* very unlikely unless something is messed up */
  142. puts("Error: Could not find TLB for FLASH BASE\n");
  143. flash_esel = 2; /* give our best effort to continue */
  144. } else {
  145. /* invalidate existing TLB entry for flash + promjet */
  146. disable_tlb(flash_esel);
  147. }
  148. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  149. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  150. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  151. return 0;
  152. }
  153. #ifdef CONFIG_TSEC_ENET
  154. int board_eth_init(bd_t *bis)
  155. {
  156. struct fsl_pq_mdio_info mdio_info;
  157. struct tsec_info_struct tsec_info[4];
  158. int num = 0;
  159. #ifdef CONFIG_TSEC1
  160. SET_STD_TSEC_INFO(tsec_info[num], 1);
  161. num++;
  162. #endif
  163. #ifdef CONFIG_TSEC2
  164. SET_STD_TSEC_INFO(tsec_info[num], 2);
  165. if (is_serdes_configured(SGMII_TSEC2)) {
  166. puts("eTSEC2 is in sgmii mode.\n");
  167. tsec_info[num].flags |= TSEC_SGMII;
  168. }
  169. num++;
  170. #endif
  171. #ifdef CONFIG_TSEC3
  172. SET_STD_TSEC_INFO(tsec_info[num], 3);
  173. if (is_serdes_configured(SGMII_TSEC3)) {
  174. puts("eTSEC3 is in sgmii mode.\n");
  175. tsec_info[num].flags |= TSEC_SGMII;
  176. }
  177. num++;
  178. #endif
  179. if (!num) {
  180. printf("No TSECs initialized\n");
  181. return 0;
  182. }
  183. #ifdef CONFIG_FSL_SGMII_RISER
  184. fsl_sgmii_riser_init(tsec_info, num);
  185. #endif
  186. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  187. mdio_info.name = DEFAULT_MII_NAME;
  188. fsl_pq_mdio_init(bis, &mdio_info);
  189. tsec_eth_init(bis, tsec_info, num);
  190. return pci_eth_init(bis);
  191. }
  192. #endif
  193. #if defined(CONFIG_OF_BOARD_SETUP)
  194. int ft_board_setup(void *blob, bd_t *bd)
  195. {
  196. phys_addr_t base;
  197. phys_size_t size;
  198. ft_cpu_setup(blob, bd);
  199. base = getenv_bootm_low();
  200. size = getenv_bootm_size();
  201. fdt_fixup_memory(blob, (u64)base, (u64)size);
  202. #ifdef CONFIG_HAS_FSL_DR_USB
  203. fdt_fixup_dr_usb(blob, bd);
  204. #endif
  205. FT_FSL_PCI_SETUP;
  206. #ifdef CONFIG_FSL_SGMII_RISER
  207. fsl_sgmii_riser_fdt_fixup(blob);
  208. #endif
  209. return 0;
  210. }
  211. #endif