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