ebtables: fix compilation with GCC14
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 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 @@ -79,6 +79,7 @@
17 #define RTLGEN_SPEED_MASK 0x0630
18
19 #define RTL_GENERIC_PHYID 0x001cc800
20 +#define RTL_8221B_VB_CG_PHYID 0x001cc849
21
22 MODULE_DESCRIPTION("Realtek PHY driver");
23 MODULE_AUTHOR("Johnson Leung");
24 @@ -744,6 +745,38 @@ static int rtl8226_match_phy_device(stru
25 rtlgen_supports_2_5gbps(phydev);
26 }
27
28 +static int rtl8221b_vb_cg_match_phy_device(struct phy_device *phydev)
29 +{
30 + int val;
31 + u32 id;
32 +
33 + if (phydev->mdio.bus->probe_capabilities >= MDIOBUS_C45) {
34 + val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PKGID1);
35 + if (val < 0)
36 + return 0;
37 +
38 + id = val << 16;
39 + val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PKGID2);
40 + if (val < 0)
41 + return 0;
42 +
43 + id |= val;
44 + } else {
45 + val = phy_read(phydev, MII_PHYSID1);
46 + if (val < 0)
47 + return 0;
48 +
49 + id = val << 16;
50 + val = phy_read(phydev, MII_PHYSID2);
51 + if (val < 0)
52 + return 0;
53 +
54 + id |= val;
55 + }
56 +
57 + return (id == RTL_8221B_VB_CG_PHYID);
58 +}
59 +
60 static int rtl822x_probe(struct phy_device *phydev)
61 {
62 struct device *dev = &phydev->mdio.dev;
63 @@ -1082,7 +1115,7 @@ static struct phy_driver realtek_drvs[]
64 .write_page = rtl821x_write_page,
65 .soft_reset = genphy_soft_reset,
66 }, {
67 - PHY_ID_MATCH_EXACT(0x001cc849),
68 + .match_phy_device = rtl8221b_vb_cg_match_phy_device,
69 .name = "RTL8221B-VB-CG 2.5Gbps PHY",
70 .get_features = rtl822x_get_features,
71 .config_init = rtl8221b_config_init,