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) 34*cd734d54SRichard Cochran #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE) 352df4de16SJacob Keller 362df4de16SJacob Keller /* 372df4de16SJacob Keller * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl. 382df4de16SJacob Keller */ 3941560658SFelipe Balbi #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \ 4041560658SFelipe Balbi PTP_RISING_EDGE | \ 4141560658SFelipe Balbi PTP_FALLING_EDGE) 4241560658SFelipe Balbi 4341560658SFelipe Balbi /* 442df4de16SJacob Keller * flag fields valid for the original PTP_EXTTS_REQUEST ioctl. 452df4de16SJacob Keller * DO NOT ADD NEW FLAGS HERE. 462df4de16SJacob Keller */ 472df4de16SJacob Keller #define PTP_EXTTS_V1_VALID_FLAGS (PTP_ENABLE_FEATURE | \ 482df4de16SJacob Keller PTP_RISING_EDGE | \ 492df4de16SJacob Keller PTP_FALLING_EDGE) 502df4de16SJacob Keller 512df4de16SJacob Keller /* 5241560658SFelipe Balbi * Bits of the ptp_perout_request.flags field: 5341560658SFelipe Balbi */ 54823eb2a3SFelipe Balbi #define PTP_PEROUT_ONE_SHOT (1<<0) 552df4de16SJacob Keller 562df4de16SJacob Keller /* 572df4de16SJacob Keller * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl. 582df4de16SJacob Keller */ 59823eb2a3SFelipe Balbi #define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT) 602df4de16SJacob Keller 612df4de16SJacob Keller /* 622df4de16SJacob Keller * No flags are valid for the original PTP_PEROUT_REQUEST ioctl 632df4de16SJacob Keller */ 642df4de16SJacob Keller #define PTP_PEROUT_V1_VALID_FLAGS (0) 652df4de16SJacob Keller 66607ca46eSDavid Howells /* 67607ca46eSDavid Howells * struct ptp_clock_time - represents a time value 68607ca46eSDavid Howells * 69607ca46eSDavid Howells * The sign of the seconds field applies to the whole value. The 70607ca46eSDavid Howells * nanoseconds field is always unsigned. The reserved field is 71607ca46eSDavid Howells * included for sub-nanosecond resolution, should the demand for 72607ca46eSDavid Howells * this ever appear. 73607ca46eSDavid Howells * 74607ca46eSDavid Howells */ 75607ca46eSDavid Howells struct ptp_clock_time { 76607ca46eSDavid Howells __s64 sec; /* seconds */ 77607ca46eSDavid Howells __u32 nsec; /* nanoseconds */ 78607ca46eSDavid Howells __u32 reserved; 79607ca46eSDavid Howells }; 80607ca46eSDavid Howells 81607ca46eSDavid Howells struct ptp_clock_caps { 82607ca46eSDavid Howells int max_adj; /* Maximum frequency adjustment in parts per billon. */ 83607ca46eSDavid Howells int n_alarm; /* Number of programmable alarms. */ 84607ca46eSDavid Howells int n_ext_ts; /* Number of external time stamp channels. */ 85607ca46eSDavid Howells int n_per_out; /* Number of programmable periodic signals. */ 86607ca46eSDavid Howells int pps; /* Whether the clock supports a PPS callback. */ 876092315dSRichard Cochran int n_pins; /* Number of input/output pins. */ 88719f1aa4SChristopher S. Hall /* Whether the clock supports precise system-device cross timestamps */ 89719f1aa4SChristopher S. Hall int cross_timestamping; 90719f1aa4SChristopher S. Hall int rsv[13]; /* Reserved for future use. */ 91607ca46eSDavid Howells }; 92607ca46eSDavid Howells 93607ca46eSDavid Howells struct ptp_extts_request { 94607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 95607ca46eSDavid Howells unsigned int flags; /* Bit field for PTP_xxx flags. */ 96607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 97607ca46eSDavid Howells }; 98607ca46eSDavid Howells 99607ca46eSDavid Howells struct ptp_perout_request { 100607ca46eSDavid Howells struct ptp_clock_time start; /* Absolute start time. */ 101607ca46eSDavid Howells struct ptp_clock_time period; /* Desired period, zero means disable. */ 102607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 103823eb2a3SFelipe Balbi unsigned int flags; 104607ca46eSDavid Howells unsigned int rsv[4]; /* Reserved for future use. */ 105607ca46eSDavid Howells }; 106607ca46eSDavid Howells 107215b13ddSRichard Cochran #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ 108215b13ddSRichard Cochran 109215b13ddSRichard Cochran struct ptp_sys_offset { 110215b13ddSRichard Cochran unsigned int n_samples; /* Desired number of measurements. */ 111215b13ddSRichard Cochran unsigned int rsv[3]; /* Reserved for future use. */ 112215b13ddSRichard Cochran /* 113215b13ddSRichard Cochran * Array of interleaved system/phc time stamps. The kernel 114215b13ddSRichard Cochran * will provide 2*n_samples + 1 time stamps, with the last 115215b13ddSRichard Cochran * one as a system time stamp. 116215b13ddSRichard Cochran */ 117215b13ddSRichard Cochran struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 118215b13ddSRichard Cochran }; 119215b13ddSRichard Cochran 12036180087SMiroslav Lichvar struct ptp_sys_offset_extended { 12136180087SMiroslav Lichvar unsigned int n_samples; /* Desired number of measurements. */ 12236180087SMiroslav Lichvar unsigned int rsv[3]; /* Reserved for future use. */ 12336180087SMiroslav Lichvar /* 12436180087SMiroslav Lichvar * Array of [system, phc, system] time stamps. The kernel will provide 12536180087SMiroslav Lichvar * 3*n_samples time stamps. 12636180087SMiroslav Lichvar */ 12736180087SMiroslav Lichvar struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; 12836180087SMiroslav Lichvar }; 12936180087SMiroslav Lichvar 130719f1aa4SChristopher S. Hall struct ptp_sys_offset_precise { 131719f1aa4SChristopher S. Hall struct ptp_clock_time device; 132719f1aa4SChristopher S. Hall struct ptp_clock_time sys_realtime; 133719f1aa4SChristopher S. Hall struct ptp_clock_time sys_monoraw; 134719f1aa4SChristopher S. Hall unsigned int rsv[4]; /* Reserved for future use. */ 135719f1aa4SChristopher S. Hall }; 136719f1aa4SChristopher S. Hall 1376092315dSRichard Cochran enum ptp_pin_function { 1386092315dSRichard Cochran PTP_PF_NONE, 1396092315dSRichard Cochran PTP_PF_EXTTS, 1406092315dSRichard Cochran PTP_PF_PEROUT, 1416092315dSRichard Cochran PTP_PF_PHYSYNC, 1426092315dSRichard Cochran }; 1436092315dSRichard Cochran 1446092315dSRichard Cochran struct ptp_pin_desc { 1456092315dSRichard Cochran /* 1466092315dSRichard Cochran * Hardware specific human readable pin name. This field is 1476092315dSRichard Cochran * set by the kernel during the PTP_PIN_GETFUNC ioctl and is 1486092315dSRichard Cochran * ignored for the PTP_PIN_SETFUNC ioctl. 1496092315dSRichard Cochran */ 1506092315dSRichard Cochran char name[64]; 1516092315dSRichard Cochran /* 1526092315dSRichard Cochran * Pin index in the range of zero to ptp_clock_caps.n_pins - 1. 1536092315dSRichard Cochran */ 1546092315dSRichard Cochran unsigned int index; 1556092315dSRichard Cochran /* 1566092315dSRichard Cochran * Which of the PTP_PF_xxx functions to use on this pin. 1576092315dSRichard Cochran */ 1586092315dSRichard Cochran unsigned int func; 1596092315dSRichard Cochran /* 1606092315dSRichard Cochran * The specific channel to use for this function. 1616092315dSRichard Cochran * This corresponds to the 'index' field of the 1626092315dSRichard Cochran * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls. 1636092315dSRichard Cochran */ 1646092315dSRichard Cochran unsigned int chan; 1656092315dSRichard Cochran /* 1666092315dSRichard Cochran * Reserved for future use. 1676092315dSRichard Cochran */ 1686092315dSRichard Cochran unsigned int rsv[5]; 1696092315dSRichard Cochran }; 1706092315dSRichard Cochran 171607ca46eSDavid Howells #define PTP_CLK_MAGIC '=' 172607ca46eSDavid Howells 173607ca46eSDavid Howells #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) 174607ca46eSDavid Howells #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) 175607ca46eSDavid Howells #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) 176607ca46eSDavid Howells #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) 177215b13ddSRichard Cochran #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 1786092315dSRichard Cochran #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) 1796092315dSRichard Cochran #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) 180719f1aa4SChristopher S. Hall #define PTP_SYS_OFFSET_PRECISE \ 181719f1aa4SChristopher S. Hall _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise) 18236180087SMiroslav Lichvar #define PTP_SYS_OFFSET_EXTENDED \ 183b7ea4894SEugene Syromiatnikov _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended) 184607ca46eSDavid Howells 18541560658SFelipe Balbi #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps) 18641560658SFelipe Balbi #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request) 18741560658SFelipe Balbi #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request) 18841560658SFelipe Balbi #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int) 18941560658SFelipe Balbi #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset) 19041560658SFelipe Balbi #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc) 19141560658SFelipe Balbi #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc) 19241560658SFelipe Balbi #define PTP_SYS_OFFSET_PRECISE2 \ 19341560658SFelipe Balbi _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise) 19441560658SFelipe Balbi #define PTP_SYS_OFFSET_EXTENDED2 \ 19541560658SFelipe Balbi _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) 19641560658SFelipe Balbi 197607ca46eSDavid Howells struct ptp_extts_event { 198607ca46eSDavid Howells struct ptp_clock_time t; /* Time event occured. */ 199607ca46eSDavid Howells unsigned int index; /* Which channel produced the event. */ 200607ca46eSDavid Howells unsigned int flags; /* Reserved for future use. */ 201607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 202607ca46eSDavid Howells }; 203607ca46eSDavid Howells 204607ca46eSDavid Howells #endif 205