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
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().
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().
16 Add reading speed to rtl822x_c45_read_status().
18 Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
20 Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
23 drivers/net/phy/realtek.c | 46 +++++++++++++++++++++------------------
24 1 file changed, 25 insertions(+), 21 deletions(-)
26 --- a/drivers/net/phy/realtek.c
27 +++ b/drivers/net/phy/realtek.c
30 #define RTL822X_VND2_GANLPAR 0xa414
32 +#define RTL822X_VND2_PHYSR 0xa434
34 #define RTL8366RB_POWER_SAVE 0x15
35 #define RTL8366RB_POWER_SAVE_ON BIT(12)
37 @@ -551,17 +553,8 @@ static int rtl8366rb_config_init(struct
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)
49 - val = phy_read_paged(phydev, 0xa43, 0x12);
53 switch (val & RTLGEN_SPEED_MASK) {
55 phydev->speed = SPEED_10;
56 @@ -584,19 +577,26 @@ static int rtlgen_get_speed(struct phy_d
64 static int rtlgen_read_status(struct phy_device *phydev)
69 ret = genphy_read_status(phydev);
73 - return rtlgen_get_speed(phydev);
77 + val = phy_read_paged(phydev, 0xa43, 0x12);
81 + rtlgen_decode_speed(phydev, val);
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
89 static int rtl822x_read_status(struct phy_device *phydev)
93 if (phydev->autoneg == AUTONEG_ENABLE) {
94 int lpadv = phy_read_paged(phydev, 0xa5d, 0x13);
96 @@ -829,11 +827,7 @@ static int rtl822x_read_status(struct ph
100 - ret = genphy_read_status(phydev);
104 - return rtlgen_get_speed(phydev);
105 + return rtlgen_read_status(phydev);
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);
116 + /* Read actual speed from vendor register. */
117 + val = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_PHYSR);
121 + rtlgen_decode_speed(phydev, val);