generic_10g.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 & MDIO_DEVS_LINK;
  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. /*
  42. * Go through all the link-reporting devices, and make sure
  43. * they're all up and happy
  44. */
  45. for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) {
  46. if (!(mmd_mask & 1))
  47. continue;
  48. /* Read twice because link state is latched and a
  49. * read moves the current state into the register */
  50. phy_read(phydev, devad, MDIO_STAT1);
  51. reg = phy_read(phydev, devad, MDIO_STAT1);
  52. if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
  53. phydev->link = 0;
  54. }
  55. return 0;
  56. }
  57. int gen10g_discover_mmds(struct phy_device *phydev)
  58. {
  59. int mmd, stat2, devs1, devs2;
  60. /* Assume PHY must have at least one of PMA/PMD, WIS, PCS, PHY
  61. * XS or DTE XS; give up if none is present. */
  62. for (mmd = 1; mmd <= 5; mmd++) {
  63. /* Is this MMD present? */
  64. stat2 = phy_read(phydev, mmd, MDIO_STAT2);
  65. if (stat2 < 0 ||
  66. (stat2 & MDIO_STAT2_DEVPRST) != MDIO_STAT2_DEVPRST_VAL)
  67. continue;
  68. /* It should tell us about all the other MMDs */
  69. devs1 = phy_read(phydev, mmd, MDIO_DEVS1);
  70. devs2 = phy_read(phydev, mmd, MDIO_DEVS2);
  71. if (devs1 < 0 || devs2 < 0)
  72. continue;
  73. phydev->mmds = devs1 | (devs2 << 16);
  74. return 0;
  75. }
  76. return 0;
  77. }
  78. int gen10g_config(struct phy_device *phydev)
  79. {
  80. /* For now, assume 10000baseT. Fill in later */
  81. phydev->supported = phydev->advertising = SUPPORTED_10000baseT_Full;
  82. return gen10g_discover_mmds(phydev);
  83. }
  84. struct phy_driver gen10g_driver = {
  85. .uid = 0xffffffff,
  86. .mask = 0xffffffff,
  87. .name = "Generic 10G PHY",
  88. .features = 0,
  89. .config = gen10g_config,
  90. .startup = gen10g_startup,
  91. .shutdown = gen10g_shutdown,
  92. };