fsl_lsch3_serdes.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/errno.h>
  9. #include <asm/arch/fsl_serdes.h>
  10. #include <asm/arch/soc.h>
  11. #include <fsl-mc/ldpaa_wriop.h>
  12. #ifdef CONFIG_SYS_FSL_SRDS_1
  13. static u8 serdes1_prtcl_map[SERDES_PRCTL_COUNT];
  14. #endif
  15. #ifdef CONFIG_SYS_FSL_SRDS_2
  16. static u8 serdes2_prtcl_map[SERDES_PRCTL_COUNT];
  17. #endif
  18. int is_serdes_configured(enum srds_prtcl device)
  19. {
  20. int ret = 0;
  21. #ifdef CONFIG_SYS_FSL_SRDS_1
  22. ret |= serdes1_prtcl_map[device];
  23. #endif
  24. #ifdef CONFIG_SYS_FSL_SRDS_2
  25. ret |= serdes2_prtcl_map[device];
  26. #endif
  27. return !!ret;
  28. }
  29. int serdes_get_first_lane(u32 sd, enum srds_prtcl device)
  30. {
  31. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  32. u32 cfg = gur_in32(&gur->rcwsr[28]);
  33. int i;
  34. switch (sd) {
  35. #ifdef CONFIG_SYS_FSL_SRDS_1
  36. case FSL_SRDS_1:
  37. cfg &= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK;
  38. cfg >>= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  39. break;
  40. #endif
  41. #ifdef CONFIG_SYS_FSL_SRDS_2
  42. case FSL_SRDS_2:
  43. cfg &= FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK;
  44. cfg >>= FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  45. break;
  46. #endif
  47. default:
  48. printf("invalid SerDes%d\n", sd);
  49. break;
  50. }
  51. /* Is serdes enabled at all? */
  52. if (cfg == 0)
  53. return -ENODEV;
  54. for (i = 0; i < SRDS_MAX_LANES; i++) {
  55. if (serdes_get_prtcl(sd, cfg, i) == device)
  56. return i;
  57. }
  58. return -ENODEV;
  59. }
  60. void serdes_init(u32 sd, u32 sd_addr, u32 sd_prctl_mask, u32 sd_prctl_shift,
  61. u8 serdes_prtcl_map[SERDES_PRCTL_COUNT])
  62. {
  63. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  64. u32 cfg;
  65. int lane;
  66. memset(serdes_prtcl_map, 0, sizeof(serdes_prtcl_map));
  67. cfg = gur_in32(&gur->rcwsr[28]) & sd_prctl_mask;
  68. cfg >>= sd_prctl_shift;
  69. printf("Using SERDES%d Protocol: %d (0x%x)\n", sd + 1, cfg, cfg);
  70. if (!is_serdes_prtcl_valid(sd, cfg))
  71. printf("SERDES%d[PRTCL] = 0x%x is not valid\n", sd + 1, cfg);
  72. for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
  73. enum srds_prtcl lane_prtcl = serdes_get_prtcl(sd, cfg, lane);
  74. if (unlikely(lane_prtcl >= SERDES_PRCTL_COUNT))
  75. debug("Unknown SerDes lane protocol %d\n", lane_prtcl);
  76. else {
  77. serdes_prtcl_map[lane_prtcl] = 1;
  78. #ifdef CONFIG_FSL_MC_ENET
  79. switch (lane_prtcl) {
  80. case QSGMII_A:
  81. wriop_init_dpmac(sd, 5, (int)lane_prtcl);
  82. wriop_init_dpmac(sd, 6, (int)lane_prtcl);
  83. wriop_init_dpmac(sd, 7, (int)lane_prtcl);
  84. wriop_init_dpmac(sd, 8, (int)lane_prtcl);
  85. break;
  86. case QSGMII_B:
  87. wriop_init_dpmac(sd, 1, (int)lane_prtcl);
  88. wriop_init_dpmac(sd, 2, (int)lane_prtcl);
  89. wriop_init_dpmac(sd, 3, (int)lane_prtcl);
  90. wriop_init_dpmac(sd, 4, (int)lane_prtcl);
  91. break;
  92. case QSGMII_C:
  93. wriop_init_dpmac(sd, 13, (int)lane_prtcl);
  94. wriop_init_dpmac(sd, 14, (int)lane_prtcl);
  95. wriop_init_dpmac(sd, 15, (int)lane_prtcl);
  96. wriop_init_dpmac(sd, 16, (int)lane_prtcl);
  97. break;
  98. case QSGMII_D:
  99. wriop_init_dpmac(sd, 9, (int)lane_prtcl);
  100. wriop_init_dpmac(sd, 10, (int)lane_prtcl);
  101. wriop_init_dpmac(sd, 11, (int)lane_prtcl);
  102. wriop_init_dpmac(sd, 12, (int)lane_prtcl);
  103. break;
  104. default:
  105. if (lane_prtcl >= SGMII1 &&
  106. lane_prtcl <= SGMII16)
  107. wriop_init_dpmac(sd, lane + 1,
  108. (int)lane_prtcl);
  109. break;
  110. }
  111. #endif
  112. }
  113. }
  114. }
  115. void fsl_serdes_init(void)
  116. {
  117. #ifdef CONFIG_SYS_FSL_SRDS_1
  118. serdes_init(FSL_SRDS_1,
  119. CONFIG_SYS_FSL_LSCH3_SERDES_ADDR,
  120. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK,
  121. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT,
  122. serdes1_prtcl_map);
  123. #endif
  124. #ifdef CONFIG_SYS_FSL_SRDS_2
  125. serdes_init(FSL_SRDS_2,
  126. CONFIG_SYS_FSL_LSCH3_SERDES_ADDR + FSL_SRDS_2 * 0x10000,
  127. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK,
  128. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT,
  129. serdes2_prtcl_map);
  130. #endif
  131. }