diff options
author | Alexander Gordeev <lasaine@lvk.cs.msu.su> | 2011-01-12 20:00:50 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 11:03:19 -0500 |
commit | 6f4229b51106cbc859e9d8209b22c8a2ec749e64 (patch) | |
tree | 346e08800b0f45330e99c9fae0255c73f1666835 | |
parent | 3003d55b59aa98aeaff2773df69732b27c0cbf6a (diff) |
pps: unify timestamp gathering
Add a helper function to gather timestamps. This way clients don't have
to duplicate it.
Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su>
Acked-by: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/pps/clients/pps-ktimer.c | 9 | ||||
-rw-r--r-- | drivers/pps/clients/pps-ldisc.c | 18 | ||||
-rw-r--r-- | drivers/pps/kapi.c | 19 | ||||
-rw-r--r-- | include/linux/pps_kernel.h | 20 | ||||
-rw-r--r-- | include/linux/serial_core.h | 5 | ||||
-rw-r--r-- | include/linux/tty_ldisc.h | 5 |
6 files changed, 45 insertions, 31 deletions
diff --git a/drivers/pps/clients/pps-ktimer.c b/drivers/pps/clients/pps-ktimer.c index e7ef5b8186d0..e1bdd8bc8c9c 100644 --- a/drivers/pps/clients/pps-ktimer.c +++ b/drivers/pps/clients/pps-ktimer.c | |||
@@ -40,18 +40,13 @@ static struct timer_list ktimer; | |||
40 | 40 | ||
41 | static void pps_ktimer_event(unsigned long ptr) | 41 | static void pps_ktimer_event(unsigned long ptr) |
42 | { | 42 | { |
43 | struct timespec __ts; | 43 | struct pps_event_time ts; |
44 | struct pps_ktime ts; | ||
45 | 44 | ||
46 | /* First of all we get the time stamp... */ | 45 | /* First of all we get the time stamp... */ |
47 | getnstimeofday(&__ts); | 46 | pps_get_ts(&ts); |
48 | 47 | ||
49 | pr_info("PPS event at %lu\n", jiffies); | 48 | pr_info("PPS event at %lu\n", jiffies); |
50 | 49 | ||
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); | 50 | pps_event(source, &ts, PPS_CAPTUREASSERT, NULL); |
56 | 51 | ||
57 | mod_timer(&ktimer, jiffies + HZ); | 52 | mod_timer(&ktimer, jiffies + HZ); |
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c index 8e1932d29fd4..20fc9f7645c8 100644 --- a/drivers/pps/clients/pps-ldisc.c +++ b/drivers/pps/clients/pps-ldisc.c | |||
@@ -27,26 +27,20 @@ | |||
27 | #define PPS_TTY_MAGIC 0x0001 | 27 | #define PPS_TTY_MAGIC 0x0001 |
28 | 28 | ||
29 | static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, | 29 | static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, |
30 | struct timespec *ts) | 30 | struct pps_event_time *ts) |
31 | { | 31 | { |
32 | int id = (long)tty->disc_data; | 32 | int id = (long)tty->disc_data; |
33 | struct timespec __ts; | 33 | struct pps_event_time __ts; |
34 | struct pps_ktime pps_ts; | ||
35 | 34 | ||
36 | /* First of all we get the time stamp... */ | 35 | /* First of all we get the time stamp... */ |
37 | getnstimeofday(&__ts); | 36 | pps_get_ts(&__ts); |
38 | 37 | ||
39 | /* Does caller give us a timestamp? */ | 38 | /* Does caller give us a timestamp? */ |
40 | if (ts) { /* Yes. Let's use it! */ | 39 | if (!ts) /* No. Do it ourself! */ |
41 | pps_ts.sec = ts->tv_sec; | 40 | ts = &__ts; |
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 | 41 | ||
48 | /* Now do the PPS event report */ | 42 | /* Now do the PPS event report */ |
49 | pps_event(id, &pps_ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR, | 43 | pps_event(id, ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR, |
50 | NULL); | 44 | NULL); |
51 | 45 | ||
52 | pr_debug("PPS %s at %lu on source #%d\n", | 46 | pr_debug("PPS %s at %lu on source #%d\n", |
diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c index 3f89f5eba81c..b431d83b824a 100644 --- a/drivers/pps/kapi.c +++ b/drivers/pps/kapi.c | |||
@@ -268,11 +268,12 @@ EXPORT_SYMBOL(pps_unregister_source); | |||
268 | * pps->info.echo(source, event, data); | 268 | * pps->info.echo(source, event, data); |
269 | */ | 269 | */ |
270 | 270 | ||
271 | void pps_event(int source, struct pps_ktime *ts, int event, void *data) | 271 | void pps_event(int source, struct pps_event_time *ts, int event, void *data) |
272 | { | 272 | { |
273 | struct pps_device *pps; | 273 | struct pps_device *pps; |
274 | unsigned long flags; | 274 | unsigned long flags; |
275 | int captured = 0; | 275 | int captured = 0; |
276 | struct pps_ktime ts_real; | ||
276 | 277 | ||
277 | if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0) { | 278 | if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0) { |
278 | printk(KERN_ERR "pps: unknown event (%x) for source %d\n", | 279 | printk(KERN_ERR "pps: unknown event (%x) for source %d\n", |
@@ -284,8 +285,10 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) | |||
284 | if (!pps) | 285 | if (!pps) |
285 | return; | 286 | return; |
286 | 287 | ||
287 | pr_debug("PPS event on source %d at %llu.%06u\n", | 288 | pr_debug("PPS event on source %d at %ld.%09ld\n", |
288 | pps->id, (unsigned long long) ts->sec, ts->nsec); | 289 | pps->id, ts->ts_real.tv_sec, ts->ts_real.tv_nsec); |
290 | |||
291 | timespec_to_pps_ktime(&ts_real, ts->ts_real); | ||
289 | 292 | ||
290 | spin_lock_irqsave(&pps->lock, flags); | 293 | spin_lock_irqsave(&pps->lock, flags); |
291 | 294 | ||
@@ -299,10 +302,11 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) | |||
299 | (pps->params.mode & PPS_CAPTUREASSERT)) { | 302 | (pps->params.mode & PPS_CAPTUREASSERT)) { |
300 | /* We have to add an offset? */ | 303 | /* We have to add an offset? */ |
301 | if (pps->params.mode & PPS_OFFSETASSERT) | 304 | if (pps->params.mode & PPS_OFFSETASSERT) |
302 | pps_add_offset(ts, &pps->params.assert_off_tu); | 305 | pps_add_offset(&ts_real, |
306 | &pps->params.assert_off_tu); | ||
303 | 307 | ||
304 | /* Save the time stamp */ | 308 | /* Save the time stamp */ |
305 | pps->assert_tu = *ts; | 309 | pps->assert_tu = ts_real; |
306 | pps->assert_sequence++; | 310 | pps->assert_sequence++; |
307 | pr_debug("capture assert seq #%u for source %d\n", | 311 | pr_debug("capture assert seq #%u for source %d\n", |
308 | pps->assert_sequence, source); | 312 | pps->assert_sequence, source); |
@@ -313,10 +317,11 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) | |||
313 | (pps->params.mode & PPS_CAPTURECLEAR)) { | 317 | (pps->params.mode & PPS_CAPTURECLEAR)) { |
314 | /* We have to add an offset? */ | 318 | /* We have to add an offset? */ |
315 | if (pps->params.mode & PPS_OFFSETCLEAR) | 319 | if (pps->params.mode & PPS_OFFSETCLEAR) |
316 | pps_add_offset(ts, &pps->params.clear_off_tu); | 320 | pps_add_offset(&ts_real, |
321 | &pps->params.clear_off_tu); | ||
317 | 322 | ||
318 | /* Save the time stamp */ | 323 | /* Save the time stamp */ |
319 | pps->clear_tu = *ts; | 324 | pps->clear_tu = ts_real; |
320 | pps->clear_sequence++; | 325 | pps->clear_sequence++; |
321 | pr_debug("capture clear seq #%u for source %d\n", | 326 | pr_debug("capture clear seq #%u for source %d\n", |
322 | pps->clear_sequence, source); | 327 | pps->clear_sequence, source); |
diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h index 65194fe498bb..32aa6763ca1b 100644 --- a/include/linux/pps_kernel.h +++ b/include/linux/pps_kernel.h | |||
@@ -43,6 +43,10 @@ struct pps_source_info { | |||
43 | struct device *dev; | 43 | struct device *dev; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | struct pps_event_time { | ||
47 | struct timespec ts_real; | ||
48 | }; | ||
49 | |||
46 | /* The main struct */ | 50 | /* The main struct */ |
47 | struct pps_device { | 51 | struct pps_device { |
48 | struct pps_source_info info; /* PSS source info */ | 52 | struct pps_source_info info; /* PSS source info */ |
@@ -88,6 +92,20 @@ extern int pps_register_source(struct pps_source_info *info, | |||
88 | extern void pps_unregister_source(int source); | 92 | extern void pps_unregister_source(int source); |
89 | extern int pps_register_cdev(struct pps_device *pps); | 93 | extern int pps_register_cdev(struct pps_device *pps); |
90 | extern void pps_unregister_cdev(struct pps_device *pps); | 94 | extern void pps_unregister_cdev(struct pps_device *pps); |
91 | extern void pps_event(int source, struct pps_ktime *ts, int event, void *data); | 95 | extern void pps_event(int source, struct pps_event_time *ts, int event, |
96 | void *data); | ||
97 | |||
98 | static inline void timespec_to_pps_ktime(struct pps_ktime *kt, | ||
99 | struct timespec ts) | ||
100 | { | ||
101 | kt->sec = ts.tv_sec; | ||
102 | kt->nsec = ts.tv_nsec; | ||
103 | } | ||
104 | |||
105 | static inline void pps_get_ts(struct pps_event_time *ts) | ||
106 | { | ||
107 | getnstimeofday(&ts->ts_real); | ||
108 | } | ||
92 | 109 | ||
93 | #endif /* LINUX_PPS_KERNEL_H */ | 110 | #endif /* LINUX_PPS_KERNEL_H */ |
111 | |||
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index a23fa29d4eb0..758c5b0c6fd3 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h | |||
@@ -212,6 +212,7 @@ | |||
212 | #include <linux/tty.h> | 212 | #include <linux/tty.h> |
213 | #include <linux/mutex.h> | 213 | #include <linux/mutex.h> |
214 | #include <linux/sysrq.h> | 214 | #include <linux/sysrq.h> |
215 | #include <linux/pps_kernel.h> | ||
215 | 216 | ||
216 | struct uart_port; | 217 | struct uart_port; |
217 | struct serial_struct; | 218 | struct serial_struct; |
@@ -528,10 +529,10 @@ uart_handle_dcd_change(struct uart_port *uport, unsigned int status) | |||
528 | struct uart_state *state = uport->state; | 529 | struct uart_state *state = uport->state; |
529 | struct tty_port *port = &state->port; | 530 | struct tty_port *port = &state->port; |
530 | struct tty_ldisc *ld = tty_ldisc_ref(port->tty); | 531 | struct tty_ldisc *ld = tty_ldisc_ref(port->tty); |
531 | struct timespec ts; | 532 | struct pps_event_time ts; |
532 | 533 | ||
533 | if (ld && ld->ops->dcd_change) | 534 | if (ld && ld->ops->dcd_change) |
534 | getnstimeofday(&ts); | 535 | pps_get_ts(&ts); |
535 | 536 | ||
536 | uport->icount.dcd++; | 537 | uport->icount.dcd++; |
537 | #ifdef CONFIG_HARD_PPS | 538 | #ifdef CONFIG_HARD_PPS |
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h index 526d66f066a3..763e061e19f1 100644 --- a/include/linux/tty_ldisc.h +++ b/include/linux/tty_ldisc.h | |||
@@ -101,7 +101,7 @@ | |||
101 | * any pending driver I/O is completed. | 101 | * any pending driver I/O is completed. |
102 | * | 102 | * |
103 | * void (*dcd_change)(struct tty_struct *tty, unsigned int status, | 103 | * void (*dcd_change)(struct tty_struct *tty, unsigned int status, |
104 | * struct timespec *ts) | 104 | * struct pps_event_time *ts) |
105 | * | 105 | * |
106 | * Tells the discipline that the DCD pin has changed its status and | 106 | * Tells the discipline that the DCD pin has changed its status and |
107 | * the relative timestamp. Pointer ts can be NULL. | 107 | * the relative timestamp. Pointer ts can be NULL. |
@@ -109,6 +109,7 @@ | |||
109 | 109 | ||
110 | #include <linux/fs.h> | 110 | #include <linux/fs.h> |
111 | #include <linux/wait.h> | 111 | #include <linux/wait.h> |
112 | #include <linux/pps_kernel.h> | ||
112 | 113 | ||
113 | struct tty_ldisc_ops { | 114 | struct tty_ldisc_ops { |
114 | int magic; | 115 | int magic; |
@@ -143,7 +144,7 @@ struct tty_ldisc_ops { | |||
143 | char *fp, int count); | 144 | char *fp, int count); |
144 | void (*write_wakeup)(struct tty_struct *); | 145 | void (*write_wakeup)(struct tty_struct *); |
145 | void (*dcd_change)(struct tty_struct *, unsigned int, | 146 | void (*dcd_change)(struct tty_struct *, unsigned int, |
146 | struct timespec *); | 147 | struct pps_event_time *); |
147 | 148 | ||
148 | struct module *owner; | 149 | struct module *owner; |
149 | 150 | ||