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