commit: http://blackfin.uclinux.org/git/?p=linux-kernel;a=commitdiff;h=730a7431ce3c176758ea536cc47473ec34a8d162
branch: http://blackfin.uclinux.org/git/?p=linux-kernel;a=shortlog;h=refs/heads/trunk

Set TSCTRLSSR bit in timestamp control register to roll over nanosecond after it
increases to 1 second. Set 20 to sub-second increment register to generate
nanoseconds register at accuracy of 1 ns when the PTP clock is 50M Hz.

Signed-off-by: Sonic Zhang <[email protected]>
Signed-off-by: Bob Liu <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |    1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 1763333..dbb02fe 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -38,6 +38,7 @@
 #define PTP_EN          (0x1)        /* Enable the PTP_TSYNC module */
 #define PTP_TSINIT      (0x4)        /* update system timer */
 #define PTP_TSENALL     (1 << 8)
+#define PTP_TSCTRLSSR   (1 << 9)
 #define PTP_TSVER2ENA   (1 << 10)
 #define PTP_TSIPENA     (1 << 11)
 #define PTP_TSIPV4ENA   (1 << 13)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 370e84d..d8cbbc3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -217,7 +217,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *netdev,
 
 		SSYNC();
 	} else {
-		ptpctl |= PTP_EN;
+		ptpctl |= PTP_EN | PTP_TSCTRLSSR;
 		writel(ptpctl, priv->ioaddr + EMAC_TM_CTL);
 
 		/* write init time value */
@@ -225,7 +225,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *netdev,
 		writel(ktime_get_real().tv.nsec, priv->ioaddr + EMAC_TM_NSECUPDT);
 		ptpctl |= PTP_TSINIT;
 		writel(ptpctl, priv->ioaddr + EMAC_TM_CTL);
-		writel(0x2b, priv->ioaddr + EMAC_TM_SUBSEC);
+		writel(0x14, priv->ioaddr + EMAC_TM_SUBSEC);
 		SSYNC();
 
 		priv->compare.last_update = 0;
@@ -336,10 +336,15 @@ static void stmmac_rx_hwtstamp(struct stmmac_priv *priv, struct sk_buff *skb, st
 static cycle_t stmmac_read_clock(const struct cyclecounter *tc)
 {
 	u64 ns;
+	u32 tmp1, tmp2;
 	ktime_t hw_time;
 	struct stmmac_priv *priv = container_of(tc, struct stmmac_priv, cycles);
-	hw_time.tv.sec = readl(priv->ioaddr + EMAC_TM_SEC);
+	tmp1 = readl(priv->ioaddr + EMAC_TM_SEC);
 	hw_time.tv.nsec = readl(priv->ioaddr + EMAC_TM_NSEC);
+	tmp2 = readl(priv->ioaddr + EMAC_TM_SEC);
+	if (tmp2 > tmp1)
+		hw_time.tv.nsec = readl(priv->ioaddr + EMAC_TM_NSEC);
+	hw_time.tv.sec = tmp2;
 	ns = ktime_to_ns(hw_time);
 	do_div(ns, 20);
 	return ns;
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to