Add the STMMAC_RELATIVE_FLEX_PPS config switch so that the MAC system time is added to the requested start time when configuring the flexible PPS signal start time. This eases the configuration of the generation of flexible PPS signals. Signed-off-by: Gatien Chevallier --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 9 +++++++++ drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 67fa879b1e521ef6d7bd2a8db30d812301eb4cf7..949c744d30f19f5ff480dca4811e678d2b93c450 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -357,3 +357,12 @@ config STMMAC_PCI If unsure, say N. endif + +config STMMAC_RELATIVE_FLEX_PPS + bool "Support for STMMAC system time relative flexible PPS generation" + default n + help + Say Y to add the MAC system time to the arguments passed to the + PTP driver when requesting a flexible PPS generation. This avoids + the tedious task of passing an absolute time value when using sysfs + entry. diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 3767ba495e78d210b0529ee1754e5331f2dd0a47..cc898eab4df6a3e2530a8b03dfdaa9016d1bb0b9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -180,6 +180,19 @@ static int stmmac_enable(struct ptp_clock_info *ptp, cfg->start.tv_sec = rq->perout.start.sec; cfg->start.tv_nsec = rq->perout.start.nsec; + if (IS_ENABLED(CONFIG_STMMAC_RELATIVE_FLEX_PPS)) { + struct timespec64 curr_time; + u64 ns = 0; + + /* Be aware that an offset too low may not trigger flexible PPS generation + * if time spent in this configuration makes this relative time already + * outdated. + */ + stmmac_get_systime(priv, priv->ptpaddr, &ns); + curr_time = ns_to_timespec64(ns); + cfg->start.tv_sec += curr_time.tv_sec; + cfg->start.tv_nsec += curr_time.tv_nsec; + } cfg->period.tv_sec = rq->perout.period.sec; cfg->period.tv_nsec = rq->perout.period.nsec; -- 2.25.1 In order to simplify the generation of flexible PPS signals by passing an time offset relative to the MAC system time, select STMMAC_RELATIVE_FLEX_PPS for DWMAC_STM32 config. E.g: "echo "0 3 0 1 1" > /sys/class/ptp/ptp0/period" generates a PPS that has a 1s period, 3 seconds after entering the command for ptp0 clock, given that the MAC system time stays stable. Signed-off-by: Gatien Chevallier --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 949c744d30f19f5ff480dca4811e678d2b93c450..98fae30ad5a2760ec6b9cebf3dcaf8e4d7d19b77 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -233,6 +233,7 @@ config DWMAC_STM32 default ARCH_STM32 depends on OF && HAS_IOMEM && (ARCH_STM32 || COMPILE_TEST) select MFD_SYSCON + select STMMAC_RELATIVE_FLEX_PPS help Support for ethernet controller on STM32 SOCs. -- 2.25.1