729-net-phy-realtek-introduce-rtl822x_probe.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 9155098547fb1172d4fa536f3f6bc9d42f59d08c Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Sat, 22 Apr 2023 03:26:01 +0100
  4. Subject: [PATCH] net: phy: realtek: setup ALDPS on RTL822x
  5. Setup Link Down Power Saving Mode according the DTS property
  6. just like for RTL821x 1GE PHYs.
  7. Signed-off-by: Daniel Golle <[email protected]>
  8. ---
  9. drivers/net/phy/realtek.c | 11 +++++++++++
  10. 1 file changed, 11 insertions(+)
  11. --- a/drivers/net/phy/realtek.c
  12. +++ b/drivers/net/phy/realtek.c
  13. @@ -63,6 +63,10 @@
  14. #define RTL8221B_SERDES_OPTION_MODE_2500BASEX 2
  15. #define RTL8221B_SERDES_OPTION_MODE_HISGMII 3
  16. +#define RTL8221B_PHYCR1 0xa430
  17. +#define RTL8221B_PHYCR1_ALDPS_EN BIT(2)
  18. +#define RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN BIT(12)
  19. +
  20. #define RTL8366RB_POWER_SAVE 0x15
  21. #define RTL8366RB_POWER_SAVE_ON BIT(12)
  22. @@ -778,6 +782,25 @@ static int rtl8226_match_phy_device(stru
  23. rtlgen_supports_2_5gbps(phydev);
  24. }
  25. +static int rtl822x_probe(struct phy_device *phydev)
  26. +{
  27. + struct device *dev = &phydev->mdio.dev;
  28. + int val;
  29. +
  30. + val = phy_read_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, RTL8221B_PHYCR1);
  31. + if (val < 0)
  32. + return val;
  33. +
  34. + if (of_property_read_bool(dev->of_node, "realtek,aldps-enable"))
  35. + val |= RTL8221B_PHYCR1_ALDPS_EN | RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN;
  36. + else
  37. + val &= ~(RTL8221B_PHYCR1_ALDPS_EN | RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN);
  38. +
  39. + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, RTL8221B_PHYCR1, val);
  40. +
  41. + return 0;
  42. +}
  43. +
  44. static int rtlgen_resume(struct phy_device *phydev)
  45. {
  46. int ret = genphy_resume(phydev);
  47. @@ -1091,6 +1114,7 @@ static struct phy_driver realtek_drvs[]
  48. .name = "RTL8226-CG 2.5Gbps PHY",
  49. .get_features = rtl822x_get_features,
  50. .config_aneg = rtl822x_config_aneg,
  51. + .probe = rtl822x_probe,
  52. .read_status = rtl822x_read_status,
  53. .suspend = genphy_suspend,
  54. .resume = rtlgen_resume,
  55. @@ -1102,6 +1126,7 @@ static struct phy_driver realtek_drvs[]
  56. .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY",
  57. .get_features = rtl822x_get_features,
  58. .config_aneg = rtl822x_config_aneg,
  59. + .probe = rtl822x_probe,
  60. .read_status = rtl822x_read_status,
  61. .suspend = genphy_suspend,
  62. .resume = rtlgen_resume,
  63. @@ -1114,6 +1139,7 @@ static struct phy_driver realtek_drvs[]
  64. .get_features = rtl822x_get_features,
  65. .config_init = rtl8221b_config_init,
  66. .config_aneg = rtl822x_config_aneg,
  67. + .probe = rtl822x_probe,
  68. .read_status = rtl822x_read_status,
  69. .suspend = genphy_suspend,
  70. .resume = rtlgen_resume,
  71. @@ -1126,6 +1152,7 @@ static struct phy_driver realtek_drvs[]
  72. .get_features = rtl822x_get_features,
  73. .config_aneg = rtl822x_config_aneg,
  74. .config_init = rtl8221b_config_init,
  75. + .probe = rtl822x_probe,
  76. .read_status = rtl822x_read_status,
  77. .suspend = genphy_suspend,
  78. .resume = rtlgen_resume,