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