ptp_clock.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * PTP 1588 clock support - user space interface
  4. *
  5. * Copyright (C) 2010 OMICRON electronics GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef _PTP_CLOCK_H_
  22. #define _PTP_CLOCK_H_
  23. #include <linux/ioctl.h>
  24. #include <linux/types.h>
  25. /*
  26. * Bits of the ptp_extts_request.flags field:
  27. */
  28. #define PTP_ENABLE_FEATURE (1<<0)
  29. #define PTP_RISING_EDGE (1<<1)
  30. #define PTP_FALLING_EDGE (1<<2)
  31. #define PTP_STRICT_FLAGS (1<<3)
  32. #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)
  33. /*
  34. * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
  35. */
  36. #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
  37. PTP_RISING_EDGE | \
  38. PTP_FALLING_EDGE | \
  39. PTP_STRICT_FLAGS)
  40. /*
  41. * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
  42. * DO NOT ADD NEW FLAGS HERE.
  43. */
  44. #define PTP_EXTTS_V1_VALID_FLAGS (PTP_ENABLE_FEATURE | \
  45. PTP_RISING_EDGE | \
  46. PTP_FALLING_EDGE)
  47. /*
  48. * Bits of the ptp_perout_request.flags field:
  49. */
  50. #define PTP_PEROUT_ONE_SHOT (1<<0)
  51. #define PTP_PEROUT_DUTY_CYCLE (1<<1)
  52. #define PTP_PEROUT_PHASE (1<<2)
  53. /*
  54. * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl.
  55. */
  56. #define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT | \
  57. PTP_PEROUT_DUTY_CYCLE | \
  58. PTP_PEROUT_PHASE)
  59. /*
  60. * No flags are valid for the original PTP_PEROUT_REQUEST ioctl
  61. */
  62. #define PTP_PEROUT_V1_VALID_FLAGS (0)
  63. /*
  64. * struct ptp_clock_time - represents a time value
  65. *
  66. * The sign of the seconds field applies to the whole value. The
  67. * nanoseconds field is always unsigned. The reserved field is
  68. * included for sub-nanosecond resolution, should the demand for
  69. * this ever appear.
  70. *
  71. */
  72. struct ptp_clock_time {
  73. __s64 sec; /* seconds */
  74. __u32 nsec; /* nanoseconds */
  75. __u32 reserved;
  76. };
  77. struct ptp_clock_caps {
  78. int max_adj; /* Maximum frequency adjustment in parts per billon. */
  79. int n_alarm; /* Number of programmable alarms. */
  80. int n_ext_ts; /* Number of external time stamp channels. */
  81. int n_per_out; /* Number of programmable periodic signals. */
  82. int pps; /* Whether the clock supports a PPS callback. */
  83. int n_pins; /* Number of input/output pins. */
  84. /* Whether the clock supports precise system-device cross timestamps */
  85. int cross_timestamping;
  86. /* Whether the clock supports adjust phase */
  87. int adjust_phase;
  88. int max_phase_adj; /* Maximum phase adjustment in nanoseconds. */
  89. int rsv[11]; /* Reserved for future use. */
  90. };
  91. struct ptp_extts_request {
  92. unsigned int index; /* Which channel to configure. */
  93. unsigned int flags; /* Bit field for PTP_xxx flags. */
  94. unsigned int rsv[2]; /* Reserved for future use. */
  95. };
  96. struct ptp_perout_request {
  97. union {
  98. /*
  99. * Absolute start time.
  100. * Valid only if (flags & PTP_PEROUT_PHASE) is unset.
  101. */
  102. struct ptp_clock_time start;
  103. /*
  104. * Phase offset. The signal should start toggling at an
  105. * unspecified integer multiple of the period, plus this value.
  106. * The start time should be "as soon as possible".
  107. * Valid only if (flags & PTP_PEROUT_PHASE) is set.
  108. */
  109. struct ptp_clock_time phase;
  110. };
  111. struct ptp_clock_time period; /* Desired period, zero means disable. */
  112. unsigned int index; /* Which channel to configure. */
  113. unsigned int flags;
  114. union {
  115. /*
  116. * The "on" time of the signal.
  117. * Must be lower than the period.
  118. * Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set.
  119. */
  120. struct ptp_clock_time on;
  121. /* Reserved for future use. */
  122. unsigned int rsv[4];
  123. };
  124. };
  125. #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
  126. struct ptp_sys_offset {
  127. unsigned int n_samples; /* Desired number of measurements. */
  128. unsigned int rsv[3]; /* Reserved for future use. */
  129. /*
  130. * Array of interleaved system/phc time stamps. The kernel
  131. * will provide 2*n_samples + 1 time stamps, with the last
  132. * one as a system time stamp.
  133. */
  134. struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
  135. };
  136. struct ptp_sys_offset_extended {
  137. unsigned int n_samples; /* Desired number of measurements. */
  138. unsigned int rsv[3]; /* Reserved for future use. */
  139. /*
  140. * Array of [system, phc, system] time stamps. The kernel will provide
  141. * 3*n_samples time stamps.
  142. */
  143. struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
  144. };
  145. struct ptp_sys_offset_precise {
  146. struct ptp_clock_time device;
  147. struct ptp_clock_time sys_realtime;
  148. struct ptp_clock_time sys_monoraw;
  149. unsigned int rsv[4]; /* Reserved for future use. */
  150. };
  151. enum ptp_pin_function {
  152. PTP_PF_NONE,
  153. PTP_PF_EXTTS,
  154. PTP_PF_PEROUT,
  155. PTP_PF_PHYSYNC,
  156. };
  157. struct ptp_pin_desc {
  158. /*
  159. * Hardware specific human readable pin name. This field is
  160. * set by the kernel during the PTP_PIN_GETFUNC ioctl and is
  161. * ignored for the PTP_PIN_SETFUNC ioctl.
  162. */
  163. char name[64];
  164. /*
  165. * Pin index in the range of zero to ptp_clock_caps.n_pins - 1.
  166. */
  167. unsigned int index;
  168. /*
  169. * Which of the PTP_PF_xxx functions to use on this pin.
  170. */
  171. unsigned int func;
  172. /*
  173. * The specific channel to use for this function.
  174. * This corresponds to the 'index' field of the
  175. * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls.
  176. */
  177. unsigned int chan;
  178. /*
  179. * Reserved for future use.
  180. */
  181. unsigned int rsv[5];
  182. };
  183. #define PTP_CLK_MAGIC '='
  184. #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps)
  185. #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request)
  186. #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request)
  187. #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int)
  188. #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
  189. #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
  190. #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
  191. #define PTP_SYS_OFFSET_PRECISE \
  192. _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
  193. #define PTP_SYS_OFFSET_EXTENDED \
  194. _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
  195. #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps)
  196. #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request)
  197. #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request)
  198. #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int)
  199. #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset)
  200. #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc)
  201. #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc)
  202. #define PTP_SYS_OFFSET_PRECISE2 \
  203. _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise)
  204. #define PTP_SYS_OFFSET_EXTENDED2 \
  205. _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended)
  206. struct ptp_extts_event {
  207. struct ptp_clock_time t; /* Time event occured. */
  208. unsigned int index; /* Which channel produced the event. */
  209. unsigned int flags; /* Reserved for future use. */
  210. unsigned int rsv[2]; /* Reserved for future use. */
  211. };
  212. #endif