1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef LINUX_PPS_KERNEL_H
22#define LINUX_PPS_KERNEL_H
23
24#include <linux/pps.h>
25#include <linux/cdev.h>
26#include <linux/device.h>
27#include <linux/time.h>
28
29
30
31
32
33struct pps_device;
34
35
36struct pps_source_info {
37 char name[PPS_MAX_NAME_LEN];
38 char path[PPS_MAX_NAME_LEN];
39 int mode;
40
41 void (*echo)(struct pps_device *pps,
42 int event, void *data);
43
44 struct module *owner;
45 struct device *dev;
46};
47
48struct pps_event_time {
49#ifdef CONFIG_NTP_PPS
50 struct timespec64 ts_raw;
51#endif
52 struct timespec64 ts_real;
53};
54
55
56struct pps_device {
57 struct pps_source_info info;
58
59 struct pps_kparams params;
60
61 __u32 assert_sequence;
62 __u32 clear_sequence;
63 struct pps_ktime assert_tu;
64 struct pps_ktime clear_tu;
65 int current_mode;
66
67 unsigned int last_ev;
68 wait_queue_head_t queue;
69
70 unsigned int id;
71 void const *lookup_cookie;
72 struct cdev cdev;
73 struct device *dev;
74 struct fasync_struct *async_queue;
75 spinlock_t lock;
76};
77
78
79
80
81
82extern const struct attribute_group *pps_groups[];
83
84
85
86
87
88
89
90
91extern int pps_register_cdev(struct pps_device *pps);
92extern void pps_unregister_cdev(struct pps_device *pps);
93
94
95
96
97
98extern struct pps_device *pps_register_source(
99 struct pps_source_info *info, int default_params);
100extern void pps_unregister_source(struct pps_device *pps);
101extern void pps_event(struct pps_device *pps,
102 struct pps_event_time *ts, int event, void *data);
103
104struct pps_device *pps_lookup_dev(void const *cookie);
105
106static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
107 struct timespec64 ts)
108{
109 kt->sec = ts.tv_sec;
110 kt->nsec = ts.tv_nsec;
111}
112
113static inline void pps_get_ts(struct pps_event_time *ts)
114{
115 struct system_time_snapshot snap;
116
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
122}
123
124
125static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
126{
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
131}
132
133#endif
134