xref: /linux/include/uapi/linux/pps.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  * PPS API header
4607ca46eSDavid Howells  *
5607ca46eSDavid Howells  * Copyright (C) 2005-2009   Rodolfo Giometti <giometti@linux.it>
6607ca46eSDavid Howells  *
7607ca46eSDavid Howells  *   This program is free software; you can redistribute it and/or modify
8607ca46eSDavid Howells  *   it under the terms of the GNU General Public License as published by
9607ca46eSDavid Howells  *   the Free Software Foundation; either version 2 of the License, or
10607ca46eSDavid Howells  *   (at your option) any later version.
11607ca46eSDavid Howells  *
12607ca46eSDavid Howells  *   This program is distributed in the hope that it will be useful,
13607ca46eSDavid Howells  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14607ca46eSDavid Howells  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15607ca46eSDavid Howells  *   GNU General Public License for more details.
16607ca46eSDavid Howells  *
17607ca46eSDavid Howells  *   You should have received a copy of the GNU General Public License
18607ca46eSDavid Howells  *   along with this program; if not, write to the Free Software
19607ca46eSDavid Howells  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20607ca46eSDavid Howells  */
21607ca46eSDavid Howells 
22607ca46eSDavid Howells 
23607ca46eSDavid Howells #ifndef _PPS_H_
24607ca46eSDavid Howells #define _PPS_H_
25607ca46eSDavid Howells 
26607ca46eSDavid Howells #include <linux/types.h>
27607ca46eSDavid Howells 
28607ca46eSDavid Howells #define PPS_VERSION		"5.3.6"
29607ca46eSDavid Howells #define PPS_MAX_SOURCES		16		/* should be enough... */
30607ca46eSDavid Howells 
31607ca46eSDavid Howells /* Implementation note: the logical states ``assert'' and ``clear''
32607ca46eSDavid Howells  * are implemented in terms of the chip register, i.e. ``assert''
33607ca46eSDavid Howells  * means the bit is set.  */
34607ca46eSDavid Howells 
35607ca46eSDavid Howells /*
36607ca46eSDavid Howells  * 3.2 New data structures
37607ca46eSDavid Howells  */
38607ca46eSDavid Howells 
39607ca46eSDavid Howells #define PPS_API_VERS_1		1
40607ca46eSDavid Howells #define PPS_API_VERS		PPS_API_VERS_1	/* we use API version 1 */
41607ca46eSDavid Howells #define PPS_MAX_NAME_LEN	32
42607ca46eSDavid Howells 
43607ca46eSDavid Howells /* 32-bit vs. 64-bit compatibility.
44607ca46eSDavid Howells  *
45607ca46eSDavid Howells  * 0n i386, the alignment of a uint64_t is only 4 bytes, while on most other
46607ca46eSDavid Howells  * architectures it's 8 bytes. On i386, there will be no padding between the
47607ca46eSDavid Howells  * two consecutive 'struct pps_ktime' members of struct pps_kinfo and struct
48607ca46eSDavid Howells  * pps_kparams. But on most platforms there will be padding to ensure correct
49607ca46eSDavid Howells  * alignment.
50607ca46eSDavid Howells  *
51607ca46eSDavid Howells  * The simple fix is probably to add an explicit padding.
52607ca46eSDavid Howells  *					 		[David Woodhouse]
53607ca46eSDavid Howells  */
54607ca46eSDavid Howells struct pps_ktime {
55607ca46eSDavid Howells 	__s64 sec;
56607ca46eSDavid Howells 	__s32 nsec;
57607ca46eSDavid Howells 	__u32 flags;
58607ca46eSDavid Howells };
59c2a49fe8SMatt Ranostay 
60c2a49fe8SMatt Ranostay struct pps_ktime_compat {
61c2a49fe8SMatt Ranostay 	__s64 sec;
62c2a49fe8SMatt Ranostay 	__s32 nsec;
63c2a49fe8SMatt Ranostay 	__u32 flags;
64c2a49fe8SMatt Ranostay } __attribute__((packed, aligned(4)));
65607ca46eSDavid Howells #define PPS_TIME_INVALID	(1<<0)	/* used to specify timeout==NULL */
66607ca46eSDavid Howells 
67607ca46eSDavid Howells struct pps_kinfo {
68607ca46eSDavid Howells 	__u32 assert_sequence;		/* seq. num. of assert event */
69607ca46eSDavid Howells 	__u32 clear_sequence; 		/* seq. num. of clear event */
70607ca46eSDavid Howells 	struct pps_ktime assert_tu;	/* time of assert event */
71607ca46eSDavid Howells 	struct pps_ktime clear_tu;	/* time of clear event */
72607ca46eSDavid Howells 	int current_mode;		/* current mode bits */
73607ca46eSDavid Howells };
74607ca46eSDavid Howells 
75c2a49fe8SMatt Ranostay struct pps_kinfo_compat {
76c2a49fe8SMatt Ranostay 	__u32 assert_sequence;			/* seq. num. of assert event */
77c2a49fe8SMatt Ranostay 	__u32 clear_sequence;			/* seq. num. of clear event */
78c2a49fe8SMatt Ranostay 	struct pps_ktime_compat assert_tu;	/* time of assert event */
79c2a49fe8SMatt Ranostay 	struct pps_ktime_compat clear_tu;	/* time of clear event */
80c2a49fe8SMatt Ranostay 	int current_mode;			/* current mode bits */
81c2a49fe8SMatt Ranostay };
82c2a49fe8SMatt Ranostay 
83607ca46eSDavid Howells struct pps_kparams {
84607ca46eSDavid Howells 	int api_version;		/* API version # */
85607ca46eSDavid Howells 	int mode;			/* mode bits */
86607ca46eSDavid Howells 	struct pps_ktime assert_off_tu;	/* offset compensation for assert */
87607ca46eSDavid Howells 	struct pps_ktime clear_off_tu;	/* offset compensation for clear */
88607ca46eSDavid Howells };
89607ca46eSDavid Howells 
90607ca46eSDavid Howells /*
91607ca46eSDavid Howells  * 3.3 Mode bit definitions
92607ca46eSDavid Howells  */
93607ca46eSDavid Howells 
94607ca46eSDavid Howells /* Device/implementation parameters */
95607ca46eSDavid Howells #define PPS_CAPTUREASSERT	0x01	/* capture assert events */
96607ca46eSDavid Howells #define PPS_CAPTURECLEAR	0x02	/* capture clear events */
97607ca46eSDavid Howells #define PPS_CAPTUREBOTH		0x03	/* capture assert and clear events */
98607ca46eSDavid Howells 
99a2d81803SRobert P. J. Day #define PPS_OFFSETASSERT	0x10	/* apply compensation for assert event */
100a2d81803SRobert P. J. Day #define PPS_OFFSETCLEAR		0x20	/* apply compensation for clear event */
101607ca46eSDavid Howells 
102607ca46eSDavid Howells #define PPS_CANWAIT		0x100	/* can we wait for an event? */
103607ca46eSDavid Howells #define PPS_CANPOLL		0x200	/* bit reserved for future use */
104607ca46eSDavid Howells 
105607ca46eSDavid Howells /* Kernel actions */
106607ca46eSDavid Howells #define PPS_ECHOASSERT		0x40	/* feed back assert event to output */
107607ca46eSDavid Howells #define PPS_ECHOCLEAR		0x80	/* feed back clear event to output */
108607ca46eSDavid Howells 
109607ca46eSDavid Howells /* Timestamp formats */
110607ca46eSDavid Howells #define PPS_TSFMT_TSPEC		0x1000	/* select timespec format */
111607ca46eSDavid Howells #define PPS_TSFMT_NTPFP		0x2000	/* select NTP format */
112607ca46eSDavid Howells 
113607ca46eSDavid Howells /*
114607ca46eSDavid Howells  * 3.4.4 New functions: disciplining the kernel timebase
115607ca46eSDavid Howells  */
116607ca46eSDavid Howells 
117607ca46eSDavid Howells /* Kernel consumers */
118607ca46eSDavid Howells #define PPS_KC_HARDPPS		0	/* hardpps() (or equivalent) */
119607ca46eSDavid Howells #define PPS_KC_HARDPPS_PLL	1	/* hardpps() constrained to
120607ca46eSDavid Howells 					   use a phase-locked loop */
121607ca46eSDavid Howells #define PPS_KC_HARDPPS_FLL	2	/* hardpps() constrained to
122607ca46eSDavid Howells 					   use a frequency-locked loop */
123607ca46eSDavid Howells /*
124607ca46eSDavid Howells  * Here begins the implementation-specific part!
125607ca46eSDavid Howells  */
126607ca46eSDavid Howells 
127607ca46eSDavid Howells struct pps_fdata {
128607ca46eSDavid Howells 	struct pps_kinfo info;
129607ca46eSDavid Howells 	struct pps_ktime timeout;
130607ca46eSDavid Howells };
131607ca46eSDavid Howells 
132c2a49fe8SMatt Ranostay struct pps_fdata_compat {
133c2a49fe8SMatt Ranostay 	struct pps_kinfo_compat info;
134c2a49fe8SMatt Ranostay 	struct pps_ktime_compat timeout;
135c2a49fe8SMatt Ranostay };
136c2a49fe8SMatt Ranostay 
137607ca46eSDavid Howells struct pps_bind_args {
138607ca46eSDavid Howells 	int tsformat;	/* format of time stamps */
139607ca46eSDavid Howells 	int edge;	/* selected event type */
140607ca46eSDavid Howells 	int consumer;	/* selected kernel consumer */
141607ca46eSDavid Howells };
142607ca46eSDavid Howells 
143607ca46eSDavid Howells #include <linux/ioctl.h>
144607ca46eSDavid Howells 
145607ca46eSDavid Howells #define PPS_GETPARAMS		_IOR('p', 0xa1, struct pps_kparams *)
146607ca46eSDavid Howells #define PPS_SETPARAMS		_IOW('p', 0xa2, struct pps_kparams *)
147607ca46eSDavid Howells #define PPS_GETCAP		_IOR('p', 0xa3, int *)
148607ca46eSDavid Howells #define PPS_FETCH		_IOWR('p', 0xa4, struct pps_fdata *)
149607ca46eSDavid Howells #define PPS_KC_BIND		_IOW('p', 0xa5, struct pps_bind_args *)
150607ca46eSDavid Howells 
151607ca46eSDavid Howells #endif /* _PPS_H_ */
152