|
| 1 | +From f87a17ed3b51fba4dfdd8f8b643b5423a85fc551 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Heiner Kallweit <hkallweit1@gmail.com> |
| 3 | +Date: Tue, 15 Oct 2024 07:47:14 +0200 |
| 4 | +Subject: [PATCH] net: phy: realtek: merge the drivers for internal NBase-T |
| 5 | + PHY's |
| 6 | + |
| 7 | +The Realtek RTL8125/RTL8126 NBase-T MAC/PHY chips have internal PHY's |
| 8 | +which are register-compatible, at least for the registers we use here. |
| 9 | +So let's use just one PHY driver to support all of them. |
| 10 | +These internal PHY's exist also as external C45 PHY's, but on the |
| 11 | +internal PHY's no access to MMD registers is possible. This can be |
| 12 | +used to differentiate between the internal and external version. |
| 13 | + |
| 14 | +As a side effect the drivers for two now external-only drivers don't |
| 15 | +require read_mmd/write_mmd hooks any longer. |
| 16 | + |
| 17 | +Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> |
| 18 | +Link: https://patch.msgid.link/c57081a6-811f-4571-ab35-34f4ca6de9af@gmail.com |
| 19 | +Signed-off-by: Paolo Abeni <pabeni@redhat.com> |
| 20 | +--- |
| 21 | + drivers/net/phy/realtek.c | 53 +++++++++++++++++++++++++++++++-------- |
| 22 | + 1 file changed, 43 insertions(+), 10 deletions(-) |
| 23 | + |
| 24 | +diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c |
| 25 | +index 905038b1bb6414..66646212053173 100644 |
| 26 | +--- a/drivers/net/phy/realtek.c |
| 27 | ++++ b/drivers/net/phy/realtek.c |
| 28 | +@@ -95,6 +95,7 @@ |
| 29 | + |
| 30 | + #define RTL_GENERIC_PHYID 0x001cc800 |
| 31 | + #define RTL_8211FVD_PHYID 0x001cc878 |
| 32 | ++#define RTL_8221B 0x001cc840 |
| 33 | + #define RTL_8221B_VB_CG 0x001cc849 |
| 34 | + #define RTL_8221B_VN_CG 0x001cc84a |
| 35 | + #define RTL_8251B 0x001cc862 |
| 36 | +@@ -1077,6 +1078,23 @@ static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) |
| 37 | + return val >= 0 && val & MDIO_PMA_SPEED_2_5G; |
| 38 | + } |
| 39 | + |
| 40 | ++/* On internal PHY's MMD reads over C22 always return 0. |
| 41 | ++ * Check a MMD register which is known to be non-zero. |
| 42 | ++ */ |
| 43 | ++static bool rtlgen_supports_mmd(struct phy_device *phydev) |
| 44 | ++{ |
| 45 | ++ int val; |
| 46 | ++ |
| 47 | ++ phy_lock_mdio_bus(phydev); |
| 48 | ++ __phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS); |
| 49 | ++ __phy_write(phydev, MII_MMD_DATA, MDIO_PCS_EEE_ABLE); |
| 50 | ++ __phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS | MII_MMD_CTRL_NOINCR); |
| 51 | ++ val = __phy_read(phydev, MII_MMD_DATA); |
| 52 | ++ phy_unlock_mdio_bus(phydev); |
| 53 | ++ |
| 54 | ++ return val > 0; |
| 55 | ++} |
| 56 | ++ |
| 57 | + static int rtlgen_match_phy_device(struct phy_device *phydev) |
| 58 | + { |
| 59 | + return phydev->phy_id == RTL_GENERIC_PHYID && |
| 60 | +@@ -1086,7 +1104,8 @@ static int rtlgen_match_phy_device(struct phy_device *phydev) |
| 61 | + static int rtl8226_match_phy_device(struct phy_device *phydev) |
| 62 | + { |
| 63 | + return phydev->phy_id == RTL_GENERIC_PHYID && |
| 64 | +- rtlgen_supports_2_5gbps(phydev); |
| 65 | ++ rtlgen_supports_2_5gbps(phydev) && |
| 66 | ++ rtlgen_supports_mmd(phydev); |
| 67 | + } |
| 68 | + |
| 69 | + static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id, |
| 70 | +@@ -1098,6 +1117,11 @@ static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id, |
| 71 | + return !is_c45 && (id == phydev->phy_id); |
| 72 | + } |
| 73 | + |
| 74 | ++static int rtl8221b_match_phy_device(struct phy_device *phydev) |
| 75 | ++{ |
| 76 | ++ return phydev->phy_id == RTL_8221B && rtlgen_supports_mmd(phydev); |
| 77 | ++} |
| 78 | ++ |
| 79 | + static int rtl8221b_vb_cg_c22_match_phy_device(struct phy_device *phydev) |
| 80 | + { |
| 81 | + return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, false); |
| 82 | +@@ -1118,9 +1142,21 @@ static int rtl8221b_vn_cg_c45_match_phy_device(struct phy_device *phydev) |
| 83 | + return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, true); |
| 84 | + } |
| 85 | + |
| 86 | +-static int rtl8251b_c22_match_phy_device(struct phy_device *phydev) |
| 87 | ++static int rtl_internal_nbaset_match_phy_device(struct phy_device *phydev) |
| 88 | + { |
| 89 | +- return rtlgen_is_c45_match(phydev, RTL_8251B, false); |
| 90 | ++ if (phydev->is_c45) |
| 91 | ++ return false; |
| 92 | ++ |
| 93 | ++ switch (phydev->phy_id) { |
| 94 | ++ case RTL_GENERIC_PHYID: |
| 95 | ++ case RTL_8221B: |
| 96 | ++ case RTL_8251B: |
| 97 | ++ break; |
| 98 | ++ default: |
| 99 | ++ return false; |
| 100 | ++ } |
| 101 | ++ |
| 102 | ++ return rtlgen_supports_2_5gbps(phydev) && !rtlgen_supports_mmd(phydev); |
| 103 | + } |
| 104 | + |
| 105 | + static int rtl8251b_c45_match_phy_device(struct phy_device *phydev) |
| 106 | +@@ -1382,10 +1418,8 @@ static struct phy_driver realtek_drvs[] = { |
| 107 | + .resume = rtlgen_resume, |
| 108 | + .read_page = rtl821x_read_page, |
| 109 | + .write_page = rtl821x_write_page, |
| 110 | +- .read_mmd = rtl822x_read_mmd, |
| 111 | +- .write_mmd = rtl822x_write_mmd, |
| 112 | + }, { |
| 113 | +- PHY_ID_MATCH_EXACT(0x001cc840), |
| 114 | ++ .match_phy_device = rtl8221b_match_phy_device, |
| 115 | + .name = "RTL8226B_RTL8221B 2.5Gbps PHY", |
| 116 | + .get_features = rtl822x_get_features, |
| 117 | + .config_aneg = rtl822x_config_aneg, |
| 118 | +@@ -1396,8 +1430,6 @@ static struct phy_driver realtek_drvs[] = { |
| 119 | + .resume = rtlgen_resume, |
| 120 | + .read_page = rtl821x_read_page, |
| 121 | + .write_page = rtl821x_write_page, |
| 122 | +- .read_mmd = rtl822x_read_mmd, |
| 123 | +- .write_mmd = rtl822x_write_mmd, |
| 124 | + }, { |
| 125 | + PHY_ID_MATCH_EXACT(0x001cc838), |
| 126 | + .name = "RTL8226-CG 2.5Gbps PHY", |
| 127 | +@@ -1475,8 +1507,9 @@ static struct phy_driver realtek_drvs[] = { |
| 128 | + .read_page = rtl821x_read_page, |
| 129 | + .write_page = rtl821x_write_page, |
| 130 | + }, { |
| 131 | +- .match_phy_device = rtl8251b_c22_match_phy_device, |
| 132 | +- .name = "RTL8126A-internal 5Gbps PHY", |
| 133 | ++ .match_phy_device = rtl_internal_nbaset_match_phy_device, |
| 134 | ++ .name = "Realtek Internal NBASE-T PHY", |
| 135 | ++ .flags = PHY_IS_INTERNAL, |
| 136 | + .get_features = rtl822x_get_features, |
| 137 | + .config_aneg = rtl822x_config_aneg, |
| 138 | + .read_status = rtl822x_read_status, |
0 commit comments