730-net-phy-realtek-detect-early-version-of-RTL8221B.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From e52faf1564a8bcaf866f9a6c7bf0e8a8748afb15 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Sun, 30 Apr 2023 00:15:41 +0100
  4. Subject: [PATCH] net: phy: realtek: detect early version of RTL8221B
  5. Early versions (?) of the RTL8221B PHY cannot be identified in a regular
  6. Clause-45 bus scan as the PHY doesn't report the implemented MMDs
  7. correctly but returns 0 instead.
  8. Implement custom identify function using the PKGID instead of iterating
  9. over the implemented MMDs.
  10. Signed-off-by: Daniel Golle <[email protected]>
  11. ---
  12. drivers/net/phy/realtek.c | 50 ++++++++++++++++++++++++++++++++++++++-
  13. 1 file changed, 49 insertions(+), 1 deletion(-)
  14. --- a/drivers/net/phy/realtek.c
  15. +++ b/drivers/net/phy/realtek.c
  16. @@ -81,6 +81,7 @@
  17. #define RTL_GENERIC_PHYID 0x001cc800
  18. #define RTL_8211FVD_PHYID 0x001cc878
  19. +#define RTL_8221B_VB_CG 0x001cc849
  20. MODULE_DESCRIPTION("Realtek PHY driver");
  21. MODULE_AUTHOR("Johnson Leung");
  22. @@ -801,6 +802,54 @@ static int rtl822x_probe(struct phy_devi
  23. return 0;
  24. }
  25. +static int rtl8221b_vb_cg_match_phy_device(struct phy_device *phydev)
  26. +{
  27. + int val;
  28. + u32 id;
  29. +
  30. + if (phydev->is_c45) {
  31. + if (phydev->c45_ids.device_ids[1])
  32. + return phydev->c45_ids.device_ids[1] == RTL_8221B_VB_CG;
  33. + } else {
  34. + if (phydev->phy_id)
  35. + return phydev->phy_id == RTL_8221B_VB_CG;
  36. + }
  37. +
  38. + if (phydev->mdio.bus->read_c45) {
  39. + val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PKGID1);
  40. + if (val < 0)
  41. + return 0;
  42. +
  43. + id = val << 16;
  44. + val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PKGID2);
  45. + if (val < 0)
  46. + return 0;
  47. +
  48. + id |= val;
  49. + } else {
  50. + val = phy_read(phydev, MII_PHYSID1);
  51. + if (val < 0)
  52. + return 0;
  53. +
  54. + id = val << 16;
  55. + val = phy_read(phydev, MII_PHYSID2);
  56. + if (val < 0)
  57. + return 0;
  58. +
  59. + id |= val;
  60. + }
  61. +
  62. + if (id != RTL_8221B_VB_CG)
  63. + return 0;
  64. +
  65. + if (phydev->is_c45)
  66. + phydev->c45_ids.device_ids[1] = id;
  67. + else
  68. + phydev->phy_id = id;
  69. +
  70. + return 1;
  71. +}
  72. +
  73. static int rtlgen_resume(struct phy_device *phydev)
  74. {
  75. int ret = genphy_resume(phydev);
  76. @@ -1134,7 +1183,7 @@ static struct phy_driver realtek_drvs[]
  77. .write_page = rtl821x_write_page,
  78. .soft_reset = genphy_soft_reset,
  79. }, {
  80. - PHY_ID_MATCH_EXACT(0x001cc849),
  81. + .match_phy_device = rtl8221b_vb_cg_match_phy_device,
  82. .name = "RTL8221B-VB-CG 2.5Gbps PHY",
  83. .get_features = rtl822x_get_features,
  84. .config_init = rtl8221b_config_init,