From 215b13dd288c2e1e4461c1530a801f5f83e8cd90 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Wed, 31 Oct 2012 06:19:07 +0000 Subject: ptp: add an ioctl to compare PHC time with system time This patch adds an ioctl for PTP Hardware Clock (PHC) devices that allows user space to measure the time offset between the PHC and the system clock. Rather than hard coding any kind of estimation algorithm into the kernel, this patch takes the more flexible approach of just delivering an array of raw clock readings. In that way, the user space clock servo may be adapted to new and different hardware clocks. Signed-off-by: Richard Cochran Acked-by: Jacob Keller Signed-off-by: David S. Miller --- drivers/ptp/ptp_chardev.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'drivers') diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index e7f301da2..4f8ae80 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -33,9 +33,13 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) { struct ptp_clock_caps caps; struct ptp_clock_request req; + struct ptp_sys_offset sysoff; struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); struct ptp_clock_info *ops = ptp->info; + struct ptp_clock_time *pct; + struct timespec ts; int enable, err = 0; + unsigned int i; switch (cmd) { @@ -88,6 +92,34 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) err = ops->enable(ops, &req, enable); break; + case PTP_SYS_OFFSET: + if (copy_from_user(&sysoff, (void __user *)arg, + sizeof(sysoff))) { + err = -EFAULT; + break; + } + if (sysoff.n_samples > PTP_MAX_SAMPLES) { + err = -EINVAL; + break; + } + pct = &sysoff.ts[0]; + for (i = 0; i < sysoff.n_samples; i++) { + getnstimeofday(&ts); + pct->sec = ts.tv_sec; + pct->nsec = ts.tv_nsec; + pct++; + ptp->info->gettime(ptp->info, &ts); + pct->sec = ts.tv_sec; + pct->nsec = ts.tv_nsec; + pct++; + } + getnstimeofday(&ts); + pct->sec = ts.tv_sec; + pct->nsec = ts.tv_nsec; + if (copy_to_user((void __user *)arg, &sysoff, sizeof(sysoff))) + err = -EFAULT; + break; + default: err = -ENOTTY; break; -- cgit v1.1