2019-05-20 10:19:02 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-06-18 03:28:37 +04:00
|
|
|
/*
|
|
|
|
* PPS API kernel header
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it>
|
|
|
|
*/
|
|
|
|
|
2011-01-13 04:00:49 +03:00
|
|
|
#ifndef LINUX_PPS_KERNEL_H
|
|
|
|
#define LINUX_PPS_KERNEL_H
|
|
|
|
|
2009-06-18 03:28:37 +04:00
|
|
|
#include <linux/pps.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global defines
|
|
|
|
*/
|
|
|
|
|
2011-01-13 04:00:51 +03:00
|
|
|
struct pps_device;
|
|
|
|
|
2009-06-18 03:28:37 +04:00
|
|
|
/* The specific PPS source info */
|
|
|
|
struct pps_source_info {
|
2017-09-09 02:17:19 +03:00
|
|
|
char name[PPS_MAX_NAME_LEN]; /* symbolic name */
|
2009-06-18 03:28:37 +04:00
|
|
|
char path[PPS_MAX_NAME_LEN]; /* path of connected device */
|
2017-09-09 02:17:19 +03:00
|
|
|
int mode; /* PPS allowed mode */
|
2009-06-18 03:28:37 +04:00
|
|
|
|
2011-01-13 04:00:51 +03:00
|
|
|
void (*echo)(struct pps_device *pps,
|
|
|
|
int event, void *data); /* PPS echo function */
|
2009-06-18 03:28:37 +04:00
|
|
|
|
|
|
|
struct module *owner;
|
2013-02-10 13:08:32 +04:00
|
|
|
struct device *dev; /* Parent device for device_create */
|
2009-06-18 03:28:37 +04:00
|
|
|
};
|
|
|
|
|
2011-01-13 04:00:50 +03:00
|
|
|
struct pps_event_time {
|
2011-01-13 04:00:57 +03:00
|
|
|
#ifdef CONFIG_NTP_PPS
|
2015-09-28 23:21:31 +03:00
|
|
|
struct timespec64 ts_raw;
|
2011-01-13 04:00:57 +03:00
|
|
|
#endif /* CONFIG_NTP_PPS */
|
2015-09-28 23:21:31 +03:00
|
|
|
struct timespec64 ts_real;
|
2011-01-13 04:00:50 +03:00
|
|
|
};
|
|
|
|
|
2009-06-18 03:28:37 +04:00
|
|
|
/* The main struct */
|
|
|
|
struct pps_device {
|
|
|
|
struct pps_source_info info; /* PSS source info */
|
|
|
|
|
2017-09-09 02:17:19 +03:00
|
|
|
struct pps_kparams params; /* PPS current params */
|
2009-06-18 03:28:37 +04:00
|
|
|
|
2017-09-09 02:17:19 +03:00
|
|
|
__u32 assert_sequence; /* PPS assert event seq # */
|
|
|
|
__u32 clear_sequence; /* PPS clear event seq # */
|
2009-06-18 03:28:37 +04:00
|
|
|
struct pps_ktime assert_tu;
|
|
|
|
struct pps_ktime clear_tu;
|
|
|
|
int current_mode; /* PPS mode at event time */
|
|
|
|
|
2011-01-13 04:00:50 +03:00
|
|
|
unsigned int last_ev; /* last PPS event id */
|
2009-06-18 03:28:37 +04:00
|
|
|
wait_queue_head_t queue; /* PPS event queue */
|
|
|
|
|
|
|
|
unsigned int id; /* PPS source unique ID */
|
2017-09-09 02:17:19 +03:00
|
|
|
void const *lookup_cookie; /* For pps_lookup_dev() only */
|
2009-06-18 03:28:37 +04:00
|
|
|
struct cdev cdev;
|
|
|
|
struct device *dev;
|
|
|
|
struct fasync_struct *async_queue; /* fasync method */
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
|
2013-07-25 02:05:19 +04:00
|
|
|
extern const struct attribute_group *pps_groups[];
|
2009-06-18 03:28:37 +04:00
|
|
|
|
2013-02-10 13:08:32 +04:00
|
|
|
/*
|
|
|
|
* Internal functions.
|
|
|
|
*
|
|
|
|
* These are not actually part of the exported API, but this is a
|
|
|
|
* convenient header file to put them in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int pps_register_cdev(struct pps_device *pps);
|
|
|
|
extern void pps_unregister_cdev(struct pps_device *pps);
|
|
|
|
|
2009-06-18 03:28:37 +04:00
|
|
|
/*
|
|
|
|
* Exported functions
|
|
|
|
*/
|
|
|
|
|
2011-01-13 04:00:51 +03:00
|
|
|
extern struct pps_device *pps_register_source(
|
|
|
|
struct pps_source_info *info, int default_params);
|
|
|
|
extern void pps_unregister_source(struct pps_device *pps);
|
|
|
|
extern void pps_event(struct pps_device *pps,
|
|
|
|
struct pps_event_time *ts, int event, void *data);
|
2017-09-09 02:17:19 +03:00
|
|
|
/* Look up a pps_device by magic cookie */
|
2013-02-10 13:08:32 +04:00
|
|
|
struct pps_device *pps_lookup_dev(void const *cookie);
|
2011-01-13 04:00:50 +03:00
|
|
|
|
|
|
|
static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
|
2015-09-28 23:21:31 +03:00
|
|
|
struct timespec64 ts)
|
2011-01-13 04:00:50 +03:00
|
|
|
{
|
|
|
|
kt->sec = ts.tv_sec;
|
|
|
|
kt->nsec = ts.tv_nsec;
|
|
|
|
}
|
|
|
|
|
2011-01-13 04:00:57 +03:00
|
|
|
static inline void pps_get_ts(struct pps_event_time *ts)
|
|
|
|
{
|
2016-02-22 14:15:21 +03:00
|
|
|
struct system_time_snapshot snap;
|
2011-01-13 04:00:57 +03:00
|
|
|
|
2016-02-22 14:15:21 +03:00
|
|
|
ktime_get_snapshot(&snap);
|
|
|
|
ts->ts_real = ktime_to_timespec64(snap.real);
|
|
|
|
#ifdef CONFIG_NTP_PPS
|
|
|
|
ts->ts_raw = ktime_to_timespec64(snap.raw);
|
|
|
|
#endif
|
2011-01-13 04:00:50 +03:00
|
|
|
}
|
2011-01-13 04:00:49 +03:00
|
|
|
|
2012-09-03 14:34:58 +04:00
|
|
|
/* Subtract known time delay from PPS event time(s) */
|
2015-09-28 23:21:31 +03:00
|
|
|
static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
|
2012-09-03 14:34:58 +04:00
|
|
|
{
|
2015-09-28 23:21:31 +03:00
|
|
|
ts->ts_real = timespec64_sub(ts->ts_real, delta);
|
2012-09-03 14:34:58 +04:00
|
|
|
#ifdef CONFIG_NTP_PPS
|
2015-09-28 23:21:31 +03:00
|
|
|
ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
|
2012-09-03 14:34:58 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-01-13 04:00:49 +03:00
|
|
|
#endif /* LINUX_PPS_KERNEL_H */
|