1/* 2 * PTP 1588 clock support - user space interface 3 * 4 * Copyright (C) 2010 OMICRON electronics GmbH 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#ifndef _PTP_CLOCK_H_ 22#define _PTP_CLOCK_H_ 23 24#include <linux/ioctl.h> 25#include <linux/types.h> 26 27/* PTP_xxx bits, for the flags field within the request structures. */ 28#define PTP_ENABLE_FEATURE (1<<0) 29#define PTP_RISING_EDGE (1<<1) 30#define PTP_FALLING_EDGE (1<<2) 31 32/* 33 * struct ptp_clock_time - represents a time value 34 * 35 * The sign of the seconds field applies to the whole value. The 36 * nanoseconds field is always unsigned. The reserved field is 37 * included for sub-nanosecond resolution, should the demand for 38 * this ever appear. 39 * 40 */ 41struct ptp_clock_time { 42 __s64 sec; /* seconds */ 43 __u32 nsec; /* nanoseconds */ 44 __u32 reserved; 45}; 46 47struct ptp_clock_caps { 48 int max_adj; /* Maximum frequency adjustment in parts per billon. */ 49 int n_alarm; /* Number of programmable alarms. */ 50 int n_ext_ts; /* Number of external time stamp channels. */ 51 int n_per_out; /* Number of programmable periodic signals. */ 52 int pps; /* Whether the clock supports a PPS callback. */ 53 int n_pins; /* Number of input/output pins. */ 54 /* Whether the clock supports precise system-device cross timestamps */ 55 int cross_timestamping; 56 int rsv[13]; /* Reserved for future use. */ 57}; 58 59struct ptp_extts_request { 60 unsigned int index; /* Which channel to configure. */ 61 unsigned int flags; /* Bit field for PTP_xxx flags. */ 62 unsigned int rsv[2]; /* Reserved for future use. */ 63}; 64 65struct ptp_perout_request { 66 struct ptp_clock_time start; /* Absolute start time. */ 67 struct ptp_clock_time period; /* Desired period, zero means disable. */ 68 unsigned int index; /* Which channel to configure. */ 69 unsigned int flags; /* Reserved for future use. */ 70 unsigned int rsv[4]; /* Reserved for future use. */ 71}; 72 73#define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ 74 75struct ptp_sys_offset { 76 unsigned int n_samples; /* Desired number of measurements. */ 77 unsigned int rsv[3]; /* Reserved for future use. */ 78 /* 79 * Array of interleaved system/phc time stamps. The kernel 80 * will provide 2*n_samples + 1 time stamps, with the last 81 * one as a system time stamp. 82 */ 83 struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 84}; 85 86struct ptp_sys_offset_precise { 87 struct ptp_clock_time device; 88 struct ptp_clock_time sys_realtime; 89 struct ptp_clock_time sys_monoraw; 90 unsigned int rsv[4]; /* Reserved for future use. */ 91}; 92 93enum ptp_pin_function { 94 PTP_PF_NONE, 95 PTP_PF_EXTTS, 96 PTP_PF_PEROUT, 97 PTP_PF_PHYSYNC, 98}; 99 100struct ptp_pin_desc { 101 /* 102 * Hardware specific human readable pin name. This field is 103 * set by the kernel during the PTP_PIN_GETFUNC ioctl and is 104 * ignored for the PTP_PIN_SETFUNC ioctl. 105 */ 106 char name[64]; 107 /* 108 * Pin index in the range of zero to ptp_clock_caps.n_pins - 1. 109 */ 110 unsigned int index; 111 /* 112 * Which of the PTP_PF_xxx functions to use on this pin. 113 */ 114 unsigned int func; 115 /* 116 * The specific channel to use for this function. 117 * This corresponds to the 'index' field of the 118 * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls. 119 */ 120 unsigned int chan; 121 /* 122 * Reserved for future use. 123 */ 124 unsigned int rsv[5]; 125}; 126 127#define PTP_CLK_MAGIC '=' 128 129#define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) 130#define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) 131#define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) 132#define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) 133#define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 134#define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) 135#define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) 136#define PTP_SYS_OFFSET_PRECISE \ 137 _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise) 138 139struct ptp_extts_event { 140 struct ptp_clock_time t; /* Time event occured. */ 141 unsigned int index; /* Which channel produced the event. */ 142 unsigned int flags; /* Reserved for future use. */ 143 unsigned int rsv[2]; /* Reserved for future use. */ 144}; 145 146#endif 147