Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 2 | /* |
| 3 | * PTP 1588 clock support - private declarations for the core module. |
| 4 | * |
| 5 | * Copyright (C) 2010 OMICRON electronics GmbH |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 6 | */ |
| 7 | #ifndef _PTP_PRIVATE_H_ |
| 8 | #define _PTP_PRIVATE_H_ |
| 9 | |
| 10 | #include <linux/cdev.h> |
| 11 | #include <linux/device.h> |
Grygorii Strashko | d9535cb | 2017-07-28 17:30:02 -0500 | [diff] [blame] | 12 | #include <linux/kthread.h> |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 13 | #include <linux/mutex.h> |
| 14 | #include <linux/posix-clock.h> |
| 15 | #include <linux/ptp_clock.h> |
| 16 | #include <linux/ptp_clock_kernel.h> |
| 17 | #include <linux/time.h> |
| 18 | |
| 19 | #define PTP_MAX_TIMESTAMPS 128 |
| 20 | #define PTP_BUF_TIMESTAMPS 30 |
| 21 | |
| 22 | struct timestamp_event_queue { |
| 23 | struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS]; |
| 24 | int head; |
| 25 | int tail; |
| 26 | spinlock_t lock; |
| 27 | }; |
| 28 | |
| 29 | struct ptp_clock { |
| 30 | struct posix_clock clock; |
Vladis Dronov | a33121e | 2019-12-27 03:26:27 +0100 | [diff] [blame] | 31 | struct device dev; |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 32 | struct ptp_clock_info *info; |
| 33 | dev_t devid; |
| 34 | int index; /* index into clocks.map */ |
| 35 | struct pps_device *pps_source; |
Richard Cochran | 39a8cbd | 2012-09-22 07:02:01 +0000 | [diff] [blame] | 36 | long dialed_frequency; /* remembers the frequency adjustment */ |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 37 | struct timestamp_event_queue tsevq; /* simple fifo for time stamps */ |
| 38 | struct mutex tsevq_mux; /* one process at a time reading the fifo */ |
Richard Cochran | 6092315 | 2014-03-20 22:21:52 +0100 | [diff] [blame] | 39 | struct mutex pincfg_mux; /* protect concurrent info->pin_config access */ |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 40 | wait_queue_head_t tsev_wq; |
| 41 | int defunct; /* tells readers to go away when clock is being removed */ |
Richard Cochran | 653104d | 2014-03-20 22:21:54 +0100 | [diff] [blame] | 42 | struct device_attribute *pin_dev_attr; |
| 43 | struct attribute **pin_attr; |
| 44 | struct attribute_group pin_attr_group; |
Dmitry Torokhov | 85a66e5 | 2017-02-14 10:23:34 -0800 | [diff] [blame] | 45 | /* 1st entry is a pointer to the real group, 2nd is NULL terminator */ |
| 46 | const struct attribute_group *pin_attr_groups[2]; |
Grygorii Strashko | d9535cb | 2017-07-28 17:30:02 -0500 | [diff] [blame] | 47 | struct kthread_worker *kworker; |
| 48 | struct kthread_delayed_work aux_work; |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /* |
| 52 | * The function queue_cnt() is safe for readers to call without |
| 53 | * holding q->lock. Readers use this function to verify that the queue |
| 54 | * is nonempty before proceeding with a dequeue operation. The fact |
| 55 | * that a writer might concurrently increment the tail does not |
| 56 | * matter, since the queue remains nonempty nonetheless. |
| 57 | */ |
| 58 | static inline int queue_cnt(struct timestamp_event_queue *q) |
| 59 | { |
| 60 | int cnt = q->tail - q->head; |
| 61 | return cnt < 0 ? PTP_MAX_TIMESTAMPS + cnt : cnt; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * see ptp_chardev.c |
| 66 | */ |
| 67 | |
Richard Cochran | 6092315 | 2014-03-20 22:21:52 +0100 | [diff] [blame] | 68 | /* caller must hold pincfg_mux */ |
| 69 | int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin, |
| 70 | enum ptp_pin_function func, unsigned int chan); |
| 71 | |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 72 | long ptp_ioctl(struct posix_clock *pc, |
| 73 | unsigned int cmd, unsigned long arg); |
| 74 | |
| 75 | int ptp_open(struct posix_clock *pc, fmode_t fmode); |
| 76 | |
| 77 | ssize_t ptp_read(struct posix_clock *pc, |
| 78 | uint flags, char __user *buf, size_t cnt); |
| 79 | |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 80 | __poll_t ptp_poll(struct posix_clock *pc, |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 81 | struct file *fp, poll_table *wait); |
| 82 | |
| 83 | /* |
| 84 | * see ptp_sysfs.c |
| 85 | */ |
| 86 | |
Greg Kroah-Hartman | 3499116 | 2013-07-24 15:05:20 -0700 | [diff] [blame] | 87 | extern const struct attribute_group *ptp_groups[]; |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 88 | |
Dmitry Torokhov | 85a66e5 | 2017-02-14 10:23:34 -0800 | [diff] [blame] | 89 | int ptp_populate_pin_groups(struct ptp_clock *ptp); |
| 90 | void ptp_cleanup_pin_groups(struct ptp_clock *ptp); |
Richard Cochran | d94ba80 | 2011-04-22 12:03:08 +0200 | [diff] [blame] | 91 | |
| 92 | #endif |