p1_twr.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2013 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. #include <hwconfig.h>
  8. #include <pci.h>
  9. #include <i2c.h>
  10. #include <asm/processor.h>
  11. #include <asm/mmu.h>
  12. #include <asm/cache.h>
  13. #include <asm/immap_85xx.h>
  14. #include <asm/fsl_pci.h>
  15. #include <fsl_ddr_sdram.h>
  16. #include <asm/io.h>
  17. #include <asm/fsl_law.h>
  18. #include <asm/fsl_lbc.h>
  19. #include <asm/mp.h>
  20. #include <miiphy.h>
  21. #include <linux/libfdt.h>
  22. #include <fdt_support.h>
  23. #include <fsl_mdio.h>
  24. #include <tsec.h>
  25. #include <ioports.h>
  26. #include <asm/fsl_serdes.h>
  27. #include <netdev.h>
  28. #define SYSCLK_64 64000000
  29. #define SYSCLK_66 66666666
  30. unsigned long get_board_sys_clk(ulong dummy)
  31. {
  32. ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  33. par_io_t *par_io = (par_io_t *) &(gur->qe_par_io);
  34. unsigned int cpdat_val = 0;
  35. /* Set-up up pin muxing based on board switch settings */
  36. cpdat_val = par_io[1].cpdat;
  37. /* Check switch setting for SYSCLK select (PB3) */
  38. if (cpdat_val & 0x10000000)
  39. return SYSCLK_64;
  40. else
  41. return SYSCLK_66;
  42. return 0;
  43. }
  44. #ifdef CONFIG_QE
  45. #define PCA_IOPORT_I2C_ADDR 0x23
  46. #define PCA_IOPORT_OUTPUT_CMD 0x2
  47. #define PCA_IOPORT_CFG_CMD 0x6
  48. const qe_iop_conf_t qe_iop_conf_tab[] = {
  49. #ifdef CONFIG_TWR_P1025
  50. /* GPIO */
  51. {1, 0, 1, 0, 0},
  52. {1, 18, 1, 0, 0},
  53. /* GPIO for switch options */
  54. {1, 2, 2, 0, 0}, /* PROFIBUS_MODE_SEL */
  55. {1, 3, 2, 0, 0}, /* SYS_CLK_SELECT */
  56. {1, 29, 2, 0, 0}, /* LOCALBUS_QE_MUXSEL */
  57. {1, 30, 2, 0, 0}, /* ETH_TDM_SEL */
  58. /* QE_MUX_MDC */
  59. {1, 19, 1, 0, 1}, /* QE_MUX_MDC */
  60. /* QE_MUX_MDIO */
  61. {1, 20, 3, 0, 1}, /* QE_MUX_MDIO */
  62. /* UCC_1_MII */
  63. {0, 23, 2, 0, 2}, /* CLK12 */
  64. {0, 24, 2, 0, 1}, /* CLK9 */
  65. {0, 7, 1, 0, 2}, /* ENET1_TXD0_SER1_TXD0 */
  66. {0, 9, 1, 0, 2}, /* ENET1_TXD1_SER1_TXD1 */
  67. {0, 11, 1, 0, 2}, /* ENET1_TXD2_SER1_TXD2 */
  68. {0, 12, 1, 0, 2}, /* ENET1_TXD3_SER1_TXD3 */
  69. {0, 6, 2, 0, 2}, /* ENET1_RXD0_SER1_RXD0 */
  70. {0, 10, 2, 0, 2}, /* ENET1_RXD1_SER1_RXD1 */
  71. {0, 14, 2, 0, 2}, /* ENET1_RXD2_SER1_RXD2 */
  72. {0, 15, 2, 0, 2}, /* ENET1_RXD3_SER1_RXD3 */
  73. {0, 5, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
  74. {0, 13, 1, 0, 2}, /* ENET1_TX_ER */
  75. {0, 4, 2, 0, 2}, /* ENET1_RX_DV_SER1_CTS_B */
  76. {0, 8, 2, 0, 2}, /* ENET1_RX_ER_SER1_CD_B */
  77. {0, 17, 2, 0, 2}, /* ENET1_CRS */
  78. {0, 16, 2, 0, 2}, /* ENET1_COL */
  79. /* UCC_5_RMII */
  80. {1, 11, 2, 0, 1}, /* CLK13 */
  81. {1, 7, 1, 0, 2}, /* ENET5_TXD0_SER5_TXD0 */
  82. {1, 10, 1, 0, 2}, /* ENET5_TXD1_SER5_TXD1 */
  83. {1, 6, 2, 0, 2}, /* ENET5_RXD0_SER5_RXD0 */
  84. {1, 9, 2, 0, 2}, /* ENET5_RXD1_SER5_RXD1 */
  85. {1, 5, 1, 0, 2}, /* ENET5_TX_EN_SER5_RTS_B */
  86. {1, 4, 2, 0, 2}, /* ENET5_RX_DV_SER5_CTS_B */
  87. {1, 8, 2, 0, 2}, /* ENET5_RX_ER_SER5_CD_B */
  88. /* TDMA - clock option is configured in OS based on board setting */
  89. {1, 23, 2, 0, 2}, /* TDMA_TXD */
  90. {1, 25, 2, 0, 2}, /* TDMA_RXD */
  91. {1, 26, 1, 0, 2}, /* TDMA_SYNC */
  92. #endif
  93. {0, 0, 0, 0, QE_IOP_TAB_END} /* END of table */
  94. };
  95. #endif
  96. int board_early_init_f(void)
  97. {
  98. ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  99. setbits_be32(&gur->pmuxcr,
  100. (MPC85xx_PMUXCR_SDHC_CD | MPC85xx_PMUXCR_SDHC_WP));
  101. /* SDHC_DAT[4:7] not exposed to pins (use as SPI) */
  102. clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
  103. return 0;
  104. }
  105. int checkboard(void)
  106. {
  107. ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  108. u8 boot_status;
  109. printf("Board: %s\n", CONFIG_BOARDNAME);
  110. boot_status = ((gur->porbmsr) >> MPC85xx_PORBMSR_ROMLOC_SHIFT) & 0xf;
  111. puts("rom_loc: ");
  112. if (boot_status == PORBMSR_ROMLOC_NOR)
  113. puts("nor flash");
  114. else if (boot_status == PORBMSR_ROMLOC_SDHC)
  115. puts("sd");
  116. else
  117. puts("unknown");
  118. puts("\n");
  119. return 0;
  120. }
  121. #ifdef CONFIG_PCI
  122. void pci_init_board(void)
  123. {
  124. fsl_pcie_init_board(0);
  125. }
  126. #endif
  127. int board_early_init_r(void)
  128. {
  129. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  130. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  131. /*
  132. * Remap Boot flash region to caching-inhibited
  133. * so that flash can be erased properly.
  134. */
  135. /* Flush d-cache and invalidate i-cache of any FLASH data */
  136. flush_dcache();
  137. invalidate_icache();
  138. if (flash_esel == -1) {
  139. /* very unlikely unless something is messed up */
  140. puts("Error: Could not find TLB for FLASH BASE\n");
  141. flash_esel = 2; /* give our best effort to continue */
  142. } else {
  143. /* invalidate existing TLB entry for flash */
  144. disable_tlb(flash_esel);
  145. }
  146. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
  147. MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
  148. 0, flash_esel, BOOKE_PAGESZ_64M, 1);/* ts, esel, tsize, iprot */
  149. return 0;
  150. }
  151. int board_eth_init(bd_t *bis)
  152. {
  153. struct fsl_pq_mdio_info mdio_info;
  154. struct tsec_info_struct tsec_info[4];
  155. ccsr_gur_t *gur __attribute__((unused)) =
  156. (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  157. int num = 0;
  158. #ifdef CONFIG_TSEC1
  159. SET_STD_TSEC_INFO(tsec_info[num], 1);
  160. num++;
  161. #endif
  162. #ifdef CONFIG_TSEC2
  163. SET_STD_TSEC_INFO(tsec_info[num], 2);
  164. if (is_serdes_configured(SGMII_TSEC2)) {
  165. printf("eTSEC2 is in sgmii mode.\n");
  166. tsec_info[num].flags |= TSEC_SGMII;
  167. }
  168. num++;
  169. #endif
  170. #ifdef CONFIG_TSEC3
  171. SET_STD_TSEC_INFO(tsec_info[num], 3);
  172. num++;
  173. #endif
  174. if (!num) {
  175. printf("No TSECs initialized\n");
  176. return 0;
  177. }
  178. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  179. mdio_info.name = DEFAULT_MII_NAME;
  180. fsl_pq_mdio_init(bis, &mdio_info);
  181. tsec_eth_init(bis, tsec_info, num);
  182. #if defined(CONFIG_UEC_ETH)
  183. /* QE0 and QE3 need to be exposed for UCC1
  184. * and UCC5 Eth mode (in PMUXCR register).
  185. * Currently QE/LBC muxed pins assumed to be
  186. * LBC for U-Boot and PMUXCR updated by OS if required */
  187. uec_standard_init(bis);
  188. #endif
  189. return pci_eth_init(bis);
  190. }
  191. #if defined(CONFIG_QE)
  192. static void fdt_board_fixup_qe_pins(void *blob)
  193. {
  194. int node;
  195. if (!hwconfig("qe")) {
  196. /* For QE and eLBC pins multiplexing,
  197. * When don't use QE function, remove
  198. * qe node from dt blob.
  199. */
  200. node = fdt_path_offset(blob, "/qe");
  201. if (node >= 0)
  202. fdt_del_node(blob, node);
  203. } else {
  204. /* For TWR Peripheral Modules - TWR-SER2
  205. * board only can support Signal Port MII,
  206. * so delete one UEC node when use MII port.
  207. */
  208. if (hwconfig("mii"))
  209. node = fdt_path_offset(blob, "/qe/ucc@2400");
  210. else
  211. node = fdt_path_offset(blob, "/qe/ucc@2000");
  212. if (node >= 0)
  213. fdt_del_node(blob, node);
  214. }
  215. return;
  216. }
  217. #endif
  218. #ifdef CONFIG_OF_BOARD_SETUP
  219. int ft_board_setup(void *blob, bd_t *bd)
  220. {
  221. phys_addr_t base;
  222. phys_size_t size;
  223. ft_cpu_setup(blob, bd);
  224. base = env_get_bootm_low();
  225. size = env_get_bootm_size();
  226. fdt_fixup_memory(blob, (u64)base, (u64)size);
  227. FT_FSL_PCI_SETUP;
  228. #ifdef CONFIG_QE
  229. do_fixup_by_compat(blob, "fsl,qe", "status", "okay",
  230. sizeof("okay"), 0);
  231. #endif
  232. #if defined(CONFIG_TWR_P1025)
  233. fdt_board_fixup_qe_pins(blob);
  234. #endif
  235. fsl_fdt_fixup_dr_usb(blob, bd);
  236. return 0;
  237. }
  238. #endif