pps.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * PPS API header
  4. *
  5. * Copyright (C) 2005-2009 Rodolfo Giometti <giometti@linux.it>
  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 _PPS_H_
  22. #define _PPS_H_
  23. #include <linux/types.h>
  24. #define PPS_VERSION "5.3.6"
  25. #define PPS_MAX_SOURCES 16 /* should be enough... */
  26. /* Implementation note: the logical states ``assert'' and ``clear''
  27. * are implemented in terms of the chip register, i.e. ``assert''
  28. * means the bit is set. */
  29. /*
  30. * 3.2 New data structures
  31. */
  32. #define PPS_API_VERS_1 1
  33. #define PPS_API_VERS PPS_API_VERS_1 /* we use API version 1 */
  34. #define PPS_MAX_NAME_LEN 32
  35. /* 32-bit vs. 64-bit compatibility.
  36. *
  37. * 0n i386, the alignment of a uint64_t is only 4 bytes, while on most other
  38. * architectures it's 8 bytes. On i386, there will be no padding between the
  39. * two consecutive 'struct pps_ktime' members of struct pps_kinfo and struct
  40. * pps_kparams. But on most platforms there will be padding to ensure correct
  41. * alignment.
  42. *
  43. * The simple fix is probably to add an explicit padding.
  44. * [David Woodhouse]
  45. */
  46. struct pps_ktime {
  47. __s64 sec;
  48. __s32 nsec;
  49. __u32 flags;
  50. };
  51. struct pps_ktime_compat {
  52. __s64 sec;
  53. __s32 nsec;
  54. __u32 flags;
  55. } __attribute__((packed, aligned(4)));
  56. #define PPS_TIME_INVALID (1<<0) /* used to specify timeout==NULL */
  57. struct pps_kinfo {
  58. __u32 assert_sequence; /* seq. num. of assert event */
  59. __u32 clear_sequence; /* seq. num. of clear event */
  60. struct pps_ktime assert_tu; /* time of assert event */
  61. struct pps_ktime clear_tu; /* time of clear event */
  62. int current_mode; /* current mode bits */
  63. };
  64. struct pps_kinfo_compat {
  65. __u32 assert_sequence; /* seq. num. of assert event */
  66. __u32 clear_sequence; /* seq. num. of clear event */
  67. struct pps_ktime_compat assert_tu; /* time of assert event */
  68. struct pps_ktime_compat clear_tu; /* time of clear event */
  69. int current_mode; /* current mode bits */
  70. };
  71. struct pps_kparams {
  72. int api_version; /* API version # */
  73. int mode; /* mode bits */
  74. struct pps_ktime assert_off_tu; /* offset compensation for assert */
  75. struct pps_ktime clear_off_tu; /* offset compensation for clear */
  76. };
  77. /*
  78. * 3.3 Mode bit definitions
  79. */
  80. /* Device/implementation parameters */
  81. #define PPS_CAPTUREASSERT 0x01 /* capture assert events */
  82. #define PPS_CAPTURECLEAR 0x02 /* capture clear events */
  83. #define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */
  84. #define PPS_OFFSETASSERT 0x10 /* apply compensation for assert event */
  85. #define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear event */
  86. #define PPS_CANWAIT 0x100 /* can we wait for an event? */
  87. #define PPS_CANPOLL 0x200 /* bit reserved for future use */
  88. /* Kernel actions */
  89. #define PPS_ECHOASSERT 0x40 /* feed back assert event to output */
  90. #define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */
  91. /* Timestamp formats */
  92. #define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */
  93. #define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */
  94. /*
  95. * 3.4.4 New functions: disciplining the kernel timebase
  96. */
  97. /* Kernel consumers */
  98. #define PPS_KC_HARDPPS 0 /* hardpps() (or equivalent) */
  99. #define PPS_KC_HARDPPS_PLL 1 /* hardpps() constrained to
  100. use a phase-locked loop */
  101. #define PPS_KC_HARDPPS_FLL 2 /* hardpps() constrained to
  102. use a frequency-locked loop */
  103. /*
  104. * Here begins the implementation-specific part!
  105. */
  106. struct pps_fdata {
  107. struct pps_kinfo info;
  108. struct pps_ktime timeout;
  109. };
  110. struct pps_fdata_compat {
  111. struct pps_kinfo_compat info;
  112. struct pps_ktime_compat timeout;
  113. };
  114. struct pps_bind_args {
  115. int tsformat; /* format of time stamps */
  116. int edge; /* selected event type */
  117. int consumer; /* selected kernel consumer */
  118. };
  119. #include <linux/ioctl.h>
  120. #define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *)
  121. #define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *)
  122. #define PPS_GETCAP _IOR('p', 0xa3, int *)
  123. #define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *)
  124. #define PPS_KC_BIND _IOW('p', 0xa5, struct pps_bind_args *)
  125. #endif /* _PPS_H_ */