pps_kernel.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * PPS API kernel header
  3. *
  4. * Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef LINUX_PPS_KERNEL_H
  21. #define LINUX_PPS_KERNEL_H
  22. #include <linux/pps.h>
  23. #include <linux/cdev.h>
  24. #include <linux/device.h>
  25. #include <linux/time.h>
  26. /*
  27. * Global defines
  28. */
  29. struct pps_device;
  30. /* The specific PPS source info */
  31. struct pps_source_info {
  32. char name[PPS_MAX_NAME_LEN]; /* simbolic name */
  33. char path[PPS_MAX_NAME_LEN]; /* path of connected device */
  34. int mode; /* PPS's allowed mode */
  35. void (*echo)(struct pps_device *pps,
  36. int event, void *data); /* PPS echo function */
  37. struct module *owner;
  38. struct device *dev; /* Parent device for device_create */
  39. };
  40. struct pps_event_time {
  41. #ifdef CONFIG_NTP_PPS
  42. struct timespec ts_raw;
  43. #endif /* CONFIG_NTP_PPS */
  44. struct timespec ts_real;
  45. };
  46. /* The main struct */
  47. struct pps_device {
  48. struct pps_source_info info; /* PSS source info */
  49. struct pps_kparams params; /* PPS's current params */
  50. __u32 assert_sequence; /* PPS' assert event seq # */
  51. __u32 clear_sequence; /* PPS' clear event seq # */
  52. struct pps_ktime assert_tu;
  53. struct pps_ktime clear_tu;
  54. int current_mode; /* PPS mode at event time */
  55. unsigned int last_ev; /* last PPS event id */
  56. wait_queue_head_t queue; /* PPS event queue */
  57. unsigned int id; /* PPS source unique ID */
  58. void const *lookup_cookie; /* pps_lookup_dev only */
  59. struct cdev cdev;
  60. struct device *dev;
  61. struct fasync_struct *async_queue; /* fasync method */
  62. spinlock_t lock;
  63. };
  64. /*
  65. * Global variables
  66. */
  67. extern struct device_attribute pps_attrs[];
  68. /*
  69. * Internal functions.
  70. *
  71. * These are not actually part of the exported API, but this is a
  72. * convenient header file to put them in.
  73. */
  74. extern int pps_register_cdev(struct pps_device *pps);
  75. extern void pps_unregister_cdev(struct pps_device *pps);
  76. /*
  77. * Exported functions
  78. */
  79. extern struct pps_device *pps_register_source(
  80. struct pps_source_info *info, int default_params);
  81. extern void pps_unregister_source(struct pps_device *pps);
  82. extern void pps_event(struct pps_device *pps,
  83. struct pps_event_time *ts, int event, void *data);
  84. /* Look up a pps device by magic cookie */
  85. struct pps_device *pps_lookup_dev(void const *cookie);
  86. static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
  87. struct timespec ts)
  88. {
  89. kt->sec = ts.tv_sec;
  90. kt->nsec = ts.tv_nsec;
  91. }
  92. #ifdef CONFIG_NTP_PPS
  93. static inline void pps_get_ts(struct pps_event_time *ts)
  94. {
  95. getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
  96. }
  97. #else /* CONFIG_NTP_PPS */
  98. static inline void pps_get_ts(struct pps_event_time *ts)
  99. {
  100. getnstimeofday(&ts->ts_real);
  101. }
  102. #endif /* CONFIG_NTP_PPS */
  103. #endif /* LINUX_PPS_KERNEL_H */