ptp_private.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * PTP 1588 clock support - private declarations for the core module.
  4. *
  5. * Copyright (C) 2010 OMICRON electronics GmbH
  6. */
  7. #ifndef _PTP_PRIVATE_H_
  8. #define _PTP_PRIVATE_H_
  9. #include <linux/cdev.h>
  10. #include <linux/device.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/posix-clock.h>
  14. #include <linux/ptp_clock.h>
  15. #include <linux/ptp_clock_kernel.h>
  16. #include <linux/time.h>
  17. #define PTP_MAX_TIMESTAMPS 128
  18. #define PTP_BUF_TIMESTAMPS 30
  19. struct timestamp_event_queue {
  20. struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS];
  21. int head;
  22. int tail;
  23. spinlock_t lock;
  24. };
  25. struct ptp_clock {
  26. struct posix_clock clock;
  27. struct device dev;
  28. struct ptp_clock_info *info;
  29. dev_t devid;
  30. int index; /* index into clocks.map */
  31. struct pps_device *pps_source;
  32. long dialed_frequency; /* remembers the frequency adjustment */
  33. struct timestamp_event_queue tsevq; /* simple fifo for time stamps */
  34. struct mutex tsevq_mux; /* one process at a time reading the fifo */
  35. struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
  36. wait_queue_head_t tsev_wq;
  37. int defunct; /* tells readers to go away when clock is being removed */
  38. struct device_attribute *pin_dev_attr;
  39. struct attribute **pin_attr;
  40. struct attribute_group pin_attr_group;
  41. /* 1st entry is a pointer to the real group, 2nd is NULL terminator */
  42. const struct attribute_group *pin_attr_groups[2];
  43. struct kthread_worker *kworker;
  44. struct kthread_delayed_work aux_work;
  45. };
  46. /*
  47. * The function queue_cnt() is safe for readers to call without
  48. * holding q->lock. Readers use this function to verify that the queue
  49. * is nonempty before proceeding with a dequeue operation. The fact
  50. * that a writer might concurrently increment the tail does not
  51. * matter, since the queue remains nonempty nonetheless.
  52. */
  53. static inline int queue_cnt(struct timestamp_event_queue *q)
  54. {
  55. int cnt = q->tail - q->head;
  56. return cnt < 0 ? PTP_MAX_TIMESTAMPS + cnt : cnt;
  57. }
  58. /*
  59. * see ptp_chardev.c
  60. */
  61. /* caller must hold pincfg_mux */
  62. int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
  63. enum ptp_pin_function func, unsigned int chan);
  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. __poll_t ptp_poll(struct posix_clock *pc,
  70. struct file *fp, poll_table *wait);
  71. /*
  72. * see ptp_sysfs.c
  73. */
  74. extern const struct attribute_group *ptp_groups[];
  75. int ptp_populate_pin_groups(struct ptp_clock *ptp);
  76. void ptp_cleanup_pin_groups(struct ptp_clock *ptp);
  77. #endif