| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 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 |  | 
| Alexander Gordeev | 7f7cce7 | 2011-01-12 17:00:52 -0800 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 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 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 35 | static struct pps_device *pps; | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 36 | static struct timer_list ktimer; | 
 | 37 |  | 
 | 38 | /* | 
 | 39 |  * The kernel timer | 
 | 40 |  */ | 
 | 41 |  | 
 | 42 | static void pps_ktimer_event(unsigned long ptr) | 
 | 43 | { | 
| Alexander Gordeev | 6f4229b | 2011-01-12 17:00:50 -0800 | [diff] [blame] | 44 | 	struct pps_event_time ts; | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 45 |  | 
 | 46 | 	/* First of all we get the time stamp... */ | 
| Alexander Gordeev | 6f4229b | 2011-01-12 17:00:50 -0800 | [diff] [blame] | 47 | 	pps_get_ts(&ts); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 48 |  | 
| Alexander Gordeev | 7f7cce7 | 2011-01-12 17:00:52 -0800 | [diff] [blame] | 49 | 	dev_info(pps->dev, "PPS event at %lu\n", jiffies); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 50 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 51 | 	pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 52 |  | 
 | 53 | 	mod_timer(&ktimer, jiffies + HZ); | 
 | 54 | } | 
 | 55 |  | 
 | 56 | /* | 
 | 57 |  * The echo function | 
 | 58 |  */ | 
 | 59 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 60 | static void pps_ktimer_echo(struct pps_device *pps, int event, void *data) | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 61 | { | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 62 | 	dev_info(pps->dev, "echo %s %s\n", | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 63 | 		event & PPS_CAPTUREASSERT ? "assert" : "", | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 64 | 		event & PPS_CAPTURECLEAR ? "clear" : ""); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 65 | } | 
 | 66 |  | 
 | 67 | /* | 
 | 68 |  * The PPS info struct | 
 | 69 |  */ | 
 | 70 |  | 
 | 71 | static struct pps_source_info pps_ktimer_info = { | 
 | 72 | 	.name		= "ktimer", | 
 | 73 | 	.path		= "", | 
 | 74 | 	.mode		= PPS_CAPTUREASSERT | PPS_OFFSETASSERT | | 
 | 75 | 			  PPS_ECHOASSERT | | 
 | 76 | 			  PPS_CANWAIT | PPS_TSFMT_TSPEC, | 
 | 77 | 	.echo		= pps_ktimer_echo, | 
 | 78 | 	.owner		= THIS_MODULE, | 
 | 79 | }; | 
 | 80 |  | 
 | 81 | /* | 
 | 82 |  * Module staff | 
 | 83 |  */ | 
 | 84 |  | 
 | 85 | static void __exit pps_ktimer_exit(void) | 
 | 86 | { | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 87 | 	dev_info(pps->dev, "ktimer PPS source unregistered\n"); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 88 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 89 | 	del_timer_sync(&ktimer); | 
 | 90 | 	pps_unregister_source(pps); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 91 | } | 
 | 92 |  | 
 | 93 | static int __init pps_ktimer_init(void) | 
 | 94 | { | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 95 | 	pps = pps_register_source(&pps_ktimer_info, | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 96 | 				PPS_CAPTUREASSERT | PPS_OFFSETASSERT); | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 97 | 	if (pps == NULL) { | 
| Alexander Gordeev | 7f7cce7 | 2011-01-12 17:00:52 -0800 | [diff] [blame] | 98 | 		pr_err("cannot register PPS source\n"); | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 99 | 		return -ENOMEM; | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 100 | 	} | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 101 |  | 
 | 102 | 	setup_timer(&ktimer, pps_ktimer_event, 0); | 
 | 103 | 	mod_timer(&ktimer, jiffies + HZ); | 
 | 104 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 105 | 	dev_info(pps->dev, "ktimer PPS source registered\n"); | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 106 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame] | 107 | 	return 0; | 
| Rodolfo Giometti | 697fb85 | 2010-03-10 15:23:45 -0800 | [diff] [blame] | 108 | } | 
 | 109 |  | 
 | 110 | module_init(pps_ktimer_init); | 
 | 111 | module_exit(pps_ktimer_exit); | 
 | 112 |  | 
 | 113 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | 
 | 114 | MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)"); | 
 | 115 | MODULE_LICENSE("GPL"); |