eth.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Author Adrian Cox
  4. * Based somewhat on board/freescale/corenet_ds/eth_hydra.c
  5. */
  6. #include <common.h>
  7. #include <netdev.h>
  8. #include <asm/fsl_serdes.h>
  9. #include <fm_eth.h>
  10. #include <fsl_mdio.h>
  11. #include <malloc.h>
  12. #include <fdt_support.h>
  13. #include <fsl_dtsec.h>
  14. #ifdef CONFIG_FMAN_ENET
  15. #define FIRST_PORT_ADDR 3
  16. #define SECOND_PORT_ADDR 7
  17. #ifdef CONFIG_ARCH_P5040
  18. #define FIRST_PORT FM1_DTSEC5
  19. #define SECOND_PORT FM2_DTSEC5
  20. #else
  21. #define FIRST_PORT FM1_DTSEC4
  22. #define SECOND_PORT FM1_DTSEC5
  23. #endif
  24. #define IS_VALID_PORT(p) ((p) == FIRST_PORT || (p) == SECOND_PORT)
  25. static void cyrus_phy_tuning(int phy)
  26. {
  27. /*
  28. * Enable RGMII delay on Tx and Rx for CPU port
  29. */
  30. printf("Tuning PHY @ %d\n", phy);
  31. /* sets address 0x104 or reg 260 for writing */
  32. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0xb, 0x8104);
  33. /* Sets RXC/TXC to +0.96ns and TX_CTL/RX_CTL to -0.84ns */
  34. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0xc, 0xf0f0);
  35. /* sets address 0x105 or reg 261 for writing */
  36. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0xb, 0x8105);
  37. /* writes to address 0x105 , RXD[3..0] to -0. */
  38. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0xc, 0x0000);
  39. /* sets address 0x106 or reg 261 for writing */
  40. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0xb, 0x8106);
  41. /* writes to address 0x106 , TXD[3..0] to -0.84ns */
  42. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0xc, 0x0000);
  43. /* force re-negotiation */
  44. miiphy_write(DEFAULT_FM_MDIO_NAME, phy, 0x0, 0x1340);
  45. }
  46. #endif
  47. int board_eth_init(bd_t *bis)
  48. {
  49. #ifdef CONFIG_FMAN_ENET
  50. struct fsl_pq_mdio_info dtsec_mdio_info;
  51. unsigned int i;
  52. printf("Initializing Fman\n");
  53. /* Register the real 1G MDIO bus */
  54. dtsec_mdio_info.regs =
  55. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  56. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  57. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  58. fm_info_set_phy_address(FIRST_PORT, FIRST_PORT_ADDR);
  59. fm_info_set_mdio(FIRST_PORT,
  60. miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
  61. fm_info_set_phy_address(SECOND_PORT, SECOND_PORT_ADDR);
  62. fm_info_set_mdio(SECOND_PORT,
  63. miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
  64. /* Never disable DTSEC1 - it controls MDIO */
  65. for (i = FM1_DTSEC2; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  66. if (!IS_VALID_PORT(i))
  67. fm_disable_port(i);
  68. }
  69. #ifdef CONFIG_ARCH_P5040
  70. for (i = FM2_DTSEC2; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  71. if (!IS_VALID_PORT(i))
  72. fm_disable_port(i);
  73. }
  74. #endif
  75. cpu_eth_init(bis);
  76. cyrus_phy_tuning(FIRST_PORT_ADDR);
  77. cyrus_phy_tuning(SECOND_PORT_ADDR);
  78. #endif
  79. return pci_eth_init(bis);
  80. }