0001
0002
0003
0004
0005
0006
0007
0008 #ifndef LINUX_PPS_KERNEL_H
0009 #define LINUX_PPS_KERNEL_H
0010
0011 #include <linux/pps.h>
0012 #include <linux/cdev.h>
0013 #include <linux/device.h>
0014 #include <linux/time.h>
0015
0016
0017
0018
0019
0020 struct pps_device;
0021
0022
0023 struct pps_source_info {
0024 char name[PPS_MAX_NAME_LEN];
0025 char path[PPS_MAX_NAME_LEN];
0026 int mode;
0027
0028 void (*echo)(struct pps_device *pps,
0029 int event, void *data);
0030
0031 struct module *owner;
0032 struct device *dev;
0033 };
0034
0035 struct pps_event_time {
0036 #ifdef CONFIG_NTP_PPS
0037 struct timespec64 ts_raw;
0038 #endif
0039 struct timespec64 ts_real;
0040 };
0041
0042
0043 struct pps_device {
0044 struct pps_source_info info;
0045
0046 struct pps_kparams params;
0047
0048 __u32 assert_sequence;
0049 __u32 clear_sequence;
0050 struct pps_ktime assert_tu;
0051 struct pps_ktime clear_tu;
0052 int current_mode;
0053
0054 unsigned int last_ev;
0055 wait_queue_head_t queue;
0056
0057 unsigned int id;
0058 void const *lookup_cookie;
0059 struct cdev cdev;
0060 struct device *dev;
0061 struct fasync_struct *async_queue;
0062 spinlock_t lock;
0063 };
0064
0065
0066
0067
0068
0069 extern const struct attribute_group *pps_groups[];
0070
0071
0072
0073
0074
0075
0076
0077
0078 extern int pps_register_cdev(struct pps_device *pps);
0079 extern void pps_unregister_cdev(struct pps_device *pps);
0080
0081
0082
0083
0084
0085 extern struct pps_device *pps_register_source(
0086 struct pps_source_info *info, int default_params);
0087 extern void pps_unregister_source(struct pps_device *pps);
0088 extern void pps_event(struct pps_device *pps,
0089 struct pps_event_time *ts, int event, void *data);
0090
0091 struct pps_device *pps_lookup_dev(void const *cookie);
0092
0093 static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
0094 struct timespec64 ts)
0095 {
0096 kt->sec = ts.tv_sec;
0097 kt->nsec = ts.tv_nsec;
0098 }
0099
0100 static inline void pps_get_ts(struct pps_event_time *ts)
0101 {
0102 struct system_time_snapshot snap;
0103
0104 ktime_get_snapshot(&snap);
0105 ts->ts_real = ktime_to_timespec64(snap.real);
0106 #ifdef CONFIG_NTP_PPS
0107 ts->ts_raw = ktime_to_timespec64(snap.raw);
0108 #endif
0109 }
0110
0111
0112 static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
0113 {
0114 ts->ts_real = timespec64_sub(ts->ts_real, delta);
0115 #ifdef CONFIG_NTP_PPS
0116 ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
0117 #endif
0118 }
0119
0120 #endif