20 #include <linux/bitops.h>
21 #include <linux/device.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
28 #include <linux/slab.h>
34 #define PTP_MAX_ALARMS 4
35 #define PTP_MAX_CLOCKS 8
36 #define PTP_PPS_DEFAULTS (PPS_CAPTUREASSERT | PPS_OFFSETASSERT)
37 #define PTP_PPS_EVENT PPS_CAPTUREASSERT
38 #define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC)
42 static dev_t ptp_devt;
43 static struct class *ptp_class;
63 seconds = div_u64_rem(src->
timestamp, 1000000000, &remainder);
70 dst->
t.nsec = remainder;
72 if (!queue_free(queue))
77 spin_unlock_irqrestore(&queue->
lock, flags);
80 static s32 scaled_ppm_to_ppb(
long ppm)
112 return ptp->
info->settime(ptp->
info, tp);
118 return ptp->
info->gettime(ptp->
info, tp);
134 ts.tv_sec = tx->
time.tv_sec;
135 ts.tv_nsec = tx->
time.tv_usec;
143 kt = timespec_to_ktime(
ts);
144 delta = ktime_to_ns(kt);
145 err = ops->
adjtime(ops, delta);
147 err = ops->
adjfreq(ops, scaled_ppm_to_ppb(tx->
freq));
149 }
else if (tx->
modes == 0) {
159 .clock_adjtime = ptp_clock_adjtime,
160 .clock_gettime = ptp_clock_gettime,
161 .clock_getres = ptp_clock_getres,
162 .clock_settime = ptp_clock_settime,
169 static void delete_ptp_clock(
struct posix_clock *pc)
209 ptp->
clock.ops = ptp_clock_ops;
210 ptp->
clock.release = delete_ptp_clock;
220 "ptp%d", ptp->
index);
221 if (IS_ERR(ptp->
dev))
233 memset(&pps, 0,
sizeof(pps));
239 pr_err(
"failed to register pps source\n");
247 pr_err(
"failed to create posix clock\n");
292 switch (event->
type) {
298 enqueue_external_timestamp(&ptp->
tsevq, event);
323 static void __exit ptp_exit(
void)
329 static int __init ptp_init(
void)
334 if (IS_ERR(ptp_class)) {
335 pr_err(
"ptp: failed to allocate class\n");
336 return PTR_ERR(ptp_class);
341 pr_err(
"ptp: failed to allocate device region\n");
346 pr_info(
"PTP clock support registered\n");