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*6138e687SRichard 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 | \ 42*6138e687SRichard Cochran PTP_FALLING_EDGE | \ 43*6138e687SRichard 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) 572df4de16SJacob Keller 582df4de16SJacob Keller /* 592df4de16SJacob Keller * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl. 602df4de16SJacob Keller */ 61823eb2a3SFelipe Balbi #define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT) 622df4de16SJacob Keller 632df4de16SJacob Keller /* 642df4de16SJacob Keller * No flags are valid for the original PTP_PEROUT_REQUEST ioctl 652df4de16SJacob Keller */ 662df4de16SJacob Keller #define PTP_PEROUT_V1_VALID_FLAGS (0) 672df4de16SJacob Keller 68607ca46eSDavid Howells /* 69607ca46eSDavid Howells * struct ptp_clock_time - represents a time value 70607ca46eSDavid Howells * 71607ca46eSDavid Howells * The sign of the seconds field applies to the whole value. The 72607ca46eSDavid Howells * nanoseconds field is always unsigned. The reserved field is 73607ca46eSDavid Howells * included for sub-nanosecond resolution, should the demand for 74607ca46eSDavid Howells * this ever appear. 75607ca46eSDavid Howells * 76607ca46eSDavid Howells */ 77607ca46eSDavid Howells struct ptp_clock_time { 78607ca46eSDavid Howells __s64 sec; /* seconds */ 79607ca46eSDavid Howells __u32 nsec; /* nanoseconds */ 80607ca46eSDavid Howells __u32 reserved; 81607ca46eSDavid Howells }; 82607ca46eSDavid Howells 83607ca46eSDavid Howells struct ptp_clock_caps { 84607ca46eSDavid Howells int max_adj; /* Maximum frequency adjustment in parts per billon. */ 85607ca46eSDavid Howells int n_alarm; /* Number of programmable alarms. */ 86607ca46eSDavid Howells int n_ext_ts; /* Number of external time stamp channels. */ 87607ca46eSDavid Howells int n_per_out; /* Number of programmable periodic signals. */ 88607ca46eSDavid Howells int pps; /* Whether the clock supports a PPS callback. */ 896092315dSRichard Cochran int n_pins; /* Number of input/output pins. */ 90719f1aa4SChristopher S. Hall /* Whether the clock supports precise system-device cross timestamps */ 91719f1aa4SChristopher S. Hall int cross_timestamping; 92719f1aa4SChristopher S. Hall int rsv[13]; /* Reserved for future use. */ 93607ca46eSDavid Howells }; 94607ca46eSDavid Howells 95607ca46eSDavid Howells struct ptp_extts_request { 96607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 97607ca46eSDavid Howells unsigned int flags; /* Bit field for PTP_xxx flags. */ 98607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 99607ca46eSDavid Howells }; 100607ca46eSDavid Howells 101607ca46eSDavid Howells struct ptp_perout_request { 102607ca46eSDavid Howells struct ptp_clock_time start; /* Absolute start time. */ 103607ca46eSDavid Howells struct ptp_clock_time period; /* Desired period, zero means disable. */ 104607ca46eSDavid Howells unsigned int index; /* Which channel to configure. */ 105823eb2a3SFelipe Balbi unsigned int flags; 106607ca46eSDavid Howells unsigned int rsv[4]; /* Reserved for future use. */ 107607ca46eSDavid Howells }; 108607ca46eSDavid Howells 109215b13ddSRichard Cochran #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ 110215b13ddSRichard Cochran 111215b13ddSRichard Cochran struct ptp_sys_offset { 112215b13ddSRichard Cochran unsigned int n_samples; /* Desired number of measurements. */ 113215b13ddSRichard Cochran unsigned int rsv[3]; /* Reserved for future use. */ 114215b13ddSRichard Cochran /* 115215b13ddSRichard Cochran * Array of interleaved system/phc time stamps. The kernel 116215b13ddSRichard Cochran * will provide 2*n_samples + 1 time stamps, with the last 117215b13ddSRichard Cochran * one as a system time stamp. 118215b13ddSRichard Cochran */ 119215b13ddSRichard Cochran struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 120215b13ddSRichard Cochran }; 121215b13ddSRichard Cochran 12236180087SMiroslav Lichvar struct ptp_sys_offset_extended { 12336180087SMiroslav Lichvar unsigned int n_samples; /* Desired number of measurements. */ 12436180087SMiroslav Lichvar unsigned int rsv[3]; /* Reserved for future use. */ 12536180087SMiroslav Lichvar /* 12636180087SMiroslav Lichvar * Array of [system, phc, system] time stamps. The kernel will provide 12736180087SMiroslav Lichvar * 3*n_samples time stamps. 12836180087SMiroslav Lichvar */ 12936180087SMiroslav Lichvar struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; 13036180087SMiroslav Lichvar }; 13136180087SMiroslav Lichvar 132719f1aa4SChristopher S. Hall struct ptp_sys_offset_precise { 133719f1aa4SChristopher S. Hall struct ptp_clock_time device; 134719f1aa4SChristopher S. Hall struct ptp_clock_time sys_realtime; 135719f1aa4SChristopher S. Hall struct ptp_clock_time sys_monoraw; 136719f1aa4SChristopher S. Hall unsigned int rsv[4]; /* Reserved for future use. */ 137719f1aa4SChristopher S. Hall }; 138719f1aa4SChristopher S. Hall 1396092315dSRichard Cochran enum ptp_pin_function { 1406092315dSRichard Cochran PTP_PF_NONE, 1416092315dSRichard Cochran PTP_PF_EXTTS, 1426092315dSRichard Cochran PTP_PF_PEROUT, 1436092315dSRichard Cochran PTP_PF_PHYSYNC, 1446092315dSRichard Cochran }; 1456092315dSRichard Cochran 1466092315dSRichard Cochran struct ptp_pin_desc { 1476092315dSRichard Cochran /* 1486092315dSRichard Cochran * Hardware specific human readable pin name. This field is 1496092315dSRichard Cochran * set by the kernel during the PTP_PIN_GETFUNC ioctl and is 1506092315dSRichard Cochran * ignored for the PTP_PIN_SETFUNC ioctl. 1516092315dSRichard Cochran */ 1526092315dSRichard Cochran char name[64]; 1536092315dSRichard Cochran /* 1546092315dSRichard Cochran * Pin index in the range of zero to ptp_clock_caps.n_pins - 1. 1556092315dSRichard Cochran */ 1566092315dSRichard Cochran unsigned int index; 1576092315dSRichard Cochran /* 1586092315dSRichard Cochran * Which of the PTP_PF_xxx functions to use on this pin. 1596092315dSRichard Cochran */ 1606092315dSRichard Cochran unsigned int func; 1616092315dSRichard Cochran /* 1626092315dSRichard Cochran * The specific channel to use for this function. 1636092315dSRichard Cochran * This corresponds to the 'index' field of the 1646092315dSRichard Cochran * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls. 1656092315dSRichard Cochran */ 1666092315dSRichard Cochran unsigned int chan; 1676092315dSRichard Cochran /* 1686092315dSRichard Cochran * Reserved for future use. 1696092315dSRichard Cochran */ 1706092315dSRichard Cochran unsigned int rsv[5]; 1716092315dSRichard Cochran }; 1726092315dSRichard Cochran 173607ca46eSDavid Howells #define PTP_CLK_MAGIC '=' 174607ca46eSDavid Howells 175607ca46eSDavid Howells #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) 176607ca46eSDavid Howells #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) 177607ca46eSDavid Howells #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) 178607ca46eSDavid Howells #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) 179215b13ddSRichard Cochran #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 1806092315dSRichard Cochran #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) 1816092315dSRichard Cochran #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) 182719f1aa4SChristopher S. Hall #define PTP_SYS_OFFSET_PRECISE \ 183719f1aa4SChristopher S. Hall _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise) 18436180087SMiroslav Lichvar #define PTP_SYS_OFFSET_EXTENDED \ 185b7ea4894SEugene Syromiatnikov _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended) 186607ca46eSDavid Howells 18741560658SFelipe Balbi #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps) 18841560658SFelipe Balbi #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request) 18941560658SFelipe Balbi #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request) 19041560658SFelipe Balbi #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int) 19141560658SFelipe Balbi #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset) 19241560658SFelipe Balbi #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc) 19341560658SFelipe Balbi #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc) 19441560658SFelipe Balbi #define PTP_SYS_OFFSET_PRECISE2 \ 19541560658SFelipe Balbi _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise) 19641560658SFelipe Balbi #define PTP_SYS_OFFSET_EXTENDED2 \ 19741560658SFelipe Balbi _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) 19841560658SFelipe Balbi 199607ca46eSDavid Howells struct ptp_extts_event { 200607ca46eSDavid Howells struct ptp_clock_time t; /* Time event occured. */ 201607ca46eSDavid Howells unsigned int index; /* Which channel produced the event. */ 202607ca46eSDavid Howells unsigned int flags; /* Reserved for future use. */ 203607ca46eSDavid Howells unsigned int rsv[2]; /* Reserved for future use. */ 204607ca46eSDavid Howells }; 205607ca46eSDavid Howells 206607ca46eSDavid Howells #endif 207