generic_10g.c 2.1 KB

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