b4860.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2012 Freescale Semiconductor, Inc.
  4. * Roy Zang <tie-fei.zang@freescale.com>
  5. */
  6. #include <common.h>
  7. #include <phy.h>
  8. #include <fm_eth.h>
  9. #include <asm/io.h>
  10. #include <asm/immap_85xx.h>
  11. #include <asm/fsl_serdes.h>
  12. #include <hwconfig.h>
  13. u32 port_to_devdisr[] = {
  14. [FM1_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC1_1,
  15. [FM1_DTSEC2] = FSL_CORENET_DEVDISR2_DTSEC1_2,
  16. [FM1_DTSEC3] = FSL_CORENET_DEVDISR2_DTSEC1_3,
  17. [FM1_DTSEC4] = FSL_CORENET_DEVDISR2_DTSEC1_4,
  18. [FM1_DTSEC5] = FSL_CORENET_DEVDISR2_DTSEC1_5,
  19. [FM1_DTSEC6] = FSL_CORENET_DEVDISR2_DTSEC1_6,
  20. [FM1_10GEC1] = FSL_CORENET_DEVDISR2_10GEC1_1,
  21. [FM1_10GEC2] = FSL_CORENET_DEVDISR2_10GEC1_2,
  22. };
  23. static int is_device_disabled(enum fm_port port)
  24. {
  25. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  26. u32 devdisr2 = in_be32(&gur->devdisr2);
  27. return port_to_devdisr[port] & devdisr2;
  28. }
  29. void fman_disable_port(enum fm_port port)
  30. {
  31. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  32. setbits_be32(&gur->devdisr2, port_to_devdisr[port]);
  33. }
  34. void fman_enable_port(enum fm_port port)
  35. {
  36. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  37. clrbits_be32(&gur->devdisr2, port_to_devdisr[port]);
  38. }
  39. phy_interface_t fman_port_enet_if(enum fm_port port)
  40. {
  41. #if defined(CONFIG_TARGET_B4860QDS) || defined(CONFIG_TARGET_B4420QDS)
  42. u32 serdes2_prtcl;
  43. char buffer[HWCONFIG_BUFFER_SIZE];
  44. char *buf = NULL;
  45. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  46. #endif
  47. if (is_device_disabled(port))
  48. return PHY_INTERFACE_MODE_NONE;
  49. /*B4860 has two 10Gig Mac*/
  50. if ((port == FM1_10GEC1 || port == FM1_10GEC2) &&
  51. ((is_serdes_configured(XAUI_FM1_MAC9)) ||
  52. #if (!defined(CONFIG_TARGET_B4860QDS) && \
  53. !defined(CONFIG_TARGET_B4R420QDS))
  54. (is_serdes_configured(XFI_FM1_MAC9)) ||
  55. (is_serdes_configured(XFI_FM1_MAC10)) ||
  56. #endif
  57. (is_serdes_configured(XAUI_FM1_MAC10))
  58. ))
  59. return PHY_INTERFACE_MODE_XGMII;
  60. #if defined(CONFIG_TARGET_B4860QDS) || defined(CONFIG_TARGET_B4420QDS)
  61. serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
  62. FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
  63. if (serdes2_prtcl) {
  64. serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
  65. switch (serdes2_prtcl) {
  66. case 0x80:
  67. case 0x81:
  68. case 0x82:
  69. case 0x83:
  70. case 0x84:
  71. case 0x85:
  72. case 0x86:
  73. case 0x87:
  74. case 0x88:
  75. case 0x89:
  76. case 0x8a:
  77. case 0x8b:
  78. case 0x8c:
  79. case 0x8d:
  80. case 0x8e:
  81. case 0xb1:
  82. case 0xb2:
  83. /*
  84. * Extract hwconfig from environment since environment
  85. * is not setup yet
  86. */
  87. env_get_f("hwconfig", buffer, sizeof(buffer));
  88. buf = buffer;
  89. /* check if XFI interface enable in hwconfig for 10g */
  90. if (hwconfig_subarg_cmp_f("fsl_b4860_serdes2",
  91. "sfp_amc", "sfp", buf)) {
  92. if ((port == FM1_10GEC1 ||
  93. port == FM1_10GEC2) &&
  94. ((is_serdes_configured(XFI_FM1_MAC9)) ||
  95. (is_serdes_configured(XFI_FM1_MAC10))))
  96. return PHY_INTERFACE_MODE_XGMII;
  97. else if ((port == FM1_DTSEC1) ||
  98. (port == FM1_DTSEC2) ||
  99. (port == FM1_DTSEC3) ||
  100. (port == FM1_DTSEC4))
  101. return PHY_INTERFACE_MODE_NONE;
  102. }
  103. }
  104. }
  105. #endif
  106. /* Fix me need to handle RGMII here first */
  107. switch (port) {
  108. case FM1_DTSEC1:
  109. case FM1_DTSEC2:
  110. case FM1_DTSEC3:
  111. case FM1_DTSEC4:
  112. case FM1_DTSEC5:
  113. case FM1_DTSEC6:
  114. if (is_serdes_configured(SGMII_FM1_DTSEC1 + port - FM1_DTSEC1))
  115. return PHY_INTERFACE_MODE_SGMII;
  116. break;
  117. default:
  118. return PHY_INTERFACE_MODE_NONE;
  119. }
  120. return PHY_INTERFACE_MODE_NONE;
  121. }