5c7130d2e03a406b93902fe222c856b59e506207
[openwrt/staging/wigyori.git] /
1 From 2e4ea707c7e04eb83e58c43e0e744bbdf6b23ff2 Mon Sep 17 00:00:00 2001
2 From: Eric Woudstra <ericwouds@gmail.com>
3 Date: Tue, 9 Apr 2024 09:30:14 +0200
4 Subject: [PATCH] net: phy: realtek: Change rtlgen_get_speed() to
5 rtlgen_decode_speed()
6
7 The value of the register to determine the speed, is retrieved
8 differently when using Clause 45 only. To use the rtlgen_get_speed()
9 function in this case, pass the value of the register as argument to
10 rtlgen_get_speed(). The function would then always return 0, so change it
11 to void. A better name for this function now is rtlgen_decode_speed().
12
13 Replace a call to genphy_read_status() followed by rtlgen_get_speed()
14 with a call to rtlgen_read_status() in rtl822x_read_status().
15
16 Add reading speed to rtl822x_c45_read_status().
17
18 Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
19
20 Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22 ---
23 drivers/net/phy/realtek.c | 46 +++++++++++++++++++++------------------
24 1 file changed, 25 insertions(+), 21 deletions(-)
25
26 --- a/drivers/net/phy/realtek.c
27 +++ b/drivers/net/phy/realtek.c
28 @@ -71,6 +71,8 @@
29
30 #define RTL822X_VND2_GANLPAR 0xa414
31
32 +#define RTL822X_VND2_PHYSR 0xa434
33 +
34 #define RTL8366RB_POWER_SAVE 0x15
35 #define RTL8366RB_POWER_SAVE_ON BIT(12)
36
37 @@ -551,17 +553,8 @@ static int rtl8366rb_config_init(struct
38 }
39
40 /* get actual speed to cover the downshift case */
41 -static int rtlgen_get_speed(struct phy_device *phydev)
42 +static void rtlgen_decode_speed(struct phy_device *phydev, int val)
43 {
44 - int val;
45 -
46 - if (!phydev->link)
47 - return 0;
48 -
49 - val = phy_read_paged(phydev, 0xa43, 0x12);
50 - if (val < 0)
51 - return val;
52 -
53 switch (val & RTLGEN_SPEED_MASK) {
54 case 0x0000:
55 phydev->speed = SPEED_10;
56 @@ -584,19 +577,26 @@ static int rtlgen_get_speed(struct phy_d
57 default:
58 break;
59 }
60 -
61 - return 0;
62 }
63
64 static int rtlgen_read_status(struct phy_device *phydev)
65 {
66 - int ret;
67 + int ret, val;
68
69 ret = genphy_read_status(phydev);
70 if (ret < 0)
71 return ret;
72
73 - return rtlgen_get_speed(phydev);
74 + if (!phydev->link)
75 + return 0;
76 +
77 + val = phy_read_paged(phydev, 0xa43, 0x12);
78 + if (val < 0)
79 + return val;
80 +
81 + rtlgen_decode_speed(phydev, val);
82 +
83 + return 0;
84 }
85
86 static int rtlgen_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
87 @@ -817,8 +817,6 @@ static void rtl822xb_update_interface(st
88
89 static int rtl822x_read_status(struct phy_device *phydev)
90 {
91 - int ret;
92 -
93 if (phydev->autoneg == AUTONEG_ENABLE) {
94 int lpadv = phy_read_paged(phydev, 0xa5d, 0x13);
95
96 @@ -829,11 +827,7 @@ static int rtl822x_read_status(struct ph
97 lpadv);
98 }
99
100 - ret = genphy_read_status(phydev);
101 - if (ret < 0)
102 - return ret;
103 -
104 - return rtlgen_get_speed(phydev);
105 + return rtlgen_read_status(phydev);
106 }
107
108 static int rtl822xb_read_status(struct phy_device *phydev)
109 @@ -894,6 +888,16 @@ static int rtl822x_c45_read_status(struc
110 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
111 }
112
113 + if (!phydev->link)
114 + return 0;
115 +
116 + /* Read actual speed from vendor register. */
117 + val = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_PHYSR);
118 + if (val < 0)
119 + return val;
120 +
121 + rtlgen_decode_speed(phydev, val);
122 +
123 return 0;
124 }
125