b5dbfa383a2b6420a08c4c12fcae59edd488bccb
[openwrt/staging/hauke.git] / target / linux / generic / pending-6.1 / 729-net-phy-realtek-introduce-rtl822x_probe.patch
1 From 9155098547fb1172d4fa536f3f6bc9d42f59d08c Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sat, 22 Apr 2023 03:26:01 +0100
4 Subject: [PATCH] net: phy: realtek: setup ALDPS on RTL822x
5
6 Setup Link Down Power Saving Mode according the DTS property
7 just like for RTL821x 1GE PHYs.
8
9 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
10 ---
11 drivers/net/phy/realtek.c | 11 +++++++++++
12 1 file changed, 11 insertions(+)
13
14 --- a/drivers/net/phy/realtek.c
15 +++ b/drivers/net/phy/realtek.c
16 @@ -62,6 +62,10 @@
17 #define RTL8221B_SERDES_OPTION_MODE_2500BASEX 2
18 #define RTL8221B_SERDES_OPTION_MODE_HISGMII 3
19
20 +#define RTL8221B_PHYCR1 0xa430
21 +#define RTL8221B_PHYCR1_ALDPS_EN BIT(2)
22 +#define RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN BIT(12)
23 +
24 #define RTL8366RB_POWER_SAVE 0x15
25 #define RTL8366RB_POWER_SAVE_ON BIT(12)
26
27 @@ -748,6 +752,25 @@ static int rtl8226_match_phy_device(stru
28 rtlgen_supports_2_5gbps(phydev);
29 }
30
31 +static int rtl822x_probe(struct phy_device *phydev)
32 +{
33 + struct device *dev = &phydev->mdio.dev;
34 + int val;
35 +
36 + val = phy_read_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, RTL8221B_PHYCR1);
37 + if (val < 0)
38 + return val;
39 +
40 + if (of_property_read_bool(dev->of_node, "realtek,aldps-enable"))
41 + val |= RTL8221B_PHYCR1_ALDPS_EN | RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN;
42 + else
43 + val &= ~(RTL8221B_PHYCR1_ALDPS_EN | RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN);
44 +
45 + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, RTL8221B_PHYCR1, val);
46 +
47 + return 0;
48 +}
49 +
50 static int rtlgen_resume(struct phy_device *phydev)
51 {
52 int ret = genphy_resume(phydev);
53 @@ -1033,6 +1056,7 @@ static struct phy_driver realtek_drvs[]
54 .match_phy_device = rtl8226_match_phy_device,
55 .get_features = rtl822x_get_features,
56 .config_aneg = rtl822x_config_aneg,
57 + .probe = rtl822x_probe,
58 .read_status = rtl822x_read_status,
59 .suspend = genphy_suspend,
60 .resume = rtlgen_resume,
61 @@ -1046,6 +1070,7 @@ static struct phy_driver realtek_drvs[]
62 .name = "RTL8226B_RTL8221B 2.5Gbps PHY",
63 .get_features = rtl822x_get_features,
64 .config_aneg = rtl822x_config_aneg,
65 + .probe = rtl822x_probe,
66 .read_status = rtl822x_read_status,
67 .suspend = genphy_suspend,
68 .resume = rtlgen_resume,
69 @@ -1059,6 +1084,7 @@ static struct phy_driver realtek_drvs[]
70 .name = "RTL8226-CG 2.5Gbps PHY",
71 .get_features = rtl822x_get_features,
72 .config_aneg = rtl822x_config_aneg,
73 + .probe = rtl822x_probe,
74 .read_status = rtl822x_read_status,
75 .suspend = genphy_suspend,
76 .resume = rtlgen_resume,
77 @@ -1070,6 +1096,7 @@ static struct phy_driver realtek_drvs[]
78 .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY",
79 .get_features = rtl822x_get_features,
80 .config_aneg = rtl822x_config_aneg,
81 + .probe = rtl822x_probe,
82 .read_status = rtl822x_read_status,
83 .suspend = genphy_suspend,
84 .resume = rtlgen_resume,
85 @@ -1082,6 +1109,7 @@ static struct phy_driver realtek_drvs[]
86 .get_features = rtl822x_get_features,
87 .config_init = rtl8221b_config_init,
88 .config_aneg = rtl822x_config_aneg,
89 + .probe = rtl822x_probe,
90 .read_status = rtl822x_read_status,
91 .suspend = genphy_suspend,
92 .resume = rtlgen_resume,
93 @@ -1094,6 +1122,7 @@ static struct phy_driver realtek_drvs[]
94 .get_features = rtl822x_get_features,
95 .config_aneg = rtl822x_config_aneg,
96 .config_init = rtl8221b_config_init,
97 + .probe = rtl822x_probe,
98 .read_status = rtl822x_read_status,
99 .suspend = genphy_suspend,
100 .resume = rtlgen_resume,