Skip to content

Commit

Permalink
pps/ptp: Allow PHC devices to adjust PPS events for known delay
Browse files Browse the repository at this point in the history
Initial version by Stuart Hodgson <[email protected]>

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 <[email protected]>
  • Loading branch information
Ben Hutchings committed Sep 7, 2012
1 parent ef2c7d7 commit 220a60a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions drivers/ptp/ptp_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions include/linux/pps_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

10 changes: 8 additions & 2 deletions include/linux/ptp_clock_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef _PTP_CLOCK_KERNEL_H_
#define _PTP_CLOCK_KERNEL_H_

#include <linux/pps_kernel.h>
#include <linux/ptp_clock.h>


Expand Down Expand Up @@ -110,20 +111,25 @@ enum ptp_clock_events {
PTP_CLOCK_ALARM,
PTP_CLOCK_EXTTS,
PTP_CLOCK_PPS,
PTP_CLOCK_PPSUSR,
};

/**
* struct ptp_clock_event - decribes a PTP hardware clock event
*
* @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;
};
};

/**
Expand Down

0 comments on commit 220a60a

Please sign in to comment.