@@ -1222,31 +1222,16 @@ static int at803x_cdt_fault_length(u16 status)
1222
1222
return (dt * 824 ) / 10 ;
1223
1223
}
1224
1224
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 )
1226
1227
{
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 );
1239
1229
}
1240
1230
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 )
1242
1233
{
1243
1234
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 ;
1250
1235
1251
1236
/* One test run takes about 25ms */
1252
1237
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)
1266
1251
};
1267
1252
int ret , val ;
1268
1253
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 );
1270
1257
if (ret )
1271
1258
return ret ;
1272
1259
1273
- ret = at803x_cdt_wait_for_completion (phydev );
1260
+ ret = at803x_cdt_wait_for_completion (phydev , AT803X_CDT_ENABLE_TEST );
1274
1261
if (ret )
1275
1262
return ret ;
1276
1263
@@ -1292,19 +1279,11 @@ static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
1292
1279
}
1293
1280
1294
1281
static int at803x_cable_test_get_status (struct phy_device * phydev ,
1295
- bool * finished )
1282
+ bool * finished , unsigned long pair_mask )
1296
1283
{
1297
- unsigned long pair_mask ;
1298
1284
int retries = 20 ;
1299
1285
int pair , ret ;
1300
1286
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
-
1308
1287
* finished = false;
1309
1288
1310
1289
/* 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,
1331
1310
return 0 ;
1332
1311
}
1333
1312
1334
- static int at803x_cable_test_start (struct phy_device * phydev )
1313
+ static void at803x_cable_test_autoneg (struct phy_device * phydev )
1335
1314
{
1336
1315
/* Enable auto-negotiation, but advertise no capabilities, no link
1337
1316
* will be established. A restart of the auto-negotiation is not
1338
1317
* required, because the cable test will automatically break the link.
1339
1318
*/
1340
1319
phy_write (phydev , MII_BMCR , BMCR_ANENABLE );
1341
1320
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
+ }
1346
1322
1323
+ static int at803x_cable_test_start (struct phy_device * phydev )
1324
+ {
1325
+ at803x_cable_test_autoneg (phydev );
1347
1326
/* we do all the (time consuming) work later */
1348
1327
return 0 ;
1349
1328
}
@@ -1618,6 +1597,29 @@ static int at8031_config_intr(struct phy_device *phydev)
1618
1597
return at803x_config_intr (phydev );
1619
1598
}
1620
1599
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
+
1621
1623
static int at8035_parse_dt (struct phy_device * phydev )
1622
1624
{
1623
1625
struct at803x_priv * priv = phydev -> priv ;
@@ -2041,11 +2043,14 @@ static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finish
2041
2043
2042
2044
* finished = false;
2043
2045
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 );
2045
2050
if (ret )
2046
2051
return ret ;
2047
2052
2048
- ret = at803x_cdt_wait_for_completion (phydev );
2053
+ ret = at803x_cdt_wait_for_completion (phydev , QCA808X_CDT_ENABLE_TEST );
2049
2054
if (ret )
2050
2055
return ret ;
2051
2056
@@ -2143,8 +2148,8 @@ static struct phy_driver at803x_driver[] = {
2143
2148
.handle_interrupt = at803x_handle_interrupt ,
2144
2149
.get_tunable = at803x_get_tunable ,
2145
2150
.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 ,
2148
2153
}, {
2149
2154
/* Qualcomm Atheros AR8030 */
2150
2155
.phy_id = ATH8030_PHY_ID ,
@@ -2181,8 +2186,8 @@ static struct phy_driver at803x_driver[] = {
2181
2186
.handle_interrupt = at803x_handle_interrupt ,
2182
2187
.get_tunable = at803x_get_tunable ,
2183
2188
.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 ,
2186
2191
}, {
2187
2192
/* Qualcomm Atheros AR8032 */
2188
2193
PHY_ID_MATCH_EXACT (ATH8032_PHY_ID ),
@@ -2197,7 +2202,7 @@ static struct phy_driver at803x_driver[] = {
2197
2202
.config_intr = at803x_config_intr ,
2198
2203
.handle_interrupt = at803x_handle_interrupt ,
2199
2204
.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 ,
2201
2206
}, {
2202
2207
/* ATHEROS AR9331 */
2203
2208
PHY_ID_MATCH_EXACT (ATH9331_PHY_ID ),
@@ -2210,7 +2215,7 @@ static struct phy_driver at803x_driver[] = {
2210
2215
.config_intr = at803x_config_intr ,
2211
2216
.handle_interrupt = at803x_handle_interrupt ,
2212
2217
.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 ,
2214
2219
.read_status = at803x_read_status ,
2215
2220
.soft_reset = genphy_soft_reset ,
2216
2221
.config_aneg = at803x_config_aneg ,
@@ -2226,7 +2231,7 @@ static struct phy_driver at803x_driver[] = {
2226
2231
.config_intr = at803x_config_intr ,
2227
2232
.handle_interrupt = at803x_handle_interrupt ,
2228
2233
.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 ,
2230
2235
.read_status = at803x_read_status ,
2231
2236
.soft_reset = genphy_soft_reset ,
2232
2237
.config_aneg = at803x_config_aneg ,
0 commit comments