10
10
#include <linux/ethtool.h>
11
11
#include <linux/ethtool_netlink.h>
12
12
#include <linux/bitfield.h>
13
+ #include "microchip_rds_ptp.h"
13
14
14
15
#define PHY_ID_LAN87XX 0x0007c150
15
16
#define PHY_ID_LAN937X 0x0007c180
16
17
#define PHY_ID_LAN887X 0x0007c1f0
17
18
19
+ #define MCHP_RDS_PTP_LTC_BASE_ADDR 0xe000
20
+ #define MCHP_RDS_PTP_PORT_BASE_ADDR (MCHP_RDS_PTP_LTC_BASE_ADDR + 0x800)
21
+
18
22
/* External Register Control Register */
19
23
#define LAN87XX_EXT_REG_CTL (0x14)
20
24
#define LAN87XX_EXT_REG_CTL_RD_CTL (0x1000)
229
233
230
234
#define LAN887X_INT_STS 0xf000
231
235
#define LAN887X_INT_MSK 0xf001
236
+ #define LAN887X_INT_MSK_P1588_MOD_INT_MSK BIT(3)
232
237
#define LAN887X_INT_MSK_T1_PHY_INT_MSK BIT(2)
233
238
#define LAN887X_INT_MSK_LINK_UP_MSK BIT(1)
234
239
#define LAN887X_INT_MSK_LINK_DOWN_MSK BIT(0)
@@ -319,6 +324,8 @@ struct lan887x_regwr_map {
319
324
320
325
struct lan887x_priv {
321
326
u64 stats [ARRAY_SIZE (lan887x_hw_stats )];
327
+ struct mchp_rds_ptp_clock * clock ;
328
+ bool init_done ;
322
329
};
323
330
324
331
static int lan937x_dsp_workaround (struct phy_device * phydev , u16 ereg , u8 bank )
@@ -1269,8 +1276,19 @@ static int lan887x_get_features(struct phy_device *phydev)
1269
1276
1270
1277
static int lan887x_phy_init (struct phy_device * phydev )
1271
1278
{
1279
+ struct lan887x_priv * priv = phydev -> priv ;
1272
1280
int ret ;
1273
1281
1282
+ if (!priv -> init_done && phy_interrupt_is_valid (phydev )) {
1283
+ priv -> clock = mchp_rds_ptp_probe (phydev , MDIO_MMD_VEND1 ,
1284
+ MCHP_RDS_PTP_LTC_BASE_ADDR ,
1285
+ MCHP_RDS_PTP_PORT_BASE_ADDR );
1286
+ if (IS_ERR (priv -> clock ))
1287
+ return PTR_ERR (priv -> clock );
1288
+
1289
+ priv -> init_done = true;
1290
+ }
1291
+
1274
1292
/* Clear loopback */
1275
1293
ret = phy_clear_bits_mmd (phydev , MDIO_MMD_VEND1 ,
1276
1294
LAN887X_MIS_CFG_REG2 ,
@@ -1470,6 +1488,7 @@ static int lan887x_probe(struct phy_device *phydev)
1470
1488
if (!priv )
1471
1489
return - ENOMEM ;
1472
1490
1491
+ priv -> init_done = false;
1473
1492
phydev -> priv = priv ;
1474
1493
1475
1494
return lan887x_phy_setup (phydev );
@@ -1518,6 +1537,7 @@ static void lan887x_get_strings(struct phy_device *phydev, u8 *data)
1518
1537
1519
1538
static int lan887x_config_intr (struct phy_device * phydev )
1520
1539
{
1540
+ struct lan887x_priv * priv = phydev -> priv ;
1521
1541
int rc ;
1522
1542
1523
1543
if (phydev -> interrupts == PHY_INTERRUPT_ENABLED ) {
@@ -1537,12 +1557,24 @@ static int lan887x_config_intr(struct phy_device *phydev)
1537
1557
1538
1558
rc = phy_read_mmd (phydev , MDIO_MMD_VEND1 , LAN887X_INT_STS );
1539
1559
}
1560
+ if (rc < 0 )
1561
+ return rc ;
1540
1562
1541
- return rc < 0 ? rc : 0 ;
1563
+ if (phy_is_default_hwtstamp (phydev )) {
1564
+ return mchp_rds_ptp_top_config_intr (priv -> clock ,
1565
+ LAN887X_INT_MSK ,
1566
+ LAN887X_INT_MSK_P1588_MOD_INT_MSK ,
1567
+ (phydev -> interrupts ==
1568
+ PHY_INTERRUPT_ENABLED ));
1569
+ }
1570
+
1571
+ return 0 ;
1542
1572
}
1543
1573
1544
1574
static irqreturn_t lan887x_handle_interrupt (struct phy_device * phydev )
1545
1575
{
1576
+ struct lan887x_priv * priv = phydev -> priv ;
1577
+ int rc = IRQ_NONE ;
1546
1578
int irq_status ;
1547
1579
1548
1580
irq_status = phy_read_mmd (phydev , MDIO_MMD_VEND1 , LAN887X_INT_STS );
@@ -1553,10 +1585,13 @@ static irqreturn_t lan887x_handle_interrupt(struct phy_device *phydev)
1553
1585
1554
1586
if (irq_status & LAN887X_MX_CHIP_TOP_LINK_MSK ) {
1555
1587
phy_trigger_machine (phydev );
1556
- return IRQ_HANDLED ;
1588
+ rc = IRQ_HANDLED ;
1557
1589
}
1558
1590
1559
- return IRQ_NONE ;
1591
+ if (irq_status & LAN887X_INT_MSK_P1588_MOD_INT_MSK )
1592
+ rc = mchp_rds_ptp_handle_interrupt (priv -> clock );
1593
+
1594
+ return rc ;
1560
1595
}
1561
1596
1562
1597
static int lan887x_cd_reset (struct phy_device * phydev ,
0 commit comments