1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* 3607ca46eSDavid Howells * PTP 1588 clock support - user space interface 4607ca46eSDavid Howells * 5607ca46eSDavid Howells * Copyright (C) 2010 OMICRON electronics GmbH 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 #ifndef _PTP_CLOCK_H_ 23607ca46eSDavid Howells #define _PTP_CLOCK_H_ 24607ca46eSDavid Howells 25607ca46eSDavid Howells #include <linux/ioctl.h> 26607ca46eSDavid Howells #include <linux/types.h> 27607ca46eSDavid Howells 2841560658SFelipe Balbi /* 2941560658SFelipe Balbi * Bits of the ptp_extts_request.flags field: 3041560658SFelipe Balbi */ 31607ca46eSDavid Howells #define PTP_ENABLE_FEATURE (1<<0) 32607ca46eSDavid Howells #define PTP_RISING_EDGE (1<<1) 33607ca46eSDavid Howells #define PTP_FALLING_EDGE (1<<2) 346138e687SRichard Cochran #define PTP_STRICT_FLAGS (1<<3) 35cd734d54SRichard Cochran #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE) 362df4de16SJacob Keller 372df4de16SJacob Keller /* 382df4de16SJacob Keller * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl. 392df4de16SJacob Keller */ 4041560658SFelipe Balbi #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \ 4141560658SFelipe Balbi PTP_RISING_EDGE | \ 426138e687SRichard Cochran PTP_FALLING_EDGE | \ 436138e687SRichard Cochran PTP_STRICT_FLAGS) 4441560658SFelipe Balbi 4541560658SFelipe Balbi /* 462df4de16SJacob Keller * flag fields valid for the original PTP_EXTTS_REQUEST ioctl. 472df4de16SJacob Keller * DO NOT ADD NEW FLAGS HERE. 482df4de16SJacob Keller */ 492df4de16SJacob Keller #define PTP_EXTTS_V1_VALID_FLAGS (PTP_ENABLE_FEATURE | \ 502df4de16SJacob Keller PTP_RISING_EDGE | \ 512df4de16SJacob Keller PTP_FALLING_EDGE) 522df4de16SJacob Keller 532df4de16SJacob Keller /* 5441560658SFelipe Balbi * Bits of the ptp_perout_request.flags field: 5541560658SFelipe Balbi */ 56823eb2a3SFelipe Balbi #define PTP_PEROUT_ONE_SHOT (1<<0) 57f65b71aaSVladimir Oltean #define PTP_PEROUT_DUTY_CYCLE (1<<1) 58b6bd4136SVladimir Oltean #define PTP_PEROUT_PHASE (1<<2) 592df4de16SJacob Keller 602df4de16SJacob Keller /* 612df4de16SJacob Keller * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl. 622df4de16SJacob Keller */ 63f65b71aaSVladimir Oltean #define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT | \ 64b6bd4136SVladimir Oltean PTP_PEROUT_DUTY_CYCLE | \ 65b6bd4136SVladimir Oltean PTP_PEROUT_PHASE) 662df4de16SJacob Keller 672df4de16SJacob Keller /* 682df4de16SJacob Keller * No flags are valid for the original PTP_PEROUT_REQUEST ioctl 692df4de16SJacob Keller */ 702df4de16SJacob Keller #define PTP_PEROUT_V1_VALID_FLAGS (0) 712df4de16SJacob Keller 72607ca46eSDavid Howells /* 73607ca46eSDavid Howells * struct ptp_clock_time - represents a time value 74607ca46eSDavid Howells * 75607ca46eSDavid Howells * The sign of the seconds field applies to the whole value. The 76607ca46eSDavid Howells * nanoseconds field is always unsigned. The reserved field is 77607ca46eSDavid Howells * included for sub-nanosecond resolution, should the demand for 78607ca46eSDavid Howells * this ever appear. 79607ca46eSDavid Howells * 80607ca46eSDavid Howells */ 81607ca46eSDavid Howells struct ptp_clock_time { 82607ca46eSDavid Howells __s64 sec; /* seconds */ 83607ca46eSDavid Howells __u32 nsec; /* nanoseconds */ 84607ca46eSDavid Howells __u32 reserved; 85607ca46eSDavid Howells }; 86607ca46eSDavid Howells 87607ca46eSDavid Howells struct ptp_clock_caps { 88607ca46eSDavid Howells int max_adj; /* Maximum frequency adjustment in parts per billon. */ 89607ca46eSDavid Howells int n_alarm; /* Number of programmable alarms. */ 90607ca46eSDavid Howells int n_ext_ts; /* Number of external time stamp channels. */ 91607ca46eSDavid Howells int n_per_out; /* Number of programmable periodic signals. */ 92607ca46eSDavid Howells int pps; /* Whether the clock supports a PPS callback. */ 936092315dSRichard Cochran int n_pins; /* Number of input/output pins. */ 94719f1aa4SChristopher S. Hall /* Whether the clock supports precise system-device cross timestamps */ 95719f1aa4SChristopher S. Hall int cross_timestamping; 96d3f1cbd2SVincent Cheng /* Whether the clock supports adjust phase */ 97d3f1cbd2SVincent Cheng int adjust_phase; 98*c3b60ab7SRahul Rameshbabu int max_phase_adj; /* Maximum phase adjustment in nanoseconds. */ 99*c3b60ab7SRahul Rameshbabu int rsv[11]; /* Reserved for future use. */ 100607ca46eSDavid Howells }; 101607ca46eSDavid Howells 102607ca46eSDavid Howells struct ptp_extts_request { 103607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 104607ca46eSDavid Howells unsigned int flags; /* Bit field for PTP_xxx flags. */ 105607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 106607ca46eSDavid Howells }; 107607ca46eSDavid Howells 108607ca46eSDavid Howells struct ptp_perout_request { 109b6bd4136SVladimir Oltean union { 110b6bd4136SVladimir Oltean /* 111b6bd4136SVladimir Oltean * Absolute start time. 112b6bd4136SVladimir Oltean * Valid only if (flags & PTP_PEROUT_PHASE) is unset. 113b6bd4136SVladimir Oltean */ 114b6bd4136SVladimir Oltean struct ptp_clock_time start; 115b6bd4136SVladimir Oltean /* 116b6bd4136SVladimir Oltean * Phase offset. The signal should start toggling at an 117b6bd4136SVladimir Oltean * unspecified integer multiple of the period, plus this value. 118b6bd4136SVladimir Oltean * The start time should be "as soon as possible". 119b6bd4136SVladimir Oltean * Valid only if (flags & PTP_PEROUT_PHASE) is set. 120b6bd4136SVladimir Oltean */ 121b6bd4136SVladimir Oltean struct ptp_clock_time phase; 122b6bd4136SVladimir Oltean }; 123607ca46eSDavid Howells struct ptp_clock_time period; /* Desired period, zero means disable. */ 124607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 125823eb2a3SFelipe Balbi unsigned int flags; 126f65b71aaSVladimir Oltean union { 127f65b71aaSVladimir Oltean /* 128f65b71aaSVladimir Oltean * The "on" time of the signal. 129f65b71aaSVladimir Oltean * Must be lower than the period. 130f65b71aaSVladimir Oltean * Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set. 131f65b71aaSVladimir Oltean */ 132f65b71aaSVladimir Oltean struct ptp_clock_time on; 133f65b71aaSVladimir Oltean /* Reserved for future use. */ 134f65b71aaSVladimir Oltean unsigned int rsv[4]; 135f65b71aaSVladimir Oltean }; 136607ca46eSDavid Howells }; 137607ca46eSDavid Howells 138215b13ddSRichard Cochran #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ 139215b13ddSRichard Cochran 140215b13ddSRichard Cochran struct ptp_sys_offset { 141215b13ddSRichard Cochran unsigned int n_samples; /* Desired number of measurements. */ 142215b13ddSRichard Cochran unsigned int rsv[3]; /* Reserved for future use. */ 143215b13ddSRichard Cochran /* 144215b13ddSRichard Cochran * Array of interleaved system/phc time stamps. The kernel 145215b13ddSRichard Cochran * will provide 2*n_samples + 1 time stamps, with the last 146215b13ddSRichard Cochran * one as a system time stamp. 147215b13ddSRichard Cochran */ 148215b13ddSRichard Cochran struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 149215b13ddSRichard Cochran }; 150215b13ddSRichard Cochran 15136180087SMiroslav Lichvar struct ptp_sys_offset_extended { 15236180087SMiroslav Lichvar unsigned int n_samples; /* Desired number of measurements. */ 15336180087SMiroslav Lichvar unsigned int rsv[3]; /* Reserved for future use. */ 15436180087SMiroslav Lichvar /* 15536180087SMiroslav Lichvar * Array of [system, phc, system] time stamps. The kernel will provide 15636180087SMiroslav Lichvar * 3*n_samples time stamps. 15736180087SMiroslav Lichvar */ 15836180087SMiroslav Lichvar struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; 15936180087SMiroslav Lichvar }; 16036180087SMiroslav Lichvar 161719f1aa4SChristopher S. Hall struct ptp_sys_offset_precise { 162719f1aa4SChristopher S. Hall struct ptp_clock_time device; 163719f1aa4SChristopher S. Hall struct ptp_clock_time sys_realtime; 164719f1aa4SChristopher S. Hall struct ptp_clock_time sys_monoraw; 165719f1aa4SChristopher S. Hall unsigned int rsv[4]; /* Reserved for future use. */ 166719f1aa4SChristopher S. Hall }; 167719f1aa4SChristopher S. Hall 1686092315dSRichard Cochran enum ptp_pin_function { 1696092315dSRichard Cochran PTP_PF_NONE, 1706092315dSRichard Cochran PTP_PF_EXTTS, 1716092315dSRichard Cochran PTP_PF_PEROUT, 1726092315dSRichard Cochran PTP_PF_PHYSYNC, 1736092315dSRichard Cochran }; 1746092315dSRichard Cochran 1756092315dSRichard Cochran struct ptp_pin_desc { 1766092315dSRichard Cochran /* 1776092315dSRichard Cochran * Hardware specific human readable pin name. This field is 1786092315dSRichard Cochran * set by the kernel during the PTP_PIN_GETFUNC ioctl and is 1796092315dSRichard Cochran * ignored for the PTP_PIN_SETFUNC ioctl. 1806092315dSRichard Cochran */ 1816092315dSRichard Cochran char name[64]; 1826092315dSRichard Cochran /* 1836092315dSRichard Cochran * Pin index in the range of zero to ptp_clock_caps.n_pins - 1. 1846092315dSRichard Cochran */ 1856092315dSRichard Cochran unsigned int index; 1866092315dSRichard Cochran /* 1876092315dSRichard Cochran * Which of the PTP_PF_xxx functions to use on this pin. 1886092315dSRichard Cochran */ 1896092315dSRichard Cochran unsigned int func; 1906092315dSRichard Cochran /* 1916092315dSRichard Cochran * The specific channel to use for this function. 1926092315dSRichard Cochran * This corresponds to the 'index' field of the 1936092315dSRichard Cochran * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls. 1946092315dSRichard Cochran */ 1956092315dSRichard Cochran unsigned int chan; 1966092315dSRichard Cochran /* 1976092315dSRichard Cochran * Reserved for future use. 1986092315dSRichard Cochran */ 1996092315dSRichard Cochran unsigned int rsv[5]; 2006092315dSRichard Cochran }; 2016092315dSRichard Cochran 202607ca46eSDavid Howells #define PTP_CLK_MAGIC '=' 203607ca46eSDavid Howells 204607ca46eSDavid Howells #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) 205607ca46eSDavid Howells #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) 206607ca46eSDavid Howells #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) 207607ca46eSDavid Howells #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) 208215b13ddSRichard Cochran #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 2096092315dSRichard Cochran #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) 2106092315dSRichard Cochran #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) 211719f1aa4SChristopher S. Hall #define PTP_SYS_OFFSET_PRECISE \ 212719f1aa4SChristopher S. Hall _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise) 21336180087SMiroslav Lichvar #define PTP_SYS_OFFSET_EXTENDED \ 214b7ea4894SEugene Syromiatnikov _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended) 215607ca46eSDavid Howells 21641560658SFelipe Balbi #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps) 21741560658SFelipe Balbi #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request) 21841560658SFelipe Balbi #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request) 21941560658SFelipe Balbi #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int) 22041560658SFelipe Balbi #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset) 22141560658SFelipe Balbi #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc) 22241560658SFelipe Balbi #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc) 22341560658SFelipe Balbi #define PTP_SYS_OFFSET_PRECISE2 \ 22441560658SFelipe Balbi _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise) 22541560658SFelipe Balbi #define PTP_SYS_OFFSET_EXTENDED2 \ 22641560658SFelipe Balbi _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) 22741560658SFelipe Balbi 228607ca46eSDavid Howells struct ptp_extts_event { 229607ca46eSDavid Howells struct ptp_clock_time t; /* Time event occured. */ 230607ca46eSDavid Howells unsigned int index; /* Which channel produced the event. */ 231607ca46eSDavid Howells unsigned int flags; /* Reserved for future use. */ 232607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 233607ca46eSDavid Howells }; 234607ca46eSDavid Howells 235607ca46eSDavid Howells #endif 236