logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ptp_clock.h (8294B)


  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_EXT_OFFSET (1<<4)
  33. #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)
  34. /*
  35. * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
  36. */
  37. #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
  38. PTP_RISING_EDGE | \
  39. PTP_FALLING_EDGE | \
  40. PTP_STRICT_FLAGS | \
  41. PTP_EXT_OFFSET)
  42. /*
  43. * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
  44. * DO NOT ADD NEW FLAGS HERE.
  45. */
  46. #define PTP_EXTTS_V1_VALID_FLAGS (PTP_ENABLE_FEATURE | \
  47. PTP_RISING_EDGE | \
  48. PTP_FALLING_EDGE)
  49. /*
  50. * flag fields valid for the ptp_extts_event report.
  51. */
  52. #define PTP_EXTTS_EVENT_VALID (PTP_ENABLE_FEATURE)
  53. /*
  54. * Bits of the ptp_perout_request.flags field:
  55. */
  56. #define PTP_PEROUT_ONE_SHOT (1<<0)
  57. #define PTP_PEROUT_DUTY_CYCLE (1<<1)
  58. #define PTP_PEROUT_PHASE (1<<2)
  59. /*
  60. * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl.
  61. */
  62. #define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT | \
  63. PTP_PEROUT_DUTY_CYCLE | \
  64. PTP_PEROUT_PHASE)
  65. /*
  66. * No flags are valid for the original PTP_PEROUT_REQUEST ioctl
  67. */
  68. #define PTP_PEROUT_V1_VALID_FLAGS (0)
  69. /*
  70. * struct ptp_clock_time - represents a time value
  71. *
  72. * The sign of the seconds field applies to the whole value. The
  73. * nanoseconds field is always unsigned. The reserved field is
  74. * included for sub-nanosecond resolution, should the demand for
  75. * this ever appear.
  76. *
  77. */
  78. struct ptp_clock_time {
  79. __s64 sec; /* seconds */
  80. __u32 nsec; /* nanoseconds */
  81. __u32 reserved;
  82. };
  83. struct ptp_clock_caps {
  84. int max_adj; /* Maximum frequency adjustment in parts per billon. */
  85. int n_alarm; /* Number of programmable alarms. */
  86. int n_ext_ts; /* Number of external time stamp channels. */
  87. int n_per_out; /* Number of programmable periodic signals. */
  88. int pps; /* Whether the clock supports a PPS callback. */
  89. int n_pins; /* Number of input/output pins. */
  90. /* Whether the clock supports precise system-device cross timestamps */
  91. int cross_timestamping;
  92. /* Whether the clock supports adjust phase */
  93. int adjust_phase;
  94. int max_phase_adj; /* Maximum phase adjustment in nanoseconds. */
  95. int rsv[11]; /* Reserved for future use. */
  96. };
  97. struct ptp_extts_request {
  98. unsigned int index; /* Which channel to configure. */
  99. unsigned int flags; /* Bit field for PTP_xxx flags. */
  100. unsigned int rsv[2]; /* Reserved for future use. */
  101. };
  102. struct ptp_perout_request {
  103. union {
  104. /*
  105. * Absolute start time.
  106. * Valid only if (flags & PTP_PEROUT_PHASE) is unset.
  107. */
  108. struct ptp_clock_time start;
  109. /*
  110. * Phase offset. The signal should start toggling at an
  111. * unspecified integer multiple of the period, plus this value.
  112. * The start time should be "as soon as possible".
  113. * Valid only if (flags & PTP_PEROUT_PHASE) is set.
  114. */
  115. struct ptp_clock_time phase;
  116. };
  117. struct ptp_clock_time period; /* Desired period, zero means disable. */
  118. unsigned int index; /* Which channel to configure. */
  119. unsigned int flags;
  120. union {
  121. /*
  122. * The "on" time of the signal.
  123. * Must be lower than the period.
  124. * Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set.
  125. */
  126. struct ptp_clock_time on;
  127. /* Reserved for future use. */
  128. unsigned int rsv[4];
  129. };
  130. };
  131. #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
  132. struct ptp_sys_offset {
  133. unsigned int n_samples; /* Desired number of measurements. */
  134. unsigned int rsv[3]; /* Reserved for future use. */
  135. /*
  136. * Array of interleaved system/phc time stamps. The kernel
  137. * will provide 2*n_samples + 1 time stamps, with the last
  138. * one as a system time stamp.
  139. */
  140. struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
  141. };
  142. /*
  143. * ptp_sys_offset_extended - data structure for IOCTL operation
  144. * PTP_SYS_OFFSET_EXTENDED
  145. *
  146. * @n_samples: Desired number of measurements.
  147. * @clockid: clockid of a clock-base used for pre/post timestamps.
  148. * @rsv: Reserved for future use.
  149. * @ts: Array of samples in the form [pre-TS, PHC, post-TS]. The
  150. * kernel provides @n_samples.
  151. *
  152. * Starting from kernel 6.12 and onwards, the first word of the reserved-field
  153. * is used for @clockid. That's backward compatible since previous kernel
  154. * expect all three reserved words (@rsv[3]) to be 0 while the clockid (first
  155. * word in the new structure) for CLOCK_REALTIME is '0'.
  156. */
  157. struct ptp_sys_offset_extended {
  158. unsigned int n_samples;
  159. __kernel_clockid_t clockid;
  160. unsigned int rsv[2];
  161. struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
  162. };
  163. struct ptp_sys_offset_precise {
  164. struct ptp_clock_time device;
  165. struct ptp_clock_time sys_realtime;
  166. struct ptp_clock_time sys_monoraw;
  167. unsigned int rsv[4]; /* Reserved for future use. */
  168. };
  169. enum ptp_pin_function {
  170. PTP_PF_NONE,
  171. PTP_PF_EXTTS,
  172. PTP_PF_PEROUT,
  173. PTP_PF_PHYSYNC,
  174. };
  175. struct ptp_pin_desc {
  176. /*
  177. * Hardware specific human readable pin name. This field is
  178. * set by the kernel during the PTP_PIN_GETFUNC ioctl and is
  179. * ignored for the PTP_PIN_SETFUNC ioctl.
  180. */
  181. char name[64];
  182. /*
  183. * Pin index in the range of zero to ptp_clock_caps.n_pins - 1.
  184. */
  185. unsigned int index;
  186. /*
  187. * Which of the PTP_PF_xxx functions to use on this pin.
  188. */
  189. unsigned int func;
  190. /*
  191. * The specific channel to use for this function.
  192. * This corresponds to the 'index' field of the
  193. * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls.
  194. */
  195. unsigned int chan;
  196. /*
  197. * Reserved for future use.
  198. */
  199. unsigned int rsv[5];
  200. };
  201. #define PTP_CLK_MAGIC '='
  202. #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps)
  203. #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request)
  204. #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request)
  205. #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int)
  206. #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
  207. #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
  208. #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
  209. #define PTP_SYS_OFFSET_PRECISE \
  210. _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
  211. #define PTP_SYS_OFFSET_EXTENDED \
  212. _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
  213. #define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps)
  214. #define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request)
  215. #define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request)
  216. #define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int)
  217. #define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset)
  218. #define PTP_PIN_GETFUNC2 _IOWR(PTP_CLK_MAGIC, 15, struct ptp_pin_desc)
  219. #define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc)
  220. #define PTP_SYS_OFFSET_PRECISE2 \
  221. _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise)
  222. #define PTP_SYS_OFFSET_EXTENDED2 \
  223. _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended)
  224. #define PTP_MASK_CLEAR_ALL _IO(PTP_CLK_MAGIC, 19)
  225. #define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC, 20, unsigned int)
  226. struct ptp_extts_event {
  227. struct ptp_clock_time t; /* Time event occurred. */
  228. unsigned int index; /* Which channel produced the event. */
  229. unsigned int flags; /* Event type. */
  230. unsigned int rsv[2]; /* Reserved for future use. */
  231. };
  232. #endif