1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pps-ktimer.c -- kernel timer test client
5 * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/time.h>
14 #include <linux/timer.h>
15 #include <linux/pps_kernel.h>
21 static struct pps_device
*pps
;
22 static struct timer_list ktimer
;
28 static void pps_ktimer_event(struct timer_list
*unused
)
30 struct pps_event_time ts
;
32 /* First of all we get the time stamp... */
35 pps_event(pps
, &ts
, PPS_CAPTUREASSERT
, NULL
);
37 mod_timer(&ktimer
, jiffies
+ HZ
);
44 static struct pps_source_info pps_ktimer_info
= {
47 .mode
= PPS_CAPTUREASSERT
| PPS_OFFSETASSERT
|
49 PPS_CANWAIT
| PPS_TSFMT_TSPEC
,
57 static void __exit
pps_ktimer_exit(void)
59 dev_info(pps
->dev
, "ktimer PPS source unregistered\n");
61 del_timer_sync(&ktimer
);
62 pps_unregister_source(pps
);
65 static int __init
pps_ktimer_init(void)
67 pps
= pps_register_source(&pps_ktimer_info
,
68 PPS_CAPTUREASSERT
| PPS_OFFSETASSERT
);
70 pr_err("cannot register PPS source\n");
74 timer_setup(&ktimer
, pps_ktimer_event
, 0);
75 mod_timer(&ktimer
, jiffies
+ HZ
);
77 dev_info(pps
->dev
, "ktimer PPS source registered\n");
82 module_init(pps_ktimer_init
);
83 module_exit(pps_ktimer_exit
);
85 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
86 MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
87 MODULE_LICENSE("GPL");