28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/kernel.h>
31 #include <linux/module.h>
33 #include <linux/time.h>
34 #include <linux/hrtimer.h>
35 #include <linux/parport.h>
37 #define DRVDESC "parallel port PPS signal generator"
40 #define NO_SIGNAL PARPORT_CONTROL_STROBE
44 #define SEND_DELAY_MAX 100000
46 static unsigned int send_delay = 30000;
48 "Delay between setting and dropping the signal (ns)");
52 #define SAFETY_INTERVAL 3000
73 struct timespec expire_time, ts1, ts2, ts3, dts;
92 expire_time = ktime_to_timespec(hrtimer_get_softexpires(timer));
97 if (expire_time.tv_sec != ts1.tv_sec || ts1.tv_nsec > lim) {
99 pr_err(
"we are late this time %ld.%09ld\n",
100 ts1.tv_sec, ts1.tv_nsec);
107 }
while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
117 }
while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
127 dts = timespec_sub(ts3, ts2);
133 dts = timespec_sub(ts1, expire_time);
134 delta = timespec_to_ns(&dts);
140 if (delta >= hrtimer_error)
141 hrtimer_error =
delta;
143 hrtimer_error = (3 * hrtimer_error +
delta) >> 2;
146 hrtimer_set_expires(timer,
147 ktime_set(expire_time.tv_sec + 1,
150 2 * hrtimer_error)));
156 #define PORT_NTESTS_SHIFT 5
165 unsigned long irq_flags;
173 b = timespec_sub(b, a);
174 acc += timespec_to_ns(&b);
187 return ktime_set(
ts.tv_sec +
193 static void parport_attach(
struct parport *port)
203 pr_err(
"couldn't register with %s\n", port->
name);
209 goto err_unregister_dev;
215 calibrate_port(&device);
218 device.
timer.function = hrtimer_event;
227 static void parport_detach(
struct parport *port)
238 .name = KBUILD_MODNAME,
239 .attach = parport_attach,
240 .detach = parport_detach,
245 static int __init pps_gen_parport_init(
void)
252 pr_err(
"delay value should be not greater"
259 pr_err(
"unable to register with parport\n");
266 static void __exit pps_gen_parport_exit(
void)
269 pr_info(
"hrtimer avg error is %ldns\n", hrtimer_error);