aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pps
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2010-05-03 03:17:01 -0400
committerIngo Molnar <mingo@elte.hu>2010-05-03 03:17:01 -0400
commit53ba4f2fa73225113a488584df0d85d3cba52943 (patch)
treed85b984d9818abc3ccc0237eb53b710d9e96c39e /drivers/pps
parentbd6d29c25bb1a24a4c160ec5de43e0004e01f72b (diff)
parent66f41d4c5c8a5deed66fdcc84509376c9a0bf9d8 (diff)
Merge commit 'v2.6.34-rc6' into core/locking
Diffstat (limited to 'drivers/pps')
-rw-r--r--drivers/pps/Kconfig2
-rw-r--r--drivers/pps/Makefile1
-rw-r--r--drivers/pps/clients/Kconfig25
-rw-r--r--drivers/pps/clients/Makefile10
-rw-r--r--drivers/pps/clients/pps-ktimer.c123
-rw-r--r--drivers/pps/clients/pps-ldisc.c154
-rw-r--r--drivers/pps/kapi.c1
7 files changed, 316 insertions, 0 deletions
diff --git a/drivers/pps/Kconfig b/drivers/pps/Kconfig
index cc2eb8edb514..1afe4e03440f 100644
--- a/drivers/pps/Kconfig
+++ b/drivers/pps/Kconfig
@@ -30,4 +30,6 @@ config PPS_DEBUG
30 messages to the system log. Select this if you are having a 30 messages to the system log. Select this if you are having a
31 problem with PPS support and want to see more of what is going on. 31 problem with PPS support and want to see more of what is going on.
32 32
33source drivers/pps/clients/Kconfig
34
33endmenu 35endmenu
diff --git a/drivers/pps/Makefile b/drivers/pps/Makefile
index 19ea582f431d..98960ddd3188 100644
--- a/drivers/pps/Makefile
+++ b/drivers/pps/Makefile
@@ -4,5 +4,6 @@
4 4
5pps_core-y := pps.o kapi.o sysfs.o 5pps_core-y := pps.o kapi.o sysfs.o
6obj-$(CONFIG_PPS) := pps_core.o 6obj-$(CONFIG_PPS) := pps_core.o
7obj-y += clients/
7 8
8ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG 9ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
diff --git a/drivers/pps/clients/Kconfig b/drivers/pps/clients/Kconfig
new file mode 100644
index 000000000000..4e801bd7254f
--- /dev/null
+++ b/drivers/pps/clients/Kconfig
@@ -0,0 +1,25 @@
1#
2# PPS clients configuration
3#
4
5if PPS
6
7comment "PPS clients support"
8
9config PPS_CLIENT_KTIMER
10 tristate "Kernel timer client (Testing client, use for debug)"
11 help
12 If you say yes here you get support for a PPS debugging client
13 which uses a kernel timer to generate the PPS signal.
14
15 This driver can also be built as a module. If so, the module
16 will be called pps-ktimer.
17
18config PPS_CLIENT_LDISC
19 tristate "PPS line discipline"
20 depends on PPS
21 help
22 If you say yes here you get support for a PPS source connected
23 with the CD (Carrier Detect) pin of your serial port.
24
25endif
diff --git a/drivers/pps/clients/Makefile b/drivers/pps/clients/Makefile
new file mode 100644
index 000000000000..812c9b19b430
--- /dev/null
+++ b/drivers/pps/clients/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for PPS clients.
3#
4
5obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o
6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o
7
8ifeq ($(CONFIG_PPS_DEBUG),y)
9EXTRA_CFLAGS += -DDEBUG
10endif
diff --git a/drivers/pps/clients/pps-ktimer.c b/drivers/pps/clients/pps-ktimer.c
new file mode 100644
index 000000000000..e7ef5b8186d0
--- /dev/null
+++ b/drivers/pps/clients/pps-ktimer.c
@@ -0,0 +1,123 @@
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
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/time.h>
27#include <linux/timer.h>
28#include <linux/pps_kernel.h>
29
30/*
31 * Global variables
32 */
33
34static int source;
35static struct timer_list ktimer;
36
37/*
38 * The kernel timer
39 */
40
41static void pps_ktimer_event(unsigned long ptr)
42{
43 struct timespec __ts;
44 struct pps_ktime ts;
45
46 /* First of all we get the time stamp... */
47 getnstimeofday(&__ts);
48
49 pr_info("PPS event at %lu\n", jiffies);
50
51 /* ... and translate it to PPS time data struct */
52 ts.sec = __ts.tv_sec;
53 ts.nsec = __ts.tv_nsec;
54
55 pps_event(source, &ts, PPS_CAPTUREASSERT, NULL);
56
57 mod_timer(&ktimer, jiffies + HZ);
58}
59
60/*
61 * The echo function
62 */
63
64static void pps_ktimer_echo(int source, int event, void *data)
65{
66 pr_info("echo %s %s for source %d\n",
67 event & PPS_CAPTUREASSERT ? "assert" : "",
68 event & PPS_CAPTURECLEAR ? "clear" : "",
69 source);
70}
71
72/*
73 * The PPS info struct
74 */
75
76static struct pps_source_info pps_ktimer_info = {
77 .name = "ktimer",
78 .path = "",
79 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
80 PPS_ECHOASSERT |
81 PPS_CANWAIT | PPS_TSFMT_TSPEC,
82 .echo = pps_ktimer_echo,
83 .owner = THIS_MODULE,
84};
85
86/*
87 * Module staff
88 */
89
90static void __exit pps_ktimer_exit(void)
91{
92 del_timer_sync(&ktimer);
93 pps_unregister_source(source);
94
95 pr_info("ktimer PPS source unregistered\n");
96}
97
98static int __init pps_ktimer_init(void)
99{
100 int ret;
101
102 ret = pps_register_source(&pps_ktimer_info,
103 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
104 if (ret < 0) {
105 printk(KERN_ERR "cannot register ktimer source\n");
106 return ret;
107 }
108 source = ret;
109
110 setup_timer(&ktimer, pps_ktimer_event, 0);
111 mod_timer(&ktimer, jiffies + HZ);
112
113 pr_info("ktimer PPS source registered at %d\n", source);
114
115 return 0;
116}
117
118module_init(pps_ktimer_init);
119module_exit(pps_ktimer_exit);
120
121MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
122MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
123MODULE_LICENSE("GPL");
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c
new file mode 100644
index 000000000000..8e1932d29fd4
--- /dev/null
+++ b/drivers/pps/clients/pps-ldisc.c
@@ -0,0 +1,154 @@
1/*
2 * pps-ldisc.c -- PPS line discipline
3 *
4 *
5 * Copyright (C) 2008 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#include <linux/module.h>
23#include <linux/serial_core.h>
24#include <linux/tty.h>
25#include <linux/pps_kernel.h>
26
27#define PPS_TTY_MAGIC 0x0001
28
29static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status,
30 struct timespec *ts)
31{
32 int id = (long)tty->disc_data;
33 struct timespec __ts;
34 struct pps_ktime pps_ts;
35
36 /* First of all we get the time stamp... */
37 getnstimeofday(&__ts);
38
39 /* Does caller give us a timestamp? */
40 if (ts) { /* Yes. Let's use it! */
41 pps_ts.sec = ts->tv_sec;
42 pps_ts.nsec = ts->tv_nsec;
43 } else { /* No. Do it ourself! */
44 pps_ts.sec = __ts.tv_sec;
45 pps_ts.nsec = __ts.tv_nsec;
46 }
47
48 /* Now do the PPS event report */
49 pps_event(id, &pps_ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR,
50 NULL);
51
52 pr_debug("PPS %s at %lu on source #%d\n",
53 status ? "assert" : "clear", jiffies, id);
54}
55
56static int (*alias_n_tty_open)(struct tty_struct *tty);
57
58static int pps_tty_open(struct tty_struct *tty)
59{
60 struct pps_source_info info;
61 struct tty_driver *drv = tty->driver;
62 int index = tty->index + drv->name_base;
63 int ret;
64
65 info.owner = THIS_MODULE;
66 info.dev = NULL;
67 snprintf(info.name, PPS_MAX_NAME_LEN, "%s%d", drv->driver_name, index);
68 snprintf(info.path, PPS_MAX_NAME_LEN, "/dev/%s%d", drv->name, index);
69 info.mode = PPS_CAPTUREBOTH | \
70 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
71 PPS_CANWAIT | PPS_TSFMT_TSPEC;
72
73 ret = pps_register_source(&info, PPS_CAPTUREBOTH | \
74 PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
75 if (ret < 0) {
76 pr_err("cannot register PPS source \"%s\"\n", info.path);
77 return ret;
78 }
79 tty->disc_data = (void *)(long)ret;
80
81 /* Should open N_TTY ldisc too */
82 ret = alias_n_tty_open(tty);
83 if (ret < 0)
84 pps_unregister_source((long)tty->disc_data);
85
86 pr_info("PPS source #%d \"%s\" added\n", ret, info.path);
87
88 return 0;
89}
90
91static void (*alias_n_tty_close)(struct tty_struct *tty);
92
93static void pps_tty_close(struct tty_struct *tty)
94{
95 int id = (long)tty->disc_data;
96
97 pps_unregister_source(id);
98 alias_n_tty_close(tty);
99
100 pr_info("PPS source #%d removed\n", id);
101}
102
103static struct tty_ldisc_ops pps_ldisc_ops;
104
105/*
106 * Module stuff
107 */
108
109static int __init pps_tty_init(void)
110{
111 int err;
112
113 /* Inherit the N_TTY's ops */
114 n_tty_inherit_ops(&pps_ldisc_ops);
115
116 /* Save N_TTY's open()/close() methods */
117 alias_n_tty_open = pps_ldisc_ops.open;
118 alias_n_tty_close = pps_ldisc_ops.close;
119
120 /* Init PPS_TTY data */
121 pps_ldisc_ops.owner = THIS_MODULE;
122 pps_ldisc_ops.magic = PPS_TTY_MAGIC;
123 pps_ldisc_ops.name = "pps_tty";
124 pps_ldisc_ops.dcd_change = pps_tty_dcd_change;
125 pps_ldisc_ops.open = pps_tty_open;
126 pps_ldisc_ops.close = pps_tty_close;
127
128 err = tty_register_ldisc(N_PPS, &pps_ldisc_ops);
129 if (err)
130 pr_err("can't register PPS line discipline\n");
131 else
132 pr_info("PPS line discipline registered\n");
133
134 return err;
135}
136
137static void __exit pps_tty_cleanup(void)
138{
139 int err;
140
141 err = tty_unregister_ldisc(N_PPS);
142 if (err)
143 pr_err("can't unregister PPS line discipline\n");
144 else
145 pr_info("PPS line discipline removed\n");
146}
147
148module_init(pps_tty_init);
149module_exit(pps_tty_cleanup);
150
151MODULE_ALIAS_LDISC(N_PPS);
152MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
153MODULE_DESCRIPTION("PPS TTY device driver");
154MODULE_LICENSE("GPL");
diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
index 2d414e23d390..1aa02db3ff4e 100644
--- a/drivers/pps/kapi.c
+++ b/drivers/pps/kapi.c
@@ -29,6 +29,7 @@
29#include <linux/idr.h> 29#include <linux/idr.h>
30#include <linux/fs.h> 30#include <linux/fs.h>
31#include <linux/pps_kernel.h> 31#include <linux/pps_kernel.h>
32#include <linux/slab.h>
32 33
33/* 34/*
34 * Global variables 35 * Global variables