1607ca46eSDavid Howells /* 2607ca46eSDavid Howells * PTP 1588 clock support - user space interface 3607ca46eSDavid Howells * 4607ca46eSDavid Howells * Copyright (C) 2010 OMICRON electronics GmbH 5607ca46eSDavid Howells * 6607ca46eSDavid Howells * This program is free software; you can redistribute it and/or modify 7607ca46eSDavid Howells * it under the terms of the GNU General Public License as published by 8607ca46eSDavid Howells * the Free Software Foundation; either version 2 of the License, or 9607ca46eSDavid Howells * (at your option) any later version. 10607ca46eSDavid Howells * 11607ca46eSDavid Howells * This program is distributed in the hope that it will be useful, 12607ca46eSDavid Howells * but WITHOUT ANY WARRANTY; without even the implied warranty of 13607ca46eSDavid Howells * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14607ca46eSDavid Howells * GNU General Public License for more details. 15607ca46eSDavid Howells * 16607ca46eSDavid Howells * You should have received a copy of the GNU General Public License 17607ca46eSDavid Howells * along with this program; if not, write to the Free Software 18607ca46eSDavid Howells * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19607ca46eSDavid Howells */ 20607ca46eSDavid Howells 21607ca46eSDavid Howells #ifndef _PTP_CLOCK_H_ 22607ca46eSDavid Howells #define _PTP_CLOCK_H_ 23607ca46eSDavid Howells 24607ca46eSDavid Howells #include <linux/ioctl.h> 25607ca46eSDavid Howells #include <linux/types.h> 26607ca46eSDavid Howells 27607ca46eSDavid Howells /* PTP_xxx bits, for the flags field within the request structures. */ 28607ca46eSDavid Howells #define PTP_ENABLE_FEATURE (1<<0) 29607ca46eSDavid Howells #define PTP_RISING_EDGE (1<<1) 30607ca46eSDavid Howells #define PTP_FALLING_EDGE (1<<2) 31607ca46eSDavid Howells 32607ca46eSDavid Howells /* 33607ca46eSDavid Howells * struct ptp_clock_time - represents a time value 34607ca46eSDavid Howells * 35607ca46eSDavid Howells * The sign of the seconds field applies to the whole value. The 36607ca46eSDavid Howells * nanoseconds field is always unsigned. The reserved field is 37607ca46eSDavid Howells * included for sub-nanosecond resolution, should the demand for 38607ca46eSDavid Howells * this ever appear. 39607ca46eSDavid Howells * 40607ca46eSDavid Howells */ 41607ca46eSDavid Howells struct ptp_clock_time { 42607ca46eSDavid Howells __s64 sec; /* seconds */ 43607ca46eSDavid Howells __u32 nsec; /* nanoseconds */ 44607ca46eSDavid Howells __u32 reserved; 45607ca46eSDavid Howells }; 46607ca46eSDavid Howells 47607ca46eSDavid Howells struct ptp_clock_caps { 48607ca46eSDavid Howells int max_adj; /* Maximum frequency adjustment in parts per billon. */ 49607ca46eSDavid Howells int n_alarm; /* Number of programmable alarms. */ 50607ca46eSDavid Howells int n_ext_ts; /* Number of external time stamp channels. */ 51607ca46eSDavid Howells int n_per_out; /* Number of programmable periodic signals. */ 52607ca46eSDavid Howells int pps; /* Whether the clock supports a PPS callback. */ 53607ca46eSDavid Howells int rsv[15]; /* Reserved for future use. */ 54607ca46eSDavid Howells }; 55607ca46eSDavid Howells 56607ca46eSDavid Howells struct ptp_extts_request { 57607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 58607ca46eSDavid Howells unsigned int flags; /* Bit field for PTP_xxx flags. */ 59607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 60607ca46eSDavid Howells }; 61607ca46eSDavid Howells 62607ca46eSDavid Howells struct ptp_perout_request { 63607ca46eSDavid Howells struct ptp_clock_time start; /* Absolute start time. */ 64607ca46eSDavid Howells struct ptp_clock_time period; /* Desired period, zero means disable. */ 65607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 66607ca46eSDavid Howells unsigned int flags; /* Reserved for future use. */ 67607ca46eSDavid Howells unsigned int rsv[4]; /* Reserved for future use. */ 68607ca46eSDavid Howells }; 69607ca46eSDavid Howells 70*215b13ddSRichard Cochran #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ 71*215b13ddSRichard Cochran 72*215b13ddSRichard Cochran struct ptp_sys_offset { 73*215b13ddSRichard Cochran unsigned int n_samples; /* Desired number of measurements. */ 74*215b13ddSRichard Cochran unsigned int rsv[3]; /* Reserved for future use. */ 75*215b13ddSRichard Cochran /* 76*215b13ddSRichard Cochran * Array of interleaved system/phc time stamps. The kernel 77*215b13ddSRichard Cochran * will provide 2*n_samples + 1 time stamps, with the last 78*215b13ddSRichard Cochran * one as a system time stamp. 79*215b13ddSRichard Cochran */ 80*215b13ddSRichard Cochran struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 81*215b13ddSRichard Cochran }; 82*215b13ddSRichard Cochran 83607ca46eSDavid Howells #define PTP_CLK_MAGIC '=' 84607ca46eSDavid Howells 85607ca46eSDavid Howells #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) 86607ca46eSDavid Howells #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) 87607ca46eSDavid Howells #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) 88607ca46eSDavid Howells #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) 89*215b13ddSRichard Cochran #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 90607ca46eSDavid Howells 91607ca46eSDavid Howells struct ptp_extts_event { 92607ca46eSDavid Howells struct ptp_clock_time t; /* Time event occured. */ 93607ca46eSDavid Howells unsigned int index; /* Which channel produced the event. */ 94607ca46eSDavid Howells unsigned int flags; /* Reserved for future use. */ 95607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 96607ca46eSDavid Howells }; 97607ca46eSDavid Howells 98607ca46eSDavid Howells #endif 99