diff options
author | Rodolfo Giometti <giometti@linux.it> | 2009-06-17 19:28:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-18 16:04:04 -0400 |
commit | eae9d2ba0cfc27a2ad9765f23efb98fb80d80234 (patch) | |
tree | f4be40ca528b2f23f97fa9cb6ebe91b8d6696d5b /include | |
parent | 8820f27ad9a5ad2a62cdcdf425d7921c31831800 (diff) |
LinuxPPS: core support
This patch adds the kernel side of the PPS support currently named
"LinuxPPS".
PPS means "pulse per second" and a PPS source is just a device which
provides a high precision signal each second so that an application can
use it to adjust system clock time.
Common use is the combination of the NTPD as userland program with a GPS
receiver as PPS source to obtain a wallclock-time with sub-millisecond
synchronisation to UTC.
To obtain this goal the userland programs shoud use the PPS API
specification (RFC 2783 - Pulse-Per-Second API for UNIX-like Operating
Systems, Version 1.0) which in part is implemented by this patch. It
provides a set of chars devices, one per PPS source, which can be used to
get the time signal. The RFC's functions can be implemented by accessing
to these char devices.
Signed-off-by: Rodolfo Giometti <giometti@linux.it>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Greg KH <greg@kroah.com>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Acked-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/Kbuild | 1 | ||||
-rw-r--r-- | include/linux/pps.h | 122 | ||||
-rw-r--r-- | include/linux/pps_kernel.h | 89 |
3 files changed, 212 insertions, 0 deletions
diff --git a/include/linux/Kbuild b/include/linux/Kbuild index a2df7030d49d..03f22076381f 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild | |||
@@ -308,6 +308,7 @@ unifdef-y += pmu.h | |||
308 | unifdef-y += poll.h | 308 | unifdef-y += poll.h |
309 | unifdef-y += ppp_defs.h | 309 | unifdef-y += ppp_defs.h |
310 | unifdef-y += ppp-comp.h | 310 | unifdef-y += ppp-comp.h |
311 | unifdef-y += pps.h | ||
311 | unifdef-y += ptrace.h | 312 | unifdef-y += ptrace.h |
312 | unifdef-y += quota.h | 313 | unifdef-y += quota.h |
313 | unifdef-y += random.h | 314 | unifdef-y += random.h |
diff --git a/include/linux/pps.h b/include/linux/pps.h new file mode 100644 index 000000000000..cfe5c7214ec6 --- /dev/null +++ b/include/linux/pps.h | |||
@@ -0,0 +1,122 @@ | |||
1 | /* | ||
2 | * PPS API header | ||
3 | * | ||
4 | * Copyright (C) 2005-2009 Rodolfo Giometti <giometti@linux.it> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | |||
22 | #ifndef _PPS_H_ | ||
23 | #define _PPS_H_ | ||
24 | |||
25 | #define PPS_VERSION "5.3.6" | ||
26 | #define PPS_MAX_SOURCES 16 /* should be enough... */ | ||
27 | |||
28 | /* Implementation note: the logical states ``assert'' and ``clear'' | ||
29 | * are implemented in terms of the chip register, i.e. ``assert'' | ||
30 | * means the bit is set. */ | ||
31 | |||
32 | /* | ||
33 | * 3.2 New data structures | ||
34 | */ | ||
35 | |||
36 | #define PPS_API_VERS_1 1 | ||
37 | #define PPS_API_VERS PPS_API_VERS_1 /* we use API version 1 */ | ||
38 | #define PPS_MAX_NAME_LEN 32 | ||
39 | |||
40 | /* 32-bit vs. 64-bit compatibility. | ||
41 | * | ||
42 | * 0n i386, the alignment of a uint64_t is only 4 bytes, while on most other | ||
43 | * architectures it's 8 bytes. On i386, there will be no padding between the | ||
44 | * two consecutive 'struct pps_ktime' members of struct pps_kinfo and struct | ||
45 | * pps_kparams. But on most platforms there will be padding to ensure correct | ||
46 | * alignment. | ||
47 | * | ||
48 | * The simple fix is probably to add an explicit padding. | ||
49 | * [David Woodhouse] | ||
50 | */ | ||
51 | struct pps_ktime { | ||
52 | __s64 sec; | ||
53 | __s32 nsec; | ||
54 | __u32 flags; | ||
55 | }; | ||
56 | #define PPS_TIME_INVALID (1<<0) /* used to specify timeout==NULL */ | ||
57 | |||
58 | struct pps_kinfo { | ||
59 | __u32 assert_sequence; /* seq. num. of assert event */ | ||
60 | __u32 clear_sequence; /* seq. num. of clear event */ | ||
61 | struct pps_ktime assert_tu; /* time of assert event */ | ||
62 | struct pps_ktime clear_tu; /* time of clear event */ | ||
63 | int current_mode; /* current mode bits */ | ||
64 | }; | ||
65 | |||
66 | struct pps_kparams { | ||
67 | int api_version; /* API version # */ | ||
68 | int mode; /* mode bits */ | ||
69 | struct pps_ktime assert_off_tu; /* offset compensation for assert */ | ||
70 | struct pps_ktime clear_off_tu; /* offset compensation for clear */ | ||
71 | }; | ||
72 | |||
73 | /* | ||
74 | * 3.3 Mode bit definitions | ||
75 | */ | ||
76 | |||
77 | /* Device/implementation parameters */ | ||
78 | #define PPS_CAPTUREASSERT 0x01 /* capture assert events */ | ||
79 | #define PPS_CAPTURECLEAR 0x02 /* capture clear events */ | ||
80 | #define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */ | ||
81 | |||
82 | #define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */ | ||
83 | #define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */ | ||
84 | |||
85 | #define PPS_CANWAIT 0x100 /* can we wait for an event? */ | ||
86 | #define PPS_CANPOLL 0x200 /* bit reserved for future use */ | ||
87 | |||
88 | /* Kernel actions */ | ||
89 | #define PPS_ECHOASSERT 0x40 /* feed back assert event to output */ | ||
90 | #define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */ | ||
91 | |||
92 | /* Timestamp formats */ | ||
93 | #define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */ | ||
94 | #define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */ | ||
95 | |||
96 | /* | ||
97 | * 3.4.4 New functions: disciplining the kernel timebase | ||
98 | */ | ||
99 | |||
100 | /* Kernel consumers */ | ||
101 | #define PPS_KC_HARDPPS 0 /* hardpps() (or equivalent) */ | ||
102 | #define PPS_KC_HARDPPS_PLL 1 /* hardpps() constrained to | ||
103 | use a phase-locked loop */ | ||
104 | #define PPS_KC_HARDPPS_FLL 2 /* hardpps() constrained to | ||
105 | use a frequency-locked loop */ | ||
106 | /* | ||
107 | * Here begins the implementation-specific part! | ||
108 | */ | ||
109 | |||
110 | struct pps_fdata { | ||
111 | struct pps_kinfo info; | ||
112 | struct pps_ktime timeout; | ||
113 | }; | ||
114 | |||
115 | #include <linux/ioctl.h> | ||
116 | |||
117 | #define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *) | ||
118 | #define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *) | ||
119 | #define PPS_GETCAP _IOR('p', 0xa3, int *) | ||
120 | #define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *) | ||
121 | |||
122 | #endif /* _PPS_H_ */ | ||
diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h new file mode 100644 index 000000000000..e0a193f830ef --- /dev/null +++ b/include/linux/pps_kernel.h | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * PPS API kernel header | ||
3 | * | ||
4 | * Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #include <linux/pps.h> | ||
22 | |||
23 | #include <linux/cdev.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/time.h> | ||
26 | |||
27 | /* | ||
28 | * Global defines | ||
29 | */ | ||
30 | |||
31 | /* The specific PPS source info */ | ||
32 | struct pps_source_info { | ||
33 | char name[PPS_MAX_NAME_LEN]; /* simbolic name */ | ||
34 | char path[PPS_MAX_NAME_LEN]; /* path of connected device */ | ||
35 | int mode; /* PPS's allowed mode */ | ||
36 | |||
37 | void (*echo)(int source, int event, void *data); /* PPS echo function */ | ||
38 | |||
39 | struct module *owner; | ||
40 | struct device *dev; | ||
41 | }; | ||
42 | |||
43 | /* The main struct */ | ||
44 | struct pps_device { | ||
45 | struct pps_source_info info; /* PSS source info */ | ||
46 | |||
47 | struct pps_kparams params; /* PPS's current params */ | ||
48 | |||
49 | __u32 assert_sequence; /* PPS' assert event seq # */ | ||
50 | __u32 clear_sequence; /* PPS' clear event seq # */ | ||
51 | struct pps_ktime assert_tu; | ||
52 | struct pps_ktime clear_tu; | ||
53 | int current_mode; /* PPS mode at event time */ | ||
54 | |||
55 | int go; /* PPS event is arrived? */ | ||
56 | wait_queue_head_t queue; /* PPS event queue */ | ||
57 | |||
58 | unsigned int id; /* PPS source unique ID */ | ||
59 | struct cdev cdev; | ||
60 | struct device *dev; | ||
61 | int devno; | ||
62 | struct fasync_struct *async_queue; /* fasync method */ | ||
63 | spinlock_t lock; | ||
64 | |||
65 | atomic_t usage; /* usage count */ | ||
66 | }; | ||
67 | |||
68 | /* | ||
69 | * Global variables | ||
70 | */ | ||
71 | |||
72 | extern spinlock_t pps_idr_lock; | ||
73 | extern struct idr pps_idr; | ||
74 | extern struct timespec pps_irq_ts[]; | ||
75 | |||
76 | extern struct device_attribute pps_attrs[]; | ||
77 | |||
78 | /* | ||
79 | * Exported functions | ||
80 | */ | ||
81 | |||
82 | struct pps_device *pps_get_source(int source); | ||
83 | extern void pps_put_source(struct pps_device *pps); | ||
84 | extern int pps_register_source(struct pps_source_info *info, | ||
85 | int default_params); | ||
86 | extern void pps_unregister_source(int source); | ||
87 | extern int pps_register_cdev(struct pps_device *pps); | ||
88 | extern void pps_unregister_cdev(struct pps_device *pps); | ||
89 | extern void pps_event(int source, struct pps_ktime *ts, int event, void *data); | ||