Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 /*
0003  * PTP 1588 clock support - user space interface
0004  *
0005  * Copyright (C) 2010 OMICRON electronics GmbH
0006  *
0007  *  This program is free software; you can redistribute it and/or modify
0008  *  it under the terms of the GNU General Public License as published by
0009  *  the Free Software Foundation; either version 2 of the License, or
0010  *  (at your option) any later version.
0011  *
0012  *  This program is distributed in the hope that it will be useful,
0013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  *  GNU General Public License for more details.
0016  *
0017  *  You should have received a copy of the GNU General Public License
0018  *  along with this program; if not, write to the Free Software
0019  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0020  */
0021 
0022 #ifndef _PTP_CLOCK_H_
0023 #define _PTP_CLOCK_H_
0024 
0025 #include <linux/ioctl.h>
0026 #include <linux/types.h>
0027 
0028 /*
0029  * Bits of the ptp_extts_request.flags field:
0030  */
0031 #define PTP_ENABLE_FEATURE (1<<0)
0032 #define PTP_RISING_EDGE    (1<<1)
0033 #define PTP_FALLING_EDGE   (1<<2)
0034 #define PTP_STRICT_FLAGS   (1<<3)
0035 #define PTP_EXTTS_EDGES    (PTP_RISING_EDGE | PTP_FALLING_EDGE)
0036 
0037 /*
0038  * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
0039  */
0040 #define PTP_EXTTS_VALID_FLAGS   (PTP_ENABLE_FEATURE |   \
0041                  PTP_RISING_EDGE |  \
0042                  PTP_FALLING_EDGE | \
0043                  PTP_STRICT_FLAGS)
0044 
0045 /*
0046  * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
0047  * DO NOT ADD NEW FLAGS HERE.
0048  */
0049 #define PTP_EXTTS_V1_VALID_FLAGS    (PTP_ENABLE_FEATURE |   \
0050                      PTP_RISING_EDGE |  \
0051                      PTP_FALLING_EDGE)
0052 
0053 /*
0054  * Bits of the ptp_perout_request.flags field:
0055  */
0056 #define PTP_PEROUT_ONE_SHOT     (1<<0)
0057 #define PTP_PEROUT_DUTY_CYCLE       (1<<1)
0058 #define PTP_PEROUT_PHASE        (1<<2)
0059 
0060 /*
0061  * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl.
0062  */
0063 #define PTP_PEROUT_VALID_FLAGS      (PTP_PEROUT_ONE_SHOT | \
0064                      PTP_PEROUT_DUTY_CYCLE | \
0065                      PTP_PEROUT_PHASE)
0066 
0067 /*
0068  * No flags are valid for the original PTP_PEROUT_REQUEST ioctl
0069  */
0070 #define PTP_PEROUT_V1_VALID_FLAGS   (0)
0071 
0072 /*
0073  * struct ptp_clock_time - represents a time value
0074  *
0075  * The sign of the seconds field applies to the whole value. The
0076  * nanoseconds field is always unsigned. The reserved field is
0077  * included for sub-nanosecond resolution, should the demand for
0078  * this ever appear.
0079  *
0080  */
0081 struct ptp_clock_time {
0082     __s64 sec;  /* seconds */
0083     __u32 nsec; /* nanoseconds */
0084     __u32 reserved;
0085 };
0086 
0087 struct ptp_clock_caps {
0088     int max_adj;   /* Maximum frequency adjustment in parts per billon. */
0089     int n_alarm;   /* Number of programmable alarms. */
0090     int n_ext_ts;  /* Number of external time stamp channels. */
0091     int n_per_out; /* Number of programmable periodic signals. */
0092     int pps;       /* Whether the clock supports a PPS callback. */
0093     int n_pins;    /* Number of input/output pins. */
0094     /* Whether the clock supports precise system-device cross timestamps */
0095     int cross_timestamping;
0096     /* Whether the clock supports adjust phase */
0097     int adjust_phase;
0098     int rsv[12];   /* Reserved for future use. */
0099 };
0100 
0101 struct ptp_extts_request {
0102     unsigned int index;  /* Which channel to configure. */
0103     unsigned int flags;  /* Bit field for PTP_xxx flags. */
0104     unsigned int rsv[2]; /* Reserved for future use. */
0105 };
0106 
0107 struct ptp_perout_request {
0108     union {
0109         /*
0110          * Absolute start time.
0111          * Valid only if (flags & PTP_PEROUT_PHASE) is unset.
0112          */
0113         struct ptp_clock_time start;
0114         /*
0115          * Phase offset. The signal should start toggling at an
0116          * unspecified integer multiple of the period, plus this value.
0117          * The start time should be "as soon as possible".
0118          * Valid only if (flags & PTP_PEROUT_PHASE) is set.
0119          */
0120         struct ptp_clock_time phase;
0121     };
0122     struct ptp_clock_time period; /* Desired period, zero means disable. */
0123     unsigned int index;           /* Which channel to configure. */
0124     unsigned int flags;
0125     union {
0126         /*
0127          * The "on" time of the signal.
0128          * Must be lower than the period.
0129          * Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set.
0130          */
0131         struct ptp_clock_time on;
0132         /* Reserved for future use. */
0133         unsigned int rsv[4];
0134     };
0135 };
0136 
0137 #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
0138 
0139 struct ptp_sys_offset {
0140     unsigned int n_samples; /* Desired number of measurements. */
0141     unsigned int rsv[3];    /* Reserved for future use. */
0142     /*
0143      * Array of interleaved system/phc time stamps. The kernel
0144      * will provide 2*n_samples + 1 time stamps, with the last
0145      * one as a system time stamp.
0146      */
0147     struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
0148 };
0149 
0150 struct ptp_sys_offset_extended {
0151     unsigned int n_samples; /* Desired number of measurements. */
0152     unsigned int rsv[3];    /* Reserved for future use. */
0153     /*
0154      * Array of [system, phc, system] time stamps. The kernel will provide
0155      * 3*n_samples time stamps.
0156      */
0157     struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
0158 };
0159 
0160 struct ptp_sys_offset_precise {
0161     struct ptp_clock_time device;
0162     struct ptp_clock_time sys_realtime;
0163     struct ptp_clock_time sys_monoraw;
0164     unsigned int rsv[4];    /* Reserved for future use. */
0165 };
0166 
0167 enum ptp_pin_function {
0168     PTP_PF_NONE,
0169     PTP_PF_EXTTS,
0170     PTP_PF_PEROUT,
0171     PTP_PF_PHYSYNC,
0172 };
0173 
0174 struct ptp_pin_desc {
0175     /*
0176      * Hardware specific human readable pin name. This field is
0177      * set by the kernel during the PTP_PIN_GETFUNC ioctl and is
0178      * ignored for the PTP_PIN_SETFUNC ioctl.
0179      */
0180     char name[64];
0181     /*
0182      * Pin index in the range of zero to ptp_clock_caps.n_pins - 1.
0183      */
0184     unsigned int index;
0185     /*
0186      * Which of the PTP_PF_xxx functions to use on this pin.
0187      */
0188     unsigned int func;
0189     /*
0190      * The specific channel to use for this function.
0191      * This corresponds to the 'index' field of the
0192      * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls.
0193      */
0194     unsigned int chan;
0195     /*
0196      * Reserved for future use.
0197      */
0198     unsigned int rsv[5];
0199 };
0200 
0201 #define PTP_CLK_MAGIC '='
0202 
0203 #define PTP_CLOCK_GETCAPS  _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps)
0204 #define PTP_EXTTS_REQUEST  _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request)
0205 #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request)
0206 #define PTP_ENABLE_PPS     _IOW(PTP_CLK_MAGIC, 4, int)
0207 #define PTP_SYS_OFFSET     _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
0208 #define PTP_PIN_GETFUNC    _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
0209 #define PTP_PIN_SETFUNC    _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
0210 #define PTP_SYS_OFFSET_PRECISE \
0211     _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
0212 #define PTP_SYS_OFFSET_EXTENDED \
0213     _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
0214 
0215 #define PTP_CLOCK_GETCAPS2  _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps)
0216 #define PTP_EXTTS_REQUEST2  _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request)
0217 #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request)
0218 #define PTP_ENABLE_PPS2     _IOW(PTP_CLK_MAGIC, 13, int)
0219 #define PTP_SYS_OFFSET2     _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset)
0220 #define PTP_PIN_GETFUNC2    _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc)
0221 #define PTP_PIN_SETFUNC2    _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc)
0222 #define PTP_SYS_OFFSET_PRECISE2 \
0223     _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise)
0224 #define PTP_SYS_OFFSET_EXTENDED2 \
0225     _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended)
0226 
0227 struct ptp_extts_event {
0228     struct ptp_clock_time t; /* Time event occured. */
0229     unsigned int index;      /* Which channel produced the event. */
0230     unsigned int flags;      /* Reserved for future use. */
0231     unsigned int rsv[2];     /* Reserved for future use. */
0232 };
0233 
0234 #endif