teranetics.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Teranetics PHY drivers
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. *
  19. * Copyright 2010-2011 Freescale Semiconductor, Inc.
  20. * author Andy Fleming
  21. *
  22. */
  23. #include <config.h>
  24. #include <common.h>
  25. #include <phy.h>
  26. #ifndef CONFIG_PHYLIB_10G
  27. #error The Teranetics PHY needs 10G support
  28. #endif
  29. int tn2020_config(struct phy_device *phydev)
  30. {
  31. if (phydev->port == PORT_FIBRE) {
  32. unsigned short restart_an = (MDIO_AN_CTRL1_RESTART |
  33. MDIO_AN_CTRL1_ENABLE |
  34. MDIO_AN_CTRL1_XNP);
  35. u8 phy_hwversion;
  36. /*
  37. * bit 15:12 of register 30.32 indicates PHY hardware
  38. * version. It can be used to distinguish TN80xx from
  39. * TN2020. TN2020 needs write 0x2 to 30.93, but TN80xx
  40. * needs 0x1.
  41. */
  42. phy_hwversion = (phy_read(phydev, 30, 32) >> 12) & 0xf;
  43. if (phy_hwversion <= 3) {
  44. phy_write(phydev, 30, 93, 2);
  45. phy_write(phydev, MDIO_MMD_AN, MDIO_CTRL1, restart_an);
  46. } else {
  47. phy_write(phydev, 30, 93, 1);
  48. }
  49. }
  50. return 0;
  51. }
  52. int tn2020_startup(struct phy_device *phydev)
  53. {
  54. unsigned int timeout = 5 * 1000; /* 5 second timeout */
  55. #define MDIO_PHYXS_LANE_READY (MDIO_PHYXS_LNSTAT_SYNC0 | \
  56. MDIO_PHYXS_LNSTAT_SYNC1 | \
  57. MDIO_PHYXS_LNSTAT_SYNC2 | \
  58. MDIO_PHYXS_LNSTAT_SYNC3 | \
  59. MDIO_PHYXS_LNSTAT_ALIGN)
  60. /*
  61. * Wait for the XAUI-SERDES lanes to align first. Under normal
  62. * circumstances, this can take up to three seconds.
  63. */
  64. while (--timeout) {
  65. int reg = phy_read(phydev, MDIO_MMD_PHYXS, MDIO_PHYXS_LNSTAT);
  66. if (reg < 0) {
  67. printf("TN2020: Error reading from PHY at "
  68. "address %u\n", phydev->addr);
  69. break;
  70. }
  71. if ((reg & MDIO_PHYXS_LANE_READY) == MDIO_PHYXS_LANE_READY)
  72. break;
  73. udelay(1000);
  74. }
  75. if (!timeout) {
  76. /*
  77. * A timeout is bad, but it may not be fatal, so don't
  78. * return an error. Display a warning instead.
  79. */
  80. printf("TN2020: Timeout waiting for PHY at address %u to "
  81. "align.\n", phydev->addr);
  82. }
  83. if (phydev->port != PORT_FIBRE)
  84. return gen10g_startup(phydev);
  85. /*
  86. * The TN2020 only pretends to support fiber.
  87. * It works, but it doesn't look like it works,
  88. * so the link status reports no link.
  89. */
  90. phydev->link = 1;
  91. /* For now just lie and say it's 10G all the time */
  92. phydev->speed = SPEED_10000;
  93. phydev->duplex = DUPLEX_FULL;
  94. return 0;
  95. }
  96. struct phy_driver tn2020_driver = {
  97. .name = "Teranetics TN2020",
  98. .uid = PHY_UID_TN2020,
  99. .mask = 0xfffffff0,
  100. .features = PHY_10G_FEATURES,
  101. .mmds = (MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS |
  102. MDIO_DEVS_PHYXS | MDIO_DEVS_AN |
  103. MDIO_DEVS_VEND1 | MDIO_DEVS_VEND2),
  104. .config = &tn2020_config,
  105. .startup = &tn2020_startup,
  106. .shutdown = &gen10g_shutdown,
  107. };
  108. int phy_teranetics_init(void)
  109. {
  110. phy_register(&tn2020_driver);
  111. return 0;
  112. }