0001
0002
0003
0004
0005
0006
0007
0008 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0009
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include <linux/init.h>
0013 #include <linux/time.h>
0014 #include <linux/timer.h>
0015 #include <linux/pps_kernel.h>
0016
0017
0018
0019
0020
0021 static struct pps_device *pps;
0022 static struct timer_list ktimer;
0023
0024
0025
0026
0027
0028 static void pps_ktimer_event(struct timer_list *unused)
0029 {
0030 struct pps_event_time ts;
0031
0032
0033 pps_get_ts(&ts);
0034
0035 pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
0036
0037 mod_timer(&ktimer, jiffies + HZ);
0038 }
0039
0040
0041
0042
0043
0044 static struct pps_source_info pps_ktimer_info = {
0045 .name = "ktimer",
0046 .path = "",
0047 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
0048 PPS_ECHOASSERT |
0049 PPS_CANWAIT | PPS_TSFMT_TSPEC,
0050 .owner = THIS_MODULE,
0051 };
0052
0053
0054
0055
0056
0057 static void __exit pps_ktimer_exit(void)
0058 {
0059 dev_info(pps->dev, "ktimer PPS source unregistered\n");
0060
0061 del_timer_sync(&ktimer);
0062 pps_unregister_source(pps);
0063 }
0064
0065 static int __init pps_ktimer_init(void)
0066 {
0067 pps = pps_register_source(&pps_ktimer_info,
0068 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
0069 if (IS_ERR(pps)) {
0070 pr_err("cannot register PPS source\n");
0071 return PTR_ERR(pps);
0072 }
0073
0074 timer_setup(&ktimer, pps_ktimer_event, 0);
0075 mod_timer(&ktimer, jiffies + HZ);
0076
0077 dev_info(pps->dev, "ktimer PPS source registered\n");
0078
0079 return 0;
0080 }
0081
0082 module_init(pps_ktimer_init);
0083 module_exit(pps_ktimer_exit);
0084
0085 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
0086 MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
0087 MODULE_LICENSE("GPL");