1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * PPS API header 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2005-2009 Rodolfo Giometti <giometti@linux.it> 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify 8*4882a593Smuzhiyun * it under the terms of the GNU General Public License as published by 9*4882a593Smuzhiyun * the Free Software Foundation; either version 2 of the License, or 10*4882a593Smuzhiyun * (at your option) any later version. 11*4882a593Smuzhiyun * 12*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, 13*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of 14*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*4882a593Smuzhiyun * GNU General Public License for more details. 16*4882a593Smuzhiyun * 17*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License 18*4882a593Smuzhiyun * along with this program; if not, write to the Free Software 19*4882a593Smuzhiyun * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20*4882a593Smuzhiyun */ 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun #ifndef _PPS_H_ 24*4882a593Smuzhiyun #define _PPS_H_ 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun #include <linux/types.h> 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun #define PPS_VERSION "5.3.6" 29*4882a593Smuzhiyun #define PPS_MAX_SOURCES 16 /* should be enough... */ 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun /* Implementation note: the logical states ``assert'' and ``clear'' 32*4882a593Smuzhiyun * are implemented in terms of the chip register, i.e. ``assert'' 33*4882a593Smuzhiyun * means the bit is set. */ 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /* 36*4882a593Smuzhiyun * 3.2 New data structures 37*4882a593Smuzhiyun */ 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun #define PPS_API_VERS_1 1 40*4882a593Smuzhiyun #define PPS_API_VERS PPS_API_VERS_1 /* we use API version 1 */ 41*4882a593Smuzhiyun #define PPS_MAX_NAME_LEN 32 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun /* 32-bit vs. 64-bit compatibility. 44*4882a593Smuzhiyun * 45*4882a593Smuzhiyun * 0n i386, the alignment of a uint64_t is only 4 bytes, while on most other 46*4882a593Smuzhiyun * architectures it's 8 bytes. On i386, there will be no padding between the 47*4882a593Smuzhiyun * two consecutive 'struct pps_ktime' members of struct pps_kinfo and struct 48*4882a593Smuzhiyun * pps_kparams. But on most platforms there will be padding to ensure correct 49*4882a593Smuzhiyun * alignment. 50*4882a593Smuzhiyun * 51*4882a593Smuzhiyun * The simple fix is probably to add an explicit padding. 52*4882a593Smuzhiyun * [David Woodhouse] 53*4882a593Smuzhiyun */ 54*4882a593Smuzhiyun struct pps_ktime { 55*4882a593Smuzhiyun __s64 sec; 56*4882a593Smuzhiyun __s32 nsec; 57*4882a593Smuzhiyun __u32 flags; 58*4882a593Smuzhiyun }; 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun struct pps_ktime_compat { 61*4882a593Smuzhiyun __s64 sec; 62*4882a593Smuzhiyun __s32 nsec; 63*4882a593Smuzhiyun __u32 flags; 64*4882a593Smuzhiyun } __attribute__((packed, aligned(4))); 65*4882a593Smuzhiyun #define PPS_TIME_INVALID (1<<0) /* used to specify timeout==NULL */ 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun struct pps_kinfo { 68*4882a593Smuzhiyun __u32 assert_sequence; /* seq. num. of assert event */ 69*4882a593Smuzhiyun __u32 clear_sequence; /* seq. num. of clear event */ 70*4882a593Smuzhiyun struct pps_ktime assert_tu; /* time of assert event */ 71*4882a593Smuzhiyun struct pps_ktime clear_tu; /* time of clear event */ 72*4882a593Smuzhiyun int current_mode; /* current mode bits */ 73*4882a593Smuzhiyun }; 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun struct pps_kinfo_compat { 76*4882a593Smuzhiyun __u32 assert_sequence; /* seq. num. of assert event */ 77*4882a593Smuzhiyun __u32 clear_sequence; /* seq. num. of clear event */ 78*4882a593Smuzhiyun struct pps_ktime_compat assert_tu; /* time of assert event */ 79*4882a593Smuzhiyun struct pps_ktime_compat clear_tu; /* time of clear event */ 80*4882a593Smuzhiyun int current_mode; /* current mode bits */ 81*4882a593Smuzhiyun }; 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun struct pps_kparams { 84*4882a593Smuzhiyun int api_version; /* API version # */ 85*4882a593Smuzhiyun int mode; /* mode bits */ 86*4882a593Smuzhiyun struct pps_ktime assert_off_tu; /* offset compensation for assert */ 87*4882a593Smuzhiyun struct pps_ktime clear_off_tu; /* offset compensation for clear */ 88*4882a593Smuzhiyun }; 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun /* 91*4882a593Smuzhiyun * 3.3 Mode bit definitions 92*4882a593Smuzhiyun */ 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun /* Device/implementation parameters */ 95*4882a593Smuzhiyun #define PPS_CAPTUREASSERT 0x01 /* capture assert events */ 96*4882a593Smuzhiyun #define PPS_CAPTURECLEAR 0x02 /* capture clear events */ 97*4882a593Smuzhiyun #define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */ 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun #define PPS_OFFSETASSERT 0x10 /* apply compensation for assert event */ 100*4882a593Smuzhiyun #define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear event */ 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun #define PPS_CANWAIT 0x100 /* can we wait for an event? */ 103*4882a593Smuzhiyun #define PPS_CANPOLL 0x200 /* bit reserved for future use */ 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun /* Kernel actions */ 106*4882a593Smuzhiyun #define PPS_ECHOASSERT 0x40 /* feed back assert event to output */ 107*4882a593Smuzhiyun #define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */ 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun /* Timestamp formats */ 110*4882a593Smuzhiyun #define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */ 111*4882a593Smuzhiyun #define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */ 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun /* 114*4882a593Smuzhiyun * 3.4.4 New functions: disciplining the kernel timebase 115*4882a593Smuzhiyun */ 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun /* Kernel consumers */ 118*4882a593Smuzhiyun #define PPS_KC_HARDPPS 0 /* hardpps() (or equivalent) */ 119*4882a593Smuzhiyun #define PPS_KC_HARDPPS_PLL 1 /* hardpps() constrained to 120*4882a593Smuzhiyun use a phase-locked loop */ 121*4882a593Smuzhiyun #define PPS_KC_HARDPPS_FLL 2 /* hardpps() constrained to 122*4882a593Smuzhiyun use a frequency-locked loop */ 123*4882a593Smuzhiyun /* 124*4882a593Smuzhiyun * Here begins the implementation-specific part! 125*4882a593Smuzhiyun */ 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun struct pps_fdata { 128*4882a593Smuzhiyun struct pps_kinfo info; 129*4882a593Smuzhiyun struct pps_ktime timeout; 130*4882a593Smuzhiyun }; 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun struct pps_fdata_compat { 133*4882a593Smuzhiyun struct pps_kinfo_compat info; 134*4882a593Smuzhiyun struct pps_ktime_compat timeout; 135*4882a593Smuzhiyun }; 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun struct pps_bind_args { 138*4882a593Smuzhiyun int tsformat; /* format of time stamps */ 139*4882a593Smuzhiyun int edge; /* selected event type */ 140*4882a593Smuzhiyun int consumer; /* selected kernel consumer */ 141*4882a593Smuzhiyun }; 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun #include <linux/ioctl.h> 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun #define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *) 146*4882a593Smuzhiyun #define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *) 147*4882a593Smuzhiyun #define PPS_GETCAP _IOR('p', 0xa3, int *) 148*4882a593Smuzhiyun #define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *) 149*4882a593Smuzhiyun #define PPS_KC_BIND _IOW('p', 0xa5, struct pps_bind_args *) 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun #endif /* _PPS_H_ */ 152