130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * PPS API header 330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Copyright (C) 2005-2009 Rodolfo Giometti <giometti@linux.it> 530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * This program is free software; you can redistribute it and/or modify 730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * it under the terms of the GNU General Public License as published by 830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * the Free Software Foundation; either version 2 of the License, or 930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * (at your option) any later version. 1030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 1130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * This program is distributed in the hope that it will be useful, 1230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * but WITHOUT ANY WARRANTY; without even the implied warranty of 1330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * GNU General Public License for more details. 1530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 1630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * You should have received a copy of the GNU General Public License 1730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * along with this program; if not, write to the Free Software 1830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 2030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#ifndef _PPS_H_ 2330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define _PPS_H_ 2430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/types.h> 2630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_VERSION "5.3.6" 2830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_MAX_SOURCES 16 /* should be enough... */ 2930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 3030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Implementation note: the logical states ``assert'' and ``clear'' 3130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * are implemented in terms of the chip register, i.e. ``assert'' 3230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * means the bit is set. */ 3330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 3430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 3530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 3.2 New data structures 3630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 3730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 3830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_API_VERS_1 1 3930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_API_VERS PPS_API_VERS_1 /* we use API version 1 */ 4030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_MAX_NAME_LEN 32 4130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 4230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 32-bit vs. 64-bit compatibility. 4330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 4430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 0n i386, the alignment of a uint64_t is only 4 bytes, while on most other 4530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * architectures it's 8 bytes. On i386, there will be no padding between the 4630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * two consecutive 'struct pps_ktime' members of struct pps_kinfo and struct 4730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * pps_kparams. But on most platforms there will be padding to ensure correct 4830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * alignment. 4930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 5030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * The simple fix is probably to add an explicit padding. 5130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * [David Woodhouse] 5230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 5330692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pps_ktime { 5430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng __s64 sec; 5530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng __s32 nsec; 5630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng __u32 flags; 5730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng}; 5830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_TIME_INVALID (1<<0) /* used to specify timeout==NULL */ 5930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 6030692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pps_kinfo { 6130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng __u32 assert_sequence; /* seq. num. of assert event */ 6230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng __u32 clear_sequence; /* seq. num. of clear event */ 6330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng struct pps_ktime assert_tu; /* time of assert event */ 6430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng struct pps_ktime clear_tu; /* time of clear event */ 6530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng int current_mode; /* current mode bits */ 6630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng}; 6730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 6830692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pps_kparams { 6930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng int api_version; /* API version # */ 7030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng int mode; /* mode bits */ 7130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng struct pps_ktime assert_off_tu; /* offset compensation for assert */ 7230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng struct pps_ktime clear_off_tu; /* offset compensation for clear */ 7330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng}; 7430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 7530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 7630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 3.3 Mode bit definitions 7730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 7830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 7930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Device/implementation parameters */ 8030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_CAPTUREASSERT 0x01 /* capture assert events */ 8130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_CAPTURECLEAR 0x02 /* capture clear events */ 8230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */ 8330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 8430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */ 8530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */ 8630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 8730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_CANWAIT 0x100 /* can we wait for an event? */ 8830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_CANPOLL 0x200 /* bit reserved for future use */ 8930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 9030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Kernel actions */ 9130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_ECHOASSERT 0x40 /* feed back assert event to output */ 9230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */ 9330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 9430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Timestamp formats */ 9530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */ 9630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */ 9730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 9830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 9930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 3.4.4 New functions: disciplining the kernel timebase 10030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 10130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 10230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Kernel consumers */ 10330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_KC_HARDPPS 0 /* hardpps() (or equivalent) */ 10430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_KC_HARDPPS_PLL 1 /* hardpps() constrained to 10530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng use a phase-locked loop */ 10630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_KC_HARDPPS_FLL 2 /* hardpps() constrained to 10730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng use a frequency-locked loop */ 10830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 10930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Here begins the implementation-specific part! 11030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 11130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 11230692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pps_fdata { 11330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng struct pps_kinfo info; 11430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng struct pps_ktime timeout; 11530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng}; 11630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 11730692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pps_bind_args { 11830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng int tsformat; /* format of time stamps */ 11930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng int edge; /* selected event type */ 12030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng int consumer; /* selected kernel consumer */ 12130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng}; 12230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 12330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/ioctl.h> 12430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 12530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *) 12630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *) 12730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_GETCAP _IOR('p', 0xa3, int *) 12830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *) 12930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PPS_KC_BIND _IOW('p', 0xa5, struct pps_bind_args *) 13030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 13130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#endif /* _PPS_H_ */ 132