xref: /openbmc/linux/include/uapi/linux/ptp_clock.h (revision b7ea4894)
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 
28607ca46eSDavid Howells /* PTP_xxx bits, for the flags field within the request structures. */
29607ca46eSDavid Howells #define PTP_ENABLE_FEATURE (1<<0)
30607ca46eSDavid Howells #define PTP_RISING_EDGE    (1<<1)
31607ca46eSDavid Howells #define PTP_FALLING_EDGE   (1<<2)
32607ca46eSDavid Howells 
33607ca46eSDavid Howells /*
34607ca46eSDavid Howells  * struct ptp_clock_time - represents a time value
35607ca46eSDavid Howells  *
36607ca46eSDavid Howells  * The sign of the seconds field applies to the whole value. The
37607ca46eSDavid Howells  * nanoseconds field is always unsigned. The reserved field is
38607ca46eSDavid Howells  * included for sub-nanosecond resolution, should the demand for
39607ca46eSDavid Howells  * this ever appear.
40607ca46eSDavid Howells  *
41607ca46eSDavid Howells  */
42607ca46eSDavid Howells struct ptp_clock_time {
43607ca46eSDavid Howells 	__s64 sec;  /* seconds */
44607ca46eSDavid Howells 	__u32 nsec; /* nanoseconds */
45607ca46eSDavid Howells 	__u32 reserved;
46607ca46eSDavid Howells };
47607ca46eSDavid Howells 
48607ca46eSDavid Howells struct ptp_clock_caps {
49607ca46eSDavid Howells 	int max_adj;   /* Maximum frequency adjustment in parts per billon. */
50607ca46eSDavid Howells 	int n_alarm;   /* Number of programmable alarms. */
51607ca46eSDavid Howells 	int n_ext_ts;  /* Number of external time stamp channels. */
52607ca46eSDavid Howells 	int n_per_out; /* Number of programmable periodic signals. */
53607ca46eSDavid Howells 	int pps;       /* Whether the clock supports a PPS callback. */
546092315dSRichard Cochran 	int n_pins;    /* Number of input/output pins. */
55719f1aa4SChristopher S. Hall 	/* Whether the clock supports precise system-device cross timestamps */
56719f1aa4SChristopher S. Hall 	int cross_timestamping;
57719f1aa4SChristopher S. Hall 	int rsv[13];   /* Reserved for future use. */
58607ca46eSDavid Howells };
59607ca46eSDavid Howells 
60607ca46eSDavid Howells struct ptp_extts_request {
61607ca46eSDavid Howells 	unsigned int index;  /* Which channel to configure. */
62607ca46eSDavid Howells 	unsigned int flags;  /* Bit field for PTP_xxx flags. */
63607ca46eSDavid Howells 	unsigned int rsv[2]; /* Reserved for future use. */
64607ca46eSDavid Howells };
65607ca46eSDavid Howells 
66607ca46eSDavid Howells struct ptp_perout_request {
67607ca46eSDavid Howells 	struct ptp_clock_time start;  /* Absolute start time. */
68607ca46eSDavid Howells 	struct ptp_clock_time period; /* Desired period, zero means disable. */
69607ca46eSDavid Howells 	unsigned int index;           /* Which channel to configure. */
70607ca46eSDavid Howells 	unsigned int flags;           /* Reserved for future use. */
71607ca46eSDavid Howells 	unsigned int rsv[4];          /* Reserved for future use. */
72607ca46eSDavid Howells };
73607ca46eSDavid Howells 
74215b13ddSRichard Cochran #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
75215b13ddSRichard Cochran 
76215b13ddSRichard Cochran struct ptp_sys_offset {
77215b13ddSRichard Cochran 	unsigned int n_samples; /* Desired number of measurements. */
78215b13ddSRichard Cochran 	unsigned int rsv[3];    /* Reserved for future use. */
79215b13ddSRichard Cochran 	/*
80215b13ddSRichard Cochran 	 * Array of interleaved system/phc time stamps. The kernel
81215b13ddSRichard Cochran 	 * will provide 2*n_samples + 1 time stamps, with the last
82215b13ddSRichard Cochran 	 * one as a system time stamp.
83215b13ddSRichard Cochran 	 */
84215b13ddSRichard Cochran 	struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
85215b13ddSRichard Cochran };
86215b13ddSRichard Cochran 
8736180087SMiroslav Lichvar struct ptp_sys_offset_extended {
8836180087SMiroslav Lichvar 	unsigned int n_samples; /* Desired number of measurements. */
8936180087SMiroslav Lichvar 	unsigned int rsv[3];    /* Reserved for future use. */
9036180087SMiroslav Lichvar 	/*
9136180087SMiroslav Lichvar 	 * Array of [system, phc, system] time stamps. The kernel will provide
9236180087SMiroslav Lichvar 	 * 3*n_samples time stamps.
9336180087SMiroslav Lichvar 	 */
9436180087SMiroslav Lichvar 	struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
9536180087SMiroslav Lichvar };
9636180087SMiroslav Lichvar 
97719f1aa4SChristopher S. Hall struct ptp_sys_offset_precise {
98719f1aa4SChristopher S. Hall 	struct ptp_clock_time device;
99719f1aa4SChristopher S. Hall 	struct ptp_clock_time sys_realtime;
100719f1aa4SChristopher S. Hall 	struct ptp_clock_time sys_monoraw;
101719f1aa4SChristopher S. Hall 	unsigned int rsv[4];    /* Reserved for future use. */
102719f1aa4SChristopher S. Hall };
103719f1aa4SChristopher S. Hall 
1046092315dSRichard Cochran enum ptp_pin_function {
1056092315dSRichard Cochran 	PTP_PF_NONE,
1066092315dSRichard Cochran 	PTP_PF_EXTTS,
1076092315dSRichard Cochran 	PTP_PF_PEROUT,
1086092315dSRichard Cochran 	PTP_PF_PHYSYNC,
1096092315dSRichard Cochran };
1106092315dSRichard Cochran 
1116092315dSRichard Cochran struct ptp_pin_desc {
1126092315dSRichard Cochran 	/*
1136092315dSRichard Cochran 	 * Hardware specific human readable pin name. This field is
1146092315dSRichard Cochran 	 * set by the kernel during the PTP_PIN_GETFUNC ioctl and is
1156092315dSRichard Cochran 	 * ignored for the PTP_PIN_SETFUNC ioctl.
1166092315dSRichard Cochran 	 */
1176092315dSRichard Cochran 	char name[64];
1186092315dSRichard Cochran 	/*
1196092315dSRichard Cochran 	 * Pin index in the range of zero to ptp_clock_caps.n_pins - 1.
1206092315dSRichard Cochran 	 */
1216092315dSRichard Cochran 	unsigned int index;
1226092315dSRichard Cochran 	/*
1236092315dSRichard Cochran 	 * Which of the PTP_PF_xxx functions to use on this pin.
1246092315dSRichard Cochran 	 */
1256092315dSRichard Cochran 	unsigned int func;
1266092315dSRichard Cochran 	/*
1276092315dSRichard Cochran 	 * The specific channel to use for this function.
1286092315dSRichard Cochran 	 * This corresponds to the 'index' field of the
1296092315dSRichard Cochran 	 * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls.
1306092315dSRichard Cochran 	 */
1316092315dSRichard Cochran 	unsigned int chan;
1326092315dSRichard Cochran 	/*
1336092315dSRichard Cochran 	 * Reserved for future use.
1346092315dSRichard Cochran 	 */
1356092315dSRichard Cochran 	unsigned int rsv[5];
1366092315dSRichard Cochran };
1376092315dSRichard Cochran 
138607ca46eSDavid Howells #define PTP_CLK_MAGIC '='
139607ca46eSDavid Howells 
140607ca46eSDavid Howells #define PTP_CLOCK_GETCAPS  _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps)
141607ca46eSDavid Howells #define PTP_EXTTS_REQUEST  _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request)
142607ca46eSDavid Howells #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request)
143607ca46eSDavid Howells #define PTP_ENABLE_PPS     _IOW(PTP_CLK_MAGIC, 4, int)
144215b13ddSRichard Cochran #define PTP_SYS_OFFSET     _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
1456092315dSRichard Cochran #define PTP_PIN_GETFUNC    _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
1466092315dSRichard Cochran #define PTP_PIN_SETFUNC    _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
147719f1aa4SChristopher S. Hall #define PTP_SYS_OFFSET_PRECISE \
148719f1aa4SChristopher S. Hall 	_IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
14936180087SMiroslav Lichvar #define PTP_SYS_OFFSET_EXTENDED \
150*b7ea4894SEugene Syromiatnikov 	_IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
151607ca46eSDavid Howells 
152607ca46eSDavid Howells struct ptp_extts_event {
153607ca46eSDavid Howells 	struct ptp_clock_time t; /* Time event occured. */
154607ca46eSDavid Howells 	unsigned int index;      /* Which channel produced the event. */
155607ca46eSDavid Howells 	unsigned int flags;      /* Reserved for future use. */
156607ca46eSDavid Howells 	unsigned int rsv[2];     /* Reserved for future use. */
157607ca46eSDavid Howells };
158607ca46eSDavid Howells 
159607ca46eSDavid Howells #endif
160