generic_10g.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Generic PHY Management code
  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. *
  20. * Copyright 2011 Freescale Semiconductor, Inc.
  21. * author Andy Fleming
  22. *
  23. * Based loosely off of Linux's PHY Lib
  24. */
  25. #include <config.h>
  26. #include <common.h>
  27. #include <miiphy.h>
  28. #include <phy.h>
  29. int gen10g_shutdown(struct phy_device *phydev)
  30. {
  31. return 0;
  32. }
  33. int gen10g_startup(struct phy_device *phydev)
  34. {
  35. int devad, reg;
  36. u32 mmd_mask = phydev->mmds;
  37. phydev->link = 1;
  38. /* For now just lie and say it's 10G all the time */
  39. phydev->speed = SPEED_10000;
  40. phydev->duplex = DUPLEX_FULL;
  41. for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) {
  42. if (!mmd_mask & 1)
  43. continue;
  44. /* Read twice because link state is latched and a
  45. * read moves the current state into the register */
  46. phy_read(phydev, devad, MDIO_STAT1);
  47. reg = phy_read(phydev, devad, MDIO_STAT1);
  48. if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
  49. phydev->link = 0;
  50. }
  51. return 0;
  52. }
  53. int gen10g_discover_mmds(struct phy_device *phydev)
  54. {
  55. int mmd, stat2, devs1, devs2;
  56. /* Assume PHY must have at least one of PMA/PMD, WIS, PCS, PHY
  57. * XS or DTE XS; give up if none is present. */
  58. for (mmd = 1; mmd <= 5; mmd++) {
  59. /* Is this MMD present? */
  60. stat2 = phy_read(phydev, mmd, MDIO_STAT2);
  61. if (stat2 < 0 ||
  62. (stat2 & MDIO_STAT2_DEVPRST) != MDIO_STAT2_DEVPRST_VAL)
  63. continue;
  64. /* It should tell us about all the other MMDs */
  65. devs1 = phy_read(phydev, mmd, MDIO_DEVS1);
  66. devs2 = phy_read(phydev, mmd, MDIO_DEVS2);
  67. if (devs1 < 0 || devs2 < 0)
  68. continue;
  69. phydev->mmds = devs1 | (devs2 << 16);
  70. return 0;
  71. }
  72. return 0;
  73. }
  74. int gen10g_config(struct phy_device *phydev)
  75. {
  76. /* For now, assume 10000baseT. Fill in later */
  77. phydev->supported = phydev->advertising = SUPPORTED_10000baseT_Full;
  78. return gen10g_discover_mmds(phydev);
  79. }
  80. struct phy_driver gen10g_driver = {
  81. .uid = 0xffffffff,
  82. .mask = 0xffffffff,
  83. .name = "Generic 10G PHY",
  84. .features = 0,
  85. .config = gen10g_config,
  86. .startup = gen10g_startup,
  87. .shutdown = gen10g_shutdown,
  88. };