1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linu 1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2 /* 2 /* 3 * PTP 1588 clock support - user space interfa 3 * PTP 1588 clock support - user space interface 4 * 4 * 5 * Copyright (C) 2010 OMICRON electronics GmbH 5 * Copyright (C) 2010 OMICRON electronics GmbH 6 * 6 * 7 * This program is free software; you can red 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Publ 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either versi 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 10 * (at your option) any later version. 11 * 11 * 12 * This program is distributed in the hope th 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULA 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more detail 15 * GNU General Public License for more details. 16 * 16 * 17 * You should have received a copy of the GNU 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 675 Mass Ave, Cambridge, 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 */ 20 */ 21 21 22 #ifndef _PTP_CLOCK_H_ 22 #ifndef _PTP_CLOCK_H_ 23 #define _PTP_CLOCK_H_ 23 #define _PTP_CLOCK_H_ 24 24 25 #include <linux/ioctl.h> 25 #include <linux/ioctl.h> 26 #include <linux/types.h> 26 #include <linux/types.h> 27 27 28 /* 28 /* 29 * Bits of the ptp_extts_request.flags field: 29 * Bits of the ptp_extts_request.flags field: 30 */ 30 */ 31 #define PTP_ENABLE_FEATURE (1<<0) 31 #define PTP_ENABLE_FEATURE (1<<0) 32 #define PTP_RISING_EDGE (1<<1) 32 #define PTP_RISING_EDGE (1<<1) 33 #define PTP_FALLING_EDGE (1<<2) 33 #define PTP_FALLING_EDGE (1<<2) 34 #define PTP_STRICT_FLAGS (1<<3) 34 #define PTP_STRICT_FLAGS (1<<3) 35 #define PTP_EXT_OFFSET (1<<4) << 36 #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | 35 #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE) 37 36 38 /* 37 /* 39 * flag fields valid for the new PTP_EXTTS_REQ 38 * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl. 40 */ 39 */ 41 #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FE 40 #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \ 42 PTP_RISING_ED 41 PTP_RISING_EDGE | \ 43 PTP_FALLING_E 42 PTP_FALLING_EDGE | \ 44 PTP_STRICT_FL !! 43 PTP_STRICT_FLAGS) 45 PTP_EXT_OFFSE << 46 44 47 /* 45 /* 48 * flag fields valid for the original PTP_EXTT 46 * flag fields valid for the original PTP_EXTTS_REQUEST ioctl. 49 * DO NOT ADD NEW FLAGS HERE. 47 * DO NOT ADD NEW FLAGS HERE. 50 */ 48 */ 51 #define PTP_EXTTS_V1_VALID_FLAGS (PTP_E 49 #define PTP_EXTTS_V1_VALID_FLAGS (PTP_ENABLE_FEATURE | \ 52 PTP_R 50 PTP_RISING_EDGE | \ 53 PTP_F 51 PTP_FALLING_EDGE) 54 52 55 /* 53 /* 56 * flag fields valid for the ptp_extts_event r << 57 */ << 58 #define PTP_EXTTS_EVENT_VALID (PTP_ENABLE_FE << 59 << 60 /* << 61 * Bits of the ptp_perout_request.flags field: 54 * Bits of the ptp_perout_request.flags field: 62 */ 55 */ 63 #define PTP_PEROUT_ONE_SHOT (1<<0) 56 #define PTP_PEROUT_ONE_SHOT (1<<0) 64 #define PTP_PEROUT_DUTY_CYCLE (1<<1) 57 #define PTP_PEROUT_DUTY_CYCLE (1<<1) 65 #define PTP_PEROUT_PHASE (1<<2) 58 #define PTP_PEROUT_PHASE (1<<2) 66 59 67 /* 60 /* 68 * flag fields valid for the new PTP_PEROUT_RE 61 * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl. 69 */ 62 */ 70 #define PTP_PEROUT_VALID_FLAGS (PTP_P 63 #define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT | \ 71 PTP_P 64 PTP_PEROUT_DUTY_CYCLE | \ 72 PTP_P 65 PTP_PEROUT_PHASE) 73 66 74 /* 67 /* 75 * No flags are valid for the original PTP_PER 68 * No flags are valid for the original PTP_PEROUT_REQUEST ioctl 76 */ 69 */ 77 #define PTP_PEROUT_V1_VALID_FLAGS (0) 70 #define PTP_PEROUT_V1_VALID_FLAGS (0) 78 71 79 /* 72 /* 80 * struct ptp_clock_time - represents a time v 73 * struct ptp_clock_time - represents a time value 81 * 74 * 82 * The sign of the seconds field applies to th 75 * The sign of the seconds field applies to the whole value. The 83 * nanoseconds field is always unsigned. The r 76 * nanoseconds field is always unsigned. The reserved field is 84 * included for sub-nanosecond resolution, sho 77 * included for sub-nanosecond resolution, should the demand for 85 * this ever appear. 78 * this ever appear. 86 * 79 * 87 */ 80 */ 88 struct ptp_clock_time { 81 struct ptp_clock_time { 89 __s64 sec; /* seconds */ 82 __s64 sec; /* seconds */ 90 __u32 nsec; /* nanoseconds */ 83 __u32 nsec; /* nanoseconds */ 91 __u32 reserved; 84 __u32 reserved; 92 }; 85 }; 93 86 94 struct ptp_clock_caps { 87 struct ptp_clock_caps { 95 int max_adj; /* Maximum frequency ad 88 int max_adj; /* Maximum frequency adjustment in parts per billon. */ 96 int n_alarm; /* Number of programmab 89 int n_alarm; /* Number of programmable alarms. */ 97 int n_ext_ts; /* Number of external t 90 int n_ext_ts; /* Number of external time stamp channels. */ 98 int n_per_out; /* Number of programmab 91 int n_per_out; /* Number of programmable periodic signals. */ 99 int pps; /* Whether the clock su 92 int pps; /* Whether the clock supports a PPS callback. */ 100 int n_pins; /* Number of input/outp 93 int n_pins; /* Number of input/output pins. */ 101 /* Whether the clock supports precise 94 /* Whether the clock supports precise system-device cross timestamps */ 102 int cross_timestamping; 95 int cross_timestamping; 103 /* Whether the clock supports adjust p 96 /* Whether the clock supports adjust phase */ 104 int adjust_phase; 97 int adjust_phase; 105 int max_phase_adj; /* Maximum phase ad !! 98 int rsv[12]; /* Reserved for future use. */ 106 int rsv[11]; /* Reserved for fut << 107 }; 99 }; 108 100 109 struct ptp_extts_request { 101 struct ptp_extts_request { 110 unsigned int index; /* Which channel 102 unsigned int index; /* Which channel to configure. */ 111 unsigned int flags; /* Bit field for 103 unsigned int flags; /* Bit field for PTP_xxx flags. */ 112 unsigned int rsv[2]; /* Reserved for f 104 unsigned int rsv[2]; /* Reserved for future use. */ 113 }; 105 }; 114 106 115 struct ptp_perout_request { 107 struct ptp_perout_request { 116 union { 108 union { 117 /* 109 /* 118 * Absolute start time. 110 * Absolute start time. 119 * Valid only if (flags & PTP_ 111 * Valid only if (flags & PTP_PEROUT_PHASE) is unset. 120 */ 112 */ 121 struct ptp_clock_time start; 113 struct ptp_clock_time start; 122 /* 114 /* 123 * Phase offset. The signal sh 115 * Phase offset. The signal should start toggling at an 124 * unspecified integer multipl 116 * unspecified integer multiple of the period, plus this value. 125 * The start time should be "a 117 * The start time should be "as soon as possible". 126 * Valid only if (flags & PTP_ 118 * Valid only if (flags & PTP_PEROUT_PHASE) is set. 127 */ 119 */ 128 struct ptp_clock_time phase; 120 struct ptp_clock_time phase; 129 }; 121 }; 130 struct ptp_clock_time period; /* Desir 122 struct ptp_clock_time period; /* Desired period, zero means disable. */ 131 unsigned int index; /* Which 123 unsigned int index; /* Which channel to configure. */ 132 unsigned int flags; 124 unsigned int flags; 133 union { 125 union { 134 /* 126 /* 135 * The "on" time of the signal 127 * The "on" time of the signal. 136 * Must be lower than the peri 128 * Must be lower than the period. 137 * Valid only if (flags & PTP_ 129 * Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set. 138 */ 130 */ 139 struct ptp_clock_time on; 131 struct ptp_clock_time on; 140 /* Reserved for future use. */ 132 /* Reserved for future use. */ 141 unsigned int rsv[4]; 133 unsigned int rsv[4]; 142 }; 134 }; 143 }; 135 }; 144 136 145 #define PTP_MAX_SAMPLES 25 /* Maximum allowed 137 #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ 146 138 147 struct ptp_sys_offset { 139 struct ptp_sys_offset { 148 unsigned int n_samples; /* Desired num 140 unsigned int n_samples; /* Desired number of measurements. */ 149 unsigned int rsv[3]; /* Reserved fo 141 unsigned int rsv[3]; /* Reserved for future use. */ 150 /* 142 /* 151 * Array of interleaved system/phc tim 143 * Array of interleaved system/phc time stamps. The kernel 152 * will provide 2*n_samples + 1 time s 144 * will provide 2*n_samples + 1 time stamps, with the last 153 * one as a system time stamp. 145 * one as a system time stamp. 154 */ 146 */ 155 struct ptp_clock_time ts[2 * PTP_MAX_S 147 struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 156 }; 148 }; 157 149 158 /* << 159 * ptp_sys_offset_extended - data structure fo << 160 * PTP_SYS_OFFSET_EX << 161 * << 162 * @n_samples: Desired number of measurements << 163 * @clockid: clockid of a clock-base used f << 164 * @rsv: Reserved for future use. << 165 * @ts: Array of samples in the form [ << 166 * kernel provides @n_samples. << 167 * << 168 * Starting from kernel 6.12 and onwards, the << 169 * is used for @clockid. That's backward compa << 170 * expect all three reserved words (@rsv[3]) t << 171 * word in the new structure) for CLOCK_REALTI << 172 */ << 173 struct ptp_sys_offset_extended { 150 struct ptp_sys_offset_extended { 174 unsigned int n_samples; !! 151 unsigned int n_samples; /* Desired number of measurements. */ 175 __kernel_clockid_t clockid; !! 152 unsigned int rsv[3]; /* Reserved for future use. */ 176 unsigned int rsv[2]; !! 153 /* >> 154 * Array of [system, phc, system] time stamps. The kernel will provide >> 155 * 3*n_samples time stamps. >> 156 */ 177 struct ptp_clock_time ts[PTP_MAX_SAMPL 157 struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; 178 }; 158 }; 179 159 180 struct ptp_sys_offset_precise { 160 struct ptp_sys_offset_precise { 181 struct ptp_clock_time device; 161 struct ptp_clock_time device; 182 struct ptp_clock_time sys_realtime; 162 struct ptp_clock_time sys_realtime; 183 struct ptp_clock_time sys_monoraw; 163 struct ptp_clock_time sys_monoraw; 184 unsigned int rsv[4]; /* Reserved fo 164 unsigned int rsv[4]; /* Reserved for future use. */ 185 }; 165 }; 186 166 187 enum ptp_pin_function { 167 enum ptp_pin_function { 188 PTP_PF_NONE, 168 PTP_PF_NONE, 189 PTP_PF_EXTTS, 169 PTP_PF_EXTTS, 190 PTP_PF_PEROUT, 170 PTP_PF_PEROUT, 191 PTP_PF_PHYSYNC, 171 PTP_PF_PHYSYNC, 192 }; 172 }; 193 173 194 struct ptp_pin_desc { 174 struct ptp_pin_desc { 195 /* 175 /* 196 * Hardware specific human readable pi 176 * Hardware specific human readable pin name. This field is 197 * set by the kernel during the PTP_PI 177 * set by the kernel during the PTP_PIN_GETFUNC ioctl and is 198 * ignored for the PTP_PIN_SETFUNC ioc 178 * ignored for the PTP_PIN_SETFUNC ioctl. 199 */ 179 */ 200 char name[64]; 180 char name[64]; 201 /* 181 /* 202 * Pin index in the range of zero to p 182 * Pin index in the range of zero to ptp_clock_caps.n_pins - 1. 203 */ 183 */ 204 unsigned int index; 184 unsigned int index; 205 /* 185 /* 206 * Which of the PTP_PF_xxx functions t 186 * Which of the PTP_PF_xxx functions to use on this pin. 207 */ 187 */ 208 unsigned int func; 188 unsigned int func; 209 /* 189 /* 210 * The specific channel to use for thi 190 * The specific channel to use for this function. 211 * This corresponds to the 'index' fie 191 * This corresponds to the 'index' field of the 212 * PTP_EXTTS_REQUEST and PTP_PEROUT_RE 192 * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls. 213 */ 193 */ 214 unsigned int chan; 194 unsigned int chan; 215 /* 195 /* 216 * Reserved for future use. 196 * Reserved for future use. 217 */ 197 */ 218 unsigned int rsv[5]; 198 unsigned int rsv[5]; 219 }; 199 }; 220 200 221 #define PTP_CLK_MAGIC '=' 201 #define PTP_CLK_MAGIC '=' 222 202 223 #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 203 #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) 224 #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 204 #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) 225 #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 205 #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) 226 #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 206 #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) 227 #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 207 #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 228 #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC 208 #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) 229 #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 209 #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) 230 #define PTP_SYS_OFFSET_PRECISE \ 210 #define PTP_SYS_OFFSET_PRECISE \ 231 _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys 211 _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise) 232 #define PTP_SYS_OFFSET_EXTENDED \ 212 #define PTP_SYS_OFFSET_EXTENDED \ 233 _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys 213 _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended) 234 214 235 #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC 215 #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps) 236 #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC 216 #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request) 237 #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC 217 #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request) 238 #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC 218 #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int) 239 #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC 219 #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset) 240 #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGI 220 #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc) 241 #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC 221 #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc) 242 #define PTP_SYS_OFFSET_PRECISE2 \ 222 #define PTP_SYS_OFFSET_PRECISE2 \ 243 _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sy 223 _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise) 244 #define PTP_SYS_OFFSET_EXTENDED2 \ 224 #define PTP_SYS_OFFSET_EXTENDED2 \ 245 _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sy 225 _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) 246 #define PTP_MASK_CLEAR_ALL _IO(PTP_CLK_MAGIC, << 247 #define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC << 248 226 249 struct ptp_extts_event { 227 struct ptp_extts_event { 250 struct ptp_clock_time t; /* Time event !! 228 struct ptp_clock_time t; /* Time event occured. */ 251 unsigned int index; /* Which chan 229 unsigned int index; /* Which channel produced the event. */ 252 unsigned int flags; /* Event type !! 230 unsigned int flags; /* Reserved for future use. */ 253 unsigned int rsv[2]; /* Reserved f 231 unsigned int rsv[2]; /* Reserved for future use. */ 254 }; 232 }; 255 233 256 #endif 234 #endif 257 235
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.