Linux 6.14-rc1
[linux.git] / include / linux / pps_kernel.h
blobc7abce28ed29958db487a1bc249966e080a10236
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * PPS API kernel header
5 * Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it>
6 */
8 #ifndef LINUX_PPS_KERNEL_H
9 #define LINUX_PPS_KERNEL_H
11 #include <linux/pps.h>
12 #include <linux/cdev.h>
13 #include <linux/device.h>
14 #include <linux/time.h>
17 * Global defines
20 struct pps_device;
22 /* The specific PPS source info */
23 struct pps_source_info {
24 char name[PPS_MAX_NAME_LEN]; /* symbolic name */
25 char path[PPS_MAX_NAME_LEN]; /* path of connected device */
26 int mode; /* PPS allowed mode */
28 void (*echo)(struct pps_device *pps,
29 int event, void *data); /* PPS echo function */
31 struct module *owner;
32 struct device *dev; /* Parent device for device_create */
35 struct pps_event_time {
36 #ifdef CONFIG_NTP_PPS
37 struct timespec64 ts_raw;
38 #endif /* CONFIG_NTP_PPS */
39 struct timespec64 ts_real;
42 /* The main struct */
43 struct pps_device {
44 struct pps_source_info info; /* PSS source info */
46 struct pps_kparams params; /* PPS current params */
48 __u32 assert_sequence; /* PPS assert event seq # */
49 __u32 clear_sequence; /* PPS clear event seq # */
50 struct pps_ktime assert_tu;
51 struct pps_ktime clear_tu;
52 int current_mode; /* PPS mode at event time */
54 unsigned int last_ev; /* last PPS event id */
55 wait_queue_head_t queue; /* PPS event queue */
57 unsigned int id; /* PPS source unique ID */
58 void const *lookup_cookie; /* For pps_lookup_dev() only */
59 struct device dev;
60 struct fasync_struct *async_queue; /* fasync method */
61 spinlock_t lock;
65 * Global variables
68 extern const struct attribute_group *pps_groups[];
71 * Internal functions.
73 * These are not actually part of the exported API, but this is a
74 * convenient header file to put them in.
77 extern int pps_register_cdev(struct pps_device *pps);
78 extern void pps_unregister_cdev(struct pps_device *pps);
81 * Exported functions
84 extern struct pps_device *pps_register_source(
85 struct pps_source_info *info, int default_params);
86 extern void pps_unregister_source(struct pps_device *pps);
87 extern void pps_event(struct pps_device *pps,
88 struct pps_event_time *ts, int event, void *data);
89 /* Look up a pps_device by magic cookie */
90 struct pps_device *pps_lookup_dev(void const *cookie);
92 static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
93 struct timespec64 ts)
95 kt->sec = ts.tv_sec;
96 kt->nsec = ts.tv_nsec;
99 static inline void pps_get_ts(struct pps_event_time *ts)
101 struct system_time_snapshot snap;
103 ktime_get_snapshot(&snap);
104 ts->ts_real = ktime_to_timespec64(snap.real);
105 #ifdef CONFIG_NTP_PPS
106 ts->ts_raw = ktime_to_timespec64(snap.raw);
107 #endif
110 /* Subtract known time delay from PPS event time(s) */
111 static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
113 ts->ts_real = timespec64_sub(ts->ts_real, delta);
114 #ifdef CONFIG_NTP_PPS
115 ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
116 #endif
119 #endif /* LINUX_PPS_KERNEL_H */