ptp_private.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * PTP 1588 clock support - private declarations for the core module.
  3. *
  4. * Copyright (C) 2010 OMICRON electronics GmbH
  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 _PTP_PRIVATE_H_
  21. #define _PTP_PRIVATE_H_
  22. #include <linux/cdev.h>
  23. #include <linux/device.h>
  24. #include <linux/mutex.h>
  25. #include <linux/posix-clock.h>
  26. #include <linux/ptp_clock.h>
  27. #include <linux/ptp_clock_kernel.h>
  28. #include <linux/time.h>
  29. #define PTP_MAX_TIMESTAMPS 128
  30. #define PTP_BUF_TIMESTAMPS 30
  31. struct timestamp_event_queue {
  32. struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS];
  33. int head;
  34. int tail;
  35. spinlock_t lock;
  36. };
  37. struct ptp_clock {
  38. struct posix_clock clock;
  39. struct device *dev;
  40. struct ptp_clock_info *info;
  41. dev_t devid;
  42. int index; /* index into clocks.map */
  43. struct pps_device *pps_source;
  44. struct timestamp_event_queue tsevq; /* simple fifo for time stamps */
  45. struct mutex tsevq_mux; /* one process at a time reading the fifo */
  46. wait_queue_head_t tsev_wq;
  47. int defunct; /* tells readers to go away when clock is being removed */
  48. };
  49. /*
  50. * The function queue_cnt() is safe for readers to call without
  51. * holding q->lock. Readers use this function to verify that the queue
  52. * is nonempty before proceeding with a dequeue operation. The fact
  53. * that a writer might concurrently increment the tail does not
  54. * matter, since the queue remains nonempty nonetheless.
  55. */
  56. static inline int queue_cnt(struct timestamp_event_queue *q)
  57. {
  58. int cnt = q->tail - q->head;
  59. return cnt < 0 ? PTP_MAX_TIMESTAMPS + cnt : cnt;
  60. }
  61. /*
  62. * see ptp_chardev.c
  63. */
  64. long ptp_ioctl(struct posix_clock *pc,
  65. unsigned int cmd, unsigned long arg);
  66. int ptp_open(struct posix_clock *pc, fmode_t fmode);
  67. ssize_t ptp_read(struct posix_clock *pc,
  68. uint flags, char __user *buf, size_t cnt);
  69. uint ptp_poll(struct posix_clock *pc,
  70. struct file *fp, poll_table *wait);
  71. /*
  72. * see ptp_sysfs.c
  73. */
  74. extern struct device_attribute ptp_dev_attrs[];
  75. int ptp_cleanup_sysfs(struct ptp_clock *ptp);
  76. int ptp_populate_sysfs(struct ptp_clock *ptp);
  77. #endif