Skip to content

Commit dc06507

Browse files
MeghanaMalladiTIPaolo Abeni
authored andcommitted
net: ti: icssg-prueth: Fix 1 PPS sync
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: 186734c ("net: ti: icssg-prueth: add packet timestamping and ptp support") Signed-off-by: Meghana Malladi <[email protected]> Reviewed-by: Vadim Fedorenko <[email protected]> Reviewed-by: MD Danish Anwar <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 5b366ea commit dc06507

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/if_hsr.h>
1717
#include <linux/if_vlan.h>
1818
#include <linux/interrupt.h>
19+
#include <linux/io-64-nonatomic-hi-lo.h>
1920
#include <linux/kernel.h>
2021
#include <linux/mfd/syscon.h>
2122
#include <linux/module.h>
@@ -411,6 +412,8 @@ static int prueth_perout_enable(void *clockops_data,
411412
struct prueth_emac *emac = clockops_data;
412413
u32 reduction_factor = 0, offset = 0;
413414
struct timespec64 ts;
415+
u64 current_cycle;
416+
u64 start_offset;
414417
u64 ns_period;
415418

416419
if (!on)
@@ -449,8 +452,14 @@ static int prueth_perout_enable(void *clockops_data,
449452
writel(reduction_factor, emac->prueth->shram.va +
450453
TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET);
451454

452-
writel(0, emac->prueth->shram.va +
453-
TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET);
455+
current_cycle = icssg_read_time(emac->prueth->shram.va +
456+
TIMESYNC_FW_WC_CYCLECOUNT_OFFSET);
457+
458+
/* Rounding of current_cycle count to next second */
459+
start_offset = roundup(current_cycle, MSEC_PER_SEC);
460+
461+
hi_lo_writeq(start_offset, emac->prueth->shram.va +
462+
TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET);
454463

455464
return 0;
456465
}

drivers/net/ethernet/ti/icssg/icssg_prueth.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ static inline int prueth_emac_slice(struct prueth_emac *emac)
330330
extern const struct ethtool_ops icssg_ethtool_ops;
331331
extern const struct dev_pm_ops prueth_dev_pm_ops;
332332

333+
static inline u64 icssg_read_time(const void __iomem *addr)
334+
{
335+
u32 low, high;
336+
337+
do {
338+
high = readl(addr + 4);
339+
low = readl(addr);
340+
} while (high != readl(addr + 4));
341+
342+
return low + ((u64)high << 32);
343+
}
344+
333345
/* Classifier helpers */
334346
void icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac);
335347
void icssg_class_set_host_mac_addr(struct regmap *miig_rt, const u8 *mac);

0 commit comments

Comments
 (0)