ls1012aqds.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2016 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <i2c.h>
  7. #include <fdt_support.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/clock.h>
  10. #include <asm/arch/fsl_serdes.h>
  11. #ifdef CONFIG_FSL_LS_PPA
  12. #include <asm/arch/ppa.h>
  13. #endif
  14. #include <asm/arch/fdt.h>
  15. #include <asm/arch/mmu.h>
  16. #include <asm/arch/soc.h>
  17. #include <ahci.h>
  18. #include <hwconfig.h>
  19. #include <mmc.h>
  20. #include <scsi.h>
  21. #include <fm_eth.h>
  22. #include <fsl_esdhc.h>
  23. #include <fsl_mmdc.h>
  24. #include <spl.h>
  25. #include <netdev.h>
  26. #include "../common/qixis.h"
  27. #include "ls1012aqds_qixis.h"
  28. #include "ls1012aqds_pfe.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. int checkboard(void)
  31. {
  32. char buf[64];
  33. u8 sw;
  34. sw = QIXIS_READ(arch);
  35. printf("Board Arch: V%d, ", sw >> 4);
  36. printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
  37. sw = QIXIS_READ(brdcfg[QIXIS_LBMAP_BRDCFG_REG]);
  38. if (sw & QIXIS_LBMAP_ALTBANK)
  39. printf("flash: 2\n");
  40. else
  41. printf("flash: 1\n");
  42. printf("FPGA: v%d (%s), build %d",
  43. (int)QIXIS_READ(scver), qixis_read_tag(buf),
  44. (int)qixis_read_minor());
  45. /* the timestamp string contains "\n" at the end */
  46. printf(" on %s", qixis_read_time(buf));
  47. return 0;
  48. }
  49. int dram_init(void)
  50. {
  51. static const struct fsl_mmdc_info mparam = {
  52. 0x05180000, /* mdctl */
  53. 0x00030035, /* mdpdc */
  54. 0x12554000, /* mdotc */
  55. 0xbabf7954, /* mdcfg0 */
  56. 0xdb328f64, /* mdcfg1 */
  57. 0x01ff00db, /* mdcfg2 */
  58. 0x00001680, /* mdmisc */
  59. 0x0f3c8000, /* mdref */
  60. 0x00002000, /* mdrwd */
  61. 0x00bf1023, /* mdor */
  62. 0x0000003f, /* mdasp */
  63. 0x0000022a, /* mpodtctrl */
  64. 0xa1390003, /* mpzqhwctrl */
  65. };
  66. mmdc_init(&mparam);
  67. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  68. #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
  69. /* This will break-before-make MMU for DDR */
  70. update_early_mmu_table();
  71. #endif
  72. return 0;
  73. }
  74. int board_early_init_f(void)
  75. {
  76. fsl_lsch2_early_init_f();
  77. return 0;
  78. }
  79. #ifdef CONFIG_MISC_INIT_R
  80. int misc_init_r(void)
  81. {
  82. u8 mux_sdhc_cd = 0x80;
  83. i2c_set_bus_num(0);
  84. i2c_write(CONFIG_SYS_I2C_FPGA_ADDR, 0x5a, 1, &mux_sdhc_cd, 1);
  85. return 0;
  86. }
  87. #endif
  88. int board_init(void)
  89. {
  90. struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
  91. CONFIG_SYS_CCI400_OFFSET);
  92. /* Set CCI-400 control override register to enable barrier
  93. * transaction */
  94. out_le32(&cci->ctrl_ord,
  95. CCI400_CTRLORD_EN_BARRIER);
  96. #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
  97. erratum_a010315();
  98. #endif
  99. #ifdef CONFIG_ENV_IS_NOWHERE
  100. gd->env_addr = (ulong)&default_environment[0];
  101. #endif
  102. #ifdef CONFIG_FSL_LS_PPA
  103. ppa_init();
  104. #endif
  105. return 0;
  106. }
  107. int esdhc_status_fixup(void *blob, const char *compat)
  108. {
  109. char esdhc0_path[] = "/soc/esdhc@1560000";
  110. char esdhc1_path[] = "/soc/esdhc@1580000";
  111. u8 card_id;
  112. do_fixup_by_path(blob, esdhc0_path, "status", "okay",
  113. sizeof("okay"), 1);
  114. /*
  115. * The Presence Detect 2 register detects the installation
  116. * of cards in various PCI Express or SGMII slots.
  117. *
  118. * STAT_PRS2[7:5]: Specifies the type of card installed in the
  119. * SDHC2 Adapter slot. 0b111 indicates no adapter is installed.
  120. */
  121. card_id = (QIXIS_READ(present2) & 0xe0) >> 5;
  122. /* If no adapter is installed in SDHC2, disable SDHC2 */
  123. if (card_id == 0x7)
  124. do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
  125. sizeof("disabled"), 1);
  126. else
  127. do_fixup_by_path(blob, esdhc1_path, "status", "okay",
  128. sizeof("okay"), 1);
  129. return 0;
  130. }
  131. static int pfe_set_properties(void *set_blob, struct pfe_prop_val prop_val,
  132. char *enet_path, char *mdio_path)
  133. {
  134. do_fixup_by_path(set_blob, enet_path, "fsl,gemac-bus-id",
  135. &prop_val.busid, PFE_PROP_LEN, 1);
  136. do_fixup_by_path(set_blob, enet_path, "fsl,gemac-phy-id",
  137. &prop_val.phyid, PFE_PROP_LEN, 1);
  138. do_fixup_by_path(set_blob, enet_path, "fsl,mdio-mux-val",
  139. &prop_val.mux_val, PFE_PROP_LEN, 1);
  140. do_fixup_by_path(set_blob, enet_path, "phy-mode",
  141. prop_val.phy_mode, strlen(prop_val.phy_mode) + 1, 1);
  142. do_fixup_by_path(set_blob, mdio_path, "fsl,mdio-phy-mask",
  143. &prop_val.phy_mask, PFE_PROP_LEN, 1);
  144. return 0;
  145. }
  146. static void fdt_fsl_fixup_of_pfe(void *blob)
  147. {
  148. int i = 0;
  149. struct pfe_prop_val prop_val;
  150. void *l_blob = blob;
  151. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  152. unsigned int srds_s1 = in_be32(&gur->rcwsr[4]) &
  153. FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK;
  154. srds_s1 >>= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT;
  155. for (i = 0; i < NUM_ETH_NODE; i++) {
  156. switch (srds_s1) {
  157. case SERDES_1_G_PROTOCOL:
  158. if (i == 0) {
  159. prop_val.busid = cpu_to_fdt32(
  160. ETH_1_1G_BUS_ID);
  161. prop_val.phyid = cpu_to_fdt32(
  162. ETH_1_1G_PHY_ID);
  163. prop_val.mux_val = cpu_to_fdt32(
  164. ETH_1_1G_MDIO_MUX);
  165. prop_val.phy_mask = cpu_to_fdt32(
  166. ETH_1G_MDIO_PHY_MASK);
  167. prop_val.phy_mode = "sgmii";
  168. pfe_set_properties(l_blob, prop_val, ETH_1_PATH,
  169. ETH_1_MDIO);
  170. } else {
  171. prop_val.busid = cpu_to_fdt32(
  172. ETH_2_1G_BUS_ID);
  173. prop_val.phyid = cpu_to_fdt32(
  174. ETH_2_1G_PHY_ID);
  175. prop_val.mux_val = cpu_to_fdt32(
  176. ETH_2_1G_MDIO_MUX);
  177. prop_val.phy_mask = cpu_to_fdt32(
  178. ETH_1G_MDIO_PHY_MASK);
  179. prop_val.phy_mode = "rgmii";
  180. pfe_set_properties(l_blob, prop_val, ETH_2_PATH,
  181. ETH_2_MDIO);
  182. }
  183. break;
  184. case SERDES_2_5_G_PROTOCOL:
  185. if (i == 0) {
  186. prop_val.busid = cpu_to_fdt32(
  187. ETH_1_2_5G_BUS_ID);
  188. prop_val.phyid = cpu_to_fdt32(
  189. ETH_1_2_5G_PHY_ID);
  190. prop_val.mux_val = cpu_to_fdt32(
  191. ETH_1_2_5G_MDIO_MUX);
  192. prop_val.phy_mask = cpu_to_fdt32(
  193. ETH_2_5G_MDIO_PHY_MASK);
  194. prop_val.phy_mode = "sgmii-2500";
  195. pfe_set_properties(l_blob, prop_val, ETH_1_PATH,
  196. ETH_1_MDIO);
  197. } else {
  198. prop_val.busid = cpu_to_fdt32(
  199. ETH_2_2_5G_BUS_ID);
  200. prop_val.phyid = cpu_to_fdt32(
  201. ETH_2_2_5G_PHY_ID);
  202. prop_val.mux_val = cpu_to_fdt32(
  203. ETH_2_2_5G_MDIO_MUX);
  204. prop_val.phy_mask = cpu_to_fdt32(
  205. ETH_2_5G_MDIO_PHY_MASK);
  206. prop_val.phy_mode = "sgmii-2500";
  207. pfe_set_properties(l_blob, prop_val, ETH_2_PATH,
  208. ETH_2_MDIO);
  209. }
  210. break;
  211. default:
  212. printf("serdes:[%d]\n", srds_s1);
  213. }
  214. }
  215. }
  216. #ifdef CONFIG_OF_BOARD_SETUP
  217. int ft_board_setup(void *blob, bd_t *bd)
  218. {
  219. arch_fixup_fdt(blob);
  220. ft_cpu_setup(blob, bd);
  221. fdt_fsl_fixup_of_pfe(blob);
  222. return 0;
  223. }
  224. #endif