pps/ptp: Allow PHC devices to adjust PPS events for known delay
authorBen Hutchings <bhutchings@solarflare.com>
Mon, 3 Sep 2012 10:34:58 +0000 (11:34 +0100)
committerBen Hutchings <bhutchings@solarflare.com>
Fri, 7 Sep 2012 20:13:28 +0000 (21:13 +0100)
Initial version by Stuart Hodgson <smhodgson@solarflare.com>

Some PHC device drivers may deliver PPS events with a significant
and variable delay, but still be able to measure precisely what
that delay is.

Add a pps_sub_ts() function for subtracting a delay from the
timestamp(s) in a PPS event, and a PTP event type (PTP_CLOCK_PPSUSR)
for which the caller provides a complete PPS event.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
drivers/ptp/ptp_clock.c
include/linux/pps_kernel.h
include/linux/ptp_clock_kernel.h

index 1e528b539a07f202a04b9e9dbdfbffbac6656703..966875dcda569b1d44a668fa4cc71b884b8d8444 100644 (file)
@@ -300,6 +300,11 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event)
                pps_get_ts(&evt);
                pps_event(ptp->pps_source, &evt, PTP_PPS_EVENT, NULL);
                break;
+
+       case PTP_CLOCK_PPSUSR:
+               pps_event(ptp->pps_source, &event->pps_times,
+                         PTP_PPS_EVENT, NULL);
+               break;
        }
 }
 EXPORT_SYMBOL(ptp_clock_event);
index 94048547f29ad424e27013c4eaa17ca6ca28c422..0cc45ae1afd54aca12247724c73972a5ab8f6cc4 100644 (file)
@@ -116,5 +116,14 @@ static inline void pps_get_ts(struct pps_event_time *ts)
 
 #endif /* CONFIG_NTP_PPS */
 
+/* Subtract known time delay from PPS event time(s) */
+static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec delta)
+{
+       ts->ts_real = timespec_sub(ts->ts_real, delta);
+#ifdef CONFIG_NTP_PPS
+       ts->ts_raw = timespec_sub(ts->ts_raw, delta);
+#endif
+}
+
 #endif /* LINUX_PPS_KERNEL_H */
 
index 945704c2ed65307bb8ec47c39cbd24d364b40fa3..a644b29f116125830dd8c5c01e06a05eace8db70 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef _PTP_CLOCK_KERNEL_H_
 #define _PTP_CLOCK_KERNEL_H_
 
+#include <linux/pps_kernel.h>
 #include <linux/ptp_clock.h>
 
 
@@ -110,6 +111,7 @@ enum ptp_clock_events {
        PTP_CLOCK_ALARM,
        PTP_CLOCK_EXTTS,
        PTP_CLOCK_PPS,
+       PTP_CLOCK_PPSUSR,
 };
 
 /**
@@ -117,13 +119,17 @@ enum ptp_clock_events {
  *
  * @type:  One of the ptp_clock_events enumeration values.
  * @index: Identifies the source of the event.
- * @timestamp: When the event occured.
+ * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only).
+ * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only).
  */
 
 struct ptp_clock_event {
        int type;
        int index;
-       u64 timestamp;
+       union {
+               u64 timestamp;
+               struct pps_event_time pps_times;
+       };
 };
 
 /**