Skip to content

Commit ef9df47

Browse files
Ansueldavem330
authored andcommitted
net: phy: at803x: drop specific PHY ID check from cable test functions
Drop specific PHY ID check for cable test functions for at803x. This is done to make functions more generic. While at it better describe what the functions does by using more symbolic function names. PHYs that requires to set additional reg are moved to specific function calling the more generic one. cdt_start and cdt_wait_for_completion are changed to take an additional arg to pass specific values specific to the PHY. Signed-off-by: Christian Marangi <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 21a2802 commit ef9df47

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

drivers/net/phy/at803x.c

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,31 +1222,16 @@ static int at803x_cdt_fault_length(u16 status)
12221222
return (dt * 824) / 10;
12231223
}
12241224

1225-
static int at803x_cdt_start(struct phy_device *phydev, int pair)
1225+
static int at803x_cdt_start(struct phy_device *phydev,
1226+
u32 cdt_start)
12261227
{
1227-
u16 cdt;
1228-
1229-
/* qca8081 takes the different bit 15 to enable CDT test */
1230-
if (phydev->drv->phy_id == QCA8081_PHY_ID)
1231-
cdt = QCA808X_CDT_ENABLE_TEST |
1232-
QCA808X_CDT_LENGTH_UNIT |
1233-
QCA808X_CDT_INTER_CHECK_DIS;
1234-
else
1235-
cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
1236-
AT803X_CDT_ENABLE_TEST;
1237-
1238-
return phy_write(phydev, AT803X_CDT, cdt);
1228+
return phy_write(phydev, AT803X_CDT, cdt_start);
12391229
}
12401230

1241-
static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
1231+
static int at803x_cdt_wait_for_completion(struct phy_device *phydev,
1232+
u32 cdt_en)
12421233
{
12431234
int val, ret;
1244-
u16 cdt_en;
1245-
1246-
if (phydev->drv->phy_id == QCA8081_PHY_ID)
1247-
cdt_en = QCA808X_CDT_ENABLE_TEST;
1248-
else
1249-
cdt_en = AT803X_CDT_ENABLE_TEST;
12501235

12511236
/* One test run takes about 25ms */
12521237
ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
@@ -1266,11 +1251,13 @@ static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
12661251
};
12671252
int ret, val;
12681253

1269-
ret = at803x_cdt_start(phydev, pair);
1254+
val = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
1255+
AT803X_CDT_ENABLE_TEST;
1256+
ret = at803x_cdt_start(phydev, val);
12701257
if (ret)
12711258
return ret;
12721259

1273-
ret = at803x_cdt_wait_for_completion(phydev);
1260+
ret = at803x_cdt_wait_for_completion(phydev, AT803X_CDT_ENABLE_TEST);
12741261
if (ret)
12751262
return ret;
12761263

@@ -1292,19 +1279,11 @@ static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
12921279
}
12931280

12941281
static int at803x_cable_test_get_status(struct phy_device *phydev,
1295-
bool *finished)
1282+
bool *finished, unsigned long pair_mask)
12961283
{
1297-
unsigned long pair_mask;
12981284
int retries = 20;
12991285
int pair, ret;
13001286

1301-
if (phydev->phy_id == ATH9331_PHY_ID ||
1302-
phydev->phy_id == ATH8032_PHY_ID ||
1303-
phydev->phy_id == QCA9561_PHY_ID)
1304-
pair_mask = 0x3;
1305-
else
1306-
pair_mask = 0xf;
1307-
13081287
*finished = false;
13091288

13101289
/* According to the datasheet the CDT can be performed when
@@ -1331,19 +1310,19 @@ static int at803x_cable_test_get_status(struct phy_device *phydev,
13311310
return 0;
13321311
}
13331312

1334-
static int at803x_cable_test_start(struct phy_device *phydev)
1313+
static void at803x_cable_test_autoneg(struct phy_device *phydev)
13351314
{
13361315
/* Enable auto-negotiation, but advertise no capabilities, no link
13371316
* will be established. A restart of the auto-negotiation is not
13381317
* required, because the cable test will automatically break the link.
13391318
*/
13401319
phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
13411320
phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
1342-
if (phydev->phy_id != ATH9331_PHY_ID &&
1343-
phydev->phy_id != ATH8032_PHY_ID &&
1344-
phydev->phy_id != QCA9561_PHY_ID)
1345-
phy_write(phydev, MII_CTRL1000, 0);
1321+
}
13461322

1323+
static int at803x_cable_test_start(struct phy_device *phydev)
1324+
{
1325+
at803x_cable_test_autoneg(phydev);
13471326
/* we do all the (time consuming) work later */
13481327
return 0;
13491328
}
@@ -1618,6 +1597,29 @@ static int at8031_config_intr(struct phy_device *phydev)
16181597
return at803x_config_intr(phydev);
16191598
}
16201599

1600+
/* AR8031 and AR8035 share the same cable test get status reg */
1601+
static int at8031_cable_test_get_status(struct phy_device *phydev,
1602+
bool *finished)
1603+
{
1604+
return at803x_cable_test_get_status(phydev, finished, 0xf);
1605+
}
1606+
1607+
/* AR8031 and AR8035 share the same cable test start logic */
1608+
static int at8031_cable_test_start(struct phy_device *phydev)
1609+
{
1610+
at803x_cable_test_autoneg(phydev);
1611+
phy_write(phydev, MII_CTRL1000, 0);
1612+
/* we do all the (time consuming) work later */
1613+
return 0;
1614+
}
1615+
1616+
/* AR8032, AR9331 and QCA9561 share the same cable test get status reg */
1617+
static int at8032_cable_test_get_status(struct phy_device *phydev,
1618+
bool *finished)
1619+
{
1620+
return at803x_cable_test_get_status(phydev, finished, 0x3);
1621+
}
1622+
16211623
static int at8035_parse_dt(struct phy_device *phydev)
16221624
{
16231625
struct at803x_priv *priv = phydev->priv;
@@ -2041,11 +2043,14 @@ static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finish
20412043

20422044
*finished = false;
20432045

2044-
ret = at803x_cdt_start(phydev, 0);
2046+
val = QCA808X_CDT_ENABLE_TEST |
2047+
QCA808X_CDT_LENGTH_UNIT |
2048+
QCA808X_CDT_INTER_CHECK_DIS;
2049+
ret = at803x_cdt_start(phydev, val);
20452050
if (ret)
20462051
return ret;
20472052

2048-
ret = at803x_cdt_wait_for_completion(phydev);
2053+
ret = at803x_cdt_wait_for_completion(phydev, QCA808X_CDT_ENABLE_TEST);
20492054
if (ret)
20502055
return ret;
20512056

@@ -2143,8 +2148,8 @@ static struct phy_driver at803x_driver[] = {
21432148
.handle_interrupt = at803x_handle_interrupt,
21442149
.get_tunable = at803x_get_tunable,
21452150
.set_tunable = at803x_set_tunable,
2146-
.cable_test_start = at803x_cable_test_start,
2147-
.cable_test_get_status = at803x_cable_test_get_status,
2151+
.cable_test_start = at8031_cable_test_start,
2152+
.cable_test_get_status = at8031_cable_test_get_status,
21482153
}, {
21492154
/* Qualcomm Atheros AR8030 */
21502155
.phy_id = ATH8030_PHY_ID,
@@ -2181,8 +2186,8 @@ static struct phy_driver at803x_driver[] = {
21812186
.handle_interrupt = at803x_handle_interrupt,
21822187
.get_tunable = at803x_get_tunable,
21832188
.set_tunable = at803x_set_tunable,
2184-
.cable_test_start = at803x_cable_test_start,
2185-
.cable_test_get_status = at803x_cable_test_get_status,
2189+
.cable_test_start = at8031_cable_test_start,
2190+
.cable_test_get_status = at8031_cable_test_get_status,
21862191
}, {
21872192
/* Qualcomm Atheros AR8032 */
21882193
PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
@@ -2197,7 +2202,7 @@ static struct phy_driver at803x_driver[] = {
21972202
.config_intr = at803x_config_intr,
21982203
.handle_interrupt = at803x_handle_interrupt,
21992204
.cable_test_start = at803x_cable_test_start,
2200-
.cable_test_get_status = at803x_cable_test_get_status,
2205+
.cable_test_get_status = at8032_cable_test_get_status,
22012206
}, {
22022207
/* ATHEROS AR9331 */
22032208
PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
@@ -2210,7 +2215,7 @@ static struct phy_driver at803x_driver[] = {
22102215
.config_intr = at803x_config_intr,
22112216
.handle_interrupt = at803x_handle_interrupt,
22122217
.cable_test_start = at803x_cable_test_start,
2213-
.cable_test_get_status = at803x_cable_test_get_status,
2218+
.cable_test_get_status = at8032_cable_test_get_status,
22142219
.read_status = at803x_read_status,
22152220
.soft_reset = genphy_soft_reset,
22162221
.config_aneg = at803x_config_aneg,
@@ -2226,7 +2231,7 @@ static struct phy_driver at803x_driver[] = {
22262231
.config_intr = at803x_config_intr,
22272232
.handle_interrupt = at803x_handle_interrupt,
22282233
.cable_test_start = at803x_cable_test_start,
2229-
.cable_test_get_status = at803x_cable_test_get_status,
2234+
.cable_test_get_status = at8032_cable_test_get_status,
22302235
.read_status = at803x_read_status,
22312236
.soft_reset = genphy_soft_reset,
22322237
.config_aneg = at803x_config_aneg,

0 commit comments

Comments
 (0)