Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * pps-ktimer.c -- kernel timer test client
4 *
5 * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
6 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
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>
16
17/*
18 * Global variables
19 */
20
21static struct pps_device *pps;
22static struct timer_list ktimer;
23
24/*
25 * The kernel timer
26 */
27
28static void pps_ktimer_event(struct timer_list *unused)
29{
30 struct pps_event_time ts;
31
32 /* First of all we get the time stamp... */
33 pps_get_ts(&ts);
34
35 pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
36
37 mod_timer(&ktimer, jiffies + HZ);
38}
39
40/*
41 * The PPS info struct
42 */
43
44static struct pps_source_info pps_ktimer_info = {
45 .name = "ktimer",
46 .path = "",
47 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
48 PPS_ECHOASSERT |
49 PPS_CANWAIT | PPS_TSFMT_TSPEC,
50 .owner = THIS_MODULE,
51};
52
53/*
54 * Module staff
55 */
56
57static void __exit pps_ktimer_exit(void)
58{
59 dev_info(pps->dev, "ktimer PPS source unregistered\n");
60
61 del_timer_sync(&ktimer);
62 pps_unregister_source(pps);
63}
64
65static int __init pps_ktimer_init(void)
66{
67 pps = pps_register_source(&pps_ktimer_info,
68 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
69 if (IS_ERR(pps)) {
70 pr_err("cannot register PPS source\n");
71 return PTR_ERR(pps);
72 }
73
74 timer_setup(&ktimer, pps_ktimer_event, 0);
75 mod_timer(&ktimer, jiffies + HZ);
76
77 dev_info(pps->dev, "ktimer PPS source registered\n");
78
79 return 0;
80}
81
82module_init(pps_ktimer_init);
83module_exit(pps_ktimer_exit);
84
85MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
86MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
87MODULE_LICENSE("GPL");
1/*
2 * pps-ktimer.c -- kernel timer test client
3 *
4 *
5 * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 * Global variables
33 */
34
35static struct pps_device *pps;
36static struct timer_list ktimer;
37
38/*
39 * The kernel timer
40 */
41
42static void pps_ktimer_event(unsigned long ptr)
43{
44 struct pps_event_time ts;
45
46 /* First of all we get the time stamp... */
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 * The echo function
56 */
57
58static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
59{
60 dev_info(pps->dev, "echo %s %s\n",
61 event & PPS_CAPTUREASSERT ? "assert" : "",
62 event & PPS_CAPTURECLEAR ? "clear" : "");
63}
64
65/*
66 * The PPS info struct
67 */
68
69static struct pps_source_info pps_ktimer_info = {
70 .name = "ktimer",
71 .path = "",
72 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
73 PPS_ECHOASSERT |
74 PPS_CANWAIT | PPS_TSFMT_TSPEC,
75 .echo = pps_ktimer_echo,
76 .owner = THIS_MODULE,
77};
78
79/*
80 * Module staff
81 */
82
83static void __exit pps_ktimer_exit(void)
84{
85 dev_info(pps->dev, "ktimer PPS source unregistered\n");
86
87 del_timer_sync(&ktimer);
88 pps_unregister_source(pps);
89}
90
91static int __init pps_ktimer_init(void)
92{
93 pps = pps_register_source(&pps_ktimer_info,
94 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
95 if (pps == NULL) {
96 pr_err("cannot register PPS source\n");
97 return -ENOMEM;
98 }
99
100 setup_timer(&ktimer, pps_ktimer_event, 0);
101 mod_timer(&ktimer, jiffies + HZ);
102
103 dev_info(pps->dev, "ktimer PPS source registered\n");
104
105 return 0;
106}
107
108module_init(pps_ktimer_init);
109module_exit(pps_ktimer_exit);
110
111MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
112MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
113MODULE_LICENSE("GPL");