Skip to content

Commit 5eb0b10

Browse files
hkallweitgregkh
authored andcommitted
net: phy: realtek: merge the drivers for internal NBase-T PHY's
commit f87a17e upstream. The Realtek RTL8125/RTL8126 NBase-T MAC/PHY chips have internal PHY's which are register-compatible, at least for the registers we use here. So let's use just one PHY driver to support all of them. These internal PHY's exist also as external C45 PHY's, but on the internal PHY's no access to MMD registers is possible. This can be used to differentiate between the internal and external version. As a side effect the drivers for two now external-only drivers don't require read_mmd/write_mmd hooks any longer. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Link: https://patch.msgid.link/c57081a6-811f-4571-ab35-34f4ca6de9af@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 37cb596 commit 5eb0b10

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

drivers/net/phy/realtek.c

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292

9393
#define RTL_GENERIC_PHYID 0x001cc800
9494
#define RTL_8211FVD_PHYID 0x001cc878
95+
#define RTL_8221B 0x001cc840
9596
#define RTL_8221B_VB_CG 0x001cc849
9697
#define RTL_8221B_VN_CG 0x001cc84a
9798
#define RTL_8251B 0x001cc862
@@ -1040,6 +1041,23 @@ static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
10401041
return val >= 0 && val & MDIO_PMA_SPEED_2_5G;
10411042
}
10421043

1044+
/* On internal PHY's MMD reads over C22 always return 0.
1045+
* Check a MMD register which is known to be non-zero.
1046+
*/
1047+
static bool rtlgen_supports_mmd(struct phy_device *phydev)
1048+
{
1049+
int val;
1050+
1051+
phy_lock_mdio_bus(phydev);
1052+
__phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS);
1053+
__phy_write(phydev, MII_MMD_DATA, MDIO_PCS_EEE_ABLE);
1054+
__phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS | MII_MMD_CTRL_NOINCR);
1055+
val = __phy_read(phydev, MII_MMD_DATA);
1056+
phy_unlock_mdio_bus(phydev);
1057+
1058+
return val > 0;
1059+
}
1060+
10431061
static int rtlgen_match_phy_device(struct phy_device *phydev)
10441062
{
10451063
return phydev->phy_id == RTL_GENERIC_PHYID &&
@@ -1049,7 +1067,8 @@ static int rtlgen_match_phy_device(struct phy_device *phydev)
10491067
static int rtl8226_match_phy_device(struct phy_device *phydev)
10501068
{
10511069
return phydev->phy_id == RTL_GENERIC_PHYID &&
1052-
rtlgen_supports_2_5gbps(phydev);
1070+
rtlgen_supports_2_5gbps(phydev) &&
1071+
rtlgen_supports_mmd(phydev);
10531072
}
10541073

10551074
static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id,
@@ -1061,6 +1080,11 @@ static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id,
10611080
return !is_c45 && (id == phydev->phy_id);
10621081
}
10631082

1083+
static int rtl8221b_match_phy_device(struct phy_device *phydev)
1084+
{
1085+
return phydev->phy_id == RTL_8221B && rtlgen_supports_mmd(phydev);
1086+
}
1087+
10641088
static int rtl8221b_vb_cg_c22_match_phy_device(struct phy_device *phydev)
10651089
{
10661090
return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, false);
@@ -1081,9 +1105,21 @@ static int rtl8221b_vn_cg_c45_match_phy_device(struct phy_device *phydev)
10811105
return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, true);
10821106
}
10831107

1084-
static int rtl8251b_c22_match_phy_device(struct phy_device *phydev)
1108+
static int rtl_internal_nbaset_match_phy_device(struct phy_device *phydev)
10851109
{
1086-
return rtlgen_is_c45_match(phydev, RTL_8251B, false);
1110+
if (phydev->is_c45)
1111+
return false;
1112+
1113+
switch (phydev->phy_id) {
1114+
case RTL_GENERIC_PHYID:
1115+
case RTL_8221B:
1116+
case RTL_8251B:
1117+
break;
1118+
default:
1119+
return false;
1120+
}
1121+
1122+
return rtlgen_supports_2_5gbps(phydev) && !rtlgen_supports_mmd(phydev);
10871123
}
10881124

10891125
static int rtl8251b_c45_match_phy_device(struct phy_device *phydev)
@@ -1345,10 +1381,8 @@ static struct phy_driver realtek_drvs[] = {
13451381
.resume = rtlgen_resume,
13461382
.read_page = rtl821x_read_page,
13471383
.write_page = rtl821x_write_page,
1348-
.read_mmd = rtl822x_read_mmd,
1349-
.write_mmd = rtl822x_write_mmd,
13501384
}, {
1351-
PHY_ID_MATCH_EXACT(0x001cc840),
1385+
.match_phy_device = rtl8221b_match_phy_device,
13521386
.name = "RTL8226B_RTL8221B 2.5Gbps PHY",
13531387
.get_features = rtl822x_get_features,
13541388
.config_aneg = rtl822x_config_aneg,
@@ -1359,8 +1393,6 @@ static struct phy_driver realtek_drvs[] = {
13591393
.resume = rtlgen_resume,
13601394
.read_page = rtl821x_read_page,
13611395
.write_page = rtl821x_write_page,
1362-
.read_mmd = rtl822x_read_mmd,
1363-
.write_mmd = rtl822x_write_mmd,
13641396
}, {
13651397
PHY_ID_MATCH_EXACT(0x001cc838),
13661398
.name = "RTL8226-CG 2.5Gbps PHY",
@@ -1438,8 +1470,9 @@ static struct phy_driver realtek_drvs[] = {
14381470
.read_page = rtl821x_read_page,
14391471
.write_page = rtl821x_write_page,
14401472
}, {
1441-
.match_phy_device = rtl8251b_c22_match_phy_device,
1442-
.name = "RTL8126A-internal 5Gbps PHY",
1473+
.match_phy_device = rtl_internal_nbaset_match_phy_device,
1474+
.name = "Realtek Internal NBASE-T PHY",
1475+
.flags = PHY_IS_INTERNAL,
14431476
.get_features = rtl822x_get_features,
14441477
.config_aneg = rtl822x_config_aneg,
14451478
.read_status = rtl822x_read_status,

0 commit comments

Comments
 (0)