1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/time.h>
28#include <linux/timer.h>
29#include <linux/pps_kernel.h>
30
31
32
33
34
35static struct pps_device *pps;
36static struct timer_list ktimer;
37
38
39
40
41
42static void pps_ktimer_event(unsigned long ptr)
43{
44 struct pps_event_time ts;
45
46
47 pps_get_ts(&ts);
48
49 pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
50
51 mod_timer(&ktimer, jiffies + HZ);
52}
53
54
55
56
57
58static struct pps_source_info pps_ktimer_info = {
59 .name = "ktimer",
60 .path = "",
61 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
62 PPS_ECHOASSERT |
63 PPS_CANWAIT | PPS_TSFMT_TSPEC,
64 .owner = THIS_MODULE,
65};
66
67
68
69
70
71static void __exit pps_ktimer_exit(void)
72{
73 dev_info(pps->dev, "ktimer PPS source unregistered\n");
74
75 del_timer_sync(&ktimer);
76 pps_unregister_source(pps);
77}
78
79static int __init pps_ktimer_init(void)
80{
81 pps = pps_register_source(&pps_ktimer_info,
82 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
83 if (pps == NULL) {
84 pr_err("cannot register PPS source\n");
85 return -ENOMEM;
86 }
87
88 setup_timer(&ktimer, pps_ktimer_event, 0);
89 mod_timer(&ktimer, jiffies + HZ);
90
91 dev_info(pps->dev, "ktimer PPS source registered\n");
92
93 return 0;
94}
95
96module_init(pps_ktimer_init);
97module_exit(pps_ktimer_exit);
98
99MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
100MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
101MODULE_LICENSE("GPL");
102