722-net-phy-realtek-support-switching-between-SGMII-and-.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 312753d0aadba0f58841ae513b80fdbabc887523 Mon Sep 17 00:00:00 2001
  2. From: Chukun Pan <[email protected]>
  3. Date: Wed, 8 Feb 2023 16:32:18 +0800
  4. Subject: [PATCH] net: phy: realtek: support switching between SGMII and
  5. 2500BASE-X for RTL822x series
  6. After commit ace6aba ("net: phy: realtek: rtl8221: allow to configure
  7. SERDES mode"), the rtl8221 phy can work in SGMII and 2500base-x modes
  8. respectively. So add interface automatic switching for rtl8221 phy to
  9. match various wire speeds.
  10. Signed-off-by: Chukun Pan <[email protected]>
  11. ---
  12. drivers/net/phy/realtek.c | 26 ++++++++++++++++++++++++--
  13. 1 file changed, 24 insertions(+), 2 deletions(-)
  14. --- a/drivers/net/phy/realtek.c
  15. +++ b/drivers/net/phy/realtek.c
  16. @@ -714,6 +714,25 @@ static int rtl822x_config_aneg(struct ph
  17. return __genphy_config_aneg(phydev, ret);
  18. }
  19. +static void rtl822x_update_interface(struct phy_device *phydev)
  20. +{
  21. + /* Automatically switch SERDES interface between
  22. + * SGMII and 2500-BaseX according to speed.
  23. + */
  24. + switch (phydev->speed) {
  25. + case SPEED_2500:
  26. + phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
  27. + break;
  28. + case SPEED_1000:
  29. + case SPEED_100:
  30. + case SPEED_10:
  31. + phydev->interface = PHY_INTERFACE_MODE_SGMII;
  32. + break;
  33. + default:
  34. + break;
  35. + }
  36. +}
  37. +
  38. static int rtl822x_read_status(struct phy_device *phydev)
  39. {
  40. int ret;
  41. @@ -732,11 +751,14 @@ static int rtl822x_read_status(struct ph
  42. phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
  43. }
  44. - ret = genphy_read_status(phydev);
  45. + ret = rtlgen_read_status(phydev);
  46. if (ret < 0)
  47. return ret;
  48. - return rtlgen_get_speed(phydev);
  49. + if (phydev->is_c45 && phydev->link)
  50. + rtl822x_update_interface(phydev);
  51. +
  52. + return 0;
  53. }
  54. static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)