1 From ef9df47b449e32e06501a11272809be49019bdb6 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Fri, 8 Dec 2023 15:52:00 +0100
4 Subject: [PATCH 13/13] net: phy: at803x: drop specific PHY ID check from cable
7 Drop specific PHY ID check for cable test functions for at803x. This is
8 done to make functions more generic. While at it better describe what
9 the functions does by using more symbolic function names.
11 PHYs that requires to set additional reg are moved to specific function
12 calling the more generic one.
14 cdt_start and cdt_wait_for_completion are changed to take an additional
15 arg to pass specific values specific to the PHY.
17 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
18 Signed-off-by: David S. Miller <davem@davemloft.net>
20 drivers/net/phy/at803x.c | 95 +++++++++++++++++++++-------------------
21 1 file changed, 50 insertions(+), 45 deletions(-)
23 --- a/drivers/net/phy/at803x.c
24 +++ b/drivers/net/phy/at803x.c
25 @@ -1222,31 +1222,16 @@ static int at803x_cdt_fault_length(u16 s
26 return (dt * 824) / 10;
29 -static int at803x_cdt_start(struct phy_device *phydev, int pair)
30 +static int at803x_cdt_start(struct phy_device *phydev,
35 - /* qca8081 takes the different bit 15 to enable CDT test */
36 - if (phydev->drv->phy_id == QCA8081_PHY_ID)
37 - cdt = QCA808X_CDT_ENABLE_TEST |
38 - QCA808X_CDT_LENGTH_UNIT |
39 - QCA808X_CDT_INTER_CHECK_DIS;
41 - cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
42 - AT803X_CDT_ENABLE_TEST;
44 - return phy_write(phydev, AT803X_CDT, cdt);
45 + return phy_write(phydev, AT803X_CDT, cdt_start);
48 -static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
49 +static int at803x_cdt_wait_for_completion(struct phy_device *phydev,
55 - if (phydev->drv->phy_id == QCA8081_PHY_ID)
56 - cdt_en = QCA808X_CDT_ENABLE_TEST;
58 - cdt_en = AT803X_CDT_ENABLE_TEST;
60 /* One test run takes about 25ms */
61 ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
62 @@ -1266,11 +1251,13 @@ static int at803x_cable_test_one_pair(st
66 - ret = at803x_cdt_start(phydev, pair);
67 + val = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
68 + AT803X_CDT_ENABLE_TEST;
69 + ret = at803x_cdt_start(phydev, val);
73 - ret = at803x_cdt_wait_for_completion(phydev);
74 + ret = at803x_cdt_wait_for_completion(phydev, AT803X_CDT_ENABLE_TEST);
78 @@ -1292,19 +1279,11 @@ static int at803x_cable_test_one_pair(st
81 static int at803x_cable_test_get_status(struct phy_device *phydev,
83 + bool *finished, unsigned long pair_mask)
85 - unsigned long pair_mask;
89 - if (phydev->phy_id == ATH9331_PHY_ID ||
90 - phydev->phy_id == ATH8032_PHY_ID ||
91 - phydev->phy_id == QCA9561_PHY_ID)
98 /* According to the datasheet the CDT can be performed when
99 @@ -1331,7 +1310,7 @@ static int at803x_cable_test_get_status(
103 -static int at803x_cable_test_start(struct phy_device *phydev)
104 +static void at803x_cable_test_autoneg(struct phy_device *phydev)
106 /* Enable auto-negotiation, but advertise no capabilities, no link
107 * will be established. A restart of the auto-negotiation is not
108 @@ -1339,11 +1318,11 @@ static int at803x_cable_test_start(struc
110 phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
111 phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
112 - if (phydev->phy_id != ATH9331_PHY_ID &&
113 - phydev->phy_id != ATH8032_PHY_ID &&
114 - phydev->phy_id != QCA9561_PHY_ID)
115 - phy_write(phydev, MII_CTRL1000, 0);
118 +static int at803x_cable_test_start(struct phy_device *phydev)
120 + at803x_cable_test_autoneg(phydev);
121 /* we do all the (time consuming) work later */
124 @@ -1618,6 +1597,29 @@ static int at8031_config_intr(struct phy
125 return at803x_config_intr(phydev);
128 +/* AR8031 and AR8035 share the same cable test get status reg */
129 +static int at8031_cable_test_get_status(struct phy_device *phydev,
132 + return at803x_cable_test_get_status(phydev, finished, 0xf);
135 +/* AR8031 and AR8035 share the same cable test start logic */
136 +static int at8031_cable_test_start(struct phy_device *phydev)
138 + at803x_cable_test_autoneg(phydev);
139 + phy_write(phydev, MII_CTRL1000, 0);
140 + /* we do all the (time consuming) work later */
144 +/* AR8032, AR9331 and QCA9561 share the same cable test get status reg */
145 +static int at8032_cable_test_get_status(struct phy_device *phydev,
148 + return at803x_cable_test_get_status(phydev, finished, 0x3);
151 static int at8035_parse_dt(struct phy_device *phydev)
153 struct at803x_priv *priv = phydev->priv;
154 @@ -2041,11 +2043,14 @@ static int qca808x_cable_test_get_status
158 - ret = at803x_cdt_start(phydev, 0);
159 + val = QCA808X_CDT_ENABLE_TEST |
160 + QCA808X_CDT_LENGTH_UNIT |
161 + QCA808X_CDT_INTER_CHECK_DIS;
162 + ret = at803x_cdt_start(phydev, val);
166 - ret = at803x_cdt_wait_for_completion(phydev);
167 + ret = at803x_cdt_wait_for_completion(phydev, QCA808X_CDT_ENABLE_TEST);
171 @@ -2143,8 +2148,8 @@ static struct phy_driver at803x_driver[]
172 .handle_interrupt = at803x_handle_interrupt,
173 .get_tunable = at803x_get_tunable,
174 .set_tunable = at803x_set_tunable,
175 - .cable_test_start = at803x_cable_test_start,
176 - .cable_test_get_status = at803x_cable_test_get_status,
177 + .cable_test_start = at8031_cable_test_start,
178 + .cable_test_get_status = at8031_cable_test_get_status,
180 /* Qualcomm Atheros AR8030 */
181 .phy_id = ATH8030_PHY_ID,
182 @@ -2181,8 +2186,8 @@ static struct phy_driver at803x_driver[]
183 .handle_interrupt = at803x_handle_interrupt,
184 .get_tunable = at803x_get_tunable,
185 .set_tunable = at803x_set_tunable,
186 - .cable_test_start = at803x_cable_test_start,
187 - .cable_test_get_status = at803x_cable_test_get_status,
188 + .cable_test_start = at8031_cable_test_start,
189 + .cable_test_get_status = at8031_cable_test_get_status,
191 /* Qualcomm Atheros AR8032 */
192 PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
193 @@ -2197,7 +2202,7 @@ static struct phy_driver at803x_driver[]
194 .config_intr = at803x_config_intr,
195 .handle_interrupt = at803x_handle_interrupt,
196 .cable_test_start = at803x_cable_test_start,
197 - .cable_test_get_status = at803x_cable_test_get_status,
198 + .cable_test_get_status = at8032_cable_test_get_status,
201 PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
202 @@ -2210,7 +2215,7 @@ static struct phy_driver at803x_driver[]
203 .config_intr = at803x_config_intr,
204 .handle_interrupt = at803x_handle_interrupt,
205 .cable_test_start = at803x_cable_test_start,
206 - .cable_test_get_status = at803x_cable_test_get_status,
207 + .cable_test_get_status = at8032_cable_test_get_status,
208 .read_status = at803x_read_status,
209 .soft_reset = genphy_soft_reset,
210 .config_aneg = at803x_config_aneg,
211 @@ -2226,7 +2231,7 @@ static struct phy_driver at803x_driver[]
212 .config_intr = at803x_config_intr,
213 .handle_interrupt = at803x_handle_interrupt,
214 .cable_test_start = at803x_cable_test_start,
215 - .cable_test_get_status = at803x_cable_test_get_status,
216 + .cable_test_get_status = at8032_cable_test_get_status,
217 .read_status = at803x_read_status,
218 .soft_reset = genphy_soft_reset,
219 .config_aneg = at803x_config_aneg,