97e128ccdb77c3e259b9deb86012f441aada7484
[openwrt/staging/stintel.git] / target / linux / generic / pending-6.1 / 730-net-phy-realtek-detect-early-version-of-RTL8221B.patch
1 From 0de82310d2b32e78ff79d42c08b1122a6ede3778 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 --- a/drivers/net/phy/realtek.c
15 +++ b/drivers/net/phy/realtek.c
16 @@ -752,6 +752,38 @@ static int rtl8226_match_phy_device(stru
17 rtlgen_supports_2_5gbps(phydev);
18 }
19
20 +static int rtl8221b_vb_cg_match_phy_device(struct phy_device *phydev)
21 +{
22 + int val;
23 + u32 id;
24 +
25 + if (phydev->mdio.bus->probe_capabilities >= MDIOBUS_C45) {
26 + val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PKGID1);
27 + if (val < 0)
28 + return 0;
29 +
30 + id = val << 16;
31 + val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PKGID2);
32 + if (val < 0)
33 + return 0;
34 +
35 + id |= val;
36 + } else {
37 + val = phy_read(phydev, MII_PHYSID1);
38 + if (val < 0)
39 + return 0;
40 +
41 + id = val << 16;
42 + val = phy_read(phydev, MII_PHYSID2);
43 + if (val < 0)
44 + return 0;
45 +
46 + id |= val;
47 + }
48 +
49 + return (id == 0x001cc849);
50 +}
51 +
52 static int rtl822x_probe(struct phy_device *phydev)
53 {
54 struct device *dev = &phydev->mdio.dev;
55 @@ -1102,7 +1134,7 @@ static struct phy_driver realtek_drvs[]
56 .write_page = rtl821x_write_page,
57 .soft_reset = genphy_soft_reset,
58 }, {
59 - PHY_ID_MATCH_EXACT(0x001cc849),
60 + .match_phy_device = rtl8221b_vb_cg_match_phy_device,
61 .name = "RTL8221B-VB-CG 2.5Gbps PHY",
62 .get_features = rtl822x_get_features,
63 .config_init = rtl8221b_config_init,