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