generic_10g.c 2.1 KB

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