ptp_clock.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /* PTP_xxx bits, for the flags field within the request structures. */
  26. #define PTP_ENABLE_FEATURE (1<<0)
  27. #define PTP_RISING_EDGE (1<<1)
  28. #define PTP_FALLING_EDGE (1<<2)
  29. /*
  30. * struct ptp_clock_time - represents a time value
  31. *
  32. * The sign of the seconds field applies to the whole value. The
  33. * nanoseconds field is always unsigned. The reserved field is
  34. * included for sub-nanosecond resolution, should the demand for
  35. * this ever appear.
  36. *
  37. */
  38. struct ptp_clock_time {
  39. __s64 sec; /* seconds */
  40. __u32 nsec; /* nanoseconds */
  41. __u32 reserved;
  42. };
  43. struct ptp_clock_caps {
  44. int max_adj; /* Maximum frequency adjustment in parts per billon. */
  45. int n_alarm; /* Number of programmable alarms. */
  46. int n_ext_ts; /* Number of external time stamp channels. */
  47. int n_per_out; /* Number of programmable periodic signals. */
  48. int pps; /* Whether the clock supports a PPS callback. */
  49. int n_pins; /* Number of input/output pins. */
  50. /* Whether the clock supports precise system-device cross timestamps */
  51. int cross_timestamping;
  52. int rsv[13]; /* Reserved for future use. */
  53. };
  54. struct ptp_extts_request {
  55. unsigned int index; /* Which channel to configure. */
  56. unsigned int flags; /* Bit field for PTP_xxx flags. */
  57. unsigned int rsv[2]; /* Reserved for future use. */
  58. };
  59. struct ptp_perout_request {
  60. struct ptp_clock_time start; /* Absolute start time. */
  61. struct ptp_clock_time period; /* Desired period, zero means disable. */
  62. unsigned int index; /* Which channel to configure. */
  63. unsigned int flags; /* Reserved for future use. */
  64. unsigned int rsv[4]; /* Reserved for future use. */
  65. };
  66. #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
  67. struct ptp_sys_offset {
  68. unsigned int n_samples; /* Desired number of measurements. */
  69. unsigned int rsv[3]; /* Reserved for future use. */
  70. /*
  71. * Array of interleaved system/phc time stamps. The kernel
  72. * will provide 2*n_samples + 1 time stamps, with the last
  73. * one as a system time stamp.
  74. */
  75. struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
  76. };
  77. struct ptp_sys_offset_precise {
  78. struct ptp_clock_time device;
  79. struct ptp_clock_time sys_realtime;
  80. struct ptp_clock_time sys_monoraw;
  81. unsigned int rsv[4]; /* Reserved for future use. */
  82. };
  83. enum ptp_pin_function {
  84. PTP_PF_NONE,
  85. PTP_PF_EXTTS,
  86. PTP_PF_PEROUT,
  87. PTP_PF_PHYSYNC,
  88. };
  89. struct ptp_pin_desc {
  90. /*
  91. * Hardware specific human readable pin name. This field is
  92. * set by the kernel during the PTP_PIN_GETFUNC ioctl and is
  93. * ignored for the PTP_PIN_SETFUNC ioctl.
  94. */
  95. char name[64];
  96. /*
  97. * Pin index in the range of zero to ptp_clock_caps.n_pins - 1.
  98. */
  99. unsigned int index;
  100. /*
  101. * Which of the PTP_PF_xxx functions to use on this pin.
  102. */
  103. unsigned int func;
  104. /*
  105. * The specific channel to use for this function.
  106. * This corresponds to the 'index' field of the
  107. * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls.
  108. */
  109. unsigned int chan;
  110. /*
  111. * Reserved for future use.
  112. */
  113. unsigned int rsv[5];
  114. };
  115. #define PTP_CLK_MAGIC '='
  116. #define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps)
  117. #define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request)
  118. #define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request)
  119. #define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int)
  120. #define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
  121. #define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
  122. #define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
  123. #define PTP_SYS_OFFSET_PRECISE \
  124. _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
  125. struct ptp_extts_event {
  126. struct ptp_clock_time t; /* Time event occured. */
  127. unsigned int index; /* Which channel produced the event. */
  128. unsigned int flags; /* Reserved for future use. */
  129. unsigned int rsv[2]; /* Reserved for future use. */
  130. };
  131. #endif