Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * PPS API kernel header
0004  *
0005  * Copyright (C) 2009   Rodolfo Giometti <giometti@linux.it>
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  * Global defines
0018  */
0019 
0020 struct pps_device;
0021 
0022 /* The specific PPS source info */
0023 struct pps_source_info {
0024     char name[PPS_MAX_NAME_LEN];        /* symbolic name */
0025     char path[PPS_MAX_NAME_LEN];        /* path of connected device */
0026     int mode;               /* PPS allowed mode */
0027 
0028     void (*echo)(struct pps_device *pps,
0029             int event, void *data); /* PPS echo function */
0030 
0031     struct module *owner;
0032     struct device *dev;     /* Parent device for device_create */
0033 };
0034 
0035 struct pps_event_time {
0036 #ifdef CONFIG_NTP_PPS
0037     struct timespec64 ts_raw;
0038 #endif /* CONFIG_NTP_PPS */
0039     struct timespec64 ts_real;
0040 };
0041 
0042 /* The main struct */
0043 struct pps_device {
0044     struct pps_source_info info;        /* PSS source info */
0045 
0046     struct pps_kparams params;      /* PPS current params */
0047 
0048     __u32 assert_sequence;          /* PPS assert event seq # */
0049     __u32 clear_sequence;           /* PPS clear event seq # */
0050     struct pps_ktime assert_tu;
0051     struct pps_ktime clear_tu;
0052     int current_mode;           /* PPS mode at event time */
0053 
0054     unsigned int last_ev;           /* last PPS event id */
0055     wait_queue_head_t queue;        /* PPS event queue */
0056 
0057     unsigned int id;            /* PPS source unique ID */
0058     void const *lookup_cookie;      /* For pps_lookup_dev() only */
0059     struct cdev cdev;
0060     struct device *dev;
0061     struct fasync_struct *async_queue;  /* fasync method */
0062     spinlock_t lock;
0063 };
0064 
0065 /*
0066  * Global variables
0067  */
0068 
0069 extern const struct attribute_group *pps_groups[];
0070 
0071 /*
0072  * Internal functions.
0073  *
0074  * These are not actually part of the exported API, but this is a
0075  * convenient header file to put them in.
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  * Exported functions
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 /* Look up a pps_device by magic cookie */
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 /* Subtract known time delay from PPS event time(s) */
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 /* LINUX_PPS_KERNEL_H */