eth.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Author: Mingkai Hu <Mingkai.hu@freescale.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * The RGMII PHYs are provided by the two on-board PHY. The SGMII PHYs
  25. * are provided by the three on-board PHY or by the standard Freescale
  26. * four-port SGMII riser card. We need to change the phy-handle in the
  27. * kernel dts file to point to the correct PHY according to serdes mux
  28. * and serdes protocol selection.
  29. */
  30. #include <common.h>
  31. #include <netdev.h>
  32. #include <asm/fsl_serdes.h>
  33. #include <fm_eth.h>
  34. #include <fsl_mdio.h>
  35. #include <malloc.h>
  36. #include <asm/fsl_dtsec.h>
  37. #include "cpld.h"
  38. #include "../common/fman.h"
  39. #ifdef CONFIG_FMAN_ENET
  40. /*
  41. * Mapping of all 18 SERDES lanes to board slots. A value of '0' here means
  42. * that the mapping must be determined dynamically, or that the lane maps to
  43. * something other than a board slot
  44. */
  45. static u8 lane_to_slot[] = {
  46. 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0
  47. };
  48. static int riser_phy_addr[] = {
  49. CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR,
  50. CONFIG_SYS_FM1_DTSEC2_RISER_PHY_ADDR,
  51. CONFIG_SYS_FM1_DTSEC3_RISER_PHY_ADDR,
  52. CONFIG_SYS_FM1_DTSEC4_RISER_PHY_ADDR,
  53. };
  54. /*
  55. * Initialize the lane_to_slot[] array.
  56. *
  57. * On the P2040RDB board the mapping is controlled by CPLD register.
  58. */
  59. static void initialize_lane_to_slot(void)
  60. {
  61. u8 mux = CPLD_READ(serdes_mux);
  62. lane_to_slot[6] = (mux & SERDES_MUX_LANE_6_MASK) ? 0 : 1;
  63. lane_to_slot[10] = (mux & SERDES_MUX_LANE_A_MASK) ? 0 : 2;
  64. lane_to_slot[12] = (mux & SERDES_MUX_LANE_C_MASK) ? 0 : 2;
  65. lane_to_slot[13] = (mux & SERDES_MUX_LANE_D_MASK) ? 0 : 2;
  66. }
  67. /*
  68. * Given the following ...
  69. *
  70. * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
  71. * compatible string and 'addr' physical address)
  72. *
  73. * 2) An Fman port
  74. *
  75. * ... update the phy-handle property of the Ethernet node to point to the
  76. * right PHY. This assumes that we already know the PHY for each port.
  77. *
  78. * The offset of the Fman Ethernet node is also passed in for convenience, but
  79. * it is not used, and we recalculate the offset anyway.
  80. *
  81. * Note that what we call "Fman ports" (enum fm_port) is really an Fman MAC.
  82. * Inside the Fman, "ports" are things that connect to MACs. We only call them
  83. * ports in U-Boot because on previous Ethernet devices (e.g. Gianfar), MACs
  84. * and ports are the same thing.
  85. *
  86. */
  87. void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
  88. enum fm_port port, int offset)
  89. {
  90. phy_interface_t intf = fm_info_get_enet_if(port);
  91. char phy[16];
  92. /* The RGMII PHY is identified by the MAC connected to it */
  93. if (intf == PHY_INTERFACE_MODE_RGMII) {
  94. sprintf(phy, "phy_rgmii_%u", port == FM1_DTSEC5 ? 0 : 1);
  95. fdt_set_phy_handle(fdt, compat, addr, phy);
  96. }
  97. /* The SGMII PHY is identified by the MAC connected to it */
  98. if (intf == PHY_INTERFACE_MODE_SGMII) {
  99. int lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + port);
  100. u8 slot;
  101. if (lane < 0)
  102. return;
  103. slot = lane_to_slot[lane];
  104. if (slot) {
  105. sprintf(phy, "phy_sgmii_%x",
  106. CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR
  107. + (port - FM1_DTSEC1));
  108. fdt_set_phy_handle(fdt, compat, addr, phy);
  109. } else {
  110. sprintf(phy, "phy_sgmii_%x",
  111. CONFIG_SYS_FM1_DTSEC1_PHY_ADDR
  112. + (port - FM1_DTSEC1));
  113. fdt_set_phy_handle(fdt, compat, addr, phy);
  114. }
  115. }
  116. if (intf == PHY_INTERFACE_MODE_XGMII) {
  117. /* XAUI */
  118. int lane = serdes_get_first_lane(XAUI_FM1);
  119. if (lane >= 0) {
  120. /* The XAUI PHY is identified by the slot */
  121. sprintf(phy, "phy_xgmii_%u", lane_to_slot[lane]);
  122. fdt_set_phy_handle(fdt, compat, addr, phy);
  123. }
  124. }
  125. }
  126. #endif /* #ifdef CONFIG_FMAN_ENET */
  127. int board_eth_init(bd_t *bis)
  128. {
  129. #ifdef CONFIG_FMAN_ENET
  130. struct dtsec *tsec = (void *)CONFIG_SYS_FSL_FM1_DTSEC1_ADDR;
  131. struct fsl_pq_mdio_info dtsec_mdio_info;
  132. struct tgec_mdio_info tgec_mdio_info;
  133. unsigned int i, slot;
  134. int lane;
  135. printf("Initializing Fman\n");
  136. initialize_lane_to_slot();
  137. /*
  138. * Set TBIPA on FM1@DTSEC1. This is needed for configurations
  139. * where FM1@DTSEC1 isn't used directly, since it provides
  140. * MDIO for other ports.
  141. */
  142. out_be32(&tsec->tbipa, CONFIG_SYS_TBIPA_VALUE);
  143. dtsec_mdio_info.regs =
  144. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  145. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  146. /* Register the real 1G MDIO bus */
  147. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  148. tgec_mdio_info.regs =
  149. (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  150. tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  151. /* Register the real 10G MDIO bus */
  152. fm_tgec_mdio_init(bis, &tgec_mdio_info);
  153. /*
  154. * Program the three on-board SGMII PHY addresses. If the SGMII Riser
  155. * card used, we'll override the PHY address later. For any DTSEC that
  156. * is RGMII, we'll also override its PHY address later. We assume that
  157. * DTSEC4 and DTSEC5 are used for RGMII.
  158. */
  159. fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  160. fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  161. fm_info_set_phy_address(FM1_DTSEC3, CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
  162. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  163. int idx = i - FM1_DTSEC1;
  164. switch (fm_info_get_enet_if(i)) {
  165. case PHY_INTERFACE_MODE_SGMII:
  166. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  167. if (lane < 0)
  168. break;
  169. slot = lane_to_slot[lane];
  170. if (slot)
  171. fm_info_set_phy_address(i, riser_phy_addr[i]);
  172. break;
  173. case PHY_INTERFACE_MODE_RGMII:
  174. /* Only DTSEC4 and DTSEC5 can be routed to RGMII */
  175. fm_info_set_phy_address(i, i == FM1_DTSEC5 ?
  176. CONFIG_SYS_FM1_DTSEC5_PHY_ADDR :
  177. CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
  178. break;
  179. default:
  180. printf("Fman1: DTSEC%u set to unknown interface %i\n",
  181. idx + 1, fm_info_get_enet_if(i));
  182. break;
  183. }
  184. fm_info_set_mdio(i,
  185. miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
  186. }
  187. lane = serdes_get_first_lane(XAUI_FM1);
  188. if (lane >= 0) {
  189. slot = lane_to_slot[lane];
  190. if (slot)
  191. fm_info_set_phy_address(FM1_10GEC1,
  192. CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  193. }
  194. fm_info_set_mdio(FM1_10GEC1,
  195. miiphy_get_dev_by_name(DEFAULT_FM_TGEC_MDIO_NAME));
  196. cpu_eth_init(bis);
  197. #endif
  198. return pci_eth_init(bis);
  199. }