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