Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / include / linux / pps_kernel.h
blob80a980cc8d95f174a120fbd1aece4bdf7e55315b
1 /*
2 * PPS API kernel header
4 * Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it>
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.
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.
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.
21 #ifndef LINUX_PPS_KERNEL_H
22 #define LINUX_PPS_KERNEL_H
24 #include <linux/pps.h>
25 #include <linux/cdev.h>
26 #include <linux/device.h>
27 #include <linux/time.h>
30 * Global defines
33 struct pps_device;
35 /* The specific PPS source info */
36 struct pps_source_info {
37 char name[PPS_MAX_NAME_LEN]; /* symbolic name */
38 char path[PPS_MAX_NAME_LEN]; /* path of connected device */
39 int mode; /* PPS allowed mode */
41 void (*echo)(struct pps_device *pps,
42 int event, void *data); /* PPS echo function */
44 struct module *owner;
45 struct device *dev; /* Parent device for device_create */
48 struct pps_event_time {
49 #ifdef CONFIG_NTP_PPS
50 struct timespec64 ts_raw;
51 #endif /* CONFIG_NTP_PPS */
52 struct timespec64 ts_real;
55 /* The main struct */
56 struct pps_device {
57 struct pps_source_info info; /* PSS source info */
59 struct pps_kparams params; /* PPS current params */
61 __u32 assert_sequence; /* PPS assert event seq # */
62 __u32 clear_sequence; /* PPS clear event seq # */
63 struct pps_ktime assert_tu;
64 struct pps_ktime clear_tu;
65 int current_mode; /* PPS mode at event time */
67 unsigned int last_ev; /* last PPS event id */
68 wait_queue_head_t queue; /* PPS event queue */
70 unsigned int id; /* PPS source unique ID */
71 void const *lookup_cookie; /* For pps_lookup_dev() only */
72 struct cdev cdev;
73 struct device *dev;
74 struct fasync_struct *async_queue; /* fasync method */
75 spinlock_t lock;
79 * Global variables
82 extern const struct attribute_group *pps_groups[];
85 * Internal functions.
87 * These are not actually part of the exported API, but this is a
88 * convenient header file to put them in.
91 extern int pps_register_cdev(struct pps_device *pps);
92 extern void pps_unregister_cdev(struct pps_device *pps);
95 * Exported functions
98 extern struct pps_device *pps_register_source(
99 struct pps_source_info *info, int default_params);
100 extern void pps_unregister_source(struct pps_device *pps);
101 extern void pps_event(struct pps_device *pps,
102 struct pps_event_time *ts, int event, void *data);
103 /* Look up a pps_device by magic cookie */
104 struct pps_device *pps_lookup_dev(void const *cookie);
106 static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
107 struct timespec64 ts)
109 kt->sec = ts.tv_sec;
110 kt->nsec = ts.tv_nsec;
113 static inline void pps_get_ts(struct pps_event_time *ts)
115 struct system_time_snapshot snap;
117 ktime_get_snapshot(&snap);
118 ts->ts_real = ktime_to_timespec64(snap.real);
119 #ifdef CONFIG_NTP_PPS
120 ts->ts_raw = ktime_to_timespec64(snap.raw);
121 #endif
124 /* Subtract known time delay from PPS event time(s) */
125 static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
127 ts->ts_real = timespec64_sub(ts->ts_real, delta);
128 #ifdef CONFIG_NTP_PPS
129 ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
130 #endif
133 #endif /* LINUX_PPS_KERNEL_H */