Commit | Line | Data |
---|---|---|
74ba9207 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
eae9d2ba RG |
2 | /* |
3 | * PPS API kernel header | |
4 | * | |
5 | * Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it> | |
eae9d2ba RG |
6 | */ |
7 | ||
7a21a3cc AG |
8 | #ifndef LINUX_PPS_KERNEL_H |
9 | #define LINUX_PPS_KERNEL_H | |
10 | ||
eae9d2ba | 11 | #include <linux/pps.h> |
eae9d2ba RG |
12 | #include <linux/cdev.h> |
13 | #include <linux/device.h> | |
14 | #include <linux/time.h> | |
15 | ||
16 | /* | |
17 | * Global defines | |
18 | */ | |
19 | ||
5e196d34 AG |
20 | struct pps_device; |
21 | ||
eae9d2ba RG |
22 | /* The specific PPS source info */ |
23 | struct pps_source_info { | |
a2d81803 | 24 | char name[PPS_MAX_NAME_LEN]; /* symbolic name */ |
eae9d2ba | 25 | char path[PPS_MAX_NAME_LEN]; /* path of connected device */ |
a2d81803 | 26 | int mode; /* PPS allowed mode */ |
eae9d2ba | 27 | |
5e196d34 AG |
28 | void (*echo)(struct pps_device *pps, |
29 | int event, void *data); /* PPS echo function */ | |
eae9d2ba RG |
30 | |
31 | struct module *owner; | |
513b032c | 32 | struct device *dev; /* Parent device for device_create */ |
eae9d2ba RG |
33 | }; |
34 | ||
6f4229b5 | 35 | struct pps_event_time { |
e2c18e49 | 36 | #ifdef CONFIG_NTP_PPS |
ade1bdff | 37 | struct timespec64 ts_raw; |
e2c18e49 | 38 | #endif /* CONFIG_NTP_PPS */ |
ade1bdff | 39 | struct timespec64 ts_real; |
6f4229b5 AG |
40 | }; |
41 | ||
eae9d2ba RG |
42 | /* The main struct */ |
43 | struct pps_device { | |
44 | struct pps_source_info info; /* PSS source info */ | |
45 | ||
a2d81803 | 46 | struct pps_kparams params; /* PPS current params */ |
eae9d2ba | 47 | |
a2d81803 RD |
48 | __u32 assert_sequence; /* PPS assert event seq # */ |
49 | __u32 clear_sequence; /* PPS clear event seq # */ | |
eae9d2ba RG |
50 | struct pps_ktime assert_tu; |
51 | struct pps_ktime clear_tu; | |
52 | int current_mode; /* PPS mode at event time */ | |
53 | ||
3003d55b | 54 | unsigned int last_ev; /* last PPS event id */ |
eae9d2ba RG |
55 | wait_queue_head_t queue; /* PPS event queue */ |
56 | ||
57 | unsigned int id; /* PPS source unique ID */ | |
a2d81803 | 58 | void const *lookup_cookie; /* For pps_lookup_dev() only */ |
eae9d2ba RG |
59 | struct cdev cdev; |
60 | struct device *dev; | |
eae9d2ba RG |
61 | struct fasync_struct *async_queue; /* fasync method */ |
62 | spinlock_t lock; | |
eae9d2ba RG |
63 | }; |
64 | ||
65 | /* | |
66 | * Global variables | |
67 | */ | |
68 | ||
bd0eae4e | 69 | extern const struct attribute_group *pps_groups[]; |
eae9d2ba | 70 | |
513b032c GS |
71 | /* |
72 | * Internal functions. | |
73 | * | |
74 | * These are not actually part of the exported API, but this is a | |
75 | * convenient header file to put them in. | |
76 | */ | |
77 | ||
78 | extern int pps_register_cdev(struct pps_device *pps); | |
79 | extern void pps_unregister_cdev(struct pps_device *pps); | |
80 | ||
eae9d2ba RG |
81 | /* |
82 | * Exported functions | |
83 | */ | |
84 | ||
5e196d34 AG |
85 | extern struct pps_device *pps_register_source( |
86 | struct pps_source_info *info, int default_params); | |
87 | extern void pps_unregister_source(struct pps_device *pps); | |
5e196d34 AG |
88 | extern void pps_event(struct pps_device *pps, |
89 | struct pps_event_time *ts, int event, void *data); | |
a2d81803 | 90 | /* Look up a pps_device by magic cookie */ |
513b032c | 91 | struct pps_device *pps_lookup_dev(void const *cookie); |
6f4229b5 AG |
92 | |
93 | static inline void timespec_to_pps_ktime(struct pps_ktime *kt, | |
ade1bdff | 94 | struct timespec64 ts) |
6f4229b5 AG |
95 | { |
96 | kt->sec = ts.tv_sec; | |
97 | kt->nsec = ts.tv_nsec; | |
98 | } | |
99 | ||
e2c18e49 AG |
100 | static inline void pps_get_ts(struct pps_event_time *ts) |
101 | { | |
ba26621e | 102 | struct system_time_snapshot snap; |
e2c18e49 | 103 | |
ba26621e CH |
104 | ktime_get_snapshot(&snap); |
105 | ts->ts_real = ktime_to_timespec64(snap.real); | |
106 | #ifdef CONFIG_NTP_PPS | |
107 | ts->ts_raw = ktime_to_timespec64(snap.raw); | |
108 | #endif | |
6f4229b5 | 109 | } |
7a21a3cc | 110 | |
220a60a4 | 111 | /* Subtract known time delay from PPS event time(s) */ |
ade1bdff | 112 | static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta) |
220a60a4 | 113 | { |
ade1bdff | 114 | ts->ts_real = timespec64_sub(ts->ts_real, delta); |
220a60a4 | 115 | #ifdef CONFIG_NTP_PPS |
ade1bdff | 116 | ts->ts_raw = timespec64_sub(ts->ts_raw, delta); |
220a60a4 BH |
117 | #endif |
118 | } | |
119 | ||
7a21a3cc | 120 | #endif /* LINUX_PPS_KERNEL_H */ |