]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net: ti: icssg-prueth: Fix 1 PPS sync
authorMeghana Malladi <m-malladi@ti.com>
Mon, 11 Nov 2024 09:58:42 +0000 (15:28 +0530)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 14 Nov 2024 09:34:56 +0000 (10:34 +0100)
The first PPS latch time needs to be calculated by the driver
(in rounded off seconds) and configured as the start time
offset for the cycle. After synchronizing two PTP clocks
running as master/slave, missing this would cause master
and slave to start immediately with some milliseconds
drift which causes the PPS signal to never synchronize with
the PTP master.

Fixes: 186734c15886 ("net: ti: icssg-prueth: add packet timestamping and ptp support")
Signed-off-by: Meghana Malladi <m-malladi@ti.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: MD Danish Anwar <danishanwar@ti.com>
Link: https://patch.msgid.link/20241111095842.478833-1-m-malladi@ti.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/ti/icssg/icssg_prueth.c
drivers/net/ethernet/ti/icssg/icssg_prueth.h

index 5c20ceb164dff2198799582aa2c64ca2328fec3e..fe2fd1bfc904db2db8ed2ead9ea284393ed85529 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/if_hsr.h>
 #include <linux/if_vlan.h>
 #include <linux/interrupt.h>
+#include <linux/io-64-nonatomic-hi-lo.h>
 #include <linux/kernel.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
@@ -411,6 +412,8 @@ static int prueth_perout_enable(void *clockops_data,
        struct prueth_emac *emac = clockops_data;
        u32 reduction_factor = 0, offset = 0;
        struct timespec64 ts;
+       u64 current_cycle;
+       u64 start_offset;
        u64 ns_period;
 
        if (!on)
@@ -449,8 +452,14 @@ static int prueth_perout_enable(void *clockops_data,
        writel(reduction_factor, emac->prueth->shram.va +
                TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET);
 
-       writel(0, emac->prueth->shram.va +
-               TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET);
+       current_cycle = icssg_read_time(emac->prueth->shram.va +
+                                       TIMESYNC_FW_WC_CYCLECOUNT_OFFSET);
+
+       /* Rounding of current_cycle count to next second */
+       start_offset = roundup(current_cycle, MSEC_PER_SEC);
+
+       hi_lo_writeq(start_offset, emac->prueth->shram.va +
+                    TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET);
 
        return 0;
 }
index 8722bb4a268a1571cda5ac1086359ad816ac69f3..f5c1d473e9f991df4aa5ac878f21bc6de2ad33a6 100644 (file)
@@ -330,6 +330,18 @@ static inline int prueth_emac_slice(struct prueth_emac *emac)
 extern const struct ethtool_ops icssg_ethtool_ops;
 extern const struct dev_pm_ops prueth_dev_pm_ops;
 
+static inline u64 icssg_read_time(const void __iomem *addr)
+{
+       u32 low, high;
+
+       do {
+               high = readl(addr + 4);
+               low = readl(addr);
+       } while (high != readl(addr + 4));
+
+       return low + ((u64)high << 32);
+}
+
 /* Classifier helpers */
 void icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac);
 void icssg_class_set_host_mac_addr(struct regmap *miig_rt, const u8 *mac);